Search in sources :

Example 61 with Path

use of org.apache.tools.ant.types.Path in project ant-ivy by apache.

the class IvyCachePathTest method testWithResolveId.

@Test
public void testWithResolveId() {
    IvyResolve resolve = new IvyResolve();
    resolve.setProject(project);
    resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-simple.xml"));
    resolve.setResolveId("withResolveId");
    resolve.execute();
    // resolve another ivy file
    resolve = new IvyResolve();
    resolve.setProject(project);
    resolve.setFile(new File("test/java/org/apache/ivy/ant/ivy-latest.xml"));
    resolve.execute();
    path.setResolveId("withResolveId");
    path.setPathid("withresolveid-pathid");
    path.execute();
    Object ref = project.getReference("withresolveid-pathid");
    assertNotNull(ref);
    assertTrue(ref instanceof Path);
    Path p = (Path) ref;
    assertEquals(1, p.size());
    assertEquals(getArchiveFileInCache("org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").getAbsolutePath(), new File(p.list()[0]).getAbsolutePath());
}
Also used : Path(org.apache.tools.ant.types.Path) File(java.io.File) Test(org.junit.Test)

Example 62 with Path

use of org.apache.tools.ant.types.Path in project ant-ivy by apache.

the class AddPathTask method setProject.

public void setProject(Project project) {
    super.setProject(project);
    toAdd = new Path(project);
}
Also used : Path(org.apache.tools.ant.types.Path)

Example 63 with Path

use of org.apache.tools.ant.types.Path in project ant-ivy by apache.

the class AddPathTask method execute.

public void execute() throws BuildException {
    Object element = getProject().getReference(toPath);
    if (element == null) {
        throw new BuildException("destination path not found: " + toPath);
    }
    if (!(element instanceof Path)) {
        throw new BuildException("destination path is not a path: " + element.getClass());
    }
    Path dest = (Path) element;
    if (first) {
        // now way to add path elements at te beginning of the existing path: we do the opposite
        // and replace the reference
        toAdd.append(dest);
        getProject().addReference(toPath, toAdd);
    } else {
        dest.append(toAdd);
    }
}
Also used : Path(org.apache.tools.ant.types.Path) BuildException(org.apache.tools.ant.BuildException)

Example 64 with Path

use of org.apache.tools.ant.types.Path 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 65 with Path

use of org.apache.tools.ant.types.Path in project ant-ivy by apache.

the class IvyCachePath method doExecute.

public void doExecute() throws BuildException {
    prepareAndCheck();
    if (pathid == null) {
        if (id == null) {
            throw new BuildException("pathid is required in ivy classpath");
        }
        pathid = id;
        log("ID IS DEPRECATED, PLEASE USE PATHID INSTEAD", Project.MSG_WARN);
    }
    try {
        Path path = new Path(getProject());
        getProject().addReference(pathid, path);
        for (ArtifactDownloadReport adr : getArtifactReports()) {
            File f = adr.getLocalFile();
            if (adr.getUnpackedLocalFile() != null) {
                f = adr.getUnpackedLocalFile();
            }
            addToPath(path, f);
        }
    } catch (Exception ex) {
        throw new BuildException("impossible to build ivy path: " + ex, ex);
    }
}
Also used : Path(org.apache.tools.ant.types.Path) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) BuildException(org.apache.tools.ant.BuildException)

Aggregations

Path (org.apache.tools.ant.types.Path)175 File (java.io.File)81 BuildException (org.apache.tools.ant.BuildException)57 Test (org.junit.Test)49 Project (org.apache.tools.ant.Project)28 IOException (java.io.IOException)27 Commandline (org.apache.tools.ant.types.Commandline)21 ArrayList (java.util.ArrayList)15 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)12 AntClassLoader (org.apache.tools.ant.AntClassLoader)9 GroovyClassLoader (groovy.lang.GroovyClassLoader)8 URL (java.net.URL)8 StringTokenizer (java.util.StringTokenizer)8 Reference (org.apache.tools.ant.types.Reference)8 Java (org.apache.tools.ant.taskdefs.Java)7 FileSet (org.apache.tools.ant.types.FileSet)7 Resource (org.apache.tools.ant.types.Resource)7 FileWriter (java.io.FileWriter)6 List (java.util.List)6 Execute (org.apache.tools.ant.taskdefs.Execute)6