Skip to content

Commit

Permalink
[MEAR-301] fix repackaging when defaultLibBundleDir beginning with dot
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Oct 9, 2022
1 parent 39b8e0f commit cd033ab
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/main/java/org/apache/maven/plugins/ear/EarMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,6 @@ private void copyModules( final JavaEEVersion javaEEVersion,
Collection<String> outdatedResources )
throws MojoExecutionException, MojoFailureException
{
final Path workingDir = getWorkDirectory().toPath();

try
{
for ( EarModule module : getModules() )
Expand Down Expand Up @@ -497,7 +495,7 @@ private void copyModules( final JavaEEVersion javaEEVersion,
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 );
}
}
}
Expand Down Expand Up @@ -1037,7 +1035,7 @@ private void deleteOutdatedResources( final Collection<String> outdatedResources

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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,20 @@ protected File doTestProject( final String projectName, final String[] expectedA
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() );
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -1318,4 +1318,18 @@ public void testProject100()
{
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 );
}
}
Original file line number Diff line number Diff line change
@@ -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>
56 changes: 56 additions & 0 deletions src/test/resources/projects/project-101/pom.xml
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit cd033ab

Please sign in to comment.