You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2016/04/09 17:04:29 UTC

[2/2] ant git commit: symlink and executable file selectors

symlink and executable file selectors


Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/c5e90bea
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/c5e90bea
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/c5e90bea

Branch: refs/heads/master
Commit: c5e90beadb2583e589051154b37f6e092a88e50d
Parents: dcf2413
Author: Stefan Bodewig <bo...@apache.org>
Authored: Sat Apr 9 17:04:02 2016 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Sat Apr 9 17:04:02 2016 +0200

----------------------------------------------------------------------
 WHATSNEW                                        |  2 +
 manual/Types/selectors.html                     | 26 +++++-
 .../apache/tools/ant/types/AbstractFileSet.java | 10 +++
 .../selectors/AbstractSelectorContainer.java    |  8 ++
 .../types/selectors/BaseSelectorContainer.java  |  8 ++
 .../ant/types/selectors/ExecutableSelector.java | 51 ++++++++++++
 .../ant/types/selectors/SymlinkSelector.java    | 50 ++++++++++++
 .../antunit/types/selectors/executable-test.xml | 85 +++++++++++++++++++
 .../antunit/types/selectors/symlink-test.xml    | 86 ++++++++++++++++++++
 9 files changed, 325 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/c5e90bea/WHATSNEW
----------------------------------------------------------------------
diff --git a/WHATSNEW b/WHATSNEW
index 4372dca..1836653 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -16,6 +16,8 @@ Fixed bugs:
 Other changes:
 --------------
 
+ * New file selectors <executable> and <symlink>
+
 Changes from Ant 1.9.6 TO Ant 1.9.7
 ===================================
 

http://git-wip-us.apache.org/repos/asf/ant/blob/c5e90bea/manual/Types/selectors.html
----------------------------------------------------------------------
diff --git a/manual/Types/selectors.html b/manual/Types/selectors.html
index 560b416..ab0a293 100644
--- a/manual/Types/selectors.html
+++ b/manual/Types/selectors.html
@@ -92,6 +92,10 @@
         Select files if they are readable.</li>
       <li><a href="#writable"><code>&lt;writable&gt;</code></a> -
         Select files if they are writable.</li>
+      <li><a href="#executable"><code>&lt;executable&gt;</code></a> -
+        Select files if they are executable.</li>
+      <li><a href="#symlink"><code>&lt;symlink&gt;</code></a> -
+        Select files if they are symlink.</li>
     </ul>
 
     <h4><a name="containsselect">Contains Selector</a></h4>
@@ -1009,7 +1013,7 @@
         but the Java VM cannot detect this state, this selector will
         still select the file.</p>
 
-      <h4><a name="writable">Writable Selector</a></h4>
+      <h4><a name="symlink">Writable Selector</a></h4>
 
       <p>The <code>&lt;writable&gt;</code> 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.</p>
 
+      <h4><a name="executable">Executable Selector</a></h4>
+
+      <p>The <code>&lt;executable&gt;</code> selector selects only files
+        that are executable.  Ant only invokes
+        <code>java.nio.file.Files#isExecutable</code> so if a file is not executable
+        but the Java VM cannot detect this state, this selector will
+        still select the file.</p>
+
+      <p><em>Since Ant 1.10.0</em></p>
+
+      <h4><a name="symlink">Symlink Selector</a></h4>
+
+      <p>The <code>&lt;symlink&gt;</code> selector selects only files
+        that are symbolic links.  Ant only invokes
+        <code>java.nio.file.Files#isSymbolicLink</code> so if a file
+        is a symbolic link but the Java VM cannot detect this state,
+        this selector will not select the file.</p>
+
+      <p><em>Since Ant 1.10.0</em></p>
+
       <h4><a name="scriptselector">Script Selector</a></h4>
 
       <p>

http://git-wip-us.apache.org/repos/asf/ant/blob/c5e90bea/src/main/org/apache/tools/ant/types/AbstractFileSet.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/AbstractFileSet.java b/src/main/org/apache/tools/ant/types/AbstractFileSet.java
index 8f274a0..bf15607 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 <code>FileSelector</code> to add.

