Java Code Examples for org.apache.ivy.Ivy#install()

The following examples show how to use org.apache.ivy.Ivy#install() . 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: InstallTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testMaven() throws Exception {
    Ivy ivy = Ivy.newInstance();
    ivy.configure(new File("test/repositories/ivysettings.xml"));

    @SuppressWarnings("unused")
    ResolveReport rr = ivy.install(ModuleRevisionId.newInstance("org.apache", "test", "1.0"),
        ivy.getSettings().getDefaultResolver().getName(), "install", new InstallOptions());

    assertTrue(new File("build/test/install/org.apache/test/ivy-1.0.xml").exists());
    assertTrue(new File("build/test/install/org.apache/test/test-1.0.jar").exists());

    // the original descriptor is not installed
    assertFalse(new File("build/test/install/org.apache/test/test-1.0.pom").exists());

    ivy.install(ModuleRevisionId.newInstance("org.apache", "test", "1.0"), ivy.getSettings()
            .getDefaultResolver().getName(), "install", new InstallOptions()
            .setInstallOriginalMetadata(true).setOverwrite(true));

    // the original descriptor is installed now, too
    assertTrue(new File("build/test/install/org.apache/test/test-1.0.pom").exists());
}
 
Example 2
Source File: InstallTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testLatestDependenciesNoDefaultResolver() throws Exception {
    Ivy ivy = Ivy.newInstance();
    ivy.configure(new File("test/repositories/ivysettings-nodefaultresolver.xml"));

    ivy.install(ModuleRevisionId.newInstance("org1", "mod1.4", "1.0.1"), "test", "install",
        new InstallOptions());

    assertTrue(new File("build/test/install/org1/mod1.4/ivy-1.0.1.xml").exists());

    assertTrue(new File("build/test/install/org1/mod1.1/ivy-2.0.xml").exists());
    assertTrue(new File("build/test/install/org1/mod1.1/mod1.1-2.0.jar").exists());

    assertTrue(new File("build/test/install/org1/mod1.2/ivy-2.2.xml").exists());
    assertTrue(new File("build/test/install/org1/mod1.2/mod1.2-2.2.jar").exists());
}
 
Example 3
Source File: InstallTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testLatestDependenciesDummyDefaultResolver() throws Exception {
    Ivy ivy = Ivy.newInstance();
    ivy.configure(new File("test/repositories/ivysettings-dummydefaultresolver.xml"));

    ivy.install(ModuleRevisionId.newInstance("org1", "mod1.4", "1.0.1"), "test", "install",
        new InstallOptions());

    assertTrue(new File("build/test/install/org1/mod1.4/ivy-1.0.1.xml").exists());

    assertTrue(new File("build/test/install/org1/mod1.1/ivy-2.0.xml").exists());
    assertTrue(new File("build/test/install/org1/mod1.1/mod1.1-2.0.jar").exists());

    assertTrue(new File("build/test/install/org1/mod1.2/ivy-2.2.xml").exists());
    assertTrue(new File("build/test/install/org1/mod1.2/mod1.2-2.2.jar").exists());
}
 
Example 4
Source File: InstallTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testRegexpMatcher() throws Exception {
    Ivy ivy = Ivy.newInstance();
    ivy.configure(new File("test/repositories/ivysettings.xml"));

    ivy.install(ModuleRevisionId.newInstance("org1", ".*", ".*"), "1", "install",
        new InstallOptions().setMatcherName(PatternMatcher.REGEXP).setOverwrite(true));

    assertTrue(new File("build/test/install/org1/mod1.1/ivy-1.0.xml").exists());
    assertTrue(new File("build/test/install/org1/mod1.1/mod1.1-1.0.jar").exists());

    assertTrue(new File("build/test/install/org1/mod1.1/ivy-1.1.xml").exists());
    assertTrue(new File("build/test/install/org1/mod1.1/mod1.1-1.1.jar").exists());

    assertTrue(new File("build/test/install/org1/mod1.2/ivy-2.0.xml").exists());
    assertTrue(new File("build/test/install/org1/mod1.2/mod1.2-2.0.jar").exists());

    // mod1.3 is split because Ivy thinks there are two versions of the module:
    // this is the normal behaviour in this case
    assertTrue(new File("build/test/install/org1/mod1.3/ivy-B-3.0.xml").exists());
    assertTrue(new File("build/test/install/org1/mod1.3/ivy-A-3.0.xml").exists());
    assertTrue(new File("build/test/install/org1/mod1.3/mod1.3-A-3.0.jar").exists());
    assertTrue(new File("build/test/install/org1/mod1.3/mod1.3-B-3.0.jar").exists());

    assertTrue(new File("build/test/install/org1/mod1.4/ivy-1.0.1.xml").exists());
}
 
Example 5
Source File: InstallTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimple() throws Exception {
    Ivy ivy = Ivy.newInstance();
    ivy.configure(new File("test/repositories/ivysettings.xml"));

    ivy.install(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"), ivy.getSettings()
            .getDefaultResolver().getName(), "install", new InstallOptions());

    assertTrue(new File("build/test/install/org1/mod1.2/ivy-2.0.xml").exists());
    assertTrue(new File("build/test/install/org1/mod1.2/mod1.2-2.0.jar").exists());
}
 
