mirror of https://github.com/sbt/sbt.git
detect packaging for make-pom
This commit is contained in:
parent
5909728299
commit
9720566f84
|
|
@ -343,4 +343,10 @@ private object IvySbt
|
||||||
case dmd: DefaultModuleDescriptor => dmd
|
case dmd: DefaultModuleDescriptor => dmd
|
||||||
case _ => error("Unknown ModuleDescriptor type.")
|
case _ => error("Unknown ModuleDescriptor type.")
|
||||||
}
|
}
|
||||||
|
def getConfigurations(module: ModuleDescriptor, configurations: Option[Iterable[Configuration]]) =
|
||||||
|
configurations match
|
||||||
|
{
|
||||||
|
case Some(confs) => confs.map(_.name).toList.toArray
|
||||||
|
case None => module.getPublicConfigurationsNames
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,8 +49,7 @@ object IvyActions
|
||||||
{
|
{
|
||||||
module.withModule { (ivy, md, default) =>
|
module.withModule { (ivy, md, default) =>
|
||||||
addLateDependencies(ivy, md, default, extraDependencies)
|
addLateDependencies(ivy, md, default, extraDependencies)
|
||||||
val pomModule = keepConfigurations(md, configurations)
|
(new MakePom).write(ivy, md, configurations, extra, output)
|
||||||
(new MakePom).write(ivy, pomModule, extra, output)
|
|
||||||
module.logger.info("Wrote " + output.getAbsolutePath)
|
module.logger.info("Wrote " + output.getAbsolutePath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -61,32 +60,6 @@ object IvyActions
|
||||||
parser.setMd(module)
|
parser.setMd(module)
|
||||||
IvySbt.addDependencies(module, extraDependencies, parser)
|
IvySbt.addDependencies(module, extraDependencies, parser)
|
||||||
}
|
}
|
||||||
private def getConfigurations(module: ModuleDescriptor, configurations: Option[Iterable[Configuration]]) =
|
|
||||||
configurations match
|
|
||||||
{
|
|
||||||
case Some(confs) => confs.map(_.name).toList.toArray
|
|
||||||
case None => module.getPublicConfigurationsNames
|
|
||||||
}
|
|
||||||
/** Retain dependencies only with the configurations given, or all public configurations of `module` if `configurations` is None.
|
|
||||||
* This currently only preserves the information required by makePom*/
|
|
||||||
private def keepConfigurations(module: ModuleDescriptor, configurations: Option[Iterable[Configuration]]): ModuleDescriptor =
|
|
||||||
{
|
|
||||||
val keepConfigurations = getConfigurations(module, configurations)
|
|
||||||
val keepSet = Set(keepConfigurations.toSeq : _*)
|
|
||||||
def translate(dependency: DependencyDescriptor) =
|
|
||||||
{
|
|
||||||
val keep = dependency.getModuleConfigurations.filter(keepSet.contains)
|
|
||||||
if(keep.isEmpty)
|
|
||||||
None
|
|
||||||
else // TODO: translate the dependency to contain only configurations to keep
|
|
||||||
Some(dependency)
|
|
||||||
}
|
|
||||||
val newModule = new DefaultModuleDescriptor(module.getModuleRevisionId, "", null)
|
|
||||||
newModule.setHomePage(module.getHomePage)
|
|
||||||
for(dependency <- module.getDependencies; translated <- translate(dependency))
|
|
||||||
newModule.addDependency(translated)
|
|
||||||
newModule
|
|
||||||
}
|
|
||||||
|
|
||||||
def deliver(module: IvySbt#Module, status: String, deliverIvyPattern: String, extraDependencies: Iterable[ModuleID], configurations: Option[Iterable[Configuration]], quiet: Boolean)
|
def deliver(module: IvySbt#Module, status: String, deliverIvyPattern: String, extraDependencies: Iterable[ModuleID], configurations: Option[Iterable[Configuration]], quiet: Boolean)
|
||||||
{
|
{
|
||||||
|
|
@ -95,7 +68,7 @@ object IvyActions
|
||||||
resolve(quiet)(ivy, md, default) // todo: set download = false for resolve
|
resolve(quiet)(ivy, md, default) // todo: set download = false for resolve
|
||||||
val revID = md.getModuleRevisionId
|
val revID = md.getModuleRevisionId
|
||||||
val options = DeliverOptions.newInstance(ivy.getSettings).setStatus(status)
|
val options = DeliverOptions.newInstance(ivy.getSettings).setStatus(status)
|
||||||
options.setConfs(getConfigurations(md, configurations))
|
options.setConfs(IvySbt.getConfigurations(md, configurations))
|
||||||
ivy.deliver(revID, revID.getRevision, deliverIvyPattern, options)
|
ivy.deliver(revID, revID.getRevision, deliverIvyPattern, options)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -108,7 +81,7 @@ object IvyActions
|
||||||
srcArtifactPatterns.foreach(pattern => patterns.add(pattern))
|
srcArtifactPatterns.foreach(pattern => patterns.add(pattern))
|
||||||
val options = (new PublishOptions).setOverwrite(true)
|
val options = (new PublishOptions).setOverwrite(true)
|
||||||
deliveredIvyPattern.foreach(options.setSrcIvyPattern)
|
deliveredIvyPattern.foreach(options.setSrcIvyPattern)
|
||||||
options.setConfs(getConfigurations(md, configurations))
|
options.setConfs(IvySbt.getConfigurations(md, configurations))
|
||||||
ivy.publish(revID, patterns, resolverName, options)
|
ivy.publish(revID, patterns, resolverName, options)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,8 @@ import plugins.resolver.{ChainResolver, DependencyResolver, IBiblioResolver}
|
||||||
class MakePom
|
class MakePom
|
||||||
{
|
{
|
||||||
def encoding = "UTF-8"
|
def encoding = "UTF-8"
|
||||||
def write(ivy: Ivy, module: ModuleDescriptor, extra: NodeSeq, output: File): Unit = write(toPom(ivy, module, extra), output)
|
def write(ivy: Ivy, module: ModuleDescriptor, configurations: Option[Iterable[Configuration]], extra: NodeSeq, output: File): Unit =
|
||||||
|
write(toPom(ivy, module, configurations, extra), output)
|
||||||
def write(node: Node, output: File): Unit = write(toString(node), output)
|
def write(node: Node, output: File): Unit = write(toString(node), output)
|
||||||
def write(xmlString: String, output: File)
|
def write(xmlString: String, output: File)
|
||||||
{
|
{
|
||||||
|
|
@ -36,12 +37,12 @@ class MakePom
|
||||||
}
|
}
|
||||||
|
|
||||||
def toString(node: Node): String = new PrettyPrinter(1000, 4).format(node)
|
def toString(node: Node): String = new PrettyPrinter(1000, 4).format(node)
|
||||||
def toPom(ivy: Ivy, module: ModuleDescriptor, extra: NodeSeq): Node =
|
def toPom(ivy: Ivy, module: ModuleDescriptor, configurations: Option[Iterable[Configuration]], extra: NodeSeq): Node =
|
||||||
(<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
(<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
{ makeModuleID(module) }
|
{ makeModuleID(module) }
|
||||||
{ extra }
|
{ extra }
|
||||||
{ makeDependencies(module) }
|
{ makeDependencies(module, configurations) }
|
||||||
{ makeRepositories(ivy.getSettings) }
|
{ makeRepositories(ivy.getSettings) }
|
||||||
</project>)
|
</project>)
|
||||||
|
|
||||||
|
|
@ -51,7 +52,7 @@ class MakePom
|
||||||
val a: NodeSeq =
|
val a: NodeSeq =
|
||||||
(<groupId>{ mrid.getOrganisation }</groupId>
|
(<groupId>{ mrid.getOrganisation }</groupId>
|
||||||
<artifactId>{ mrid.getName }</artifactId>
|
<artifactId>{ mrid.getName }</artifactId>
|
||||||
<packaging>{ packaging(mrid) }</packaging>)
|
<packaging>{ packaging(module) }</packaging>)
|
||||||
val b: NodeSeq =
|
val b: NodeSeq =
|
||||||
( (description(module.getDescription) ++
|
( (description(module.getDescription) ++
|
||||||
homePage(module.getHomePage) ++
|
homePage(module.getHomePage) ++
|
||||||
|
|
@ -70,11 +71,19 @@ class MakePom
|
||||||
</license>
|
</license>
|
||||||
def homePage(homePage: String) = if(homePage eq null) NodeSeq.Empty else <url>{homePage}</url>
|
def homePage(homePage: String) = if(homePage eq null) NodeSeq.Empty else <url>{homePage}</url>
|
||||||
def revision(version: String) = if(version ne null) <version>{version}</version> else NodeSeq.Empty
|
def revision(version: String) = if(version ne null) <version>{version}</version> else NodeSeq.Empty
|
||||||
def packaging(module: ModuleRevisionId) = "jar"//module.getDefaultArtifact.getExt
|
def packaging(module: ModuleDescriptor) =
|
||||||
|
module.getAllArtifacts match
|
||||||
|
{
|
||||||
|
case Array() => "pom"
|
||||||
|
case Array(x) => x.getType
|
||||||
|
case xs =>
|
||||||
|
val notpom = xs.filter(_.getType != "pom")
|
||||||
|
if(notpom.isEmpty) "pom" else notpom(0).getType
|
||||||
|
}
|
||||||
|
|
||||||
def makeDependencies(module: ModuleDescriptor): NodeSeq =
|
def makeDependencies(module: ModuleDescriptor, configurations: Option[Iterable[Configuration]]): NodeSeq =
|
||||||
{
|
{
|
||||||
val dependencies = module.getDependencies
|
val dependencies = depsInConfs(module, configurations)
|
||||||
if(dependencies.isEmpty) NodeSeq.Empty
|
if(dependencies.isEmpty) NodeSeq.Empty
|
||||||
else
|
else
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
@ -147,4 +156,21 @@ class MakePom
|
||||||
<name>{name}</name>
|
<name>{name}</name>
|
||||||
<url>{root}</url>
|
<url>{root}</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
|
/** Retain dependencies only with the configurations given, or all public configurations of `module` if `configurations` is None.
|
||||||
|
* This currently only preserves the information required by makePom*/
|
||||||
|
private def depsInConfs(module: ModuleDescriptor, configurations: Option[Iterable[Configuration]]): Seq[DependencyDescriptor] =
|
||||||
|
{
|
||||||
|
val keepConfigurations = IvySbt.getConfigurations(module, configurations)
|
||||||
|
val keepSet = Set(keepConfigurations.toSeq : _*)
|
||||||
|
def translate(dependency: DependencyDescriptor) =
|
||||||
|
{
|
||||||
|
val keep = dependency.getModuleConfigurations.filter(keepSet.contains)
|
||||||
|
if(keep.isEmpty)
|
||||||
|
None
|
||||||
|
else // TODO: translate the dependency to contain only configurations to keep
|
||||||
|
Some(dependency)
|
||||||
|
}
|
||||||
|
module.getDependencies flatMap translate
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6,7 +6,7 @@ import sbt._
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
abstract class SbtProject(info: ProjectInfo) extends DefaultProject(info) with test.SbtScripted with posterous.Publish with Sxr
|
abstract class SbtProject(info: ProjectInfo) extends DefaultProject(info) with test.SbtScripted with posterous.Publish// with Sxr
|
||||||
{
|
{
|
||||||
/* Additional resources to include in the produced jar.*/
|
/* Additional resources to include in the produced jar.*/
|
||||||
def extraResources = descendents(info.projectPath / "licenses", "*") +++ "LICENSE" +++ "NOTICE"
|
def extraResources = descendents(info.projectPath / "licenses", "*") +++ "LICENSE" +++ "NOTICE"
|
||||||
|
|
@ -46,6 +46,7 @@ abstract class SbtProject(info: ProjectInfo) extends DefaultProject(info) with t
|
||||||
|
|
||||||
val testInterface = "org.scala-tools.testing" % "test-interface" % "0.5"
|
val testInterface = "org.scala-tools.testing" % "test-interface" % "0.5"
|
||||||
|
|
||||||
|
def deepSources = Path.finder { topologicalSort.flatMap { case p: ScalaPaths => p.mainSources.getFiles } }
|
||||||
lazy val sbtDoc = scaladocTask("sbt", deepSources, docPath, docClasspath, documentOptions)
|
lazy val sbtDoc = scaladocTask("sbt", deepSources, docPath, docClasspath, documentOptions)
|
||||||
|
|
||||||
/* For generating JettyRun for Jetty 6 and 7. The only difference is the imports, but the file has to be compiled against each set of imports. */
|
/* For generating JettyRun for Jetty 6 and 7. The only difference is the imports, but the file has to be compiled against each set of imports. */
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
project.name=Pom Test
|
||||||
|
project.version=1.0
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
import sbt._
|
||||||
|
|
||||||
|
class PomTest(info: ProjectInfo) extends ParentProject(info) with BasicManagedProject
|
||||||
|
{
|
||||||
|
val subJar = project("subJar", "Sub Jar", new DefaultProject(_))
|
||||||
|
val subWar = project("subWar", "Sub War", new DefaultWebProject(_))
|
||||||
|
val subParent = project("subParent", "Sub Parent", i => new ParentProject(i) with BasicManagedProject)
|
||||||
|
|
||||||
|
def readPom(path: Path) = xml.XML.loadFile(path.asFile)
|
||||||
|
lazy val checkPom = task {
|
||||||
|
checkPackaging(subJar.pomPath, "jar") orElse
|
||||||
|
checkPackaging(subWar.pomPath, "war") orElse
|
||||||
|
checkPackaging(subParent.pomPath, "pom") orElse
|
||||||
|
checkPackaging(pomPath, "pom")
|
||||||
|
}
|
||||||
|
def checkPackaging(pom: Path, expected: String) =
|
||||||
|
{
|
||||||
|
val packaging = (readPom(pom) \\ "packaging").text
|
||||||
|
if(packaging == expected) None else Some("Incorrect packaging for '" + pom + "'. Expected '" + expected + "', but got '" + packaging + "'")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
-> check-pom
|
||||||
|
> package
|
||||||
|
> make-pom
|
||||||
|
> check-pom
|
||||||
Loading…
Reference in New Issue