use of org.apache.ivy.core.resolve.ResolveOptions in project walkmod-core by walkmod.
the class IvyConfigurationProvider method initIvy.
/**
* Ivy configuration initialization
*
* @throws ParseException
* If an error occurs when loading ivy settings file
* (ivysettings.xml)
* @throws IOException
* If an error occurs when reading ivy settings file
* (ivysettings.xml)
* @throws ConfigurationException
* If ivy settings file (ivysettings.xml) is not found in
* classpath
*/
public void initIvy() throws ParseException, IOException, ConfigurationException {
if (ivy == null) {
// creates clear ivy settings
IvySettings ivySettings = new IvySettings();
File settingsFile = new File(IVY_SETTINGS_FILE);
if (settingsFile.exists()) {
ivySettings.load(settingsFile);
} else {
URL settingsURL = ClassLoader.getSystemResource(IVY_SETTINGS_FILE);
if (settingsURL == null) {
// file not found in System classloader, we try the current one
settingsURL = this.getClass().getClassLoader().getResource(IVY_SETTINGS_FILE);
// when invoking toURI()
if (settingsURL == null)
throw new ConfigurationException("Ivy settings file (" + IVY_SETTINGS_FILE + ") could not be found in classpath");
}
ivySettings.load(settingsURL);
}
// creates an Ivy instance with settings
ivy = Ivy.newInstance(ivySettings);
}
ivyfile = File.createTempFile("ivy", ".xml");
ivyfile.deleteOnExit();
applyVerbose();
String[] confs = new String[] { "default" };
resolveOptions = new ResolveOptions().setConfs(confs);
if (isOffLine) {
resolveOptions = resolveOptions.setUseCacheOnly(true);
} else {
Map<String, Object> params = configuration.getParameters();
if (params != null) {
Object value = params.get("offline");
if (value != null) {
String offlineOpt = value.toString();
if (offlineOpt != null) {
boolean offline = Boolean.parseBoolean(offlineOpt);
if (offline) {
resolveOptions = resolveOptions.setUseCacheOnly(true);
}
}
}
}
}
}
use of org.apache.ivy.core.resolve.ResolveOptions in project ant-ivy by apache.
the class IvyRepositoryReport method doExecute.
public void doExecute() throws BuildException {
Ivy ivy = getIvyInstance();
IvySettings settings = ivy.getSettings();
if (xsl && xslFile == null) {
throw new BuildException("xsl file is mandatory when using xsl generation");
}
if (module == null && PatternMatcher.EXACT.equals(matcher)) {
throw new BuildException("no module name provided for ivy repository graph task: " + "It can either be set explicitly via the attribute 'module' or " + "via 'ivy.module' property or a prior call to <resolve/>");
} else if (module == null && !PatternMatcher.EXACT.equals(matcher)) {
module = PatternMatcher.ANY_EXPRESSION;
}
ModuleRevisionId moduleRevisionId = ModuleRevisionId.newInstance(organisation, module, revision);
try {
ModuleRevisionId criteria = (revision == null) || settings.getVersionMatcher().isDynamic(moduleRevisionId) ? new ModuleRevisionId(new ModuleId(organisation, module), branch, "*") : new ModuleRevisionId(new ModuleId(organisation, module), branch, revision);
ModuleRevisionId[] mrids = ivy.listModules(criteria, settings.getMatcher(matcher));
// replace all found revisions with the original requested revision
Set<ModuleRevisionId> modules = new HashSet<>();
for (ModuleRevisionId mrid : mrids) {
modules.add(ModuleRevisionId.newInstance(mrid, revision));
}
mrids = modules.toArray(new ModuleRevisionId[modules.size()]);
ModuleDescriptor md = DefaultModuleDescriptor.newCallerInstance(mrids, true, false);
String resolveId = ResolveOptions.getDefaultResolveId(md);
ResolveReport report = ivy.resolve(md, new ResolveOptions().setResolveId(resolveId).setValidate(doValidate(settings)));
ResolutionCacheManager cacheMgr = getIvyInstance().getResolutionCacheManager();
new XmlReportOutputter().output(report, cacheMgr, new ResolveOptions());
if (graph) {
gengraph(cacheMgr, md.getModuleRevisionId().getOrganisation(), md.getModuleRevisionId().getName());
}
if (dot) {
gendot(cacheMgr, md.getModuleRevisionId().getOrganisation(), md.getModuleRevisionId().getName());
}
if (xml) {
FileUtil.copy(cacheMgr.getConfigurationResolveReportInCache(resolveId, "default"), new File(getTodir(), outputname + ".xml"), null);
}
if (xsl) {
genreport(cacheMgr, md.getModuleRevisionId().getOrganisation(), md.getModuleRevisionId().getName());
}
} catch (Exception e) {
throw new BuildException("impossible to generate graph for " + moduleRevisionId + ": " + e, e);
}
}
use of org.apache.ivy.core.resolve.ResolveOptions in project ant-ivy by apache.
the class IvyDependencyUpdateChecker method doExecute.
public void doExecute() throws BuildException {
prepareAndCheck();
ModuleDescriptor originalModuleDescriptor = getResolvedReport().getModuleDescriptor();
// clone module descriptor
DefaultModuleDescriptor latestModuleDescriptor = new DefaultModuleDescriptor(originalModuleDescriptor.getModuleRevisionId(), originalModuleDescriptor.getStatus(), originalModuleDescriptor.getPublicationDate());
// copy configurations
for (Configuration configuration : originalModuleDescriptor.getConfigurations()) {
latestModuleDescriptor.addConfiguration(configuration);
}
// clone dependency and add new one with the requested revisionToCheck
for (DependencyDescriptor dependencyDescriptor : originalModuleDescriptor.getDependencies()) {
ModuleRevisionId upToDateMrid = ModuleRevisionId.newInstance(dependencyDescriptor.getDependencyRevisionId(), revisionToCheck);
latestModuleDescriptor.addDependency(dependencyDescriptor.clone(upToDateMrid));
}
// resolve
ResolveOptions resolveOptions = new ResolveOptions();
resolveOptions.setDownload(isDownload());
resolveOptions.setLog(getLog());
resolveOptions.setConfs(splitToArray(getConf()));
resolveOptions.setCheckIfChanged(checkIfChanged);
ResolveReport latestReport;
try {
latestReport = getIvyInstance().getResolveEngine().resolve(latestModuleDescriptor, resolveOptions);
displayDependencyUpdates(getResolvedReport(), latestReport);
if (showTransitive) {
displayNewDependencyOnLatest(getResolvedReport(), latestReport);
displayMissingDependencyOnLatest(getResolvedReport(), latestReport);
}
} catch (ParseException | IOException e) {
throw new BuildException("impossible to resolve dependencies:\n\t" + e, e);
}
}
use of org.apache.ivy.core.resolve.ResolveOptions 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.resolve.ResolveOptions 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;
}
Aggregations