diff --git a/WHATSNEW b/WHATSNEW
index 4372dca09..183665384 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -16,6 +16,8 @@ Fixed bugs:
Other changes:
--------------
+ * New file selectors <writable>
-
Select files if they are writable.<executable>
-
+ Select files if they are executable.<symlink>
-
+ Select files if they are symlink.Contains Selector
@@ -1009,7 +1013,7 @@
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
@@ -1017,6 +1021,26 @@
but the Java VM cannot detect this state, this selector will
still select the file.
The <executable>
selector selects only files
+ that are executable. Ant only invokes
+ java.nio.file.Files#isExecutable
so if a file is not executable
+ but the Java VM cannot detect this state, this selector will
+ still select the file.
Since Ant 1.10.0
+ +The <symlink>
selector selects only files
+ that are symbolic links. Ant only invokes
+ java.nio.file.Files#isSymbolicLink
so if a file
+ is a symbolic link but the Java VM cannot detect this state,
+ this selector will not select the file.
Since Ant 1.10.0
+
diff --git a/src/main/org/apache/tools/ant/types/AbstractFileSet.java b/src/main/org/apache/tools/ant/types/AbstractFileSet.java
index 8f274a09e..bf1560771 100644
--- a/src/main/org/apache/tools/ant/types/AbstractFileSet.java
+++ b/src/main/org/apache/tools/ant/types/AbstractFileSet.java
@@ -36,6 +36,7 @@ import org.apache.tools.ant.types.selectors.DependSelector;
import org.apache.tools.ant.types.selectors.DepthSelector;
import org.apache.tools.ant.types.selectors.DifferentSelector;
import org.apache.tools.ant.types.selectors.ExtendSelector;
+import org.apache.tools.ant.types.selectors.ExecutableSelector;
import org.apache.tools.ant.types.selectors.FileSelector;
import org.apache.tools.ant.types.selectors.FilenameSelector;
import org.apache.tools.ant.types.selectors.MajoritySelector;
@@ -48,6 +49,7 @@ import org.apache.tools.ant.types.selectors.SelectSelector;
import org.apache.tools.ant.types.selectors.SelectorContainer;
import org.apache.tools.ant.types.selectors.SelectorScanner;
import org.apache.tools.ant.types.selectors.SizeSelector;
+import org.apache.tools.ant.types.selectors.SymlinkSelector;
import org.apache.tools.ant.types.selectors.TypeSelector;
import org.apache.tools.ant.types.selectors.WritableSelector;
import org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector;
@@ -797,6 +799,14 @@ public abstract class AbstractFileSet extends DataType
appendSelector(w);
}
+ public void addExecutable(ExecutableSelector e) {
+ appendSelector(e);
+ }
+
+ public void addSymlink(SymlinkSelector e) {
+ appendSelector(e);
+ }
+
/**
* Add an arbitrary selector.
* @param selector the 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 b80816dac..c2f41a796 100644
--- a/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java
+++ b/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java
@@ -312,6 +312,14 @@ public abstract class AbstractSelectorContainer extends DataType
appendSelector(w);
}
+ public void addExecutable(ExecutableSelector e) {
+ appendSelector(e);
+ }
+
+ public void addSymlink(SymlinkSelector e) {
+ appendSelector(e);
+ }
+
/**
* add an arbitrary 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 1edf08574..e7aa6121f 100644
--- a/src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java
+++ b/src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java
@@ -315,6 +315,14 @@ public abstract class BaseSelectorContainer extends BaseSelector
appendSelector(w);
}
+ public void addExecutable(ExecutableSelector e) {
+ appendSelector(e);
+ }
+
+ public void addSymlink(SymlinkSelector e) {
+ appendSelector(e);
+ }
+
/**
* add an arbitrary selector
* @param selector the selector to add
diff --git a/src/main/org/apache/tools/ant/types/selectors/ExecutableSelector.java b/src/main/org/apache/tools/ant/types/selectors/ExecutableSelector.java
new file mode 100644
index 000000000..891b79508
--- /dev/null
+++ b/src/main/org/apache/tools/ant/types/selectors/ExecutableSelector.java
@@ -0,0 +1,51 @@
+/*
+ * 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.nio.file.Files;
+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 executable files.
+ *
+ *
Executable is defined in terms of {@link + * java.nio.file.Files#isExecutable}, this means the selector will + * accept any file that exists and is executable by the + * application.
+ * + * @since Ant 1.10.0 + */ +public class ExecutableSelector implements FileSelector, ResourceSelector { + + public boolean isSelected(File basedir, String filename, File file) { + return file != null && Files.isExecutable(file.toPath()); + } + + public boolean isSelected(Resource r) { + FileProvider fp = r.as(FileProvider.class); + if (fp != null) { + return isSelected(null, null, fp.getFile()); + } + return false; + } +} diff --git a/src/main/org/apache/tools/ant/types/selectors/SymlinkSelector.java b/src/main/org/apache/tools/ant/types/selectors/SymlinkSelector.java new file mode 100644 index 000000000..28c3bcb08 --- /dev/null +++ b/src/main/org/apache/tools/ant/types/selectors/SymlinkSelector.java @@ -0,0 +1,50 @@ +/* + * 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.nio.file.Files; +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 symbolic links. + * + *Executable is defined in terms of {@link + * java.nio.file.Files#isSymbolicLink}, this means the selector will + * accept any file that exists and is a symbolic link.
+ * + * @since Ant 1.10.0 + */ +public class SymlinkSelector implements FileSelector, ResourceSelector { + + public boolean isSelected(File basedir, String filename, File file) { + return file != null && Files.isSymbolicLink(file.toPath()); + } + + public boolean isSelected(Resource r) { + FileProvider fp = r.as(FileProvider.class); + if (fp != null) { + return isSelected(null, null, fp.getFile()); + } + return false; + } +} diff --git a/src/tests/antunit/types/selectors/executable-test.xml b/src/tests/antunit/types/selectors/executable-test.xml new file mode 100644 index 000000000..ed1e1ceac --- /dev/null +++ b/src/tests/antunit/types/selectors/executable-test.xml @@ -0,0 +1,85 @@ + + +