Search in sources :

Example 16 with ResolveOptions

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());
}
Also used : ChainResolver(org.apache.ivy.plugins.resolver.ChainResolver) IBiblioResolver(org.apache.ivy.plugins.resolver.IBiblioResolver) ResolveData(org.apache.ivy.core.resolve.ResolveData) RepositoryCacheManager(org.apache.ivy.core.cache.RepositoryCacheManager) IvySettings(org.apache.ivy.core.settings.IvySettings) File(java.io.File) Ivy(org.apache.ivy.Ivy) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) Before(org.junit.Before)

Example 17 with 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;
}
Also used : IvyNodeElement(org.apache.lucene.validation.ivyde.IvyNodeElement) IOException(java.io.IOException) ResolveReport(org.apache.ivy.core.report.ResolveReport) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) BuildException(org.apache.tools.ant.BuildException) ParseException(java.text.ParseException) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) File(java.io.File) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) StringWriter(java.io.StringWriter)

Example 18 with ResolveOptions

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;
}
Also used : IvyNodeElement(org.apache.lucene.validation.ivyde.IvyNodeElement) Matcher(java.util.regex.Matcher) IOException(java.io.IOException) ResolveReport(org.apache.ivy.core.report.ResolveReport) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) BuildException(org.apache.tools.ant.BuildException) ParseException(java.text.ParseException) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) File(java.io.File) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) StringWriter(java.io.StringWriter)

Example 19 with ResolveOptions

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;
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) URL(java.net.URL) ResolveReport(org.apache.ivy.core.report.ResolveReport) ParseException(java.text.ParseException) File(java.io.File) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 20 with ResolveOptions

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());
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ResolveReport(org.apache.ivy.core.report.ResolveReport) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Aggregations

ResolveOptions (org.apache.ivy.core.resolve.ResolveOptions)36 File (java.io.File)23 IvySettings (org.apache.ivy.core.settings.IvySettings)21 ResolveData (org.apache.ivy.core.resolve.ResolveData)19 Before (org.junit.Before)16 ResolveReport (org.apache.ivy.core.report.ResolveReport)13 ResolveEngine (org.apache.ivy.core.resolve.ResolveEngine)13 EventManager (org.apache.ivy.core.event.EventManager)12 SortEngine (org.apache.ivy.core.sort.SortEngine)12 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)10 IOException (java.io.IOException)7 ParseException (java.text.ParseException)6 Ivy (org.apache.ivy.Ivy)6 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)6 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)6 URL (java.net.URL)5 HashSet (java.util.HashSet)5 RepositoryCacheManager (org.apache.ivy.core.cache.RepositoryCacheManager)5 BuildException (org.apache.tools.ant.BuildException)5 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)3