git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@685593 13f79535-47bb-0310-9956-ffa450edef68master
@@ -252,6 +252,11 @@ Other changes: | |||||
not an archive earlier if the file is big. | not an archive earlier if the file is big. | ||||
Bugzilla Report 45463. | 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 | Changes from Ant 1.7.0 TO Ant 1.7.1 | ||||
============================================= | ============================================= | ||||
@@ -487,6 +487,10 @@ platforms. | |||||
resources whose contents match a particular regular expression.</li> | resources whose contents match a particular regular expression.</li> | ||||
<li><a href="#rsel.compare">compare</a> - select resources | <li><a href="#rsel.compare">compare</a> - select resources | ||||
based on comparison to other resources.</li> | 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> | </ul> | ||||
<h4><a name="rsel.name">name</a></h4> | <h4><a name="rsel.name">name</a></h4> | ||||
@@ -89,6 +89,10 @@ | |||||
Use a BSF or JSR 223 scripting language to create | Use a BSF or JSR 223 scripting language to create | ||||
your own selector | your own selector | ||||
</li> | </li> | ||||
<li><a href="#readable"><code><readable></code></a> - | |||||
Select files if they are readable.</li> | |||||
<li><a href="#writable"><code><writable></code></a> - | |||||
Select files if they are writable.</li> | |||||
</ul> | </ul> | ||||
<a name="containsselect"></a> | <a name="containsselect"></a> | ||||
@@ -969,6 +973,24 @@ | |||||
</tr> | </tr> | ||||
</table> | </table> | ||||
<a name="readable"></a> | |||||
<h4>Readable Selector</h4> | |||||
<p>The <code><readable></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><writable></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> | <a name="scriptselector"></a> | ||||
<h4>Script Selector</h4> | <h4>Script Selector</h4> | ||||
@@ -45,6 +45,8 @@ import org.apache.tools.ant.types.selectors.MajoritySelector; | |||||
import org.apache.tools.ant.types.selectors.DifferentSelector; | import org.apache.tools.ant.types.selectors.DifferentSelector; | ||||
import org.apache.tools.ant.types.selectors.SelectorContainer; | import org.apache.tools.ant.types.selectors.SelectorContainer; | ||||
import org.apache.tools.ant.types.selectors.ContainsRegexpSelector; | 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; | import org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector; | ||||
/** | /** | ||||
@@ -724,6 +726,14 @@ public abstract class AbstractFileSet extends DataType | |||||
appendSelector(selector); | appendSelector(selector); | ||||
} | } | ||||
public void addReadable(ReadableSelector r) { | |||||
appendSelector(r); | |||||
} | |||||
public void addWritable(WritableSelector w) { | |||||
appendSelector(w); | |||||
} | |||||
/** | /** | ||||
* Add an arbitary selector. | * Add an arbitary selector. | ||||
* @param selector the <code>FileSelector</code> to add. | * @param selector the <code>FileSelector</code> to add. | ||||
@@ -276,6 +276,14 @@ public abstract class AbstractSelectorContainer extends DataType | |||||
appendSelector(selector); | appendSelector(selector); | ||||
} | } | ||||
public void addReadable(ReadableSelector r) { | |||||
appendSelector(r); | |||||
} | |||||
public void addWritable(WritableSelector w) { | |||||
appendSelector(w); | |||||
} | |||||
/** | /** | ||||
* add an arbitary selector | * add an arbitary selector | ||||
* @param selector the selector to add | * @param selector the selector to add | ||||
@@ -301,6 +301,14 @@ public abstract class BaseSelectorContainer extends BaseSelector | |||||
appendSelector(selector); | appendSelector(selector); | ||||
} | } | ||||
public void addReadable(ReadableSelector r) { | |||||
appendSelector(r); | |||||
} | |||||
public void addWritable(WritableSelector w) { | |||||
appendSelector(w); | |||||
} | |||||
/** | /** | ||||
* add an arbitary selector | * add an arbitary selector | ||||
* @param selector the selector to add | * @param selector the selector to add | ||||
@@ -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; | |||||
} | |||||
} |
@@ -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; | |||||
} | |||||
} |
@@ -42,8 +42,12 @@ | |||||
classname="org.apache.tools.ant.types.resources.selectors.Not" /> | classname="org.apache.tools.ant.types.resources.selectors.Not" /> | ||||
<typedef name="or" | <typedef name="or" | ||||
classname="org.apache.tools.ant.types.resources.selectors.Or" /> | classname="org.apache.tools.ant.types.resources.selectors.Or" /> | ||||
<typedef name="readable" | |||||
classname="org.apache.tools.ant.types.selectors.ReadableSelector" /> | |||||
<typedef name="size" | <typedef name="size" | ||||
classname="org.apache.tools.ant.types.resources.selectors.Size" /> | classname="org.apache.tools.ant.types.resources.selectors.Size" /> | ||||
<typedef name="type" | <typedef name="type" | ||||
classname="org.apache.tools.ant.types.resources.selectors.Type" /> | classname="org.apache.tools.ant.types.resources.selectors.Type" /> | ||||
<typedef name="writable" | |||||
classname="org.apache.tools.ant.types.selectors.WritableSelector" /> | |||||
</antlib> | </antlib> |
@@ -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> |
@@ -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> |