use of org.apache.ivy.core.module.descriptor.Artifact 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.Artifact in project ant-ivy by apache.
the class ResolveTest method assertContainsArtifact.
// //////////////////////////////////////////////////////////
// helper methods to ease the tests
// //////////////////////////////////////////////////////////
private void assertContainsArtifact(String org, String module, String rev, String artName, String type, String ext, ConfigurationResolveReport conf) {
Artifact art = getArtifact(org, module, rev, artName, type, ext);
assertContainsArtifact(conf, art);
}
use of org.apache.ivy.core.module.descriptor.Artifact in project ant-ivy by apache.
the class ResolveTest method testArtifactOrigin.
@Test
public void testArtifactOrigin() throws Exception {
ResolveReport report = ivy.resolve(new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml"), getResolveOptions(new String[] { "default" }));
assertNotNull(report);
ArtifactDownloadReport[] dReports = report.getConfigurationReport("default").getDownloadReports(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"));
assertNotNull(dReports);
assertEquals("number of downloaded artifacts not correct", 1, dReports.length);
Artifact artifact = dReports[0].getArtifact();
assertNotNull(artifact);
String expectedLocation = new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar").getAbsolutePath();
// verify the origin in the report
ArtifactOrigin reportOrigin = dReports[0].getArtifactOrigin();
assertNotNull(reportOrigin);
assertTrue("isLocal for artifact not correct", reportOrigin.isLocal());
assertEquals("location for artifact not correct", expectedLocation, reportOrigin.getLocation());
// verify the saved origin on disk
ArtifactOrigin ivyOrigin = getSavedArtifactOrigin(artifact);
assertNotNull(ivyOrigin);
assertTrue("isLocal for artifact not correct", ivyOrigin.isLocal());
assertEquals("location for artifact not correct", expectedLocation, ivyOrigin.getLocation());
// now resolve the same artifact again and verify the origin of the (not-downloaded)
// artifact
report = ivy.resolve(new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml"), getResolveOptions(new String[] { "default" }));
assertNotNull(report);
dReports = report.getConfigurationReport("default").getDownloadReports(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"));
assertNotNull(dReports);
assertEquals("number of downloaded artifacts not correct", 1, dReports.length);
assertEquals("download status not correct", DownloadStatus.NO, dReports[0].getDownloadStatus());
reportOrigin = dReports[0].getArtifactOrigin();
assertNotNull(reportOrigin);
assertTrue("isLocal for artifact not correct", reportOrigin.isLocal());
assertEquals("location for artifact not correct", expectedLocation, reportOrigin.getLocation());
}
use of org.apache.ivy.core.module.descriptor.Artifact in project ant-ivy by apache.
the class ResolveTest method testIVY1366.
/**
* Test case for IVY-1366.
*
* @throws Exception if something goes wrong
* @see <a href="https://issues.apache.org/jira/browse/IVY-1366">IVY-1366</a>
*/
@Test
public void testIVY1366() throws Exception {
Ivy ivy = new Ivy();
ivy.configure(new File("test/repositories/IVY-1366/ivysettings.xml"));
ResolveReport report = ivy.resolve(new File("test/repositories/IVY-1366/ivy.xml"), new ResolveOptions().setConfs(new String[] { "runtime" }));
assertFalse(report.hasError());
List<Artifact> artifacts = report.getArtifacts();
assertEquals(3, artifacts.size());
assertEquals("test#a;1!a.jar", artifacts.get(0).toString());
assertEquals("test#c;1!c.jar", artifacts.get(1).toString());
assertEquals("test#b;1!b.jar", artifacts.get(2).toString());
}
use of org.apache.ivy.core.module.descriptor.Artifact in project ant-ivy by apache.
the class PomModuleDescriptorParserTest method testParent.
@Test
public void testParent() throws Exception {
ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-parent.pom"), false);
assertNotNull(md);
ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "test", "1.0");
assertEquals(mrid, md.getModuleRevisionId());
Artifact[] artifact = md.getArtifacts("master");
assertEquals(1, artifact.length);
assertEquals(mrid, artifact[0].getModuleRevisionId());
assertEquals("test", artifact[0].getName());
}
Aggregations