Search in sources :

Example 11 with ResolveReport

use of org.apache.ivy.core.report.ResolveReport in project ant-ivy by apache.

the class IvyPostResolveTaskTest method testWithResolveIdAndPreviousResolveInSameBuildAndLessConfs.

@Test
public void testWithResolveIdAndPreviousResolveInSameBuildAndLessConfs() {
    IvyResolve resolve = new IvyResolve();
    resolve.setProject(project);
    resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-multiconf.xml"));
    resolve.setConf("default,compile");
    resolve.setResolveId("testResolveId");
    resolve.execute();
    ResolveReport report1 = project.getReference("ivy.resolved.report.testResolveId");
    // perform another resolve
    resolve = new IvyResolve();
    resolve.setProject(project);
    resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml"));
    resolve.setConf("*");
    resolve.execute();
    ResolveReport reportBefore = project.getReference("ivy.resolved.report");
    task.setConf("default");
    task.setResolveId("testResolveId");
    task.execute();
    ResolveReport reportAfter = project.getReference("ivy.resolved.report");
    ResolveReport report2 = project.getReference("ivy.resolved.report.testResolveId");
    assertSame("IvyPostResolveTask has performed a resolve where it shouldn't", reportBefore, reportAfter);
    assertSame("IvyPostResolveTask has performed a resolve where it shouldn't", report1, report2);
}
Also used : ResolveReport(org.apache.ivy.core.report.ResolveReport) File(java.io.File) Test(org.junit.Test)

Example 12 with ResolveReport

use of org.apache.ivy.core.report.ResolveReport in project ant-ivy by apache.

the class IvyAntSettingsBuildFileTest method testSettingsWithIdIvyInstance.

/**
 * Test case for IVY-925.
 *
 * @see <a href="https://issues.apache.org/jira/browse/IVY-925">IVY-925</a>
 */
@Test
public void testSettingsWithIdIvyInstance() {
    buildRule.executeTarget("testSettingsWithPropertyAsId");
    ResolveReport report = buildRule.getProject().getReference("ivy.resolved.report");
    assertNotNull(report);
    assertFalse(report.hasError());
    assertEquals(1, report.getDependencies().size());
}
Also used : ResolveReport(org.apache.ivy.core.report.ResolveReport) Test(org.junit.Test)

Example 13 with ResolveReport

use of org.apache.ivy.core.report.ResolveReport in project ant-ivy by apache.

the class IvyAntSettingsBuildFileTest method testOverrideSetToFalse.

@Test
public void testOverrideSetToFalse() {
    buildRule.executeTarget("testOverrideSetToFalse");
    ResolveReport report = buildRule.getProject().getReference("ivy.resolved.report");
    assertNotNull(report);
    assertFalse(report.hasError());
    assertEquals(1, report.getDependencies().size());
}
Also used : ResolveReport(org.apache.ivy.core.report.ResolveReport) Test(org.junit.Test)

Example 14 with ResolveReport

use of org.apache.ivy.core.report.ResolveReport 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;
}
Also used : IvySettings(org.apache.ivy.core.settings.IvySettings) RetrieveOptions(org.apache.ivy.core.retrieve.RetrieveOptions) PublishOptions(org.apache.ivy.core.publish.PublishOptions) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ResolveReport(org.apache.ivy.core.report.ResolveReport) ResolveProcessException(org.apache.ivy.core.resolve.ResolveProcessException) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) PropertiesFile(org.apache.ivy.util.PropertiesFile) File(java.io.File) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) PomWriterOptions(org.apache.ivy.plugins.parser.m2.PomWriterOptions)

Example 15 with ResolveReport

use of org.apache.ivy.core.report.ResolveReport in project ant-ivy by apache.

the class FixDepsTask method doExecute.

@Override
public void doExecute() throws BuildException {
    prepareAndCheck();
    if (dest == null) {
        throw new BuildException("Missing required parameter 'tofile'");
    }
    if (dest.exists() && dest.isDirectory()) {
        throw new BuildException("The destination file '" + dest.getAbsolutePath() + "' already exist and is a folder");
    }
    ResolveReport report = getResolvedReport();
    List<ModuleId> midToKeep = new ArrayList<>();
    for (Keep keep : keeps) {
        midToKeep.add(ModuleId.newInstance(keep.org, keep.module));
    }
    ModuleDescriptor md = report.toFixedModuleDescriptor(getSettings(), midToKeep);
    try {
        XmlModuleDescriptorWriter.write(md, dest);
    } catch (IOException e) {
        throw new BuildException("Failed to write into the file " + dest.getAbsolutePath() + " (" + e.getMessage() + ")", e);
    }
}
Also used : ModuleId(org.apache.ivy.core.module.id.ModuleId) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ResolveReport(org.apache.ivy.core.report.ResolveReport) ArrayList(java.util.ArrayList) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException)

Aggregations

ResolveReport (org.apache.ivy.core.report.ResolveReport)278 Test (org.junit.Test)259 File (java.io.File)253 ConfigurationResolveReport (org.apache.ivy.core.report.ConfigurationResolveReport)218 JarFile (java.util.jar.JarFile)199 Ivy (org.apache.ivy.Ivy)102 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)101 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)94 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)15 ResolveOptions (org.apache.ivy.core.resolve.ResolveOptions)13 BuildException (org.apache.tools.ant.BuildException)9 URL (java.net.URL)8 HashMap (java.util.HashMap)8 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)8 DefaultRepositoryCacheManager (org.apache.ivy.core.cache.DefaultRepositoryCacheManager)7 Artifact (org.apache.ivy.core.module.descriptor.Artifact)7 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)6