Search in sources :

Example 51 with Path

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

the class Depend method getCheckClassPath.

/**
 * Get the classpath for dependency checking.
 *
 * This method removes the dest dirs if it is given from the dependency classpath
 */
private Path getCheckClassPath() {
    if (dependClasspath == null) {
        return null;
    }
    Set<Resource> dependNotInDest = new LinkedHashSet<>();
    dependClasspath.forEach(dependNotInDest::add);
    destPath.forEach(dependNotInDest::remove);
    Path p;
    if (dependNotInDest.isEmpty()) {
        p = null;
    } else {
        p = new Path(getProject());
        dependNotInDest.forEach(p::add);
    }
    log("Classpath without dest dir is " + p, Project.MSG_DEBUG);
    return p;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Path(org.apache.tools.ant.types.Path) HashMap(java.util.HashMap) Map(java.util.Map) Resource(org.apache.tools.ant.types.Resource)

Example 52 with Path

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

the class Find method execute.

public void execute() {
    validate();
    // find all files
    for (Path path : paths) {
        for (String includedFile : path.list()) {
            String filename = includedFile.replace('\\', '/');
            filename = filename.substring(filename.lastIndexOf("/") + 1);
            if (file.equals(filename) && !foundFiles.contains(includedFile)) {
                foundFiles.add(includedFile);
            }
        }
    }
    // create the return value (list/single)
    String rv = null;
    if (!foundFiles.isEmpty()) {
        if (delimiter == null) {
            // only the first
            rv = foundFiles.get(0);
        } else {
            // create list
            StringBuilder list = new StringBuilder();
            for (String file : foundFiles) {
                if (list.length() > 0)
                    list.append(delimiter);
                list.append(file);
            }
            rv = list.toString();
        }
    }
    // create the property
    if (rv != null)
        getProject().setNewProperty(location, rv);
}
Also used : Path(org.apache.tools.ant.types.Path)

Example 53 with Path

use of org.apache.tools.ant.types.Path in project narayana by jbosstm.

the class ClasspathBuilder method createClasspath.

public Path createClasspath() {
    Path c = new Path(project);
    _paths.add(c);
    return (c);
}
Also used : Path(org.apache.tools.ant.types.Path)

Example 54 with Path

use of org.apache.tools.ant.types.Path in project narayana by jbosstm.

the class ClasspathBuilder method execute.

public void execute() throws BuildException {
    if (_filename == null) {
        throw new BuildException("No filename specified to store built classpath!");
    }
    if (_paths.size() > 0) {
        try {
            for (int filenameCount = 0; filenameCount < _filename.length; filenameCount++) {
                BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(_filename[filenameCount], !_clear)));
                for (int count = 0; count < _paths.size(); count++) {
                    Object obj = _paths.get(count);
                    if (obj instanceof Path) {
                        Path path = (Path) obj;
                        String[] paths = path.list();
                        for (int pathCount = 0; pathCount < paths.length; pathCount++) {
                            out.write(paths[pathCount] + "\n");
                        }
                    }
                }
                out.close();
            }
        } catch (java.io.IOException e) {
            throw new BuildException("Failed to update file (reason: " + e + ")");
        }
    } else if (_clear) {
        /**
         * If a request to clear the file has been made but no entries have been
         * given then we need to delete the classpath builder file.
         */
        for (int filenameCount = 0; filenameCount < _filename.length; filenameCount++) {
            new File(_filename[filenameCount]).delete();
        }
    }
    if (_property != null) {
        putClasspathInProperty(_filename, _property);
    }
}
Also used : Path(org.apache.tools.ant.types.Path) java.io(java.io) BuildException(org.apache.tools.ant.BuildException)

Example 55 with Path

use of org.apache.tools.ant.types.Path in project ci.ant by WASdev.

the class CompileJSPs method createAppXML.

private void createAppXML(File serverDir) throws FileNotFoundException {
    if (srcdir != null) {
        // TODO write the loose application xml.
        File appsDir = new File(serverDir, "apps");
        appsDir.mkdirs();
        PrintStream ps = new PrintStream(new File(appsDir, "fake.war.xml"));
        ps.println("<archive>");
        ps.println("  <dir targetInArchive=\"/\" sourceOnDisk=\"" + srcdir.getAbsolutePath() + "\"/>");
        Path p = new Path(getProject(), classpath);
        if (classpathRef != null) {
            Path path = (Path) getProject().getReference(classpathRef);
            p.add(path);
        }
        String[] cp = p.toString().split(File.pathSeparator);
        for (String entry : cp) {
            File f = new File(entry);
            String basename = f.getName();
            if (f.isFile() && f.exists() && f.getName().endsWith(".jar")) {
                ps.println("  <file targetInArchive=\"/WEB-INF/lib/" + basename + "\" sourceOnDisk=\"" + f.getAbsolutePath() + "\"/>");
            } else if (f.isDirectory() && f.exists()) {
                // TODO: What if basename is NOT "classes"?
                ps.println("  <dir targetInArchive=\"/WEB-INF/classes\" sourceOnDisk=\"" + f.getAbsolutePath() + "\"/>");
            }
        }
        ps.println("</archive>");
        ps.close();
    }
}
Also used : Path(org.apache.tools.ant.types.Path) PrintStream(java.io.PrintStream) File(java.io.File)

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