diff --git a/docs/manual/CoreTypes/resources.html b/docs/manual/CoreTypes/resources.html index ff9d86a52..8651d58ca 100644 --- a/docs/manual/CoreTypes/resources.html +++ b/docs/manual/CoreTypes/resources.html @@ -154,7 +154,7 @@ implementations are also usable as single-element

The classpath along which to search for a Java resource - can also be specified by means of one or more nested + can also be specified by means of one or more nested classpath elements.

@@ -347,6 +347,8 @@ platforms. - select resources selected by no nested resource selectors.
  • majority - select resources selected by a majority of nested resource selectors.
  • +
  • modified - select resources which + content has changed.
  • name

    @@ -597,4 +599,4 @@ natural order, or by one or more nested resource comparators:

    Reserved.

    - + \ No newline at end of file diff --git a/docs/manual/CoreTypes/selectors.html b/docs/manual/CoreTypes/selectors.html index 9ec2e4e39..4044ea177 100755 --- a/docs/manual/CoreTypes/selectors.html +++ b/docs/manual/CoreTypes/selectors.html @@ -659,6 +659,12 @@ The comparison, computing of the hashvalue and the store is done by implementation of special interfaces. Therefore they may provide additional parameters.

    +

    The <modified> selector can be used as ResourceSelector. + In that case it maps simple file resources to files and does its job. If the + resource is from another type, the <modified> selector tries + to (attention!) copy the content into a local file for computing the + hashvalue.

    + @@ -729,6 +735,13 @@ + + + + + -
    Attribute Should directories be selected? (boolean) No, defaults to true
    selres Should Resources whithout an InputStream, and + therefore without checking, be selected? (boolean) No, defaults to true. Only relevant + when used as ResourceSelector.
    delayupdate If set to true, the storage of the cache will be delayed until the @@ -932,7 +945,7 @@

    Script Selector

    - The <scriptselector> element enables you + The <scriptselector> element enables you to write a complex selection algorithm in any Apache BSF supported language.

    @@ -958,22 +971,22 @@
    filename of the script no
    +

    If no src attribute is supplied, the script must be nested - inside the selector declaration. + inside the selector declaration.

    The embedded script is invoked for every test, with - the bean self + the bean self is bound to the selector. It has an attribute selected must can be set using setSelected(boolean) to select that file. - +

    - + The following beans are configured for every script, alongside the classic set of project, properties, and targets. - + @@ -1000,13 +1013,13 @@ - -
    BeanFileset base directory java.io.File
    + +

    The self bean maps to the selector, which has the following - attributes. Only the selected flag is writeable, the rest + attributes. Only the selected flag is writeable, the rest are read only via their getter methods. - + @@ -1034,7 +1047,7 @@
    Attributejava.io.File
    - +

    Example

    @@ -1053,7 +1066,7 @@ </scriptselector> Select files whose filename length is even. - +

    Selector Containers

    @@ -1450,4 +1463,4 @@ Select files whose filename length is even. - + \ No newline at end of file diff --git a/src/etc/testcases/types/resources/selectors/build.xml b/src/etc/testcases/types/resources/selectors/build.xml index d0500bfaf..2abf7608a 100755 --- a/src/etc/testcases/types/resources/selectors/build.xml +++ b/src/etc/testcases/types/resources/selectors/build.xml @@ -407,4 +407,12 @@ + + + + + diff --git a/src/etc/testcases/types/selectors.xml b/src/etc/testcases/types/selectors.xml index 1f60cb683..42e0f874d 100644 --- a/src/etc/testcases/types/selectors.xml +++ b/src/etc/testcases/types/selectors.xml @@ -261,4 +261,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/org/apache/tools/ant/types/selectors/modifiedselector/ModifiedSelector.java b/src/main/org/apache/tools/ant/types/selectors/modifiedselector/ModifiedSelector.java index 583318b80..89bffe2ef 100644 --- a/src/main/org/apache/tools/ant/types/selectors/modifiedselector/ModifiedSelector.java +++ b/src/main/org/apache/tools/ant/types/selectors/modifiedselector/ModifiedSelector.java @@ -33,7 +33,11 @@ import org.apache.tools.ant.BuildEvent; import org.apache.tools.ant.types.EnumeratedAttribute; import org.apache.tools.ant.types.Parameter; import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.Resource; +import org.apache.tools.ant.types.resources.FileResource; +import org.apache.tools.ant.types.resources.selectors.ResourceSelector; import org.apache.tools.ant.types.selectors.BaseExtendSelector; +import org.apache.tools.ant.util.FileUtils; /** @@ -228,10 +232,11 @@ import org.apache.tools.ant.types.selectors.BaseExtendSelector; * a nested . * * - * @version 2004-07-12 + * @version 2005-07-19 * @since Ant 1.6 */ -public class ModifiedSelector extends BaseExtendSelector implements BuildListener { +public class ModifiedSelector extends BaseExtendSelector + implements BuildListener, ResourceSelector { // ----- attributes ----- @@ -261,6 +266,12 @@ public class ModifiedSelector extends BaseExtendSelector implements BuildListene /** Are directories selected? */ private boolean selectDirectories = true; + /** + * Should Resources whithout an InputStream, and + * therefore without checking, be selected? + */ + private boolean selectResourcesWithoutInputStream = true; + /** Delay the writing of the cache file */ private boolean delayUpdate = true; @@ -506,14 +517,73 @@ public class ModifiedSelector extends BaseExtendSelector implements BuildListene // ----- the selection work ----- + /** + * Implementation of ResourceSelector.isSelected(). + * + * @param resource The resource to check + * @return whether the resource is selected + * @see org.apache.tools.ant.types.resources.selectors.ResourceSelector#isSelected(org.apache.tools.ant.types.Resource) + */ + 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); + } else { + 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); + Resource tmpResource = new FileResource(tmpFile); + fu.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. " + + "Akkording to 'selres' attribute value it is " + + ((selectResourcesWithoutInputStream) ? "" : " not") + + "selected.", Project.MSG_INFO); + return selectResourcesWithoutInputStream; + } catch (Exception e) { + throw new BuildException(e); + } + } + } + + /** * Implementation of BaseExtendSelector.isSelected(). + * * @param basedir as described in BaseExtendSelector * @param filename as described in BaseExtendSelector * @param file as described in BaseExtendSelector * @return as described in BaseExtendSelector */ public boolean isSelected(File basedir, String filename, File file) { + return isSelected(basedir, filename, file.getAbsolutePath()); + } + + + /** + * The business logic of this selector for use as ResourceSelector of + * FileSelector. + * + * @param basedir as described in BaseExtendSelector + * @param filename as described in BaseExtendSelector + * @param cacheKey the name for the key for storing the hashvalue + * @return + */ + private boolean isSelected(File basedir, String filename, String cacheKey) { validate(); File f = new File(basedir, filename); @@ -524,7 +594,7 @@ public class ModifiedSelector extends BaseExtendSelector implements BuildListene // Get the values and do the comparison String cachedValue = String.valueOf(cache.get(f.getAbsolutePath())); - String newValue = algorithm.getValue(f); + String newValue = algorithm.getValue(f); boolean rv = (comparator.compare(cachedValue, newValue) != 0); @@ -600,6 +670,15 @@ public class ModifiedSelector extends BaseExtendSelector implements BuildListene } + /** + * Support for selres attribute. + * @param newValue the new value + */ + public void setSelres(boolean newValue) { + this.selectResourcesWithoutInputStream = newValue; + } + + /** * Getter for the modified count * @return modified count @@ -964,4 +1043,5 @@ public class ModifiedSelector extends BaseExtendSelector implements BuildListene return new String[] {"equal", "rule" }; } } + } diff --git a/src/resources/org/apache/tools/ant/types/resources/selectors/antlib.xml b/src/resources/org/apache/tools/ant/types/resources/selectors/antlib.xml index 5c1654c11..05aeb89e6 100755 --- a/src/resources/org/apache/tools/ant/types/resources/selectors/antlib.xml +++ b/src/resources/org/apache/tools/ant/types/resources/selectors/antlib.xml @@ -21,4 +21,6 @@ classname="org.apache.tools.ant.types.resources.selectors.Size" /> + diff --git a/src/testcases/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java b/src/testcases/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java index cec781c63..f7dd2e048 100644 --- a/src/testcases/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java +++ b/src/testcases/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java @@ -43,7 +43,7 @@ import org.apache.tools.ant.util.FileUtils; /** * Unit tests for ModifiedSelector. * - * @version 2004-07-12 + * @version 2005-07-19 * @since Ant 1.6 */ public class ModifiedSelectorTest extends BaseSelectorTest {