ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r685593 - in /ant/core/trunk: ./ docs/manual/CoreTypes/ src/main/org/apache/tools/ant/types/ src/main/org/apache/tools/ant/types/selectors/ src/resources/org/apache/tools/ant/types/resources/selectors/ src/tests/antunit/types/resources/sele...
Date Wed, 13 Aug 2008 15:55:03 GMT
Author: bodewig
Date: Wed Aug 13 08:55:01 2008
New Revision: 685593

URL: http://svn.apache.org/viewvc?rev=685593&view=rev
Log:
Add readable and writable selectors.  Addresses PR 45081.

Added:
    ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/ReadableSelector.java   (with
props)
    ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/WritableSelector.java   (with
props)
    ant/core/trunk/src/tests/antunit/types/resources/selectors/readwrite-test.xml   (with
props)
    ant/core/trunk/src/tests/antunit/types/selectors/
    ant/core/trunk/src/tests/antunit/types/selectors/readwrite-test.xml   (with props)
Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/docs/manual/CoreTypes/resources.html
    ant/core/trunk/docs/manual/CoreTypes/selectors.html
    ant/core/trunk/src/main/org/apache/tools/ant/types/AbstractFileSet.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java
    ant/core/trunk/src/resources/org/apache/tools/ant/types/resources/selectors/antlib.xml

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=685593&r1=685592&r2=685593&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Wed Aug 13 08:55:01 2008
@@ -252,6 +252,11 @@
    not an archive earlier if the file is big.
    Bugzilla Report 45463.
 
+ * New file and resource selectors <readable/> and <writable/> have
+   been added that select file which the current process can read or
+   write.
+   Bugzilla Report 45081.
+
 Changes from Ant 1.7.0 TO Ant 1.7.1
 =============================================
 

Modified: ant/core/trunk/docs/manual/CoreTypes/resources.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTypes/resources.html?rev=685593&r1=685592&r2=685593&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTypes/resources.html (original)
+++ ant/core/trunk/docs/manual/CoreTypes/resources.html Wed Aug 13 08:55:01 2008
@@ -487,6 +487,10 @@
       resources whose contents match a particular regular expression.</li>
     <li><a href="#rsel.compare">compare</a> - select resources
       based on comparison to other resources.</li>
+    <li><a href="selectors.html#readable">readable</a> -
+      Select files (resources must be files) if they are readable.</li>
+    <li><a href="selectors.html#writable">writable</a> -
+      Select files (resources must be files) if they are writable.</li>
   </ul>
 
   <h4><a name="rsel.name">name</a></h4>

Modified: ant/core/trunk/docs/manual/CoreTypes/selectors.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTypes/selectors.html?rev=685593&r1=685592&r2=685593&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTypes/selectors.html (original)
+++ ant/core/trunk/docs/manual/CoreTypes/selectors.html Wed Aug 13 08:55:01 2008
@@ -89,6 +89,10 @@
         Use a BSF or JSR 223 scripting language to create
         your own selector
       </li>
+      <li><a href="#readable"><code>&lt;readable&gt;</code></a>
-
+        Select files if they are readable.</li>
+      <li><a href="#writable"><code>&lt;writable&gt;</code></a>
-
+        Select files if they are writable.</li>
     </ul>
 
     <a name="containsselect"></a>
@@ -969,6 +973,24 @@
         </tr>
       </table>
 
