org.apache.ivy.core.resolve.ResolveOptions Java Examples

The following examples show how to use org.apache.ivy.core.resolve.ResolveOptions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IvyRepositoryReport.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
private void genreport(ResolutionCacheManager cache, String organisation, String module) {
    // first process the report with xslt
    XSLTProcess xslt = new XSLTProcess();
    xslt.setTaskName(getTaskName());
    xslt.setProject(getProject());
    xslt.init();

    String resolveId = ResolveOptions.getDefaultResolveId(new ModuleId(organisation, module));
    xslt.setIn(cache.getConfigurationResolveReportInCache(resolveId, "default"));
    xslt.setOut(new File(getTodir(), outputname + "." + xslext));

    xslt.setStyle(xslFile);

    XSLTProcess.Param xslExt = xslt.createParam();
    xslExt.setName("extension");
    xslExt.setExpression(xslext);

    // add the provided XSLT parameters
    for (XSLTProcess.Param param : params) {
        XSLTProcess.Param realParam = xslt.createParam();
        realParam.setName(param.getName());
        realParam.setExpression(param.getExpression());
    }

    xslt.execute();
}
 
Example #2
Source File: MavenResolver.java    From IJava with MIT License 6 votes vote down vote up
private List<File> resolveFromIvyFile(Ivy ivy, File ivyFile, List<String> scopes) throws IOException, ParseException {
    ResolveOptions resolveOptions = new ResolveOptions();
    resolveOptions.setTransitive(true);
    resolveOptions.setDownload(true);
    resolveOptions.setConfs(!scopes.isEmpty()
            ? scopes.toArray(new String[0])
            : DEFAULT_RESOLVE_CONFS
    );

    ResolveReport resolved = ivy.resolve(ivyFile, resolveOptions);
    if (resolved.hasError())
        // TODO better error...
        throw new RuntimeException("Error resolving '" + ivyFile + "'. " + resolved.getAllProblemMessages());

    return Arrays.stream(resolved.getAllArtifactsReports())
            .map(ArtifactDownloadReport::getLocalFile)
            .collect(Collectors.toList());
}
 
Example #3
Source File: PackagerResolverTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    Message.setDefaultLogger(new DefaultMessageLogger(99));

    settings = new IvySettings();
    ResolveEngine engine = new ResolveEngine(settings, new EventManager(), new SortEngine(
            settings));
    cache = new File("build/cache");
    data = new ResolveData(engine, new ResolveOptions());
    cache.mkdirs();
    settings.setDefaultCache(cache);

    // Create work space with build and resource cache directories
    workdir = new File("build/test/PackagerResolverTest");
    builddir = new File(workdir, "build");
    cachedir = new File(workdir, "resources");
    cleanupTempDirs();
    if (!builddir.mkdirs() || !cachedir.mkdirs()) {
        throw new Exception("can't create directories under " + workdir);
    }
}
 
Example #4
Source File: MirroredURLResolverTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    settings = new IvySettings();
    engine = new ResolveEngine(settings, new EventManager(), new SortEngine(settings));
    data = new ResolveData(engine, new ResolveOptions());
    TestHelper.createCache();
    settings.setDefaultCache(TestHelper.cache);
    settings.setVariable("test.mirroredurl.mirrorlist-solo.url",
        this.getClass().getResource("mirrorlist-solo.txt").toExternalForm());
    settings.setVariable("test.mirroredurl.mirrorlist-failover.url", this.getClass()
            .getResource("mirrorlist-failover.txt").toExternalForm());
    settings.setVariable("test.mirroredurl.mirrorlist-fail.url",
        this.getClass().getResource("mirrorlist-fail.txt").toExternalForm());
    new XmlSettingsParser(settings).parse(MirroredURLResolverTest.class
            .getResource("mirror-resolver-settings.xml"));
}
 
Example #5
Source File: RetrieveTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example #6
Source File: IvyArtifactProperty.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
public void doExecute() throws BuildException {
    prepareAndCheck();

    try {
        ResolutionCacheManager cacheMgr = getIvyInstance().getResolutionCacheManager();
        String resolveId = getResolveId();
        if (resolveId == null) {
            resolveId = ResolveOptions.getDefaultResolveId(getResolvedModuleId());
        }
        XmlReportParser parser = new XmlReportParser();
        for (String conf : splitToArray(getConf())) {
            File report = cacheMgr.getConfigurationResolveReportInCache(resolveId, conf);
            parser.parse(report);

            for (Artifact artifact : parser.getArtifacts()) {
                String name = IvyPatternHelper.substitute(getSettings().substitute(getName()),
                        artifact, conf);
                String value = IvyPatternHelper.substitute(
                        getSettings().substitute(getValue()), artifact, conf);
                setProperty(name, value);
            }
        }
    } catch (Exception ex) {
        throw new BuildException("impossible to add artifact properties: " + ex, ex);
    }
}
 
