Search in sources :

Example 11 with Ivy

use of org.apache.ivy.Ivy in project ant-ivy by apache.

the class IvyAntSettings method createIvyEngine.

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();
    }
}
Also used : Project(org.apache.tools.ant.Project) IvySettings(org.apache.ivy.core.settings.IvySettings) BuildException(org.apache.tools.ant.BuildException) ParseException(java.text.ParseException) IOException(java.io.IOException) Property(org.apache.tools.ant.taskdefs.Property) Ivy(org.apache.ivy.Ivy)

Example 12 with Ivy

use of org.apache.ivy.Ivy in project ant-ivy by apache.

the class IvyBuildList method doExecute.

@Override
public void doExecute() throws BuildException {
    if (reference == null) {
        throw new BuildException("reference should be provided in ivy build list");
    }
    if (buildFileSets.isEmpty()) {
        throw new BuildException("at least one nested fileset should be provided in ivy build list");
    }
    Ivy ivy = getIvyInstance();
    IvySettings settings = ivy.getSettings();
    ivyFilePath = getProperty(ivyFilePath, settings, "ivy.buildlist.ivyfilepath");
    Path path = new Path(getProject());
    Map<ModuleDescriptor, File> buildFiles = new HashMap<>();
    List<File> independent = new ArrayList<>();
    List<File> noDescriptor = new ArrayList<>();
    Collection<ModuleDescriptor> mds = new ArrayList<>();
    Set<String> rootModuleNames = new LinkedHashSet<>();
    if (!"*".equals(root)) {
        StringTokenizer st = new StringTokenizer(root, delimiter);
        while (st.hasMoreTokens()) {
            rootModuleNames.add(st.nextToken());
        }
    }
    Set<String> leafModuleNames = new LinkedHashSet<>();
    if (!"*".equals(leaf)) {
        StringTokenizer st = new StringTokenizer(leaf, delimiter);
        while (st.hasMoreTokens()) {
            leafModuleNames.add(st.nextToken());
        }
    }
    Set<String> restartFromModuleNames = new LinkedHashSet<>();
    if (!"*".equals(restartFrom)) {
        StringTokenizer st = new StringTokenizer(restartFrom, delimiter);
        // Only accept one (first) module
        restartFromModuleNames.add(st.nextToken());
    }
    for (FileSet fs : buildFileSets) {
        DirectoryScanner ds = fs.getDirectoryScanner(getProject());
        for (String build : ds.getIncludedFiles()) {
            File buildFile = new File(ds.getBasedir(), build);
            File ivyFile = getIvyFileFor(buildFile);
            if (!ivyFile.exists()) {
                onMissingDescriptor(buildFile, ivyFile, noDescriptor);
            } else {
                try {
                    ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance().parseDescriptor(settings, ivyFile.toURI().toURL(), doValidate(settings));
                    buildFiles.put(md, buildFile);
                    mds.add(md);
                    Message.debug("Add " + md.getModuleRevisionId().getModuleId());
                } catch (Exception ex) {
                    if (haltOnError) {
                        throw new BuildException("impossible to parse ivy file for " + buildFile + ": ivyfile=" + ivyFile + " exception=" + ex, ex);
                    } else {
                        Message.warn("impossible to parse ivy file for " + buildFile + ": ivyfile=" + ivyFile + " exception=" + ex.getMessage());
                        Message.info("\t=> adding it at the beginning of the path");
                        independent.add(buildFile);
                    }
                }
            }
        }
    }
    List<ModuleDescriptor> leafModuleDescriptors = convertModuleNamesToModuleDescriptors(mds, leafModuleNames, "leaf");
    List<ModuleDescriptor> rootModuleDescriptors = convertModuleNamesToModuleDescriptors(mds, rootModuleNames, "root");
    List<ModuleDescriptor> restartFromModuleDescriptors = convertModuleNamesToModuleDescriptors(mds, restartFromModuleNames, "restartFrom");
    if (!rootModuleDescriptors.isEmpty()) {
        Message.info("Filtering modules based on roots " + rootModuleNames);
        mds = filterModulesFromRoot(mds, rootModuleDescriptors);
    }
    if (!leafModuleDescriptors.isEmpty()) {
        Message.info("Filtering modules based on leafs " + leafModuleNames);
        mds = filterModulesFromLeaf(mds, leafModuleDescriptors);
    }
    List<ModuleDescriptor> sortedModules = ivy.sortModuleDescriptors(mds, SortOptions.DEFAULT);
    if (!OnMissingDescriptor.TAIL.equals(onMissingDescriptor)) {
        for (File buildFile : noDescriptor) {
            addBuildFile(path, buildFile);
        }
    }
    for (File buildFile : independent) {
        addBuildFile(path, buildFile);
    }
    if (isReverse()) {
        Collections.reverse(sortedModules);
    }
    // so they are not removed from build path.
    if (!restartFromModuleDescriptors.isEmpty()) {
        boolean foundRestartFrom = false;
        List<ModuleDescriptor> keptModules = new ArrayList<>();
        ModuleDescriptor restartFromModuleDescriptor = restartFromModuleDescriptors.get(0);
        for (ModuleDescriptor md : sortedModules) {
            if (md.equals(restartFromModuleDescriptor)) {
                foundRestartFrom = true;
            }
            if (foundRestartFrom) {
                keptModules.add(md);
            }
        }
        sortedModules = keptModules;
    }
    StringBuilder order = new StringBuilder();
    for (ModuleDescriptor md : sortedModules) {
        if (order.length() > 0) {
            order.append(", ");
        }
        order.append(md.getModuleRevisionId().getModuleId());
        addBuildFile(path, buildFiles.get(md));
    }
    if (OnMissingDescriptor.TAIL.equals(onMissingDescriptor)) {
        for (File buildFile : noDescriptor) {
            addBuildFile(path, buildFile);
        }
    }
    getProject().addReference(getReference(), path);
    getProject().setProperty("ivy.sorted.modules", order.toString());
}
Also used : Path(org.apache.tools.ant.types.Path) LinkedHashSet(java.util.LinkedHashSet) FileSet(org.apache.tools.ant.types.FileSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IvySettings(org.apache.ivy.core.settings.IvySettings) Ivy(org.apache.ivy.Ivy) BuildException(org.apache.tools.ant.BuildException) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) StringTokenizer(java.util.StringTokenizer) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) BuildException(org.apache.tools.ant.BuildException) File(java.io.File)