http://git-wip-us.apache.org/repos/asf/ant/blob/c5e90bea/src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java
----------------------------------------------------------------------
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 b80816d..c2f41a7 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

http://git-wip-us.apache.org/repos/asf/ant/blob/c5e90bea/src/main/org/apache/tools/ant/types/selectors/BaseSelectorContainer.java
----------------------------------------------------------------------
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 1edf085..e7aa612 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

http://git-wip-us.apache.org/repos/asf/ant/blob/c5e90bea/src/main/org/apache/tools/ant/types/selectors/ExecutableSelector.java
----------------------------------------------------------------------
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 0000000..891b795
--- /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.
+ *
+ * <p>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.</p>
+ *
+ * @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;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ant/blob/c5e90bea/src/main/org/apache/tools/ant/types/selectors/SymlinkSelector.java
----------------------------------------------------------------------
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 0000000..28c3bcb
--- /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.
+ *
+ * <p>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.</p>
+ *
+ * @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;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ant/blob/c5e90bea/src/tests/antunit/types/selectors/executable-test.xml
----------------------------------------------------------------------
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 0000000..ed1e1ce
--- /dev/null
+++ b/src/tests/antunit/types/selectors/executable-test.xml
@@ -0,0 +1,85 @@
+<?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="file" value="testfile"/>
+
+  <condition property="unix">
+    <os family="unix"/>
+  </condition>
+
+  <target name="createTestdir">
+    <mkdir dir="${output}"/>
+    <touch file="${output}/${file}"/>
+  </target>
+
+  <target name="testExecutable" depends="makeFileExecutable" if="unix">
+    <au:assertTrue>
+      <resourcecount when="equal" count="1">
+        <fileset dir="${output}">
+          <executable/>
+        </fileset>
+      </resourcecount>
+    </au:assertTrue>
+    <au:assertTrue>
+      <resourcecount when="equal" count="0">
+        <fileset dir="${output}" excludes="${file}">
+          <executable/>
+        </fileset>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="makeFileExecutable"
+          depends="createTestdir,makeFileExecutable-Unix,makeFileExecutable-Windows"/>
+  <target name="makeFileExecutable-Unix" if="unix">
+    <chmod file="${output}/${file}" perm="755"/>
+  </target>
+  <target name="makeFileExecutable-Windows" unless="unix">
+    <!-- no idea how to do this -->
+  </target>
+
+  <target name="testNotexecutable" depends="createTestdir">
+    <au:assertTrue>
+      <resourcecount when="equal" count="0">
+        <fileset dir="${output}">
+          <executable/>
+        </fileset>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testAsFalseConditions" depends="createTestdir">
+    <au:assertFalse>
+      <isfileselected file="${output}/${file}">
+        <executable/>
+      </isfileselected>
+    </au:assertFalse>
+  </target>
+
+  <target name="testAsTrueConditions" depends="makeFileExecutable" if="unix">
+    <au:assertTrue>
+      <isfileselected file="${output}/${file}">
+        <executable/>
+      </isfileselected>
+    </au:assertTrue>
+  </target>
+
+</project>

