Port dependency-management/pom-packaging

This commit is contained in:
Eugene Yokota 2016-03-29 00:51:11 -04:00
parent 23eb8c4ee2
commit 1e2b2ec594
3 changed files with 36 additions and 26 deletions

View File

@ -0,0 +1,35 @@
import sbt.Def.Initialize
lazy val checkPom = taskKey[Unit]("")
lazy val root = (project in file(".")).
settings(
checkPom in ThisBuild := checkPomTask.value
)
lazy val subJar = (project in file("subJar"))
lazy val subWar = (project in file("subWar")).
settings(
warArtifact
)
lazy val subParent = (project in file("subParent")).
settings(
publishArtifact in Compile := false
)
def art(p: ProjectReference) = makePom in p
def checkPomTask: Initialize[Task[Unit]] =
(art(subJar), art(subWar), art(subParent)) map { (jar, war, pom) =>
checkPackaging(jar, "jar")
checkPackaging(war, "war")
checkPackaging(pom, "pom")
}
def checkPackaging(pom: File, expected: String) =
{
val packaging = (xml.XML.loadFile(pom) \\ "packaging").text
if(packaging != expected) sys.error("Incorrect packaging for '" + pom + "'. Expected '" + expected + "', but got '" + packaging + "'")
}
def warArtifact = artifact in (Compile, packageBin) ~= { _.copy(`type` = "war", extension = "war") }

View File

@ -1,25 +0,0 @@
import sbt._
import Keys._
import Import._
object PomTest extends Build
{
override def settings = super.settings :+ (TaskKey[Unit]("check-pom") <<= checkPom)
lazy val subJar = Project("sub-jar", file("subJar"))
lazy val subWar = Project("sub-war", file("subWar")) settings( warArtifact)
lazy val subParent = Project("sub-parent", file("subParent")) settings( publishArtifact in Compile := false )
def art(p: ProjectReference) = makePom in p
def checkPom = (art(subJar), art(subWar), art(subParent)) map { (jar, war, pom) =>
checkPackaging(jar, "jar")
checkPackaging(war, "war")
checkPackaging(pom, "pom")
}
def checkPackaging(pom: File, expected: String) =
{
val packaging = (xml.XML.loadFile(pom) \\ "packaging").text
if(packaging != expected) sys.error("Incorrect packaging for '" + pom + "'. Expected '" + expected + "', but got '" + packaging + "'")
}
def warArtifact = artifact in (Compile, packageBin) ~= { _.copy(`type` = "war", extension = "war") }
}

View File

@ -1 +1 @@
> check-pom
> checkPom