Example #7
Source File: Ivy14.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private ResolveOptions newResolveOptions(String[] confs, String revision, File cache, Date date,
        boolean validate, boolean useCacheOnly, boolean transitive, boolean useOrigin,
        boolean download, boolean outputReport, Filter<Artifact> artifactFilter) {
    if (useOrigin) {
        ivy.getSettings().useDeprecatedUseOrigin();
    }
    return new ResolveOptions().setConfs(confs).setRevision(revision).setValidate(validate)
            .setUseCacheOnly(useCacheOnly).setTransitive(transitive).setDownload(download)
            .setOutputReport(outputReport).setArtifactFilter(artifactFilter);
}
 
Example #8
Source File: ResolverManifestIterable.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public ResolverManifestIterator() {
    organisations = resolver.listOrganisations();
    IvySettings settings = new IvySettings();
    ResolveEngine engine = new ResolveEngine(settings, new EventManager(), new SortEngine(
            settings));
    data = new ResolveData(engine, new ResolveOptions());
}
 
Example #9
Source File: IvyResolve.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private ResolveOptions getResolveOptions(Ivy ivy, String[] confs, IvySettings settings) {
    if (useOrigin) {
        settings.useDeprecatedUseOrigin();
    }
    return ((ResolveOptions) new ResolveOptions().setLog(log)).setConfs(confs)
            .setValidate(doValidate(settings))
            .setArtifactFilter(FilterHelper.getArtifactTypeFilter(type)).setRevision(revision)
            .setDate(getPubDate(pubdate, null)).setUseCacheOnly(useCacheOnly)
            .setRefresh(refresh).setTransitive(transitive).setResolveMode(resolveMode)
            .setResolveId(resolveId).setCheckIfChanged(checkIfChanged);
}
 
Example #10
Source File: IBiblioResolverTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    settings = new IvySettings();
    engine = new ResolveEngine(settings, new EventManager(), new SortEngine(settings));
    data = new ResolveData(engine, new ResolveOptions());
    TestHelper.createCache();
    settings.setDefaultCache(TestHelper.cache);
}
 
Example #11
Source File: PublishEngineTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private ResolvedModuleRevision resolveModule(IvySettings settings, FileSystemResolver resolver,
        String module) throws ParseException {
    return resolver.getDependency(
        new DefaultDependencyDescriptor(ModuleRevisionId.parse(module), false),
        new ResolveData(new ResolveEngine(settings, new EventManager(),
                new SortEngine(settings)), new ResolveOptions()));
}
 
Example #12
Source File: RetrieveTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnpackSync() throws Exception {
    ResolveOptions roptions = getResolveOptions(new String[] {"*"});

    URL url = new File("test/repositories/1/packaging/module1/ivys/ivy-1.0.xml").toURI()
            .toURL();

    // normal resolve, the file goes in the cache
    ResolveReport report = ivy.resolve(url, roptions);
    assertFalse(report.hasError());
    ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull(md);

    String pattern = "build/test/retrieve/[organization]/[module]/[conf]/[type]s/[artifact]-[revision](.[ext])";

    ivy.retrieve(md.getModuleRevisionId(),
        getRetrieveOptions().setSync(true).setDestArtifactPattern(pattern));

    File dest = new File("build/test/retrieve/packaging/module2/default/jars/module2-1.0");
    assertTrue(dest.exists());
    assertTrue(dest.isDirectory());
    File[] jarContents = dest.listFiles();
    Arrays.sort(jarContents);
    assertEquals(new File(dest, "META-INF"), jarContents[0]);
    assertEquals(new File(dest, "test.txt"), jarContents[1]);
    assertEquals(new File(dest, "META-INF/MANIFEST.MF"), jarContents[0].listFiles()[0]);
}
 
Example #13
Source File: IvyRepositoryReport.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private void gen(ResolutionCacheManager cache, String organisation, String module,
        String style, String ext) {
    XSLTProcess xslt = new XSLTProcess();
    xslt.setTaskName(getTaskName());
    xslt.setProject(getProject());
    xslt.init();

    String resolveId = ResolveOptions.getDefaultResolveId(new ModuleId(organisation, module));
    xslt.setIn(cache.getConfigurationResolveReportInCache(resolveId, "default"));
    xslt.setOut(new File(getTodir(), outputname + "." + ext));
    xslt.setBasedir(cache.getResolutionCacheRoot());
    xslt.setStyle(style);
    xslt.execute();
}
 
Example #14
Source File: Ivy.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public ResolveReport resolve(ModuleRevisionId mrid, ResolveOptions options, boolean changing)
        throws ParseException, IOException {
    pushContext();
    try {
        return resolveEngine.resolve(mrid, options, changing);
    } finally {
        popContext();
    }
}
 
