use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.
the class AbstractWorkspaceResolver method checkCandidate.
protected ResolvedModuleRevision checkCandidate(DependencyDescriptor dd, ModuleDescriptor md, String workspaceModuleName) {
if (workspaceModuleName == null) {
workspaceModuleName = dd.getDependencyId().toString();
}
ModuleRevisionId dependencyMrid = dd.getDependencyRevisionId();
String org = dependencyMrid.getModuleId().getOrganisation();
String module = dependencyMrid.getModuleId().getName();
VersionMatcher versionMatcher = getSettings().getVersionMatcher();
ModuleRevisionId candidateMrid = md.getModuleRevisionId();
switch(org) {
case BundleInfo.BUNDLE_TYPE:
// looking for an OSGi bundle via its symbolic name
String sn = md.getExtraInfoContentByTagName("Bundle-SymbolicName");
if (sn == null || !module.equals(sn)) {
// not found, skip to next
return null;
}
break;
case BundleInfo.PACKAGE_TYPE:
// looking for an OSGi bundle via its exported package
String exportedPackages = md.getExtraInfoContentByTagName("Export-Package");
if (exportedPackages == null) {
// not found, skip to next
return null;
}
boolean found = false;
String version = null;
ManifestHeaderValue exportElements;
try {
exportElements = new ManifestHeaderValue(exportedPackages);
} catch (ParseException e) {
// wrong OSGi header: skip it
return null;
}
for (ManifestHeaderElement exportElement : exportElements.getElements()) {
if (exportElement.getValues().contains(module)) {
found = true;
version = exportElement.getAttributes().get("version");
break;
}
}
if (!found) {
// not found, skip to next
return null;
}
if (version == null) {
// no version means anything can match. Let's trick the version matcher by
// setting the exact expected version
version = dependencyMrid.getRevision();
}
md.setResolvedModuleRevisionId(ModuleRevisionId.newInstance(org, module, version));
break;
default:
if (!candidateMrid.getModuleId().equals(dependencyMrid.getModuleId())) {
// it doesn't match org#module, skip to next
return null;
}
break;
}
Message.verbose("Workspace resolver found potential matching workspace module " + workspaceModuleName + " with module " + candidateMrid + " for module " + dependencyMrid);
if (!ignoreBranch) {
ModuleId mid = dependencyMrid.getModuleId();
String defaultBranch = getSettings().getDefaultBranch(mid);
String dependencyBranch = dependencyMrid.getBranch();
String candidateBranch = candidateMrid.getBranch();
if (dependencyBranch == null) {
dependencyBranch = defaultBranch;
}
if (candidateBranch == null) {
candidateBranch = defaultBranch;
}
if (dependencyBranch != candidateBranch) {
// Both cannot be null
if (dependencyBranch == null || candidateBranch == null) {
Message.verbose("\t\trejected since branches doesn't match (one is set, the other isn't)");
return null;
}
if (!dependencyBranch.equals(candidateBranch)) {
Message.verbose("\t\trejected since branches doesn't match");
return null;
}
}
}
// Found one; check if it is for the module we need
if (!ignoreVersion && !md.getModuleRevisionId().getRevision().equals(Ivy.getWorkingRevision()) && !versionMatcher.accept(dd.getDependencyRevisionId(), md)) {
Message.verbose("\t\treject as version didn't match");
return null;
}
if (ignoreVersion) {
Message.verbose("\t\tmatched (version are ignored)");
} else {
Message.verbose("\t\tversion matched");
}
WorkspaceModuleDescriptor workspaceMd = createWorkspaceMd(md);
Artifact mdaf = md.getMetadataArtifact();
if (mdaf == null) {
mdaf = new DefaultArtifact(md.getModuleRevisionId(), md.getPublicationDate(), workspaceModuleName, "ivy", "");
}
MetadataArtifactDownloadReport madr = new MetadataArtifactDownloadReport(mdaf);
madr.setDownloadStatus(DownloadStatus.SUCCESSFUL);
madr.setSearched(true);
return new ResolvedModuleRevision(this, this, workspaceMd, madr);
}
use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.
the class IvyInfo method doExecute.
public void doExecute() throws BuildException {
Ivy ivy = getIvyInstance();
IvySettings settings = ivy.getSettings();
try {
if (organisation != null || module != null || revision != null || branch != null) {
if (organisation == null) {
throw new BuildException("no organisation provided for ivy info task");
}
if (module == null) {
throw new BuildException("no module name provided for ivy info task");
}
if (revision == null) {
throw new BuildException("no revision provided for ivy info task");
}
if (branch == null) {
settings.getDefaultBranch(new ModuleId(organisation, module));
}
ResolvedModuleRevision rmr = ivy.findModule(ModuleRevisionId.newInstance(organisation, module, branch, revision));
if (rmr != null) {
ModuleDescriptor md = rmr.getDescriptor();
ModuleRevisionId mrid = rmr.getId();
setProperties(md, mrid);
}
} else {
if (file == null) {
file = getProject().resolveFile(getProperty(settings, "ivy.dep.file"));
}
ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance().parseDescriptor(settings, file.toURI().toURL(), doValidate(settings));
ModuleRevisionId mrid = md.getModuleRevisionId();
setProperties(md, mrid);
}
} catch (MalformedURLException e) {
throw new BuildException("unable to convert given ivy file to url: " + file + ": " + e, e);
} catch (ParseException e) {
log(e.getMessage(), Project.MSG_ERR);
throw new BuildException("syntax errors in ivy file: " + e, e);
} catch (Exception e) {
throw new BuildException("impossible to resolve dependencies: " + e, e);
}
}
use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.
the class IvyReport method doExecute.
public void doExecute() throws BuildException {
Ivy ivy = getIvyInstance();
IvySettings settings = ivy.getSettings();
conf = getProperty(conf, settings, "ivy.resolved.configurations", resolveId);
if ("*".equals(conf)) {
conf = getProperty(settings, "ivy.resolved.configurations", resolveId);
}
if (conf == null) {
throw new BuildException("no conf provided for ivy report task: " + "It can either be set explicitly via the attribute 'conf' or " + "via 'ivy.resolved.configurations' property or a prior call to <resolve/>");
}
if (todir == null) {
String t = getProperty(settings, "ivy.report.todir");
if (t != null) {
todir = getProject().resolveFile(t);
}
}
if (todir != null && todir.exists()) {
todir.mkdirs();
}
outputpattern = getProperty(outputpattern, settings, "ivy.report.output.pattern");
if (outputpattern == null) {
outputpattern = "[organisation]-[module]-[conf].[ext]";
}
if (todir != null && todir.exists() && !todir.isDirectory()) {
throw new BuildException("destination directory should be a directory !");
}
if (resolveId == null) {
organisation = getProperty(organisation, settings, "ivy.organisation", resolveId);
module = getProperty(module, settings, "ivy.module", resolveId);
if (organisation == null) {
throw new BuildException("no organisation provided for ivy report 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) {
throw new BuildException("no module name provided for ivy report task: " + "It can either be set explicitly via the attribute 'module' or " + "via 'ivy.module' property or a prior call to <resolve/>");
}
resolveId = ResolveOptions.getDefaultResolveId(new ModuleId(organisation, module));
}
try {
String[] confs = splitToArray(conf);
if (xsl) {
genreport(confs);
}
if (xml) {
genxml(confs);
}
if (graph) {
genStyled(confs, getStylePath("ivy-report-graph.xsl"), "graphml");
}
if (dot) {
genStyled(confs, getStylePath("ivy-report-dot.xsl"), "dot");
}
} catch (IOException e) {
throw new BuildException("impossible to generate report: " + e, e);
}
}
use of org.apache.ivy.core.module.id.ModuleId 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.module.id.ModuleId in project ant-ivy by apache.
the class IvyRepositoryReport method gen.
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();
}
Aggregations