+      <a name="readable"></a>
+      <h4>Readable Selector</h4>
+
+      <p>The <code>&lt;readable&gt;</code> selector selects only
files
+        that are readable.  Ant only invokes
+        <code>java.io.File#canRead</code> so if a file is unreadable
+        but the Java VM cannot detect this state, this selector will
+        still select the file.</p>
+
+      <a name="writable"></a>
+      <h4>Writable Selector</h4>
+
+      <p>The <code>&lt;writable&gt;</code> selector selects only
files
+        that are writable.  Ant only invokes
+        <code>java.io.File#canWrite</code> so if a file is unwritable
+        but the Java VM cannot detect this state, this selector will
+        still select the file.</p>
+
       <a name="scriptselector"></a>
       <h4>Script Selector</h4>
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/AbstractFileSet.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/AbstractFileSet.java?rev=685593&r1=685592&r2=685593&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/AbstractFileSet.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/AbstractFileSet.java Wed Aug 13 08:55:01
2008
@@ -45,6 +45,8 @@
 import org.apache.tools.ant.types.selectors.DifferentSelector;
 import org.apache.tools.ant.types.selectors.SelectorContainer;
 import org.apache.tools.ant.types.selectors.ContainsRegexpSelector;
+import org.apache.tools.ant.types.selectors.ReadableSelector;
+import org.apache.tools.ant.types.selectors.WritableSelector;
 import org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector;
 
 /**
@@ -724,6 +726,14 @@
         appendSelector(selector);
     }
 
+    public void addReadable(ReadableSelector r) {
+        appendSelector(r);
+    }
+
+    public void addWritable(WritableSelector w) {
+        appendSelector(w);
+    }
+
     /**
      * Add an arbitary selector.
      * @param selector the <code>FileSelector</code> to add.

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java?rev=685593&r1=685592&r2=685593&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java
Wed Aug 13 08:55:01 2008
@@ -276,6 +276,14 @@
         appendSelector(selector);
     }
 
+    public void addReadable(ReadableSelector r) {
+        appendSelector(r);
+    }
+
+    public void addWritable(WritableSelector w) {
+        appendSelector(w);
+    }
+
     /**
      * add an arbitary selector
      * @param selector the selector to add

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java?rev=685593&r1=685592&r2=685593&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java
Wed Aug 13 08:55:01 2008
@@ -301,6 +301,14 @@
         appendSelector(selector);
     }
 
+    public void addReadable(ReadableSelector r) {
+        appendSelector(r);
+    }
+
+    public void addWritable(WritableSelector w) {
+        appendSelector(w);
+    }
+
     /**
      * add an arbitary selector
      * @param selector the selector to add

Added: ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/ReadableSelector.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/ReadableSelector.java?rev=685593&view=auto
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/ReadableSelector.java (added)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/ReadableSelector.java Wed
Aug 13 08:55:01 2008
@@ -0,0 +1,47 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types.selectors;
+
+import java.io.File;
+import org.apache.tools.ant.types.Resource;
+import org.apache.tools.ant.types.resources.FileProvider;
+import org.apache.tools.ant.types.resources.selectors.ResourceSelector;
+
+/**
+ * A selector that selects readable files.
+ *
+ * <p>Readable is definied in terms of java.io.File#canRead, this
+ * means the selector will accept any file that exists and is readable
+ * by the application.</p>
+ *
+ * @since Ant 1.8.0
+ */
+public class ReadableSelector implements FileSelector, ResourceSelector {
+
+    public boolean isSelected(File basedir, String filename, File file) {
+        return file != null && file.canRead();
+    }
+
+    public boolean isSelected(Resource r) {
+        if (r instanceof FileProvider) {
+            return isSelected(null, null, ((FileProvider) r).getFile());
+        }
+        return false;
+    }
+}
\ No newline at end of file

Propchange: ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/ReadableSelector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/WritableSelector.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/WritableSelector.java?rev=685593&view=auto
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/WritableSelector.java (added)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/WritableSelector.java Wed
Aug 13 08:55:01 2008
@@ -0,0 +1,47 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types.selectors;
+
+import java.io.File;
+import org.apache.tools.ant.types.Resource;
+import org.apache.tools.ant.types.resources.FileProvider;
+import org.apache.tools.ant.types.resources.selectors.ResourceSelector;
+
+/**
+ * A selector that selects writable files.
+ *
+ * <p>Writable is definied in terms of java.io.File#canWrite, this
+ * means the selector will accept any file that exists and is
+ * writable by the application.</p>
+ *
+ * @since Ant 1.8.0
+ */
+public class WritableSelector implements FileSelector, ResourceSelector {
+
+    public boolean isSelected(File basedir, String filename, File file) {
+        return file != null && file.canWrite();
+    }
+
+    public boolean isSelected(Resource r) {
+        if (r instanceof FileProvider) {
+            return isSelected(null, null, ((FileProvider) r).getFile());
+        }
+        return false;
+    }
+}
\ No newline at end of file

