2010-02-08 05:45:19 +01:00
|
|
|
/* sbt -- Simple Build Tool
|
|
|
|
|
* Copyright 2008, 2009, 2010 Mark Harrah
|
|
|
|
|
*/
|
2010-01-16 01:05:23 +01:00
|
|
|
package sbt
|
2009-08-16 20:29:08 +02:00
|
|
|
|
|
|
|
|
import java.io.File
|
2010-01-30 02:31:07 +01:00
|
|
|
import scala.xml.NodeSeq
|
2009-08-16 20:29:08 +02:00
|
|
|
|
|
|
|
|
import org.apache.ivy.{core, plugins, util, Ivy}
|
|
|
|
|
import core.cache.DefaultRepositoryCacheManager
|
|
|
|
|
import core.LogOptions
|
|
|
|
|
import core.deliver.DeliverOptions
|
2009-08-20 06:02:06 +02:00
|
|
|
import core.install.InstallOptions
|
2009-08-16 20:29:08 +02:00
|
|
|
import core.module.descriptor.{DefaultArtifact, DefaultDependencyArtifactDescriptor, MDArtifact}
|
|
|
|
|
import core.module.descriptor.{DefaultDependencyDescriptor, DefaultModuleDescriptor, DependencyDescriptor, ModuleDescriptor}
|
|
|
|
|
import core.module.id.{ArtifactId,ModuleId, ModuleRevisionId}
|
|
|
|
|
import core.publish.PublishOptions
|
|
|
|
|
import core.resolve.ResolveOptions
|
|
|
|
|
import core.retrieve.RetrieveOptions
|
|
|
|
|
import plugins.parser.m2.{PomModuleDescriptorParser,PomModuleDescriptorWriter}
|
|
|
|
|
|
|
|
|
|
final class UpdateConfiguration(val retrieveDirectory: File, val outputPattern: String, val synchronize: Boolean, val quiet: Boolean) extends NotNull
|
|
|
|
|
|
|
|
|
|
object IvyActions
|
|
|
|
|
{
|
2009-08-20 06:02:06 +02:00
|
|
|
/** Installs the dependencies of the given 'module' from the resolver named 'from' to the resolver named 'to'.*/
|
|
|
|
|
def install(module: IvySbt#Module, from: String, to: String)
|
2009-08-18 06:51:08 +02:00
|
|
|
{
|
2009-08-20 06:02:06 +02:00
|
|
|
module.withModule { (ivy, md, default) =>
|
|
|
|
|
for(dependency <- md.getDependencies)
|
|
|
|
|
{
|
|
|
|
|
module.logger.info("Installing " + dependency)
|
|
|
|
|
val options = new InstallOptions
|
2009-09-27 20:39:26 +02:00
|
|
|
options.setValidate(module.moduleSettings.validate)
|
2009-08-20 06:02:06 +02:00
|
|
|
options.setTransitive(dependency.isTransitive)
|
|
|
|
|
ivy.install(dependency.getDependencyRevisionId, from, to, options)
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-08-18 06:51:08 +02:00
|
|
|
}
|
|
|
|
|
|
2009-08-16 20:29:08 +02:00
|
|
|
/** Clears the Ivy cache, as configured by 'config'. */
|
2010-01-30 02:31:07 +01:00
|
|
|
def cleanCache(ivy: IvySbt) = ivy.withIvy { iv =>
|
|
|
|
|
iv.getSettings.getResolutionCacheManager.clean()
|
|
|
|
|
iv.getSettings.getRepositoryCacheManagers.foreach(_.clean())
|
|
|
|
|
}
|
2009-08-20 06:02:06 +02:00
|
|
|
|
2009-08-16 20:29:08 +02:00
|
|
|
/** Creates a Maven pom from the given Ivy configuration*/
|
2010-01-30 02:31:07 +01:00
|
|
|
def makePom(module: IvySbt#Module, extraDependencies: Iterable[ModuleID], configurations: Option[Iterable[Configuration]], extra: NodeSeq, output: File)
|
2009-08-16 20:29:08 +02:00
|
|
|
{
|
|
|
|
|
module.withModule { (ivy, md, default) =>
|
|
|
|
|
addLateDependencies(ivy, md, default, extraDependencies)
|
2010-03-30 15:19:36 +02:00
|
|
|
(new MakePom).write(ivy, md, configurations, extra, output)
|
2009-08-16 20:29:08 +02:00
|
|
|
module.logger.info("Wrote " + output.getAbsolutePath)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// todo: correct default configuration for extra dependencies
|
|
|
|
|
private def addLateDependencies(ivy: Ivy, module: DefaultModuleDescriptor, defaultConfiguration: String, extraDependencies: Iterable[ModuleID])
|
|
|
|
|
{
|
2009-09-27 20:39:26 +02:00
|
|
|
val parser = new CustomXmlParser.CustomParser(ivy.getSettings, Some(defaultConfiguration))
|
2009-08-16 20:29:08 +02:00
|
|
|
parser.setMd(module)
|
|
|
|
|
IvySbt.addDependencies(module, extraDependencies, parser)
|
|
|
|
|
}
|
2009-08-20 06:02:06 +02:00
|
|
|
|
2009-08-16 20:29:08 +02:00
|
|
|
def deliver(module: IvySbt#Module, status: String, deliverIvyPattern: String, extraDependencies: Iterable[ModuleID], configurations: Option[Iterable[Configuration]], quiet: Boolean)
|
|
|
|
|
{
|
|
|
|
|
module.withModule { case (ivy, md, default) =>
|
|
|
|
|
addLateDependencies(ivy, md, default, extraDependencies)
|
|
|
|
|
resolve(quiet)(ivy, md, default) // todo: set download = false for resolve
|
|
|
|
|
val revID = md.getModuleRevisionId
|
|
|
|
|
val options = DeliverOptions.newInstance(ivy.getSettings).setStatus(status)
|
2010-03-30 15:19:36 +02:00
|
|
|
options.setConfs(IvySbt.getConfigurations(md, configurations))
|
2009-08-16 20:29:08 +02:00
|
|
|
ivy.deliver(revID, revID.getRevision, deliverIvyPattern, options)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// todo: map configurations, extra dependencies
|
|
|
|
|
def publish(module: IvySbt#Module, resolverName: String, srcArtifactPatterns: Iterable[String], deliveredIvyPattern: Option[String], configurations: Option[Iterable[Configuration]])
|
|
|
|
|
{
|
|
|
|
|
module.withModule { case (ivy, md, default) =>
|
|
|
|
|
val revID = md.getModuleRevisionId
|
|
|
|
|
val patterns = new java.util.ArrayList[String]
|
|
|
|
|
srcArtifactPatterns.foreach(pattern => patterns.add(pattern))
|
|
|
|
|
val options = (new PublishOptions).setOverwrite(true)
|
|
|
|
|
deliveredIvyPattern.foreach(options.setSrcIvyPattern)
|
2010-03-30 15:19:36 +02:00
|
|
|
options.setConfs(IvySbt.getConfigurations(md, configurations))
|
2009-08-16 20:29:08 +02:00
|
|
|
ivy.publish(revID, patterns, resolverName, options)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/** Resolves and retrieves dependencies. 'ivyConfig' is used to produce an Ivy file and configuration.
|
|
|
|
|
* 'updateConfig' configures the actual resolution and retrieval process. */
|
|
|
|
|
def update(module: IvySbt#Module, configuration: UpdateConfiguration)
|
|
|
|
|
{
|
|
|
|
|
module.withModule { case (ivy, md, default) =>
|
|
|
|
|
import configuration._
|
|
|
|
|
resolve(quiet)(ivy, md, default)
|
|
|
|
|
val retrieveOptions = new RetrieveOptions
|
|
|
|
|
retrieveOptions.setSync(synchronize)
|
|
|
|
|
val patternBase = retrieveDirectory.getAbsolutePath
|
|
|
|
|
val pattern =
|
|
|
|
|
if(patternBase.endsWith(File.separator))
|
|
|
|
|
patternBase + outputPattern
|
|
|
|
|
else
|
|
|
|
|
patternBase + File.separatorChar + outputPattern
|
|
|
|
|
ivy.retrieve(md.getModuleRevisionId, pattern, retrieveOptions)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private def resolve(quiet: Boolean)(ivy: Ivy, module: DefaultModuleDescriptor, defaultConf: String) =
|
|
|
|
|
{
|
|
|
|
|
val resolveOptions = new ResolveOptions
|
|
|
|
|
if(quiet)
|
|
|
|
|
resolveOptions.setLog(LogOptions.LOG_DOWNLOAD_ONLY)
|
|
|
|
|
val resolveReport = ivy.resolve(module, resolveOptions)
|
|
|
|
|
if(resolveReport.hasError)
|
2010-02-06 23:43:14 +01:00
|
|
|
throw new ResolveException(resolveReport.getAllProblemMessages.toArray.map(_.toString).toList.removeDuplicates)
|
2009-08-16 20:29:08 +02:00
|
|
|
}
|
2010-02-06 23:43:14 +01:00
|
|
|
}
|
|
|
|
|
final class ResolveException(messages: List[String]) extends RuntimeException(messages.mkString("\n"))
|