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

The following examples show how to use org.apache.ivy.Ivy#configure() . 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: LatestConflictManagerTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * Test case for IVY-407.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-407">IVY-407</a>
 */
@Test
public void testLatestTime1() throws Exception {
    ivy = new Ivy();
    ivy.configure(LatestConflictManagerTest.class.getResource("ivysettings-latest-time.xml"));
    ivy.getSettings().setVariable("ivy.log.conflict.resolution", "true", true);

    // set timestamps, because svn is not preserving this information,
    // and the latest time strategy is relying on it
    long time = System.currentTimeMillis() - 10000;
    new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar").setLastModified(time);
    new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.2.jar")
            .setLastModified(time + 2000);

    ResolveReport report = ivy.resolve(
        LatestConflictManagerTest.class.getResource("ivy-latest-time-1.xml"),
        getResolveOptions());
    ConfigurationResolveReport defaultReport = report.getConfigurationReport("default");
    for (ModuleRevisionId mrid : defaultReport.getModuleRevisionIds()) {
        if (mrid.getName().equals("mod1.1")) {
            assertEquals("1.0", mrid.getRevision());
        } else if (mrid.getName().equals("mod1.2")) {
            assertEquals("2.2", mrid.getRevision());
        }
    }
}
 
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: LatestConflictManagerTest.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
@Test
public void testLatestTime2() throws Exception {
    ivy = new Ivy();
    ivy.configure(LatestConflictManagerTest.class.getResource("ivysettings-latest-time.xml"));
    ivy.getSettings().setVariable("ivy.log.conflict.resolution", "true", true);

    // set timestamps, because svn is not preserving this information,
    // and the latest time strategy is relying on it
    long time = System.currentTimeMillis() - 10000;
    new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar").setLastModified(time);
    new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.2.jar")
            .setLastModified(time + 2000);

    ResolveReport report = ivy.resolve(
        LatestConflictManagerTest.class.getResource("ivy-latest-time-2.xml"),
        getResolveOptions());
    ConfigurationResolveReport defaultReport = report.getConfigurationReport("default");
    for (ModuleRevisionId mrid : defaultReport.getModuleRevisionIds()) {
        if (mrid.getName().equals("mod1.1")) {
            assertEquals("1.0", mrid.getRevision());
        } else if (mrid.getName().equals("mod1.2")) {
            assertEquals("2.2", mrid.getRevision());
        }
    }
}
 
Example 4
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 5
Source File: IvyConfigureTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that if the Ivy settings file <code>include</code>s another file as
 * <code>optional</code>, then the absence of that file doesn't lead to failures
 *
 * @throws Exception if something goes wrong
 */
@Test
public void testOptionalFileInclude() throws Exception {
    final File ivySettingsXml = new File("test/repositories/ivysettings-optional-file-include.xml");
    final Ivy ivy = new Ivy();
    ivy.configure(ivySettingsXml);
    final IvySettings ivySettings = ivy.getSettings();
    // just test that it indeed parsed fine
    assertTrue("Unexpected number of resolvers in Ivy settings", ivySettings.getResolvers().isEmpty());
    final List<Status> statuses = ivySettings.getStatusManager().getStatuses();
    assertEquals("Unexpected number of custom status in parsed Ivy settings", 1, statuses.size());
    assertEquals("Custom status not found in the parsed Ivy settings", "ivy-1555", statuses.get(0).getName());
}
 
Example 6
Source File: LatestConflictManagerTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
/**
 * Test case for IVY-407 (with transitivity). There are 5 modules A, B, C, D and E.
 * <ol>
 * <li>publish C-1.0.0, C-1.0.1 and C-1.0.2</li>
 * <li>B needs C-1.0.0 : retrieve ok and publish B-1.0.0</li>
 * <li>A needs B-1.0.0 and C-1.0.2 : retrieve ok and publish A-1.0.0</li>
 * <li>D needs C-1.0.1 : retrieve ok and publish D-1.0.0</li>
 * <li>E needs D-1.0.0 and A-1.0.0 (D before A in ivy file) :
 * retrieve failed to get C-1.0.2 from A (get apparently C-1.0.1 from D)</li>
 * </ol>
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-407">IVY-407</a>
 */
