This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-jar-plugin.git

commit 50be4b50eb502ed21ebb1752e40ec31916cb6435
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Wed Nov 4 18:19:05 2026 +0000

    Test forceCreation and addDefaultExcludes in unit tests
    
    MJAR-70-recreation passed even when the jar was not rewritten, and the
    MJAR-296 ITs asserted .cvsignore, which plexus-utils 4.1.0 no longer 
excludes
    by default. MJAR-62-toolchain is dropped as a copy of github-470.
---
 src/it/MJAR-296-exclude-default/pom.xml            |  58 --------
 src/it/MJAR-296-exclude-default/setup.groovy       |  32 -----
 .../src/main/java/Foo.java                         |  31 -----
 src/it/MJAR-296-exclude-default/verify.groovy      |  34 -----
 src/it/MJAR-296-suppress-default-excludes/pom.xml  |  61 ---------
 .../setup.groovy                                   |  32 -----
 .../src/main/java/Foo.java                         |  31 -----
 .../verify.groovy                                  |  33 -----
 src/it/MJAR-62-toolchain/invoker.properties        |  18 ---
 src/it/MJAR-62-toolchain/pom.xml                   |  60 ---------
 .../src/main/java/myproject/HelloWorld.java        |  36 -----
 src/it/MJAR-62-toolchain/verify.groovy             |  26 ----
 src/it/MJAR-70-recreation/invoker.properties       |  20 ---
 src/it/MJAR-70-recreation/pom.xml                  |  68 ----------
 .../src/main/java/myproject/HelloWorld.java        |  36 -----
 src/it/MJAR-70-recreation/verify.groovy            |  95 -------------
 .../maven/plugins/jar/JarDefaultExcludesTest.java  | 132 ++++++++++++++++++
 .../maven/plugins/jar/JarRecreationTest.java       | 148 +++++++++++++++++++++
 18 files changed, 280 insertions(+), 671 deletions(-)

