You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2024/05/02 16:46:34 UTC
(maven-invoker-plugin) branch master updated: [MINVOKER-335] Preserve symlinks for copied files
This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 6a67708 [MINVOKER-335] Preserve symlinks for copied files
6a67708 is described below
commit 6a6770833f2df4fcb92c9869a6e2605c22d83dee
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Wed May 1 13:20:50 2024 +0200
[MINVOKER-335] Preserve symlinks for copied files
---
.../invoker.properties | 19 +++++++
src/it/MINVOKER-335-symlinks-in-source/pom.xml | 65 ++++++++++++++++++++++
.../MINVOKER-335-symlinks-in-source/setup.groovy | 34 +++++++++++
.../src/it/clone-symlinks/pom.xml | 32 +++++++++++
.../MINVOKER-335-symlinks-in-source/verify.groovy | 26 +++++++++
.../maven/plugins/invoker/AbstractInvokerMojo.java | 9 ++-
6 files changed, 183 insertions(+), 2 deletions(-)
diff --git a/src/it/MINVOKER-335-symlinks-in-source/invoker.properties b/src/it/MINVOKER-335-symlinks-in-source/invoker.properties
new file mode 100644
index 0000000..f45dd01
--- /dev/null
+++ b/src/it/MINVOKER-335-symlinks-in-source/invoker.properties
@@ -0,0 +1,19 @@
+# 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.
+
+# NOTE: Don't clean here to be able to detect test failures
+invoker.goals = initialize
diff --git a/src/it/MINVOKER-335-symlinks-in-source/pom.xml b/src/it/MINVOKER-335-symlinks-in-source/pom.xml
new file mode 100644
index 0000000..a62be04
--- /dev/null
+++ b/src/it/MINVOKER-335-symlinks-in-source/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.plugins.invoker</groupId>
+ <artifactId>clone-clean-invocation</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <description>Test to check for copping symlinks from source to target</description>
+ <url>https://issues.apache.org/jira/browse/MINVOKER-335</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-invoker-plugin</artifactId>
+ <version>@project.version@</version>
+ <configuration>
+ <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
+ <pomIncludes>
+ <pomInclude>*/pom.xml</pomInclude>
+ </pomIncludes>
+ <goals>
+ <goal>validate</goal>
+ </goals>
+ </configuration>
+ <executions>
+ <execution>
+ <id>integration-test</id>
+ <phase>initialize</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/src/it/MINVOKER-335-symlinks-in-source/setup.groovy b/src/it/MINVOKER-335-symlinks-in-source/setup.groovy
new file mode 100644
index 0000000..1d0e0fb
--- /dev/null
+++ b/src/it/MINVOKER-335-symlinks-in-source/setup.groovy
@@ -0,0 +1,34 @@
+/*
+ * 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.nio.file.Files
+import java.nio.file.Paths
+
+def projectPath = new File(basedir, 'src/it/clone-symlinks').toPath()
+
+def testDir = projectPath.resolve('testDir');
+def testFile = projectPath.resolve('test.txt')
+
+Files.createDirectory(testDir)
+Files.createFile(testFile)
+
+Files.createSymbolicLink(projectPath.resolve('testDirLink'), Paths.get('testDir'))
+Files.createSymbolicLink(projectPath.resolve('testLink.txt'), Paths.get('test.txt'))
+
+true
\ No newline at end of file
diff --git a/src/it/MINVOKER-335-symlinks-in-source/src/it/clone-symlinks/pom.xml b/src/it/MINVOKER-335-symlinks-in-source/src/it/clone-symlinks/pom.xml
new file mode 100644
index 0000000..b49b412
--- /dev/null
+++ b/src/it/MINVOKER-335-symlinks-in-source/src/it/clone-symlinks/pom.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>test</groupId>
+ <artifactId>clone-symlnks</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+</project>
diff --git a/src/it/MINVOKER-335-symlinks-in-source/verify.groovy b/src/it/MINVOKER-335-symlinks-in-source/verify.groovy
new file mode 100644
index 0000000..dee7a37
--- /dev/null
+++ b/src/it/MINVOKER-335-symlinks-in-source/verify.groovy
@@ -0,0 +1,26 @@
+/*
+ * 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.nio.file.Files
+import java.nio.file.Paths
+
+def projectPath = new File(basedir, 'target/it/clone-symlinks').toPath()
+
+assert Files.readSymbolicLink(projectPath.resolve('testDirLink')) == Paths.get('testDir')
+assert Files.readSymbolicLink(projectPath.resolve('testLink.txt')) == Paths.get('test.txt')
diff --git a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
index 3f13a13..70ca4fe 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
@@ -92,6 +92,7 @@ import org.codehaus.plexus.util.DirectoryScanner;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.InterpolationFilterReader;
+import org.codehaus.plexus.util.NioFiles;
import org.codehaus.plexus.util.ReflectionUtils;
import org.codehaus.plexus.util.cli.CommandLineException;
import org.codehaus.plexus.util.cli.CommandLineUtils;
@@ -1178,14 +1179,18 @@ public abstract class AbstractInvokerMojo extends AbstractMojo {
/*
* NOTE: Make sure the destination directory is always there (even if empty) to support POM-less ITs.
*/
- destDir.mkdirs();
+ Files.createDirectories(destDir.toPath());
// Create all the directories, including any symlinks present in source
FileUtils.mkDirs(sourceDir, scanner.getIncludedDirectories(), destDir);
for (String includedFile : scanner.getIncludedFiles()) {
File sourceFile = new File(sourceDir, includedFile);
File destFile = new File(destDir, includedFile);
- FileUtils.copyFile(sourceFile, destFile);
+ if (NioFiles.isSymbolicLink(sourceFile)) {
+ NioFiles.createSymbolicLink(destFile, NioFiles.readSymbolicLink(sourceFile));
+ } else {
+ FileUtils.copyFile(sourceFile, destFile);
+ }
// ensure clone project must be writable for additional changes
destFile.setWritable(true);