diff --git a/WHATSNEW b/WHATSNEW
index 17c7173b5..2ecbcd468 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -252,6 +252,11 @@ Other changes:
not an archive earlier if the file is big.
Bugzilla Report 45463.
+ * New file and resource selectors
<readable>
-
+ Select files if they are readable.<writable>
-
+ Select files if they are writable.The <readable>
selector selects only files
+ that are readable. Ant only invokes
+ java.io.File#canRead
so if a file is unreadable
+ but the Java VM cannot detect this state, this selector will
+ still select the file.
The <writable>
selector selects only files
+ that are writable. Ant only invokes
+ java.io.File#canWrite
so if a file is unwritable
+ but the Java VM cannot detect this state, this selector will
+ still select the file.
FileSelector
to add.
diff --git a/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java b/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java
index c118068f4..f0eae3f13 100644
--- a/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java
+++ b/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java
@@ -276,6 +276,14 @@ public abstract class AbstractSelectorContainer extends DataType
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
diff --git a/src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java b/src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java
index 10a44b9bd..e5f7d539d 100644
--- a/src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java
+++ b/src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java
@@ -301,6 +301,14 @@ public abstract class BaseSelectorContainer extends BaseSelector
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
diff --git a/src/main/org/apache/tools/ant/types/selectors/ReadableSelector.java b/src/main/org/apache/tools/ant/types/selectors/ReadableSelector.java
new file mode 100644
index 000000000..3eb02ab3a
--- /dev/null
+++ b/src/main/org/apache/tools/ant/types/selectors/ReadableSelector.java
@@ -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.
+ *
+ * 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.
+ * + * @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 diff --git a/src/main/org/apache/tools/ant/types/selectors/WritableSelector.java b/src/main/org/apache/tools/ant/types/selectors/WritableSelector.java new file mode 100644 index 000000000..4dc1096a2 --- /dev/null +++ b/src/main/org/apache/tools/ant/types/selectors/WritableSelector.java @@ -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. + * + *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.
+ * + * @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 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 115e2fbaa..0d0e50248 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 @@ -42,8 +42,12 @@ classname="org.apache.tools.ant.types.resources.selectors.Not" />