Example #15
Source File: Ivy.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public ResolveReport resolve(URL ivySource, ResolveOptions options) throws ParseException,
        IOException {
    pushContext();
    try {
        return resolveEngine.resolve(ivySource, options);
    } finally {
        popContext();
    }
}
 
Example #16
Source File: FileSystemResolverTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    settings = new IvySettings();
    engine = new ResolveEngine(settings, new EventManager(), new SortEngine(settings));
    cache = new File("build/cache");
    data = new ResolveData(engine, new ResolveOptions());
    cache.mkdirs();
    settings.setDefaultCache(cache);
    cacheManager = (DefaultRepositoryCacheManager) settings.getDefaultRepositoryCacheManager();
}
 
Example #17
Source File: URLResolverTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    settings = new IvySettings();
    engine = new ResolveEngine(settings, new EventManager(), new SortEngine(settings));
    data = new ResolveData(engine, new ResolveOptions());
    TestHelper.createCache();
    settings.setDefaultCache(TestHelper.cache);
}
 
Example #18
Source File: BintrayResolverTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    settings = new IvySettings();
    engine = new ResolveEngine(settings, new EventManager(), new SortEngine(settings));
    data = new ResolveData(engine, new ResolveOptions());
    settings.setDefaultCache(TestHelper.cache);
}
 
Example #19
Source File: Main.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private static void outputCachePath(Ivy ivy, File cache, ModuleDescriptor md, String[] confs,
        String outFile) {
    try {
        StringBuilder buf = new StringBuilder();
        Collection<ArtifactDownloadReport> all = new LinkedHashSet<>();
        ResolutionCacheManager cacheMgr = ivy.getResolutionCacheManager();
        XmlReportParser parser = new XmlReportParser();
        for (String conf : confs) {
            String resolveId = ResolveOptions.getDefaultResolveId(md);
            File report = cacheMgr.getConfigurationResolveReportInCache(resolveId, conf);
            parser.parse(report);

            all.addAll(Arrays.asList(parser.getArtifactReports()));
        }
        for (ArtifactDownloadReport artifact : all) {
            if (artifact.getLocalFile() != null) {
                buf.append(artifact.getLocalFile().getCanonicalPath());
                buf.append(File.pathSeparator);
            }
        }

        PrintWriter writer = new PrintWriter(new FileOutputStream(outFile));
        if (buf.length() > 0) {
            buf.setLength(buf.length() - File.pathSeparator.length());
            writer.println(buf);
        }
        writer.close();
        System.out.println("cachepath output to " + outFile);

    } catch (Exception ex) {
        throw new RuntimeException("impossible to build ivy cache path: " + ex.getMessage(), ex);
    }
}
 
Example #20
Source File: Maven2LocalTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    settings = new IvySettings();
    engine = new ResolveEngine(settings, new EventManager(), new SortEngine(settings));
    cache = new File("build/cache");
    data = new ResolveData(engine, new ResolveOptions());
    cache.mkdirs();
    settings.setDefaultCache(cache);
}
 
Example #21
Source File: RetrieveTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnpack() throws Exception {
    ResolveOptions roptions = getResolveOptions(new String[] {"*"});

    URL url = new File("test/repositories/1/packaging/module1/ivys/ivy-1.0.xml").toURI()
            .toURL();

    // normal resolve, the file goes in the cache
    ResolveReport report = ivy.resolve(url, roptions);
    assertFalse(report.hasError());
    ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull(md);

    String pattern = "build/test/retrieve/[organization]/[module]/[conf]/[type]s/[artifact]-[revision](.[ext])";

    ivy.retrieve(md.getModuleRevisionId(),
        getRetrieveOptions().setDestArtifactPattern(pattern));

    File dest = new File("build/test/retrieve/packaging/module2/default/jars/module2-1.0");
    assertTrue(dest.exists());
    assertTrue(dest.isDirectory());
    File[] jarContents = dest.listFiles();
    Arrays.sort(jarContents);
    assertEquals(new File(dest, "META-INF"), jarContents[0]);
    assertEquals(new File(dest, "test.txt"), jarContents[1]);
    assertEquals(new File(dest, "META-INF/MANIFEST.MF"), jarContents[0].listFiles()[0]);
}
 
Example #22
Source File: JarResolverTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    settings = new IvySettings();
    engine = new ResolveEngine(settings, new EventManager(), new SortEngine(settings));
    cache = new File("build/cache");
    data = new ResolveData(engine, new ResolveOptions());
    cache.mkdirs();
    settings.setDefaultCache(cache);
    cacheManager = (DefaultRepositoryCacheManager) settings.getDefaultRepositoryCacheManager();
}
 
