Search in sources :

Example 21 with ArtifactDownloadReport

use of org.apache.ivy.core.report.ArtifactDownloadReport in project ant-ivy by apache.

the class ResolveTest method testUnpack.

@Test
public void testUnpack() throws Exception {
    ResolveOptions options = getResolveOptions(new String[] { "*" });
    URL url = new File("test/repositories/1/packaging/module1/ivys/ivy-1.0.xml").toURI().toURL();
    // normal resolve, the file goes in the cache
    ResolveReport report = ivy.resolve(url, options);
    assertFalse(report.hasError());
    ArtifactDownloadReport adr = report.getAllArtifactsReports()[0];
    File cacheDir = ivy.getSettings().getDefaultRepositoryCacheBasedir();
    assertEquals(new File(cacheDir, "packaging/module2/jars/module2-1.0.jar"), adr.getLocalFile());
    assertEquals(new File(cacheDir, "packaging/module2/jar_unpackeds/module2-1.0"), adr.getUnpackedLocalFile());
    File[] jarContents = adr.getUnpackedLocalFile().listFiles();
    Arrays.sort(jarContents);
    assertEquals(new File(adr.getUnpackedLocalFile(), "META-INF"), jarContents[0]);
    assertEquals(new File(adr.getUnpackedLocalFile(), "test.txt"), jarContents[1]);
    assertEquals(new File(adr.getUnpackedLocalFile(), "META-INF/MANIFEST.MF"), jarContents[0].listFiles()[0]);
}
Also used : ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) JarFile(java.util.jar.JarFile) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 22 with ArtifactDownloadReport

use of org.apache.ivy.core.report.ArtifactDownloadReport in project ant-ivy by apache.

the class ResolveTest method testResolveWithConflictManagerDefinedAtHigherLevel.

/**
 * Test case for IVY-1404.
 *
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1404">IVY-1404</a>
 * @throws Exception if something goes wrong
 */
@Test
public void testResolveWithConflictManagerDefinedAtHigherLevel() throws Exception {
    // #M1;1.0 -> #M2;1.0
    // #M1;2.0 -> {#M2;1.0 #M3;1.0}
    // #M2;1.0 -> org1#mod1.2;1.1
    // #M3;1.0 -> org1#mod1.2;2.0
    // #M1;1.0 has conflict manager: <conflict org="org1" module="mod1.2" rev="1.1,2.0" />
    ResolveReport report = ivy.resolve(new File("test/repositories/1/IVY-1404/M1/ivys/ivy-1.0.xml"), getResolveOptions(new String[] { "*" }));
    assertFalse(report.hasError());
    ArtifactDownloadReport[] adrs = report.getConfigurationReport("default").getDownloadedArtifactsReports();
    assertEquals(2, adrs.length);
    assertEquals("1.1", adrs[0].getArtifact().getId().getRevision());
    assertEquals("2.0", adrs[1].getArtifact().getId().getRevision());
}
Also used : ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) JarFile(java.util.jar.JarFile) File(java.io.File) Test(org.junit.Test)

Example 23 with ArtifactDownloadReport

use of org.apache.ivy.core.report.ArtifactDownloadReport in project ant-ivy by apache.

the class RetrieveTest method testRetrieveWithSymlinkToggling.

/**
 * Test case for IVY-1498.
 * More than one retrieve, one having symlink enabled and the other not,
 * must not lead to repository cache corruption.
 * <p>
 * The test does the following:
 * </p>
 * <ul>
 * <li>
 * Resolves a module, let's call it "irrelevant-A" which has a dependency on
 * "org:foo-bar:1.2.3"
 * </li>
 * <li>
 * Invokes a retrieve RT1, with {@link RetrieveOptions#setMakeSymlinks(boolean) symlinks true}
 * on that resolved module with a pattern that translates to a path "a/b/c/foo-bar.jar". When
 * the RT1 retrieve is done, the path "a/b/c/foo-bar.jar" will be a symlink to a path
 * "repo/cache/org/foo-bar/foo-bar-1.2.3.jar" in the Ivy cache.
 * All fine so far.
 * </li>
 * <li>
 * We then resolve another module, let's call it "irrelevant-B" which has a dependency on
 * "org:foo-bar:2.3.4"
 * </li>
 * <li>
 * Next, do a new retrieve RT2, on this newly resolved module with
 * {@link RetrieveOptions#setMakeSymlinks(boolean) symlinks false} and
 * {@link RetrieveOptions#getOverwriteMode() overwrite semantics enabled}
 * and with the same pattern as before), that translates to a path "a/b/c/foo-bar.jar".
 * </li>
 * </ul>
 * <p>
 * When RT2 retrieve is done, we expect the path "a/b/c/foo-bar.jar" will *not* be a symlink
 * and instead be an actual file that represents the org:foo-bar:2.3.4 artifact jar.
 * </p>
 * <p>
 * We also expect that this RT2 retrieve will not update/overwrite the file at path
 * "repo/cache/org/foo-bar/foo-bar-1.2.3.jar" in the Ivy cache - the file that was the end
 * target of the symlink generated by the previous RT1.
 * </p>
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1498">IVY-1498</a>
 */
