mirror of https://github.com/sbt/sbt.git
detect packaging for make-pom
This commit is contained in:
parent
1f17a80bbf
commit
f6e8adfff5
|
|
@ -343,4 +343,10 @@ private object IvySbt
|
|||
case dmd: DefaultModuleDescriptor => dmd
|
||||
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) =>
|
||||
addLateDependencies(ivy, md, default, extraDependencies)
|
||||
val pomModule = keepConfigurations(md, configurations)
|
||||
(new MakePom).write(ivy, pomModule, extra, output)
|
||||
(new MakePom).write(ivy, md, configurations, extra, output)
|
||||
module.logger.info("Wrote " + output.getAbsolutePath)
|
||||
}
|
||||
}
|
||||
|
|
@ -61,32 +60,6 @@ object IvyActions
|
|||
parser.setMd(module)
|
||||
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)
|
||||
{
|
||||
|
|
@ -95,7 +68,7 @@ object IvyActions
|
|||
resolve(quiet)(ivy, md, default) // todo: set download = false for resolve
|
||||
val revID = md.getModuleRevisionId
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
@ -108,7 +81,7 @@ object IvyActions
|
|||
srcArtifactPatterns.foreach(pattern => patterns.add(pattern))
|
||||
val options = (new PublishOptions).setOverwrite(true)
|
||||
deliveredIvyPattern.foreach(options.setSrcIvyPattern)
|
||||
options.setConfs(getConfigurations(md, configurations))
|
||||
options.setConfs(IvySbt.getConfigurations(md, configurations))
|
||||
ivy.publish(revID, patterns, resolverName, options)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@ import plugins.resolver.{ChainResolver, DependencyResolver, IBiblioResolver}
|
|||
class MakePom
|
||||
{
|
||||
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(xmlString: String, output: File)
|
||||
{
|
||||
|
|
@ -36,12 +37,12 @@ class MakePom
|
|||
}
|
||||
|
||||
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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
{ makeModuleID(module) }
|
||||
{ extra }
|
||||
{ makeDependencies(module) }
|
||||
{ makeDependencies(module, configurations) }
|
||||
{ makeRepositories(ivy.getSettings) }
|
||||
</project>)
|
||||
|
||||
|
|
@ -51,7 +52,7 @@ class MakePom
|
|||
val a: NodeSeq =
|
||||
(<groupId>{ mrid.getOrganisation }</groupId>
|
||||
<artifactId>{ mrid.getName }</artifactId>
|
||||
<packaging>{ packaging(mrid) }</packaging>)
|
||||
<packaging>{ packaging(module) }</packaging>)
|
||||
val b: NodeSeq =
|
||||
( (description(module.getDescription) ++
|
||||
homePage(module.getHomePage) ++
|
||||
|
|
@ -70,11 +71,19 @@ class MakePom
|
|||
</license>
|
||||
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 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
|
||||
else
|
||||
<dependencies>
|
||||
|
|
@ -147,4 +156,21 @@ class MakePom
|
|||
<name>{name}</name>
|
||||
<url>{root}</url>
|
||||
</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
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue