Skip to content

Commit

Permalink
[MINVOKER-335] Preserve symlinks for copied files
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed May 2, 2024
1 parent f121de5 commit 6a67708
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/it/MINVOKER-335-symlinks-in-source/invoker.properties
Original file line number Diff line number Diff line change
@@ -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
65 changes: 65 additions & 0 deletions src/it/MINVOKER-335-symlinks-in-source/pom.xml
Original file line number Diff line number Diff line change
@@ -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>
34 changes: 34 additions & 0 deletions src/it/MINVOKER-335-symlinks-in-source/setup.groovy
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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>
26 changes: 26 additions & 0 deletions src/it/MINVOKER-335-symlinks-in-source/verify.groovy
Original file line number Diff line number Diff line change
@@ -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')
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
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;
Expand Down Expand Up @@ -1178,14 +1179,18 @@ private void copyDirectoryStructure(File sourceDir, File destDir) throws IOExcep
/*
* 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);
Expand Down

0 comments on commit 6a67708

Please sign in to comment.