Search in sources :

Example 1 with SourceFileScanner

use of org.apache.tools.ant.util.SourceFileScanner in project ant by apache.

the class Copy method buildMap.

/**
 * Add to a map of files/directories to copy.
 *
 * @param fromDir the source directory.
 * @param toDir   the destination directory.
 * @param names   a list of filenames.
 * @param mapper  a <code>FileNameMapper</code> value.
 * @param map     a map of source file to array of destination files.
 */
protected void buildMap(final File fromDir, final File toDir, final String[] names, final FileNameMapper mapper, final Hashtable<String, String[]> map) {
    String[] toCopy = null;
    if (forceOverwrite) {
        final Vector<String> v = new Vector<String>();
        for (String name : names) {
            if (mapper.mapFileName(name) != null) {
                v.addElement(name);
            }
        }
        toCopy = new String[v.size()];
        v.copyInto(toCopy);
    } else {
        final SourceFileScanner ds = new SourceFileScanner(this);
        toCopy = ds.restrict(names, fromDir, toDir, mapper, granularity);
    }
    for (String name : toCopy) {
        final File src = new File(fromDir, name);
        final String[] mappedFiles = mapper.mapFileName(name);
        if (mappedFiles == null || mappedFiles.length == 0) {
            continue;
        }
        if (!enableMultipleMappings) {
            map.put(src.getAbsolutePath(), new String[] { new File(toDir, mappedFiles[0]).getAbsolutePath() });
        } else {
            // reuse the array created by the mapper
            for (int k = 0; k < mappedFiles.length; k++) {
                mappedFiles[k] = new File(toDir, mappedFiles[k]).getAbsolutePath();
            }
            map.put(src.getAbsolutePath(), mappedFiles);
        }
    }
}
Also used : SourceFileScanner(org.apache.tools.ant.util.SourceFileScanner) Vector(java.util.Vector) File(java.io.File)

Example 2 with SourceFileScanner

use of org.apache.tools.ant.util.SourceFileScanner in project ant by apache.

the class Native2Ascii method execute.

/**
 * Execute the task
 *
 * @throws BuildException is there is a problem in the task execution.
 */
@Override
public void execute() throws BuildException {
    // Scanner to find our inputs
    DirectoryScanner scanner = null;
    // list of files to process
    String[] files;
    // default srcDir to basedir
    if (srcDir == null) {
        srcDir = getProject().resolveFile(".");
    }
    // Require destDir
    if (destDir == null) {
        throw new BuildException("The dest attribute must be set.");
    }
    // include a file with the same extension, but ....
    if (srcDir.equals(destDir) && extension == null && mapper == null) {
        throw new BuildException("The ext attribute or a mapper must be set if src and dest dirs are the same.");
    }
    FileNameMapper m;
    if (mapper == null) {
        if (extension == null) {
            m = new IdentityMapper();
        } else {
            m = new ExtMapper();
        }
    } else {
        m = mapper.getImplementation();
    }
    scanner = getDirectoryScanner(srcDir);
    files = scanner.getIncludedFiles();
    SourceFileScanner sfs = new SourceFileScanner(this);
    files = sfs.restrict(files, srcDir, destDir, m);
    int count = files.length;
    if (count == 0) {
        return;
    }
    String message = "Converting " + count + " file" + (count != 1 ? "s" : "") + " from ";
    log(message + srcDir + " to " + destDir);
    for (String file : files) {
        String[] dest = m.mapFileName(file);
        if (dest != null && dest.length > 0) {
            convert(file, dest[0]);
        }
    }
}
Also used : IdentityMapper(org.apache.tools.ant.util.IdentityMapper) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) BuildException(org.apache.tools.ant.BuildException) FileNameMapper(org.apache.tools.ant.util.FileNameMapper) SourceFileScanner(org.apache.tools.ant.util.SourceFileScanner)

Example 3 with SourceFileScanner

use of org.apache.tools.ant.util.SourceFileScanner in project jangaroo-tools by CoreMedia.

the class PropcTask method scanDir.

/**
 * Scans the directory looking for source files to be compiled.
 * The results are returned in the class variable compileList
 *
 * @param srcDir  the source directory
 * @param destDir the destination directory
 * @param files   the files to scan
 */
protected void scanDir(File srcDir, File destDir, String[] files) {
    GlobPatternMapper m = new GlobPatternMapper();
    m.setFrom("*.properties");
    m.setTo("*.as");
    SourceFileScanner sfs = new SourceFileScanner(this);
    File[] newFiles = sfs.restrictAsFiles(files, srcDir, destDir, m);
    if (newFiles.length > 0) {
        File[] newCompileList = new File[compileList.length + newFiles.length];
        System.arraycopy(compileList, 0, newCompileList, 0, compileList.length);
        System.arraycopy(newFiles, 0, newCompileList, compileList.length, newFiles.length);
        compileList = newCompileList;
    }
}
Also used : GlobPatternMapper(org.apache.tools.ant.util.GlobPatternMapper) SourceFileScanner(org.apache.tools.ant.util.SourceFileScanner) File(java.io.File)

