This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-file-management.git
The following commit(s) were added to refs/heads/master by this push:
new 540165d [MSHARED-1203] no longer need to shell out to create a
symbolic link (#24)
540165d is described below
commit 540165da240431b70cc3a8f17e6ce969f3001018
Author: Elliotte Rusty Harold <[email protected]>
AuthorDate: Sun Jun 11 08:12:02 2023 -0400
[MSHARED-1203] no longer need to shell out to create a symbolic link (#24)
---
.../model/fileset/util/FileSetUtilsTest.java | 53 ++++++----------------
1 file changed, 14 insertions(+), 39 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 6e95211..6192df0 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,10 @@ import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLDecoder;
-import java.util.HashSet;
-import java.util.Set;
+import java.nio.file.Files;
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.Test;
import org.junit.jupiter.api.io.TempDir;
@@ -46,16 +42,6 @@ public class FileSetUtilsTest {
@TempDir
File testDirectory;
- private final Set<File> linkFiles = new HashSet<>();
-
- /** {@inheritDoc} */
- @AfterEach
- public void tearDown() throws IOException {
- for (File linkFile : linkFiles) {
- linkFile.delete();
- }
- }
-
/**
* @throws IOException if any
*/
@@ -75,13 +61,11 @@ public class FileSetUtilsTest {
}
@Test
- void testIncludesDontFollowSymlinks() throws IOException,
InterruptedException, CommandLineException {
+ void testIncludesDontFollowSymlinks() throws IOException {
File directory = setupTestDirectory("testIncludesDontFollowSymlinks");
File subdir = new File(directory, directory.getName());
- // assume failure to create a sym link is because the system does not
support them
- // and not because the sym link creation failed.
- assumeTrue(createSymlink(directory, subdir));
+ createSymlink(directory, subdir);
FileSet set = new FileSet();
set.setDirectory(directory.getPath());
@@ -96,13 +80,11 @@ public class FileSetUtilsTest {
}
@Test
- void testDeleteDontFollowSymlinks() throws IOException,
InterruptedException, CommandLineException {
+ void testDeleteDontFollowSymlinks() throws IOException {
File directory = setupTestDirectory("testDeleteDontFollowSymlinks");
File subdir = new File(directory, directory.getName());
- // assume failure to create a sym link is because the system does not
support them
- // and not because the sym link creation failed.
- assumeTrue(createSymlink(directory, subdir));
+ createSymlink(directory, subdir);
FileSet set = new FileSet();
set.setDirectory(directory.getPath());
@@ -146,9 +128,7 @@ public class FileSetUtilsTest {
File targetFile = new File(directory, "test.txt");
File linkFile = new File(directory, "symlink");
- // assume failure to create a sym link is because the system does not
support them
- // and not because the sym link creation failed.
- assumeTrue(createSymlink(targetFile, linkFile));
+ createSymlink(targetFile, linkFile);
targetFile.delete();
@@ -269,23 +249,18 @@ public class FileSetUtilsTest {
assertFalse(new File(directory, "dir1").exists(), "included directory
has not been deleted");
}
- private boolean createSymlink(File target, File link) throws
InterruptedException, CommandLineException {
-
+ private void createSymlink(File target, File link) {
if (link.exists()) {
link.delete();
}
- 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;
+ try {
+ Files.createSymbolicLink(link.toPath(), target.toPath());
+ } catch (IOException | SecurityException |
UnsupportedOperationException ex) {
+ // assume failure to create a symlink is because the system does
not support
+ // them and not because the symlink creation failed.
+ assumeTrue(false);
+ }
}
private File setupTestDirectory(String directoryName) throws IOException {