@Test
public void testRetrieveWithSymlinkToggling() throws Exception {
    // org:mod1:2.0 depends on org:foo-bar:1.2.3
    final ResolveReport resolve1Report = ivy.resolve(new File("test/repositories/1/org/mod1/ivys/ivy-2.0.xml").toURI().toURL(), getResolveOptions(new String[] { "*" }));
    assertNotNull("Resolve report isn't available", resolve1Report);
    assertNotNull("Module descriptor missing in resolve report", resolve1Report.getModuleDescriptor());
    // verify the downloaded dependency artifact in cache
    final ModuleRevisionId fooBar123Mrid = ModuleRevisionId.newInstance("org", "foo-bar", "1.2.3");
    final ArtifactDownloadReport[] downloadReports = resolve1Report.getArtifactsReports(fooBar123Mrid);
    assertNotNull("No artifact download report found for the " + fooBar123Mrid + " dependency", downloadReports);
    assertEquals("Unexpected number for artifact download reports for the " + fooBar123Mrid + " dependency", 1, downloadReports.length);
    final File fooBar123ArtifactInCache = downloadReports[0].getLocalFile();
    assertNotNull("Local file for " + fooBar123Mrid + " missing in download report", fooBar123ArtifactInCache);
    assertTrue("Artifact file for " + fooBar123Mrid + " isn't a file, in cache at " + fooBar123ArtifactInCache, fooBar123ArtifactInCache.isFile());
    final byte[] fooBar123ArtifactContentsInCache = Files.readAllBytes(fooBar123ArtifactInCache.toPath());
    assertTrue("Artifact content was empty at " + new String(fooBar123ArtifactContentsInCache), fooBar123ArtifactContentsInCache.length > 0);
    // now do a retrieve of the resolved module
    final String retrievePattern = "build/test/retrieve/symlink-test/[module]/[artifact].[ext]";
    ivy.retrieve(resolve1Report.getModuleDescriptor().getModuleRevisionId(), getRetrieveOptions().setMakeSymlinks(true).setOverwriteMode(RetrieveOptions.OVERWRITEMODE_ALWAYS).setDestArtifactPattern(retrievePattern));
    // we expect org:foo-bar:1.2.3 to have been retrieved
    final String retrievedArtifactSymlinkPath = IvyPatternHelper.substitute(retrievePattern, "org", "foo-bar", "1.2.3", "foo-bar", "jar", "jar", "default");
    assertLinkOrExists(retrievedArtifactSymlinkPath);
    // get hold of the contents of the retrieved artifact
    final byte[] retrievedArtifactContent = Files.readAllBytes(Paths.get(retrievedArtifactSymlinkPath));
    // compare it to the contents of org:foo-bar:1.2.3 artifact in repo cache. Should be the same
    assertTrue("Unexpected content in the retrieved artifact at " + retrievedArtifactSymlinkPath, Arrays.equals(fooBar123ArtifactContentsInCache, retrievedArtifactContent));
    // let this retrieved artifact file stay and let's now try and resolve a module and then
    // retrieve a different version of the same artifact, *without* symlinking enabled, which
    // will end up at this exact location org:mod1:2.0 depends on org:foo-bar:1.2.3
    final ResolveReport resolve2Report = ivy.resolve(new File("test/repositories/1/org/mod1/ivys/ivy-5.0.xml").toURI().toURL(), getResolveOptions(new String[] { "*" }));
    assertNotNull("Resolve report isn't available", resolve2Report);
    assertNotNull("Module descriptor missing in resolve report", resolve2Report.getModuleDescriptor());
    // verify the downloaded dependency artifact in cache
    final ModuleRevisionId fooBar234Mrid = ModuleRevisionId.newInstance("org", "foo-bar", "2.3.4");
    final ArtifactDownloadReport[] foobar234report = resolve2Report.getArtifactsReports(fooBar234Mrid);
    assertNotNull("No artifact download report found for the " + fooBar234Mrid + " dependency", foobar234report);
    assertEquals("Unexpected number for artifact download reports for the " + fooBar234Mrid + " dependency", 1, foobar234report.length);
    final File foobar234InCache = foobar234report[0].getLocalFile();
    assertNotNull("Local file for " + fooBar234Mrid + " missing in download report", foobar234InCache);
    assertTrue("Artifact file for " + fooBar234Mrid + " isn't a file, in cache at " + foobar234InCache, foobar234InCache.isFile());
    final byte[] foobar234CacheFileContents = Files.readAllBytes(foobar234InCache.toPath());
    assertTrue("Artifact content was empty at " + new String(foobar234CacheFileContents), foobar234CacheFileContents.length > 0);
    // do the retrieve with symlinks disabled
    ivy.retrieve(resolve2Report.getModuleDescriptor().getModuleRevisionId(), getRetrieveOptions().setMakeSymlinks(false).setDestArtifactPattern(retrievePattern).setOverwriteMode(RetrieveOptions.OVERWRITEMODE_ALWAYS));
    // we expect org:foo-bar:2.3.4 to have been retrieved
    final Path secondRetrieveArtifactPath = new File(IvyPatternHelper.substitute(retrievePattern, "org", "foo-bar", "2.3.4", "foo-bar", "jar", "jar", "default")).toPath();
    assertTrue("Artifact wasn't retrieved to " + secondRetrieveArtifactPath, Files.exists(secondRetrieveArtifactPath));
    // expected to be a regular file and not a symlink
    assertFalse("Artifact retrieved at " + secondRetrieveArtifactPath + " wasn't expected to be a " + "symlink", Files.isSymbolicLink(secondRetrieveArtifactPath));
    // get hold of the contents of the retrieved artifact
    final byte[] secondRetrievedArtifactContents = Files.readAllBytes(secondRetrieveArtifactPath);
    // compare it to the contents of org:foo-bar:2.3.4 artifact in repo cache. Should be the same
    assertTrue("Unexpected content in the retrieved artifact at " + secondRetrieveArtifactPath, Arrays.equals(foobar234CacheFileContents, secondRetrievedArtifactContents));
    // also make sure that this retrieved content hasn't messed up the other (unrelated) file,
    // in the cache, that was previously symlinked to this retrieved path
    assertTrue("A second retrieve of an artifact has corrupted an unrelated (previously symlinked) artifact in cache", Arrays.equals(fooBar123ArtifactContentsInCache, Files.readAllBytes(Paths.get(fooBar123ArtifactInCache.getPath()))));
}
Also used : Path(java.nio.file.Path) ResolveReport(org.apache.ivy.core.report.ResolveReport) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) File(java.io.File) Test(org.junit.Test)

