Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ under the License.
<mavenPluginPluginVersion>4.0.0-beta-2</mavenPluginPluginVersion>
<mavenPluginTestingVersion>4.0.0-beta-4</mavenPluginTestingVersion>
<mockitoVersion>5.23.0</mockitoVersion>
<plexusArchiverVersion>4.13.0</plexusArchiverVersion>
<plexusArchiverVersion>4.14.0</plexusArchiverVersion>
<version.maven-plugin-tools>${mavenPluginPluginVersion}</version.maven-plugin-tools>
<project.build.outputTimestamp>2024-06-26T08:31:50Z</project.build.outputTimestamp>
</properties>
Expand Down
19 changes: 19 additions & 0 deletions src/it/jar-follow-symlinks/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.

# Creating a symbolic link needs privileges that are not granted by default on Windows.
invoker.os.family = !windows
59 changes: 59 additions & 0 deletions src/it/jar-follow-symlinks/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?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.its.source</groupId>
<artifactId>jar-follow-symlinks</artifactId>
<version>1.0-SNAPSHOT</version>

<name>Test for followSymlinks</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<followSymlinks>true</followSymlinks>
</configuration>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
29 changes: 29 additions & 0 deletions src/it/jar-follow-symlinks/setup.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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

// A source directory that is a symbolic link to a tree kept outside src/main/java.
File link = new File(basedir, 'src/main/java/shared')
if (Files.isSymbolicLink(link.toPath())) {
Files.delete(link.toPath())
}
Files.createSymbolicLink(link.toPath(), new File(basedir, 'shared-sources/shared').toPath())

return true
22 changes: 22 additions & 0 deletions src/it/jar-follow-symlinks/shared-sources/shared/Shared.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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.
*/

package shared;

public class Shared {}
20 changes: 20 additions & 0 deletions src/it/jar-follow-symlinks/src/main/java/MyClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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.
*/

public class MyClass {}
34 changes: 34 additions & 0 deletions src/it/jar-follow-symlinks/verify.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.util.zip.ZipFile

File jar = new File(basedir, 'target/jar-follow-symlinks-1.0-SNAPSHOT-sources.jar')
assert jar.isFile() : "Missing sources jar $jar"

new ZipFile(jar).withCloseable { zip ->
def entry = zip.getEntry('shared/Shared.java')
assert entry != null : "shared/Shared.java is missing; entries were ${zip.entries().collect { it.name }}"

// The link was resolved, so the entry carries the target's source rather than a link path.
def text = zip.getInputStream(entry).text
assert text.contains('class Shared') : "shared/Shared.java holds $text"
}

return true
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ public abstract class AbstractSourceJarMojo implements Mojo {
@Parameter(property = "maven.source.useDefaultExcludes", defaultValue = "true")
protected boolean useDefaultExcludes;

/**
* Whether to follow symbolic links below the source directories. When false, a symbolic link is archived as a
* link, which points nowhere once the jar is unpacked somewhere else; when true, a link is archived as the file
* or directory it points at, and a linked directory's contents are included.
*
* @since 3.5.0
*/
@Parameter(property = "maven.source.followSymlinks", defaultValue = "false")
private boolean followSymlinks;

/**
* The Maven Project Object
*/
Expand Down Expand Up @@ -450,7 +460,9 @@ protected void addDirectory(Archiver archiver, Path sourceDirectory, String[] pI
throws MojoException {
try {
getLog().debug("add directory " + sourceDirectory + " to archiver");
archiver.addFileSet(DefaultFileSet.fileSet(sourceDirectory.toFile()).includeExclude(pIncludes, pExcludes));
archiver.addFileSet(DefaultFileSet.fileSet(sourceDirectory.toFile())
.includeExclude(pIncludes, pExcludes)
.followingSymLinks(followSymlinks));
} catch (ArchiverException e) {
throw new MojoException("Error adding directory to source archive.", e);
}
Expand All @@ -471,7 +483,8 @@ protected void addDirectory(
getLog().debug("add directory " + sourceDirectory + " to archiver with prefix " + prefix);
archiver.addFileSet(DefaultFileSet.fileSet(sourceDirectory.toFile())
.prefixed(prefix)
.includeExclude(pIncludes, pExcludes));
.includeExclude(pIncludes, pExcludes)
.followingSymLinks(followSymlinks));
} catch (ArchiverException e) {
throw new MojoException("Error adding directory to source archive.", e);
}
Expand Down
Loading