Java Code Examples for org.apache.ivy.core.report.ResolveReport#getModuleDescriptor()

The following examples show how to use org.apache.ivy.core.report.ResolveReport#getModuleDescriptor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RetrieveTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testRetrieveSimple() throws Exception {
    // mod1.1 depends on mod1.2
    ResolveReport report = ivy.resolve(new File(
            "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURI().toURL(),
        getResolveOptions(new String[] {"*"}));
    assertNotNull(report);
    ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull(md);

    String pattern = "build/test/retrieve/[module]/[conf]/[artifact]-[revision].[ext]";
    ivy.retrieve(md.getModuleRevisionId(),
        getRetrieveOptions().setDestArtifactPattern(pattern));
    assertTrue(new File(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2",
        "jar", "jar", "default")).exists());

    pattern = "build/test/retrieve/[module]/[conf]/[type]s/[artifact]-[revision].[ext]";
    ivy.retrieve(md.getModuleRevisionId(),
        getRetrieveOptions().setDestArtifactPattern(pattern));
    assertTrue(new File(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2",
        "jar", "jar", "default")).exists());
}
 
Example 2
Source File: RetrieveTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testRetrieveSameFileConflict() throws Exception {
    // mod1.1 depends on mod1.2
    ResolveReport report = ivy.resolve(new File(
            "test/repositories/1/org1/mod1.4/ivys/ivy-1.0.1.xml").toURI().toURL(),
        getResolveOptions(new String[] {"*"}));
    assertNotNull(report);
    ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull(md);

    String pattern = "build/test/retrieve/[module]/[artifact]-[revision].[ext]";
    MockMessageLogger mockLogger = new MockMessageLogger();
    Message.setDefaultLogger(mockLogger);
    ivy.retrieve(md.getModuleRevisionId(),
        getRetrieveOptions().setDestArtifactPattern(pattern));
    assertTrue(new File(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.2", "mod1.2",
        "jar", "jar", "default")).exists());
    mockLogger.assertLogDoesntContain("conflict on");
}
 
Example 3
Source File: RetrieveTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test(expected = RuntimeException.class)
public void testRetrieveDifferentArtifactsOfSameModuleToSameFile() throws Exception {
    ResolveReport report = ivy.resolve(new File(
            "test/repositories/1/org2/mod2.2/ivys/ivy-0.5.xml").toURI().toURL(),
        getResolveOptions(new String[] {"*"}));
    assertNotNull(report);
    ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull(md);

    String pattern = "build/test/retrieve/[module]/[module].[ext]";
    MockMessageLogger mockLogger = new MockMessageLogger();
    Message.setDefaultLogger(mockLogger);
    try {
        ivy.retrieve(md.getModuleRevisionId(),
            getRetrieveOptions().setDestArtifactPattern(pattern));
    } finally {
        mockLogger.assertLogDoesntContain("multiple artifacts");
    }
}
 
Example 4
Source File: RetrieveTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testRetrieveOverwrite() throws Exception {
    // mod1.1 depends on mod1.2
    ResolveReport report = ivy.resolve(new File(
            "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURI().toURL(),
        getResolveOptions(new String[] {"*"}));
    assertNotNull(report);
    ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull(md);

    String pattern = "build/test/retrieve/[module]/[conf]/[artifact]-[revision].[ext]";

    // we create a fake old file to see if it is overwritten
    File file = new File(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0",
        "mod1.2", "jar", "jar", "default")).getCanonicalFile();
    file.getParentFile().mkdirs();
    file.createNewFile();
    ivy.retrieve(md.getModuleRevisionId(),
        getRetrieveOptions().setOverwriteMode("always").setDestArtifactPattern(pattern));
    assertEquals(new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar").lastModified(),
        file.lastModified());
}
 
