Search in sources :

Example 26 with Artifact

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

the class FileSystemResolverTest method testDisableTransaction.

@Test
public void testDisableTransaction() throws Exception {
    FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("test");
    resolver.setSettings(settings);
    resolver.setTransactional("false");
    resolver.addIvyPattern(settings.getBaseDir() + "/test/repositories/1/[organisation]/[module]/[revision]/[artifact].[ext]");
    resolver.addArtifactPattern(settings.getBaseDir() + "/test/repositories/1/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]");
    ModuleRevisionId mrid = ModuleRevisionId.newInstance("myorg", "mymodule", "myrevision");
    Artifact ivyArtifact = new DefaultArtifact(mrid, new Date(), "ivy", "ivy", "xml");
    Artifact artifact = new DefaultArtifact(mrid, new Date(), "myartifact", "mytype", "myext");
    File src = new File("test/repositories/ivysettings.xml");
    resolver.beginPublishTransaction(mrid, false);
    // with transactions disabled the file should be available as soon as they are published
    resolver.publish(ivyArtifact, src, false);
    assertTrue(new File("test/repositories/1/myorg/mymodule/myrevision/ivy.xml").exists());
    resolver.publish(artifact, src, false);
    assertTrue(new File("test/repositories/1/myorg/mymodule/myrevision/myartifact-myrevision.myext").exists());
    resolver.commitPublishTransaction();
    assertTrue(new File("test/repositories/1/myorg/mymodule/myrevision/ivy.xml").exists());
    assertTrue(new File("test/repositories/1/myorg/mymodule/myrevision/myartifact-myrevision.myext").exists());
}
Also used : ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) 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) Date(java.util.Date) Test(org.junit.Test)

Example 27 with Artifact

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

the class XmlModuleUpdaterTest method testUpdateWithExcludeConfigurations4.

@Test
public void testUpdateWithExcludeConfigurations4() throws Exception {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    URL settingsUrl = new File("test/java/org/apache/ivy/plugins/parser/xml/" + "test-update-excludedconfs4.xml").toURI().toURL();
    XmlModuleDescriptorUpdater.update(settingsUrl, buffer, getUpdateOptions("release", "mynewrev").setConfsToExclude(new String[] { "myconf2" }));
    XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance();
    ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, false), true);
    // test the number of configurations
    Artifact[] artifacts = updatedMd.getAllArtifacts();
    assertNotNull("Published artifacts shouldn't be null", artifacts);
    assertEquals("Number of published artifacts incorrect", 4, artifacts.length);
    // test that the correct configuration has been removed
    for (Artifact current : artifacts) {
        List<String> currentConfs = Arrays.asList(current.getConfigurations());
        assertTrue("myconf2 hasn't been removed for artifact " + current.getName(), !currentConfs.contains("myconf2"));
    }
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ByteArrayInputStream(java.io.ByteArrayInputStream) IvySettings(org.apache.ivy.core.settings.IvySettings) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BasicResource(org.apache.ivy.plugins.repository.BasicResource) File(java.io.File) URL(java.net.URL) Artifact(org.apache.ivy.core.module.descriptor.Artifact) Test(org.junit.Test)

Example 28 with Artifact

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

the class BintrayResolverTest method testBintrayArtifacts.

@Test
public void testBintrayArtifacts() throws Exception {
    BintrayResolver resolver = new BintrayResolver();
    resolver.setName("test");
    resolver.setSettings(settings);
    assertEquals("test", resolver.getName());
    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache.ant", "ant-antunit", "1.2");
    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(mrid, false);
    dd.addIncludeRule("default", new DefaultIncludeRule(new ArtifactId(mrid.getModuleId(), "ant-antunit", "javadoc", "jar"), ExactPatternMatcher.INSTANCE, null));
    dd.addIncludeRule("default", new DefaultIncludeRule(new ArtifactId(mrid.getModuleId(), "ant-antunit", "sources", "jar"), ExactPatternMatcher.INSTANCE, null));
    ResolvedModuleRevision rmr = resolver.getDependency(dd, data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());
    DefaultArtifact profiler = new DefaultArtifact(mrid, rmr.getPublicationDate(), "ant-antunit", "javadoc", "jar");
    DefaultArtifact trace = new DefaultArtifact(mrid, rmr.getPublicationDate(), "ant-antunit", "sources", "jar");
    DownloadReport report = resolver.download(new Artifact[] { profiler, trace }, downloadOptions());
    assertNotNull(report);
    assertEquals(2, report.getArtifactsReports().length);
    ArtifactDownloadReport ar = report.getArtifactReport(profiler);
    assertNotNull(ar);
    assertEquals(profiler, ar.getArtifact());
    assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
    ar = report.getArtifactReport(trace);
    assertNotNull(ar);
    assertEquals(trace, ar.getArtifact());
    assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
    // test to ask to download again, should use cache
    report = resolver.download(new Artifact[] { profiler, trace }, downloadOptions());
    assertNotNull(report);
    assertEquals(2, report.getArtifactsReports().length);
    ar = report.getArtifactReport(profiler);
    assertNotNull(ar);
    assertEquals(profiler, ar.getArtifact());
    assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
    ar = report.getArtifactReport(trace);
    assertNotNull(ar);
    assertEquals(trace, ar.getArtifact());
    assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
}
Also used : DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ArtifactId(org.apache.ivy.core.module.id.ArtifactId) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) DefaultIncludeRule(org.apache.ivy.core.module.descriptor.DefaultIncludeRule) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Example 29 with Artifact

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

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

Artifact (org.apache.ivy.core.module.descriptor.Artifact)106 Test (org.junit.Test)68 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)59 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)55 File (java.io.File)53 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)31 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)30 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)28 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)25 Date (java.util.Date)22 DownloadReport (org.apache.ivy.core.report.DownloadReport)20 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)15 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)13 Configuration (org.apache.ivy.core.module.descriptor.Configuration)10 IOException (java.io.IOException)9 PublishArtifact (org.gradle.api.artifacts.PublishArtifact)9 ParseException (java.text.ParseException)8 XmlModuleDescriptorParserTest (org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest)8 ResolveReport (org.apache.ivy.core.report.ResolveReport)7 DownloadOptions (org.apache.ivy.core.resolve.DownloadOptions)7