use of org.apache.ivy.core.module.descriptor.ModuleDescriptor in project ant-ivy by apache.
the class IvyNodeCallers method addCaller.
/**
* @param rootModuleConf ditto
* @param callerNode IvyNode
* @param callerConf ditto
* @param requestedConf ditto
* @param dependencyConfs
* '*' must have been resolved
* @param dd
* the dependency revision id asked by the caller
*/
public void addCaller(String rootModuleConf, IvyNode callerNode, String callerConf, String requestedConf, String[] dependencyConfs, DependencyDescriptor dd) {
ModuleDescriptor md = callerNode.getDescriptor();
ModuleRevisionId mrid = callerNode.getResolvedId();
if (mrid.getModuleId().equals(node.getId().getModuleId())) {
throw new IllegalArgumentException("a module is not authorized to depend on itself: " + node.getId());
}
Map<ModuleRevisionId, Caller> callers = callersByRootConf.get(rootModuleConf);
if (callers == null) {
callers = new HashMap<>();
callersByRootConf.put(rootModuleConf, callers);
}
Caller caller = callers.get(mrid);
if (caller == null) {
caller = new Caller(md, mrid, dd, callerNode.canExclude(rootModuleConf));
callers.put(mrid, caller);
}
caller.addConfiguration(requestedConf, dependencyConfs);
IvyNode parent = callerNode.getRealNode();
for (ModuleId mid : parent.getAllCallersModuleIds()) {
allCallers.put(mid, parent);
}
allCallers.put(mrid.getModuleId(), callerNode);
}
use of org.apache.ivy.core.module.descriptor.ModuleDescriptor in project ant-ivy by apache.
the class ResolveEngine method resolve.
/**
* Resolve dependencies of a module described by an ivy file.
*
* @param ivySource URL
* @param options ResolveOptions
* @return ResolveReport
* @throws ParseException if something goes wrong
* @throws IOException if something goes wrong
*/
public ResolveReport resolve(URL ivySource, ResolveOptions options) throws ParseException, IOException {
URLResource res = new URLResource(ivySource);
ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance().getParser(res);
Message.verbose("using " + parser + " to parse " + ivySource);
ModuleDescriptor md = parser.parseDescriptor(settings, ivySource, options.isValidate());
String revision = options.getRevision();
if (revision == null && md.getResolvedModuleRevisionId().getRevision() == null) {
revision = Ivy.getWorkingRevision();
}
if (revision != null) {
md.setResolvedModuleRevisionId(ModuleRevisionId.newInstance(md.getModuleRevisionId(), revision));
}
return resolve(md, options);
}
use of org.apache.ivy.core.module.descriptor.ModuleDescriptor in project ant-ivy by apache.
the class PublishEngine method publish.
/**
* Publishes a module to the repository. The publish can update the ivy file to publish if
* update is set to true. In this case it will use the given pubrevision, pubdate and status. If
* pubdate is null it will default to the current date. If status is null it will default to the
* current ivy file status (which itself defaults to integration if none is found). If update is
* false, then if the revision is not the same in the ivy file than the one expected (given as
* parameter), this method will fail with an IllegalArgumentException. pubdate and status are
* not used if update is false. extra artifacts can be used to publish more artifacts than
* actually declared in the ivy file. This can be useful to publish additional metadata or
* reports. The extra artifacts array can be null (= no extra artifacts), and if non null only
* the name, type, ext url and extra attributes of the artifacts are really used. Other methods
* can return null safely.
*
* @param mrid ModuleRevisionId
* @param srcArtifactPattern a Collection of String
* @param resolverName String
* @param options PublishOptions
* @return Collection<Artifact>
* @throws IOException if something goes wrong
*/
public Collection<Artifact> publish(ModuleRevisionId mrid, Collection<String> srcArtifactPattern, String resolverName, PublishOptions options) throws IOException {
Message.info(":: publishing :: " + mrid.getModuleId());
Message.verbose("\tvalidate = " + options.isValidate());
long start = System.currentTimeMillis();
options.setSrcIvyPattern(settings.substitute(options.getSrcIvyPattern()));
if (options.getPubBranch() == null) {
options.setPubbranch(mrid.getBranch());
}
if (options.getPubrevision() == null) {
options.setPubrevision(mrid.getRevision());
}
ModuleRevisionId pubmrid = ModuleRevisionId.newInstance(mrid, options.getPubBranch(), options.getPubrevision());
// let's find the resolved module descriptor
ModuleDescriptor md = null;
if (options.getSrcIvyPattern() != null) {
File ivyFile = settings.resolveFile(IvyPatternHelper.substitute(options.getSrcIvyPattern(), DefaultArtifact.newIvyArtifact(pubmrid, new Date())));
if (!ivyFile.exists()) {
throw new IllegalArgumentException("ivy file to publish not found for " + mrid + ": call deliver before (" + ivyFile + ")");
}
URL ivyFileURL = ivyFile.toURI().toURL();
try {
md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, ivyFileURL, false);
if (options.isUpdate()) {
File tmp = File.createTempFile("ivy", ".xml");
tmp.deleteOnExit();
String[] confs = replaceWildcards(options.getConfs(), md);
Set<String> confsToRemove = new HashSet<>(Arrays.asList(md.getConfigurationsNames()));
confsToRemove.removeAll(Arrays.asList(confs));
try {
XmlModuleDescriptorUpdater.update(ivyFileURL, tmp, new UpdateOptions().setSettings(settings).setStatus(options.getStatus() == null ? md.getStatus() : options.getStatus()).setRevision(options.getPubrevision()).setBranch(options.getPubBranch()).setPubdate(options.getPubdate() == null ? new Date() : options.getPubdate()).setMerge(options.isMerge()).setMergedDescriptor(md).setConfsToExclude(confsToRemove.toArray(new String[confsToRemove.size()])));
ivyFile = tmp;
// we parse the new file to get updated module descriptor
md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, ivyFile.toURI().toURL(), false);
options.setSrcIvyPattern(ivyFile.getAbsolutePath());
} catch (SAXException e) {
throw new IllegalStateException("bad ivy file for " + mrid + ": " + ivyFile + ": " + e);
}
} else if (!options.getPubrevision().equals(md.getModuleRevisionId().getRevision())) {
throw new IllegalArgumentException("cannot publish " + ivyFile + " as " + options.getPubrevision() + ": bad revision found in ivy file (Revision: " + md.getModuleRevisionId().getRevision() + "). Use forcedeliver or update.");
}
} catch (ParseException e) {
throw new IllegalStateException("bad ivy file for " + mrid + ": " + ivyFile + ": " + e);
}
} else {
ResolutionCacheManager cacheManager = settings.getResolutionCacheManager();
try {
md = cacheManager.getResolvedModuleDescriptor(mrid);
} catch (ParseException e) {
throw new IllegalStateException("bad ivy file in cache for " + mrid + ": " + e);
}
md.setResolvedModuleRevisionId(pubmrid);
}
DependencyResolver resolver = settings.getResolver(resolverName);
if (resolver == null) {
throw new IllegalArgumentException("unknown resolver " + resolverName);
}
// collect all declared artifacts of this module
Collection<Artifact> missing = publish(md, srcArtifactPattern, resolver, options);
Message.verbose("\tpublish done (" + (System.currentTimeMillis() - start) + "ms)");
return missing;
}
use of org.apache.ivy.core.module.descriptor.ModuleDescriptor in project ant-ivy by apache.
the class ResolveTest method testResolveConflict.
@Test
public void testResolveConflict() throws Exception {
// mod4.1 v 4.1 depends on
// - mod1.1 v 1.0 which depends on mod1.2 v 2.0
// - mod3.1 v 1.1 which depends on mod1.2 v 2.1
ResolveReport report = ivy.resolve(new File("test/repositories/2/mod4.1/ivy-4.1.xml"), getResolveOptions(new String[] { "*" }));
assertNotNull(report);
ModuleDescriptor md = report.getModuleDescriptor();
assertNotNull(md);
ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.1");
assertEquals(mrid, md.getModuleRevisionId());
assertTrue(getResolvedIvyFileInCache(mrid).exists());
// dependencies
ConfigurationResolveReport crr = report.getConfigurationReport("default");
assertNotNull(crr);
assertEquals(0, crr.getDownloadReports(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).length);
assertEquals(1, crr.getDownloadReports(ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).length);
File r = getConfigurationResolveReportInCache(ResolveOptions.getDefaultResolveId(md), "default");
assertTrue(r.exists());
final boolean[] found = new boolean[] { false };
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
saxParser.parse(r, new DefaultHandler() {
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) {
if ("revision".equals(qName) && "2.0".equals(attributes.getValue("name"))) {
found[0] = true;
}
}
});
// the report should contain the evicted revision
assertTrue(found[0]);
assertTrue(getIvyFileInCache(ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists());
assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists());
assertTrue(getIvyFileInCache(ModuleRevisionId.newInstance("org3", "mod3.1", "1.1")).exists());
assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.1", "mod3.1", "jar", "jar").exists());
assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
assertTrue(getIvyFileInCache(ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists());
assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists());
}
use of org.apache.ivy.core.module.descriptor.ModuleDescriptor in project ant-ivy by apache.
the class ResolveTest method testIVY1300.
/**
* Test case for IVY-1300.
*
* @throws Exception if something goes wrong
* @see <a href="https://issues.apache.org/jira/browse/IVY-1300">IVY-1300</a>
*/
@Test
public void testIVY1300() throws Exception {
ivy = Ivy.newInstance();
ivy.configure(new File("test/repositories/IVY-1300/ivysettings.xml"));
ResolveOptions opts = new ResolveOptions();
opts.setConfs(new String[] { "*" });
opts.setResolveId("resolveid");
opts.setTransitive(true);
ResolveReport report = ivy.resolve(new File("test/repositories/IVY-1300/assembly-ivy.xml"), opts);
assertFalse(report.hasError());
ModuleRevisionId modAExpectedRevId = ModuleRevisionId.newInstance("myorg", "modA", "trunk", "5");
ModuleRevisionId modBExpectedRevId = ModuleRevisionId.newInstance("myorg", "modB", "releasebranch", "1");
// check that the resolve report has the expected results, namely that
// trunk/5 is considered later than branch/1 purely because 5>1. Of
// course it is more likely that we would want to consider this a
// 'bad comparison', but this Unit Test is not about that. It is about
// inconsistency of results between the resolve report and the
// delivered descriptor. In fact the delivered descriptor is out of
// step, because retrieve and the report both agree that trunk/5 is
// selected. Deliver begs to differ.
Set<ModuleRevisionId> reportMrids = report.getConfigurationReport("default").getModuleRevisionIds();
assertEquals(new HashSet<>(Arrays.asList(modAExpectedRevId, modBExpectedRevId)), reportMrids);
DeliverOptions dopts = new DeliverOptions();
dopts.setGenerateRevConstraint(true);
dopts.setConfs(new String[] { "*" });
dopts.setStatus("release");
dopts.setPubdate(new Date());
dopts.setResolveId("resolveid");
String pubrev = "1";
String deliveryPattern = "build/test/deliver/assembly-[revision].xml";
ivy.deliver(pubrev, deliveryPattern, dopts);
// now check that the resolve report has the same info as the delivered descriptor
File deliveredIvyFile = new File("build/test/deliver/assembly-1.xml");
assertTrue(deliveredIvyFile.exists());
ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(ivy.getSettings(), deliveredIvyFile.toURI().toURL(), false);
DependencyDescriptor[] dds = md.getDependencies();
assertEquals(2, dds.length);
assertEquals(ModuleRevisionId.newInstance("myorg", "modB", "releasebranch", "1"), dds[1].getDependencyRevisionId());
assertEquals(ModuleRevisionId.newInstance("myorg", "modA", "trunk", "5"), dds[0].getDependencyRevisionId());
}
Aggregations