Example 5
Source File: RetrieveTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testRetrieveWithSymlinks() throws Exception {
    // mod1.1 depends on mod1.2
    ResolveReport report = ivy.resolve(new File(
            "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURI().toURL(),
        getResolveOptions(new String[] {"*"}));
    assertNotNull(report);
    ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull(md);

    String pattern = "build/test/retrieve/[module]/[conf]/[artifact]-[revision].[ext]";
    ivy.retrieve(md.getModuleRevisionId(),
        getRetrieveOptions().setMakeSymlinks(true).setDestArtifactPattern(pattern));
    assertLinkOrExists(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2", "jar",
        "jar", "default"));

    pattern = "build/test/retrieve/[module]/[conf]/[type]s/[artifact]-[revision].[ext]";
    ivy.retrieve(md.getModuleRevisionId(),
        getRetrieveOptions().setMakeSymlinks(true).setDestArtifactPattern(pattern));
    assertLinkOrExists(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2", "jar",
        "jar", "default"));
}
 
Example 6
Source File: RetrieveTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that retrieve, when invoked with "symlink" enabled, creates the necessary symlink
 * when the artifact being retrieved is a directory instead of a regular file
 *
 * @throws Exception
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1594">IVY-1594</a>
 */
@Test
public void testRetrieveZipArtifactWithSymlinks() throws Exception {
    // resolve (inline) with org1:mod1.1:3.0 as a dependency
    final ResolveReport report = ivy.resolve(new ModuleRevisionId(new ModuleId("org1", "mod1.7"), "3.0"),
            getResolveOptions(new String[]{"*"}), false);
    assertNotNull("Resolution report is null", report);
    final ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull("Module descriptor is null", md);

    final String retrievePattern = "build/test/retrieve/[module]/[conf]/[artifact]-[revision]";
    ivy.retrieve(md.getModuleRevisionId(),
            getRetrieveOptions().setMakeSymlinks(true).setDestArtifactPattern(retrievePattern));

    final String expectedRetrieveLocation = IvyPatternHelper.substitute(retrievePattern, "org1", "mod1.7",
            "3.0", "zipped-artifact", null, null, "default");
    // make sure it's retrieved as a symlink (on systems that support symlink)
    assertLinkOrExists(expectedRetrieveLocation);
}
 
Example 7
Source File: RetrieveTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * This test is here to just test the deprecated {@code symlinkmass} option for retrieve task.
 * A version or two down the line, after 2.5 release, we can remove this test and the option
 * altogether.
 *
 * @throws Exception if something goes wrong
 */
@SuppressWarnings("deprecation")
@Test
public void testRetrieveWithSymlinksMass() throws Exception {
    // mod1.1 depends on mod1.2
    ResolveReport report = ivy.resolve(new File(
            "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURI().toURL(),
        getResolveOptions(new String[] {"*"}));
    assertNotNull(report);
    ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull(md);

    String pattern = "build/test/retrieve/[module]/[conf]/[artifact]-[revision].[ext]";
    ivy.retrieve(md.getModuleRevisionId(),
        getRetrieveOptions().setMakeSymlinksInMass(true).setDestArtifactPattern(pattern));
    assertLinkOrExists(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2", "jar",
        "jar", "default"));

    pattern = "build/test/retrieve/[module]/[conf]/[type]s/[artifact]-[revision].[ext]";
    ivy.retrieve(md.getModuleRevisionId(),
        getRetrieveOptions().setMakeSymlinksInMass(true).setDestArtifactPattern(pattern));
    assertLinkOrExists(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2", "jar",
        "jar", "default"));
}
 
Example 8
Source File: RetrieveTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testRetrieveWithVariable() throws Exception {
    // mod1.1 depends on mod1.2
    ivy.setVariable("retrieve.dir", "retrieve");
    ResolveReport report = ivy.resolve(new File(
            "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURI().toURL(),
        getResolveOptions(new String[] {"*"}));
    assertNotNull(report);
    ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull(md);

    String pattern = "build/test/${retrieve.dir}/[module]/[conf]/[artifact]-[revision].[ext]";
    ivy.retrieve(md.getModuleRevisionId(),
        getRetrieveOptions().setDestArtifactPattern(pattern));
    pattern = IvyPatternHelper.substituteVariable(pattern, "retrieve.dir", "retrieve");
    assertTrue(new File(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2",
        "jar", "jar", "default")).exists());

    pattern = "build/test/${retrieve.dir}/[module]/[conf]/[type]s/[artifact]-[revision].[ext]";
    ivy.retrieve(md.getModuleRevisionId(),
        getRetrieveOptions().setDestArtifactPattern(pattern));
    pattern = IvyPatternHelper.substituteVariable(pattern, "retrieve.dir", "retrieve");
    assertTrue(new File(IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2",
        "jar", "jar", "default")).exists());
}
 
