Search in sources :

Example 66 with Artifact

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

the class P2DescriptorTest method testResolveZipped.

@Test
public void testResolveZipped() throws Exception {
    settings.setDefaultResolver("p2-zipped");
    ModuleRevisionId mrid = ModuleRevisionId.newInstance(BundleInfo.BUNDLE_TYPE, "org.apache.ant", "1.8.3.v20120321-1730");
    ResolvedModuleRevision rmr = p2ZippedResolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());
    assertEquals(2, rmr.getDescriptor().getAllArtifacts().length);
    DownloadOptions options = new DownloadOptions();
    DownloadReport report = p2ZippedResolver.download(rmr.getDescriptor().getAllArtifacts(), options);
    assertNotNull(report);
    assertEquals(2, report.getArtifactsReports().length);
    for (int i = 0; i < 2; i++) {
        Artifact artifact = rmr.getDescriptor().getAllArtifacts()[i];
        ArtifactDownloadReport ar = report.getArtifactReport(artifact);
        assertNotNull(ar);
        assertEquals(artifact, ar.getArtifact());
        assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
        // only the binary get unpacked
        if (ar.getArtifact().getType().equals("source")) {
            assertNull(ar.getUnpackedLocalFile());
        } else {
            assertNotNull(ar.getUnpackedLocalFile());
        }
    }
}
Also used : DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) DownloadOptions(org.apache.ivy.core.resolve.DownloadOptions) 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) Artifact(org.apache.ivy.core.module.descriptor.Artifact) Test(org.junit.Test)

Example 67 with Artifact

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

the class UpdateSiteAndIbiblioResolverTest method testArtifactRef.

@Test
public void testArtifactRef() throws ParseException {
    // Simple Dependency for ibiblio
    ModuleRevisionId mrid1 = ModuleRevisionId.newInstance("log4j", "log4j", "1.2.16");
    ResolvedModuleRevision rmr1 = chain.getDependency(new DefaultDependencyDescriptor(mrid1, false), data);
    // Simple Dependency for updatesite
    ModuleRevisionId mrid2 = ModuleRevisionId.newInstance(BundleInfo.BUNDLE_TYPE, "org.apache.ivy", "2.0.0.final_20090108225011");
    ResolvedModuleRevision rmr2 = chain.getDependency(new DefaultDependencyDescriptor(mrid2, false), data);
    assertNotNull(rmr1);
    assertNotNull(rmr2);
    Artifact[] artifacts1 = rmr1.getDescriptor().getArtifacts("default");
    Artifact[] artifacts2 = rmr2.getDescriptor().getArtifacts("default");
    chain.exists(artifacts2[0]);
    chain.exists(artifacts1[0]);
}
Also used : ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) Artifact(org.apache.ivy.core.module.descriptor.Artifact) Test(org.junit.Test)

Example 68 with Artifact

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

the class UpdateSiteResolverTest method genericTestResolveDownload.

private void genericTestResolveDownload(DependencyResolver resolver, ModuleRevisionId mrid) throws ParseException {
    ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());
    Artifact artifact = rmr.getDescriptor().getAllArtifacts()[0];
    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.SUCCESSFUL, ar.getDownloadStatus());
    // test to ask to download again, should use cache
    report = resolver.download(new Artifact[] { artifact }, new DownloadOptions());
    assertNotNull(report);
    assertEquals(1, report.getArtifactsReports().length);
    ar = report.getArtifactReport(artifact);
    assertNotNull(ar);
    assertEquals(artifact, ar.getArtifact());
    assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
}
Also used : DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) DownloadOptions(org.apache.ivy.core.resolve.DownloadOptions) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) Artifact(org.apache.ivy.core.module.descriptor.Artifact)

Example 69 with Artifact

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

the class PublishEngineTest method testAtomicity.