Example 13 with Ivy

use of org.apache.ivy.Ivy in project ant-ivy by apache.

the class IBiblioMavenSnapshotsResolutionTest method before.

@Before
public void before() throws Exception {
    TestHelper.createCache();
    this.ivy = new Ivy();
    this.ivy.configure(new File("test/repositories/ivysettings.xml"));
    // add the maven timestamped snapshot version matcher
    this.ivy.getSettings().addVersionMatcher(new MavenTimedSnapshotVersionMatcher());
}
Also used : MavenTimedSnapshotVersionMatcher(org.apache.ivy.plugins.version.MavenTimedSnapshotVersionMatcher) Ivy(org.apache.ivy.Ivy) File(java.io.File) Before(org.junit.Before)

Example 14 with Ivy

use of org.apache.ivy.Ivy in project ant-ivy by apache.

the class XmlModuleUpdaterTest method testVariableReplacement.

@Test
public void testVariableReplacement() throws Exception {
    /*
         * For updated file to be equals to updated.xml, we have to fix the line separator to the
         * one used in updated.xml, in order for this test to works in all platforms (default line
         * separator used in updater being platform dependent
         */
    XmlModuleDescriptorUpdater.LINE_SEPARATOR = "\n";
    File dest = new File("build/updated-test2.xml");
    dest.deleteOnExit();
    Map<ModuleRevisionId, String> resolvedRevisions = new HashMap<>();
    resolvedRevisions.put(ModuleRevisionId.newInstance("yourorg", "yourmodule2", "branch1", "2+"), "2.5");
    resolvedRevisions.put(ModuleRevisionId.newInstance("yourorg", "yourmodule6", "trunk", "latest.integration"), "6.3");
    Map<ModuleRevisionId, String> resolvedBranches = new HashMap<>();
    resolvedBranches.put(ModuleRevisionId.newInstance("yourorg", "yourmodule3", "3.1"), "branch1");
    resolvedBranches.put(ModuleRevisionId.newInstance("yourorg", "yourmodule2", "branch1", "2+"), null);
    GregorianCalendar cal = new GregorianCalendar();
    cal.set(2005, 2, 22, 14, 32, 54);
    Ivy ivy = Ivy.newInstance();
    ivy.setVariable("myorg", "myorg");
    ivy.setVariable("mymodule", "mymodule");
    ivy.setVariable("myrev", "myrev");
    ivy.setVariable("mystatus", "integration");
    ivy.setVariable("mypubdate", "20050322143254");
    ivy.setVariable("mylicense", "MyLicense");
    ivy.setVariable("mylicenseurl", "http://www.my.org/mymodule/mylicense.html");
    ivy.setVariable("myorgurl", "http://www.myorg.org/");
    ivy.setVariable("ivyrep", "ivyrep");
    ivy.setVariable("ivyrepurl", "http://www.jayasoft.fr/org/ivyrep/");
    ivy.setVariable("ivyreppattern", "[organisation]/[module]/ivy-[revision].xml");
    ivy.setVariable("ivys", "true");
    ivy.setVariable("artifacts", "false");
    ivy.setVariable("homepage", "http://www.my.org/mymodule/");
    ivy.setVariable("includefile", "imported-configurations-with-mapping.xml");
    ivy.setVariable("mydesc", "desc 1");
    ivy.setVariable("visibility", "public");
    ivy.setVariable("myvar", "myconf1");
    ivy.setVariable("deprecated", "20050115");
    ivy.setVariable("myartifact1", "myartifact1");
    ivy.setVariable("mytype", "jar");
    ivy.setVariable("mymodule2", "mymodule2");
    ivy.setVariable("mymodule2rev", "2.0");
    ivy.setVariable("changing", "true");
    ivy.setVariable("transitive", "false");
    ivy.setVariable("targetconf", "yourconf1");
    ivy.setVariable("art9-1", "yourartifact9-1");
    ivy.setVariable("conf3", "myconf3");
    ivy.setVariable("includename", "your.*");
    ivy.setVariable("includeext", "xml");
    ivy.setVariable("excludename", "toexclude");
    ivy.setVariable("excludemodule", "*servlet*");
    ivy.setVariable("excludematcher", "glob");
    ivy.setVariable("excludeorg", "acme");
    ivy.setVariable("excludeartifact", "test");
    ivy.setVariable("excludetype", "source");
    ivy.setVariable("yourorg", "yourorg");
    ivy.setVariable("yourmodule", ".*");
    ivy.setVariable("all", "all");
    ivy.setVariable("regexp", "regexp");
    ivy.setVariable("theirrev", "1.0, 1.1");
    XmlModuleDescriptorUpdater.update(XmlModuleUpdaterTest.class.getResource("test-update-withvar.xml"), dest, getUpdateOptions(ivy.getSettings(), resolvedRevisions, "release", "mynewrev", cal.getTime()).setResolvedBranches(resolvedBranches));
    assertTrue(dest.exists());
    String expected = FileUtil.readEntirely(new BufferedReader(new InputStreamReader(XmlModuleUpdaterTest.class.getResourceAsStream("updated.xml"))));
    String updated = FileUtil.readEntirely(new BufferedReader(new FileReader(dest)));
    assertEquals(expected, updated);
}
Also used : InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) GregorianCalendar(java.util.GregorianCalendar) BufferedReader(java.io.BufferedReader) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) FileReader(java.io.FileReader) File(java.io.File) Ivy(org.apache.ivy.Ivy) Test(org.junit.Test)

