@@ -16,6 +16,8 @@ Fixed bugs: | |||||
Other changes: | Other changes: | ||||
-------------- | -------------- | ||||
* New file selectors <executable> and <symlink> | |||||
Changes from Ant 1.9.6 TO Ant 1.9.7 | Changes from Ant 1.9.6 TO Ant 1.9.7 | ||||
=================================== | =================================== | ||||
@@ -92,6 +92,10 @@ | |||||
Select files if they are readable.</li> | Select files if they are readable.</li> | ||||
<li><a href="#writable"><code><writable></code></a> - | <li><a href="#writable"><code><writable></code></a> - | ||||
Select files if they are writable.</li> | Select files if they are writable.</li> | ||||
<li><a href="#executable"><code><executable></code></a> - | |||||
Select files if they are executable.</li> | |||||
<li><a href="#symlink"><code><symlink></code></a> - | |||||
Select files if they are symlink.</li> | |||||
</ul> | </ul> | ||||
<h4><a name="containsselect">Contains Selector</a></h4> | <h4><a name="containsselect">Contains Selector</a></h4> | ||||
@@ -1009,7 +1013,7 @@ | |||||
but the Java VM cannot detect this state, this selector will | but the Java VM cannot detect this state, this selector will | ||||
still select the file.</p> | still select the file.</p> | ||||
<h4><a name="writable">Writable Selector</a></h4> | |||||
<h4><a name="symlink">Writable Selector</a></h4> | |||||
<p>The <code><writable></code> selector selects only files | <p>The <code><writable></code> selector selects only files | ||||
that are writable. Ant only invokes | that are writable. Ant only invokes | ||||
@@ -1017,6 +1021,26 @@ | |||||
but the Java VM cannot detect this state, this selector will | but the Java VM cannot detect this state, this selector will | ||||
still select the file.</p> | still select the file.</p> | ||||
<h4><a name="executable">Executable Selector</a></h4> | |||||
<p>The <code><executable></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><symlink></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> | <h4><a name="scriptselector">Script Selector</a></h4> | ||||
<p> | <p> | ||||
@@ -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.DepthSelector; | ||||
import org.apache.tools.ant.types.selectors.DifferentSelector; | import org.apache.tools.ant.types.selectors.DifferentSelector; | ||||
import org.apache.tools.ant.types.selectors.ExtendSelector; | 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.FileSelector; | ||||
import org.apache.tools.ant.types.selectors.FilenameSelector; | import org.apache.tools.ant.types.selectors.FilenameSelector; | ||||
import org.apache.tools.ant.types.selectors.MajoritySelector; | 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.SelectorContainer; | ||||
import org.apache.tools.ant.types.selectors.SelectorScanner; | import org.apache.tools.ant.types.selectors.SelectorScanner; | ||||
import org.apache.tools.ant.types.selectors.SizeSelector; | 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.TypeSelector; | ||||
import org.apache.tools.ant.types.selectors.WritableSelector; | 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; | ||||
@@ -797,6 +799,14 @@ public abstract class AbstractFileSet extends DataType | |||||
appendSelector(w); | appendSelector(w); | ||||
} | } | ||||
public void addExecutable(ExecutableSelector e) { | |||||
appendSelector(e); | |||||
} | |||||
public void addSymlink(SymlinkSelector e) { | |||||
appendSelector(e); | |||||
} | |||||
/** | /** | ||||
* Add an arbitrary selector. | * Add an arbitrary selector. | ||||
* @param selector the <code>FileSelector</code> to add. | * @param selector the <code>FileSelector</code> to add. | ||||
@@ -312,6 +312,14 @@ public abstract class AbstractSelectorContainer extends DataType | |||||
appendSelector(w); | appendSelector(w); | ||||
} | } | ||||
public void addExecutable(ExecutableSelector e) { | |||||
appendSelector(e); | |||||
} | |||||
public void addSymlink(SymlinkSelector e) { | |||||
appendSelector(e); | |||||
} | |||||
/** | /** | ||||
* add an arbitrary selector | * add an arbitrary selector | ||||
* @param selector the selector to add | * @param selector the selector to add | ||||
@@ -315,6 +315,14 @@ public abstract class BaseSelectorContainer extends BaseSelector | |||||
appendSelector(w); | appendSelector(w); | ||||
} | } | ||||
public void addExecutable(ExecutableSelector e) { | |||||
appendSelector(e); | |||||
} | |||||
public void addSymlink(SymlinkSelector e) { | |||||
appendSelector(e); | |||||
} | |||||
/** | /** | ||||
* add an arbitrary selector | * add an arbitrary selector | ||||
* @param selector the selector to add | * @param selector the selector to add | ||||
@@ -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; | |||||
} | |||||
} |
@@ -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; | |||||
} | |||||
} |
@@ -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> |
@@ -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> |