Search in sources :

Example 11 with DirectoryScanner

use of org.apache.tools.ant.DirectoryScanner in project groovy-core by groovy.

the class Groovyc method execute.

/**
     * Executes the task.
     *
     * @throws BuildException if an error occurs
     */
public void execute() throws BuildException {
    checkParameters();
    resetFileLists();
    loadRegisteredScriptExtensions();
    if (javac != null)
        jointCompilation = true;
    // scan source directories and dest directory to build up
    // compile lists
    String[] list = src.list();
    for (String filename : list) {
        File file = getProject().resolveFile(filename);
        if (!file.exists()) {
            throw new BuildException("srcdir \"" + file.getPath() + "\" does not exist!", getLocation());
        }
        DirectoryScanner ds = this.getDirectoryScanner(file);
        String[] files = ds.getIncludedFiles();
        scanDir(file, destDir != null ? destDir : file, files);
    }
    compile();
    if (updatedProperty != null && taskSuccess && compileList.length != 0) {
        getProject().setNewProperty(updatedProperty, "true");
    }
}
Also used : DirectoryScanner(org.apache.tools.ant.DirectoryScanner) BuildException(org.apache.tools.ant.BuildException) File(java.io.File)

Example 12 with DirectoryScanner

use of org.apache.tools.ant.DirectoryScanner in project groovy-core by groovy.

the class Groovydoc method parsePackages.

/**
     * Add the directories matched by the nested dirsets to the resulting
     * packages list and the base directories of the dirsets to the Path.
     * It also handles the packages and excludepackages attributes and
     * elements.
     *
     * @param resultantPackages a list to which we add the packages found
     * @param sourcePath a path to which we add each basedir found
     * @since 1.5
     */
