Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maven test jar #11

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions src/main/scala/com/typesafe/sbt/pom/MavenHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ object MavenHelper {
getAdditionalSourcesFromPlugin(pom).filter(_.contains("test")).map(x => base / x)
},

publishArtifact in (Test, packageBin) <<= effectivePom apply { pom =>
isPublishingTestArtifactRequired(pom)

},

libraryDependencies <++= fromPom(getDependencies),
resolvers <++= fromPom(getResolvers),
// TODO - split into Compile/Test/Runtime/Console
Expand Down Expand Up @@ -126,6 +131,21 @@ object MavenHelper {
srcs <- Option(dom getChild "sources")
} yield srcs.getChildren map (_.getValue)

def getJarPlugin(pom: PomModel): Seq[PomPlugin] = {
pom.getBuild.getPlugins.asScala filter { plugin =>
(plugin.getGroupId == "org.apache.maven.plugins") &&
(plugin.getArtifactId == "maven-jar-plugin")
}
}

def isPublishingTestArtifactRequired(pom: PomModel): Boolean = {
val t = for {
plugin <- getJarPlugin(pom)
testJar = plugin.getExecutions.asScala.exists(_.getGoals.asScala.exists(_.contains("test-jar")))
} yield testJar
t.exists(_ == true)
}

def domOrNone(config: java.lang.Object): Option[org.codehaus.plexus.util.xml.Xpp3Dom] =
if(config.isInstanceOf[org.codehaus.plexus.util.xml.Xpp3Dom]) {
Some(config.asInstanceOf[org.codehaus.plexus.util.xml.Xpp3Dom])
Expand All @@ -136,6 +156,7 @@ object MavenHelper {
dom <- domOrNone(config)
child <- Option(dom.getChild(elem))
} yield child.getValue

def getScalaVersionFromPlugins(pom: PomModel): Option[String] =
for {
plugin <- getScalaPlugin(pom)
Expand Down Expand Up @@ -174,11 +195,18 @@ object MavenHelper {
for {
scope <- Option(dep.getScope)
} yield scope


val typeString: Option[String] =
for {
typeStr <- Option(dep.getType)
if typeStr == "test-jar"
} yield typeStr

def fixScope(dep: ModuleID): ModuleID =
scopeString match {
case Some(scope) => dep % scope
case None => dep
(scopeString, typeString) match {
case (Some(scope), None) => dep % scope
case (Some(scope), Some("test-jar")) => dep % "test->test"
case _ => dep
}

def addExclusions(mod: ModuleID): ModuleID = {
Expand Down Expand Up @@ -285,4 +313,4 @@ object MavenHelper {

// TODO - compiler plugins...

}
}