Example 9
Source File: RetrieveTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * Test case for IVY-1478.
 * {@link RetrieveEngine} must retrieve artifacts with the correct extension if the artifact
 * is unpacked.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1478">IVY-1478</a>
 */
@Test
public void testUnpackExt() throws Exception {
    final ResolveOptions roptions = getResolveOptions(new String[] {"*"});

    final URL url = new File("test/repositories/1/packaging/module10/ivys/ivy-1.0.xml").toURI()
            .toURL();

    // normal resolve, the file goes in the cache
    final ResolveReport report = ivy.resolve(url, roptions);
    assertFalse("Resolution report has errors", report.hasError());
    final ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull("Module descriptor from report was null", md);

    final String pattern = "build/test/retrieve/[organization]/[module]/[conf]/[type]s/[artifact]-[revision](.[ext])";

    ivy.retrieve(md.getModuleRevisionId(),
        getRetrieveOptions().setDestArtifactPattern(pattern));

    final File dest = new File("build/test/retrieve/packaging/module9/default/jars/module9-1.0.jar");
    assertTrue("Retrieved artifact is missing at " + dest.getAbsolutePath(), dest.exists());
    assertTrue("Retrieved artifact at " + dest.getAbsolutePath() + " is not a file", dest.isFile());
}
 
Example 10
Source File: IvyTask.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
protected void setResolved(ResolveReport report, boolean keep) {
    ModuleDescriptor md = report.getModuleDescriptor();
    String[] confs = report.getConfigurations();
    if (keep) {
        getProject().addReference("ivy.resolved.report", report);
        getProject().addReference("ivy.resolved.configurations.ref", confs);
        getProject().addReference("ivy.resolved.descriptor", md);
    }
    String suffix = md.getModuleRevisionId().getModuleId().getOrganisation() + "."
            + md.getModuleRevisionId().getModuleId().getName();
    getProject().addReference("ivy.resolved.report." + suffix, report);
    getProject().addReference("ivy.resolved.descriptor." + suffix, md);
    getProject().addReference("ivy.resolved.configurations.ref." + suffix, confs);
}
 
Example 11
Source File: IvyTask.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
protected void setResolved(ResolveReport report, String resolveId, boolean keep) {
    setResolved(report, keep);
    if (resolveId == null) {
        return;
    }
    ModuleDescriptor md = report.getModuleDescriptor();
    String[] confs = report.getConfigurations();
    getProject().addReference("ivy.resolved.report." + resolveId, report);
    getProject().addReference("ivy.resolved.descriptor." + resolveId, md);
    getProject().addReference("ivy.resolved.configurations.ref." + resolveId, confs);
}
 