Example #23
Source File: ConfigurationResolveReport.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public ConfigurationResolveReport(ResolveEngine resolveEngine, ModuleDescriptor md,
        String conf, Date date, ResolveOptions options) {
    this.resolveEngine = resolveEngine;
    this.md = md;
    this.conf = conf;
    this.date = date;
    this.options = options;
}
 
Example #24
Source File: IvyRepResolverTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    settings = new IvySettings();
    engine = new ResolveEngine(settings, new EventManager(), new SortEngine(settings));
    data = new ResolveData(engine, new ResolveOptions());
    TestHelper.createCache();
    settings.setDefaultCache(TestHelper.cache);
}
 
Example #25
Source File: XmlReportOutputter.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public void output(ResolveReport report, ResolutionCacheManager cacheMgr, ResolveOptions options)
        throws IOException {
    String[] confs = report.getConfigurations();
    for (String conf : confs) {
        output(report.getConfigurationReport(conf), report.getResolveId(), confs, cacheMgr);
    }
}
 
Example #26
Source File: ChainResolverTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    settings = new IvySettings();
    engine = new ResolveEngine(settings, new EventManager(), new SortEngine(settings));
    TestHelper.createCache();
    data = new ResolveData(engine, new ResolveOptions());
    settings.setDefaultCache(TestHelper.cache);
}
 
Example #27
Source File: DualResolverTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    settings = new IvySettings();
    engine = new ResolveEngine(settings, new EventManager(), new SortEngine(settings));
    cache = new File("build/cache");
    data = new ResolveData(engine, new ResolveOptions());
    cache.mkdirs();
    settings.setDefaultCache(cache);
}
 
Example #28
Source File: ArtifactLockStrategyTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private ResolvedModuleRevision resolveModule(IvySettings settings, FileSystemResolver resolver,
        String module) throws ParseException {
    return resolver.getDependency(
        new DefaultDependencyDescriptor(ModuleRevisionId.parse(module), false),
        new ResolveData(new ResolveEngine(settings, new EventManager(),
                new SortEngine(settings)), new ResolveOptions()));
}
 
Example #29
Source File: OBRResolverTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private void genericTestResolve(String jarName, String conf, ModuleRevisionId[] expectedMrids,
        ModuleRevisionId[] expected2Mrids) throws Exception {
    JarInputStream jis = new JarInputStream(
            new FileInputStream("test/test-repo/bundlerepo/" + jarName));
    Manifest manifest = jis.getManifest();
    jis.close();
    BundleInfo bundleInfo = ManifestParser.parseManifest(manifest);
    bundleInfo.addArtifact(new BundleArtifact(false, new File("test/test-repo/bundlerepo/"
            + jarName).toURI(), null));
    DefaultModuleDescriptor md = BundleInfoAdapter.toModuleDescriptor(
        OSGiManifestParser.getInstance(), null, bundleInfo, profileProvider);
    ResolveReport resolveReport = ivy.resolve(md,
        new ResolveOptions().setConfs(new String[] {conf}).setOutputReport(false));
    assertFalse("resolve failed " + resolveReport.getAllProblemMessages(),
        resolveReport.hasError());
    Set<ModuleRevisionId> actual = new HashSet<>();
    for (Artifact artifact : resolveReport.getArtifacts()) {
        actual.add(artifact.getModuleRevisionId());
    }
    Set<ModuleRevisionId> expected = new HashSet<>(Arrays.asList(expectedMrids));
    if (expected2Mrids != null) {
        // in this use case, we have two choices, let's try the second one
        try {
            Set<ModuleRevisionId> expected2 = new HashSet<>(
                    Arrays.asList(expected2Mrids));
            assertEquals(expected2, actual);
            return; // test passed
        } catch (AssertionError e) {
            // too bad, let's continue
        }
    }
    assertEquals(expected, actual);
}
 
Example #30
Source File: OBRResolverTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
private void genericTestFailingResolve(String jarName, String conf) throws Exception {
    JarInputStream jis = new JarInputStream(
            new FileInputStream("test/test-repo/bundlerepo/" + jarName));
    Manifest manifest = jis.getManifest();
    jis.close();
    BundleInfo bundleInfo = ManifestParser.parseManifest(manifest);
    bundleInfo.addArtifact(new BundleArtifact(false, new File("test/test-repo/bundlerepo/"
            + jarName).toURI(), null));
    DefaultModuleDescriptor md = BundleInfoAdapter.toModuleDescriptor(
        OSGiManifestParser.getInstance(), null, bundleInfo, manifest, profileProvider);
    ResolveReport resolveReport = ivy.resolve(md,
        new ResolveOptions().setConfs(new String[] {conf}).setOutputReport(false));
    assertTrue(resolveReport.hasError());
}