http://git-wip-us.apache.org/repos/asf/ant/blob/c5e90bea/src/tests/antunit/types/selectors/symlink-test.xml
----------------------------------------------------------------------
diff --git a/src/tests/antunit/types/selectors/symlink-test.xml b/src/tests/antunit/types/selectors/symlink-test.xml
new file mode 100644
index 0000000..0c47326
--- /dev/null
+++ b/src/tests/antunit/types/selectors/symlink-test.xml
@@ -0,0 +1,86 @@
+<?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="file" value="testfile"/>
+  <property name="link" value="testlink"/>
+
+  <condition property="unix">
+    <os family="unix"/>
+  </condition>
+
+  <target name="createTestdir">
+    <mkdir dir="${output}"/>
+    <touch file="${output}/${file}"/>
+  </target>
+
+  <target name="testSymlink" depends="makeSymlink" if="unix">
+    <au:assertTrue>
+      <resourcecount when="equal" count="1">
+        <fileset dir="${output}">
+          <symlink/>
+        </fileset>
+      </resourcecount>
+    </au:assertTrue>
+    <au:assertTrue>
+      <resourcecount when="equal" count="0">
+        <fileset dir="${output}" excludes="${link}">
+          <symlink/>
+        </fileset>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="makeSymlink"
+          depends="createTestdir,makeSymlink-Unix,makeSymlink-Windows"/>
+  <target name="makeSymlink-Unix" if="unix">
+    <symlink link="${output}/${link}" resource="${output}/${file}"/>
+  </target>
+  <target name="makeSymlink-Windows" unless="unix">
+    <!-- no idea how to do this -->
+  </target>
+
+  <target name="testNoSymlink" depends="createTestdir">
+    <au:assertTrue>
+      <resourcecount when="equal" count="0">
+        <fileset dir="${output}">
+          <symlink/>
+        </fileset>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testAsFalseConditions" depends="createTestdir">
+    <au:assertFalse>
+      <isfileselected file="${output}/${link}">
+        <symlink/>
+      </isfileselected>
+    </au:assertFalse>
+  </target>
+
+  <target name="testAsTrueConditions" depends="makeSymlink" if="unix">
+    <au:assertTrue>
+      <isfileselected file="${output}/${link}">
+        <symlink/>
+      </isfileselected>
+    </au:assertTrue>
+  </target>
+
+</project>


Re: [2/2] ant git commit: symlink and executable file selectors

Posted by Stefan Bodewig <bo...@apache.org>.
On 2016-04-12, Antoine Levy Lambert wrote:

> there is a command mklink on Windows [1] which is described as being
> able to create symbolic links.

Which is not available on Win7 - and even if it was, I'm not sure Java
would detect the things as symlinks. I'll give it a try and we'll see
what our jenkins slaves think about it.

> Concerning executable files, it seems that the executable nature of a
> file depends upon its extension, see [3].

That's what I would have expected myself as well, but the Jenkins build
failed for testAsFalseConditions in executable-test which indicates all
files looked executable to Java. Not sure what to do with this.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: [2/2] ant git commit: symlink and executable file selectors

Posted by Antoine Levy Lambert <an...@gmx.de>.
Hello Stefan,

there is a command mklink on Windows [1] which is described as being able to create symbolic links.
There is also an API function CreateSymbolicLink [2].

Concerning executable files, it seems that the executable nature of a file depends upon its extension, see [3].
So maybe if we create a file xyz.bat the file should be found executable.
What I do not understand is that I have practical remembrances of changing the executable flag of a file under cygwin and this “chmod” command allowing dll s to actually work on Windows after they were untarred or copied with cygwin utilities.

I hope this helps. 

Using a library called jna (java native access) [4] we could call system level methods from java and make them available within ant tasks for testing or production purposes.

Regards,

Antoine

[1] https://technet.microsoft.com/en-us/library/cc753194.aspx
[2] https://msdn.microsoft.com/en-us/library/windows/desktop/aa363878%28v=vs.85%29.aspx
[3] https://msdn.microsoft.com/en-us/library/windows/desktop/ms722429%28v=vs.85%29.aspx
[4] https://github.com/java-native-access/jna


On Apr 9, 2016, at 11:07 AM, Stefan Bodewig <bo...@apache.org> wrote:

> On 2016-04-09, <bo...@apache.org> wrote:
> 
>> symlink and executable file selectors
> 
> Two questions:
> 
> (1) does anybody know how to write tests for either on Windows? I've
> currently only enabled antunit tests on Unix (at least that's what I
> wanted to do).
> 
> (2) do we want to port it as optional task depending on Java7 for 1.9.8?
> This would only benefit people who can use Java7 but not Java8.
> 
> Stefan
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: [2/2] ant git commit: symlink and executable file selectors

Posted by Stefan Bodewig <bo...@apache.org>.
On 2016-04-09, <bo...@apache.org> wrote:

> symlink and executable file selectors

Two questions:

(1) does anybody know how to write tests for either on Windows? I've
currently only enabled antunit tests on Unix (at least that's what I
wanted to do).

(2) do we want to port it as optional task depending on Java7 for 1.9.8?
This would only benefit people who can use Java7 but not Java8.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org