Search in sources :

Example 1 with ResolveReport

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

the class IvyInstall method doExecute.

public void doExecute() throws BuildException {
    Ivy ivy = getIvyInstance();
    IvySettings settings = ivy.getSettings();
    if (organisation == null) {
        throw new BuildException("no organisation provided for ivy publish task: " + "It can either be set explicitly via the attribute 'organisation' " + "or via 'ivy.organisation' property or a prior call to <resolve/>");
    }
    if (module == null) {
        if (PatternMatcher.EXACT.equals(matcher)) {
            throw new BuildException("no module name provided for ivy publish task: " + "It can either be set explicitly via the attribute 'module' " + "or via 'ivy.module' property or a prior call to <resolve/>");
        }
        module = PatternMatcher.ANY_EXPRESSION;
    }
    if (revision == null) {
        if (PatternMatcher.EXACT.equals(matcher)) {
            throw new BuildException("no module revision provided for ivy publish task: " + "It can either be set explicitly via the attribute 'revision' " + "or via 'ivy.revision' property or a prior call to <resolve/>");
        }
        revision = PatternMatcher.ANY_EXPRESSION;
    }
    if (branch == null) {
        if (PatternMatcher.EXACT.equals(matcher)) {
            branch = settings.getDefaultBranch(ModuleId.newInstance(organisation, module));
        } else {
            branch = PatternMatcher.ANY_EXPRESSION;
        }
    }
    if (from == null) {
        throw new BuildException("no from resolver name: please provide it through parameter 'from'");
    }
    if (to == null) {
        throw new BuildException("no to resolver name: please provide it through parameter 'to'");
    }
    ModuleRevisionId mrid = ModuleRevisionId.newInstance(organisation, module, branch, revision);
    ResolveReport report;
    try {
        report = ivy.install(mrid, from, to, new InstallOptions().setTransitive(transitive).setValidate(doValidate(settings)).setOverwrite(overwrite).setConfs(conf.split(",")).setArtifactFilter(FilterHelper.getArtifactTypeFilter(type)).setMatcherName(matcher).setInstallOriginalMetadata(installOriginalMetadata));
    } catch (Exception e) {
        throw new BuildException("impossible to install " + mrid + ": " + e, e);
    }
    if (report.hasError() && isHaltonfailure()) {
        throw new BuildException("Problem happened while installing modules - see output for details");
    }
}
Also used : ResolveReport(org.apache.ivy.core.report.ResolveReport) IvySettings(org.apache.ivy.core.settings.IvySettings) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) InstallOptions(org.apache.ivy.core.install.InstallOptions) BuildException(org.apache.tools.ant.BuildException) Ivy(org.apache.ivy.Ivy) BuildException(org.apache.tools.ant.BuildException)

Example 2 with ResolveReport

use of org.apache.ivy.core.report.ResolveReport 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);
    }
}
Also used : ResolutionCacheManager(org.apache.ivy.core.cache.ResolutionCacheManager) IvySettings(org.apache.ivy.core.settings.IvySettings) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) Ivy(org.apache.ivy.Ivy) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) ModuleId(org.apache.ivy.core.module.id.ModuleId) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) XmlReportOutputter(org.apache.ivy.plugins.report.XmlReportOutputter) ResolveReport(org.apache.ivy.core.report.ResolveReport) BuildException(org.apache.tools.ant.BuildException) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) File(java.io.File) HashSet(java.util.HashSet)

Example 3 with ResolveReport

use of org.apache.ivy.core.report.ResolveReport 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);
    }
}
Also used : DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ResolveReport(org.apache.ivy.core.report.ResolveReport) Configuration(org.apache.ivy.core.module.descriptor.Configuration) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ParseException(java.text.ParseException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions)

Example 4 with ResolveReport

use of org.apache.ivy.core.report.ResolveReport 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);
    }
}
Also used : MetadataArtifactDownloadReport(org.apache.ivy.core.report.MetadataArtifactDownloadReport) Configuration(org.apache.ivy.core.module.descriptor.Configuration) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) MetadataArtifactDownloadReport(org.apache.ivy.core.report.MetadataArtifactDownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) Date(java.util.Date) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver) ModuleId(org.apache.ivy.core.module.id.ModuleId) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) NoConflictManager(org.apache.ivy.plugins.conflict.NoConflictManager) ResolveReport(org.apache.ivy.core.report.ResolveReport) DownloadOptions(org.apache.ivy.core.resolve.DownloadOptions) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ExactPatternMatcher(org.apache.ivy.plugins.matcher.ExactPatternMatcher) PatternMatcher(org.apache.ivy.plugins.matcher.PatternMatcher) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) File(java.io.File) IvyNode(org.apache.ivy.core.resolve.IvyNode)

Example 5 with ResolveReport

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

the class IvyPostResolveTaskTest method testWithPreviousResolveInSameBuildAndWildcard.

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

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