Search in sources :

Example 81 with FileSet

use of org.apache.tools.ant.types.FileSet in project ceylon-compiler by ceylon.

the class SourceModules method getModules.

// TODO filters by module name, supported backends (transitive)
public Set<Module> getModules() {
    if (this.dir == null) {
        this.dir = getProject().resolveFile(Constants.DEFAULT_SOURCE_DIR);
    }
    FileSet fs = new FileSet();
    fs.setDir(this.dir);
    // TODO Handle default module
    fs.setIncludes("**/" + Constants.MODULE_DESCRIPTOR);
    DirectoryScanner ds = fs.getDirectoryScanner(getProject());
    String[] files = ds.getIncludedFiles();
    log("<sourcemodules> found files " + Arrays.toString(files), Project.MSG_VERBOSE);
    URI base = dir.toURI();
    LinkedHashSet<Module> result = new LinkedHashSet<Module>();
    try {
        CeylonClassLoader loader = Util.getCeylonClassLoaderCachedInProject(getProject());
        for (String file : files) {
            URI uri = new File(this.dir, file).getParentFile().toURI();
            log("<sourcemodules> file " + file + "=> uri " + uri, Project.MSG_VERBOSE);
            String moduleName = base.relativize(uri).getPath().replace('/', '.');
            if (moduleName.endsWith(".")) {
                moduleName = moduleName.substring(0, moduleName.length() - 1);
            }
            log("<sourcemodules> file " + file + "=> moduleName " + moduleName, Project.MSG_VERBOSE);
            Module mav = new Module();
            mav.setName(moduleName);
            String version;
            try {
                version = new ModuleDescriptorReader(loader, mav.getName(), dir).getModuleVersion();
            } catch (NoSuchModuleException e) {
                log("<sourcemodules> file " + file + "=> module cannot be read: " + moduleName, Project.MSG_VERBOSE);
                // skip it
                continue;
            }
            log("<sourcemodules> file " + file + "=> module " + moduleName + "/" + version, Project.MSG_VERBOSE);
            mav.setVersion(version);
            result.add(mav);
        }
    } catch (ClassLoaderSetupException x) {
        log("failed to set up Ceylon classloader: could not load module set", Project.MSG_VERBOSE);
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) FileSet(org.apache.tools.ant.types.FileSet) CeylonClassLoader(com.redhat.ceylon.launcher.CeylonClassLoader) ClassLoaderSetupException(com.redhat.ceylon.launcher.ClassLoaderSetupException) URI(java.net.URI) ModuleDescriptorReader(com.redhat.ceylon.common.ModuleDescriptorReader) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) NoSuchModuleException(com.redhat.ceylon.common.ModuleDescriptorReader.NoSuchModuleException) File(java.io.File)

Example 82 with FileSet

use of org.apache.tools.ant.types.FileSet in project ceylon-compiler by ceylon.

the class CeylonCompileJsAntTask method addToCompileList.

private void addToCompileList(List<File> dirs) {
    for (File srcDir : dirs) {
        if (srcDir.isDirectory()) {
            FileSet fs = (FileSet) this.files.clone();
            fs.setDir(srcDir);
            DirectoryScanner ds = fs.getDirectoryScanner(getProject());
            String[] files = ds.getIncludedFiles();
            for (String fileName : files) compileList.add(new File(srcDir, fileName));
        }
    }
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) File(java.io.File)

Example 83 with FileSet

use of org.apache.tools.ant.types.FileSet in project tomcat by apache.

the class Txt2Html method execute.

/**
 * Perform the conversion
 *
 * @throws BuildException if an error occurs during execution of
 *    this task.
 */
