use of org.apache.ivy.core.module.descriptor.DefaultArtifact in project ant-ivy by apache.
the class BundleInfoAdapter method decodeIvyURI.
private static DefaultArtifact decodeIvyURI(final URI uri) {
String org = null;
String name = null;
String branch = null;
String rev = null;
String art = null;
String type = null;
String ext = null;
String path = uri.getPath();
if (!path.startsWith("/")) {
throw new IllegalArgumentException("An ivy url should be of the form ivy:///org/module but was : " + uri);
}
int i = path.indexOf('/', 1);
if (i < 0) {
throw new IllegalArgumentException("Expecting an organisation in the ivy url: " + uri);
}
org = path.substring(1, i);
name = path.substring(i + 1);
for (String parameter : uri.getQuery().split("&")) {
if (parameter.length() == 0) {
continue;
}
String[] nameAndValue = parameter.split("=");
if (nameAndValue.length != 2) {
throw new IllegalArgumentException("Malformed query string in the ivy url: " + uri);
} else if (nameAndValue[0].equals("branch")) {
branch = nameAndValue[1];
} else if (nameAndValue[0].equals("rev")) {
rev = nameAndValue[1];
} else if (nameAndValue[0].equals("art")) {
art = nameAndValue[1];
} else if (nameAndValue[0].equals("type")) {
type = nameAndValue[1];
} else if (nameAndValue[0].equals("ext")) {
ext = nameAndValue[1];
} else {
throw new IllegalArgumentException("Unrecognized parameter '" + nameAndValue[0] + " in the query string of the ivy url: " + uri);
}
}
ModuleRevisionId amrid = ModuleRevisionId.newInstance(org, name, branch, rev);
return new DefaultArtifact(amrid, null, art, type, ext);
}
use of org.apache.ivy.core.module.descriptor.DefaultArtifact in project ant-ivy by apache.
the class ResolveTest method testMultipleCache.
@Test
public void testMultipleCache() throws Exception {
Ivy ivy = new Ivy();
ivy.configure(new File("test/repositories/ivysettings-multicache.xml"));
// mod2.1 depends on mod1.1 which depends on mod1.2
ResolveReport report = ivy.resolve(new File("test/repositories/1/org2/mod2.1/ivys/ivy-0.3.xml"), getResolveOptions(new String[] { "*" }));
assertNotNull(report);
assertFalse(report.hasError());
// dependencies
DefaultArtifact depArtifact = TestHelper.newArtifact("org1", "mod1.1", "1.0", "mod1.1", "jar", "jar");
ModuleRevisionId depMrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0");
DefaultRepositoryCacheManager cacheMgr1 = (DefaultRepositoryCacheManager) ivy.getSettings().getDefaultRepositoryCacheManager();
DefaultRepositoryCacheManager cacheMgr2 = (DefaultRepositoryCacheManager) ivy.getSettings().getRepositoryCacheManager("cache2");
// ivy file should be cached in default cache, and artifact in cache2
assertTrue(cacheMgr1.getIvyFileInCache(depMrid).exists());
assertFalse(cacheMgr1.getArchiveFileInCache(depArtifact).exists());
assertEquals(new File(cache, "repo1/mod1.1/ivy-1.0.xml").getCanonicalFile(), cacheMgr1.getIvyFileInCache(depMrid).getCanonicalFile());
assertFalse(cacheMgr2.getIvyFileInCache(depMrid).exists());
assertTrue(cacheMgr2.getArchiveFileInCache(depArtifact).exists());
assertEquals(new File(cache, "repo2/mod1.1-1.0/mod1.1.jar").getCanonicalFile(), cacheMgr2.getArchiveFileInCache(depArtifact).getCanonicalFile());
}
use of org.apache.ivy.core.module.descriptor.DefaultArtifact in project ant-ivy by apache.
the class ResolveEngineTest method testLocateThenDownload.
@Test
public void testLocateThenDownload() {
ResolveEngine engine = new ResolveEngine(ivy.getSettings(), ivy.getEventManager(), ivy.getSortEngine());
testLocateThenDownload(engine, DefaultArtifact.newIvyArtifact(ModuleRevisionId.parse("org1#mod1.1;1.0"), new Date()), new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml"));
testLocateThenDownload(engine, new DefaultArtifact(ModuleRevisionId.parse("org1#mod1.1;1.0"), new Date(), "mod1.1", "jar", "jar"), new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"));
}
use of org.apache.ivy.core.module.descriptor.DefaultArtifact 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.DefaultArtifact in project ant-ivy by apache.
the class NameSpaceHelperTest method testTransformArtifactWithExtraAttributes.
@Test
public void testTransformArtifactWithExtraAttributes() {
Artifact artifact = new DefaultArtifact(ArtifactRevisionId.newInstance(ModuleRevisionId.parse("org.apache#test;1.0"), "test", "jar", "jar", Collections.singletonMap("m:qualifier", "sources")), new Date(), null, false);
MRIDTransformationRule r = new MRIDTransformationRule();
r.addSrc(new MRIDRule("org.apache", "test", null));
r.addDest(new MRIDRule("apache", "test", null));
Artifact transformed = NameSpaceHelper.transform(artifact, r);
assertEquals("apache#test;1.0", transformed.getModuleRevisionId().toString());
assertEquals(Collections.singletonMap("m:qualifier", "sources"), transformed.getQualifiedExtraAttributes());
}
Aggregations