use of org.apache.ivy.core.resolve.ResolveOptions in project ant-ivy by apache.
the class UpdateSiteAndIbiblioResolverTest method setUp.
@Before
public void setUp() throws Exception {
settings = new IvySettings();
chain = new ChainResolver();
chain.setName("chain");
chain.setSettings(settings);
resolver = new UpdateSiteResolver();
resolver.setName("ivyde-repo");
resolver.setUrl(new File("test/test-p2/ivyde-repo").toURI().toURL().toExternalForm());
resolver.setSettings(settings);
resolver2 = new IBiblioResolver();
resolver2.setName("maven2");
settings.setVariable("ivy.ibiblio.default.artifact.root", DEFAULT_M2_ROOT);
settings.setVariable("ivy.ibiblio.default.artifact.pattern", "[organisation]/[module]/[revision]/[artifact]-[revision].[ext]");
resolver2.setSettings(settings);
chain.add(resolver);
chain.add(resolver2);
settings.addResolver(chain);
settings.setDefaultResolver("chain");
cache = new File("build/cache");
cache.mkdirs();
settings.setDefaultCache(cache);
ivy = new Ivy();
ivy.setSettings(settings);
ivy.bind();
ivy.getResolutionCacheManager().clean();
RepositoryCacheManager[] caches = settings.getRepositoryCacheManagers();
for (RepositoryCacheManager cache : caches) {
cache.clean();
}
data = new ResolveData(ivy.getResolveEngine(), new ResolveOptions());
}
use of org.apache.ivy.core.resolve.ResolveOptions in project lucene-solr by apache.
the class LibVersionsCheckTask method findLatestConflictVersions.
private boolean findLatestConflictVersions() {
boolean success = true;
StringBuilder latestIvyXml = new StringBuilder();
latestIvyXml.append("<ivy-module version=\"2.0\">\n");
latestIvyXml.append(" <info organisation=\"org.apache.lucene\" module=\"core-tools-find-latest-revision\"/>\n");
latestIvyXml.append(" <configurations>\n");
latestIvyXml.append(" <conf name=\"default\" transitive=\"false\"/>\n");
latestIvyXml.append(" </configurations>\n");
latestIvyXml.append(" <dependencies>\n");
for (Map.Entry<String, Dependency> directDependency : directDependencies.entrySet()) {
Dependency dependency = directDependency.getValue();
if (dependency.conflictLocations.entrySet().isEmpty()) {
continue;
}
latestIvyXml.append(" <dependency org=\"");
latestIvyXml.append(dependency.org);
latestIvyXml.append("\" name=\"");
latestIvyXml.append(dependency.name);
latestIvyXml.append("\" rev=\"latest.release\" conf=\"default->*\"/>\n");
}
latestIvyXml.append(" </dependencies>\n");
latestIvyXml.append("</ivy-module>\n");
File buildDir = new File(commonBuildDir, "ivy-transitive-resolve");
if (!buildDir.exists() && !buildDir.mkdirs()) {
throw new BuildException("Could not create temp directory " + buildDir.getPath());
}
File findLatestIvyXmlFile = new File(buildDir, "find.latest.conflicts.ivy.xml");
try {
try (Writer writer = new OutputStreamWriter(new FileOutputStream(findLatestIvyXmlFile), StandardCharsets.UTF_8)) {
writer.write(latestIvyXml.toString());
}
ResolveOptions options = new ResolveOptions();
// Download only module descriptors, not artifacts
options.setDownload(false);
// Resolve only direct dependencies
options.setTransitive(false);
// Download the internet!
options.setUseCacheOnly(false);
// Don't print to the console
options.setOutputReport(false);
// Don't log to the console
options.setLog(LogOptions.LOG_QUIET);
// Resolve all configurations
options.setConfs(new String[] { "*" });
ResolveReport resolveReport = ivy.resolve(findLatestIvyXmlFile.toURI().toURL(), options);
IvyNodeElement root = IvyNodeElementAdapter.adapt(resolveReport);
for (IvyNodeElement element : root.getDependencies()) {
String coordinate = "/" + element.getOrganization() + "/" + element.getName();
Dependency dependency = directDependencies.get(coordinate);
if (null == dependency) {
log("ERROR: the following coordinate key does not appear in " + centralizedVersionsFile.getName() + ": " + coordinate, Project.MSG_ERR);
success = false;
} else {
dependency.latestVersion = element.getRevision();
}
}
} catch (IOException e) {
log("Exception writing to " + findLatestIvyXmlFile.getPath() + ": " + e.toString(), Project.MSG_ERR);
success = false;
} catch (ParseException e) {
log("Exception parsing filename " + findLatestIvyXmlFile.getPath() + ": " + e.toString(), Project.MSG_ERR);
success = false;
}
return success;
}
use of org.apache.ivy.core.resolve.ResolveOptions in project lucene-solr by apache.
the class LibVersionsCheckTask method resolveTransitively.
/**
* Transitively resolves all dependencies in the given ivy.xml file,
* looking for indirect dependencies with versions that conflict
* with those of direct dependencies. Dependency conflict when a
* direct dependency's version is older than that of an indirect
* dependency with the same /org/name.
*
* Returns true if no version conflicts are found and no resolution
* errors occurred, false otherwise.
*/
private boolean resolveTransitively(File ivyXmlFile) {
boolean success = true;
ResolveOptions options = new ResolveOptions();
// Download only module descriptors, not artifacts
options.setDownload(false);
// Resolve transitively, if not already specified in the ivy.xml file
options.setTransitive(true);
// Download the internet!
options.setUseCacheOnly(false);
// Don't print to the console
options.setOutputReport(false);
// Don't log to the console
options.setLog(LogOptions.LOG_QUIET);
// Resolve all configurations
options.setConfs(new String[] { "*" });
// Rewrite the ivy.xml, replacing all 'transitive="false"' with 'transitive="true"'
// The Ivy API is file-based, so we have to write the result to the filesystem.
String moduleName = "unknown";
String ivyXmlContent = xmlToString(ivyXmlFile);
Matcher matcher = MODULE_NAME_PATTERN.matcher(ivyXmlContent);
if (matcher.find()) {
moduleName = matcher.group(1);
}
ivyXmlContent = ivyXmlContent.replaceAll("\\btransitive\\s*=\\s*[\"']false[\"']", "transitive=\"true\"");
File transitiveIvyXmlFile = null;
try {
File buildDir = new File(commonBuildDir, "ivy-transitive-resolve");
if (!buildDir.exists() && !buildDir.mkdirs()) {
throw new BuildException("Could not create temp directory " + buildDir.getPath());
}
matcher = MODULE_DIRECTORY_PATTERN.matcher(ivyXmlFile.getCanonicalPath());
if (!matcher.matches()) {
throw new BuildException("Unknown ivy.xml module directory: " + ivyXmlFile.getCanonicalPath());
}
String moduleDirPrefix = matcher.group(1).replaceAll("[/\\\\]", ".");
transitiveIvyXmlFile = new File(buildDir, "transitive." + moduleDirPrefix + ".ivy.xml");
try (Writer writer = new OutputStreamWriter(new FileOutputStream(transitiveIvyXmlFile), StandardCharsets.UTF_8)) {
writer.write(ivyXmlContent);
}
ResolveReport resolveReport = ivy.resolve(transitiveIvyXmlFile.toURI().toURL(), options);
IvyNodeElement root = IvyNodeElementAdapter.adapt(resolveReport);
for (IvyNodeElement directDependency : root.getDependencies()) {
String coordinate = "/" + directDependency.getOrganization() + "/" + directDependency.getName();
Dependency dependency = directDependencies.get(coordinate);
if (null == dependency) {
log("ERROR: the following coordinate key does not appear in " + centralizedVersionsFile.getName() + ": " + coordinate);
success = false;
} else {
dependency.directlyReferenced = true;
if (collectConflicts(directDependency, directDependency, moduleName)) {
success = false;
}
}
}
} catch (ParseException | IOException e) {
if (null != transitiveIvyXmlFile) {
log("Exception reading " + transitiveIvyXmlFile.getPath() + ": " + e.toString());
}
success = false;
}
return success;
}
use of org.apache.ivy.core.resolve.ResolveOptions in project Saturn by vipshop.
the class IvyGetArtifact method get.
public List<URL> get(String org, String name, String rev, String[] confs, Set<Map<String, Object>> artifacts) throws IOException, ParseException {
Set<URL> artifactsGeted = new HashSet<URL>();
try {
ivy.getSettings().addAllVariables(System.getProperties());
ivy.pushContext();
File ivyfile = getIvyfile(org, name, rev, confs, artifacts);
String[] conf2 = new String[] { "default" };
ResolveOptions resolveOptions = new ResolveOptions().setConfs(conf2).setValidate(true).setResolveMode(null).setArtifactFilter(FilterHelper.getArtifactTypeFilter("jar,bundle,zip"));
ResolveReport report = ivy.resolve(ivyfile.toURI().toURL(), resolveOptions);
if (report.hasError()) {
List<?> problemMessages = report.getAllProblemMessages();
for (Object message : problemMessages) {
log.error(message.toString());
}
} else {
artifactsGeted.addAll(getCachePath(report.getModuleDescriptor(), conf2));
}
} catch (IOException e) {
throw e;
} catch (ParseException e) {
throw e;
} finally {
ivy.popContext();
}
List<URL> result = new ArrayList<URL>();
result.addAll(artifactsGeted);
return result;
}
use of org.apache.ivy.core.resolve.ResolveOptions in project ant-ivy by apache.
the class RetrieveTest method testUnpackExt.
/**
* Test case for IVY-1478.
* {@link RetrieveEngine} must retrieve artifacts with the correct extension if the artifact
* is unpacked.
*
* @throws Exception if something goes wrong
* @see <a href="https://issues.apache.org/jira/browse/IVY-1478">IVY-1478</a>
*/
@Test
public void testUnpackExt() throws Exception {
final ResolveOptions roptions = getResolveOptions(new String[] { "*" });
final URL url = new File("test/repositories/1/packaging/module10/ivys/ivy-1.0.xml").toURI().toURL();
// normal resolve, the file goes in the cache
final ResolveReport report = ivy.resolve(url, roptions);
assertFalse("Resolution report has errors", report.hasError());
final ModuleDescriptor md = report.getModuleDescriptor();
assertNotNull("Module descriptor from report was null", md);
final String pattern = "build/test/retrieve/[organization]/[module]/[conf]/[type]s/[artifact]-[revision](.[ext])";
ivy.retrieve(md.getModuleRevisionId(), getRetrieveOptions().setDestArtifactPattern(pattern));
final File dest = new File("build/test/retrieve/packaging/module9/default/jars/module9-1.0.jar");
assertTrue("Retrieved artifact is missing at " + dest.getAbsolutePath(), dest.exists());
assertTrue("Retrieved artifact at " + dest.getAbsolutePath() + " is not a file", dest.isFile());
}
Aggregations