Example 6
Source File: InstallTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidate() throws Exception {
    Ivy ivy = Ivy.newInstance();
    ivy.configure(new File("test/repositories/ivysettings.xml"));

    ivy.install(ModuleRevisionId.newInstance("orgfailure", "modfailure", "1.0"), ivy
            .getSettings().getDefaultResolver().getName(), "install", new InstallOptions());

    assertFalse(new File("build/test/install/orgfailure/modfailure/ivy-1.0.xml").exists());
    assertFalse(new File("build/test/install/orgfailure/modfailure/modfailure-1.0.jar")
            .exists());
}
 
Example 7
Source File: InstallTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoValidate() throws Exception {
    Ivy ivy = Ivy.newInstance();
    ivy.configure(new File("test/repositories/ivysettings.xml"));

    ivy.install(ModuleRevisionId.newInstance("orgfailure", "modfailure", "1.0"), ivy
            .getSettings().getDefaultResolver().getName(), "install",
        new InstallOptions().setValidate(false));

    assertTrue(new File("build/test/install/orgfailure/modfailure/ivy-1.0.xml").exists());
    assertTrue(new File("build/test/install/orgfailure/modfailure/modfailure-1.0.jar").exists());
}
 
Example 8
Source File: InstallTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimpleWithoutDefaultResolver() throws Exception {
    Ivy ivy = Ivy.newInstance();
    ivy.configure(new File("test/repositories/ivysettings-nodefaultresolver.xml"));

    ivy.install(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"), "test", "install",
        new InstallOptions());

    assertTrue(new File("build/test/install/org1/mod1.2/ivy-2.0.xml").exists());
    assertTrue(new File("build/test/install/org1/mod1.2/mod1.2-2.0.jar").exists());
}
 
Example 9
Source File: InstallTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testDependencies() throws Exception {
    Ivy ivy = Ivy.newInstance();
    ivy.configure(new File("test/repositories/ivysettings.xml"));

    ivy.install(ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"), ivy.getSettings()
            .getDefaultResolver().getName(), "install", new InstallOptions());

    assertTrue(new File("build/test/install/org1/mod1.1/ivy-1.0.xml").exists());
    assertTrue(new File("build/test/install/org1/mod1.1/mod1.1-1.0.jar").exists());

    assertTrue(new File("build/test/install/org1/mod1.2/ivy-2.0.xml").exists());
    assertTrue(new File("build/test/install/org1/mod1.2/mod1.2-2.0.jar").exists());
}
 
Example 10
Source File: InstallTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testNotTransitive() throws Exception {
    Ivy ivy = Ivy.newInstance();
    ivy.configure(new File("test/repositories/ivysettings.xml"));

    ivy.install(ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"), ivy.getSettings()
            .getDefaultResolver().getName(), "install",
        new InstallOptions().setTransitive(false));

    assertTrue(new File("build/test/install/org1/mod1.1/ivy-1.0.xml").exists());
    assertTrue(new File("build/test/install/org1/mod1.1/mod1.1-1.0.jar").exists());

    assertFalse(new File("build/test/install/org1/mod1.2/ivy-2.0.xml").exists());
    assertFalse(new File("build/test/install/org1/mod1.2/mod1.2-2.0.jar").exists());
}
 
Example 11
Source File: IvyInstall.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
public void doExecute() throws BuildException {
    Ivy ivy = getIvyInstance();
    IvySettings settings = ivy.getSettings();
    if (organisation == null) {
        throw new BuildException("no organisation provided for ivy publish task: "
                + "It can either be set explicitly via the attribute 'organisation' "
                + "or via 'ivy.organisation' property or a prior call to <resolve/>");
    }
    if (module == null) {
        if (PatternMatcher.EXACT.equals(matcher)) {
            throw new BuildException("no module name provided for ivy publish task: "
                    + "It can either be set explicitly via the attribute 'module' "
                    + "or via 'ivy.module' property or a prior call to <resolve/>");
        }
        module = PatternMatcher.ANY_EXPRESSION;
    }
    if (revision == null) {
        if (PatternMatcher.EXACT.equals(matcher)) {
            throw new BuildException("no module revision provided for ivy publish task: "
                    + "It can either be set explicitly via the attribute 'revision' "
                    + "or via 'ivy.revision' property or a prior call to <resolve/>");
        }
        revision = PatternMatcher.ANY_EXPRESSION;
    }
    if (branch == null) {
        if (PatternMatcher.EXACT.equals(matcher)) {
            branch = settings.getDefaultBranch(ModuleId.newInstance(organisation, module));
        } else {
            branch = PatternMatcher.ANY_EXPRESSION;
        }
    }
    if (from == null) {
        throw new BuildException(
                "no from resolver name: please provide it through parameter 'from'");
    }
    if (to == null) {
        throw new BuildException(
                "no to resolver name: please provide it through parameter 'to'");
    }
    ModuleRevisionId mrid = ModuleRevisionId
            .newInstance(organisation, module, branch, revision);

    ResolveReport report;
    try {
        report = ivy.install(
            mrid,
            from,
            to,
            new InstallOptions().setTransitive(transitive).setValidate(doValidate(settings))
                    .setOverwrite(overwrite).setConfs(conf.split(","))
                    .setArtifactFilter(FilterHelper.getArtifactTypeFilter(type))
                    .setMatcherName(matcher)
                    .setInstallOriginalMetadata(installOriginalMetadata));
    } catch (Exception e) {
        throw new BuildException("impossible to install " + mrid + ": " + e, e);
    }

    if (report.hasError() && isHaltonfailure()) {
        throw new BuildException(
                "Problem happened while installing modules - see output for details");
    }
}