@Test
public void testLatestTimeTransitivity() throws Exception {
    ivy = new Ivy();
    ivy.configure(LatestConflictManagerTest.class
            .getResource("ivysettings-latest-time-transitivity.xml"));
    ivy.getSettings().setVariable("ivy.log.conflict.resolution", "true", true);

    // set timestamps, because svn is not preserving this information,
    // and the latest time strategy is relying on it
    long time = System.currentTimeMillis() - 10000;
    new File("test/repositories/IVY-407/MyCompany/C/ivy-1.0.0.xml").setLastModified(time);
    new File("test/repositories/IVY-407/MyCompany/C/ivy-1.0.1.xml")
            .setLastModified(time + 2000);
    new File("test/repositories/IVY-407/MyCompany/C/ivy-1.0.2.xml")
            .setLastModified(time + 4000);

    ResolveReport report = ivy.resolve(
        LatestConflictManagerTest.class.getResource("ivy-latest-time-transitivity.xml"),
        getResolveOptions());
    ConfigurationResolveReport defaultReport = report.getConfigurationReport("default");
    for (ModuleRevisionId mrid : defaultReport.getModuleRevisionIds()) {
        switch (mrid.getName()) {
            case "A":
                assertEquals("A revision should be 1.0.0", "1.0.0", mrid.getRevision());
                break;
            case "B":
                // by transitivity
                assertEquals("B revision should be 1.0.0", "1.0.0", mrid.getRevision());
                break;
            case "C":
                assertEquals("C revision should be 1.0.2", "1.0.2", mrid.getRevision());
                break;
            case "D":
                assertEquals("D revision should be 1.0.0", "1.0.0", mrid.getRevision());
                break;
        }
    }
}
 
Example 7
Source File: DependenciesManager.java    From restcommander with Apache License 2.0 5 votes vote down vote up
public Ivy configure() throws Exception {

        boolean verbose = System.getProperty("verbose") != null;
        boolean debug = System.getProperty("debug") != null;
        HumanReadyLogger humanReadyLogger = new HumanReadyLogger();

        IvySettings ivySettings = new IvySettings();
        new SettingsParser(humanReadyLogger).parse(ivySettings, new File(framework, "framework/dependencies.yml"));
        new SettingsParser(humanReadyLogger).parse(ivySettings, new File(application, "conf/dependencies.yml"));
        ivySettings.setDefaultResolver("mavenCentral");
        ivySettings.setDefaultUseOrigin(true);
        PlayConflictManager conflictManager = new PlayConflictManager();
        ivySettings.addConflictManager("playConflicts", conflictManager);
        ivySettings.addConflictManager("defaultConflicts", conflictManager.deleguate);
        ivySettings.setDefaultConflictManager(conflictManager);

        Ivy ivy = Ivy.newInstance(ivySettings);

        // Default ivy config see: http://play.lighthouseapp.com/projects/57987-play-framework/tickets/807
        File ivyDefaultSettings = new File(userHome, ".ivy2/ivysettings.xml");
        if(ivyDefaultSettings.exists()) {
            ivy.configure(ivyDefaultSettings);
        }

        if (debug) {
            ivy.getLoggerEngine().pushLogger(new DefaultMessageLogger(Message.MSG_DEBUG));
        } else if (verbose) {
            ivy.getLoggerEngine().pushLogger(new DefaultMessageLogger(Message.MSG_INFO));
        } else {
            logger = humanReadyLogger;
            ivy.getLoggerEngine().setDefaultLogger(logger);
        }

        ivy.pushContext();

        return ivy;
    }
 
Example 8
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 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 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 11
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 12
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 13
Source File: ConfigureTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testTypedefWithCustomClasspathWithFile() throws Exception {
    Ivy ivy = new Ivy();
    ivy.setVariable("ivy.custom.test.dir",
        new File("test/java/org/apache/ivy/core/settings").getAbsolutePath());
    ivy.configure(ConfigureTest.class.getResource("ivysettings-custom-typedef2.xml"));

    DependencyResolver custom = ivy.getSettings().getResolver("custom");
    assertNotNull(custom);
    assertEquals("org.apache.ivy.plugins.resolver.CustomResolver", custom.getClass().getName());
}
 
Example 14
Source File: ConfigureTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testTypedefWithCustomClasspath() throws Exception {
    Ivy ivy = new Ivy();
    ivy.setVariable("ivy.custom.test.dir", new File("test/java/org/apache/ivy/core/settings")
            .toURI().toURL().toString());
    ivy.configure(ConfigureTest.class.getResource("ivysettings-custom-typedef.xml"));

    DependencyResolver custom = ivy.getSettings().getResolver("custom");
    assertNotNull(custom);
    assertEquals("org.apache.ivy.plugins.resolver.CustomResolver", custom.getClass().getName());
}
 
