Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MJAR-296] Allow including files excluded by default. #67

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 58 additions & 0 deletions src/it/MJAR-296-exclude-default/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?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</groupId>
<artifactId>mjar-296-exclude-default</artifactId>
<name>mjar-296-suppress-default-excludes</name>
<description>Verifies that the resulting jar not includes files excluded by default</description>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.outputTimestamp>2023-11-19T13:25:58Z</project.build.outputTimestamp>
</properties>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>@version.maven-resources-plugin@</version>
<configuration>
<addDefaultExcludes>false</addDefaultExcludes>
michael-o marked this conversation as resolved.
Show resolved Hide resolved
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>@project.version@</version>
</plugin>
</plugins>
</build>
</project>
29 changes: 29 additions & 0 deletions src/it/MJAR-296-exclude-default/setup.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import java.nio.file.Files
import java.nio.file.Paths

/*
* 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.
*/

// excluded files are not copied by m-invoker-p - so we need create one

def resDir = basedir.toPath().resolve("src/main/resources")
Files.createDirectories(resDir)
Files.createFile(resDir.resolve(".cvsignore"))

return true
michael-o marked this conversation as resolved.
Show resolved Hide resolved
31 changes: 31 additions & 0 deletions src/it/MJAR-296-exclude-default/src/main/java/Foo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

/*
* 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.
*/

/**
* Hello world!
*
*/
public class Foo
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
28 changes: 28 additions & 0 deletions src/it/MJAR-296-exclude-default/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.jar.*;

def target = new File(basedir, "target")
def artifact = new File(target, "mjar-296-exclude-default-1.0-SNAPSHOT.jar")

assert artifact.exists()

def jar = new JarFile(artifact)
assert ".cvsignore" !in jar.entries()*.name
61 changes: 61 additions & 0 deletions src/it/MJAR-296-suppress-default-excludes/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?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</groupId>
<artifactId>mjar-296-suppress-default-excludes</artifactId>
<name>mjar-296-suppress-default-excludes</name>
<description>Verifies that the resulting jar includes files excluded by default</description>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.outputTimestamp>2023-11-19T13:25:58Z</project.build.outputTimestamp>
</properties>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>@version.maven-resources-plugin@</version>
<configuration>
<addDefaultExcludes>false</addDefaultExcludes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<addDefaultExcludes>false</addDefaultExcludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
29 changes: 29 additions & 0 deletions src/it/MJAR-296-suppress-default-excludes/setup.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths

/*
* 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.
*/

// excluded files are not copied by m-invoker-p - so we need create one
def resDir = basedir.toPath().resolve("src/main/resources")
Files.createDirectories(resDir)
Files.createFile(resDir.resolve(".cvsignore"))

return true
31 changes: 31 additions & 0 deletions src/it/MJAR-296-suppress-default-excludes/src/main/java/Foo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

/*
* 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.
*/

/**
* Hello world!
*
*/
public class Foo
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
30 changes: 30 additions & 0 deletions src/it/MJAR-296-suppress-default-excludes/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.jar.*;

def target = new File(basedir, "target")
def artifact = new File(target, "mjar-296-suppress-default-excludes-1.0-SNAPSHOT.jar")

assert artifact.exists()

def jar = new JarFile(artifact)
assert ".cvsignore" in jar.entries()*.name


45 changes: 44 additions & 1 deletion src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.maven.toolchain.ToolchainManager;
import org.codehaus.plexus.archiver.Archiver;
import org.codehaus.plexus.archiver.jar.JarArchiver;
import org.codehaus.plexus.archiver.util.DefaultFileSet;