Example 24 with ArtifactDownloadReport

use of org.apache.ivy.core.report.ArtifactDownloadReport in project ant-ivy by apache.

the class ResolveEngineTest method testLocateThenDownload.

private void testLocateThenDownload(ResolveEngine engine, Artifact artifact, File artifactFile) {
    ArtifactOrigin origin = engine.locate(artifact);
    assertNotNull(origin);
    assertTrue(origin.isLocal());
    assertEquals(artifactFile.getAbsolutePath(), new File(origin.getLocation()).getAbsolutePath());
    ArtifactDownloadReport r = engine.download(origin, new DownloadOptions());
    assertNotNull(r);
    assertEquals(DownloadStatus.SUCCESSFUL, r.getDownloadStatus());
    assertNotNull(r.getLocalFile());
    assertTrue(r.getLocalFile().exists());
}
Also used : ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ArtifactOrigin(org.apache.ivy.core.cache.ArtifactOrigin) File(java.io.File)

Example 25 with ArtifactDownloadReport

use of org.apache.ivy.core.report.ArtifactDownloadReport in project ant-ivy by apache.

the class P2DescriptorTest method testResolveSource.

@Test
public void testResolveSource() throws Exception {
    settings.setDefaultResolver("p2-sources");
    ModuleRevisionId mrid = ModuleRevisionId.newInstance(BundleInfo.BUNDLE_TYPE, "org.apache.ivy", "2.2.0.final_20100923230623");
    ResolvedModuleRevision rmr = p2SourceResolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());
    assertEquals(2, rmr.getDescriptor().getAllArtifacts().length);
    DownloadReport report = p2SourceResolver.download(rmr.getDescriptor().getAllArtifacts(), new DownloadOptions());
    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());
        // test to ask to download again, should use cache
        DownloadReport report2 = p2SourceResolver.download(new Artifact[] { artifact }, new DownloadOptions());
        assertNotNull(report2);
        assertEquals(1, report2.getArtifactsReports().length);
        ar = report2.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) 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)

Aggregations

ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)64 File (java.io.File)33 Artifact (org.apache.ivy.core.module.descriptor.Artifact)29 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)26 Test (org.junit.Test)25 DownloadReport (org.apache.ivy.core.report.DownloadReport)23 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)18 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)18 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)17 ResolveReport (org.apache.ivy.core.report.ResolveReport)15 ConfigurationResolveReport (org.apache.ivy.core.report.ConfigurationResolveReport)11 IOException (java.io.IOException)10 DownloadOptions (org.apache.ivy.core.resolve.DownloadOptions)10 URL (java.net.URL)8 JarFile (java.util.jar.JarFile)8 Date (java.util.Date)7 MetadataArtifactDownloadReport (org.apache.ivy.core.report.MetadataArtifactDownloadReport)7 URLResource (org.apache.ivy.plugins.repository.url.URLResource)7 ArtifactOrigin (org.apache.ivy.core.cache.ArtifactOrigin)6 MalformedURLException (java.net.MalformedURLException)5