Example 15
Source File: SearchTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testListModulesWithExtraAttributes() throws ParseException, IOException {
    Ivy ivy = Ivy.newInstance();
    ivy.configure(new File("test/repositories/IVY-1128/ivysettings.xml"));
    IvySettings settings = ivy.getSettings();

    Map<String, String> extendedAttributes = new HashMap<>();
    extendedAttributes.put("e:att1", "extraatt");
    extendedAttributes.put("e:att2", "extraatt2");
    ModuleRevisionId criteria = ModuleRevisionId.newInstance("test", "a", "*",
        extendedAttributes);

    ModuleRevisionId[] mrids = ivy.listModules(criteria,
        settings.getMatcher(PatternMatcher.REGEXP));

    assertEquals(2, mrids.length);
    ModuleRevisionId mrid = mrids[0];
    assertEquals("extraatt", mrid.getExtraAttribute("att1"));

    Map<String, String> extraAttributes = mrid.getExtraAttributes();
    assertEquals(2, extraAttributes.size());
    assertTrue(extraAttributes.toString(), extraAttributes.keySet().contains("att1"));
    assertTrue(extraAttributes.toString(), extraAttributes.keySet().contains("att2"));

    Map<String, String> qualifiedExtraAttributes = mrid.getQualifiedExtraAttributes();
    assertEquals(2, qualifiedExtraAttributes.size());
    assertTrue(qualifiedExtraAttributes.toString(),
        qualifiedExtraAttributes.keySet().contains("e:att1"));
    assertTrue(qualifiedExtraAttributes.toString(),
        qualifiedExtraAttributes.keySet().contains("e:att2"));
}
 
Example 16
Source File: SearchTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Test
public void testListInMavenRepo2() throws Exception {
    Ivy ivy = Ivy.newInstance();
    ivy.configure(new File("test/repositories/m2/ivysettings.xml").toURI().toURL());
    ((IBiblioResolver) ivy.getSettings().getResolver("m2")).setUseMavenMetadata(false);

    Map<String, Object> otherTokenValues = new HashMap<>();
    otherTokenValues.put(IvyPatternHelper.ORGANISATION_KEY, "org.apache");
    otherTokenValues.put(IvyPatternHelper.MODULE_KEY, "test-metadata");
    String[] revs = ivy.listTokenValues(IvyPatternHelper.REVISION_KEY, otherTokenValues);

    assertEquals(new HashSet<>(Arrays.asList("1.0", "1.1", "1.2")),
            new HashSet<>(Arrays.asList(revs)));
}
 
Example 17
Source File: LatestConflictManagerTest.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    ivy = new Ivy();
    ivy.configure(LatestConflictManagerTest.class.getResource("ivysettings-latest.xml"));
    cache = new File("build/cache");
    cache.mkdirs();
}
 
Example 18
Source File: XmlReportWriterTest.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
    ivy = new Ivy();
    ivy.configure(new File("test/repositories/ivysettings.xml"));
    createCache();
}
 
Example 19
Source File: IvyAntSettings.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
void createIvyEngine(final ProjectComponent task) {
    Project project = task.getProject();
    Property prop = new Property() {
        public void execute() throws BuildException {
            addProperties(getDefaultProperties(task));
        }
    };
    prop.setProject(project);
    prop.init();
    prop.execute();

    IvyAntVariableContainer ivyAntVariableContainer = new IvyAntVariableContainer(project);
    IvySettings settings = new IvySettings(ivyAntVariableContainer);
    settings.setBaseDir(project.getBaseDir());

    if (file == null && url == null) {
        defineDefaultSettingFile(ivyAntVariableContainer, task);
    }

    if (antWorkspaceResolver != null) {
        settings.addConfigured(antWorkspaceResolver.getResolver());
    }

    Ivy ivy = Ivy.newInstance(settings);
    try {
        ivy.pushContext();
        AntMessageLogger.register(task, ivy);

        Message.showInfo();
        configureURLHandler();
        if (file != null) {
            if (!file.exists()) {
                throw new BuildException("settings file does not exist: " + file);
            }
            ivy.configure(file);
        } else {
            if (url == null) {
                throw new AssertionError(
                        "ivy setting should have either a file, either an url,"
                                + " and if not defineDefaultSettingFile must set it.");
            }
            ivy.configure(url);
        }
        ivyAntVariableContainer.updateProject(id);
        ivyEngine = ivy;
    } catch (ParseException | IOException e) {
        throw new BuildException("impossible to configure ivy:settings with given "
                + (file != null ? "file: " + file : "url: " + url) + " : " + e, e);
    } finally {
        ivy.popContext();
    }
}
 
Example 20
Source File: XmlReportParserTest.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
    ivy = new Ivy();
    ivy.configure(new File("test/repositories/ivysettings.xml"));
    TestHelper.createCache();
}