Skip to content

Commit

Permalink
made Play multi-project work with new forked mode support
Browse files Browse the repository at this point in the history
  • Loading branch information
Joachim Hofer committed Dec 22, 2013
1 parent 6427f5c commit d9124cf
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 36 deletions.
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ buildInfoKeys := Seq[BuildInfoKey](resourceDirectory in Test)

buildInfoPackage := "de.johoop.jacoco4sbt.build"

test in Test <<= test in Test dependsOn publishLocal
test in Test <<= test in Test dependsOn publishLocal

parallelExecution in Test := false
2 changes: 1 addition & 1 deletion src/main/scala/de/johoop/jacoco4sbt/Instrumentation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 2 additions & 28 deletions src/test/resources/play-multi-project-jacoco/project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
)

Expand Down

0 comments on commit d9124cf

Please sign in to comment.