Example 4 with SourceFileScanner

use of org.apache.tools.ant.util.SourceFileScanner in project ant by apache.

the class Javac method scanDir.

/**
 * Scans the directory looking for source files to be compiled.
 * The results are returned in the class variable compileList
 *
 * @param srcDir   The source directory
 * @param destDir  The destination directory
 * @param files    An array of filenames
 */
protected void scanDir(final File srcDir, final File destDir, final String[] files) {
    final GlobPatternMapper m = new GlobPatternMapper();
    for (String extension : findSupportedFileExtensions()) {
        m.setFrom(extension);
        m.setTo("*.class");
        final SourceFileScanner sfs = new SourceFileScanner(this);
        final File[] newFiles = sfs.restrictAsFiles(files, srcDir, destDir, m);
        if (newFiles.length > 0) {
            lookForPackageInfos(srcDir, newFiles);
            final File[] newCompileList = new File[compileList.length + newFiles.length];
            System.arraycopy(compileList, 0, newCompileList, 0, compileList.length);
            System.arraycopy(newFiles, 0, newCompileList, compileList.length, newFiles.length);
            compileList = newCompileList;
        }
    }
}
Also used : GlobPatternMapper(org.apache.tools.ant.util.GlobPatternMapper) SourceFileScanner(org.apache.tools.ant.util.SourceFileScanner) File(java.io.File)

Example 5 with SourceFileScanner

use of org.apache.tools.ant.util.SourceFileScanner in project ant by apache.

the class Rmic method scanDir.

/**
 * Scans the directory looking for class files to be compiled.
 * The result is returned in the class variable compileList.
 * @param baseDir the base direction
 * @param files   the list of files to scan
 * @param mapper  the mapper of files to target files
 */
protected void scanDir(File baseDir, String[] files, FileNameMapper mapper) {
    String[] newFiles = files;
    if (idl) {
        log("will leave uptodate test to rmic implementation in idl mode.", Project.MSG_VERBOSE);
    } else if (iiop && iiopOpts != null && iiopOpts.contains("-always")) {
        log("no uptodate test as -always option has been specified", Project.MSG_VERBOSE);
    } else {
        SourceFileScanner sfs = new SourceFileScanner(this);
        newFiles = sfs.restrict(files, baseDir, getOutputDir(), mapper);
    }
    Stream.of(newFiles).map(s -> s.replace(File.separatorChar, '.')).map(s -> s.substring(0, s.lastIndexOf(".class"))).forEach(compileList::add);
}
Also used : FileUtils(org.apache.tools.ant.util.FileUtils) Remote(java.rmi.Remote) AntClassLoader(org.apache.tools.ant.AntClassLoader) FilterSetCollection(org.apache.tools.ant.types.FilterSetCollection) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) FileNameMapper(org.apache.tools.ant.util.FileNameMapper) RmicAdapterFactory(org.apache.tools.ant.taskdefs.rmic.RmicAdapterFactory) FacadeTaskHelper(org.apache.tools.ant.util.facade.FacadeTaskHelper) RmicAdapter(org.apache.tools.ant.taskdefs.rmic.RmicAdapter) File(java.io.File) Path(org.apache.tools.ant.types.Path) SourceFileScanner(org.apache.tools.ant.util.SourceFileScanner) Vector(java.util.Vector) Stream(java.util.stream.Stream) StringUtils(org.apache.tools.ant.util.StringUtils) Project(org.apache.tools.ant.Project) Reference(org.apache.tools.ant.types.Reference) SourceFileScanner(org.apache.tools.ant.util.SourceFileScanner)

Aggregations

SourceFileScanner (org.apache.tools.ant.util.SourceFileScanner)14 File (java.io.File)11 GlobPatternMapper (org.apache.tools.ant.util.GlobPatternMapper)8 BuildException (org.apache.tools.ant.BuildException)5 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)5 Path (org.apache.tools.ant.types.Path)3 FileNameMapper (org.apache.tools.ant.util.FileNameMapper)3 GroovyClassLoader (groovy.lang.GroovyClassLoader)2 Vector (java.util.Vector)2 CompilationUnit (org.codehaus.groovy.control.CompilationUnit)2 IOException (java.io.IOException)1 Remote (java.rmi.Remote)1 Stream (java.util.stream.Stream)1 AntClassLoader (org.apache.tools.ant.AntClassLoader)1 Project (org.apache.tools.ant.Project)1 RmicAdapter (org.apache.tools.ant.taskdefs.rmic.RmicAdapter)1 RmicAdapterFactory (org.apache.tools.ant.taskdefs.rmic.RmicAdapterFactory)1 FileSet (org.apache.tools.ant.types.FileSet)1 FilterSetCollection (org.apache.tools.ant.types.FilterSetCollection)1 Reference (org.apache.tools.ant.types.Reference)1