Search in sources :

Example 1 with ResolutionCacheManager

use of org.apache.ivy.core.cache.ResolutionCacheManager in project ant-ivy by apache.

the class IvyPostResolveTask method getConfsToResolve.

private String[] getConfsToResolve(ModuleDescriptor reference, String conf, String[] rconfs) {
    Message.debug("calculating configurations to resolve");
    if (reference == null) {
        Message.debug("module not yet resolved, all confs still need to be resolved");
        if (conf == null) {
            return new String[] { "*" };
        }
        return splitToArray(conf);
    }
    if (conf == null) {
        Message.debug("module already resolved, no configuration to resolve");
        return new String[0];
    }
    String[] confs;
    if ("*".equals(conf)) {
        confs = reference.getConfigurationsNames();
    } else {
        confs = splitToArray(conf);
    }
    Set<String> rconfsSet = new HashSet<>();
    // for each resolved configuration, check if the report still exists
    ResolutionCacheManager cache = getSettings().getResolutionCacheManager();
    for (String resolvedConf : rconfs) {
        String resolveId = getResolveId();
        if (resolveId == null) {
            resolveId = ResolveOptions.getDefaultResolveId(reference);
        }
        File report = cache.getConfigurationResolveReportInCache(resolveId, resolvedConf);
        // if the report does not exist any longer, we have to recreate it...
        if (report.exists()) {
            rconfsSet.add(resolvedConf);
        }
    }
    Set<String> confsSet = new HashSet<>(Arrays.asList(confs));
    Message.debug("resolved configurations:   " + rconfsSet);
    Message.debug("asked configurations:      " + confsSet);
    confsSet.removeAll(rconfsSet);
    Message.debug("to resolve configurations: " + confsSet);
    return confsSet.toArray(new String[confsSet.size()]);
}
Also used : ResolutionCacheManager(org.apache.ivy.core.cache.ResolutionCacheManager) File(java.io.File) HashSet(java.util.HashSet)

Example 2 with ResolutionCacheManager

use of org.apache.ivy.core.cache.ResolutionCacheManager in project ant-ivy by apache.

the class IvyReport method genxml.

private void genxml(String[] confs) throws IOException {
    ResolutionCacheManager cacheMgr = getIvyInstance().getResolutionCacheManager();
    for (String config : confs) {
        File xml = cacheMgr.getConfigurationResolveReportInCache(resolveId, config);
        File out;
        if (todir == null) {
            out = getProject().resolveFile(getOutputPattern(config, "xml"));
        } else {
            out = new File(todir, getOutputPattern(config, "xml"));
        }
        FileUtil.copy(xml, out, null);
    }
}
Also used : ResolutionCacheManager(org.apache.ivy.core.cache.ResolutionCacheManager) File(java.io.File)

Example 3 with ResolutionCacheManager

use of org.apache.ivy.core.cache.ResolutionCacheManager in project ant-ivy by apache.

the class IvyReport method getOutputPattern.

private String getOutputPattern(String conf, String ext) {
    if (mRevId == null) {
        ResolutionCacheManager cacheMgr = getIvyInstance().getResolutionCacheManager();
        XmlReportParser parser = new XmlReportParser();
        File reportFile = cacheMgr.getConfigurationResolveReportInCache(resolveId, conf);
        try {
            parser.parse(reportFile);
        } catch (ParseException e) {
            throw new BuildException("Error occurred while parsing reportfile '" + reportFile.getAbsolutePath() + "'", e);
        }
        // get the resolve module
        mRevId = parser.getResolvedModule();
    }
    return IvyPatternHelper.substitute(outputpattern, mRevId.getOrganisation(), mRevId.getName(), mRevId.getRevision(), "", "", ext, conf, mRevId.getQualifiedExtraAttributes(), null);
}
Also used : XmlReportParser(org.apache.ivy.plugins.report.XmlReportParser) ResolutionCacheManager(org.apache.ivy.core.cache.ResolutionCacheManager) ParseException(java.text.ParseException) BuildException(org.apache.tools.ant.BuildException) File(java.io.File)

Example 4 with ResolutionCacheManager

use of org.apache.ivy.core.cache.ResolutionCacheManager 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 5 with ResolutionCacheManager

use of org.apache.ivy.core.cache.ResolutionCacheManager in project ant-ivy by apache.

the class ConfigurationResolveReport method checkIfChanged.

/**
 * Check if the set of dependencies has changed since the previous execution of a resolution.
 * <p>
 * This function use the report file found in the cache. So the function must be called before
 * the new report is serialized there.
 * </p>
 * <p>
 * This function also use the internal dependencies that must already be filled. This function
 * might be 'heavy' because it may have to parse the previous report.
 * </p>
 */
public void checkIfChanged() {
    ResolutionCacheManager cache = resolveEngine.getSettings().getResolutionCacheManager();
    String resolveId = options.getResolveId();
    File previousReportFile = cache.getConfigurationResolveReportInCache(resolveId, conf);
    if (previousReportFile.exists()) {
        try {
            XmlReportParser parser = new XmlReportParser();
            parser.parse(previousReportFile);
            Set<ModuleRevisionId> previousDepSet = new HashSet<>(Arrays.asList(parser.getDependencyRevisionIds()));
            hasChanged = !previousDepSet.equals(getModuleRevisionIds());
        } catch (Exception e) {
            Message.warn("Error while parsing configuration resolve report " + previousReportFile.getAbsolutePath(), e);
            hasChanged = Boolean.TRUE;
        }
    } else {
        hasChanged = Boolean.TRUE;
    }
}
Also used : XmlReportParser(org.apache.ivy.plugins.report.XmlReportParser) ResolutionCacheManager(org.apache.ivy.core.cache.ResolutionCacheManager) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) File(java.io.File) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

File (java.io.File)16 ResolutionCacheManager (org.apache.ivy.core.cache.ResolutionCacheManager)16 XmlReportParser (org.apache.ivy.plugins.report.XmlReportParser)8 HashSet (java.util.HashSet)6 LinkedHashSet (java.util.LinkedHashSet)6 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)6 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)5 BuildException (org.apache.tools.ant.BuildException)5 IOException (java.io.IOException)4 FileOutputStream (java.io.FileOutputStream)3 URL (java.net.URL)3 ResolveReport (org.apache.ivy.core.report.ResolveReport)3 XmlReportOutputter (org.apache.ivy.plugins.report.XmlReportOutputter)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MalformedURLException (java.net.MalformedURLException)2 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Artifact (org.apache.ivy.core.module.descriptor.Artifact)2 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)2