private void parsePackages(List<String> resultantPackages, Path sourcePath) {
    List<String> addedPackages = new ArrayList<String>();
    List<DirSet> dirSets = new ArrayList<DirSet>(packageSets);
    // and nested excludepackage elements
    if (this.sourcePath != null) {
        PatternSet ps = new PatternSet();
        if (packageNames.size() > 0) {
            for (String pn : packageNames) {
                String pkg = pn.replace('.', '/');
                if (pkg.endsWith("*")) {
                    pkg += "*";
                }
                ps.createInclude().setName(pkg);
            }
        } else {
            ps.createInclude().setName("**");
        }
        for (String epn : excludePackageNames) {
            String pkg = epn.replace('.', '/');
            if (pkg.endsWith("*")) {
                pkg += "*";
            }
            ps.createExclude().setName(pkg);
        }
        String[] pathElements = this.sourcePath.list();
        for (String pathElement : pathElements) {
            File dir = new File(pathElement);
            if (dir.isDirectory()) {
                DirSet ds = new DirSet();
                ds.setDefaultexcludes(useDefaultExcludes);
                ds.setDir(dir);
                ds.createPatternSet().addConfiguredPatternset(ps);
                dirSets.add(ds);
            } else {
                log.warn("Skipping " + pathElement + " since it is no directory.");
            }
        }
    }
    for (DirSet ds : dirSets) {
        File baseDir = ds.getDir(getProject());
        log.debug("scanning " + baseDir + " for packages.");
        DirectoryScanner dsc = ds.getDirectoryScanner(getProject());
        String[] dirs = dsc.getIncludedDirectories();
        boolean containsPackages = false;
        for (String dir : dirs) {
            // are there any groovy or java files in this directory?
            File pd = new File(baseDir, dir);
            String[] files = pd.list(new FilenameFilter() {

                public boolean accept(File dir1, String name) {
                    if (!includeNoSourcePackages && name.equals("package.html"))
                        return true;
                    final StringTokenizer tokenizer = new StringTokenizer(extensions, ":");
                    while (tokenizer.hasMoreTokens()) {
                        String ext = tokenizer.nextToken();
                        if (name.endsWith(ext))
                            return true;
                    }
                    return false;
                }
            });
            for (String filename : Arrays.asList(files)) {
                sourceFilesToDoc.add(dir + File.separator + filename);
            }
            if (files.length > 0) {
                if ("".equals(dir)) {
                    log.warn(baseDir + " contains source files in the default package," + " you must specify them as source files not packages.");
                } else {
                    containsPackages = true;
                    String pn = dir.replace(File.separatorChar, '.');
                    if (!addedPackages.contains(pn)) {
                        addedPackages.add(pn);
                        resultantPackages.add(pn);
                    }
                }
            }
        }
        if (containsPackages) {
            // We don't need to care for duplicates here,
            // Path.list does it for us.
            sourcePath.createPathElement().setLocation(baseDir);
        } else {
            log.verbose(baseDir + " doesn't contain any packages, dropping it.");
        }
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) DirSet(org.apache.tools.ant.types.DirSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) PatternSet(org.apache.tools.ant.types.PatternSet) File(java.io.File)

Example 13 with DirectoryScanner

use of org.apache.tools.ant.DirectoryScanner in project groovy-core by groovy.

the class GenerateStubsTask method compile.

@Override
protected void compile() {
    GroovyClassLoader gcl = createClassLoader();
    JavaStubCompilationUnit cu = new JavaStubCompilationUnit(config, gcl, destdir);
    int count = 0;
    String[] list = src.list();
    for (int i = 0; i < list.length; i++) {
        File basedir = getProject().resolveFile(list[i]);
        if (!basedir.exists()) {
            throw new BuildException("Source directory does not exist: " + basedir, getLocation());
        }
        DirectoryScanner scanner = getDirectoryScanner(basedir);
        String[] includes = scanner.getIncludedFiles();
        log.debug("Including files from: " + basedir);
        for (int j = 0; j < includes.length; j++) {
            log.debug("    " + includes[j]);
            File file = new File(basedir, includes[j]);
            cu.addSource(file);
            // Increment the count for each non/java src we found
            if (!includes[j].endsWith(".java")) {
                count++;
            }
        }
    }
    if (count > 0) {
        log.info("Generating " + count + " Java stub" + (count > 1 ? "s" : "") + " to " + destdir);
        cu.compile();
        log.info("Generated " + cu.getStubCount() + " Java stub(s)");
    } else {
        log.info("No sources found for stub generation");
    }
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) JavaStubCompilationUnit(org.codehaus.groovy.tools.javac.JavaStubCompilationUnit) BuildException(org.apache.tools.ant.BuildException) File(java.io.File)

Example 14 with DirectoryScanner

use of org.apache.tools.ant.DirectoryScanner in project hibernate-orm by hibernate.

the class EnhancementTask method execute.

@Override
public void execute() throws BuildException {
    log("Starting Hibernate EnhancementTask execution", Project.MSG_INFO);
    // we use the CtClass stuff here just as a simple vehicle for obtaining low level information about
    // the class(es) contained in a file while still maintaining easy access to the underlying byte[]
    final Project project = getProject();
    for (FileSet fileSet : filesets) {
        final File fileSetBaseDir = fileSet.getDir(project);
        final DirectoryScanner directoryScanner = fileSet.getDirectoryScanner(project);
        for (String relativeIncludedFileName : directoryScanner.getIncludedFiles()) {
            final File javaClassFile = new File(fileSetBaseDir, relativeIncludedFileName);
            if (!javaClassFile.exists()) {
                continue;
            }
            processClassFile(relativeIncludedFileName, javaClassFile);
        }
    }
}
Also used : Project(org.apache.tools.ant.Project) FileSet(org.apache.tools.ant.types.FileSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) File(java.io.File)

Example 15 with DirectoryScanner

use of org.apache.tools.ant.DirectoryScanner in project hibernate-orm by hibernate.

the class SchemaExportTask method getFiles.

private String[] getFiles() {
    List<String> files = new LinkedList<String>();
    for (FileSet fileSet : fileSets) {
        final DirectoryScanner ds = fileSet.getDirectoryScanner(getProject());
        final String[] dsFiles = ds.getIncludedFiles();
        for (String dsFileName : dsFiles) {
            File f = new File(dsFileName);
            if (!f.isFile()) {
                f = new File(ds.getBasedir(), dsFileName);
            }
            files.add(f.getAbsolutePath());
        }
    }
    return ArrayHelper.toStringArray(files);
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) File(java.io.File) LinkedList(java.util.LinkedList)

Aggregations

DirectoryScanner (org.apache.tools.ant.DirectoryScanner)57 File (java.io.File)52 BuildException (org.apache.tools.ant.BuildException)26 FileSet (org.apache.tools.ant.types.FileSet)26 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)12 GroovyClassLoader (groovy.lang.GroovyClassLoader)4 FileInputStream (java.io.FileInputStream)4 FilenameFilter (java.io.FilenameFilter)4 Project (org.apache.tools.ant.Project)4 DirSet (org.apache.tools.ant.types.DirSet)4 PatternSet (org.apache.tools.ant.types.PatternSet)4 LinkedList (java.util.LinkedList)3 Path (org.apache.tools.ant.types.Path)3 AbstractProject (hudson.model.AbstractProject)2 VirtualChannel (hudson.remoting.VirtualChannel)2 OutputStream (java.io.OutputStream)2 URI (java.net.URI)2 URL (java.net.URL)2 URLClassLoader (java.net.URLClassLoader)2