Search in sources :

Example 6 with FileUtils

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

the class ModifiedSelector method isSelected.

// -----  the selection work  -----
/**
 * Implementation of ResourceSelector.isSelected().
 *
 * @param resource The resource to check
 * @return whether the resource is selected
 * @see ResourceSelector#isSelected(Resource)
 */
@Override
public boolean isSelected(Resource resource) {
    if (resource.isFilesystemOnly()) {
        // We have a 'resourced' file, so reconvert it and use
        // the 'old' implementation.
        FileResource fileResource = (FileResource) resource;
        File file = fileResource.getFile();
        String filename = fileResource.getName();
        File basedir = fileResource.getBaseDir();
        return isSelected(basedir, filename, file);
    }
    try {
        // How to handle non-file-Resources? I copy temporarily the
        // resource to a file and use the file-implementation.
        FileUtils fu = FileUtils.getFileUtils();
        File tmpFile = fu.createTempFile("modified-", ".tmp", null, true, false);
        Resource tmpResource = new FileResource(tmpFile);
        ResourceUtils.copyResource(resource, tmpResource);
        boolean isSelected = isSelected(tmpFile.getParentFile(), tmpFile.getName(), resource.toLongString());
        tmpFile.delete();
        return isSelected;
    } catch (UnsupportedOperationException uoe) {
        log("The resource '" + resource.getName() + "' does not provide an InputStream, so it is not checked. " + "According to 'selres' attribute value it is " + ((selectResourcesWithoutInputStream) ? "" : " not") + "selected.", Project.MSG_INFO);
        return selectResourcesWithoutInputStream;
    } catch (Exception e) {
        throw new BuildException(e);
    }
}
Also used : FileUtils(org.apache.tools.ant.util.FileUtils) FileResource(org.apache.tools.ant.types.resources.FileResource) Resource(org.apache.tools.ant.types.Resource) FileResource(org.apache.tools.ant.types.resources.FileResource) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) BuildException(org.apache.tools.ant.BuildException)

Aggregations

FileUtils (org.apache.tools.ant.util.FileUtils)6 File (java.io.File)5 BuildException (org.apache.tools.ant.BuildException)3 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)1 Resource (org.apache.tools.ant.types.Resource)1 FileResource (org.apache.tools.ant.types.resources.FileResource)1 After (org.junit.After)1 Test (org.junit.Test)1