use of org.apache.ivy.core.module.descriptor.ModuleDescriptor in project ant-ivy by apache.
the class AbstractOSGiResolver method findNames.
@Override
protected Collection<String> findNames(Map<String, String> tokenValues, String token) {
if (IvyPatternHelper.ORGANISATION_KEY.equals(token)) {
return getRepoDescriptor().getCapabilities();
}
String osgiType = tokenValues.get(IvyPatternHelper.ORGANISATION_KEY);
if (isNullOrEmpty(osgiType)) {
return Collections.emptyList();
}
if (IvyPatternHelper.MODULE_KEY.equals(token)) {
return getRepoDescriptor().getCapabilityValues(osgiType);
}
if (IvyPatternHelper.REVISION_KEY.equals(token)) {
String name = tokenValues.get(IvyPatternHelper.MODULE_KEY);
List<String> versions = new ArrayList<>();
Set<ModuleDescriptorWrapper> mds = getRepoDescriptor().findModules(osgiType, name);
if (mds != null) {
for (ModuleDescriptorWrapper md : mds) {
versions.add(md.getBundleInfo().getVersion().toString());
}
}
return versions;
}
if (IvyPatternHelper.CONF_KEY.equals(token)) {
String name = tokenValues.get(IvyPatternHelper.MODULE_KEY);
if (name == null) {
return Collections.emptyList();
}
if (osgiType.equals(BundleInfo.PACKAGE_TYPE)) {
return Collections.singletonList(BundleInfoAdapter.CONF_USE_PREFIX + name);
}
Collection<ModuleDescriptor> mds = ModuleDescriptorWrapper.unwrap(getRepoDescriptor().findModules(osgiType, name));
if (mds == null) {
return Collections.emptyList();
}
String version = tokenValues.get(IvyPatternHelper.REVISION_KEY);
if (version == null) {
return Collections.emptyList();
}
ModuleDescriptor found = null;
for (ModuleDescriptor md : mds) {
if (md.getRevision().equals(version)) {
found = md;
}
}
if (found == null) {
return Collections.emptyList();
}
return Arrays.asList(found.getConfigurationsNames());
}
return Collections.emptyList();
}
use of org.apache.ivy.core.module.descriptor.ModuleDescriptor in project ant-ivy by apache.
the class IBiblioMavenSnapshotsResolutionTest method testSnapshotResolution.
/**
* Tests that an Ivy module that depends on regular and timestamped snapshots of Maven
* artifacts, when resolved using a {@link IBiblioResolver} and with
* {@link MavenTimedSnapshotVersionMatcher} configured in {@link IvySettings}, is resolved
* correctly for such snapshot dependencies.
*
* @throws Exception
* if something goes wrong
*/
@Test
public void testSnapshotResolution() throws Exception {
final IvySettings settings = this.ivy.getSettings();
assertNotNull("Maven timestamped snapshot revision version matcher is absent", settings.getVersionMatcher(new MavenTimedSnapshotVersionMatcher().getName()));
final ResolveOptions resolveOptions = new ResolveOptions();
resolveOptions.setConfs(new String[] { "default" });
final ResolveReport report = ivy.resolve(new File("test/repositories/2/maven-snapshot-deps-test/ivy-with-maven-snapshot-deps.xml"), resolveOptions);
assertNotNull("Resolution report was null", report);
assertFalse("Resolution report has error(s)", report.hasError());
final ModuleDescriptor md = report.getModuleDescriptor();
assertNotNull("Module descriptor in resolution report was null", md);
final ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache.ivy", "maven-snapshot-deps-test", "1.2.3");
assertEquals("Unexpected module resolved", mrid, md.getModuleRevisionId());
final ConfigurationResolveReport crr = report.getConfigurationReport("default");
final ModuleRevisionId exactRevision = ModuleRevisionId.newInstance("org.apache.ivy.maven-snapshot-test", "exact-revision", "2.3.4");
final ArtifactDownloadReport[] dr1 = crr.getDownloadReports(exactRevision);
assertNotNull("Artifact download report missing for dependency " + exactRevision, dr1);
assertEquals("Unexpected number of artifact download report for dependency " + exactRevision, dr1.length, 1);
final ArtifactDownloadReport exactRevDownloadReport = dr1[0];
assertEquals("Unexpected download status for dependency " + exactRevision, exactRevDownloadReport.getDownloadStatus(), DownloadStatus.SUCCESSFUL);
final ModuleRevisionId regularSnapshot = ModuleRevisionId.newInstance("org.apache.ivy.maven-snapshot-test", "regular-snapshot", "1.2.3-SNAPSHOT");
final ArtifactDownloadReport[] dr2 = crr.getDownloadReports(regularSnapshot);
assertNotNull("Artifact download report missing for dependency " + regularSnapshot, dr2);
assertEquals("Unexpected number of artifact download report for dependency " + regularSnapshot, dr2.length, 1);
final ArtifactDownloadReport regularSnapshotDownloadReport = dr2[0];
assertEquals("Unexpected download status for dependency " + regularSnapshot, regularSnapshotDownloadReport.getDownloadStatus(), DownloadStatus.SUCCESSFUL);
final ModuleRevisionId timestampedSnapshot = ModuleRevisionId.newInstance("org.apache.ivy.maven-snapshot-test", "timestamped-snapshot", "5.6.7-20170911.130943-1");
final ArtifactDownloadReport[] dr3 = crr.getDownloadReports(timestampedSnapshot);
assertNotNull("Artifact download report missing for dependency " + timestampedSnapshot, dr3);
assertEquals("Unexpected number of artifact download report for dependency " + timestampedSnapshot, dr3.length, 1);
final ArtifactDownloadReport timestampedSnapshotDownloadReport = dr3[0];
assertEquals("Unexpected download status for dependency " + timestampedSnapshot, timestampedSnapshotDownloadReport.getDownloadStatus(), DownloadStatus.SUCCESSFUL);
}
use of org.apache.ivy.core.module.descriptor.ModuleDescriptor in project ant-ivy by apache.
the class XmlModuleUpdaterTest method testMergedUpdateWithExtendsAndConfigurationsInheritance.
/**
* Test case for IVY-1437.
*
* @throws Exception if something goes wrong
* @see <a href="https://issues.apache.org/jira/browse/IVY-1437">IVY-1437</a>
*/
@Test
public void testMergedUpdateWithExtendsAndConfigurationsInheritance() throws Exception {
URL url = XmlModuleUpdaterTest.class.getResource("test-extends-configurations-inherit.xml");
XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance();
ModuleDescriptor md = parser.parseDescriptor(new IvySettings(), url, true);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
XmlModuleDescriptorUpdater.update(url, buffer, getUpdateOptions("release", "mynewrev").setMerge(true).setMergedDescriptor(md));
ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, false), true);
Configuration[] configurations = updatedMd.getConfigurations();
assertNotNull("Configurations shouldn't be null", configurations);
assertEquals("Number of configurations is incorrect", 2, configurations.length);
String updatedXml = buffer.toString();
System.out.println(updatedXml);
assertTrue(updatedXml.contains("configurations defaultconf=\"compile\" defaultconfmapping=\"*->default\""));
assertTrue(updatedXml.contains("dependencies defaultconf=\"compile\" defaultconfmapping=\"*->default\""));
}
use of org.apache.ivy.core.module.descriptor.ModuleDescriptor in project ant-ivy by apache.
the class XmlModuleUpdaterTest method testMergedUpdateWithInclude.
/**
* Test case for IVY-1315.
*
* @throws Exception if something goes wrong
* @see <a href="https://issues.apache.org/jira/browse/IVY-1315">IVY-1315</a>
*/
@Test
public void testMergedUpdateWithInclude() throws Exception {
URL url = XmlModuleUpdaterTest.class.getResource("test-update-excludedconfs6.xml");
XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance();
ModuleDescriptor md = parser.parseDescriptor(new IvySettings(), url, true);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
XmlModuleDescriptorUpdater.update(url, buffer, getUpdateOptions("release", "mynewrev").setMerge(true).setMergedDescriptor(md));
ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, false), true);
Configuration[] configurations = updatedMd.getConfigurations();
assertNotNull("Configurations shouldn't be null", configurations);
assertEquals("Number of configurations is incorrect", 6, configurations.length);
String updatedXml = buffer.toString();
System.out.println(updatedXml);
assertTrue(updatedXml.contains("dependencies defaultconf=\"conf1->default\""));
}
use of org.apache.ivy.core.module.descriptor.ModuleDescriptor in project ant-ivy by apache.
the class XmlModuleUpdaterTest method testUpdateWithExcludeConfigurations5.
@Test
public void testUpdateWithExcludeConfigurations5() throws Exception {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
URL settingsUrl = new File("test/java/org/apache/ivy/plugins/parser/xml/" + "test-update-excludedconfs5.xml").toURI().toURL();
XmlModuleDescriptorUpdater.update(settingsUrl, buffer, getUpdateOptions("release", "mynewrev").setConfsToExclude(new String[] { "myconf2" }));
XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance();
ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, false), true);
DependencyDescriptor[] deps = updatedMd.getDependencies();
assertNotNull("Dependencies shouldn't be null", deps);
assertEquals("Number of dependencies is incorrect", 8, deps.length);
// check that none of the dependencies contains myconf2
for (DependencyDescriptor dep : deps) {
String name = dep.getDependencyId().getName();
assertFalse("Dependency " + name + " shouldn't have myconf2 as module configuration", Arrays.asList(dep.getModuleConfigurations()).contains("myconf2"));
assertEquals("Dependency " + name + " shouldn't have a dependency artifact for configuration myconf2", 0, dep.getDependencyArtifacts("myconf2").length);
}
}
Aggregations