use of org.apache.ivy.core.cache.DefaultRepositoryCacheManager in project ant-ivy by apache.
the class ResolveTest method testChangeCacheLayout.
@Test
public void testChangeCacheLayout() throws Exception {
Ivy ivy = new Ivy();
ivy.configure(new File("test/repositories/ivysettings.xml"));
DefaultRepositoryCacheManager cacheMgr = (DefaultRepositoryCacheManager) ivy.getSettings().getDefaultRepositoryCacheManager();
cacheMgr.setIvyPattern("[module]/ivy.xml");
cacheMgr.setArtifactPattern("[artifact].[ext]");
// mod1.1 depends on mod1.2
ResolveReport report = ivy.resolve(new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml"), getResolveOptions(ivy.getSettings(), new String[] { "*" }));
assertNotNull(report);
ModuleDescriptor md = report.getModuleDescriptor();
assertNotNull(md);
ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0");
assertEquals(mrid, md.getModuleRevisionId());
assertTrue(getResolvedIvyFileInCache(ivy, mrid).exists());
// dependencies
assertTrue(getIvyFileInCache(ivy, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
assertTrue(new File(cache, "mod1.2/ivy.xml").exists());
assertTrue(getArchiveFileInCache(ivy, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
assertTrue(new File(cache, "mod1.2.jar").exists());
}
use of org.apache.ivy.core.cache.DefaultRepositoryCacheManager in project ant-ivy by apache.
the class XmlSettingsParserTest method testCacheTTLMatcherAttribute.
/**
* Test case for IVY-1495.
* <code><ttl></code> containing the <code>matcher</code> attribute,
* in an ivy settings file, must work as expected.
*
* @throws Exception if something goes wrong
* @see <a href="https://issues.apache.org/jira/browse/IVY-1495">IVY-1495</a>
*/
@Test
public void testCacheTTLMatcherAttribute() throws Exception {
final IvySettings settings = new IvySettings();
settings.setBaseDir(new File("test/base/dir"));
final XmlSettingsParser parser = new XmlSettingsParser(settings);
parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-cache-ttl-matcher.xml"));
// verify ttl
final DefaultRepositoryCacheManager cacheManager = (DefaultRepositoryCacheManager) settings.getRepositoryCacheManager("foo");
assertNotNull("Missing cache manager 'foo'", cacheManager);
assertEquals("Unexpected default ttl on cache manager", 30000, cacheManager.getDefaultTTL());
final ModuleRevisionId module1 = new ModuleRevisionId(new ModuleId("foo", "bar"), "*");
final long module1SpecificTTL = cacheManager.getTTL(module1);
assertEquals("Unexpected ttl for module " + module1 + " on cache manager", 60000, module1SpecificTTL);
final ModuleRevisionId module2 = new ModuleRevisionId(new ModuleId("food", "*"), "1.2.4");
final long module2SpecificTTL = cacheManager.getTTL(module2);
assertEquals("Unexpected ttl for module " + module2 + " on cache manager", 60000, module2SpecificTTL);
}
use of org.apache.ivy.core.cache.DefaultRepositoryCacheManager in project ant-ivy by apache.
the class ResolveTest method testResolveWithRetainingArtifactNameAndExtraAttributes.
@Test
public void testResolveWithRetainingArtifactNameAndExtraAttributes() throws Exception {
((DefaultRepositoryCacheManager) ivy.getSettings().getDefaultRepositoryCacheManager()).setArtifactPattern(ivy.substitute("[module]/[originalname].[ext]"));
ResolveReport report = ivy.resolve(new File("test/repositories/2/mod15.4/ivy-1.1.xml"), getResolveOptions(new String[] { "default" }).setValidate(false));
assertNotNull(report);
Map<String, String> extra = new HashMap<>();
extra.put("extra", "foo");
ArtifactDownloadReport[] dReports = report.getConfigurationReport("default").getDownloadReports(ModuleRevisionId.newInstance("org15", "mod15.3", "1.1", extra));
assertNotNull(dReports);
assertEquals("number of downloaded artifacts not correct", 1, dReports.length);
Artifact artifact = dReports[0].getArtifact();
assertNotNull(artifact);
String cachePath = getArchivePathInCache(artifact);
assertTrue("artifact name has not been retained: " + cachePath, cachePath.endsWith("library.jar"));
dReports = report.getConfigurationReport("default").getDownloadReports(ModuleRevisionId.newInstance("org14", "mod14.1", "1.1"));
assertNotNull(dReports);
assertEquals("number of downloaded artifacts not correct", 1, dReports.length);
artifact = dReports[0].getArtifact();
assertNotNull(artifact);
cachePath = getArchivePathInCache(artifact);
assertTrue("artifact name has not been retained: " + cachePath, cachePath.endsWith("mod14.1-1.1.jar"));
}
use of org.apache.ivy.core.cache.DefaultRepositoryCacheManager in project ant-ivy by apache.
the class ResolveTest method testChangeCacheLayout2.
@Test
public void testChangeCacheLayout2() throws Exception {
Ivy ivy = new Ivy();
ivy.configure(new File("test/repositories/ivysettings.xml"));
ivy.getSettings().setDefaultRepositoryCacheBasedir(new File(ivy.getSettings().getDefaultCache(), "repository").getAbsolutePath());
ivy.getSettings().setDefaultResolutionCacheBasedir(new File(ivy.getSettings().getDefaultCache(), "workspace").getAbsolutePath());
ivy.getSettings().validate();
DefaultRepositoryCacheManager cacheMgr = (DefaultRepositoryCacheManager) ivy.getSettings().getDefaultRepositoryCacheManager();
cacheMgr.setIvyPattern("[module]/ivy.xml");
cacheMgr.setArtifactPattern("[artifact].[ext]");
// mod1.1 depends on mod1.2
ResolveReport report = ivy.resolve(new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml"), getResolveOptions(ivy.getSettings(), new String[] { "*" }));
assertNotNull(report);
assertFalse(report.hasError());
ModuleDescriptor md = report.getModuleDescriptor();
assertNotNull(md);
ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0");
assertEquals(mrid, md.getModuleRevisionId());
assertTrue(getResolvedIvyFileInCache(ivy, mrid).toString().contains("workspace"));
assertTrue(getResolvedIvyFileInCache(ivy, mrid).exists());
assertTrue(getConfigurationResolveReportInCache(ivy, report.getResolveId(), "default").exists());
// dependencies
assertTrue(getIvyFileInCache(ivy, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
assertTrue(new File(cache, "repository/mod1.2/ivy.xml").exists());
assertTrue(getArchiveFileInCache(ivy, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
assertTrue(new File(cache, "repository/mod1.2.jar").exists());
}
use of org.apache.ivy.core.cache.DefaultRepositoryCacheManager in project ant-ivy by apache.
the class ResolveTest method testResolveWithRetainingArtifactName.
@Test
public void testResolveWithRetainingArtifactName() throws Exception {
((DefaultRepositoryCacheManager) ivy.getSettings().getDefaultRepositoryCacheManager()).setArtifactPattern(ivy.substitute("[module]/[originalname].[ext]"));
ResolveReport report = ivy.resolve(new File("test/repositories/2/mod15.2/ivy-1.1.xml"), getResolveOptions(new String[] { "default" }));
assertNotNull(report);
ArtifactDownloadReport[] dReports = report.getConfigurationReport("default").getDownloadReports(ModuleRevisionId.newInstance("org15", "mod15.1", "1.1"));
assertNotNull(dReports);
assertEquals("number of downloaded artifacts not correct", 1, dReports.length);
Artifact artifact = dReports[0].getArtifact();
assertNotNull(artifact);
String cachePath = getArchivePathInCache(artifact);
assertTrue("artifact name has not been retained: " + cachePath, cachePath.endsWith("library.jar"));
dReports = report.getConfigurationReport("default").getDownloadReports(ModuleRevisionId.newInstance("org14", "mod14.1", "1.1"));
assertNotNull(dReports);
assertEquals("number of downloaded artifacts not correct", 1, dReports.length);
artifact = dReports[0].getArtifact();
assertNotNull(artifact);
cachePath = getArchivePathInCache(artifact);
assertTrue("artifact name has not been retained: " + cachePath, cachePath.endsWith("mod14.1-1.1.jar"));
}
Aggregations