You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2023/06/06 18:17:52 UTC
[maven-file-management] 01/01: Revert "MSHARED-1203 use Java 7 symbolic links (#13)"
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch fix1
in repository https://gitbox.apache.org/repos/asf/maven-file-management.git
commit fb1f269e98af1f9b91416da41eeb4bfe3909002e
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Tue Jun 6 20:17:42 2023 +0200
Revert "MSHARED-1203 use Java 7 symbolic links (#13)"
---
.../model/fileset/util/FileSetUtilsTest.java | 57 +++++++++++++---------
1 file changed, 34 insertions(+), 23 deletions(-)
diff --git a/src/test/java/org/apache/maven/shared/model/fileset/util/FileSetUtilsTest.java b/src/test/java/org/apache/maven/shared/model/fileset/util/FileSetUtilsTest.java
index 662900f..a58bb5e 100644
--- a/src/test/java/org/apache/maven/shared/model/fileset/util/FileSetUtilsTest.java
+++ b/src/test/java/org/apache/maven/shared/model/fileset/util/FileSetUtilsTest.java
@@ -22,14 +22,14 @@ import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLDecoder;
-import java.nio.file.Files;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.io.FileUtils;
import org.apache.maven.shared.model.fileset.FileSet;
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.cli.Commandline;
import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -76,16 +76,14 @@ public class FileSetUtilsTest {
}
@Test
- void testIncludesDontFollowSymlinks() throws IOException {
+ void testIncludesDontFollowSymlinks() throws IOException, InterruptedException, CommandLineException {
File directory = setupTestDirectory("testIncludesDontFollowSymlinks");
File subdir = new File(directory, directory.getName());
- try {
- createSymlink(directory, subdir);
- } catch (UnsupportedOperationException | SecurityException ex) {
- // failed to create a sym link is because the system does not support them
+ if (!createSymlink(directory, subdir)) {
+ // assume failure to create a sym link is because the system does not support them
// and not because the sym link creation failed.
- Assumptions.assumeFalse(true);
+ return;
}
FileSet set = new FileSet();
@@ -101,16 +99,14 @@ public class FileSetUtilsTest {
}
@Test
- void testDeleteDontFollowSymlinks() throws IOException {
+ void testDeleteDontFollowSymlinks() throws IOException, InterruptedException, CommandLineException {
File directory = setupTestDirectory("testDeleteDontFollowSymlinks");
File subdir = new File(directory, directory.getName());
- try {
- createSymlink(directory, subdir);
- } catch (UnsupportedOperationException | SecurityException ex) {
- // failed to create a sym link is because the system does not support them
+ if (!createSymlink(directory, subdir)) {
+ // assume failure to create a sym link is because the system does not support them
// and not because the sym link creation failed.
- Assumptions.assumeFalse(true);
+ return;
}
FileSet set = new FileSet();
@@ -155,12 +151,9 @@ public class FileSetUtilsTest {
File targetFile = new File(directory, "test.txt");
File linkFile = new File(directory, "symlink");
- try {
- createSymlink(targetFile, linkFile);
- } catch (UnsupportedOperationException | SecurityException ex) {
- // failed to create a sym link is because the system does not support them
- // and not because the sym link creation failed.
- Assumptions.assumeFalse(true);
+ if (!createSymlink(targetFile, linkFile)) {
+ // symlinks apparently not supported, skip test
+ return;
}
targetFile.delete();
@@ -256,7 +249,7 @@ public class FileSetUtilsTest {
}
@Test
- void testDeleteDontFollowSymlinksButDeleteThem() throws IOException {
+ void testDeleteDontFollowSymlinksButDeleteThem() throws IOException, InterruptedException, CommandLineException {
File directory = setupTestDirectory("testDeleteDontFollowSymlinksButDeleteThem");
createSymlink(new File(directory, "excluded"), new File(directory, "dirlink"));
@@ -281,12 +274,30 @@ public class FileSetUtilsTest {
assertFalse(new File(directory, "dir1").exists(), "included directory has not been deleted");
}
- private void createSymlink(File target, File link) throws IOException {
+ /**
+ * @param target The target file/directory of the symlink, must not be <code>null</code>.
+ * @param link The link to create, must not be <code>null</code>.
+ * @return
+ * @throws InterruptedException
+ * @throws CommandLineException
+ */
+ private boolean createSymlink(File target, File link) throws InterruptedException, CommandLineException {
+
if (link.exists()) {
link.delete();
}
- Files.createSymbolicLink(link.toPath(), target.toPath());
+
+ Commandline cli = new Commandline();
+ cli.setExecutable("ln");
+ cli.createArg().setValue("-s");
+ cli.createArg().setValue(target.getPath());
+ cli.createArg().setValue(link.getPath());
+
+ int result = cli.execute().waitFor();
+
linkFiles.add(link);
+
+ return result == 0;
}
private File setupTestDirectory(String directoryName) throws IOException {