Example 15 with Ivy

use of org.apache.ivy.Ivy in project ant-ivy by apache.

the class ResolveTest method testResolveMaven2Snapshot2.

/**
 * Test case for IVY-501.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-501">IVY-501</a>
 */
@Test
public void testResolveMaven2Snapshot2() throws Exception {
    // here we test maven SNAPSHOT versions handling,
    // without m2 snapshotRepository/uniqueVersion set to true
    Ivy ivy = new Ivy();
    ivy.configure(new File("test/repositories/m2/ivysettings.xml"));
    ResolveReport report = ivy.resolve(new File("test/repositories/m2/org/apache/test4/1.1/test4-1.1.pom"), getResolveOptions(new String[] { "*" }));
    assertNotNull(report);
    assertFalse(report.hasError());
    // dependencies
    assertTrue(getIvyFileInCache(ModuleRevisionId.newInstance("org.apache", "test-SNAPSHOT2", "2.0.2-SNAPSHOT")).exists());
    assertTrue(getArchiveFileInCache(ivy, "org.apache", "test-SNAPSHOT2", "2.0.2-SNAPSHOT", "test-SNAPSHOT2", "jar", "jar").exists());
}
Also used : ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) Ivy(org.apache.ivy.Ivy) JarFile(java.util.jar.JarFile) File(java.io.File) Test(org.junit.Test)

Aggregations

Ivy (org.apache.ivy.Ivy)169 File (java.io.File)147 Test (org.junit.Test)137 ResolveReport (org.apache.ivy.core.report.ResolveReport)102 JarFile (java.util.jar.JarFile)100 ConfigurationResolveReport (org.apache.ivy.core.report.ConfigurationResolveReport)97 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)40 IvySettings (org.apache.ivy.core.settings.IvySettings)26 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)23 BuildException (org.apache.tools.ant.BuildException)17 Before (org.junit.Before)12 HashMap (java.util.HashMap)9 DependencyResolver (org.apache.ivy.plugins.resolver.DependencyResolver)8 RepositoryCacheManager (org.apache.ivy.core.cache.RepositoryCacheManager)6 ResolveOptions (org.apache.ivy.core.resolve.ResolveOptions)6 DefaultRepositoryCacheManager (org.apache.ivy.core.cache.DefaultRepositoryCacheManager)5 ModuleId (org.apache.ivy.core.module.id.ModuleId)5 IOException (java.io.IOException)4 ParseException (java.text.ParseException)4 Date (java.util.Date)4