Skip to content

Commit

Permalink
Improve implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Apr 8, 2024
1 parent b949abe commit bd967a2
Show file tree
Hide file tree
Showing 11 changed files with 219 additions and 61 deletions.
57 changes: 57 additions & 0 deletions src/it/MJAR-296-exclude-default/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?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>
<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>
</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
File renamed without changes.
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@
</properties>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<addDefaultExcludes>false</addDefaultExcludes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
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


1 change: 0 additions & 1 deletion src/it/MJAR-296/src/main/resources/.gitignore

This file was deleted.

58 changes: 0 additions & 58 deletions src/it/MJAR-296/verify.groovy

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ public abstract class AbstractJarMojo extends AbstractMojo {
* &#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")
Expand Down Expand Up @@ -261,7 +263,6 @@ public File createArchive() throws MojoExecutionException {
jarContentFileSet.setDirectory(getClassesDirectory().getAbsolutePath());
jarContentFileSet.setIncludes(Arrays.asList(getIncludes()));
jarContentFileSet.setExcludes(Arrays.asList(getExcludes()));
jarContentFileSet.setUseDefaultExcludes(addDefaultExcludes);

String[] includedFiles = fileSetManager.getIncludedFiles(jarContentFileSet);

Expand Down Expand Up @@ -388,10 +389,11 @@ private String[] getExcludes() {

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

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

0 comments on commit bd967a2

Please sign in to comment.