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()]);
}
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);
}
}
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);
}
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);
}
}
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;
}
}
Aggregations