diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3d4acd5af6..d5294d8b3a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -803,6 +803,20 @@ jobs: - name: Run Benchmark run: ./gc $(realpath ./build/scala-cli) + test-hypothetical-sbt-export: + timeout-minutes: 120 + runs-on: "ubuntu-20.04" + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + submodules: true + - uses: VirtusLab/scala-cli-setup@ae54b20650cb58733b00250aafab28f841e6d870 + with: + jvm: "temurin:17" + - name: Try to export to SBT + run: scala-cli --power export --sbt . + vc-redist: timeout-minutes: 15 runs-on: windows-latest diff --git a/.gitignore b/.gitignore index 1f941ec85a..231859a274 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ out/ .bsp .scala-build +dest/ diff --git a/examples/.gitignore b/examples/.gitignore deleted file mode 100644 index f26f6777f6..0000000000 --- a/examples/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.scala-build/ -.bsp/ diff --git a/examples/cross-build/.opts b/examples/cross-build/.opts deleted file mode 100644 index 20a0293170..0000000000 --- a/examples/cross-build/.opts +++ /dev/null @@ -1 +0,0 @@ ---js --help \ No newline at end of file diff --git a/examples/cross-build/Hello.js.scala b/examples/cross-build/Hello.js.scala deleted file mode 100644 index 85622a978a..0000000000 --- a/examples/cross-build/Hello.js.scala +++ /dev/null @@ -1,11 +0,0 @@ -//> using scala "2.13" -//> using target "scala-js" - -import scala.scalajs.js - -object Test { - def main(args: Array[String]): Unit = { - val console = js.Dynamic.global.console - console.log("Hello from Scala.js") - } -} diff --git a/examples/cross-build/Hello.native.scala b/examples/cross-build/Hello.native.scala deleted file mode 100644 index 9f810dd7d4..0000000000 --- a/examples/cross-build/Hello.native.scala +++ /dev/null @@ -1,14 +0,0 @@ -//> using scala "2.13" -//> using target "scala-native" - -import scala.scalanative.libc._ -import scala.scalanative.unsafe._ - -object Test { - def main(args: Array[String]): Unit = { - val message = "Hello from Scala Native\n" - Zone { implicit z => - stdio.printf(toCString(message)) - } - } -} diff --git a/examples/java-print-class-path/Hello.java b/examples/java-print-class-path/Hello.java deleted file mode 100644 index 9ae02fe18e..0000000000 --- a/examples/java-print-class-path/Hello.java +++ /dev/null @@ -1,27 +0,0 @@ -import java.io.File; -import java.net.URL; -import java.net.URLClassLoader; - -public class Hello { - private static void printCp(ClassLoader cl) { - if (cl == null) return; - if (cl instanceof URLClassLoader) { - URLClassLoader ucl = (URLClassLoader) cl; - for (URL url : ucl.getURLs()) { - System.out.println(url); - } - } else if (cl.getClass().getName() == "jdk.internal.loader.ClassLoaders$AppClassLoader") { - String cp = System.getProperty("java.class.path"); - for (String elem : cp.split(File.pathSeparator)) { - System.out.println(elem); - } - } else { - System.out.println("* " + cl); - } - printCp(cl.getParent()); - } - public static void main(String[] args) { - System.out.println("Hello from Java"); - printCp(Thread.currentThread().getContextClassLoader()); - } -} diff --git a/examples/java/Hello.java b/examples/java/Hello.java deleted file mode 100644 index e66603d91f..0000000000 --- a/examples/java/Hello.java +++ /dev/null @@ -1,5 +0,0 @@ -public class Hello { - public static void main(String[] args) { - System.out.println("Hello from Java"); - } -} diff --git a/examples/jmh/.opts b/examples/jmh/.opts deleted file mode 100644 index 9bfffde0ac..0000000000 --- a/examples/jmh/.opts +++ /dev/null @@ -1 +0,0 @@ ---power --jmh \ No newline at end of file diff --git a/examples/jmh/Benchmarks.scala b/examples/jmh/Benchmarks.scala deleted file mode 100644 index a0b7d1dfaf..0000000000 --- a/examples/jmh/Benchmarks.scala +++ /dev/null @@ -1,18 +0,0 @@ -package bench - -import java.util.concurrent.TimeUnit -import org.openjdk.jmh.annotations._ - -@BenchmarkMode(Array(Mode.AverageTime)) -@OutputTimeUnit(TimeUnit.NANOSECONDS) -@Warmup(iterations = 1, time = 100, timeUnit = TimeUnit.MILLISECONDS) -@Measurement(iterations = 10, time = 100, timeUnit = TimeUnit.MILLISECONDS) -@Fork(0) -class Benchmarks { - - @Benchmark - def foo(): Unit = { - (1L to 10000000L).sum - } - -} diff --git a/examples/junit/.opts b/examples/junit/.opts deleted file mode 100644 index 30d74d2584..0000000000 --- a/examples/junit/.opts +++ /dev/null @@ -1 +0,0 @@ -test \ No newline at end of file diff --git a/examples/junit/MyTests.scala b/examples/junit/MyTests.scala deleted file mode 100644 index 3f88298cb6..0000000000 --- a/examples/junit/MyTests.scala +++ /dev/null @@ -1,10 +0,0 @@ -//> using dep "com.github.sbt:junit-interface:0.13.2" -import org.junit.Test - -class MyTests { - - @Test - def foo(): Unit = { - assert(2 + 2 == 4) - } -} diff --git a/examples/scala-3/.opts b/examples/scala-3/.opts deleted file mode 100644 index fee8150323..0000000000 --- a/examples/scala-3/.opts +++ /dev/null @@ -1 +0,0 @@ --S 3 \ No newline at end of file diff --git a/examples/scala-3/foo3.sc b/examples/scala-3/foo3.sc deleted file mode 100644 index 9680e2f410..0000000000 --- a/examples/scala-3/foo3.sc +++ /dev/null @@ -1,7 +0,0 @@ -val sv = scala.util.Properties.versionNumberString - -def printMessage(): Unit = - val message = s"Hello from Scala ${sv}, Java ${System.getProperty("java.version")}" - println(message) - -printMessage() diff --git a/examples/scala-files/simple.scala b/examples/scala-files/simple.scala deleted file mode 100644 index 847fbff0ac..0000000000 --- a/examples/scala-files/simple.scala +++ /dev/null @@ -1,10 +0,0 @@ -//> using dep "com.lihaoyi::pprint:0.8.1" - -object Test { - def something[F[_]] = () - def msg = "Hello" - def main(args: Array[String]): Unit = { - pprint.log(args) - pprint.log(msg) - } -} diff --git a/examples/scala-js/.opts b/examples/scala-js/.opts deleted file mode 100644 index df774ca09a..0000000000 --- a/examples/scala-js/.opts +++ /dev/null @@ -1 +0,0 @@ ---js \ No newline at end of file diff --git a/examples/scala-js/foojs.sc b/examples/scala-js/foojs.sc deleted file mode 100644 index 073c95d768..0000000000 --- a/examples/scala-js/foojs.sc +++ /dev/null @@ -1 +0,0 @@ -println(s"Hello from Scala.js ${scala.scalajs.runtime.linkingInfo.linkerVersion}") diff --git a/examples/scala-jvm/Main.scala b/examples/scala-jvm/Main.scala deleted file mode 100644 index ac2a8c0a27..0000000000 --- a/examples/scala-jvm/Main.scala +++ /dev/null @@ -1,11 +0,0 @@ -// File was generated from based on docs/cookbooks/scala-jvm.md, do not edit manually! - -import java.nio.file.Files -import java.nio.file.Paths - -object Main extends App { - val dest = Files.createTempDirectory("scala-cli-demo").resolve("hello.txt") - val filePath = Files.writeString(dest, "Hello from ScalaCli") - val fileContent: String = Files.readString(filePath) - println(fileContent) -} \ No newline at end of file diff --git a/examples/scala-jvm/README.md b/examples/scala-jvm/README.md deleted file mode 100644 index 6ff8d93a39..0000000000 --- a/examples/scala-jvm/README.md +++ /dev/null @@ -1,48 +0,0 @@ - - - -# Test your code with different Java versions - -You can use Scala CLI to test your code compatibility with various versions of `java` (no manual installation of jdk or sdk is required). It automatically downloads the specified version of java. - -The following snippet uses the new method `Files.writeString` from Java 11. - -```scala title=Main.scala -import java.nio.file.Files -import java.nio.file.Paths - -object Main extends App { - val dest = Files.createTempDirectory("scala-cli-demo").resolve("hello.txt") - val filePath = Files.writeString(dest, "Hello from ScalaCli") - val fileContent: String = Files.readString(filePath) - println(fileContent) -} -``` - -Pass `--jvm` to the `scala-cli` command to run your application with the specified java version. - -```bash ignore -scala-cli --jvm adopt:11 Main.scala -``` - - - -To test your application with Java 8, change the value of `--jvm` parameter. -```bash ignore fail -scala-cli --jvm 8 Main.scala -# In this case, it raises an error because the `Files.createTempFile` method is not available in java 8 -# -# Exception in thread main: java.lang.Exception: java.lang.NoSuchMethodError: java.nio.file.Files.writeString(Ljava/nio/file/Path;Ljava/lang/CharSequence;[Ljava/nio/file/OpenOption;)Ljava/nio/file/Path; -# at method print in modules/runner/src/main/scala-3-stable/scala/cli/runner/Stacktrace.scala:12 inside runner_3.jar -# at method printException in modules/runner/src/main/scala/scala/cli/runner/StackTracePrinter.scala:91 inside runner_3.jar -# at method main in modules/runner/src/main/scala/scala/cli/runner/Runner.scala:22 inside runner_3.jar -``` - - \ No newline at end of file diff --git a/examples/scala-native/.opts b/examples/scala-native/.opts deleted file mode 100644 index c379fcf698..0000000000 --- a/examples/scala-native/.opts +++ /dev/null @@ -1 +0,0 @@ ---native -S 2.13.8 \ No newline at end of file diff --git a/examples/scala-native/test.sc b/examples/scala-native/test.sc deleted file mode 100644 index f0748d5b66..0000000000 --- a/examples/scala-native/test.sc +++ /dev/null @@ -1,7 +0,0 @@ -import scala.scalanative.libc._ -import scala.scalanative.unsafe._ - -Zone { implicit z => - val io = StdioHelpers(stdio) - io.printf(c"%s\n", c"Hello from Scala Native") -} \ No newline at end of file diff --git a/examples/scalatest/.opts b/examples/scalatest/.opts deleted file mode 100644 index 30d74d2584..0000000000 --- a/examples/scalatest/.opts +++ /dev/null @@ -1 +0,0 @@ -test \ No newline at end of file diff --git a/examples/scalatest/Tests.scala b/examples/scalatest/Tests.scala deleted file mode 100644 index 0d2ac85f2d..0000000000 --- a/examples/scalatest/Tests.scala +++ /dev/null @@ -1,11 +0,0 @@ -//> using dep "org.scalatest::scalatest::3.2.9" - -import org.scalatest._ -import flatspec._ -import matchers._ - -class Tests extends AnyFlatSpec with should.Matchers { - "A thing" should "thing" in { - assert(2 + 2 == 4) - } -} diff --git a/examples/scripts/.opts b/examples/scripts/.opts deleted file mode 100644 index bf8d51d132..0000000000 --- a/examples/scripts/.opts +++ /dev/null @@ -1 +0,0 @@ ---main-class foo_sc \ No newline at end of file diff --git a/examples/scripts/bar.sc b/examples/scripts/bar.sc deleted file mode 100644 index 02184b5aa0..0000000000 --- a/examples/scripts/bar.sc +++ /dev/null @@ -1 +0,0 @@ -val n = 1 diff --git a/examples/scripts/foo.sc b/examples/scripts/foo.sc deleted file mode 100644 index 5f21084e6d..0000000000 --- a/examples/scripts/foo.sc +++ /dev/null @@ -1,9 +0,0 @@ -import bar.n - -import scala.collection.JavaConverters._ -def something[F[_]] = () - -println( - s"Hello from Scala ${scala.util.Properties.versionNumberString}, Java ${System.getProperty("java.version")}, n=$n" -) - diff --git a/examples/stacktraces-script/.opts b/examples/stacktraces-script/.opts deleted file mode 100644 index f8808babbb..0000000000 --- a/examples/stacktraces-script/.opts +++ /dev/null @@ -1 +0,0 @@ -compile \ No newline at end of file diff --git a/examples/stacktraces-script/stack-traces.sc b/examples/stacktraces-script/stack-traces.sc deleted file mode 100644 index e35bd3e634..0000000000 --- a/examples/stacktraces-script/stack-traces.sc +++ /dev/null @@ -1,12 +0,0 @@ -def something(n: Int): String = - if (n % 10 == 0) sys.error("nope") - else n.toString - -try { - for (i <- 1 until 100) - println(something(i)) -} -catch { - case e: Exception => - throw new Exception("Caught exception during processing", e) -} diff --git a/examples/stacktraces/.opts b/examples/stacktraces/.opts deleted file mode 100644 index f8808babbb..0000000000 --- a/examples/stacktraces/.opts +++ /dev/null @@ -1 +0,0 @@ -compile \ No newline at end of file diff --git a/examples/stacktraces/StackTraces.scala b/examples/stacktraces/StackTraces.scala deleted file mode 100644 index 786eea6343..0000000000 --- a/examples/stacktraces/StackTraces.scala +++ /dev/null @@ -1,14 +0,0 @@ -object StackTraces { - def something(n: Int): String = - if (n % 10 == 0) sys.error("nope") - else n.toString - def main(args: Array[String]): Unit = - try { - for (i <- 1 until 100) - println(something(i)) - } - catch { - case e: Exception => - throw new Exception("Caught exception during processing", e) - } -} diff --git a/examples/tests/.opts b/examples/tests/.opts deleted file mode 100644 index 30d74d2584..0000000000 --- a/examples/tests/.opts +++ /dev/null @@ -1 +0,0 @@ -test \ No newline at end of file diff --git a/examples/tests/MyTests.scala b/examples/tests/MyTests.scala deleted file mode 100644 index 66fd25aff4..0000000000 --- a/examples/tests/MyTests.scala +++ /dev/null @@ -1,10 +0,0 @@ -//> using dep "org.scalameta::munit::0.7.29" - -class MyTests extends munit.FunSuite { - test("foo") { - assert(2 + 2 == 4) - } - // test("nope") { - // assert(2 + 2 == 5) - // } -} diff --git a/examples/utest/.opts b/examples/utest/.opts deleted file mode 100644 index 30d74d2584..0000000000 --- a/examples/utest/.opts +++ /dev/null @@ -1 +0,0 @@ -test \ No newline at end of file diff --git a/examples/utest/MyTests.scala b/examples/utest/MyTests.scala deleted file mode 100644 index 75adcbecbb..0000000000 --- a/examples/utest/MyTests.scala +++ /dev/null @@ -1,14 +0,0 @@ -//> using dep "com.lihaoyi::utest::0.7.10" - -import utest._ - -object MyTests extends TestSuite { - val tests = Tests { - test("foo") { - assert(2 + 2 == 4) - } - // test("nope") { - // assert(2 + 2 == 5) - // } - } -} diff --git a/modules/docs-tests/src/test/scala/sclicheck/ExampleTests.scala b/modules/docs-tests/src/test/scala/sclicheck/ExampleTests.scala deleted file mode 100644 index 19938d2207..0000000000 --- a/modules/docs-tests/src/test/scala/sclicheck/ExampleTests.scala +++ /dev/null @@ -1,22 +0,0 @@ -package sclicheck - -class ExampleTests extends munit.FunSuite { - - val examplesDir = Option(System.getenv("SCALA_CLI_EXAMPLES")).map(os.Path(_, os.pwd)).getOrElse { - sys.error("SCALA_CLI_EXAMPLES not set") - } - - val exampleDirs = os.list(examplesDir) - .filter(!_.last.startsWith(".")) - .filter(os.isDir(_)) - - for (dir <- exampleDirs) - test(dir.last) { - val args = - if os.exists(dir / ".opts") then os.read(dir / ".opts").split("\\s+").toSeq - else Nil - os.proc(TestUtil.scalaCliPath, args, "--jvm", "temurin:17", ".") - .call(cwd = dir, stdin = os.Inherit, stdout = os.Inherit) - } - -}