Search in sources :

Example 1 with PackagerResolver

use of org.apache.ivy.plugins.resolver.packager.PackagerResolver 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 2 with PackagerResolver

use of org.apache.ivy.plugins.resolver.packager.PackagerResolver 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)

Example 3 with PackagerResolver

use of org.apache.ivy.plugins.resolver.packager.PackagerResolver in project ant-ivy by apache.

the class XmlSettingsParserTest method testFileAttribute.

@Test
public void testFileAttribute() throws Exception {
    IvySettings settings = new IvySettings();
    File basedir = new File("test").getAbsoluteFile();
    settings.setBaseDir(basedir);
    XmlSettingsParser parser = new XmlSettingsParser(settings);
    parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-packager.xml"));
    DependencyResolver r = settings.getResolver("packager");
    assertNotNull(r);
    assertTrue(r instanceof PackagerResolver);
    PackagerResolver packager = (PackagerResolver) r;
    assertEquals(new File(basedir, "packager/build"), packager.getBuildRoot());
    assertEquals(new File(basedir, "packager/cache"), packager.getResourceCache());
}
Also used : PackagerResolver(org.apache.ivy.plugins.resolver.packager.PackagerResolver) File(java.io.File) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver) Test(org.junit.Test) ModuleDescriptorParserRegistryTest(org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistryTest)

Example 4 with PackagerResolver

use of org.apache.ivy.plugins.resolver.packager.PackagerResolver in project ant-ivy by apache.

the class PackagerResolverTest method testFile.

@Test
public void testFile() 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/packager/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/packager/website").toURI().toURL().toExternalForm());
        resolver.setName("packager");
        assertEquals("packager", resolver.getName());
        // Get module descriptor
        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org", "mod", "1.0");
        ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
        assertNotNull(rmr);
        assertEquals(mrid, rmr.getId());
        Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime();
        assertEquals(pubdate, rmr.getPublicationDate());
        // Download artifact
        Artifact artifact = new DefaultArtifact(mrid, pubdate, "mod", "jar", "jar");
        DownloadReport report = resolver.download(new Artifact[] { artifact }, downloadOptions());
        assertNotNull(report);
        assertEquals(1, report.getArtifactsReports().length);
        ArtifactDownloadReport ar = report.getArtifactReport(artifact);
        System.out.println("download details: " + ar.getDownloadDetails());
        assertNotNull(ar);
        assertEquals(artifact, ar.getArtifact());
        assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
        // Verify resource cache now contains the distribution archive
        assertTrue(new File(cachedir, "mod-1.0.tar.gz").exists());
        // Download again, should use Ivy cache this time
        report = resolver.download(new Artifact[] { artifact }, downloadOptions());
        assertNotNull(report);
        assertEquals(1, report.getArtifactsReports().length);
        ar = report.getArtifactReport(artifact);
        assertNotNull(ar);
        assertEquals(artifact, ar.getArtifact());
        assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
        // Now download the maven2 artifact
        artifact = DefaultArtifact.cloneWithAnotherName(artifact, "foobar-janfu");
        report = resolver.download(new Artifact[] { artifact }, downloadOptions());
        assertNotNull(report);
        assertEquals(1, report.getArtifactsReports().length);
        ar = report.getArtifactReport(artifact);
        assertNotNull(ar);
        assertEquals(artifact, ar.getArtifact());
        assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
    } finally {
        Locale.setDefault(oldLocale);
    }
}
Also used : Locale(java.util.Locale) GregorianCalendar(java.util.GregorianCalendar) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) Date(java.util.Date) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) PackagerResolver(org.apache.ivy.plugins.resolver.packager.PackagerResolver) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) File(java.io.File) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Aggregations

File (java.io.File)4 PackagerResolver (org.apache.ivy.plugins.resolver.packager.PackagerResolver)4 Test (org.junit.Test)4 Locale (java.util.Locale)3 Artifact (org.apache.ivy.core.module.descriptor.Artifact)3 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)3 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)3 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)3 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)3 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)1 DownloadReport (org.apache.ivy.core.report.DownloadReport)1 ModuleDescriptorParserRegistryTest (org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistryTest)1 DependencyResolver (org.apache.ivy.plugins.resolver.DependencyResolver)1