-
Notifications
You must be signed in to change notification settings - Fork 99
[MWAR-443] Fix deletion of files placed by maven-dependency-plugin #641
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,15 +18,19 @@ | |
| */ | ||
| package org.apache.maven.plugins.war; | ||
|
|
||
| import javax.inject.Inject; | ||
|
|
||
| import java.io.File; | ||
| import java.text.SimpleDateFormat; | ||
| import java.util.Date; | ||
| import java.util.Locale; | ||
|
|
||
| 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.handler.DefaultArtifactHandler; | ||
| import org.apache.maven.execution.MavenSession; | ||
| import org.apache.maven.plugin.testing.stubs.ArtifactStub; | ||
| import org.apache.maven.plugins.war.stub.AarArtifactStub; | ||
| import org.apache.maven.plugins.war.stub.EJBArtifactStub; | ||
|
|
@@ -50,10 +54,14 @@ | |
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| @MojoTest | ||
| public class WarExplodedMojoTest { | ||
|
|
||
| @Inject | ||
| private MavenSession mavenSession; | ||
|
|
||
| @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") | ||
| @MojoParameter( | ||
| name = "classesDirectory", | ||
|
|
@@ -934,4 +942,47 @@ public void testExplodedWarWithOutputFileNameMappingAndDuplicateDependencies(War | |
| expectedEJBArtifact.delete(); | ||
| expectedEJBDupArtifact.delete(); | ||
| } | ||
|
|
||
| /** | ||
| * Test for MWAR-443: Files placed by maven-dependency-plugin in WEB-INF/lib | ||
| * for provided-scope artifacts should not be deleted by the WAR plugin. | ||
| */ | ||
| @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") | ||
| @MojoParameter( | ||
| name = "classesDirectory", | ||
| value = "target/test-classes/unit/warexplodedmojo/SimpleExplodedWar-test-data/classes/") | ||
| @MojoParameter( | ||
| name = "warSourceDirectory", | ||
| value = "target/test-classes/unit/warexplodedmojo/SimpleExplodedWar-test-data/source/") | ||
| @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/MWAR443Test") | ||
| @MojoParameter(name = "outdatedCheckPath", value = "WEB-INF/lib/") | ||
| @Test | ||
| public void testProvidedScopeArtifactPlacedByDependencyPluginShouldNotBeDeleted(WarExplodedMojo mojo) | ||
| throws Exception { | ||
| // Ensure session has a start time so the outdated resource detection is active. | ||
| // Uses same pattern as WarExplodedMojoFilteringTest which also calls | ||
| // when(mavenSession.get...()).thenReturn(...) | ||
| when(mavenSession.getStartTime()).thenReturn(new Date()); | ||
|
Comment on lines
+960
to
+965
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This follows the same pattern used by |
||
|
|
||
| File webAppDirectory = mojo.getWebappDirectory(); | ||
| File libDir = new File(webAppDirectory, "WEB-INF/lib"); | ||
| File providedJar = new File(libDir, "derbyLocale_cs-10.14.2.0.jar"); | ||
| try { | ||
| // Setup: Create a file in WEB-INF/lib with an old timestamp, | ||
| // simulating a file placed by maven-dependency-plugin for a provided-scope artifact | ||
| libDir.mkdirs(); | ||
| providedJar.createNewFile(); | ||
| // Set timestamp to something in the past (before session start) | ||
| providedJar.setLastModified(0L); | ||
|
|
||
| mojo.execute(); | ||
|
|
||
| // The file should NOT be deleted - it was placed by another plugin | ||
| assertTrue(providedJar.exists(), "provided-scope artifact should not be deleted by WAR plugin"); | ||
| } finally { | ||
| // Cleanup | ||
| providedJar.delete(); | ||
| libDir.delete(); | ||
| } | ||
| } | ||
|
Comment on lines
+967
to
+987
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in the latest revision. Cleanup is now in a |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in the latest revision.
getRuntimeArtifactFileNames()now checksgetOutputFileNameMapping()and uses it if set, mirroring the same logic asArtifactsPackagingTask.getArtifactFinalName().