From d9124cf3b022c6142bb44273652d115296acf9ca Mon Sep 17 00:00:00 2001 From: Joachim Hofer Date: Sun, 22 Dec 2013 18:59:24 +0100 Subject: [PATCH] made Play multi-project work with new forked mode support --- build.sbt | 4 ++- .../johoop/jacoco4sbt/Instrumentation.scala | 2 +- .../modules/common/test/ApplicationTest.java | 7 +---- .../project/Build.scala | 30 ++----------------- 4 files changed, 7 insertions(+), 36 deletions(-) diff --git a/build.sbt b/build.sbt index c47a57f5..d37a335a 100755 --- a/build.sbt +++ b/build.sbt @@ -26,4 +26,6 @@ buildInfoKeys := Seq[BuildInfoKey](resourceDirectory in Test) buildInfoPackage := "de.johoop.jacoco4sbt.build" -test in Test <<= test in Test dependsOn publishLocal \ No newline at end of file +test in Test <<= test in Test dependsOn publishLocal + +parallelExecution in Test := false diff --git a/src/main/scala/de/johoop/jacoco4sbt/Instrumentation.scala b/src/main/scala/de/johoop/jacoco4sbt/Instrumentation.scala index cb3b454a..f0713d1b 100644 --- a/src/main/scala/de/johoop/jacoco4sbt/Instrumentation.scala +++ b/src/main/scala/de/johoop/jacoco4sbt/Instrumentation.scala @@ -31,7 +31,7 @@ trait Instrumentation extends JaCoCoRuntime { val tmp = IO.temporaryDirectory val jacocoAgent = agentJars flatMap (IO.unzip(_, tmp, (_: String) endsWith ".jar")) map Attributed.blank - streams.log info s"Found jacoco agent: $jacocoAgent" + streams.log debug s"Found jacoco agent: $jacocoAgent" (jacocoAgent, new Instrumenter(new OfflineInstrumentationAccessGenerator)) } else { diff --git a/src/test/resources/play-multi-project-jacoco/modules/common/test/ApplicationTest.java b/src/test/resources/play-multi-project-jacoco/modules/common/test/ApplicationTest.java index cae9e6da..96de4c7c 100644 --- a/src/test/resources/play-multi-project-jacoco/modules/common/test/ApplicationTest.java +++ b/src/test/resources/play-multi-project-jacoco/modules/common/test/ApplicationTest.java @@ -25,13 +25,8 @@ public class ApplicationTest { public static File relativeToBaseDir(String path) { - String baseDir = System.getProperty("play.base.dir"); - if (baseDir == null) { - throw new NullPointerException("The play.base.dir property must be set so that relative paths can be resolved."); - } - System.out.println("BASE DIRECTORY: " + baseDir); System.out.println("Absolute current working directory path: " + new File(".").getAbsolutePath()); - return new File(baseDir, path); + return new File(new File("."), path); } @Test diff --git a/src/test/resources/play-multi-project-jacoco/project/Build.scala b/src/test/resources/play-multi-project-jacoco/project/Build.scala index 45827088..69d4b8ff 100644 --- a/src/test/resources/play-multi-project-jacoco/project/Build.scala +++ b/src/test/resources/play-multi-project-jacoco/project/Build.scala @@ -12,29 +12,8 @@ object ApplicationBuild extends Build { // So we can get code coverage lazy val jacocoSettings = Seq( parallelExecution in jacoco.Config := false, - jacoco.excludes in jacoco.Config := Seq("Routes*","*Reverse*","*anonfun*")//, - - // Workaround -// Keys.fork in jacoco.Config := false - - // Workaround to run jacoco in current working directory -// testGrouping in jacoco.Config := { -// val original: Seq[Tests.Group] = (testGrouping in jacoco.Config).value -// -// original.map { group => -// val forkOptions = ForkOptions( -// bootJars = Nil, -// javaHome = javaHome.value, -// connectInput = connectInput.value, -// outputStrategy = outputStrategy.value, -// runJVMOptions = javaOptions.value, -// workingDirectory = Some(baseDirectory.value), // Run jacoco in current subproject directory -// envVars = envVars.value -// ) -// -// group.copy(runPolicy = Tests.SubProcess(forkOptions)) -// } -// } + jacoco.excludes in jacoco.Config := Seq("Routes*","*Reverse*","*anonfun*"), + Keys.fork in jacoco.Config := true ) lazy val s = playJavaSettings ++ Seq(jacoco.settings:_*) ++ jacocoSettings @@ -46,11 +25,6 @@ object ApplicationBuild extends Build { val common = play.Project( "common", appVersion, commonDependencies, settings = s, path = file("modules/common") ).settings( - javaOptions in Test += s"-Dplay.base.dir=${baseDirectory.value}", - testOptions in jacoco.Config ++= Seq( - Tests.Setup { () => System.setProperty("play.base.dir", baseDirectory.value.toString) }, - Tests.Cleanup { () => System.clearProperty("play.base.dir") } - ), concurrentRestrictions in Global += Tags.limit(Tags.Test, 1) )