@Override
public void execute() throws BuildException {
    int count = 0;
    // Step through each file and convert.
    for (FileSet fs : filesets) {
        DirectoryScanner ds = fs.getDirectoryScanner(getProject());
        File basedir = ds.getBasedir();
        String[] files = ds.getIncludedFiles();
        for (String file : files) {
            File from = new File(basedir, file);
            File to = new File(todir, file + ".html");
            if (!to.exists() || (from.lastModified() > to.lastModified())) {
                log("Converting file '" + from.getAbsolutePath() + "' to '" + to.getAbsolutePath(), Project.MSG_VERBOSE);
                try {
                    convert(from, to);
                } catch (IOException e) {
                    throw new BuildException("Could not convert '" + from.getAbsolutePath() + "' to '" + to.getAbsolutePath() + "'", e);
                }
                count++;
            }
        }
        if (count > 0) {
            log("Converted " + count + " file" + (count > 1 ? "s" : "") + " to " + todir.getAbsolutePath());
        }
    }
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) File(java.io.File)

Example 84 with FileSet

use of org.apache.tools.ant.types.FileSet in project aries by apache.

the class EsaTaskTest method generateArchiveWithNewManifest.

@Test
public void generateArchiveWithNewManifest() {
    File srcDir = new File("../src/test/resources");
    assertTrue(srcDir.exists());
    File destfile = new File("target/esa-test.esa");
    if (destfile.exists()) {
        destfile.delete();
    }
    assertFalse(destfile.exists());
    EsaTask esaTask = new EsaTask();
    Project testProject = new Project();
    esaTask.setProject(testProject);
    FileSet fileSet = new FileSet();
    fileSet.setDir(srcDir);
    fileSet.setIncludes("*.jar");
    esaTask.addFileset(fileSet);
    esaTask.setDestFile(destfile);
    esaTask.setSymbolicName("esatask-test");
    esaTask.setName("ESA Test Task");
    esaTask.setVersion("1.0.0");
    esaTask.setGenerateManifest(true);
    esaTask.execute();
    assertTrue(destfile.exists());
    try {
        ZipFile esaArchive = new ZipFile(destfile);
        assertNotNull(esaArchive);
        ZipEntry subsystemManifest = esaArchive.getEntry("OSGI-INF/SUBSYSTEM.MF");
        assertNotNull(subsystemManifest);
    } catch (IOException e) {
        fail(e.getMessage());
    }
}
Also used : Project(org.apache.tools.ant.Project) FileSet(org.apache.tools.ant.types.FileSet) ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) File(java.io.File) Test(org.junit.Test)

Example 85 with FileSet

use of org.apache.tools.ant.types.FileSet in project checkstyle by checkstyle.

the class CheckstyleAntTask method scanFileSets.

/**
 * Returns the list of files (full path name) to process.
 *
 * @return the list of files included via the filesets.
 */
protected List<File> scanFileSets() {
    final List<File> allFiles = new ArrayList<>();
    for (int i = 0; i < fileSets.size(); i++) {
        final FileSet fileSet = fileSets.get(i);
        final DirectoryScanner scanner = fileSet.getDirectoryScanner(getProject());
        final List<File> scannedFiles = retrieveAllScannedFiles(scanner, i);
        allFiles.addAll(scannedFiles);
    }
    return allFiles;
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

FileSet (org.apache.tools.ant.types.FileSet)165 File (java.io.File)124 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)83 BuildException (org.apache.tools.ant.BuildException)49 Test (org.junit.Test)41 IOException (java.io.IOException)36 ArrayList (java.util.ArrayList)29 Project (org.apache.tools.ant.Project)22 Resource (org.apache.tools.ant.types.Resource)12 FileResource (org.apache.tools.ant.types.resources.FileResource)10 URL (java.net.URL)6 Hashtable (java.util.Hashtable)6 ArchiveFileSet (org.apache.tools.ant.types.ArchiveFileSet)6 Path (org.apache.tools.ant.types.Path)6 ResourceCollection (org.apache.tools.ant.types.ResourceCollection)6 PrintStream (java.io.PrintStream)5 HashMap (java.util.HashMap)5 Iterator (java.util.Iterator)5 List (java.util.List)5 ZipFileSet (org.apache.tools.ant.types.ZipFileSet)5