diff --git a/src/it/MJAR-296-exclude-default/pom.xml 
b/src/it/MJAR-296-exclude-default/pom.xml
deleted file mode 100644
index 8aeb7e9..0000000
--- a/src/it/MJAR-296-exclude-default/pom.xml
+++ /dev/null
@@ -1,58 +0,0 @@
-<?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-exclude-default</name>
-  <description>Verifies that .cvsignore is included by default since 
plexus-utils 4.1.0 removed it from the default excludes</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>
-      </plugin>
-    </plugins>
-  </build>
-</project>
diff --git a/src/it/MJAR-296-exclude-default/setup.groovy 
b/src/it/MJAR-296-exclude-default/setup.groovy
deleted file mode 100644
index 03f3e36..0000000
--- a/src/it/MJAR-296-exclude-default/setup.groovy
+++ /dev/null
@@ -1,32 +0,0 @@
-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)
-def cvsignore = resDir.resolve(".cvsignore")
-if (!Files.exists(cvsignore)) {
-    Files.createFile(cvsignore)
-}
-
-return true
diff --git a/src/it/MJAR-296-exclude-default/src/main/java/Foo.java 
b/src/it/MJAR-296-exclude-default/src/main/java/Foo.java
deleted file mode 100644
index f939fa6..0000000
--- a/src/it/MJAR-296-exclude-default/src/main/java/Foo.java
+++ /dev/null
@@ -1,31 +0,0 @@
-
-/*
- * 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!" );
-    }
-}
diff --git a/src/it/MJAR-296-exclude-default/verify.groovy 
b/src/it/MJAR-296-exclude-default/verify.groovy
deleted file mode 100644
index 1ebc299..0000000
--- a/src/it/MJAR-296-exclude-default/verify.groovy
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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 cvsignore = new File(target, "classes/.cvsignore")
-assert cvsignore.exists()
-
-def artifact = new File(target, "mjar-296-exclude-default-1.0-SNAPSHOT.jar")
-assert artifact.exists()
-
-// Since plexus-utils 4.1.0, .cvsignore is no longer in the default excludes of
-// DirectoryScanner. As a result, maven-jar-plugin's default behaviour 
(addDefaultExcludes=true)
-// no longer excludes .cvsignore from the jar.
-def jar = new JarFile(artifact)
-assert ".cvsignore" in jar.entries()*.name
diff --git a/src/it/MJAR-296-suppress-default-excludes/pom.xml 
b/src/it/MJAR-296-suppress-default-excludes/pom.xml
deleted file mode 100644
index 9ff5b45..0000000
--- a/src/it/MJAR-296-suppress-default-excludes/pom.xml
+++ /dev/null
@@ -1,61 +0,0 @@
-<?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>
diff --git a/src/it/MJAR-296-suppress-default-excludes/setup.groovy 
b/src/it/MJAR-296-suppress-default-excludes/setup.groovy
deleted file mode 100644
index 52366d3..0000000
--- a/src/it/MJAR-296-suppress-default-excludes/setup.groovy
+++ /dev/null
@@ -1,32 +0,0 @@
-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)
-def cvsignore = resDir.resolve(".cvsignore")
-if (!Files.exists(cvsignore)) {
-    Files.createFile(cvsignore)
-}
-
-return true
diff --git a/src/it/MJAR-296-suppress-default-excludes/src/main/java/Foo.java 
b/src/it/MJAR-296-suppress-default-excludes/src/main/java/Foo.java
deleted file mode 100644
index f939fa6..0000000
--- a/src/it/MJAR-296-suppress-default-excludes/src/main/java/Foo.java
+++ /dev/null
@@ -1,31 +0,0 @@
-
-/*
- * 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!" );
-    }
-}
diff --git a/src/it/MJAR-296-suppress-default-excludes/verify.groovy 
b/src/it/MJAR-296-suppress-default-excludes/verify.groovy
deleted file mode 100644
index 806c90e..0000000
--- a/src/it/MJAR-296-suppress-default-excludes/verify.groovy
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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 cvsignore = new File(target, "classes/.cvsignore")
-assert cvsignore.exists()
-
-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
-
-
diff --git a/src/it/MJAR-62-toolchain/invoker.properties 
b/src/it/MJAR-62-toolchain/invoker.properties
deleted file mode 100644
index 75c1c4b..0000000
--- a/src/it/MJAR-62-toolchain/invoker.properties
+++ /dev/null
@@ -1,18 +0,0 @@
-# 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.
-
-invoker.toolchain.jdk.version = [17,18)
\ No newline at end of file
diff --git a/src/it/MJAR-62-toolchain/pom.xml b/src/it/MJAR-62-toolchain/pom.xml
deleted file mode 100644
index 1320747..0000000
--- a/src/it/MJAR-62-toolchain/pom.xml
+++ /dev/null
@@ -1,60 +0,0 @@
-<?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-62</artifactId>
-  <name>MJAR-62</name>
-  <packaging>jar</packaging>
-  <version>1.0-SNAPSHOT</version>
-  <organization>
-    <name>jar plugin it</name>
-  </organization>
-
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-toolchains-plugin</artifactId>
-        <version>@version.maven-toolchains-plugin@</version>
-        <executions>
-          <execution>
-            <goals>
-              <goal>toolchain</goal>
-            </goals>
-          </execution>
-        </executions>
-        <configuration>
-          <toolchains>
-            <jdk>
-              <version>[17,18)</version>
-            </jdk>
-          </toolchains>
-        </configuration>
-      </plugin>
-
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-jar-plugin</artifactId>
-        <version>@project.version@</version>
-      </plugin>
-    </plugins>
-  </build>
-</project>
diff --git a/src/it/MJAR-62-toolchain/src/main/java/myproject/HelloWorld.java 
b/src/it/MJAR-62-toolchain/src/main/java/myproject/HelloWorld.java
deleted file mode 100644
index fd0ad83..0000000
--- a/src/it/MJAR-62-toolchain/src/main/java/myproject/HelloWorld.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package myproject;
-
-/*
- * 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.
- */
-
-/**
- * The classic Hello World App.
- */
-public class HelloWorld {
-
-  /**
-     * Main method.
-     *
-     * @param args Not used
-     */
-    public static void main( String[] args )
-    {
-        System.out.println( "Hi!" );
-    } 
-}
\ No newline at end of file
diff --git a/src/it/MJAR-62-toolchain/verify.groovy 
b/src/it/MJAR-62-toolchain/verify.groovy
deleted file mode 100644
index 4fdf714..0000000
--- a/src/it/MJAR-62-toolchain/verify.groovy
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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.JarFile
-
-def mrjar = new JarFile(new File(basedir, 'target/mjar-62-1.0-SNAPSHOT.jar'))
-def manifest = mrjar.manifest.mainAttributes
-
-assert manifest.getValue("Build-Jdk-Spec") == "17"
-assert manifest.getValue("Build-Tool-Jdk-Spec") == 
System.getProperty("java.specification.version")
diff --git a/src/it/MJAR-70-recreation/invoker.properties 
b/src/it/MJAR-70-recreation/invoker.properties
deleted file mode 100644
index 7036df7..0000000
--- a/src/it/MJAR-70-recreation/invoker.properties
+++ /dev/null
@@ -1,20 +0,0 @@
-# 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: The first time, we run up to "integration-test" phase which includes 
the AntRun execution which saves the
-# timestamp of the first JAR for comparision with the timestamp of the JAR 
from the final "package" invocation.
-invoker.goals = clean integration-test package
diff --git a/src/it/MJAR-70-recreation/pom.xml 
b/src/it/MJAR-70-recreation/pom.xml
deleted file mode 100644
index 8c5c51d..0000000
--- a/src/it/MJAR-70-recreation/pom.xml
+++ /dev/null
@@ -1,68 +0,0 @@
-<?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-70-recreation</artifactId>
-  <name>MJAR-70-recreation</name>
-  <packaging>jar</packaging>
-  <version>1.0-SNAPSHOT</version>
-
-  <properties>
-    
<project.build.outputTimestamp>1980-02-01T00:00:00Z</project.build.outputTimestamp>
-  </properties>
-
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-jar-plugin</artifactId>
-        <version>@project.version@</version>
-        <configuration>
-          <forceCreation>true</forceCreation>
-        </configuration>
-      </plugin>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-antrun-plugin</artifactId>
-        <version>@version.maven-antrun-plugin@</version>
-        <executions>
-          <execution>
-            <id>touch</id>
-            <phase>integration-test</phase>
-            <goals>
-              <goal>run</goal>
-            </goals>
-            <configuration>
-              <target>
-                <!-- Save the JAR and especially its timestamp for evaluation 
by the post-build hook script -->
-                <copy file="target/MJAR-70-recreation-1.0-SNAPSHOT.jar"
-                      tofile="target/reference.jar"
-                      preservelastmodified="true" overwrite="true"/>
-                <!-- Enforce some time difference prior to building JAR again 
-->
-                <sleep seconds="2"/>
-              </target>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
-    </plugins>
-  </build>
-</project>
diff --git a/src/it/MJAR-70-recreation/src/main/java/myproject/HelloWorld.java 
b/src/it/MJAR-70-recreation/src/main/java/myproject/HelloWorld.java
deleted file mode 100644
index fd0ad83..0000000
--- a/src/it/MJAR-70-recreation/src/main/java/myproject/HelloWorld.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package myproject;
-
-/*
- * 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.
- */
-
-/**
- * The classic Hello World App.
- */
-public class HelloWorld {
-
-  /**
-     * Main method.
-     *
-     * @param args Not used
-     */
-    public static void main( String[] args )
-    {
-        System.out.println( "Hi!" );
-    } 
-}
\ No newline at end of file
diff --git a/src/it/MJAR-70-recreation/verify.groovy 
b/src/it/MJAR-70-recreation/verify.groovy
deleted file mode 100644
index 29b80ca..0000000
--- a/src/it/MJAR-70-recreation/verify.groovy
+++ /dev/null
@@ -1,95 +0,0 @@
-
-/*
- * 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.io.*;
-import java.util.*;
-import java.util.jar.*;
-
-File target = new File( basedir, "target" );
-if ( !target.isDirectory() )
-{
-    throw new IOException( "target file is missing or not a directory: " + 
target );
-}
-
-File jarFile = new File( target, "MJAR-70-recreation-1.0-SNAPSHOT.jar" );
-if ( !jarFile.isFile() )
-{
-    throw new IOException( "artifact file is missing or a directory: " + 
jarFile );
-}
-
-File refFile = new File( target, "reference.jar" );
-if ( !refFile.isFile() )
-{
-    throw new IOException( "reference file is missing or a directory: " + 
refFile );
-}
-
-// Read the build log to verify that the JAR plugin actually executed
-File buildLog = new File( basedir, "build.log" );
-String buildLogContent = "";
-if ( buildLog.exists() ) {
-    BufferedReader reader = new BufferedReader( new FileReader( buildLog ) );
-    StringBuilder sb = new StringBuilder();
-    String line;
-    while ( ( line = reader.readLine() ) != null ) {
-        sb.append( line ).append( "\n" );
-    }
-    reader.close();
-    buildLogContent = sb.toString();
-}
-
-// Count how many times the JAR plugin executed
-int jarPluginExecutions = 0;
-String[] lines = buildLogContent.split( "\n" );
-for ( String line : lines ) {
-    if ( line.contains( "Building jar:" ) && line.contains( 
"MJAR-70-recreation-1.0-SNAPSHOT.jar" ) ) {
-        jarPluginExecutions++;
-        System.out.println( "Found JAR creation: " + line );
-    }
-}
-
-System.out.println( "JAR plugin executions found: " + jarPluginExecutions );
-
-// With forceCreation=true, the JAR should be built twice:
-// 1. During the first package phase
-// 2. During the second package phase (even though nothing changed)
-if ( jarPluginExecutions < 2 ) {
-    throw new Exception( "Expected at least 2 JAR plugin executions with 
forceCreation=true, but found: " + jarPluginExecutions );
-}
-
-// Also check file timestamps as additional verification
-long referenceTimestamp = refFile.lastModified();
-long actualTimestamp = jarFile.lastModified();
-
-System.out.println( "Reference timestamp: " + referenceTimestamp );
-System.out.println( "Actual timestamp   : " + actualTimestamp );
-
-// With forceCreation=true, the second build should create a new JAR file
-// even if the content is identical, so the timestamp should be different
-if ( referenceTimestamp >= actualTimestamp ) {
-    // This might fail with reproducible builds, so let's make it a warning 
instead of an error
-    System.out.println( "WARNING: Timestamps are the same, but this might be 
expected with reproducible builds" );
-    System.out.println( "The important check is that the JAR plugin executed 
multiple times, which it did." );
-} else {
-    System.out.println( "SUCCESS: JAR timestamp changed, confirming 
recreation" );
-}
-
-System.out.println( "SUCCESS: JAR was recreated as expected with 
forceCreation=true" );
-
-return true;
diff --git 
a/src/test/java/org/apache/maven/plugins/jar/JarDefaultExcludesTest.java 
b/src/test/java/org/apache/maven/plugins/jar/JarDefaultExcludesTest.java
new file mode 100644
index 0000000..ae74636
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugins/jar/JarDefaultExcludesTest.java
@@ -0,0 +1,132 @@
+/*
+ * 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 org.apache.maven.plugins.jar;
+
+import javax.inject.Inject;
+
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.jar.JarFile;
+import java.util.zip.ZipEntry;
+
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoExtension;
+import org.apache.maven.api.plugin.testing.MojoParameter;
+import org.apache.maven.api.plugin.testing.MojoTest;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.handler.DefaultArtifactHandler;
+import org.apache.maven.project.MavenProject;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * {@code addDefaultExcludes}: whether files such as {@code .DS_Store} and 
editor backups are kept out of the jar.
+ *
+ * <p>The files are the ones the default excludes of the archiver still list; 
{@code .cvsignore} and {@code .gitignore}
+ * are not among them any more, so they cannot show the difference.
+ */
+@MojoTest
+class JarDefaultExcludesTest {
+
+    private static final String FINAL_NAME = "default-excludes-1.0-SNAPSHOT";
+
+    @Inject
+    private MavenProject project;
+
+    @TempDir
+    private Path tmp;
+
+    @Test
+    @InjectMojo(goal = "jar")
+    void defaultExcludesKeepVersionControlAndBackupFilesOutOfTheJar(JarMojo 
mojo) throws Exception {
+        Set<String> entries = packageWithIgnoredFiles(mojo);
+
+        assertTrue(entries.contains("Foo.class"), "regular files must stay");
+        assertEquals(
+                new HashSet<>(), ignoredFiles(entries), "files matched by the 
default excludes must not be in the jar");
+    }
+
+    @Test
+    @InjectMojo(goal = "jar")
+    @MojoParameter(name = "addDefaultExcludes", value = "false")
+    void disablingDefaultExcludesKeepsThoseFiles(JarMojo mojo) throws 
Exception {
+        Set<String> entries = packageWithIgnoredFiles(mojo);
+
+        assertTrue(entries.contains("Foo.class"), "regular files must stay");
+        Set<String> expected = new HashSet<>();
+        expected.add(".DS_Store");
+        expected.add(".svn/entries");
+        expected.add("Foo.java~");
+        assertEquals(expected, ignoredFiles(entries));
+    }
+
+    private Set<String> packageWithIgnoredFiles(JarMojo mojo) throws Exception 
{
+        project.setGroupId("org.apache.maven.plugins");
+        project.setArtifactId("default-excludes");
+        project.setVersion("1.0-SNAPSHOT");
+        Path pom = Files.write(tmp.resolve("pom.xml"), 
"<project/>".getBytes(StandardCharsets.UTF_8));
+        project.setFile(pom.toFile());
+        project.setArtifact(new DefaultArtifact(
+                "org.apache.maven.plugins",
+                "default-excludes",
+                "1.0-SNAPSHOT",
+                "compile",
+                "jar",
+                null,
+                new DefaultArtifactHandler("jar")));
+
+        Path classes = tmp.resolve("target/classes");
+        Files.createDirectories(classes.resolve(".svn"));
+        for (String name : new String[] {"Foo.class", ".DS_Store", 
".svn/entries", "Foo.java~"}) {
+            Files.write(classes.resolve(name), new byte[0]);
+        }
+        MojoExtension.setVariableValueToObject(mojo, "classesDirectory", 
classes.toFile());
+        MojoExtension.setVariableValueToObject(
+                mojo, "outputDirectory", tmp.resolve("target").toFile());
+        MojoExtension.setVariableValueToObject(mojo, "finalName", FINAL_NAME);
+
+        mojo.execute();
+
+        Set<String> entries = new HashSet<>();
+        try (JarFile jar =
+                new JarFile(tmp.resolve("target/" + FINAL_NAME + 
".jar").toFile())) {
+            for (Enumeration<? extends ZipEntry> e = jar.entries(); 
e.hasMoreElements(); ) {
+                ZipEntry entry = e.nextElement();
+                if (!entry.isDirectory()) {
+                    entries.add(entry.getName());
+                }
+            }
+        }
+        return entries;
+    }
+
+    /** The entries that the default excludes are meant to drop. */
+    private static Set<String> ignoredFiles(Set<String> entries) {
+        Set<String> ignored = new HashSet<>(entries);
+        ignored.retainAll(new HashSet<>(java.util.Arrays.asList(".DS_Store", 
".svn/entries", "Foo.java~")));
+        return ignored;
+    }
+}
diff --git a/src/test/java/org/apache/maven/plugins/jar/JarRecreationTest.java 
b/src/test/java/org/apache/maven/plugins/jar/JarRecreationTest.java
new file mode 100644
index 0000000..f046605
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugins/jar/JarRecreationTest.java
@@ -0,0 +1,148 @@
+/*
+ * 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 org.apache.maven.plugins.jar;
+
+import javax.inject.Inject;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.attribute.FileTime;
+import java.time.Instant;
+import java.time.temporal.ChronoUnit;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.jar.JarFile;
+import java.util.zip.ZipEntry;
+
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoExtension;
+import org.apache.maven.api.plugin.testing.MojoParameter;
+import org.apache.maven.api.plugin.testing.MojoTest;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.handler.DefaultArtifactHandler;
+import org.apache.maven.project.MavenProject;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * {@code forceCreation}: whether packaging again rewrites a jar that is 
already up to date.
+ *
+ * <p>After the first run the test replaces the jar with stale bytes and dates 
it one hour ahead, so it counts as up
+ * to date. The content after the second run tells whether the jar was 
rebuilt. The modification time cannot: an
+ * identical jar is not written again, even when the creation is forced.
+ */
+@MojoTest
+class JarRecreationTest {
+
+    private static final String FINAL_NAME = "recreation-1.0-SNAPSHOT";
+
+    private static final byte[] STALE = 
"stale".getBytes(StandardCharsets.UTF_8);
+
+    private static final FileTime AHEAD_OF_SOURCES =
+            FileTime.from(Instant.now().plus(1, 
ChronoUnit.HOURS).truncatedTo(ChronoUnit.SECONDS));
+
+    @Inject
+    private MavenProject project;
+
+    @TempDir
+    private Path tmp;
+
+    @Test
+    @InjectMojo(goal = "jar")
+    @MojoParameter(name = "forceCreation", value = "true")
+    @MojoParameter(name = "outputTimestamp", value = "1980-02-01T00:00:00Z")
+    void forceCreationRewritesAnUpToDateJar(JarMojo mojo) throws Exception {
+        Path jar = packageOverStaleJar(mojo);
+
+        assertFalse(Arrays.equals(STALE, Files.readAllBytes(jar)), "the stale 
jar was kept");
+        assertEquals(Collections.singleton("myproject/HelloWorld.class"), 
classEntries(jar));
+    }
+
+    @Test
+    @InjectMojo(goal = "jar")
+    @MojoParameter(name = "outputTimestamp", value = "1980-02-01T00:00:00Z")
+    void upToDateJarIsKeptWithoutForceCreation(JarMojo mojo) throws Exception {
+        Path jar = packageOverStaleJar(mojo);
+
+        assertArrayEquals(STALE, Files.readAllBytes(jar), "the up to date jar 
was rewritten");
+    }
+
+    /** Runs the mojo, replaces the jar with stale bytes dated ahead of its 
sources, runs the mojo again. */
+    private Path packageOverStaleJar(JarMojo mojo) throws Exception {
+        project.setGroupId("org.apache.maven.plugins");
+        project.setArtifactId("recreation");
+        project.setVersion("1.0-SNAPSHOT");
+        Path pom = Files.write(tmp.resolve("pom.xml"), 
"<project/>".getBytes(StandardCharsets.UTF_8));
+        project.setFile(pom.toFile());
+        DefaultArtifact artifact = new DefaultArtifact(
+                "org.apache.maven.plugins",
+                "recreation",
+                "1.0-SNAPSHOT",
+                "compile",
+                "jar",
+                null,
+                new DefaultArtifactHandler("jar"));
+        project.setArtifact(artifact);
+
+        Path classes = tmp.resolve("target/classes/myproject");
+        Files.createDirectories(classes);
+        Files.write(classes.resolve("HelloWorld.class"), new byte[0]);
+        Path output = tmp.resolve("target");
+        MojoExtension.setVariableValueToObject(
+                mojo, "classesDirectory", output.resolve("classes").toFile());
+        MojoExtension.setVariableValueToObject(mojo, "outputDirectory", 
output.toFile());
+        MojoExtension.setVariableValueToObject(mojo, "finalName", FINAL_NAME);
+
+        mojo.execute();
+
+        Path jar = output.resolve(FINAL_NAME + ".jar");
+        assertTrue(Files.isRegularFile(jar), "the first run must write the 
jar");
+        Files.write(jar, STALE);
+        Files.setLastModifiedTime(jar, AHEAD_OF_SOURCES);
+        // the first run set the jar as the main artifact, and the mojo 
refuses to replace it
+        artifact.setFile(null);
+
+        mojo.execute();
+
+        return jar;
+    }
+
+    private static Set<String> classEntries(Path jar) throws IOException {
+        Set<String> names = new HashSet<>();
+        try (JarFile jarFile = new JarFile(jar.toFile())) {
+            for (Enumeration<? extends ZipEntry> entries = jarFile.entries(); 
entries.hasMoreElements(); ) {
+                String name = entries.nextElement().getName();
+                if (name.endsWith(".class")) {
+                    names.add(name);
+                }
+            }
+        }
+        return names;
+    }
+}

Reply via email to