/**
* Base class for creating a jar from project classes.
Expand Down Expand Up @@ -169,6 +170,38 @@ public abstract class AbstractJarMojo extends AbstractMojo {
@Parameter(property = "maven.jar.detectMultiReleaseJar", defaultValue = "true")
private boolean detectMultiReleaseJar;

/**
* If set to {@code false}, the files that by default are excluded from the resulting archive,
slawekjaranowski marked this conversation as resolved.
Show resolved Hide resolved
* like {@code .gitignore}, {@code .cvsignore} etc. will be included.
* This means all files like the following will be included.
* <ul>
* <li>Misc: &#42;&#42;/&#42;~, &#42;&#42;/#&#42;#, &#42;&#42;/.#&#42;, &#42;&#42;/%&#42;%, &#42;&#42;/._&#42;</li>
* <li>CVS: &#42;&#42;/CVS, &#42;&#42;/CVS/&#42;&#42;, &#42;&#42;/.cvsignore</li>
* <li>RCS: &#42;&#42;/RCS, &#42;&#42;/RCS/&#42;&#42;</li>
* <li>SCCS: &#42;&#42;/SCCS, &#42;&#42;/SCCS/&#42;&#42;</li>
* <li>VSSercer: &#42;&#42;/vssver.scc</li>
* <li>MKS: &#42;&#42;/project.pj</li>
* <li>SVN: &#42;&#42;/.svn, &#42;&#42;/.svn/&#42;&#42;</li>
* <li>GNU: &#42;&#42;/.arch-ids, &#42;&#42;/.arch-ids/&#42;&#42;</li>
* <li>Bazaar: &#42;&#42;/.bzr, &#42;&#42;/.bzr/&#42;&#42;</li>
* <li>SurroundSCM: &#42;&#42;/.MySCMServerInfo</li>
* <li>Mac: &#42;&#42;/.DS_Store</li>
* <li>Serena Dimension: &#42;&#42;/.metadata, &#42;&#42;/.metadata/&#42;&#42;</li>
* <li>Mercurial: &#42;&#42;/.hg, &#42;&#42;/.hg/&#42;&#42;</li>
* <li>Git: &#42;&#42;/.git, &#42;&#42;/.git/&#42;&#42;</li>
* <li>Bitkeeper: &#42;&#42;/BitKeeper, &#42;&#42;/BitKeeper/&#42;&#42;, &#42;&#42;/ChangeSet,
* &#42;&#42;/ChangeSet/&#42;&#42;</li>
* <li>Darcs: &#42;&#42;/_darcs, &#42;&#42;/_darcs/&#42;&#42;, &#42;&#42;/.darcsrepo,
* &#42;&#42;/.darcsrepo/&#42;&#42;&#42;&#42;/-darcs-backup&#42;, &#42;&#42;/.darcs-temp-mail
* </ul>
*
* @see <a
* href="https://github.com/codehaus-plexus/plexus-utils/blob/master/src/main/java/org/codehaus/plexus/util/AbstractScanner.java">DEFAULTEXCLUDES</a>
* @since 3.4.0
*/
@Parameter(defaultValue = "true")
private boolean addDefaultExcludes;

/**
* Return the specific output directory to serve as the root for the archive.
* @return get classes directory.
Expand Down Expand Up @@ -281,7 +314,7 @@ public File createArchive() throws MojoExecutionException {
getLog().warn("JAR will be empty - no content was marked for inclusion!");
}
} else {
archiver.getArchiver().addDirectory(contentDirectory, getIncludes(), getExcludes());
archiver.getArchiver().addFileSet(getFileSet(contentDirectory));
slawekjaranowski marked this conversation as resolved.
Show resolved Hide resolved
slawekjaranowski marked this conversation as resolved.
Show resolved Hide resolved
}

archiver.createArchive(session, project, archive);
Expand Down Expand Up @@ -353,4 +386,14 @@ private String[] getExcludes() {
}
return DEFAULT_EXCLUDES;
}

private org.codehaus.plexus.archiver.FileSet getFileSet(File contentDirectory) {
DefaultFileSet fileSet = DefaultFileSet.fileSet(contentDirectory)
.prefixed("")
.includeExclude(getIncludes(), getExcludes())
.includeEmptyDirs(true);

fileSet.setUsingDefaultExcludes(addDefaultExcludes);
return fileSet;
}
}