From 0507f00ea361dff6e12ea61460de97ce17815083 Mon Sep 17 00:00:00 2001 From: Jon Fox Date: Mon, 4 Nov 2019 16:55:24 +0000 Subject: [PATCH] Exclude test config in pack Currently when project dependencies are worked out in a multi-project build, there is no check to ensure that we are only including projects with a compile dependency, i.e. those with .dependsOn(module1) or .dependsOn(module1, "compile->...") This fixes that issue and filters out projects that don't have compile dependencies. --- .../scala/xerial/sbt/pack/PackPlugin.scala | 6 ++- .../sbt-pack/exclude-test-config/build.sbt | 43 +++++++++++++++++++ .../client/src/main/scala/Client.scala | 5 +++ .../module1/src/main/scala/Module1.scala | 5 +++ .../module2/src/main/scala/Module2.scala | 5 +++ .../exclude-test-config/project/plugins.sbt | 7 +++ .../server/src/main/scala/Server.scala | 5 +++ .../sbt-pack/exclude-test-config/test | 26 +++++++++++ 8 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 src/sbt-test/sbt-pack/exclude-test-config/build.sbt create mode 100644 src/sbt-test/sbt-pack/exclude-test-config/client/src/main/scala/Client.scala create mode 100644 src/sbt-test/sbt-pack/exclude-test-config/module1/src/main/scala/Module1.scala create mode 100644 src/sbt-test/sbt-pack/exclude-test-config/module2/src/main/scala/Module2.scala create mode 100644 src/sbt-test/sbt-pack/exclude-test-config/project/plugins.sbt create mode 100644 src/sbt-test/sbt-pack/exclude-test-config/server/src/main/scala/Server.scala create mode 100644 src/sbt-test/sbt-pack/exclude-test-config/test diff --git a/src/main/scala/xerial/sbt/pack/PackPlugin.scala b/src/main/scala/xerial/sbt/pack/PackPlugin.scala index d96a58fc..702ce756 100755 --- a/src/main/scala/xerial/sbt/pack/PackPlugin.scala +++ b/src/main/scala/xerial/sbt/pack/PackPlugin.scala @@ -414,13 +414,15 @@ object PackPlugin extends AutoPlugin with PackArchive { def transitiveDependencies(currentProject: ProjectRef): Seq[ProjectRef] = { def isExcluded(p: ProjectRef) = exclude.contains(p.project) + def isCompileConfig(cp: ClasspathDep[ProjectRef]) = cp.configuration.forall(_.contains("compile->")) + // Traverse all dependent projects val children = Project .getProject(currentProject, structure) .toSeq - .flatMap{ _.dependencies.map(_.project) } + .flatMap{ _.dependencies.filter(isCompileConfig).map(_.project) } - (currentProject +: (children flatMap (transitiveDependencies(_)))) filterNot (isExcluded) + (currentProject +: (children flatMap transitiveDependencies)) filterNot (isExcluded) } val projects: Seq[ProjectRef] = transitiveDependencies(contextProject).distinct projects.map(p => (Def.task { ((targetTask in p).value, p) }) evaluate structure.data).join diff --git a/src/sbt-test/sbt-pack/exclude-test-config/build.sbt b/src/sbt-test/sbt-pack/exclude-test-config/build.sbt new file mode 100644 index 00000000..7fdf655d --- /dev/null +++ b/src/sbt-test/sbt-pack/exclude-test-config/build.sbt @@ -0,0 +1,43 @@ +scalaVersion in ThisBuild := "2.12.6" + +val commonSettings = Seq( + scalaVersion := "2.12.6", + version := "0.1", + crossPaths := false +) + +lazy val module1 = + project + .settings(commonSettings) + .settings( + libraryDependencies ++= Seq( + "org.xerial" % "xerial-core" % "3.3.6", + "jakarta-regexp" % "jakarta-regexp" % "1.4", + "xalan" % "xalan" % "2.7.1" + ), + ) + .enablePlugins(PackPlugin) + +lazy val module2 = + project + .settings(commonSettings) + .settings( + libraryDependencies ++= Seq( + "org.xerial.snappy" % "snappy-java" % "1.1.1.6", + "org.slf4j" % "slf4j-api" % "1.7.6" + ) + ) + .enablePlugins(PackPlugin) + +lazy val client = + project + .settings(commonSettings) + .dependsOn(module1, module2 % "test->test") + .enablePlugins(PackPlugin) + +lazy val server = + project + .dependsOn(module2) + .settings(commonSettings) + .dependsOn(module1, module2 % "compile->compile;test->test") + .enablePlugins(PackPlugin) diff --git a/src/sbt-test/sbt-pack/exclude-test-config/client/src/main/scala/Client.scala b/src/sbt-test/sbt-pack/exclude-test-config/client/src/main/scala/Client.scala new file mode 100644 index 00000000..4c7db351 --- /dev/null +++ b/src/sbt-test/sbt-pack/exclude-test-config/client/src/main/scala/Client.scala @@ -0,0 +1,5 @@ +package sample + +object Client { + def main(args: Array[String]) { println("hello client") } +} diff --git a/src/sbt-test/sbt-pack/exclude-test-config/module1/src/main/scala/Module1.scala b/src/sbt-test/sbt-pack/exclude-test-config/module1/src/main/scala/Module1.scala new file mode 100644 index 00000000..b60055ca --- /dev/null +++ b/src/sbt-test/sbt-pack/exclude-test-config/module1/src/main/scala/Module1.scala @@ -0,0 +1,5 @@ +package sample + +object Module1 { + def main(args: Array[String]) { println("hello module1") } +} diff --git a/src/sbt-test/sbt-pack/exclude-test-config/module2/src/main/scala/Module2.scala b/src/sbt-test/sbt-pack/exclude-test-config/module2/src/main/scala/Module2.scala new file mode 100644 index 00000000..0df4e313 --- /dev/null +++ b/src/sbt-test/sbt-pack/exclude-test-config/module2/src/main/scala/Module2.scala @@ -0,0 +1,5 @@ +package sample + +object Module2 { + def main(args: Array[String]) { println("hello module2") } +} diff --git a/src/sbt-test/sbt-pack/exclude-test-config/project/plugins.sbt b/src/sbt-test/sbt-pack/exclude-test-config/project/plugins.sbt new file mode 100644 index 00000000..df0fbb35 --- /dev/null +++ b/src/sbt-test/sbt-pack/exclude-test-config/project/plugins.sbt @@ -0,0 +1,7 @@ +{ + val pluginVersion = System.getProperty("plugin.version") + if(pluginVersion == null) + throw new RuntimeException("""|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) + else addSbtPlugin("org.xerial.sbt" % "sbt-pack" % pluginVersion) +} diff --git a/src/sbt-test/sbt-pack/exclude-test-config/server/src/main/scala/Server.scala b/src/sbt-test/sbt-pack/exclude-test-config/server/src/main/scala/Server.scala new file mode 100644 index 00000000..8f8231cf --- /dev/null +++ b/src/sbt-test/sbt-pack/exclude-test-config/server/src/main/scala/Server.scala @@ -0,0 +1,5 @@ +package sample + +object Server { + def main(args: Array[String]) { println("hello server") } +} diff --git a/src/sbt-test/sbt-pack/exclude-test-config/test b/src/sbt-test/sbt-pack/exclude-test-config/test new file mode 100644 index 00000000..9c6d05c2 --- /dev/null +++ b/src/sbt-test/sbt-pack/exclude-test-config/test @@ -0,0 +1,26 @@ +#exec commands are system dependent and have been tested in a Linux environment +> 'set version := "0.1"' + +>server/pack +$exists server/target/pack/lib/jakarta-regexp-1.4.jar +$exists server/target/pack/lib/serializer-2.7.1.jar +$exists server/target/pack/lib/xalan-2.7.1.jar +$exists server/target/pack/lib/xerial-core-3.3.6.jar +$exists server/target/pack/lib/xml-apis-1.3.04.jar +$exists server/target/pack/lib/snappy-java-1.1.1.6.jar +$exists server/target/pack/lib/slf4j-api-1.7.6.jar +$exists server/target/pack/lib/module1-0.1.jar +$exists server/target/pack/lib/module2-0.1.jar +$exists server/target/pack/lib/server-0.1.jar + +>client/pack +$exists client/target/pack/lib/jakarta-regexp-1.4.jar +$exists client/target/pack/lib/serializer-2.7.1.jar +$exists client/target/pack/lib/xalan-2.7.1.jar +$exists client/target/pack/lib/xerial-core-3.3.6.jar +$exists client/target/pack/lib/xml-apis-1.3.04.jar +$absent client/target/pack/lib/snappy-java-1.1.1.6.jar +$absent client/target/pack/lib/slf4j-api-1.7.6.jar +$exists client/target/pack/lib/module1-0.1.jar +$absent client/target/pack/lib/module2-0.1.jar +$exists client/target/pack/lib/client-0.1.jar