use of org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor in project ant-ivy by apache.
the class InstallEngine method install.
public ResolveReport install(ModuleRevisionId mrid, String from, String to, InstallOptions options) throws IOException {
DependencyResolver fromResolver = settings.getResolver(from);
DependencyResolver toResolver = settings.getResolver(to);
if (fromResolver == null) {
throw new IllegalArgumentException("unknown resolver " + from + ". Available resolvers are: " + settings.getResolverNames());
}
if (toResolver == null) {
throw new IllegalArgumentException("unknown resolver " + to + ". Available resolvers are: " + settings.getResolverNames());
}
PatternMatcher matcher = settings.getMatcher(options.getMatcherName());
if (matcher == null) {
throw new IllegalArgumentException("unknown matcher " + options.getMatcherName() + ". Available matchers are: " + settings.getMatcherNames());
}
// build module file declaring the dependency
Message.info(":: installing " + mrid + " ::");
DependencyResolver oldDictator = resolveEngine.getDictatorResolver();
boolean log = settings.logNotConvertedExclusionRule();
try {
settings.setLogNotConvertedExclusionRule(true);
resolveEngine.setDictatorResolver(fromResolver);
DefaultModuleDescriptor md = new DefaultModuleDescriptor(ModuleRevisionId.newInstance("apache", "ivy-install", "1.0"), settings.getStatusManager().getDefaultStatus(), new Date());
String resolveId = ResolveOptions.getDefaultResolveId(md);
md.addConfiguration(new Configuration("default"));
md.addConflictManager(new ModuleId(ExactPatternMatcher.ANY_EXPRESSION, ExactPatternMatcher.ANY_EXPRESSION), ExactPatternMatcher.INSTANCE, new NoConflictManager());
for (String dc : options.getConfs()) {
final String depConf = dc.trim();
if (MatcherHelper.isExact(matcher, mrid)) {
DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, mrid, false, false, options.isTransitive());
dd.addDependencyConfiguration("default", depConf);
md.addDependency(dd);
} else {
for (ModuleRevisionId imrid : searchEngine.listModules(fromResolver, mrid, matcher)) {
Message.info("\tfound " + imrid + " to install: adding to the list");
DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, imrid, false, false, options.isTransitive());
dd.addDependencyConfiguration("default", depConf);
md.addDependency(dd);
}
}
}
// resolve using appropriate resolver
ResolveReport report = new ResolveReport(md, resolveId);
Message.info(":: resolving dependencies ::");
ResolveOptions resolveOptions = new ResolveOptions().setResolveId(resolveId).setConfs(new String[] { "default" }).setValidate(options.isValidate());
IvyNode[] dependencies = resolveEngine.getDependencies(md, resolveOptions, report);
report.setDependencies(Arrays.asList(dependencies), options.getArtifactFilter());
Message.info(":: downloading artifacts to cache ::");
resolveEngine.downloadArtifacts(report, options.getArtifactFilter(), new DownloadOptions());
// now that everything is in cache, we can publish all these modules
Message.info(":: installing in " + to + " ::");
for (IvyNode dependency : dependencies) {
ModuleDescriptor depmd = dependency.getDescriptor();
if (depmd != null) {
ModuleRevisionId depMrid = depmd.getModuleRevisionId();
Message.verbose("installing " + depMrid);
boolean successfullyPublished = false;
try {
toResolver.beginPublishTransaction(depMrid, options.isOverwrite());
// publish artifacts
for (ArtifactDownloadReport artifact : report.getArtifactsReports(depMrid)) {
if (artifact.getLocalFile() != null) {
toResolver.publish(artifact.getArtifact(), artifact.getLocalFile(), options.isOverwrite());
}
}
// publish metadata
MetadataArtifactDownloadReport artifactDownloadReport = dependency.getModuleRevision().getReport();
File localIvyFile = artifactDownloadReport.getLocalFile();
toResolver.publish(depmd.getMetadataArtifact(), localIvyFile, options.isOverwrite());
if (options.isInstallOriginalMetadata()) {
if (artifactDownloadReport.getArtifactOrigin() != null && artifactDownloadReport.getArtifactOrigin().isExists() && !ArtifactOrigin.isUnknown(artifactDownloadReport.getArtifactOrigin()) && artifactDownloadReport.getArtifactOrigin().getArtifact() != null && artifactDownloadReport.getArtifactOrigin().getArtifact().getType().endsWith(".original") && !artifactDownloadReport.getArtifactOrigin().getArtifact().getType().equals(depmd.getMetadataArtifact().getType() + ".original")) {
// publish original metadata artifact, too, as it has a different
// type
toResolver.publish(artifactDownloadReport.getArtifactOrigin().getArtifact(), artifactDownloadReport.getOriginalLocalFile(), options.isOverwrite());
}
}
// end module publish
toResolver.commitPublishTransaction();
successfullyPublished = true;
} finally {
if (!successfullyPublished) {
toResolver.abortPublishTransaction();
}
}
}
}
Message.info(":: install resolution report ::");
// output report
resolveEngine.outputReport(report, settings.getResolutionCacheManager(), resolveOptions);
return report;
} finally {
// IVY-834: log the problems if there were any...
Message.sumupProblems();
resolveEngine.setDictatorResolver(oldDictator);
settings.setLogNotConvertedExclusionRule(log);
}
}
use of org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor in project ant-ivy by apache.
the class Main method run.
@SuppressWarnings("deprecation")
private static ResolveReport run(CommandLine line, boolean isCli) throws Exception {
if (line.hasOption("version")) {
System.out.println("Apache Ivy " + Ivy.getIvyVersion() + " - " + Ivy.getIvyDate() + " :: " + Ivy.getIvyHomeURL());
return null;
}
boolean validate = !line.hasOption("novalidate");
Ivy ivy = Ivy.newInstance();
initMessage(line, ivy);
IvySettings settings = initSettings(line, ivy);
ivy.pushContext();
File cache = new File(settings.substitute(line.getOptionValue("cache", settings.getDefaultCache().getAbsolutePath())));
if (line.hasOption("cache")) {
// override default cache path with user supplied cache path
settings.setDefaultCache(cache);
}
if (!cache.exists()) {
cache.mkdirs();
} else if (!cache.isDirectory()) {
error(cache + " is not a directory");
}
String[] confs;
if (line.hasOption("confs")) {
confs = line.getOptionValues("confs");
} else {
confs = new String[] { "*" };
}
File ivyfile;
if (line.hasOption("dependency")) {
String[] dep = line.getOptionValues("dependency");
ivyfile = File.createTempFile("ivy", ".xml");
ivyfile.deleteOnExit();
DefaultModuleDescriptor md = DefaultModuleDescriptor.newDefaultInstance(ModuleRevisionId.newInstance(dep[0], dep[1] + "-caller", "working"));
DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, ModuleRevisionId.newInstance(dep[0], dep[1], dep[2]), false, false, true);
for (String conf : confs) {
dd.addDependencyConfiguration("default", conf);
}
md.addDependency(dd);
XmlModuleDescriptorWriter.write(md, ivyfile);
confs = new String[] { "default" };
} else {
ivyfile = new File(settings.substitute(line.getOptionValue("ivy", "ivy.xml")));
if (!ivyfile.exists()) {
error("ivy file not found: " + ivyfile);
} else if (ivyfile.isDirectory()) {
error("ivy file is not a file: " + ivyfile);
}
}
if (line.hasOption("useOrigin")) {
ivy.getSettings().useDeprecatedUseOrigin();
}
ResolveOptions resolveOptions = new ResolveOptions().setConfs(confs).setValidate(validate).setResolveMode(line.getOptionValue("mode")).setArtifactFilter(FilterHelper.getArtifactTypeFilter(line.getOptionValues("types")));
if (line.hasOption("notransitive")) {
resolveOptions.setTransitive(false);
}
if (line.hasOption("refresh")) {
resolveOptions.setRefresh(true);
}
ResolveReport report = ivy.resolve(ivyfile.toURI().toURL(), resolveOptions);
if (report.hasError()) {
if (isCli) {
System.exit(1);
}
StringBuilder sb = new StringBuilder();
for (String problem : report.getAllProblemMessages()) {
if (sb.length() > 0) {
sb.append("\n");
}
sb.append(problem);
}
throw new ResolveProcessException(sb.toString());
}
ModuleDescriptor md = report.getModuleDescriptor();
if (confs.length == 1 && "*".equals(confs[0])) {
confs = md.getConfigurationsNames();
}
if (line.hasOption("retrieve")) {
String retrievePattern = settings.substitute(line.getOptionValue("retrieve"));
if (!retrievePattern.contains("[")) {
retrievePattern += "/lib/[conf]/[artifact].[ext]";
}
String ivyPattern = settings.substitute(line.getOptionValue("ivypattern"));
ivy.retrieve(md.getModuleRevisionId(), new RetrieveOptions().setConfs(confs).setSync(line.hasOption("sync")).setUseOrigin(line.hasOption("useOrigin")).setDestArtifactPattern(retrievePattern).setDestIvyPattern(ivyPattern).setOverwriteMode(line.getOptionValue("overwriteMode")).setArtifactFilter(FilterHelper.getArtifactTypeFilter(line.getOptionValues("types"))).setMakeSymlinks(line.hasOption("symlink")).setMakeSymlinksInMass(line.hasOption("symlinkmass")));
}
if (line.hasOption("cachepath")) {
outputCachePath(ivy, cache, md, confs, line.getOptionValue("cachepath", "ivycachepath.txt"));
}
if (line.hasOption("revision")) {
ivy.deliver(md.getResolvedModuleRevisionId(), settings.substitute(line.getOptionValue("revision")), settings.substitute(line.getOptionValue("deliverto", "ivy-[revision].xml")), DeliverOptions.newInstance(settings).setStatus(settings.substitute(line.getOptionValue("status", "release"))).setValidate(validate));
if (line.hasOption("publish")) {
ivy.publish(md.getResolvedModuleRevisionId(), Collections.singleton(settings.substitute(line.getOptionValue("publishpattern", "distrib/[type]s/[artifact]-[revision].[ext]"))), line.getOptionValue("publish"), new PublishOptions().setPubrevision(settings.substitute(line.getOptionValue("revision"))).setValidate(validate).setSrcIvyPattern(settings.substitute(line.getOptionValue("deliverto", "ivy-[revision].xml"))).setOverwrite(line.hasOption("overwrite")));
}
}
if (line.hasOption("makepom")) {
final String pomFilePath = line.getOptionValue("makepom", "pom.xml");
final File pomFile = new File(pomFilePath);
PomModuleDescriptorWriter.write(md, pomFile, new PomWriterOptions());
Message.debug("Generated a pom file for module at " + pomFile);
}
if (line.hasOption("main")) {
// check if the option cp has been set
List<File> fileList = getExtraClasspathFileList(line);
// merge -args and left over args
String[] fargs = line.getOptionValues("args");
if (fargs == null) {
fargs = new String[0];
}
String[] extra = line.getLeftOverArgs();
if (extra == null) {
extra = new String[0];
}
String[] params = new String[fargs.length + extra.length];
System.arraycopy(fargs, 0, params, 0, fargs.length);
System.arraycopy(extra, 0, params, fargs.length, extra.length);
// invoke with given main class and merged params
invoke(ivy, cache, md, confs, fileList, line.getOptionValue("main"), params);
}
ivy.getLoggerEngine().popLogger();
ivy.popContext();
return report;
}
use of org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor in project ant-ivy by apache.
the class XmlModuleDescriptorWriter method printInfoTag.
private static void printInfoTag(ModuleDescriptor md, PrintWriter out) {
out.println("\t<info organisation=\"" + XMLHelper.escape(md.getModuleRevisionId().getOrganisation()) + "\"");
out.println("\t\tmodule=\"" + XMLHelper.escape(md.getModuleRevisionId().getName()) + "\"");
String branch = md.getResolvedModuleRevisionId().getBranch();
if (branch != null) {
out.println("\t\tbranch=\"" + XMLHelper.escape(branch) + "\"");
}
String revision = md.getResolvedModuleRevisionId().getRevision();
if (revision != null) {
out.println("\t\trevision=\"" + XMLHelper.escape(revision) + "\"");
}
out.println("\t\tstatus=\"" + XMLHelper.escape(md.getStatus()) + "\"");
out.println("\t\tpublication=\"" + DateUtil.format(md.getResolvedPublicationDate()) + "\"");
if (md.isDefault()) {
out.println("\t\tdefault=\"true\"");
}
if (md instanceof DefaultModuleDescriptor) {
DefaultModuleDescriptor dmd = (DefaultModuleDescriptor) md;
if (dmd.getNamespace() != null && !dmd.getNamespace().getName().equals("system")) {
out.println("\t\tnamespace=\"" + XMLHelper.escape(dmd.getNamespace().getName()) + "\"");
}
}
if (!md.getExtraAttributes().isEmpty()) {
printExtraAttributes(md, out, "\t\t");
out.println();
}
if (requireInnerInfoElement(md)) {
out.println("\t>");
for (ExtendsDescriptor parent : md.getInheritedDescriptors()) {
ModuleRevisionId mrid = parent.getParentRevisionId();
out.print(String.format("\t\t<extends organisation=\"%s\" module=\"%s\" revision=\"%s\"", XMLHelper.escape(mrid.getOrganisation()), XMLHelper.escape(mrid.getName()), XMLHelper.escape(mrid.getRevision())));
String location = parent.getLocation();
if (location != null) {
out.print(" location=\"" + XMLHelper.escape(location) + "\"");
}
out.print(" extendType=\"" + joinArray(parent.getExtendsTypes(), ",") + "\"");
out.println("/>");
}
License[] licenses = md.getLicenses();
for (License license : licenses) {
out.print("\t\t<license ");
if (license.getName() != null) {
out.print("name=\"" + XMLHelper.escape(license.getName()) + "\" ");
}
if (license.getUrl() != null) {
out.print("url=\"" + XMLHelper.escape(license.getUrl()) + "\" ");
}
out.println("/>");
}
if (md.getHomePage() != null || md.getDescription() != null) {
out.print("\t\t<description");
if (md.getHomePage() != null) {
out.print(" homepage=\"" + XMLHelper.escape(md.getHomePage()) + "\"");
}
if (isNullOrEmpty(md.getDescription())) {
out.println(" />");
} else {
out.println(">");
out.println("\t\t" + XMLHelper.escape(md.getDescription()));
out.println("\t\t</description>");
}
}
for (ExtraInfoHolder extraInfo : md.getExtraInfos()) {
printExtraInfoElement(out, extraInfo, 2);
}
out.println("\t</info>");
} else {
out.println("\t/>");
}
}
use of org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor in project ant-ivy by apache.
the class ResolveReport method toFixedModuleDescriptor.
public ModuleDescriptor toFixedModuleDescriptor(IvySettings settings, List<ModuleId> midToKeep) {
DefaultModuleDescriptor fixedmd = new DefaultModuleDescriptor(md.getModuleRevisionId(), md.getStatus(), new Date());
// copy namespaces
for (Map.Entry<String, String> ns : md.getExtraAttributesNamespaces().entrySet()) {
fixedmd.addExtraAttributeNamespace(ns.getKey(), ns.getValue());
}
// copy info
fixedmd.setDescription(md.getDescription());
fixedmd.setHomePage(md.getHomePage());
fixedmd.getExtraInfos().addAll(md.getExtraInfos());
// copy configurations
List<String> resolvedConfs = Arrays.asList(getConfigurations());
for (String conf : resolvedConfs) {
fixedmd.addConfiguration(new Configuration(conf));
}
// copy artifacts
for (String conf : resolvedConfs) {
for (Artifact a : md.getArtifacts(conf)) {
fixedmd.addArtifact(conf, a);
}
}
// add resolved dependencies
for (IvyNode dep : dependencies) {
ModuleRevisionId depMrid;
boolean force;
if (midToKeep != null && midToKeep.contains(dep.getModuleId())) {
depMrid = dep.getId();
force = false;
} else {
depMrid = dep.getResolvedId();
force = true;
}
DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(fixedmd, depMrid, force, false, false);
boolean evicted = true;
for (String rootConf : dep.getRootModuleConfigurations()) {
if (dep.isEvicted(rootConf)) {
continue;
}
evicted = false;
for (String targetConf : dep.getConfigurations(rootConf)) {
dd.addDependencyConfiguration(rootConf, targetConf);
}
}
if (!evicted) {
fixedmd.addDependency(dd);
}
}
return fixedmd;
}
use of org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor in project ant-ivy by apache.
the class ResolveEngine method resolve.
/**
* Resolves the module identified by the given mrid with its dependencies if transitive is set
* to true.
*
* @param mrid ModuleRevisionId
* @param options ResolveOptions
* @param changing boolean
* @return ResolveReport
* @throws ParseException if something goes wrong
* @throws IOException if something goes wrong
*/
public ResolveReport resolve(final ModuleRevisionId mrid, ResolveOptions options, boolean changing) throws ParseException, IOException {
DefaultModuleDescriptor md;
ResolveOptions optionsToUse = new ResolveOptions(options);
if (options.useSpecialConfs()) {
// create new resolve options because this is a different resolve than the real resolve
// (which will be a resolve of a newCallerInstance module)
ResolvedModuleRevision rmr = findModule(mrid, new ResolveOptions(options));
if (rmr == null) {
Message.verbose("module not found " + mrid);
// we will continue the resolve anyway to get a nice error message back
// to the user, however reduce the amount of logging in this case
optionsToUse.setLog(LogOptions.LOG_DOWNLOAD_ONLY);
md = DefaultModuleDescriptor.newCallerInstance(mrid, new String[] { "default" }, options.isTransitive(), changing);
} else {
String[] confs = options.getConfs(rmr.getDescriptor());
md = DefaultModuleDescriptor.newCallerInstance(ModuleRevisionId.newInstance(mrid, rmr.getId().getRevision()), confs, options.isTransitive(), changing);
}
} else {
md = DefaultModuleDescriptor.newCallerInstance(mrid, options.getConfs(), options.isTransitive(), changing);
}
return resolve(md, optionsToUse);
}
Aggregations