Propchange: ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/WritableSelector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: ant/core/trunk/src/resources/org/apache/tools/ant/types/resources/selectors/antlib.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/resources/org/apache/tools/ant/types/resources/selectors/antlib.xml?rev=685593&r1=685592&r2=685593&view=diff
==============================================================================
--- ant/core/trunk/src/resources/org/apache/tools/ant/types/resources/selectors/antlib.xml
(original)
+++ ant/core/trunk/src/resources/org/apache/tools/ant/types/resources/selectors/antlib.xml
Wed Aug 13 08:55:01 2008
@@ -42,8 +42,12 @@
     classname="org.apache.tools.ant.types.resources.selectors.Not" />
   <typedef name="or"
     classname="org.apache.tools.ant.types.resources.selectors.Or" />
+  <typedef name="readable"
+    classname="org.apache.tools.ant.types.selectors.ReadableSelector" />
   <typedef name="size"
     classname="org.apache.tools.ant.types.resources.selectors.Size" />
   <typedef name="type"
     classname="org.apache.tools.ant.types.resources.selectors.Type" />
+  <typedef name="writable"
+    classname="org.apache.tools.ant.types.selectors.WritableSelector" />
 </antlib>

Added: ant/core/trunk/src/tests/antunit/types/resources/selectors/readwrite-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/types/resources/selectors/readwrite-test.xml?rev=685593&view=auto
==============================================================================
--- ant/core/trunk/src/tests/antunit/types/resources/selectors/readwrite-test.xml (added)
+++ ant/core/trunk/src/tests/antunit/types/resources/selectors/readwrite-test.xml Wed Aug
13 08:55:01 2008
@@ -0,0 +1,110 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"
+         xmlns:rsel="antlib:org.apache.tools.ant.types.resources.selectors">
+
+  <import file="../../../antunit-base.xml" />
+
+  <property name="dir" location="testdir"/>
+  <property name="file" value="testfile"/>
+
+  <condition property="unix">
+    <os family="unix"/>
+  </condition>
+
+  <target name="createTestdir">
+    <mkdir dir="${dir}"/>
+    <touch file="${dir}/${file}"/>
+  </target>
+
+  <target name="tearDown">
+    <delete dir="${dir}"/>
+  </target>
+
+  <target name="testReadable" depends="createTestdir">
+    <au:assertTrue>
+      <resourcecount when="equal" count="1">
+        <restrict>
+          <fileset dir="${dir}"/>
+          <rsel:readable/>
+        </restrict>
+      </resourcecount>
+    </au:assertTrue>
+    <au:assertTrue>
+      <resourcecount when="equal" count="0">
+        <restrict>
+          <fileset dir="${dir}" excludes="${file}"/>
+          <rsel:readable/>
+        </restrict>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testWritable" depends="createTestdir">
+    <au:assertTrue>
+      <resourcecount when="equal" count="1">
+        <restrict>
+          <fileset dir="${dir}"/>
+          <rsel:writable/>
+        </restrict>
+      </resourcecount>
+    </au:assertTrue>
+    <au:assertTrue>
+      <resourcecount when="equal" count="0">
+        <restrict>
+          <fileset dir="${dir}" excludes="${file}"/>
+          <rsel:writable/>
+        </restrict>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="makeFileUnwritable"
+          depends="createTestdir,makeFileUnwritable-Unix,makeFileUnwritable-Windows"/>
+  <target name="makeFileUnwritable-Unix" id="unix">
+    <chmod file="${dir}/${file}" perm="444"/>
+  </target>
+  <target name="makeFileUnwritable-Windows" unless="unix">
+    <attrib file="${dir}/${file}" readonly="true"/>
+  </target>
+
+  <target name="testUnwritable" depends="makeFileUnwritable">
+    <au:assertTrue>
+      <resourcecount when="equal" count="0">
+        <restrict>
+          <fileset dir="${dir}"/>
+          <rsel:writable/>
+        </restrict>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testAsConditions" depends="makeFileUnwritable">
+    <au:assertTrue>
+      <isfileselected file="${dir}/${file}">
+        <rsel:readable/>
+      </isfileselected>
+    </au:assertTrue>
+    <au:assertFalse>
+      <isfileselected file="${dir}/${file}">
+        <rsel:writable/>
+      </isfileselected>
+    </au:assertFalse>
+  </target>
+
+</project>

