diff --git a/bin/scalafmt b/bin/scalafmt index 62416bf44..1b0cf1421 100755 Binary files a/bin/scalafmt and b/bin/scalafmt differ diff --git a/modules/java-debug b/modules/java-debug index 6204e0a72..23df7eb04 160000 --- a/modules/java-debug +++ b/modules/java-debug @@ -1 +1 @@ -Subproject commit 6204e0a72c316368eb5a27fe9b040a9288808190 +Subproject commit 23df7eb041adbcfbde6a4b4f9118605c1bae9d16 diff --git a/modules/sbt-plugin/src/main/scala/ch/epfl/scala/debugadapter/sbtplugin/DebugAdapterPlugin.scala b/modules/sbt-plugin/src/main/scala/ch/epfl/scala/debugadapter/sbtplugin/DebugAdapterPlugin.scala index 1fc2b4a27..a3fa51ee4 100644 --- a/modules/sbt-plugin/src/main/scala/ch/epfl/scala/debugadapter/sbtplugin/DebugAdapterPlugin.scala +++ b/modules/sbt-plugin/src/main/scala/ch/epfl/scala/debugadapter/sbtplugin/DebugAdapterPlugin.scala @@ -100,7 +100,12 @@ object DebugAdapterPlugin extends sbt.AutoPlugin { def runSettings: Seq[Def.Setting[_]] = Seq( startMainClassDebugSession := mainClassSessionTask.evaluated, startRemoteDebugSession := remoteSessionTask.evaluated, - stopDebugSession := stopSessionTask.value + stopDebugSession := stopSessionTask.value, + Keys.compile / Keys.javacOptions := { + val jo = (Keys.compile / Keys.javacOptions).value + if (jo.exists(_.startsWith("-g"))) jo + else jo :+ "-g" + } ) /** diff --git a/modules/sbt-plugin/src/sbt-test/debug-session/debug-java/build.sbt b/modules/sbt-plugin/src/sbt-test/debug-session/debug-java/build.sbt new file mode 100644 index 000000000..5f66dfef2 --- /dev/null +++ b/modules/sbt-plugin/src/sbt-test/debug-session/debug-java/build.sbt @@ -0,0 +1,37 @@ +import ch.epfl.scala.debugadapter.testfmk._ + +val checkDebugJava = inputKey[Unit]("Check that the -g option has been added") + +def checkDebugJavaTask = Def.inputTask { + val uri = (Compile / startMainClassDebugSession).evaluated + val source = (Compile / sources).value.head.toPath + implicit val context: TestingContext = TestingContext(source, "3.3.0") + DebugTest.check(uri)(Breakpoint(source, 6), Evaluation.success("x", 1)) +} +def checkDebugJavaWithGSpecializedTask = Def.inputTask { + val uri = (Compile / startMainClassDebugSession).evaluated + val source = (Compile / sources).value.head.toPath + implicit val context: TestingContext = TestingContext(source, "3.3.0") + DebugTest.check(uri)(Breakpoint(source, 6), Evaluation.failed("x")) +} + +lazy val debugJavaWithG = + project + .in(file("./withG")) + .settings( + javacOptions += "-g", + checkDebugJava := checkDebugJavaTask.evaluated + ) + +lazy val debugJavaWithoutG = + project + .in(file("./withoutG")) + .settings(checkDebugJava := checkDebugJavaTask.evaluated) + +lazy val debugJavaWithGSpecialized = + project + .in(file("./withGSpecialized")) + .settings( + javacOptions += "-g:lines,source", + checkDebugJava := checkDebugJavaWithGSpecializedTask.evaluated + ) diff --git a/modules/sbt-plugin/src/sbt-test/debug-session/debug-java/project/plugins.sbt b/modules/sbt-plugin/src/sbt-test/debug-session/debug-java/project/plugins.sbt new file mode 100644 index 000000000..1d687de18 --- /dev/null +++ b/modules/sbt-plugin/src/sbt-test/debug-session/debug-java/project/plugins.sbt @@ -0,0 +1,12 @@ +val pluginVersion = sys.props + .get("plugin.version") + .getOrElse { + sys.error( + """|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D. + |""".stripMargin + ) + } + +addSbtPlugin("ch.epfl.scala" % "sbt-debug-adapter" % pluginVersion) +libraryDependencies += "ch.epfl.scala" %% "scala-debug-adapter-test" % pluginVersion diff --git a/modules/sbt-plugin/src/sbt-test/debug-session/debug-java/project/project/plugins.sbt b/modules/sbt-plugin/src/sbt-test/debug-session/debug-java/project/project/plugins.sbt new file mode 100644 index 000000000..2acfad3d4 --- /dev/null +++ b/modules/sbt-plugin/src/sbt-test/debug-session/debug-java/project/project/plugins.sbt @@ -0,0 +1,2 @@ +// required for adopt@1.8 +addSbtPlugin("org.scala-debugger" % "sbt-jdi-tools" % "1.1.1") diff --git a/modules/sbt-plugin/src/sbt-test/debug-session/debug-java/test b/modules/sbt-plugin/src/sbt-test/debug-session/debug-java/test new file mode 100644 index 000000000..3d2b2bc5e --- /dev/null +++ b/modules/sbt-plugin/src/sbt-test/debug-session/debug-java/test @@ -0,0 +1,3 @@ +> 'debugJavaWithG / checkDebugJava {"class":"example.Main","arguments":[],"jvmOptions":[]}' +> 'debugJavaWithoutG / checkDebugJava {"class":"example.Main","arguments":[],"jvmOptions":[]}' +> 'debugJavaWithGSpecialized / checkDebugJava {"class":"example.Main","arguments":[],"jvmOptions":[]}' diff --git a/modules/sbt-plugin/src/sbt-test/debug-session/debug-java/withG/src/main/java/example/Main.java b/modules/sbt-plugin/src/sbt-test/debug-session/debug-java/withG/src/main/java/example/Main.java new file mode 100644 index 000000000..b93412dd1 --- /dev/null +++ b/modules/sbt-plugin/src/sbt-test/debug-session/debug-java/withG/src/main/java/example/Main.java @@ -0,0 +1,8 @@ +package example; + +public class Main { + public static void main(String[] args) { + int x = 1; + System.out.println("Hello, world!"); + } +} diff --git a/modules/sbt-plugin/src/sbt-test/debug-session/debug-java/withGSpecialized/src/main/java/example/Main.java b/modules/sbt-plugin/src/sbt-test/debug-session/debug-java/withGSpecialized/src/main/java/example/Main.java new file mode 100644 index 000000000..b93412dd1 --- /dev/null +++ b/modules/sbt-plugin/src/sbt-test/debug-session/debug-java/withGSpecialized/src/main/java/example/Main.java @@ -0,0 +1,8 @@ +package example; + +public class Main { + public static void main(String[] args) { + int x = 1; + System.out.println("Hello, world!"); + } +} diff --git a/modules/sbt-plugin/src/sbt-test/debug-session/debug-java/withoutG/src/main/java/example/Main.java b/modules/sbt-plugin/src/sbt-test/debug-session/debug-java/withoutG/src/main/java/example/Main.java new file mode 100644 index 000000000..b93412dd1 --- /dev/null +++ b/modules/sbt-plugin/src/sbt-test/debug-session/debug-java/withoutG/src/main/java/example/Main.java @@ -0,0 +1,8 @@ +package example; + +public class Main { + public static void main(String[] args) { + int x = 1; + System.out.println("Hello, world!"); + } +}