@Test
public void testAtomicity() throws Exception {
    IvySettings settings = new IvySettings();
    final PublishEngine engine = new PublishEngine(settings, new EventManager());
    final int[] counter = new int[] { 0 };
    final DefaultModuleDescriptor md = DefaultModuleDescriptor.newDefaultInstance(ModuleRevisionId.parse("#A;1.0"));
    final FileSystemResolver resolver = new FileSystemResolver() {

        public void publish(Artifact artifact, File src, boolean overwrite) throws IOException {
            super.publish(artifact, src, overwrite);
            synchronized (PublishEngineTest.this) {
                counter[0]++;
            }
            sleepSilently(50);
            synchronized (PublishEngineTest.this) {
                counter[0]++;
            }
        }
    };
    resolver.setName("test");
    resolver.setSettings(settings);
    String publishRepoDir = new File("build/test/publish/repo").getAbsolutePath();
    resolver.addIvyPattern(publishRepoDir + "/[module]/[revision]/[artifact].[ext]");
    resolver.addArtifactPattern(publishRepoDir + "/[module]/[revision]/[artifact].[ext]");
    FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), new File("build/test/publish/module/A.jar"), null);
    XmlModuleDescriptorWriter.write(md, new File("build/test/publish/module/ivy.xml"));
    resolveAndAssertNotFound(settings, resolver, "#A;latest.integration", "before publishing");
    // run publish asynchronously
    new Thread() {

        public void run() {
            try {
                engine.publish(md, Collections.singletonList("build/test/publish/module/[artifact].[ext]"), resolver, new PublishOptions().setSrcIvyPattern("build/test/publish/module/[artifact].[ext]"));
                synchronized (PublishEngineTest.this) {
                    counter[0]++;
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }.start();
    while (true) {
        sleepSilently(5);
        synchronized (this) {
            if (counter[0] == 5) {
                break;
            } else if (counter[0] < 4) {
                resolveAndAssertNotFound(settings, resolver, "#A;latest.integration", "after " + (counter[0] / 2) + " artifacts published");
            }
        }
    }
    resolveAndAssertFound(settings, resolver, "#A;1.0");
}
Also used : EventManager(org.apache.ivy.core.event.EventManager) IvySettings(org.apache.ivy.core.settings.IvySettings) IOException(java.io.IOException) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) File(java.io.File) FileSystemResolver(org.apache.ivy.plugins.resolver.FileSystemResolver) Test(org.junit.Test)

Example 70 with Artifact

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

the class ResolveTest method testMultiClassifierMavenDepResolution.

/**
 * Tests that if a pom.xml has multiple dependencies for the same module, but for different Maven classifiers,
 * then the resolution of such dependencies, preserves those multiple (Ivy) artifacts against the dependency
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1576">IVY-1576</a> for more details
 */
@Test
public void testMultiClassifierMavenDepResolution() throws Exception {
    final File pomFile = new File("test/repositories/m2/org/apache/test-classifier/1.0/test-classifier-1.0.pom");
    final ResolveReport resolveReport = ivy.resolve(pomFile.toURI().toURL(), new ResolveOptions().setConfs(new String[] { "*" }));
    assertFalse(resolveReport.hasError());
    final ModuleRevisionId dependencyId = ModuleRevisionId.newInstance("org.apache", "test-classified", "1.0");
    final ArtifactDownloadReport[] adrs = resolveReport.getArtifactsReports(dependencyId);
    assertNotNull("Artifact download reports is null for dependency " + dependencyId, adrs);
    assertEquals("Unexpected number of artifact download reports for dependency " + dependencyId, 3, adrs.length);
    final Set<String> classifiers = new HashSet<>();
    Collections.addAll(classifiers, "other", "asl", "unix");
    for (final ArtifactDownloadReport adr : adrs) {
        final Artifact artifact = adr.getArtifact();
        assertNotNull("Artifact is null for dependency " + dependencyId, artifact);
        final ArtifactRevisionId artifactId = artifact.getId();
        assertEquals("Unexpected artifact " + artifactId.getName(), "test-classified", artifactId.getName());
        final String classifier = artifact.getExtraAttribute("m:classifier");
        assertNotNull("No classifier extra attribute on artifact for dependency " + dependencyId, classifier);
        assertTrue("Unexpected classifier " + classifier + " on artifact " + artifact, classifiers.remove(classifier));
        // just make sure it's the correct jar file
        assertJarContains(adr.getLocalFile(), classifier + ".txt");
    }
    assertTrue("Missing artifact(s) with classifiers " + classifiers, classifiers.isEmpty());
}
Also used : ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) 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) ArtifactRevisionId(org.apache.ivy.core.module.id.ArtifactRevisionId) HashSet(java.util.HashSet) 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