Propchange: ant/core/trunk/src/tests/antunit/types/resources/selectors/readwrite-test.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: ant/core/trunk/src/tests/antunit/types/selectors/readwrite-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/types/selectors/readwrite-test.xml?rev=685593&view=auto
==============================================================================
--- ant/core/trunk/src/tests/antunit/types/selectors/readwrite-test.xml (added)
+++ ant/core/trunk/src/tests/antunit/types/selectors/readwrite-test.xml Wed Aug 13 08:55:01
2008
@@ -0,0 +1,104 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit">
+
+  <import file="../../antunit-base.xml" />
+
+  <property name="dir" location="testdir"/>
+  <property name="file" value="testfile"/>
+
+  <condition property="unix">
+    <os family="unix"/>
+  </condition>
+
+  <target name="createTestdir">
+    <mkdir dir="${dir}"/>
+    <touch file="${dir}/${file}"/>
+  </target>
+
+  <target name="tearDown">
+    <delete dir="${dir}"/>
+  </target>
+
+  <target name="testReadable" depends="createTestdir">
+    <au:assertTrue>
+      <resourcecount when="equal" count="1">
+        <fileset dir="${dir}">
+          <readable/>
+        </fileset>
+      </resourcecount>
+    </au:assertTrue>
+    <au:assertTrue>
+      <resourcecount when="equal" count="0">
+        <fileset dir="${dir}" excludes="${file}">
+          <readable/>
+        </fileset>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testWritable" depends="createTestdir">
+    <au:assertTrue>
+      <resourcecount when="equal" count="1">
+        <fileset dir="${dir}">
+          <writable/>
+        </fileset>
+      </resourcecount>
+    </au:assertTrue>
+    <au:assertTrue>
+      <resourcecount when="equal" count="0">
+        <fileset dir="${dir}" excludes="${file}">
+          <writable/>
+        </fileset>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="makeFileUnwritable"
+          depends="createTestdir,makeFileUnwritable-Unix,makeFileUnwritable-Windows"/>
+  <target name="makeFileUnwritable-Unix" id="unix">
+    <chmod file="${dir}/${file}" perm="444"/>
+  </target>
+  <target name="makeFileUnwritable-Windows" unless="unix">
+    <attrib file="${dir}/${file}" readonly="true"/>
+  </target>
+
+  <target name="testUnwritable" depends="makeFileUnwritable">
+    <au:assertTrue>
+      <resourcecount when="equal" count="0">
+        <fileset dir="${dir}">
+          <writable/>
+        </fileset>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testAsConditions" depends="makeFileUnwritable">
+    <au:assertTrue>
+      <isfileselected file="${dir}/${file}">
+        <readable/>
+      </isfileselected>
+    </au:assertTrue>
+    <au:assertFalse>
+      <isfileselected file="${dir}/${file}">
+        <writable/>
+      </isfileselected>
+    </au:assertFalse>
+  </target>
+
+</project>

Propchange: ant/core/trunk/src/tests/antunit/types/selectors/readwrite-test.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message