Search in sources :

Example 36 with DefaultArtifact

use of org.apache.ivy.core.module.descriptor.DefaultArtifact 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)

Example 37 with DefaultArtifact

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

the class URLResolverTest method testDownloadWithUseOriginIsTrue.

@Test
public void testDownloadWithUseOriginIsTrue() throws Exception {
    URLResolver resolver = new URLResolver();
    resolver.setSettings(settings);
    String rootpath = new File("test/repositories/1").toURI().toURL().toExternalForm();
    resolver.addIvyPattern(rootpath + "/[organisation]/[module]/ivys/ivy-[revision].xml");
    resolver.addArtifactPattern(rootpath + "/[organisation]/[module]/[type]s/[artifact]-[revision].[type]");
    resolver.setName("test");
    ((DefaultRepositoryCacheManager) resolver.getRepositoryCacheManager()).setUseOrigin(true);
    assertEquals("test", resolver.getName());
    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "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());
    // test to ask to download
    DefaultArtifact artifact = new DefaultArtifact(mrid, pubdate, "mod1.1", "jar", "jar");
    DownloadReport report = resolver.download(new Artifact[] { artifact }, new DownloadOptions());
    assertNotNull(report);
    assertEquals(1, report.getArtifactsReports().length);
    ArtifactDownloadReport ar = report.getArtifactReport(artifact);
    assertNotNull(ar);
    assertEquals(artifact, ar.getArtifact());
    assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
}
Also used : 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) DefaultRepositoryCacheManager(org.apache.ivy.core.cache.DefaultRepositoryCacheManager) Date(java.util.Date) DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) DownloadOptions(org.apache.ivy.core.resolve.DownloadOptions) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) File(java.io.File) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Example 38 with DefaultArtifact

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

the class PomModuleDescriptorBuilder method addMainArtifact.

public void addMainArtifact(String artifactId, String packaging) {
    String ext;
    /*
         * TODO: we should make packaging to ext mapping configurable, since it's not possible to
         * cover all cases.
         */
    if ("pom".equals(packaging)) {
        // no artifact defined! Add the default artifact if it exist.
        DependencyResolver resolver = parserSettings.getResolver(mrid);
        if (resolver != null) {
            DefaultArtifact artifact = new DefaultArtifact(mrid, new Date(), artifactId, "jar", "jar");
            ArtifactOrigin artifactOrigin = resolver.locate(artifact);
            if (!ArtifactOrigin.isUnknown(artifactOrigin)) {
                mainArtifact = artifact;
                ivyModuleDescriptor.addArtifact("master", mainArtifact);
            }
        }
        return;
    } else if (JAR_PACKAGINGS.contains(packaging)) {
        ext = "jar";
    } else if ("pear".equals(packaging)) {
        ext = "phar";
    } else {
        ext = packaging;
    }
    mainArtifact = new DefaultArtifact(mrid, new Date(), artifactId, packaging, ext);
    ivyModuleDescriptor.addArtifact("master", mainArtifact);
}
Also used : ArtifactOrigin(org.apache.ivy.core.cache.ArtifactOrigin) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Date(java.util.Date) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver)

Aggregations

DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)38 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)33 Test (org.junit.Test)27 Artifact (org.apache.ivy.core.module.descriptor.Artifact)25 Date (java.util.Date)24 File (java.io.File)21 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)13 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)12 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)10 DownloadReport (org.apache.ivy.core.report.DownloadReport)10 GregorianCalendar (java.util.GregorianCalendar)5 IOException (java.io.IOException)3 Locale (java.util.Locale)3 DefaultRepositoryCacheManager (org.apache.ivy.core.cache.DefaultRepositoryCacheManager)3 ModuleId (org.apache.ivy.core.module.id.ModuleId)3 PackagerResolver (org.apache.ivy.plugins.resolver.packager.PackagerResolver)3 ResolvedResource (org.apache.ivy.plugins.resolver.util.ResolvedResource)3 MalformedURLException (java.net.MalformedURLException)2 ParseException (java.text.ParseException)2 HashMap (java.util.HashMap)2