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 2026/02/08 07:29:14 UTC
(ant) 02/02: some more tweaks
This is an automated email from the ASF dual-hosted git repository.
bodewig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git
commit 085e47148ed12704d762f40d2bbd1a9f5951606f
Author: Stefan Bodewig <bo...@apache.org>
AuthorDate: Sun Feb 8 08:28:52 2026 +0100
some more tweaks
---
src/main/org/apache/tools/ant/taskdefs/Delete.java | 4 +-
src/main/org/apache/tools/ant/util/FileUtils.java | 8 ++--
.../antunit/taskdefs/delete-and-symlinks-test.xml | 48 ++++++++++++++++++----
src/tests/antunit/taskdefs/delete-test.xml | 28 -------------
.../org/apache/tools/ant/DirectoryScannerTest.java | 5 ++-
5 files changed, 48 insertions(+), 45 deletions(-)
diff --git a/src/main/org/apache/tools/ant/taskdefs/Delete.java b/src/main/org/apache/tools/ant/taskdefs/Delete.java
index fe7c01c71..e5b01e91e 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Delete.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Delete.java
@@ -379,9 +379,9 @@ public class Delete extends MatchingTask {
}
/**
- * Sets whether or not symbolic links should be followed.
+ * Sets whether or not symbolic links or Windows junctions should be followed.
*
- * @param followSymlinks whether or not symbolic links should be followed
+ * @param followSymlinks whether or not symbolic links or Windows junctions should be followed
*/
@Override
public void setFollowSymlinks(boolean followSymlinks) {
diff --git a/src/main/org/apache/tools/ant/util/FileUtils.java b/src/main/org/apache/tools/ant/util/FileUtils.java
index 250b6a323..dbc974980 100644
--- a/src/main/org/apache/tools/ant/util/FileUtils.java
+++ b/src/main/org/apache/tools/ant/util/FileUtils.java
@@ -757,7 +757,7 @@ public class FileUtils {
* \ as the separator.</li>
* </ul>
* <p>Unlike {@link File#getCanonicalPath()} this method
- * specifically does not resolve symbolic links.</p>
+ * specifically does not resolve symbolic links or Windows junctions.</p>
*
* <p>If the path tries to go beyond the file system root (i.e. it
* contains more ".." segments than can be travelled up) the
@@ -1253,7 +1253,7 @@ public class FileUtils {
* Removes a leading path from a second path.
*
* <p>This method uses {@link #normalize} under the covers and
- * does not resolve symbolic links.</p>
+ * does not resolve symbolic links or Windows junctions.</p>
*
* @param leading The leading path, must not be null, must be absolute.
* @param path The path to remove from, must not be null, must be absolute.
@@ -1281,7 +1281,7 @@ public class FileUtils {
* Learn whether one path "leads" another.
*
* <p>This method uses {@link #normalize} under the covers and
- * does not resolve symbolic links.</p>
+ * does not resolve symbolic links or Windows junctions.</p>
*
* <p>If either path tries to go beyond the file system root
* (i.e. it contains more ".." segments than can be travelled up)
@@ -1316,7 +1316,7 @@ public class FileUtils {
*
* @param leading The leading path, must not be null, must be absolute.
* @param path The path to check, must not be null, must be absolute.
- * @param resolveSymlinks whether symbolic links shall be resolved
+ * @param resolveSymlinks whether symbolic links or Windows junctions shall be resolved
* prior to comparing the paths.
* @return true if path starts with leading; false otherwise.
* @since Ant 1.10.5
diff --git a/src/tests/antunit/taskdefs/delete-and-symlinks-test.xml b/src/tests/antunit/taskdefs/delete-and-symlinks-test.xml
index fbe94ac74..0e8e61cb2 100644
--- a/src/tests/antunit/taskdefs/delete-and-symlinks-test.xml
+++ b/src/tests/antunit/taskdefs/delete-and-symlinks-test.xml
@@ -21,9 +21,7 @@
<import file="../antunit-base.xml" />
- <condition property="unix">
- <os family="unix" />
- </condition>
+ <condition property="canCreateSymlink"><canCreateSymlink/></condition>
<target name="tearDown" depends="removelink, antunit-base.tearDown"/>
@@ -31,21 +29,21 @@
<delete link="${link}"/>
</target>
- <target name="setUp" if="unix">
+ <target name="setUp" if="canCreateSymlink">
<mkdir dir="${input}/A/B"/>
<mkdir dir="${input}/C"/>
<property name="link" location="${input}/A/B/C"/>
<symlink link="${link}" resource="${input}/C"/>
</target>
- <target name="testNotFollowedLink" if="unix" depends="setUp">
+ <target name="testNotFollowedLink" if="canCreateSymlink" depends="setUp">
<delete>
<fileset dir="${input}" followSymlinks="false"/>
</delete>
<au:assertFileExists file="${input}/A/B/C"/>
</target>
- <target name="testRemoveNotFollowedLink" if="unix" depends="setUp">
+ <target name="testRemoveNotFollowedLink" if="canCreateSymlink" depends="setUp">
<delete removeNotFollowedSymlinks="true">
<fileset dir="${input}/A" followSymlinks="false"/>
</delete>
@@ -54,7 +52,7 @@
</target>
<target name="testRemoveNotFollowedLinkHonorsIncludesOnFiles"
- depends="setUp" if="unix"
+ depends="setUp" if="canCreateSymlink"
description="https://issues.apache.org/bugzilla/show_bug.cgi?id=53959">
<delete dir="${input}/C"/>
<touch file="${input}/C"/>
@@ -65,7 +63,7 @@
</target>
<target name="testRemoveNotFollowedLinkDeletesNotIncludedDirs"
- depends="setUp" if="unix"
+ depends="setUp" if="canCreateSymlink"
description="https://issues.apache.org/bugzilla/show_bug.cgi?id=53959">
<delete removeNotFollowedSymlinks="true">
<fileset dir="${input}/A" followSymlinks="false" includes="**/D"/>
@@ -74,11 +72,43 @@
<au:assertFileExists file="${input}/C"/>
</target>
- <target name="testRemoveNotFollowedLinkHonorsExcludes" if="unix"
+ <target name="testRemoveNotFollowedLinkHonorsExcludes" if="canCreateSymlink"
depends="setUp">
<delete removeNotFollowedSymlinks="true">
<fileset dir="${input}/A" followSymlinks="false" excludes="**/C/**"/>
</delete>
<au:assertFileExists file="${input}/A/B/C"/>
</target>
+
+ <target name="prepare-dangling-tests">
+ <property name="existing.dir" location="${output}/exists"/>
+ <delete dir="${output}"/>
+ <mkdir dir="${output}"/>
+ <mkdir dir="${existing.dir}"/>
+ </target>
+
+ <target name="testDanglingSymlinkInDir" if="canCreateSymlink"
+ depends="prepare-dangling-tests">
+ <touch file="${output}/foo"/>
+ <symlink link="${existing.dir}/link"
+ resource="${output}/foo"/>
+ <delete file="${output}/foo"/>
+ <delete dir="${existing.dir}"/>
+ <au:assertFileDoesntExist file="${existing.dir}" />
+ </target>
+
+ <target name="testDanglingSymlink" if="canCreateSymlink"
+ depends="prepare-dangling-tests">
+ <touch file="${output}/foo"/>
+ <symlink link="${output}/link"
+ resource="${output}/foo"/>
+ <delete file="${output}/foo"/>
+ <delete file="${output}/link"/>
+
+ <!-- since File.exists returns false for dangling links, recreate
+ the file so that assertFileDoesntExist can actually work -->
+ <touch file="${output}/foo"/>
+ <au:assertFileDoesntExist file="${output}/link" />
+ </target>
+
</project>
diff --git a/src/tests/antunit/taskdefs/delete-test.xml b/src/tests/antunit/taskdefs/delete-test.xml
index 9229261b6..25a27f313 100644
--- a/src/tests/antunit/taskdefs/delete-test.xml
+++ b/src/tests/antunit/taskdefs/delete-test.xml
@@ -67,34 +67,6 @@
</target>
- <target name="checkCanCreateSymlink">
- <condition property="canCreateSymlink"><canCreateSymlink/></condition>
- </target>
-
- <target name="testDanglingSymlinkInDir" if="canCreateSymlink"
- depends="checkCanCreateSymlink,init">
- <touch file="${output}/foo"/>
- <symlink link="${existing.dir}/link"
- resource="${output}/foo"/>
- <delete file="${output}/foo"/>
- <delete dir="${existing.dir}"/>
- <au:assertFileDoesntExist file="${existing.dir}" />
- </target>
-
- <target name="testDanglingSymlink" if="canCreateSymlink"
- depends="checkCanCreateSymlink,init">
- <touch file="${output}/foo"/>
- <symlink link="${output}/link"
- resource="${output}/foo"/>
- <delete file="${output}/foo"/>
- <delete file="${output}/link"/>
-
- <!-- since File.exists returns false for dangling links, recreate
- the file so that assertFileDoesntExist can actually work -->
- <touch file="${output}/foo"/>
- <au:assertFileDoesntExist file="${output}/link" />
- </target>
-
<target name="testNotModifiedSelector"
description="https://issues.apache.org/bugzilla/show_bug.cgi?id=43574"
>
diff --git a/src/tests/junit/org/apache/tools/ant/DirectoryScannerTest.java b/src/tests/junit/org/apache/tools/ant/DirectoryScannerTest.java
index 6d38129ec..f16c52f9b 100644
--- a/src/tests/junit/org/apache/tools/ant/DirectoryScannerTest.java
+++ b/src/tests/junit/org/apache/tools/ant/DirectoryScannerTest.java
@@ -35,6 +35,7 @@ import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
+import org.apache.tools.ant.taskdefs.condition.CanCreateSymbolicLink;
import org.apache.tools.ant.taskdefs.condition.Os;
import org.apache.tools.ant.types.selectors.TokenizedPath;
import org.junit.Before;
@@ -50,8 +51,8 @@ public class DirectoryScannerTest {
@Rule
public BuildFileRule buildRule = new BuildFileRule();
- // keep track of what operating systems are supported here.
- private boolean supportsSymlinks = Os.isFamily("unix");
+ // keep track of what systems are supported here.
+ private boolean supportsSymlinks = new CanCreateSymbolicLink().eval();
private DirectoryScanner ds;