Example 12
Source File: RetrieveTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testEvent() throws Exception {
    ResolveReport report = ivy.resolve(new File(
            "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURI().toURL(),
        getResolveOptions(new String[] {"*"}));

    final List<IvyEvent> events = new ArrayList<>();
    ivy.getEventManager().addIvyListener(new IvyListener() {
        public void progress(IvyEvent event) {
            events.add(event);
        }
    });
    ModuleDescriptor md = report.getModuleDescriptor();
    String pattern = "build/test/retrieve/[module]/[conf]/[artifact]-[revision].[ext]";
    ivy.retrieve(md.getModuleRevisionId(),
        getRetrieveOptions().setDestArtifactPattern(pattern));
    assertEquals(4, events.size());
    assertTrue(events.get(0) instanceof StartRetrieveEvent);
    assertTrue(events.get(1) instanceof StartRetrieveArtifactEvent);
    assertTrue(events.get(2) instanceof EndRetrieveArtifactEvent);
    assertTrue(events.get(3) instanceof EndRetrieveEvent);
    EndRetrieveEvent ev = (EndRetrieveEvent) events.get(3);
    assertEquals(1, ev.getNbCopied());
    assertEquals(0, ev.getNbUpToDate());

    events.clear();
    ivy.retrieve(md.getModuleRevisionId(),
        getRetrieveOptions().setDestArtifactPattern(pattern));
    assertEquals(2, events.size());
    assertTrue(events.get(0) instanceof StartRetrieveEvent);
    assertTrue(events.get(1) instanceof EndRetrieveEvent);
    ev = (EndRetrieveEvent) events.get(1);
    assertEquals(0, ev.getNbCopied());
    assertEquals(1, ev.getNbUpToDate());
}
 
Example 13
Source File: RetrieveTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testRetrieveReport() throws Exception {
    // mod1.1 depends on mod1.2
    ResolveReport report = ivy.resolve(new File(
            "test/repositories/1/org20/mod20.1/ivys/ivy-1.2.xml").toURI().toURL(),
        getResolveOptions(new String[] {"*"}));
    assertNotNull(report);
    ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull(md);

    ModuleRevisionId mrid = md.getModuleRevisionId();
    RetrieveOptions options = getRetrieveOptions();
    options.setConfs(new String[] {"A"});
    Map<ArtifactDownloadReport, Set<String>> artifactsToCopy = ivy.getRetrieveEngine()
            .determineArtifactsToCopy(mrid,
                "build/test/retrieve/[module]/[conf]/[artifact]-[revision].[ext]", options);
    assertEquals(2, artifactsToCopy.size());

    options.setConfs(new String[] {"B"});
    artifactsToCopy = ivy.getRetrieveEngine().determineArtifactsToCopy(mrid,
        "build/test/retrieve/[module]/[conf]/[artifact]-[revision].[ext]", options);
    assertEquals(2, artifactsToCopy.size());

    options.setConfs(new String[] {"A", "B"});
    artifactsToCopy = ivy.getRetrieveEngine().determineArtifactsToCopy(mrid,
        "build/test/retrieve/[module]/[conf]/[artifact]-[revision].[ext]", options);
    assertEquals(3, artifactsToCopy.size());
}
 
Example 14
Source File: RetrieveTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnpack() throws Exception {
    ResolveOptions roptions = 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, roptions);
    assertFalse(report.hasError());
    ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull(md);

    String pattern = "build/test/retrieve/[organization]/[module]/[conf]/[type]s/[artifact]-[revision](.[ext])";

    ivy.retrieve(md.getModuleRevisionId(),
        getRetrieveOptions().setDestArtifactPattern(pattern));

    File dest = new File("build/test/retrieve/packaging/module2/default/jars/module2-1.0");
    assertTrue(dest.exists());
    assertTrue(dest.isDirectory());
    File[] jarContents = dest.listFiles();
    Arrays.sort(jarContents);
    assertEquals(new File(dest, "META-INF"), jarContents[0]);
    assertEquals(new File(dest, "test.txt"), jarContents[1]);
    assertEquals(new File(dest, "META-INF/MANIFEST.MF"), jarContents[0].listFiles()[0]);
}
 
Example 15
Source File: RetrieveTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnpackSync() throws Exception {
    ResolveOptions roptions = 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, roptions);
    assertFalse(report.hasError());
    ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull(md);

    String pattern = "build/test/retrieve/[organization]/[module]/[conf]/[type]s/[artifact]-[revision](.[ext])";

    ivy.retrieve(md.getModuleRevisionId(),
        getRetrieveOptions().setSync(true).setDestArtifactPattern(pattern));

    File dest = new File("build/test/retrieve/packaging/module2/default/jars/module2-1.0");
    assertTrue(dest.exists());
    assertTrue(dest.isDirectory());
    File[] jarContents = dest.listFiles();
    Arrays.sort(jarContents);
    assertEquals(new File(dest, "META-INF"), jarContents[0]);
    assertEquals(new File(dest, "test.txt"), jarContents[1]);
    assertEquals(new File(dest, "META-INF/MANIFEST.MF"), jarContents[0].listFiles()[0]);
}
 
