use of org.apache.ivy.core.module.descriptor.Artifact in project ant-ivy by apache.
the class XmlModuleDescriptorParserTest method testExtendsCached.
@Test
public void testExtendsCached() throws Exception {
// configure a resolver to serve the parent descriptor, so that parse succeeds.
File resolveRoot = new File("build/tmp/xmlModuleDescriptorTest");
assertTrue(resolveRoot.exists() || resolveRoot.mkdirs());
FileUtil.copy(getClass().getResource("test-extends-parent.xml"), new File(resolveRoot, "myorg/myparent/ivy.xml"), null, null);
FileSystemResolver resolver = new FileSystemResolver();
resolver.setSettings(settings);
resolver.setName("testExtendsCached");
resolver.addIvyPattern(resolveRoot.getAbsolutePath() + "/[organisation]/[module]/[artifact].[ext]");
settings.addResolver(resolver);
settings.setDefaultResolver("testExtendsCached");
// descriptor extends a module without a location="..." attribute, so resolver lookup
// must be performed.
ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-extends-cached.xml"), true);
assertNotNull(md);
assertEquals("myorg", md.getModuleRevisionId().getOrganisation());
assertEquals("mymodule", md.getModuleRevisionId().getName());
assertEquals("myrev", md.getModuleRevisionId().getRevision());
assertEquals("integration", md.getStatus());
// verify that the parent description was merged.
assertEquals("Parent module description.", md.getDescription());
// verify that the parent and child configurations were merged together.
final Configuration[] expectedConfs = { new Configuration("default"), new Configuration("conf1"), new Configuration("conf2") };
assertNotNull(md.getConfigurations());
assertEquals(Arrays.asList(expectedConfs), Arrays.asList(md.getConfigurations()));
// verify parent and child dependencies were merged together.
DependencyDescriptor[] deps = md.getDependencies();
assertNotNull(deps);
assertEquals(2, deps.length);
assertEquals(Collections.singletonList("default"), Arrays.asList(deps[0].getModuleConfigurations()));
ModuleRevisionId dep = deps[0].getDependencyRevisionId();
assertEquals("myorg", dep.getModuleId().getOrganisation());
assertEquals("mymodule1", dep.getModuleId().getName());
assertEquals("1.0", dep.getRevision());
assertEquals(Arrays.asList("conf1", "conf2"), Arrays.asList(deps[1].getModuleConfigurations()));
dep = deps[1].getDependencyRevisionId();
assertEquals("myorg", dep.getModuleId().getOrganisation());
assertEquals("mymodule2", dep.getModuleId().getName());
assertEquals("2.0", dep.getRevision());
// verify only child publications are present
Artifact[] artifacts = md.getAllArtifacts();
assertNotNull(artifacts);
assertEquals(1, artifacts.length);
assertEquals("mymodule", artifacts[0].getName());
assertEquals("jar", artifacts[0].getType());
}
use of org.apache.ivy.core.module.descriptor.Artifact in project ant-ivy by apache.
the class DefaultRepositoryCacheManagerTest method setUp.
@Before
public void setUp() throws Exception {
File f = File.createTempFile("ivycache", ".dir");
ivy = new Ivy();
ivy.configureDefault();
ivy.getLoggerEngine().setDefaultLogger(new DefaultMessageLogger(Message.MSG_DEBUG));
IvyContext.pushNewContext().setIvy(ivy);
IvySettings settings = ivy.getSettings();
// we want to use the file as a directory, so we delete the file itself
f.delete();
cacheManager = new DefaultRepositoryCacheManager();
cacheManager.setSettings(settings);
cacheManager.setBasedir(f);
artifact = createArtifact("org", "module", "rev", "name", "type", "ext");
Artifact originArtifact = createArtifact("org", "module", "rev", "name", "pom.original", "pom");
origin = new ArtifactOrigin(originArtifact, true, "file:/some/where.pom");
cacheManager.saveArtifactOrigin(originArtifact, origin);
cacheManager.saveArtifactOrigin(artifact, origin);
}
use of org.apache.ivy.core.module.descriptor.Artifact in project ant-ivy by apache.
the class DefaultRepositoryCacheManagerTest method testLatestIntegrationIsCachedPerResolver.
@Test
@Ignore
public void testLatestIntegrationIsCachedPerResolver() throws Exception {
// given a module org#module
ModuleId mi = new ModuleId("org", "module");
// and a latest.integration mrid/dd
ModuleRevisionId mridLatest = new ModuleRevisionId(mi, "trunk", "latest.integration");
DependencyDescriptor ddLatest = new DefaultDependencyDescriptor(mridLatest, false);
// and some random options
CacheMetadataOptions options = new CacheMetadataOptions().setCheckTTL(false);
// setup resolver1 to download the static content so we can call cacheModuleDescriptor
MockResolver resolver = new MockResolver();
resolver.setName("resolver1");
resolver.setSettings(ivy.getSettings());
ivy.getSettings().addResolver(resolver);
ResourceDownloader downloader = new ResourceDownloader() {
public void download(Artifact artifact, Resource resource, File dest) throws IOException {
String content = "<ivy-module version=\"2.0\"><info organisation=\"org\" module=\"module\" status=\"integration\" revision=\"1.1\" branch=\"trunk\"/></ivy-module>";
dest.getParentFile().mkdirs();
FileOutputStream out = new FileOutputStream(dest);
PrintWriter pw = new PrintWriter(out);
pw.write(content);
pw.flush();
out.close();
}
};
ModuleDescriptorWriter writer = new ModuleDescriptorWriter() {
public void write(ResolvedResource originalMdResource, ModuleDescriptor md, File src, File dest) throws IOException {
XmlModuleDescriptorWriter.write(md, dest);
}
};
// latest.integration will resolve to 1.1 in resolver1
ModuleRevisionId mrid11 = new ModuleRevisionId(mi, "trunk", "1.1");
DefaultArtifact artifact11 = new DefaultArtifact(mrid11, new Date(), "module-1.1.ivy", "ivy", "ivy", true);
DependencyDescriptor dd11 = new DefaultDependencyDescriptor(mrid11, false);
BasicResource resource11 = new BasicResource("/module-1-1.ivy", true, 1, 0, true);
ResolvedResource mdRef11 = new ResolvedResource(resource11, "1.1");
// tell the cache about 1.1
ResolvedModuleRevision rmr11 = cacheManager.cacheModuleDescriptor(resolver, mdRef11, dd11, artifact11, downloader, options);
cacheManager.originalToCachedModuleDescriptor(resolver, mdRef11, artifact11, rmr11, writer);
// and use the new overload that passes in resolver name
cacheManager.saveResolvedRevision("resolver1", mridLatest, "1.1");
ResolvedModuleRevision rmrFromCache = cacheManager.findModuleInCache(ddLatest, mridLatest, options, "resolver1");
assertEquals(rmr11, rmrFromCache);
}
use of org.apache.ivy.core.module.descriptor.Artifact in project ant-ivy by apache.
the class OBRResolverTest method genericTestResolve.
private void genericTestResolve(String jarName, String conf, ModuleRevisionId[] expectedMrids, ModuleRevisionId[] expected2Mrids) throws Exception {
JarInputStream jis = new JarInputStream(new FileInputStream("test/test-repo/bundlerepo/" + jarName));
Manifest manifest = jis.getManifest();
jis.close();
BundleInfo bundleInfo = ManifestParser.parseManifest(manifest);
bundleInfo.addArtifact(new BundleArtifact(false, new File("test/test-repo/bundlerepo/" + jarName).toURI(), null));
DefaultModuleDescriptor md = BundleInfoAdapter.toModuleDescriptor(OSGiManifestParser.getInstance(), null, bundleInfo, profileProvider);
ResolveReport resolveReport = ivy.resolve(md, new ResolveOptions().setConfs(new String[] { conf }).setOutputReport(false));
assertFalse("resolve failed " + resolveReport.getAllProblemMessages(), resolveReport.hasError());
Set<ModuleRevisionId> actual = new HashSet<>();
for (Artifact artifact : resolveReport.getArtifacts()) {
actual.add(artifact.getModuleRevisionId());
}
Set<ModuleRevisionId> expected = new HashSet<>(Arrays.asList(expectedMrids));
if (expected2Mrids != null) {
// in this use case, we have two choices, let's try the second one
try {
Set<ModuleRevisionId> expected2 = new HashSet<>(Arrays.asList(expected2Mrids));
assertEquals(expected2, actual);
// test passed
return;
} catch (AssertionError e) {
// too bad, let's continue
}
}
assertEquals(expected, actual);
}
use of org.apache.ivy.core.module.descriptor.Artifact in project ant-ivy by apache.
the class P2DescriptorTest method testResolveSource.
@Test
public void testResolveSource() throws Exception {
settings.setDefaultResolver("p2-sources");
ModuleRevisionId mrid = ModuleRevisionId.newInstance(BundleInfo.BUNDLE_TYPE, "org.apache.ivy", "2.2.0.final_20100923230623");
ResolvedModuleRevision rmr = p2SourceResolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
assertNotNull(rmr);
assertEquals(mrid, rmr.getId());
assertEquals(2, rmr.getDescriptor().getAllArtifacts().length);
DownloadReport report = p2SourceResolver.download(rmr.getDescriptor().getAllArtifacts(), new DownloadOptions());
assertNotNull(report);
assertEquals(2, report.getArtifactsReports().length);
for (int i = 0; i < 2; i++) {
Artifact artifact = rmr.getDescriptor().getAllArtifacts()[i];
ArtifactDownloadReport ar = report.getArtifactReport(artifact);
assertNotNull(ar);
assertEquals(artifact, ar.getArtifact());
assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
// test to ask to download again, should use cache
DownloadReport report2 = p2SourceResolver.download(new Artifact[] { artifact }, new DownloadOptions());
assertNotNull(report2);
assertEquals(1, report2.getArtifactsReports().length);
ar = report2.getArtifactReport(artifact);
assertNotNull(ar);
assertEquals(artifact, ar.getArtifact());
assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
}
}
Aggregations