You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2022/10/09 15:56:45 UTC

[maven-ear-plugin] branch master updated: [MEAR-301] fix repackaging when defaultLibBundleDir beginning with dot

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

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


The following commit(s) were added to refs/heads/master by this push:
     new cd033ab  [MEAR-301] fix repackaging when defaultLibBundleDir beginning with dot
cd033ab is described below

commit cd033abb8cb6b731cb85ce3d774f7046649b42b8
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Sun Oct 9 11:37:52 2022 +0200

    [MEAR-301] fix repackaging when defaultLibBundleDir beginning with dot
---
 .../java/org/apache/maven/plugins/ear/EarMojo.java |  6 +--
 .../maven/plugins/ear/it/AbstractEarPluginIT.java  | 14 ++++++
 .../org/apache/maven/plugins/ear/it/EarMojoIT.java | 14 ++++++
 .../project-101/expected-META-INF/application.xml  | 23 +++++++++
 src/test/resources/projects/project-101/pom.xml    | 56 ++++++++++++++++++++++
 5 files changed, 109 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/ear/EarMojo.java b/src/main/java/org/apache/maven/plugins/ear/EarMojo.java
index 47e7659..5ad8990 100644
--- a/src/main/java/org/apache/maven/plugins/ear/EarMojo.java
+++ b/src/main/java/org/apache/maven/plugins/ear/EarMojo.java
@@ -438,8 +438,6 @@ public class EarMojo
                               Collection<String> outdatedResources )
         throws MojoExecutionException, MojoFailureException
     {
-        final Path workingDir = getWorkDirectory().toPath();
-
         try
         {
             for ( EarModule module : getModules() )
@@ -497,7 +495,7 @@ public class EarMojo
                         getLog().debug( "Skipping artifact [" + module + "], as it is already up to date at ["
                             + module.getUri() + "]" );
                     }
-                    outdatedResources.remove( workingDir.relativize( destinationFile.toPath() ).toString() );
+                    removeFromOutdatedResources( destinationFile.toPath(), outdatedResources );
                 }
             }
         }
@@ -1037,7 +1035,7 @@ public class EarMojo
 
     private void removeFromOutdatedResources( Path destination, Collection<String> outdatedResources )
     {
-        Path relativeDestFile = getWorkDirectory().toPath().relativize( destination );
+        Path relativeDestFile = getWorkDirectory().toPath().relativize( destination.normalize() );
         if ( outdatedResources.remove( relativeDestFile.toString() ) )
         {
             getLog().debug( "Remove from outdatedResources: " + relativeDestFile );
diff --git a/src/test/java/org/apache/maven/plugins/ear/it/AbstractEarPluginIT.java b/src/test/java/org/apache/maven/plugins/ear/it/AbstractEarPluginIT.java
index cdda5ae..3fb7c83 100644
--- a/src/test/java/org/apache/maven/plugins/ear/it/AbstractEarPluginIT.java
+++ b/src/test/java/org/apache/maven/plugins/ear/it/AbstractEarPluginIT.java
@@ -197,6 +197,20 @@ public abstract class AbstractEarPluginIT
         return doTestProject( projectName, expectedArtifacts, new boolean[expectedArtifacts.length] );
     }
 
+    /**
+     * Executes the specified projects and asserts the given artifacts as artifacts (non directory)
+     *
+     * @param projectName the project to test
+     * @param expectedArtifacts the list of artifacts to be found in the EAR archive
+     * @param cleanBeforeExecute call clean plugin before execution
+     * @return the base directory of the project
+     */
+    protected File doTestProject( final String projectName, final String[] expectedArtifacts, boolean cleanBeforeExecute)
+        throws VerificationException, IOException
+    {
+        return doTestProject( projectName, null, expectedArtifacts, new boolean[expectedArtifacts.length], null, null, null, cleanBeforeExecute );
+    }
+
     protected void assertEarArchive( final File baseDir, final String projectName )
     {
         assertTrue( "EAR archive does not exist", getEarArchive( baseDir, projectName ).exists() );
diff --git a/src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java b/src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java
index 53270f4..852fc0a 100644
--- a/src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java
+++ b/src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java
@@ -1318,4 +1318,18 @@ public class EarMojoIT
     {
         doTestProject( "project-100", new String[] { "eartest-ejb-sample-one-1.0.jar" } );
     }
+
+    /**
+     * Ensure that {@code defaultLibBundleDir} with dot at begin don't remove artifacts during second execution.
+     */
+    public void testProject101() throws Exception
+    {
+        String[] expectedArtifacts = new String[] {
+            "eartest-jar-sample-one-1.0.jar", "eartest-jar-sample-two-1.0.jar", "eartest-jar-sample-three-with-deps-1.0.jar" };
+
+        boolean[] artifactsDirectory = new boolean[expectedArtifacts.length];
+
+        doTestProject( "project-101", expectedArtifacts, true );
+        doTestProject( "project-101", expectedArtifacts, false );
+    }
 }
diff --git a/src/test/resources/projects/project-101/expected-META-INF/application.xml b/src/test/resources/projects/project-101/expected-META-INF/application.xml
new file mode 100644
index 0000000..f6c74ec
--- /dev/null
+++ b/src/test/resources/projects/project-101/expected-META-INF/application.xml
@@ -0,0 +1,23 @@
+<?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.
+-->
+<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" version="5">
+  <display-name>maven-ear-plugin-test-project-101</display-name>
+  <library-directory>.</library-directory>
+</application>
diff --git a/src/test/resources/projects/project-101/pom.xml b/src/test/resources/projects/project-101/pom.xml
new file mode 100644
index 0000000..e5f4ae0
--- /dev/null
+++ b/src/test/resources/projects/project-101/pom.xml
@@ -0,0 +1,56 @@
+<?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>ear</groupId>
+  <artifactId>maven-ear-plugin-test-project-101</artifactId>
+  <version>99.0</version>
+  <name>Maven</name>
+  <packaging>ear</packaging>
+
+  <dependencies>
+    <dependency>
+      <groupId>eartest</groupId>
+      <artifactId>jar-sample-one</artifactId>
+      <version>1.0</version>
+    </dependency>
+    <dependency>
+      <groupId>eartest</groupId>
+      <artifactId>jar-sample-three-with-deps</artifactId>
+      <version>1.0</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-ear-plugin</artifactId>
+        <version>@project.version@</version>
+        <configuration>
+          <version>5</version>
+          <defaultLibBundleDir>.</defaultLibBundleDir>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>