mirror of https://github.com/sbt/sbt.git
* Added pomRepositoryFilter(repo: MavenRepository): Boolean that excludes local repositories by default
* Added pomPostProcess(pom: Node): Node to make advanced manipulation of the default pom easier (pomExtra covers basic cases)
This commit is contained in:
parent
7eb889f393
commit
262ffbf2b5
|
|
@ -4,7 +4,7 @@
|
||||||
package sbt
|
package sbt
|
||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import scala.xml.NodeSeq
|
import scala.xml.{Node,NodeSeq}
|
||||||
|
|
||||||
import org.apache.ivy.{core, plugins, util, Ivy}
|
import org.apache.ivy.{core, plugins, util, Ivy}
|
||||||
import core.cache.DefaultRepositoryCacheManager
|
import core.cache.DefaultRepositoryCacheManager
|
||||||
|
|
@ -20,6 +20,13 @@ import core.retrieve.RetrieveOptions
|
||||||
import plugins.parser.m2.{PomModuleDescriptorParser,PomModuleDescriptorWriter}
|
import plugins.parser.m2.{PomModuleDescriptorParser,PomModuleDescriptorWriter}
|
||||||
|
|
||||||
final class UpdateConfiguration(val retrieveDirectory: File, val outputPattern: String, val synchronize: Boolean, val quiet: Boolean) extends NotNull
|
final class UpdateConfiguration(val retrieveDirectory: File, val outputPattern: String, val synchronize: Boolean, val quiet: Boolean) extends NotNull
|
||||||
|
final class MakePomConfiguration(val extraDependencies: Iterable[ModuleID], val configurations: Option[Iterable[Configuration]],
|
||||||
|
val extra: NodeSeq, val process: Node => Node, val filterRepositories: MavenRepository => Boolean) extends NotNull
|
||||||
|
object MakePomConfiguration
|
||||||
|
{
|
||||||
|
def apply(extraDependencies: Iterable[ModuleID], configurations: Option[Iterable[Configuration]], extra: NodeSeq) =
|
||||||
|
new MakePomConfiguration(extraDependencies, configurations, extra, identity, _ => true)
|
||||||
|
}
|
||||||
|
|
||||||
object IvyActions
|
object IvyActions
|
||||||
{
|
{
|
||||||
|
|
@ -45,11 +52,14 @@ object IvyActions
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates a Maven pom from the given Ivy configuration*/
|
/** Creates a Maven pom from the given Ivy configuration*/
|
||||||
def makePom(module: IvySbt#Module, extraDependencies: Iterable[ModuleID], configurations: Option[Iterable[Configuration]], extra: NodeSeq, output: File)
|
@deprecated def makePom(module: IvySbt#Module, extraDependencies: Iterable[ModuleID], configurations: Option[Iterable[Configuration]], extra: NodeSeq, output: File): Unit =
|
||||||
|
makePom(module, MakePomConfiguration(extraDependencies, configurations, extra), output)
|
||||||
|
def makePom(module: IvySbt#Module, configuration: MakePomConfiguration, output: File)
|
||||||
{
|
{
|
||||||
|
import configuration.{configurations, extra, extraDependencies, filterRepositories, process}
|
||||||
module.withModule { (ivy, md, default) =>
|
module.withModule { (ivy, md, default) =>
|
||||||
addLateDependencies(ivy, md, default, extraDependencies)
|
addLateDependencies(ivy, md, default, extraDependencies)
|
||||||
(new MakePom).write(ivy, md, configurations, extra, output)
|
(new MakePom).write(ivy, md, configurations, extra, process, filterRepositories, output)
|
||||||
module.logger.info("Wrote " + output.getAbsolutePath)
|
module.logger.info("Wrote " + output.getAbsolutePath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
package sbt
|
package sbt
|
||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import scala.xml.NodeSeq
|
import scala.xml.{Node, NodeSeq}
|
||||||
|
|
||||||
final class IvyPaths(val baseDirectory: File, val cacheDirectory: Option[File]) extends NotNull
|
final class IvyPaths(val baseDirectory: File, val cacheDirectory: Option[File]) extends NotNull
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -20,8 +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, configurations: Option[Iterable[Configuration]], extra: NodeSeq, output: File): Unit =
|
def write(ivy: Ivy, module: ModuleDescriptor, configurations: Option[Iterable[Configuration]], extra: NodeSeq, process: Node => Node, filterRepositories: MavenRepository => Boolean, output: File): Unit =
|
||||||
write(toPom(ivy, module, configurations, extra), output)
|
write(process(toPom(ivy, module, configurations, extra, filterRepositories)), 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)
|
||||||
{
|
{
|
||||||
|
|
@ -37,13 +37,13 @@ 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, configurations: Option[Iterable[Configuration]], extra: NodeSeq): Node =
|
def toPom(ivy: Ivy, module: ModuleDescriptor, configurations: Option[Iterable[Configuration]], extra: NodeSeq, filterRepositories: MavenRepository => Boolean): 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, configurations) }
|
{ makeDependencies(module, configurations) }
|
||||||
{ makeRepositories(ivy.getSettings) }
|
{ makeRepositories(ivy.getSettings, filterRepositories) }
|
||||||
</project>)
|
</project>)
|
||||||
|
|
||||||
def makeModuleID(module: ModuleDescriptor): NodeSeq =
|
def makeModuleID(module: ModuleDescriptor): NodeSeq =
|
||||||
|
|
@ -125,16 +125,17 @@ class MakePom
|
||||||
def isOptional(confs: Array[String]) = confs.isEmpty || (confs.length == 1 && confs(0) == Configurations.Optional.name)
|
def isOptional(confs: Array[String]) = confs.isEmpty || (confs.length == 1 && confs(0) == Configurations.Optional.name)
|
||||||
|
|
||||||
|
|
||||||
def makeRepositories(settings: IvySettings) =
|
def makeRepositories(settings: IvySettings, filterRepositories: MavenRepository => Boolean) =
|
||||||
{
|
{
|
||||||
class MavenRepo(name: String, snapshots: Boolean, releases: Boolean)
|
class MavenRepo(name: String, snapshots: Boolean, releases: Boolean)
|
||||||
val repositories = resolvers(settings.getDefaultResolver)
|
val repositories = resolvers(settings.getDefaultResolver)
|
||||||
val mavenRepositories =
|
val mavenRepositories =
|
||||||
repositories.flatMap {
|
repositories.flatMap {
|
||||||
case m: IBiblioResolver if m.isM2compatible && m.getRoot != IBiblioResolver.DEFAULT_M2_ROOT => m :: Nil
|
case m: IBiblioResolver if m.isM2compatible && m.getRoot != IBiblioResolver.DEFAULT_M2_ROOT =>
|
||||||
|
MavenRepository(m.getName, m.getRoot) :: Nil
|
||||||
case _ => Nil
|
case _ => Nil
|
||||||
}
|
}
|
||||||
val repositoryElements = mavenRepositories.map { repo => mavenRepository(repo.getName, repo.getRoot) }
|
val repositoryElements = mavenRepositories.filter(filterRepositories).map(mavenRepository)
|
||||||
if(repositoryElements.isEmpty) repositoryElements else <repositories>{repositoryElements}</repositories>
|
if(repositoryElements.isEmpty) repositoryElements else <repositories>{repositoryElements}</repositories>
|
||||||
}
|
}
|
||||||
def flatten(rs: Seq[DependencyResolver]): Seq[DependencyResolver] = if(rs eq null) Nil else rs.flatMap(resolvers)
|
def flatten(rs: Seq[DependencyResolver]): Seq[DependencyResolver] = if(rs eq null) Nil else rs.flatMap(resolvers)
|
||||||
|
|
@ -148,8 +149,8 @@ class MakePom
|
||||||
def toID(name: String) = checkID(name.filter(isValidIDCharacter).mkString, name)
|
def toID(name: String) = checkID(name.filter(isValidIDCharacter).mkString, name)
|
||||||
def isValidIDCharacter(c: Char) = c.isLetterOrDigit
|
def isValidIDCharacter(c: Char) = c.isLetterOrDigit
|
||||||
private def checkID(id: String, name: String) = if(id.isEmpty) error("Could not convert '" + name + "' to an ID") else id
|
private def checkID(id: String, name: String) = if(id.isEmpty) error("Could not convert '" + name + "' to an ID") else id
|
||||||
def mavenRepository(name: String, root: String): Node =
|
def mavenRepository(repo: MavenRepository): Node =
|
||||||
mavenRepository(toID(name), name, root)
|
mavenRepository(toID(repo.name), repo.name, repo.root)
|
||||||
def mavenRepository(id: String, name: String, root: String): Node =
|
def mavenRepository(id: String, name: String, root: String): Node =
|
||||||
<repository>
|
<repository>
|
||||||
<id>{id}</id>
|
<id>{id}</id>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue