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:18:24 UTC

[maven-file-management] branch revert1 created (now c52faf9)

This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a change to branch revert1
in repository https://gitbox.apache.org/repos/asf/maven-file-management.git


      at c52faf9  Revert "MSHARED-1203 use Java 7 symbolic links (#13)"

This branch includes the following new commits:

     new c52faf9  Revert "MSHARED-1203 use Java 7 symbolic links (#13)"

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-file-management] 01/01: Revert "MSHARED-1203 use Java 7 symbolic links (#13)"

Posted by sl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch revert1
in repository https://gitbox.apache.org/repos/asf/maven-file-management.git

commit c52faf95652b69636df33f90e4030499bd8cb72f
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Tue Jun 6 20:18:13 2023 +0200

    Revert "MSHARED-1203 use Java 7 symbolic links (#13)"
    
    This reverts commit 3a1e97dcb11d3bb8754a9f1d905f6f5ebbdf3da3.
---
 .../model/fileset/util/FileSetUtilsTest.java       | 93 +++++++++++++++-------
 1 file changed, 66 insertions(+), 27 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 bf2054a..b50739e 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
@@ -18,24 +18,40 @@
  */
 package org.apache.maven.shared.model.fileset.util;
 
+/*
+ * 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.
+ */
+
 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.After;
-import org.junit.Assume;
 import org.junit.Test;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
 
 /**
  * Test the FileSet
@@ -75,17 +91,19 @@ public class FileSetUtilsTest {
         assertEquals(1, included.length);
     }
 
+    /**
+     * @throws IOException if any
+     * @throws InterruptedException if any
+     */
     @Test
-    public void testIncludesDontFollowSymlinks() throws IOException {
+    public 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.
-            Assume.assumeFalse(true);
+            return;
         }
 
         FileSet set = new FileSet();
@@ -100,17 +118,20 @@ public class FileSetUtilsTest {
         assertEquals(1, included.length);
     }
 
+    /**
+     * @throws IOException if any
+     * @throws InterruptedException if any
+     * @throws CommandLineException if any
+     */
     @Test
-    public void testDeleteDontFollowSymlinks() throws IOException {
+    public 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.
-            Assume.assumeFalse(true);
+            return;
         }
 
         FileSet set = new FileSet();
@@ -155,12 +176,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.
-            Assume.assumeFalse(true);
+        if (!createSymlink(targetFile, linkFile)) {
+            // symlinks apparently not supported, skip test
+            return;
         }
         targetFile.delete();
 
@@ -255,8 +273,11 @@ public class FileSetUtilsTest {
         assertFalse("included file has not been deleted", new File(directory, "included.txt").exists());
     }
 
+    /**
+     * @throws Exception if any
+     */
     @Test
-    public void testDeleteDontFollowSymlinksButDeleteThem() throws IOException {
+    public void testDeleteDontFollowSymlinksButDeleteThem() throws Exception {
         File directory = setupTestDirectory("testDeleteDontFollowSymlinksButDeleteThem");
 
         createSymlink(new File(directory, "excluded"), new File(directory, "dirlink"));
@@ -281,12 +302,30 @@ public class FileSetUtilsTest {
         assertFalse("included directory has not been deleted", new File(directory, "dir1").exists());
     }
 
-    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 {