Skip to content

Commit

Permalink
Exclude test config in pack
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jonfox committed Nov 4, 2019
1 parent 0c63aba commit 0507f00
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/scala/xerial/sbt/pack/PackPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions src/sbt-test/sbt-pack/exclude-test-config/build.sbt
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package sample

object Client {
def main(args: Array[String]) { println("hello client") }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package sample

object Module1 {
def main(args: Array[String]) { println("hello module1") }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package sample

object Module2 {
def main(args: Array[String]) { println("hello module2") }
}
7 changes: 7 additions & 0 deletions src/sbt-test/sbt-pack/exclude-test-config/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package sample

object Server {
def main(args: Array[String]) { println("hello server") }
}
26 changes: 26 additions & 0 deletions src/sbt-test/sbt-pack/exclude-test-config/test
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0507f00

Please sign in to comment.