Example 16
Source File: IBiblioMavenSnapshotsResolutionTest.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that an Ivy module that depends on regular and timestamped snapshots of Maven
 * artifacts, when resolved using a {@link IBiblioResolver} and with
 * {@link MavenTimedSnapshotVersionMatcher} configured in {@link IvySettings}, is resolved
 * correctly for such snapshot dependencies.
 *
 * @throws Exception
 *             if something goes wrong
 */
@Test
public void testSnapshotResolution() throws Exception {
    final IvySettings settings = this.ivy.getSettings();
    assertNotNull("Maven timestamped snapshot revision version matcher is absent",
        settings.getVersionMatcher(new MavenTimedSnapshotVersionMatcher().getName()));
    final ResolveOptions resolveOptions = new ResolveOptions();
    resolveOptions.setConfs(new String[]{"default"});
    final ResolveReport report = ivy.resolve(new File("test/repositories/2/maven-snapshot-deps-test/ivy-with-maven-snapshot-deps.xml"), resolveOptions);
    assertNotNull("Resolution report was null", report);
    assertFalse("Resolution report has error(s)", report.hasError());

    final ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull("Module descriptor in resolution report was null", md);
    final ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache.ivy",
        "maven-snapshot-deps-test", "1.2.3");
    assertEquals("Unexpected module resolved", mrid, md.getModuleRevisionId());

    final ConfigurationResolveReport crr = report.getConfigurationReport("default");

    final ModuleRevisionId exactRevision = ModuleRevisionId.newInstance("org.apache.ivy.maven-snapshot-test", "exact-revision", "2.3.4");
    final ArtifactDownloadReport[] dr1 = crr.getDownloadReports(exactRevision);
    assertNotNull("Artifact download report missing for dependency " + exactRevision, dr1);
    assertEquals("Unexpected number of artifact download report for dependency " + exactRevision, dr1.length, 1);
    final ArtifactDownloadReport exactRevDownloadReport = dr1[0];
    assertEquals("Unexpected download status for dependency " + exactRevision,
        exactRevDownloadReport.getDownloadStatus(), DownloadStatus.SUCCESSFUL);

    final ModuleRevisionId regularSnapshot = ModuleRevisionId.newInstance("org.apache.ivy.maven-snapshot-test", "regular-snapshot", "1.2.3-SNAPSHOT");
    final ArtifactDownloadReport[] dr2 = crr.getDownloadReports(regularSnapshot);
    assertNotNull("Artifact download report missing for dependency " + regularSnapshot, dr2);
    assertEquals("Unexpected number of artifact download report for dependency " + regularSnapshot, dr2.length, 1);
    final ArtifactDownloadReport regularSnapshotDownloadReport = dr2[0];
    assertEquals("Unexpected download status for dependency " + regularSnapshot,
        regularSnapshotDownloadReport.getDownloadStatus(), DownloadStatus.SUCCESSFUL);

    final ModuleRevisionId timestampedSnapshot = ModuleRevisionId.newInstance("org.apache.ivy.maven-snapshot-test", "timestamped-snapshot", "5.6.7-20170911.130943-1");
    final ArtifactDownloadReport[] dr3 = crr.getDownloadReports(timestampedSnapshot);
    assertNotNull("Artifact download report missing for dependency " + timestampedSnapshot, dr3);
    assertEquals("Unexpected number of artifact download report for dependency " + timestampedSnapshot, dr3.length, 1);
    final ArtifactDownloadReport timestampedSnapshotDownloadReport = dr3[0];
    assertEquals("Unexpected download status for dependency " + timestampedSnapshot,
        timestampedSnapshotDownloadReport.getDownloadStatus(), DownloadStatus.SUCCESSFUL);

}