use of org.apache.ivy.core.module.descriptor.ExtendsDescriptor in project ant-ivy by apache.
the class XmlModuleDescriptorWriter method printInfoTag.
private static void printInfoTag(ModuleDescriptor md, PrintWriter out) {
out.println("\t<info organisation=\"" + XMLHelper.escape(md.getModuleRevisionId().getOrganisation()) + "\"");
out.println("\t\tmodule=\"" + XMLHelper.escape(md.getModuleRevisionId().getName()) + "\"");
String branch = md.getResolvedModuleRevisionId().getBranch();
if (branch != null) {
out.println("\t\tbranch=\"" + XMLHelper.escape(branch) + "\"");
}
String revision = md.getResolvedModuleRevisionId().getRevision();
if (revision != null) {
out.println("\t\trevision=\"" + XMLHelper.escape(revision) + "\"");
}
out.println("\t\tstatus=\"" + XMLHelper.escape(md.getStatus()) + "\"");
out.println("\t\tpublication=\"" + DateUtil.format(md.getResolvedPublicationDate()) + "\"");
if (md.isDefault()) {
out.println("\t\tdefault=\"true\"");
}
if (md instanceof DefaultModuleDescriptor) {
DefaultModuleDescriptor dmd = (DefaultModuleDescriptor) md;
if (dmd.getNamespace() != null && !dmd.getNamespace().getName().equals("system")) {
out.println("\t\tnamespace=\"" + XMLHelper.escape(dmd.getNamespace().getName()) + "\"");
}
}
if (!md.getExtraAttributes().isEmpty()) {
printExtraAttributes(md, out, "\t\t");
out.println();
}
if (requireInnerInfoElement(md)) {
out.println("\t>");
for (ExtendsDescriptor parent : md.getInheritedDescriptors()) {
ModuleRevisionId mrid = parent.getParentRevisionId();
out.print(String.format("\t\t<extends organisation=\"%s\" module=\"%s\" revision=\"%s\"", XMLHelper.escape(mrid.getOrganisation()), XMLHelper.escape(mrid.getName()), XMLHelper.escape(mrid.getRevision())));
String location = parent.getLocation();
if (location != null) {
out.print(" location=\"" + XMLHelper.escape(location) + "\"");
}
out.print(" extendType=\"" + joinArray(parent.getExtendsTypes(), ",") + "\"");
out.println("/>");
}
License[] licenses = md.getLicenses();
for (License license : licenses) {
out.print("\t\t<license ");
if (license.getName() != null) {
out.print("name=\"" + XMLHelper.escape(license.getName()) + "\" ");
}
if (license.getUrl() != null) {
out.print("url=\"" + XMLHelper.escape(license.getUrl()) + "\" ");
}
out.println("/>");
}
if (md.getHomePage() != null || md.getDescription() != null) {
out.print("\t\t<description");
if (md.getHomePage() != null) {
out.print(" homepage=\"" + XMLHelper.escape(md.getHomePage()) + "\"");
}
if (isNullOrEmpty(md.getDescription())) {
out.println(" />");
} else {
out.println(">");
out.println("\t\t" + XMLHelper.escape(md.getDescription()));
out.println("\t\t</description>");
}
}
for (ExtraInfoHolder extraInfo : md.getExtraInfos()) {
printExtraInfoElement(out, extraInfo, 2);
}
out.println("\t</info>");
} else {
out.println("\t/>");
}
}
use of org.apache.ivy.core.module.descriptor.ExtendsDescriptor in project ant-ivy by apache.
the class ResolveTest method testIVY1347.
/**
* Test case for IVY-1347.
*
* @throws Exception if something goes wrong
* @see <a href="https://issues.apache.org/jira/browse/IVY-1347">IVY-1347</a>
*/
@Test
public void testIVY1347() throws Exception {
Ivy ivy = new Ivy();
ivy.configure(new File("test/repositories/IVY-1347/ivysettings.xml"));
ivy.getSettings().setDefaultCache(cache);
ResolveReport rr = ivy.resolve(new File("test/repositories/IVY-1347/childone/childtwo/ivy.xml"), getResolveOptions(new String[] { "*" }));
ModuleDescriptor md = rr.getModuleDescriptor();
assertNotNull(md);
ExtendsDescriptor[] parents = md.getInheritedDescriptors();
assertNotNull(parents);
assertEquals(1, parents.length);
ModuleRevisionId parent = parents[0].getParentRevisionId();
assertEquals(ModuleRevisionId.newInstance("foo", "parent", "1.0"), parent);
}
use of org.apache.ivy.core.module.descriptor.ExtendsDescriptor in project ant-ivy by apache.
the class DefaultResolutionCacheManager method saveLocalParents.
private void saveLocalParents(ModuleRevisionId baseMrevId, ModuleDescriptor md, File mdFile, Properties paths) throws ParseException, IOException {
for (ExtendsDescriptor parent : md.getInheritedDescriptors()) {
if (!parent.isLocal()) {
// we store only local parents in the cache!
continue;
}
ModuleDescriptor parentMd = parent.getParentMd();
ModuleRevisionId pRevId = ModuleRevisionId.newInstance(baseMrevId, baseMrevId.getRevision() + "-parent." + paths.size());
File parentFile = getResolvedIvyFileInCache(pRevId);
parentMd.toIvyFile(parentFile);
paths.setProperty(mdFile.getName() + "|" + parent.getLocation(), parentFile.getAbsolutePath());
saveLocalParents(baseMrevId, parentMd, parentFile, paths);
}
}
use of org.apache.ivy.core.module.descriptor.ExtendsDescriptor in project ant-ivy by apache.
the class IvyResolve method doExecute.
@Override
public void doExecute() throws BuildException {
Ivy ivy = getIvyInstance();
IvySettings settings = ivy.getSettings();
try {
conf = getProperty(conf, settings, "ivy.configurations");
type = getProperty(type, settings, "ivy.resolve.default.type.filter");
String[] confs = splitToArray(conf);
boolean childs = !dependencies.isEmpty() || !excludes.isEmpty() || !conflicts.isEmpty();
ResolveReport report;
if (childs) {
if (isInline()) {
throw new BuildException("the inline mode is incompatible with child elements");
}
if (organisation != null) {
throw new BuildException("'organisation' is not allowed with child elements");
}
if (module != null) {
throw new BuildException("'module' is not allowed with child elements");
}
if (file != null) {
throw new BuildException("'file' not allowed with child elements");
}
if (!getAllowedLogOptions().contains(log)) {
throw new BuildException("invalid option for 'log': " + log + ". Available options are " + getAllowedLogOptions());
}
ModuleRevisionId mrid = ModuleRevisionId.newInstance("", "", Ivy.getWorkingRevision());
DefaultModuleDescriptor md = DefaultModuleDescriptor.newBasicInstance(mrid, null);
for (IvyDependency dep : dependencies) {
DependencyDescriptor dd = dep.asDependencyDescriptor(md, "default", settings);
md.addDependency(dd);
}
for (IvyExclude exclude : excludes) {
DefaultExcludeRule rule = exclude.asRule(settings);
rule.addConfiguration("default");
md.addExcludeRule(rule);
}
for (IvyConflict conflict : conflicts) {
conflict.addConflict(md, settings);
}
report = ivy.resolve(md, getResolveOptions(ivy, new String[] { "default" }, settings));
} else if (isInline()) {
if (organisation == null) {
throw new BuildException("'organisation' is required when using inline mode");
}
if (module == null) {
throw new BuildException("'module' is required when using inline mode");
}
if (file != null) {
throw new BuildException("'file' not allowed when using inline mode");
}
if (!getAllowedLogOptions().contains(log)) {
throw new BuildException("invalid option for 'log': " + log + ". Available options are " + getAllowedLogOptions());
}
for (int i = 0; i < confs.length; i++) {
if ("*".equals(confs[i])) {
confs[i] = "*(public)";
}
}
if (revision == null) {
revision = "latest.integration";
}
report = ivy.resolve(ModuleRevisionId.newInstance(organisation, module, branch, revision), getResolveOptions(ivy, confs, settings), changing);
} else {
if (organisation != null) {
throw new BuildException("'organisation' not allowed when not using 'org' attribute");
}
if (module != null) {
throw new BuildException("'module' not allowed when not using 'org' attribute");
}
if (file == null) {
file = getProject().resolveFile(getProperty(settings, "ivy.dep.file"));
}
report = ivy.resolve(file.toURI().toURL(), getResolveOptions(ivy, confs, settings));
}
if (report.hasError()) {
if (failureProperty != null) {
getProject().setProperty(failureProperty, "true");
}
if (isHaltonfailure()) {
throw new BuildException("resolve failed - see output for details");
}
}
setResolved(report, resolveId, isKeep());
confs = report.getConfigurations();
if (isKeep()) {
ModuleDescriptor md = report.getModuleDescriptor();
// put resolved infos in ant properties and ivy variables
// putting them in ivy variables is important to be able to change from one resolve
// call to the other
String mdOrg = md.getModuleRevisionId().getOrganisation();
String mdName = md.getModuleRevisionId().getName();
String mdRev = md.getResolvedModuleRevisionId().getRevision();
getProject().setProperty("ivy.organisation", mdOrg);
settings.setVariable("ivy.organisation", mdOrg);
getProject().setProperty("ivy.module", mdName);
settings.setVariable("ivy.module", mdName);
getProject().setProperty("ivy.revision", mdRev);
settings.setVariable("ivy.revision", mdRev);
List<ExtendsDescriptor> parents = Arrays.asList(md.getInheritedDescriptors());
for (ExtendsDescriptor parent : parents) {
int i = parents.indexOf(parent);
String parentOrg = parent.getResolvedParentRevisionId().getOrganisation();
String parentModule = parent.getResolvedParentRevisionId().getName();
String parentRevision = parent.getResolvedParentRevisionId().getRevision();
String parentBranch = parent.getResolvedParentRevisionId().getBranch();
getProject().setProperty("ivy.parent[" + i + "].organisation", parentOrg);
settings.setVariable("ivy.parent[" + i + "].organisation", parentOrg);
getProject().setProperty("ivy.parent[" + i + "].module", parentModule);
settings.setVariable("ivy.parent[" + i + "].module", parentModule);
getProject().setProperty("ivy.parent[" + i + "].revision", parentRevision);
settings.setVariable("ivy.parent[" + i + "].revision", parentRevision);
if (parentBranch != null) {
getProject().setProperty("ivy.parent[" + i + "].branch", parentBranch);
settings.setVariable("ivy.parent[" + i + "].branch", parentBranch);
}
}
getProject().setProperty("ivy.parents.count", String.valueOf(md.getInheritedDescriptors().length));
settings.setVariable("ivy.parents.count", String.valueOf(md.getInheritedDescriptors().length));
Boolean hasChanged = null;
if (getCheckIfChanged()) {
hasChanged = report.hasChanged();
getProject().setProperty("ivy.deps.changed", hasChanged.toString());
settings.setVariable("ivy.deps.changed", hasChanged.toString());
}
getProject().setProperty("ivy.resolved.configurations", mergeConfs(confs));
settings.setVariable("ivy.resolved.configurations", mergeConfs(confs));
if (file != null) {
getProject().setProperty("ivy.resolved.file", file.getAbsolutePath());
settings.setVariable("ivy.resolved.file", file.getAbsolutePath());
}
if (resolveId != null) {
getProject().setProperty("ivy.organisation." + resolveId, mdOrg);
settings.setVariable("ivy.organisation." + resolveId, mdOrg);
getProject().setProperty("ivy.module." + resolveId, mdName);
settings.setVariable("ivy.module." + resolveId, mdName);
getProject().setProperty("ivy.revision." + resolveId, mdRev);
settings.setVariable("ivy.revision." + resolveId, mdRev);
if (getCheckIfChanged()) {
// hasChanged has already been set earlier
getProject().setProperty("ivy.deps.changed." + resolveId, hasChanged.toString());
settings.setVariable("ivy.deps.changed." + resolveId, hasChanged.toString());
}
getProject().setProperty("ivy.resolved.configurations." + resolveId, mergeConfs(confs));
settings.setVariable("ivy.resolved.configurations." + resolveId, mergeConfs(confs));
if (file != null) {
getProject().setProperty("ivy.resolved.file." + resolveId, file.getAbsolutePath());
settings.setVariable("ivy.resolved.file." + resolveId, file.getAbsolutePath());
}
}
}
} 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 (ResolveProcessException e) {
throw new BuildException("impossible to resolve dependencies:\n\t" + e.getMessage(), e);
} catch (Exception e) {
throw new BuildException("impossible to resolve dependencies:\n\t" + e, e);
}
}
Aggregations