Search in sources :

Example 26 with DefaultDependencyDescriptor

use of org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor in project ant-ivy by apache.

the class ChainResolverTest method testUseCache.

@Test
public void testUseCache() throws Exception {
    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"), false);
    // resolve dependency twice
    chainToPutDefaultModuleInCache().getDependency(dd, data);
    ChainResolver chain = new ChainResolver();
    chain.setName("chain");
    chain.setSettings(settings);
    MockResolver[] resolvers = new MockResolver[] { MockResolver.buildMockResolver(settings, "1", true, null) };
    for (MockResolver resolver : resolvers) {
        chain.add(resolver);
    }
    chain.getDependency(dd, data);
    // should not have asked any dependency, should have hit the cache
    assertEquals(Collections.emptyList(), resolvers[0].askedDeps);
}
Also used : DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) Test(org.junit.Test)

Example 27 with DefaultDependencyDescriptor

use of org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor in project ant-ivy by apache.

the class ChainResolverTest method testReturnFirstWithCheckModifiedAndDefaultAndCacheAndRealResolver.

/**
 * Test case for IVY-207.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-207">IVY-207</a>
 */
@Test
public void testReturnFirstWithCheckModifiedAndDefaultAndCacheAndRealResolver() throws Exception {
    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"), false);
    // 1 ---- we first do a first resolve which puts a default file in cache
    chainToPutDefaultModuleInCache().getDependency(dd, data);
    // 2 ---- now we ask to resolve dependencies with a chain in return first mode, in which the
    // first resolver is not able to find the module, but the second is
    ChainResolver chain = returnFirstChain();
    chain.setCheckmodified(true);
    ResolvedModuleRevision rmr = chain.getDependency(dd, data);
    assertNotNull(rmr);
    assertFalse(rmr.getDescriptor().isDefault());
    assertEquals("2", rmr.getResolver().getName());
}
Also used : ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) Test(org.junit.Test)

Example 28 with DefaultDependencyDescriptor

use of org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor in project ant-ivy by apache.

the class MirroredURLResolverTest method testFail.

@Test
public void testFail() throws Exception {
    DependencyResolver resolver = settings.getResolver("fail");
    assertNotNull(resolver);
    assertTrue(resolver instanceof MirroredURLResolver);
    MirroredURLResolver mirrored = (MirroredURLResolver) resolver;
    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId.newInstance("commons-lang", "commons-lang", "2.4"), false);
    ResolvedModuleRevision rmr = mirrored.getDependency(dd, data);
    assertNull(rmr);
}
Also used : ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) Test(org.junit.Test)

Example 29 with DefaultDependencyDescriptor

use of org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor in project ant-ivy by apache.

the class PackagerResolverTest method testZipResourceInclusion.

@Test
public void testZipResourceInclusion() throws Exception {
    Locale oldLocale = Locale.getDefault();
    try {
        // set the locale to UK as workaround for SUN bug 6240963
        Locale.setDefault(Locale.UK);
        // Create and configure resolver
        PackagerResolver resolver = new PackagerResolver();
        resolver.setSettings(settings);
        String repoRoot = new File("test/repositories/IVY-1179/repo").toURI().toURL().toExternalForm();
        resolver.addIvyPattern(repoRoot + "[organisation]/[module]/[revision]/ivy.xml");
        resolver.setPackagerPattern(repoRoot + "[organisation]/[module]/[revision]/packager.xml");
        resolver.setBuildRoot(builddir);
        resolver.setResourceCache(cachedir);
        resolver.setPreserveBuildDirectories(true);
        resolver.setVerbose(true);
        resolver.setProperty("packager.website.url", new File("test/repositories/IVY-1179/website").toURI().toURL().toExternalForm());
        resolver.setName("packager");
        // Get module descriptor
        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org", "A", "1.0");
        ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
        // Download artifact
        Artifact artifact = new DefaultArtifact(mrid, rmr.getPublicationDate(), "A", "jar", "jar");
        resolver.download(new Artifact[] { artifact }, downloadOptions());
        // assert that the file A.jar is extracted from the archive
        File jar = new File(builddir, "org/A/1.0/artifacts/jars/A.jar");
        assertTrue(jar.exists());
        // assert that the file README is not extracted from the archive
        File readme = new File(builddir, "org/A/1.0/extract/A-1.0/README");
        assertFalse(readme.exists());
    } finally {
        Locale.setDefault(oldLocale);
    }
}
Also used : Locale(java.util.Locale) PackagerResolver(org.apache.ivy.plugins.resolver.packager.PackagerResolver) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) File(java.io.File) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Example 30 with DefaultDependencyDescriptor

use of org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor in project ant-ivy by apache.

the class PackagerResolverTest method testTarResourceInclusion.

@Test
public void testTarResourceInclusion() throws Exception {
    Locale oldLocale = Locale.getDefault();
    try {
        // set the locale to UK as workaround for SUN bug 6240963
        Locale.setDefault(Locale.UK);
        // Create and configure resolver
        PackagerResolver resolver = new PackagerResolver();
        resolver.setSettings(settings);
        String repoRoot = new File("test/repositories/IVY-1179/repo").toURI().toURL().toExternalForm();
        resolver.addIvyPattern(repoRoot + "[organisation]/[module]/[revision]/ivy.xml");
        resolver.setPackagerPattern(repoRoot + "[organisation]/[module]/[revision]/packager.xml");
        resolver.setBuildRoot(builddir);
        resolver.setResourceCache(cachedir);
        resolver.setPreserveBuildDirectories(true);
        resolver.setVerbose(true);
        resolver.setProperty("packager.website.url", new File("test/repositories/IVY-1179/website").toURI().toURL().toExternalForm());
        resolver.setName("packager");
        // Get module descriptor
        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org", "B", "1.0");
        ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
        // Download artifact
        Artifact artifact = new DefaultArtifact(mrid, rmr.getPublicationDate(), "B", "jar", "jar");
        resolver.download(new Artifact[] { artifact }, downloadOptions());
        // assert that the file B.jar is extracted from the archive
        File jar = new File(builddir, "org/B/1.0/artifacts/jars/B.jar");
        assertTrue(jar.exists());
        // assert that the file README is not extracted from the archive
        File readme = new File(builddir, "org/B/1.0/extract/B-1.0/README");
        assertFalse(readme.exists());
    } finally {
        Locale.setDefault(oldLocale);
    }
}
Also used : Locale(java.util.Locale) PackagerResolver(org.apache.ivy.plugins.resolver.packager.PackagerResolver) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) File(java.io.File) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Aggregations

DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)80 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)61 Test (org.junit.Test)60 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)47 GregorianCalendar (java.util.GregorianCalendar)25 Date (java.util.Date)23 Artifact (org.apache.ivy.core.module.descriptor.Artifact)23 File (java.io.File)22 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)19 DownloadReport (org.apache.ivy.core.report.DownloadReport)18 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)16 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)12 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)9 DownloadOptions (org.apache.ivy.core.resolve.DownloadOptions)9 LatestRevisionStrategy (org.apache.ivy.plugins.latest.LatestRevisionStrategy)7 Configuration (org.apache.ivy.core.module.descriptor.Configuration)6 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)5 ModuleId (org.apache.ivy.core.module.id.ModuleId)5 BufferedReader (java.io.BufferedReader)3 Locale (java.util.Locale)3