Search in sources :

Example 6 with DefaultRepositoryCacheManager

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());
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) Ivy(org.apache.ivy.Ivy) JarFile(java.util.jar.JarFile) File(java.io.File) DefaultRepositoryCacheManager(org.apache.ivy.core.cache.DefaultRepositoryCacheManager) Test(org.junit.Test)

Example 7 with DefaultRepositoryCacheManager

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>&lt;ttl&gt;</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);
}
Also used : ModuleId(org.apache.ivy.core.module.id.ModuleId) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) File(java.io.File) DefaultRepositoryCacheManager(org.apache.ivy.core.cache.DefaultRepositoryCacheManager) Test(org.junit.Test) ModuleDescriptorParserRegistryTest(org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistryTest)

Example 8 with DefaultRepositoryCacheManager

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"));
}
Also used : ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) HashMap(java.util.HashMap) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) DefaultRepositoryCacheManager(org.apache.ivy.core.cache.DefaultRepositoryCacheManager) JarFile(java.util.jar.JarFile) File(java.io.File) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Example 9 with DefaultRepositoryCacheManager

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());
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) Ivy(org.apache.ivy.Ivy) JarFile(java.util.jar.JarFile) File(java.io.File) DefaultRepositoryCacheManager(org.apache.ivy.core.cache.DefaultRepositoryCacheManager) Test(org.junit.Test)

Example 10 with DefaultRepositoryCacheManager

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"));
}
Also used : ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) DefaultRepositoryCacheManager(org.apache.ivy.core.cache.DefaultRepositoryCacheManager) JarFile(java.util.jar.JarFile) File(java.io.File) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Aggregations

DefaultRepositoryCacheManager (org.apache.ivy.core.cache.DefaultRepositoryCacheManager)16 File (java.io.File)13 Test (org.junit.Test)11 JarFile (java.util.jar.JarFile)7 ConfigurationResolveReport (org.apache.ivy.core.report.ConfigurationResolveReport)7 ResolveReport (org.apache.ivy.core.report.ResolveReport)7 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)6 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)6 Ivy (org.apache.ivy.Ivy)5 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)5 Artifact (org.apache.ivy.core.module.descriptor.Artifact)3 Date (java.util.Date)2 GregorianCalendar (java.util.GregorianCalendar)2 RepositoryCacheManager (org.apache.ivy.core.cache.RepositoryCacheManager)2 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)2 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)2 DownloadReport (org.apache.ivy.core.report.DownloadReport)2 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)2 ModuleDescriptorParserRegistryTest (org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistryTest)2 FileNotFoundException (java.io.FileNotFoundException)1