From 1baa006e20f42b2edc09570a175225e76bf9a588 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 5 Nov 2025 09:29:28 +0100 Subject: [PATCH 01/80] refactor: inline classes --- .../war/AbstractWarExplodedMojoTest.java | 260 ---------- .../plugins/war/AbstractWarMojoTest.java | 298 ----------- .../war/WarExplodedMojoFilteringTest.java | 476 ++++++++++++++++- .../plugins/war/WarExplodedMojoTest.java | 478 +++++++++++++++++- .../maven/plugins/war/WarInPlaceMojoTest.java | 264 +++++++++- .../apache/maven/plugins/war/WarMojoTest.java | 264 +++++++++- .../maven/plugins/war/WarOverlaysTest.java | 469 ++++++++++++++++- .../apache/maven/plugins/war/WarZipTest.java | 264 +++++++++- 8 files changed, 2207 insertions(+), 566 deletions(-) delete mode 100644 src/test/java/org/apache/maven/plugins/war/AbstractWarExplodedMojoTest.java delete mode 100644 src/test/java/org/apache/maven/plugins/war/AbstractWarMojoTest.java diff --git a/src/test/java/org/apache/maven/plugins/war/AbstractWarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/AbstractWarExplodedMojoTest.java deleted file mode 100644 index 50e97127..00000000 --- a/src/test/java/org/apache/maven/plugins/war/AbstractWarExplodedMojoTest.java +++ /dev/null @@ -1,260 +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. - */ -package org.apache.maven.plugins.war; - -import java.io.File; -import java.io.FileFilter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import org.apache.maven.plugin.testing.stubs.ArtifactStub; -import org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub; -import org.codehaus.plexus.util.FileUtils; - -/** - * @author Stephane Nicoll - */ -public abstract class AbstractWarExplodedMojoTest extends AbstractWarMojoTest { - - protected WarExplodedMojo mojo; - - public void setUp() throws Exception { - super.setUp(); - mojo = lookupMojo("exploded", getPomFile()); - } - - /** - * Returns the pom configuration to use. - * - * @return the pom configuration - */ - protected abstract File getPomFile(); - - /** - * Returns the test directory to use. - * - * @return the test directory - */ - protected abstract File getTestDirectory(); - - /** - * Configures the exploded mojo for the specified test. - * - * If the {@code sourceFiles} parameter is {@code null}, sample JSPs are created by default. - * - * @param testId the id of the test - * @param artifactStubs the dependencies (may be null) - * @param sourceFiles the source files to create (may be null) - * @return the webapp directory - * @throws Exception if an error occurs while configuring the mojo - */ - protected File setUpMojo(final String testId, ArtifactStub[] artifactStubs, String[] sourceFiles) throws Exception { - final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - final File webAppDirectory = new File(getTestDirectory(), testId); - - // Create the webapp sources - File webAppSource; - if (sourceFiles == null) { - webAppSource = createWebAppSource(testId); - } else { - webAppSource = createWebAppSource(testId, false); - for (String sourceFile : sourceFiles) { - File sample = new File(webAppSource, sourceFile); - createFile(sample); - } - } - - final File classesDir = createClassesDir(testId, true); - final File workDirectory = new File(getTestDirectory(), "/war/work-" + testId); - createDir(workDirectory); - - if (artifactStubs != null) { - for (ArtifactStub artifactStub : artifactStubs) { - project.addArtifact(artifactStub); - } - } - - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "workDirectory", workDirectory); - - return webAppDirectory; - } - - /** - * Configures the exploded mojo for the specified test. - * - * @param testId the id of the test - * @param artifactStubs the dependencies (may be null) - * @return the webapp directory - * @throws Exception if an error occurs while configuring the mojo - */ - protected File setUpMojo(final String testId, ArtifactStub[] artifactStubs) throws Exception { - return setUpMojo(testId, artifactStubs, null); - } - - /** - * Cleans up a directory. - * - * @param directory the directory to remove - * @throws IOException if an error occurred while removing the directory - */ - protected void cleanDirectory(File directory) throws IOException { - if (directory != null && directory.isDirectory() && directory.exists()) { - FileUtils.deleteDirectory(directory); - } - } - - /** - * Asserts the default content of the war based on the specified webapp directory. - * - * @param webAppDirectory the webapp directory - * @return a list of File objects that have been asserted - */ - protected List assertDefaultContent(File webAppDirectory) { - // Validate content of the webapp - File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); - File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); - - assertTrue("source file not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertTrue("source file not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); - - final List content = new ArrayList<>(); - content.add(expectedWebSourceFile); - content.add(expectedWebSource2File); - - return content; - } - - /** - * Asserts the web.xml file of the war based on the specified webapp directory. - * - * @param webAppDirectory the webapp directory - * @return a list with the web.xml File object - */ - protected List assertWebXml(File webAppDirectory) { - File expectedWEBXMLFile = new File(webAppDirectory, "WEB-INF/web.xml"); - assertTrue("web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists()); - - final List content = new ArrayList<>(); - content.add(expectedWEBXMLFile); - - return content; - } - - /** - * Asserts custom content of the war based on the specified webapp directory. - * - * @param webAppDirectory the webapp directory - * @param filePaths an array of file paths relative to the webapp directory - * @param customMessage a custom message if an assertion fails - * @return a list of File objects that have been inspected - */ - protected List assertCustomContent(File webAppDirectory, String[] filePaths, String customMessage) { - final List content = new ArrayList<>(); - for (String filePath : filePaths) { - final File expectedFile = new File(webAppDirectory, filePath); - if (customMessage != null) { - assertTrue(customMessage + " - " + expectedFile.toString(), expectedFile.exists()); - } else { - assertTrue("source file not found: " + expectedFile.toString(), expectedFile.exists()); - } - content.add(expectedFile); - } - return content; - } - - /** - * Asserts that the webapp contains only the specified files. - * - * @param webAppDirectory the webapp directory - * @param expectedFiles the expected files - * @param filter an optional filter to ignore some resources - */ - protected void assertWebAppContent(File webAppDirectory, List expectedFiles, FileFilter filter) { - final List webAppContent = new ArrayList<>(); - if (filter != null) { - buildFilesList(webAppDirectory, filter, webAppContent); - } else { - buildFilesList(webAppDirectory, new FileFilterImpl(webAppDirectory, null), webAppContent); - } - - // Now we have the files, sort them. - Collections.sort(expectedFiles); - Collections.sort(webAppContent); - assertEquals( - "Invalid webapp content, expected " + expectedFiles.size() + "file(s) " + expectedFiles + " but got " - + webAppContent.size() + " file(s) " + webAppContent, - expectedFiles, - webAppContent); - } - - /** - * Builds the list of files and directories from the specified dir. - * - * Note that the filter is not used the usual way. If the filter does not accept the current file, it's not added - * but yet the subdirectories are added if any. - * - * @param dir the base directory - * @param filter the filter - * @param content the current content, updated recursively - */ - private void buildFilesList(final File dir, FileFilter filter, final List content) { - final File[] files = dir.listFiles(); - - for (File file : files) { - // Add the file if the filter is ok with it - if (filter.accept(file)) { - content.add(file); - } - - // Even if the file is not accepted and is a directory, add it - if (file.isDirectory()) { - buildFilesList(file, filter, content); - } - } - } - - class FileFilterImpl implements FileFilter { - - private final List rejectedFilePaths; - - private final int webAppDirIndex; - - FileFilterImpl(File webAppDirectory, String[] rejectedFilePaths) { - if (rejectedFilePaths != null) { - this.rejectedFilePaths = Arrays.asList(rejectedFilePaths); - } else { - this.rejectedFilePaths = new ArrayList<>(); - } - this.webAppDirIndex = webAppDirectory.getAbsolutePath().length() + 1; - } - - public boolean accept(File file) { - String effectiveRelativePath = buildRelativePath(file); - return !(rejectedFilePaths.contains(effectiveRelativePath) || file.isDirectory()); - } - - private String buildRelativePath(File f) { - return f.getAbsolutePath().substring(webAppDirIndex); - } - } -} diff --git a/src/test/java/org/apache/maven/plugins/war/AbstractWarMojoTest.java b/src/test/java/org/apache/maven/plugins/war/AbstractWarMojoTest.java deleted file mode 100644 index 217e754c..00000000 --- a/src/test/java/org/apache/maven/plugins/war/AbstractWarMojoTest.java +++ /dev/null @@ -1,298 +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. - */ -package org.apache.maven.plugins.war; - -import java.io.File; -import java.io.IOException; -import java.util.Date; - -import org.apache.maven.execution.DefaultMavenExecutionRequest; -import org.apache.maven.execution.MavenExecutionRequest; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.testing.AbstractMojoTestCase; -import org.apache.maven.plugin.testing.stubs.ArtifactStub; -import org.apache.maven.plugins.war.stub.MavenProjectBasicStub; -import org.apache.maven.plugins.war.stub.WarOverlayStub; -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.archiver.ArchiverException; -import org.codehaus.plexus.archiver.jar.JarArchiver; -import org.codehaus.plexus.util.FileUtils; -import org.eclipse.aether.RepositorySystemSession; - -public abstract class AbstractWarMojoTest extends AbstractMojoTestCase { - - protected static final File OVERLAYS_TEMP_DIR = new File(getBasedir(), "target/test-overlays/"); - - protected static final File OVERLAYS_ROOT_DIR = new File(getBasedir(), "target/test-classes/overlays/"); - - protected static final String MANIFEST_PATH = "META-INF" + File.separator + "MANIFEST.MF"; - - protected abstract File getTestDirectory() throws Exception; - - protected void setUp() throws Exception { - super.setUp(); - - MavenExecutionRequest request = new DefaultMavenExecutionRequest() - .setSystemProperties(System.getProperties()) - .setStartTime(new Date()); - - MavenSession mavenSession = - new MavenSession((PlexusContainer) null, (RepositorySystemSession) null, request, null); - getContainer().addComponent(mavenSession, MavenSession.class.getName()); - } - /** - * initialize required parameters - * - * @param mojo The mojo to be tested. - * @param classesDir The classes' directory. - * @param webAppSource The webAppSource. - * @param webAppDir The webAppDir folder. - * @param project The Maven project. - * @throws Exception in case of errors - */ - protected void configureMojo( - AbstractWarMojo mojo, File classesDir, File webAppSource, File webAppDir, MavenProjectBasicStub project) - throws Exception { - setVariableValueToObject(mojo, "outdatedCheckPath", "WEB-INF/lib/"); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDir); - mojo.setProject(project); - } - - /** - * create an isolated xml dir - * - * @param id The id. - * @param xmlFiles array of xml files. - * @return The created file. - * @throws Exception in case of errors. - */ - protected File createXMLConfigDir(String id, String[] xmlFiles) throws Exception { - File xmlConfigDir = new File(getTestDirectory(), "/" + id + "-test-data/xml-config"); - File xmlFile; - - createDir(xmlConfigDir); - - if (xmlFiles != null) { - for (String o : xmlFiles) { - xmlFile = new File(xmlConfigDir, o); - createFile(xmlFile); - } - } - - return xmlConfigDir; - } - - /** - * Returns the webapp source directory for the specified id. - * - * @param id the id of the test - * @return the source directory for that test - * @throws Exception if an exception occurs - */ - protected File getWebAppSource(String id) throws Exception { - return new File(getTestDirectory(), "/" + id + "-test-data/source"); - } - - /** - * create an isolated web source with a sample jsp file - * - * @param id The id. - * @param createSamples Create example files yes or no. - * @return The created file. - * @throws Exception in case of errors. - */ - protected File createWebAppSource(String id, boolean createSamples) throws Exception { - File webAppSource = getWebAppSource(id); - if (createSamples) { - File simpleJSP = new File(webAppSource, "pansit.jsp"); - File jspFile = new File(webAppSource, "org/web/app/last-exile.jsp"); - - createFile(simpleJSP); - createFile(jspFile); - } - return webAppSource; - } - - protected File createWebAppSource(String id) throws Exception { - return createWebAppSource(id, true); - } - - /** - * create a class directory with or without a sample class - * - * @param id The id. - * @param empty true to create a class files false otherwise. - * @return The created class file. - * @throws Exception in case of errors. - */ - protected File createClassesDir(String id, boolean empty) throws Exception { - File classesDir = new File(getTestDirectory() + "/" + id + "-test-data/classes/"); - - createDir(classesDir); - - if (!empty) { - createFile(new File(classesDir + "/sample-servlet.clazz")); - } - - return classesDir; - } - - protected void createDir(File dir) { - if (!dir.exists()) { - assertTrue("can not create test dir: " + dir.toString(), dir.mkdirs()); - } - } - - protected void createFile(File testFile, String body) throws Exception { - createDir(testFile.getParentFile()); - FileUtils.fileWrite(testFile.toString(), body); - - assertTrue("could not create file: " + testFile, testFile.exists()); - } - - protected void createFile(File testFile) throws Exception { - createFile(testFile, testFile.toString()); - } - - /** - * Generates test war. - * Generates war with such a structure: - *
    - *
  • jsp - *
      - *
    • d - *
        - *
      • a.jsp
      • - *
      • b.jsp
      • - *
      • c.jsp
      • - *
      - *
    • - *
    • a.jsp
    • - *
    • b.jsp
    • - *
    • c.jsp
    • - *
    - *
  • - *
  • WEB-INF - *
      - *
    • classes - *
        - *
      • a.clazz
      • - *
      • b.clazz
      • - *
      • c.clazz
      • - *
      - *
    • - *
    • lib - *
        - *
      • a.jar
      • - *
      • b.jar
      • - *
      • c.jar
      • - *
      - *
    • - *
    • web.xml
    • - *
    - *
  • - *
- * Each of the files will contain: id+'-'+path - * - * @param id the id of the overlay containing the full structure - * @return the war file - * @throws Exception if an error occurs - */ - protected File generateFullOverlayWar(String id) throws Exception { - final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); - if (destFile.exists()) { - return destFile; - } - - // Archive was not yet created for that id so let's create it - final File rootDir = new File(OVERLAYS_ROOT_DIR, id); - rootDir.mkdirs(); - String[] filePaths = new String[] { - "jsp/d/a.jsp", - "jsp/d/b.jsp", - "jsp/d/c.jsp", - "jsp/a.jsp", - "jsp/b.jsp", - "jsp/c.jsp", - "WEB-INF/classes/a.clazz", - "WEB-INF/classes/b.clazz", - "WEB-INF/classes/c.clazz", - "WEB-INF/lib/a.jar", - "WEB-INF/lib/b.jar", - "WEB-INF/lib/c.jar", - "WEB-INF/web.xml" - }; - - for (String filePath : filePaths) { - createFile(new File(rootDir, filePath), id + "-" + filePath); - } - - createArchive(rootDir, destFile); - return destFile; - } - - // Overlay utilities - - /** - * Builds a test overlay. - * - * @param id the id of the overlay (see test/resources/overlays) - * @return a test war artifact with the content of the given test overlay - */ - protected ArtifactStub buildWarOverlayStub(String id) { - // Create war file - final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); - if (!destFile.exists()) { - createArchive(new File(OVERLAYS_ROOT_DIR, id), destFile); - } - - return new WarOverlayStub(getBasedir(), id, destFile); - } - - protected File getOverlayFile(String id, String filePath) { - final File overlayDir = new File(OVERLAYS_ROOT_DIR, id); - final File file = new File(overlayDir, filePath); - - // Make sure the file exists - assertTrue( - "Overlay file " + filePath + " does not exist for overlay " + id + " at " + file.getAbsolutePath(), - file.exists()); - return file; - } - - protected void createArchive(final File directory, final File destinationFile) { - try { - JarArchiver archiver = new JarArchiver(); - - archiver.setDestFile(destinationFile); - archiver.addDirectory(directory); - - archiver.createArchive(); - - } catch (ArchiverException e) { - e.printStackTrace(); - fail("Failed to create overlay archive " + e.getMessage()); - } catch (IOException e) { - e.printStackTrace(); - fail("Unexpected exception " + e.getMessage()); - } - } -} diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java index abff3213..dff8578f 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java @@ -20,20 +20,41 @@ import java.io.BufferedReader; import java.io.File; +import java.io.FileFilter; +import java.io.IOException; import java.io.StringReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; import java.util.LinkedList; import java.util.List; +import org.apache.maven.execution.DefaultMavenExecutionRequest; +import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.testing.AbstractMojoTestCase; +import org.apache.maven.plugin.testing.stubs.ArtifactStub; +import org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub; import org.apache.maven.plugins.war.stub.MavenProjectBasicStub; import org.apache.maven.plugins.war.stub.ResourceStub; +import org.apache.maven.plugins.war.stub.WarOverlayStub; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.archiver.ArchiverException; +import org.codehaus.plexus.archiver.jar.JarArchiver; import org.codehaus.plexus.util.FileUtils; +import org.eclipse.aether.RepositorySystemSession; /** * @author Olivier Lamy * @since 21 juil. 2008 */ -public class WarExplodedMojoFilteringTest extends AbstractWarExplodedMojoTest { +public class WarExplodedMojoFilteringTest extends AbstractMojoTestCase { + + protected static final File OVERLAYS_TEMP_DIR = new File(getBasedir(), "target/test-overlays/"); + protected static final File OVERLAYS_ROOT_DIR = new File(getBasedir(), "target/test-classes/overlays/"); + protected static final String MANIFEST_PATH = "META-INF" + File.separator + "MANIFEST.MF"; + protected WarExplodedMojo mojo; protected File getPomFile() { return new File(getBasedir(), "/target/test-classes/unit/warexplodedmojo/plugin-config.xml"); @@ -220,4 +241,457 @@ public void testExplodedWarWithResourceFiltering() throws Exception { expectedResourceFile.delete(); expectedResourceWDirFile.delete(); } + + public void setUp() throws Exception { + super.setUp(); + + MavenExecutionRequest request = new DefaultMavenExecutionRequest() + .setSystemProperties(System.getProperties()) + .setStartTime(new Date()); + + MavenSession mavenSession = + new MavenSession((PlexusContainer) null, (RepositorySystemSession) null, request, null); + getContainer().addComponent(mavenSession, MavenSession.class.getName()); + mojo = (WarExplodedMojo) lookupMojo("exploded", getPomFile()); + } + + /** + * Configures the exploded mojo for the specified test. + * + * If the {@code sourceFiles} parameter is {@code null}, sample JSPs are created by default. + * + * @param testId the id of the test + * @param artifactStubs the dependencies (may be null) + * @param sourceFiles the source files to create (may be null) + * @return the webapp directory + * @throws Exception if an error occurs while configuring the mojo + */ + protected File setUpMojo(final String testId, ArtifactStub[] artifactStubs, String[] sourceFiles) throws Exception { + final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + final File webAppDirectory = new File(getTestDirectory(), testId); + + // Create the webapp sources + File webAppSource; + if (sourceFiles == null) { + webAppSource = createWebAppSource(testId); + } else { + webAppSource = createWebAppSource(testId, false); + for (String sourceFile : sourceFiles) { + File sample = new File(webAppSource, sourceFile); + createFile(sample); + } + } + + final File classesDir = createClassesDir(testId, true); + final File workDirectory = new File(getTestDirectory(), "/war/work-" + testId); + createDir(workDirectory); + + if (artifactStubs != null) { + for (ArtifactStub artifactStub : artifactStubs) { + project.addArtifact(artifactStub); + } + } + + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + setVariableValueToObject(mojo, "workDirectory", workDirectory); + + return webAppDirectory; + } + + /** + * Configures the exploded mojo for the specified test. + * + * @param testId the id of the test + * @param artifactStubs the dependencies (may be null) + * @return the webapp directory + * @throws Exception if an error occurs while configuring the mojo + */ + protected File setUpMojo(final String testId, ArtifactStub[] artifactStubs) throws Exception { + return setUpMojo(testId, artifactStubs, null); + } + + /** + * Cleans up a directory. + * + * @param directory the directory to remove + * @throws IOException if an error occurred while removing the directory + */ + protected void cleanDirectory(File directory) throws IOException { + if (directory != null && directory.isDirectory() && directory.exists()) { + FileUtils.deleteDirectory(directory); + } + } + + /** + * Asserts the default content of the war based on the specified webapp directory. + * + * @param webAppDirectory the webapp directory + * @return a list of File objects that have been asserted + */ + protected List assertDefaultContent(File webAppDirectory) { + // Validate content of the webapp + File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); + File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); + + assertTrue("source file not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); + assertTrue("source file not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); + + final List content = new ArrayList<>(); + content.add(expectedWebSourceFile); + content.add(expectedWebSource2File); + + return content; + } + + /** + * Asserts the web.xml file of the war based on the specified webapp directory. + * + * @param webAppDirectory the webapp directory + * @return a list with the web.xml File object + */ + protected List assertWebXml(File webAppDirectory) { + File expectedWEBXMLFile = new File(webAppDirectory, "WEB-INF/web.xml"); + assertTrue("web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists()); + + final List content = new ArrayList<>(); + content.add(expectedWEBXMLFile); + + return content; + } + + /** + * Asserts custom content of the war based on the specified webapp directory. + * + * @param webAppDirectory the webapp directory + * @param filePaths an array of file paths relative to the webapp directory + * @param customMessage a custom message if an assertion fails + * @return a list of File objects that have been inspected + */ + protected List assertCustomContent(File webAppDirectory, String[] filePaths, String customMessage) { + final List content = new ArrayList<>(); + for (String filePath : filePaths) { + final File expectedFile = new File(webAppDirectory, filePath); + if (customMessage != null) { + assertTrue(customMessage + " - " + expectedFile.toString(), expectedFile.exists()); + } else { + assertTrue("source file not found: " + expectedFile.toString(), expectedFile.exists()); + } + content.add(expectedFile); + } + return content; + } + + /** + * Asserts that the webapp contains only the specified files. + * + * @param webAppDirectory the webapp directory + * @param expectedFiles the expected files + * @param filter an optional filter to ignore some resources + */ + protected void assertWebAppContent(File webAppDirectory, List expectedFiles, FileFilter filter) { + final List webAppContent = new ArrayList<>(); + if (filter != null) { + buildFilesList(webAppDirectory, filter, webAppContent); + } else { + buildFilesList(webAppDirectory, new FileFilterImpl(webAppDirectory, null), webAppContent); + } + + // Now we have the files, sort them. + Collections.sort(expectedFiles); + Collections.sort(webAppContent); + assertEquals( + "Invalid webapp content, expected " + expectedFiles.size() + "file(s) " + expectedFiles + " but got " + + webAppContent.size() + " file(s) " + webAppContent, + expectedFiles, + webAppContent); + } + + /** + * Builds the list of files and directories from the specified dir. + * + * Note that the filter is not used the usual way. If the filter does not accept the current file, it's not added + * but yet the subdirectories are added if any. + * + * @param dir the base directory + * @param filter the filter + * @param content the current content, updated recursively + */ + private void buildFilesList(final File dir, FileFilter filter, final List content) { + final File[] files = dir.listFiles(); + + for (File file : files) { + // Add the file if the filter is ok with it + if (filter.accept(file)) { + content.add(file); + } + + // Even if the file is not accepted and is a directory, add it + if (file.isDirectory()) { + buildFilesList(file, filter, content); + } + } + } + + /** + * initialize required parameters + * + * @param mojo The mojo to be tested. + * @param classesDir The classes' directory. + * @param webAppSource The webAppSource. + * @param webAppDir The webAppDir folder. + * @param project The Maven project. + * @throws Exception in case of errors + */ + protected void configureMojo( + AbstractWarMojo mojo, File classesDir, File webAppSource, File webAppDir, MavenProjectBasicStub project) + throws Exception { + setVariableValueToObject(mojo, "outdatedCheckPath", "WEB-INF/lib/"); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDir); + mojo.setProject(project); + } + + /** + * create an isolated xml dir + * + * @param id The id. + * @param xmlFiles array of xml files. + * @return The created file. + * @throws Exception in case of errors. + */ + protected File createXMLConfigDir(String id, String[] xmlFiles) throws Exception { + File xmlConfigDir = new File(getTestDirectory(), "/" + id + "-test-data/xml-config"); + File xmlFile; + + createDir(xmlConfigDir); + + if (xmlFiles != null) { + for (String o : xmlFiles) { + xmlFile = new File(xmlConfigDir, o); + createFile(xmlFile); + } + } + + return xmlConfigDir; + } + + /** + * Returns the webapp source directory for the specified id. + * + * @param id the id of the test + * @return the source directory for that test + * @throws Exception if an exception occurs + */ + protected File getWebAppSource(String id) throws Exception { + return new File(getTestDirectory(), "/" + id + "-test-data/source"); + } + + /** + * create an isolated web source with a sample jsp file + * + * @param id The id. + * @param createSamples Create example files yes or no. + * @return The created file. + * @throws Exception in case of errors. + */ + protected File createWebAppSource(String id, boolean createSamples) throws Exception { + File webAppSource = getWebAppSource(id); + if (createSamples) { + File simpleJSP = new File(webAppSource, "pansit.jsp"); + File jspFile = new File(webAppSource, "org/web/app/last-exile.jsp"); + + createFile(simpleJSP); + createFile(jspFile); + } + return webAppSource; + } + + protected File createWebAppSource(String id) throws Exception { + return createWebAppSource(id, true); + } + + /** + * create a class directory with or without a sample class + * + * @param id The id. + * @param empty true to create a class files false otherwise. + * @return The created class file. + * @throws Exception in case of errors. + */ + protected File createClassesDir(String id, boolean empty) throws Exception { + File classesDir = new File(getTestDirectory() + "/" + id + "-test-data/classes/"); + + createDir(classesDir); + + if (!empty) { + createFile(new File(classesDir + "/sample-servlet.clazz")); + } + + return classesDir; + } + + protected void createDir(File dir) { + if (!dir.exists()) { + assertTrue("can not create test dir: " + dir.toString(), dir.mkdirs()); + } + } + + protected void createFile(File testFile, String body) throws Exception { + createDir(testFile.getParentFile()); + FileUtils.fileWrite(testFile.toString(), body); + + assertTrue("could not create file: " + testFile, testFile.exists()); + } + + protected void createFile(File testFile) throws Exception { + createFile(testFile, testFile.toString()); + } + + /** + * Generates test war. + * Generates war with such a structure: + *
    + *
  • jsp + *
      + *
    • d + *
        + *
      • a.jsp
      • + *
      • b.jsp
      • + *
      • c.jsp
      • + *
      + *
    • + *
    • a.jsp
    • + *
    • b.jsp
    • + *
    • c.jsp
    • + *
    + *
  • + *
  • WEB-INF + *
      + *
    • classes + *
        + *
      • a.clazz
      • + *
      • b.clazz
      • + *
      • c.clazz
      • + *
      + *
    • + *
    • lib + *
        + *
      • a.jar
      • + *
      • b.jar
      • + *
      • c.jar
      • + *
      + *
    • + *
    • web.xml
    • + *
    + *
  • + *
+ * Each of the files will contain: id+'-'+path + * + * @param id the id of the overlay containing the full structure + * @return the war file + * @throws Exception if an error occurs + */ + protected File generateFullOverlayWar(String id) throws Exception { + final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); + if (destFile.exists()) { + return destFile; + } + + // Archive was not yet created for that id so let's create it + final File rootDir = new File(OVERLAYS_ROOT_DIR, id); + rootDir.mkdirs(); + String[] filePaths = new String[] { + "jsp/d/a.jsp", + "jsp/d/b.jsp", + "jsp/d/c.jsp", + "jsp/a.jsp", + "jsp/b.jsp", + "jsp/c.jsp", + "WEB-INF/classes/a.clazz", + "WEB-INF/classes/b.clazz", + "WEB-INF/classes/c.clazz", + "WEB-INF/lib/a.jar", + "WEB-INF/lib/b.jar", + "WEB-INF/lib/c.jar", + "WEB-INF/web.xml" + }; + + for (String filePath : filePaths) { + createFile(new File(rootDir, filePath), id + "-" + filePath); + } + + createArchive(rootDir, destFile); + return destFile; + } + + /** + * Builds a test overlay. + * + * @param id the id of the overlay (see test/resources/overlays) + * @return a test war artifact with the content of the given test overlay + */ + protected ArtifactStub buildWarOverlayStub(String id) { + // Create war file + final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); + if (!destFile.exists()) { + createArchive(new File(OVERLAYS_ROOT_DIR, id), destFile); + } + + return new WarOverlayStub(getBasedir(), id, destFile); + } + + protected File getOverlayFile(String id, String filePath) { + final File overlayDir = new File(OVERLAYS_ROOT_DIR, id); + final File file = new File(overlayDir, filePath); + + // Make sure the file exists + assertTrue( + "Overlay file " + filePath + " does not exist for overlay " + id + " at " + file.getAbsolutePath(), + file.exists()); + return file; + } + + protected void createArchive(final File directory, final File destinationFile) { + try { + JarArchiver archiver = new JarArchiver(); + + archiver.setDestFile(destinationFile); + archiver.addDirectory(directory); + + archiver.createArchive(); + + } catch (ArchiverException e) { + e.printStackTrace(); + fail("Failed to create overlay archive " + e.getMessage()); + } catch (IOException e) { + e.printStackTrace(); + fail("Unexpected exception " + e.getMessage()); + } + } + + class FileFilterImpl implements FileFilter { + + private final List rejectedFilePaths; + + private final int webAppDirIndex; + + FileFilterImpl(File webAppDirectory, String[] rejectedFilePaths) { + if (rejectedFilePaths != null) { + this.rejectedFilePaths = Arrays.asList(rejectedFilePaths); + } else { + this.rejectedFilePaths = new ArrayList<>(); + } + this.webAppDirIndex = webAppDirectory.getAbsolutePath().length() + 1; + } + + public boolean accept(File file) { + String effectiveRelativePath = buildRelativePath(file); + return !(rejectedFilePaths.contains(effectiveRelativePath) || file.isDirectory()); + } + + private String buildRelativePath(File f) { + return f.getAbsolutePath().substring(webAppDirIndex); + } + } } diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index 1fb2b047..da3bc487 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -19,10 +19,21 @@ package org.apache.maven.plugins.war; import java.io.File; +import java.io.FileFilter; +import java.io.IOException; import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; +import java.util.List; import java.util.Locale; import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.execution.DefaultMavenExecutionRequest; +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.apache.maven.plugin.testing.stubs.ArtifactStub; import org.apache.maven.plugins.war.stub.AarArtifactStub; import org.apache.maven.plugins.war.stub.EJBArtifactStub; @@ -37,19 +48,27 @@ import org.apache.maven.plugins.war.stub.ResourceStub; import org.apache.maven.plugins.war.stub.TLDArtifactStub; import org.apache.maven.plugins.war.stub.WarArtifactStub; +import org.apache.maven.plugins.war.stub.WarOverlayStub; import org.apache.maven.plugins.war.stub.XarArtifactStub; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.archiver.ArchiverException; +import org.codehaus.plexus.archiver.jar.JarArchiver; import org.codehaus.plexus.util.FileUtils; +import org.eclipse.aether.RepositorySystemSession; import static org.junit.Assert.assertNotEquals; -public class WarExplodedMojoTest extends AbstractWarExplodedMojoTest { +public class WarExplodedMojoTest extends AbstractMojoTestCase { + + protected static final File OVERLAYS_TEMP_DIR = new File(getBasedir(), "target/test-overlays/"); + protected static final File OVERLAYS_ROOT_DIR = new File(getBasedir(), "target/test-classes/overlays/"); + protected static final String MANIFEST_PATH = "META-INF" + File.separator + "MANIFEST.MF"; + protected WarExplodedMojo mojo; - @Override protected File getPomFile() { return new File(getBasedir(), "/target/test-classes/unit/warexplodedmojo/plugin-config.xml"); } - @Override protected File getTestDirectory() { return new File(getBasedir(), "target/test-classes/unit/warexplodedmojo/test-dir"); } @@ -935,4 +954,457 @@ public void testExplodedWarWithOutputFileNameMappingAndDuplicateDependencies() t expectedEJBArtifact.delete(); expectedEJBDupArtifact.delete(); } + + public void setUp() throws Exception { + super.setUp(); + + MavenExecutionRequest request = new DefaultMavenExecutionRequest() + .setSystemProperties(System.getProperties()) + .setStartTime(new Date()); + + MavenSession mavenSession = + new MavenSession((PlexusContainer) null, (RepositorySystemSession) null, request, null); + getContainer().addComponent(mavenSession, MavenSession.class.getName()); + mojo = (WarExplodedMojo) lookupMojo("exploded", getPomFile()); + } + + /** + * Configures the exploded mojo for the specified test. + * + * If the {@code sourceFiles} parameter is {@code null}, sample JSPs are created by default. + * + * @param testId the id of the test + * @param artifactStubs the dependencies (may be null) + * @param sourceFiles the source files to create (may be null) + * @return the webapp directory + * @throws Exception if an error occurs while configuring the mojo + */ + protected File setUpMojo(final String testId, ArtifactStub[] artifactStubs, String[] sourceFiles) throws Exception { + final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + final File webAppDirectory = new File(getTestDirectory(), testId); + + // Create the webapp sources + File webAppSource; + if (sourceFiles == null) { + webAppSource = createWebAppSource(testId); + } else { + webAppSource = createWebAppSource(testId, false); + for (String sourceFile : sourceFiles) { + File sample = new File(webAppSource, sourceFile); + createFile(sample); + } + } + + final File classesDir = createClassesDir(testId, true); + final File workDirectory = new File(getTestDirectory(), "/war/work-" + testId); + createDir(workDirectory); + + if (artifactStubs != null) { + for (ArtifactStub artifactStub : artifactStubs) { + project.addArtifact(artifactStub); + } + } + + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + setVariableValueToObject(mojo, "workDirectory", workDirectory); + + return webAppDirectory; + } + + /** + * Configures the exploded mojo for the specified test. + * + * @param testId the id of the test + * @param artifactStubs the dependencies (may be null) + * @return the webapp directory + * @throws Exception if an error occurs while configuring the mojo + */ + protected File setUpMojo(final String testId, ArtifactStub[] artifactStubs) throws Exception { + return setUpMojo(testId, artifactStubs, null); + } + + /** + * Cleans up a directory. + * + * @param directory the directory to remove + * @throws IOException if an error occurred while removing the directory + */ + protected void cleanDirectory(File directory) throws IOException { + if (directory != null && directory.isDirectory() && directory.exists()) { + FileUtils.deleteDirectory(directory); + } + } + + /** + * Asserts the default content of the war based on the specified webapp directory. + * + * @param webAppDirectory the webapp directory + * @return a list of File objects that have been asserted + */ + protected List assertDefaultContent(File webAppDirectory) { + // Validate content of the webapp + File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); + File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); + + assertTrue("source file not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); + assertTrue("source file not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); + + final List content = new ArrayList<>(); + content.add(expectedWebSourceFile); + content.add(expectedWebSource2File); + + return content; + } + + /** + * Asserts the web.xml file of the war based on the specified webapp directory. + * + * @param webAppDirectory the webapp directory + * @return a list with the web.xml File object + */ + protected List assertWebXml(File webAppDirectory) { + File expectedWEBXMLFile = new File(webAppDirectory, "WEB-INF/web.xml"); + assertTrue("web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists()); + + final List content = new ArrayList<>(); + content.add(expectedWEBXMLFile); + + return content; + } + + /** + * Asserts custom content of the war based on the specified webapp directory. + * + * @param webAppDirectory the webapp directory + * @param filePaths an array of file paths relative to the webapp directory + * @param customMessage a custom message if an assertion fails + * @return a list of File objects that have been inspected + */ + protected List assertCustomContent(File webAppDirectory, String[] filePaths, String customMessage) { + final List content = new ArrayList<>(); + for (String filePath : filePaths) { + final File expectedFile = new File(webAppDirectory, filePath); + if (customMessage != null) { + assertTrue(customMessage + " - " + expectedFile.toString(), expectedFile.exists()); + } else { + assertTrue("source file not found: " + expectedFile.toString(), expectedFile.exists()); + } + content.add(expectedFile); + } + return content; + } + + /** + * Asserts that the webapp contains only the specified files. + * + * @param webAppDirectory the webapp directory + * @param expectedFiles the expected files + * @param filter an optional filter to ignore some resources + */ + protected void assertWebAppContent(File webAppDirectory, List expectedFiles, FileFilter filter) { + final List webAppContent = new ArrayList<>(); + if (filter != null) { + buildFilesList(webAppDirectory, filter, webAppContent); + } else { + buildFilesList(webAppDirectory, new FileFilterImpl(webAppDirectory, null), webAppContent); + } + + // Now we have the files, sort them. + Collections.sort(expectedFiles); + Collections.sort(webAppContent); + assertEquals( + "Invalid webapp content, expected " + expectedFiles.size() + "file(s) " + expectedFiles + " but got " + + webAppContent.size() + " file(s) " + webAppContent, + expectedFiles, + webAppContent); + } + + /** + * Builds the list of files and directories from the specified dir. + * + * Note that the filter is not used the usual way. If the filter does not accept the current file, it's not added + * but yet the subdirectories are added if any. + * + * @param dir the base directory + * @param filter the filter + * @param content the current content, updated recursively + */ + private void buildFilesList(final File dir, FileFilter filter, final List content) { + final File[] files = dir.listFiles(); + + for (File file : files) { + // Add the file if the filter is ok with it + if (filter.accept(file)) { + content.add(file); + } + + // Even if the file is not accepted and is a directory, add it + if (file.isDirectory()) { + buildFilesList(file, filter, content); + } + } + } + + /** + * initialize required parameters + * + * @param mojo The mojo to be tested. + * @param classesDir The classes' directory. + * @param webAppSource The webAppSource. + * @param webAppDir The webAppDir folder. + * @param project The Maven project. + * @throws Exception in case of errors + */ + protected void configureMojo( + AbstractWarMojo mojo, File classesDir, File webAppSource, File webAppDir, MavenProjectBasicStub project) + throws Exception { + setVariableValueToObject(mojo, "outdatedCheckPath", "WEB-INF/lib/"); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDir); + mojo.setProject(project); + } + + /** + * create an isolated xml dir + * + * @param id The id. + * @param xmlFiles array of xml files. + * @return The created file. + * @throws Exception in case of errors. + */ + protected File createXMLConfigDir(String id, String[] xmlFiles) throws Exception { + File xmlConfigDir = new File(getTestDirectory(), "/" + id + "-test-data/xml-config"); + File xmlFile; + + createDir(xmlConfigDir); + + if (xmlFiles != null) { + for (String o : xmlFiles) { + xmlFile = new File(xmlConfigDir, o); + createFile(xmlFile); + } + } + + return xmlConfigDir; + } + + /** + * Returns the webapp source directory for the specified id. + * + * @param id the id of the test + * @return the source directory for that test + * @throws Exception if an exception occurs + */ + protected File getWebAppSource(String id) throws Exception { + return new File(getTestDirectory(), "/" + id + "-test-data/source"); + } + + /** + * create an isolated web source with a sample jsp file + * + * @param id The id. + * @param createSamples Create example files yes or no. + * @return The created file. + * @throws Exception in case of errors. + */ + protected File createWebAppSource(String id, boolean createSamples) throws Exception { + File webAppSource = getWebAppSource(id); + if (createSamples) { + File simpleJSP = new File(webAppSource, "pansit.jsp"); + File jspFile = new File(webAppSource, "org/web/app/last-exile.jsp"); + + createFile(simpleJSP); + createFile(jspFile); + } + return webAppSource; + } + + protected File createWebAppSource(String id) throws Exception { + return createWebAppSource(id, true); + } + + /** + * create a class directory with or without a sample class + * + * @param id The id. + * @param empty true to create a class files false otherwise. + * @return The created class file. + * @throws Exception in case of errors. + */ + protected File createClassesDir(String id, boolean empty) throws Exception { + File classesDir = new File(getTestDirectory() + "/" + id + "-test-data/classes/"); + + createDir(classesDir); + + if (!empty) { + createFile(new File(classesDir + "/sample-servlet.clazz")); + } + + return classesDir; + } + + protected void createDir(File dir) { + if (!dir.exists()) { + assertTrue("can not create test dir: " + dir.toString(), dir.mkdirs()); + } + } + + protected void createFile(File testFile, String body) throws Exception { + createDir(testFile.getParentFile()); + FileUtils.fileWrite(testFile.toString(), body); + + assertTrue("could not create file: " + testFile, testFile.exists()); + } + + protected void createFile(File testFile) throws Exception { + createFile(testFile, testFile.toString()); + } + + /** + * Generates test war. + * Generates war with such a structure: + *
    + *
  • jsp + *
      + *
    • d + *
        + *
      • a.jsp
      • + *
      • b.jsp
      • + *
      • c.jsp
      • + *
      + *
    • + *
    • a.jsp
    • + *
    • b.jsp
    • + *
    • c.jsp
    • + *
    + *
  • + *
  • WEB-INF + *
      + *
    • classes + *
        + *
      • a.clazz
      • + *
      • b.clazz
      • + *
      • c.clazz
      • + *
      + *
    • + *
    • lib + *
        + *
      • a.jar
      • + *
      • b.jar
      • + *
      • c.jar
      • + *
      + *
    • + *
    • web.xml
    • + *
    + *
  • + *
+ * Each of the files will contain: id+'-'+path + * + * @param id the id of the overlay containing the full structure + * @return the war file + * @throws Exception if an error occurs + */ + protected File generateFullOverlayWar(String id) throws Exception { + final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); + if (destFile.exists()) { + return destFile; + } + + // Archive was not yet created for that id so let's create it + final File rootDir = new File(OVERLAYS_ROOT_DIR, id); + rootDir.mkdirs(); + String[] filePaths = new String[] { + "jsp/d/a.jsp", + "jsp/d/b.jsp", + "jsp/d/c.jsp", + "jsp/a.jsp", + "jsp/b.jsp", + "jsp/c.jsp", + "WEB-INF/classes/a.clazz", + "WEB-INF/classes/b.clazz", + "WEB-INF/classes/c.clazz", + "WEB-INF/lib/a.jar", + "WEB-INF/lib/b.jar", + "WEB-INF/lib/c.jar", + "WEB-INF/web.xml" + }; + + for (String filePath : filePaths) { + createFile(new File(rootDir, filePath), id + "-" + filePath); + } + + createArchive(rootDir, destFile); + return destFile; + } + + /** + * Builds a test overlay. + * + * @param id the id of the overlay (see test/resources/overlays) + * @return a test war artifact with the content of the given test overlay + */ + protected ArtifactStub buildWarOverlayStub(String id) { + // Create war file + final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); + if (!destFile.exists()) { + createArchive(new File(OVERLAYS_ROOT_DIR, id), destFile); + } + + return new WarOverlayStub(getBasedir(), id, destFile); + } + + protected File getOverlayFile(String id, String filePath) { + final File overlayDir = new File(OVERLAYS_ROOT_DIR, id); + final File file = new File(overlayDir, filePath); + + // Make sure the file exists + assertTrue( + "Overlay file " + filePath + " does not exist for overlay " + id + " at " + file.getAbsolutePath(), + file.exists()); + return file; + } + + protected void createArchive(final File directory, final File destinationFile) { + try { + JarArchiver archiver = new JarArchiver(); + + archiver.setDestFile(destinationFile); + archiver.addDirectory(directory); + + archiver.createArchive(); + + } catch (ArchiverException e) { + e.printStackTrace(); + fail("Failed to create overlay archive " + e.getMessage()); + } catch (IOException e) { + e.printStackTrace(); + fail("Unexpected exception " + e.getMessage()); + } + } + + class FileFilterImpl implements FileFilter { + + private final List rejectedFilePaths; + + private final int webAppDirIndex; + + FileFilterImpl(File webAppDirectory, String[] rejectedFilePaths) { + if (rejectedFilePaths != null) { + this.rejectedFilePaths = Arrays.asList(rejectedFilePaths); + } else { + this.rejectedFilePaths = new ArrayList<>(); + } + this.webAppDirIndex = webAppDirectory.getAbsolutePath().length() + 1; + } + + public boolean accept(File file) { + String effectiveRelativePath = buildRelativePath(file); + return !(rejectedFilePaths.contains(effectiveRelativePath) || file.isDirectory()); + } + + private String buildRelativePath(File f) { + return f.getAbsolutePath().substring(webAppDirIndex); + } + } } diff --git a/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java index 41b563f4..bbd931ba 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java @@ -19,13 +19,29 @@ package org.apache.maven.plugins.war; import java.io.File; +import java.io.IOException; +import java.util.Date; +import org.apache.maven.execution.DefaultMavenExecutionRequest; +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.testing.AbstractMojoTestCase; +import org.apache.maven.plugin.testing.stubs.ArtifactStub; import org.apache.maven.plugins.war.stub.MavenProjectBasicStub; import org.apache.maven.plugins.war.stub.ResourceStub; +import org.apache.maven.plugins.war.stub.WarOverlayStub; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.archiver.ArchiverException; +import org.codehaus.plexus.archiver.jar.JarArchiver; +import org.codehaus.plexus.util.FileUtils; +import org.eclipse.aether.RepositorySystemSession; -public class WarInPlaceMojoTest extends AbstractWarMojoTest { +public class WarInPlaceMojoTest extends AbstractMojoTestCase { protected static final String POM_FILE_PATH = getBasedir() + "/target/test-classes/unit/warexplodedinplacemojo/plugin-config.xml"; + protected static final File OVERLAYS_TEMP_DIR = new File(getBasedir(), "target/test-overlays/"); + protected static final File OVERLAYS_ROOT_DIR = new File(getBasedir(), "target/test-classes/overlays/"); + protected static final String MANIFEST_PATH = "META-INF" + File.separator + "MANIFEST.MF"; protected File getTestDirectory() throws Exception { return new File(getBasedir(), "target/test-classes/unit/warexplodedinplacemojo/test-dir"); @@ -36,6 +52,14 @@ protected File getTestDirectory() throws Exception { public void setUp() throws Exception { super.setUp(); + MavenExecutionRequest request = new DefaultMavenExecutionRequest() + .setSystemProperties(System.getProperties()) + .setStartTime(new Date()); + + MavenSession mavenSession = + new MavenSession((PlexusContainer) null, (RepositorySystemSession) null, request, null); + getContainer().addComponent(mavenSession, MavenSession.class.getName()); + mojo = (WarInPlaceMojo) lookupMojo("inplace", POM_FILE_PATH); assertNotNull(mojo); } @@ -71,4 +95,242 @@ public void testSimpleExplodedInplaceWar() throws Exception { assertTrue("WEB-INF not found", expectedWEBINFDir.exists()); assertTrue("META-INF not found", expectedMETAINFDir.exists()); } + + /** + * initialize required parameters + * + * @param mojo The mojo to be tested. + * @param classesDir The classes' directory. + * @param webAppSource The webAppSource. + * @param webAppDir The webAppDir folder. + * @param project The Maven project. + * @throws Exception in case of errors + */ + protected void configureMojo( + AbstractWarMojo mojo, File classesDir, File webAppSource, File webAppDir, MavenProjectBasicStub project) + throws Exception { + setVariableValueToObject(mojo, "outdatedCheckPath", "WEB-INF/lib/"); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDir); + mojo.setProject(project); + } + + /** + * create an isolated xml dir + * + * @param id The id. + * @param xmlFiles array of xml files. + * @return The created file. + * @throws Exception in case of errors. + */ + protected File createXMLConfigDir(String id, String[] xmlFiles) throws Exception { + File xmlConfigDir = new File(getTestDirectory(), "/" + id + "-test-data/xml-config"); + File xmlFile; + + createDir(xmlConfigDir); + + if (xmlFiles != null) { + for (String o : xmlFiles) { + xmlFile = new File(xmlConfigDir, o); + createFile(xmlFile); + } + } + + return xmlConfigDir; + } + + /** + * Returns the webapp source directory for the specified id. + * + * @param id the id of the test + * @return the source directory for that test + * @throws Exception if an exception occurs + */ + protected File getWebAppSource(String id) throws Exception { + return new File(getTestDirectory(), "/" + id + "-test-data/source"); + } + + /** + * create an isolated web source with a sample jsp file + * + * @param id The id. + * @param createSamples Create example files yes or no. + * @return The created file. + * @throws Exception in case of errors. + */ + protected File createWebAppSource(String id, boolean createSamples) throws Exception { + File webAppSource = getWebAppSource(id); + if (createSamples) { + File simpleJSP = new File(webAppSource, "pansit.jsp"); + File jspFile = new File(webAppSource, "org/web/app/last-exile.jsp"); + + createFile(simpleJSP); + createFile(jspFile); + } + return webAppSource; + } + + protected File createWebAppSource(String id) throws Exception { + return createWebAppSource(id, true); + } + + /** + * create a class directory with or without a sample class + * + * @param id The id. + * @param empty true to create a class files false otherwise. + * @return The created class file. + * @throws Exception in case of errors. + */ + protected File createClassesDir(String id, boolean empty) throws Exception { + File classesDir = new File(getTestDirectory() + "/" + id + "-test-data/classes/"); + + createDir(classesDir); + + if (!empty) { + createFile(new File(classesDir + "/sample-servlet.clazz")); + } + + return classesDir; + } + + protected void createDir(File dir) { + if (!dir.exists()) { + assertTrue("can not create test dir: " + dir.toString(), dir.mkdirs()); + } + } + + protected void createFile(File testFile, String body) throws Exception { + createDir(testFile.getParentFile()); + FileUtils.fileWrite(testFile.toString(), body); + + assertTrue("could not create file: " + testFile, testFile.exists()); + } + + protected void createFile(File testFile) throws Exception { + createFile(testFile, testFile.toString()); + } + + /** + * Generates test war. + * Generates war with such a structure: + *
    + *
  • jsp + *
      + *
    • d + *
        + *
      • a.jsp
      • + *
      • b.jsp
      • + *
      • c.jsp
      • + *
      + *
    • + *
    • a.jsp
    • + *
    • b.jsp
    • + *
    • c.jsp
    • + *
    + *
  • + *
  • WEB-INF + *
      + *
    • classes + *
        + *
      • a.clazz
      • + *
      • b.clazz
      • + *
      • c.clazz
      • + *
      + *
    • + *
    • lib + *
        + *
      • a.jar
      • + *
      • b.jar
      • + *
      • c.jar
      • + *
      + *
    • + *
    • web.xml
    • + *
    + *
  • + *
+ * Each of the files will contain: id+'-'+path + * + * @param id the id of the overlay containing the full structure + * @return the war file + * @throws Exception if an error occurs + */ + protected File generateFullOverlayWar(String id) throws Exception { + final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); + if (destFile.exists()) { + return destFile; + } + + // Archive was not yet created for that id so let's create it + final File rootDir = new File(OVERLAYS_ROOT_DIR, id); + rootDir.mkdirs(); + String[] filePaths = new String[] { + "jsp/d/a.jsp", + "jsp/d/b.jsp", + "jsp/d/c.jsp", + "jsp/a.jsp", + "jsp/b.jsp", + "jsp/c.jsp", + "WEB-INF/classes/a.clazz", + "WEB-INF/classes/b.clazz", + "WEB-INF/classes/c.clazz", + "WEB-INF/lib/a.jar", + "WEB-INF/lib/b.jar", + "WEB-INF/lib/c.jar", + "WEB-INF/web.xml" + }; + + for (String filePath : filePaths) { + createFile(new File(rootDir, filePath), id + "-" + filePath); + } + + createArchive(rootDir, destFile); + return destFile; + } + + /** + * Builds a test overlay. + * + * @param id the id of the overlay (see test/resources/overlays) + * @return a test war artifact with the content of the given test overlay + */ + protected ArtifactStub buildWarOverlayStub(String id) { + // Create war file + final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); + if (!destFile.exists()) { + createArchive(new File(OVERLAYS_ROOT_DIR, id), destFile); + } + + return new WarOverlayStub(getBasedir(), id, destFile); + } + + protected File getOverlayFile(String id, String filePath) { + final File overlayDir = new File(OVERLAYS_ROOT_DIR, id); + final File file = new File(overlayDir, filePath); + + // Make sure the file exists + assertTrue( + "Overlay file " + filePath + " does not exist for overlay " + id + " at " + file.getAbsolutePath(), + file.exists()); + return file; + } + + protected void createArchive(final File directory, final File destinationFile) { + try { + JarArchiver archiver = new JarArchiver(); + + archiver.setDestFile(destinationFile); + archiver.addDirectory(directory); + + archiver.createArchive(); + + } catch (ArchiverException e) { + e.printStackTrace(); + fail("Failed to create overlay archive " + e.getMessage()); + } catch (IOException e) { + e.printStackTrace(); + fail("Unexpected exception " + e.getMessage()); + } + } } diff --git a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java index 2443fd13..4e0d0af1 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java @@ -20,6 +20,7 @@ import java.io.File; import java.io.IOException; +import java.util.Date; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; @@ -28,18 +29,33 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.execution.DefaultMavenExecutionRequest; +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.testing.AbstractMojoTestCase; +import org.apache.maven.plugin.testing.stubs.ArtifactStub; import org.apache.maven.plugins.war.stub.JarArtifactStub; import org.apache.maven.plugins.war.stub.MavenProject4CopyConstructor; import org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub; +import org.apache.maven.plugins.war.stub.MavenProjectBasicStub; import org.apache.maven.plugins.war.stub.ProjectHelperStub; import org.apache.maven.plugins.war.stub.WarArtifact4CCStub; +import org.apache.maven.plugins.war.stub.WarOverlayStub; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.archiver.ArchiverException; +import org.codehaus.plexus.archiver.jar.JarArchiver; +import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; +import org.eclipse.aether.RepositorySystemSession; /** * comprehensive test on buildExplodedWebApp is done on WarExplodedMojoTest */ -public class WarMojoTest extends AbstractWarMojoTest { +public class WarMojoTest extends AbstractMojoTestCase { + protected static final File OVERLAYS_TEMP_DIR = new File(getBasedir(), "target/test-overlays/"); + protected static final File OVERLAYS_ROOT_DIR = new File(getBasedir(), "target/test-classes/overlays/"); + protected static final String MANIFEST_PATH = "META-INF" + File.separator + "MANIFEST.MF"; WarMojo mojo; private static File pomFile = @@ -51,6 +67,14 @@ protected File getTestDirectory() { public void setUp() throws Exception { super.setUp(); + + MavenExecutionRequest request = new DefaultMavenExecutionRequest() + .setSystemProperties(System.getProperties()) + .setStartTime(new Date()); + + MavenSession mavenSession = + new MavenSession((PlexusContainer) null, (RepositorySystemSession) null, request, null); + getContainer().addComponent(mavenSession, MavenSession.class.getName()); mojo = (WarMojo) lookupMojo("war", pomFile); } @@ -581,4 +605,242 @@ protected Map assertJarContent( return jarContent; } } + + /** + * initialize required parameters + * + * @param mojo The mojo to be tested. + * @param classesDir The classes' directory. + * @param webAppSource The webAppSource. + * @param webAppDir The webAppDir folder. + * @param project The Maven project. + * @throws Exception in case of errors + */ + protected void configureMojo( + AbstractWarMojo mojo, File classesDir, File webAppSource, File webAppDir, MavenProjectBasicStub project) + throws Exception { + setVariableValueToObject(mojo, "outdatedCheckPath", "WEB-INF/lib/"); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDir); + mojo.setProject(project); + } + + /** + * create an isolated xml dir + * + * @param id The id. + * @param xmlFiles array of xml files. + * @return The created file. + * @throws Exception in case of errors. + */ + protected File createXMLConfigDir(String id, String[] xmlFiles) throws Exception { + File xmlConfigDir = new File(getTestDirectory(), "/" + id + "-test-data/xml-config"); + File xmlFile; + + createDir(xmlConfigDir); + + if (xmlFiles != null) { + for (String o : xmlFiles) { + xmlFile = new File(xmlConfigDir, o); + createFile(xmlFile); + } + } + + return xmlConfigDir; + } + + /** + * Returns the webapp source directory for the specified id. + * + * @param id the id of the test + * @return the source directory for that test + * @throws Exception if an exception occurs + */ + protected File getWebAppSource(String id) throws Exception { + return new File(getTestDirectory(), "/" + id + "-test-data/source"); + } + + /** + * create an isolated web source with a sample jsp file + * + * @param id The id. + * @param createSamples Create example files yes or no. + * @return The created file. + * @throws Exception in case of errors. + */ + protected File createWebAppSource(String id, boolean createSamples) throws Exception { + File webAppSource = getWebAppSource(id); + if (createSamples) { + File simpleJSP = new File(webAppSource, "pansit.jsp"); + File jspFile = new File(webAppSource, "org/web/app/last-exile.jsp"); + + createFile(simpleJSP); + createFile(jspFile); + } + return webAppSource; + } + + protected File createWebAppSource(String id) throws Exception { + return createWebAppSource(id, true); + } + + /** + * create a class directory with or without a sample class + * + * @param id The id. + * @param empty true to create a class files false otherwise. + * @return The created class file. + * @throws Exception in case of errors. + */ + protected File createClassesDir(String id, boolean empty) throws Exception { + File classesDir = new File(getTestDirectory() + "/" + id + "-test-data/classes/"); + + createDir(classesDir); + + if (!empty) { + createFile(new File(classesDir + "/sample-servlet.clazz")); + } + + return classesDir; + } + + protected void createDir(File dir) { + if (!dir.exists()) { + assertTrue("can not create test dir: " + dir.toString(), dir.mkdirs()); + } + } + + protected void createFile(File testFile, String body) throws Exception { + createDir(testFile.getParentFile()); + FileUtils.fileWrite(testFile.toString(), body); + + assertTrue("could not create file: " + testFile, testFile.exists()); + } + + protected void createFile(File testFile) throws Exception { + createFile(testFile, testFile.toString()); + } + + /** + * Generates test war. + * Generates war with such a structure: + *
    + *
  • jsp + *
      + *
    • d + *
        + *
      • a.jsp
      • + *
      • b.jsp
      • + *
      • c.jsp
      • + *
      + *
    • + *
    • a.jsp
    • + *
    • b.jsp
    • + *
    • c.jsp
    • + *
    + *
  • + *
  • WEB-INF + *
      + *
    • classes + *
        + *
      • a.clazz
      • + *
      • b.clazz
      • + *
      • c.clazz
      • + *
      + *
    • + *
    • lib + *
        + *
      • a.jar
      • + *
      • b.jar
      • + *
      • c.jar
      • + *
      + *
    • + *
    • web.xml
    • + *
    + *
  • + *
+ * Each of the files will contain: id+'-'+path + * + * @param id the id of the overlay containing the full structure + * @return the war file + * @throws Exception if an error occurs + */ + protected File generateFullOverlayWar(String id) throws Exception { + final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); + if (destFile.exists()) { + return destFile; + } + + // Archive was not yet created for that id so let's create it + final File rootDir = new File(OVERLAYS_ROOT_DIR, id); + rootDir.mkdirs(); + String[] filePaths = new String[] { + "jsp/d/a.jsp", + "jsp/d/b.jsp", + "jsp/d/c.jsp", + "jsp/a.jsp", + "jsp/b.jsp", + "jsp/c.jsp", + "WEB-INF/classes/a.clazz", + "WEB-INF/classes/b.clazz", + "WEB-INF/classes/c.clazz", + "WEB-INF/lib/a.jar", + "WEB-INF/lib/b.jar", + "WEB-INF/lib/c.jar", + "WEB-INF/web.xml" + }; + + for (String filePath : filePaths) { + createFile(new File(rootDir, filePath), id + "-" + filePath); + } + + createArchive(rootDir, destFile); + return destFile; + } + + /** + * Builds a test overlay. + * + * @param id the id of the overlay (see test/resources/overlays) + * @return a test war artifact with the content of the given test overlay + */ + protected ArtifactStub buildWarOverlayStub(String id) { + // Create war file + final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); + if (!destFile.exists()) { + createArchive(new File(OVERLAYS_ROOT_DIR, id), destFile); + } + + return new WarOverlayStub(getBasedir(), id, destFile); + } + + protected File getOverlayFile(String id, String filePath) { + final File overlayDir = new File(OVERLAYS_ROOT_DIR, id); + final File file = new File(overlayDir, filePath); + + // Make sure the file exists + assertTrue( + "Overlay file " + filePath + " does not exist for overlay " + id + " at " + file.getAbsolutePath(), + file.exists()); + return file; + } + + protected void createArchive(final File directory, final File destinationFile) { + try { + JarArchiver archiver = new JarArchiver(); + + archiver.setDestFile(destinationFile); + archiver.addDirectory(directory); + + archiver.createArchive(); + + } catch (ArchiverException e) { + e.printStackTrace(); + fail("Failed to create overlay archive " + e.getMessage()); + } catch (IOException e) { + e.printStackTrace(); + fail("Unexpected exception " + e.getMessage()); + } + } } diff --git a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java index 991711f8..a5f93a49 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java @@ -22,22 +22,49 @@ import java.io.FileFilter; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; import java.util.LinkedList; import java.util.List; +import org.apache.maven.execution.DefaultMavenExecutionRequest; +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.apache.maven.plugin.testing.stubs.ArtifactStub; import org.apache.maven.plugins.war.overlay.DefaultOverlay; +import org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub; +import org.apache.maven.plugins.war.stub.MavenProjectBasicStub; +import org.apache.maven.plugins.war.stub.WarOverlayStub; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.archiver.ArchiverException; +import org.codehaus.plexus.archiver.jar.JarArchiver; import org.codehaus.plexus.util.FileUtils; +import org.eclipse.aether.RepositorySystemSession; /** * @author Stephane Nicoll */ -public class WarOverlaysTest extends AbstractWarExplodedMojoTest { +public class WarOverlaysTest extends AbstractMojoTestCase { + protected static final File OVERLAYS_TEMP_DIR = new File(getBasedir(), "target/test-overlays/"); + protected static final File OVERLAYS_ROOT_DIR = new File(getBasedir(), "target/test-classes/overlays/"); + protected static final String MANIFEST_PATH = "META-INF" + File.separator + "MANIFEST.MF"; private static File pomFile = new File(getBasedir(), "target/test-classes/unit/waroverlays/default.xml"); + protected WarExplodedMojo mojo; public void setUp() throws Exception { super.setUp(); + + MavenExecutionRequest request = new DefaultMavenExecutionRequest() + .setSystemProperties(System.getProperties()) + .setStartTime(new Date()); + + MavenSession mavenSession = + new MavenSession((PlexusContainer) null, (RepositorySystemSession) null, request, null); + getContainer().addComponent(mavenSession, MavenSession.class.getName()); + mojo = (WarExplodedMojo) lookupMojo("exploded", getPomFile()); generateFullOverlayWar("overlay-full-1"); generateFullOverlayWar("overlay-full-2"); generateFullOverlayWar("overlay-full-3"); @@ -473,4 +500,444 @@ protected void assertDefaultFileContent(String testId, File webAppDirectory, Str final String expectedContent = sourceFile.toString(); assertEquals("Wrong content for file " + filePath, expectedContent, FileUtils.fileRead(webAppFile)); } + + /** + * Configures the exploded mojo for the specified test. + * + * If the {@code sourceFiles} parameter is {@code null}, sample JSPs are created by default. + * + * @param testId the id of the test + * @param artifactStubs the dependencies (may be null) + * @param sourceFiles the source files to create (may be null) + * @return the webapp directory + * @throws Exception if an error occurs while configuring the mojo + */ + protected File setUpMojo(final String testId, ArtifactStub[] artifactStubs, String[] sourceFiles) throws Exception { + final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + final File webAppDirectory = new File(getTestDirectory(), testId); + + // Create the webapp sources + File webAppSource; + if (sourceFiles == null) { + webAppSource = createWebAppSource(testId); + } else { + webAppSource = createWebAppSource(testId, false); + for (String sourceFile : sourceFiles) { + File sample = new File(webAppSource, sourceFile); + createFile(sample); + } + } + + final File classesDir = createClassesDir(testId, true); + final File workDirectory = new File(getTestDirectory(), "/war/work-" + testId); + createDir(workDirectory); + + if (artifactStubs != null) { + for (ArtifactStub artifactStub : artifactStubs) { + project.addArtifact(artifactStub); + } + } + + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + setVariableValueToObject(mojo, "workDirectory", workDirectory); + + return webAppDirectory; + } + + /** + * Configures the exploded mojo for the specified test. + * + * @param testId the id of the test + * @param artifactStubs the dependencies (may be null) + * @return the webapp directory + * @throws Exception if an error occurs while configuring the mojo + */ + protected File setUpMojo(final String testId, ArtifactStub[] artifactStubs) throws Exception { + return setUpMojo(testId, artifactStubs, null); + } + + /** + * Cleans up a directory. + * + * @param directory the directory to remove + * @throws IOException if an error occurred while removing the directory + */ + protected void cleanDirectory(File directory) throws IOException { + if (directory != null && directory.isDirectory() && directory.exists()) { + FileUtils.deleteDirectory(directory); + } + } + + /** + * Asserts the default content of the war based on the specified webapp directory. + * + * @param webAppDirectory the webapp directory + * @return a list of File objects that have been asserted + */ + protected List assertDefaultContent(File webAppDirectory) { + // Validate content of the webapp + File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); + File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); + + assertTrue("source file not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); + assertTrue("source file not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); + + final List content = new ArrayList<>(); + content.add(expectedWebSourceFile); + content.add(expectedWebSource2File); + + return content; + } + + /** + * Asserts the web.xml file of the war based on the specified webapp directory. + * + * @param webAppDirectory the webapp directory + * @return a list with the web.xml File object + */ + protected List assertWebXml(File webAppDirectory) { + File expectedWEBXMLFile = new File(webAppDirectory, "WEB-INF/web.xml"); + assertTrue("web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists()); + + final List content = new ArrayList<>(); + content.add(expectedWEBXMLFile); + + return content; + } + + /** + * Asserts custom content of the war based on the specified webapp directory. + * + * @param webAppDirectory the webapp directory + * @param filePaths an array of file paths relative to the webapp directory + * @param customMessage a custom message if an assertion fails + * @return a list of File objects that have been inspected + */ + protected List assertCustomContent(File webAppDirectory, String[] filePaths, String customMessage) { + final List content = new ArrayList<>(); + for (String filePath : filePaths) { + final File expectedFile = new File(webAppDirectory, filePath); + if (customMessage != null) { + assertTrue(customMessage + " - " + expectedFile.toString(), expectedFile.exists()); + } else { + assertTrue("source file not found: " + expectedFile.toString(), expectedFile.exists()); + } + content.add(expectedFile); + } + return content; + } + + /** + * Asserts that the webapp contains only the specified files. + * + * @param webAppDirectory the webapp directory + * @param expectedFiles the expected files + * @param filter an optional filter to ignore some resources + */ + protected void assertWebAppContent(File webAppDirectory, List expectedFiles, FileFilter filter) { + final List webAppContent = new ArrayList<>(); + if (filter != null) { + buildFilesList(webAppDirectory, filter, webAppContent); + } else { + buildFilesList(webAppDirectory, new FileFilterImpl(webAppDirectory, null), webAppContent); + } + + // Now we have the files, sort them. + Collections.sort(expectedFiles); + Collections.sort(webAppContent); + assertEquals( + "Invalid webapp content, expected " + expectedFiles.size() + "file(s) " + expectedFiles + " but got " + + webAppContent.size() + " file(s) " + webAppContent, + expectedFiles, + webAppContent); + } + + /** + * Builds the list of files and directories from the specified dir. + * + * Note that the filter is not used the usual way. If the filter does not accept the current file, it's not added + * but yet the subdirectories are added if any. + * + * @param dir the base directory + * @param filter the filter + * @param content the current content, updated recursively + */ + private void buildFilesList(final File dir, FileFilter filter, final List content) { + final File[] files = dir.listFiles(); + + for (File file : files) { + // Add the file if the filter is ok with it + if (filter.accept(file)) { + content.add(file); + } + + // Even if the file is not accepted and is a directory, add it + if (file.isDirectory()) { + buildFilesList(file, filter, content); + } + } + } + + /** + * initialize required parameters + * + * @param mojo The mojo to be tested. + * @param classesDir The classes' directory. + * @param webAppSource The webAppSource. + * @param webAppDir The webAppDir folder. + * @param project The Maven project. + * @throws Exception in case of errors + */ + protected void configureMojo( + AbstractWarMojo mojo, File classesDir, File webAppSource, File webAppDir, MavenProjectBasicStub project) + throws Exception { + setVariableValueToObject(mojo, "outdatedCheckPath", "WEB-INF/lib/"); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDir); + mojo.setProject(project); + } + + /** + * create an isolated xml dir + * + * @param id The id. + * @param xmlFiles array of xml files. + * @return The created file. + * @throws Exception in case of errors. + */ + protected File createXMLConfigDir(String id, String[] xmlFiles) throws Exception { + File xmlConfigDir = new File(getTestDirectory(), "/" + id + "-test-data/xml-config"); + File xmlFile; + + createDir(xmlConfigDir); + + if (xmlFiles != null) { + for (String o : xmlFiles) { + xmlFile = new File(xmlConfigDir, o); + createFile(xmlFile); + } + } + + return xmlConfigDir; + } + + /** + * Returns the webapp source directory for the specified id. + * + * @param id the id of the test + * @return the source directory for that test + * @throws Exception if an exception occurs + */ + protected File getWebAppSource(String id) throws Exception { + return new File(getTestDirectory(), "/" + id + "-test-data/source"); + } + + /** + * create an isolated web source with a sample jsp file + * + * @param id The id. + * @param createSamples Create example files yes or no. + * @return The created file. + * @throws Exception in case of errors. + */ + protected File createWebAppSource(String id, boolean createSamples) throws Exception { + File webAppSource = getWebAppSource(id); + if (createSamples) { + File simpleJSP = new File(webAppSource, "pansit.jsp"); + File jspFile = new File(webAppSource, "org/web/app/last-exile.jsp"); + + createFile(simpleJSP); + createFile(jspFile); + } + return webAppSource; + } + + protected File createWebAppSource(String id) throws Exception { + return createWebAppSource(id, true); + } + + /** + * create a class directory with or without a sample class + * + * @param id The id. + * @param empty true to create a class files false otherwise. + * @return The created class file. + * @throws Exception in case of errors. + */ + protected File createClassesDir(String id, boolean empty) throws Exception { + File classesDir = new File(getTestDirectory() + "/" + id + "-test-data/classes/"); + + createDir(classesDir); + + if (!empty) { + createFile(new File(classesDir + "/sample-servlet.clazz")); + } + + return classesDir; + } + + protected void createDir(File dir) { + if (!dir.exists()) { + assertTrue("can not create test dir: " + dir.toString(), dir.mkdirs()); + } + } + + protected void createFile(File testFile, String body) throws Exception { + createDir(testFile.getParentFile()); + FileUtils.fileWrite(testFile.toString(), body); + + assertTrue("could not create file: " + testFile, testFile.exists()); + } + + protected void createFile(File testFile) throws Exception { + createFile(testFile, testFile.toString()); + } + + /** + * Generates test war. + * Generates war with such a structure: + *
    + *
  • jsp + *
      + *
    • d + *
        + *
      • a.jsp
      • + *
      • b.jsp
      • + *
      • c.jsp
      • + *
      + *
    • + *
    • a.jsp
    • + *
    • b.jsp
    • + *
    • c.jsp
    • + *
    + *
  • + *
  • WEB-INF + *
      + *
    • classes + *
        + *
      • a.clazz
      • + *
      • b.clazz
      • + *
      • c.clazz
      • + *
      + *
    • + *
    • lib + *
        + *
      • a.jar
      • + *
      • b.jar
      • + *
      • c.jar
      • + *
      + *
    • + *
    • web.xml
    • + *
    + *
  • + *
+ * Each of the files will contain: id+'-'+path + * + * @param id the id of the overlay containing the full structure + * @return the war file + * @throws Exception if an error occurs + */ + protected File generateFullOverlayWar(String id) throws Exception { + final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); + if (destFile.exists()) { + return destFile; + } + + // Archive was not yet created for that id so let's create it + final File rootDir = new File(OVERLAYS_ROOT_DIR, id); + rootDir.mkdirs(); + String[] filePaths = new String[] { + "jsp/d/a.jsp", + "jsp/d/b.jsp", + "jsp/d/c.jsp", + "jsp/a.jsp", + "jsp/b.jsp", + "jsp/c.jsp", + "WEB-INF/classes/a.clazz", + "WEB-INF/classes/b.clazz", + "WEB-INF/classes/c.clazz", + "WEB-INF/lib/a.jar", + "WEB-INF/lib/b.jar", + "WEB-INF/lib/c.jar", + "WEB-INF/web.xml" + }; + + for (String filePath : filePaths) { + createFile(new File(rootDir, filePath), id + "-" + filePath); + } + + createArchive(rootDir, destFile); + return destFile; + } + + /** + * Builds a test overlay. + * + * @param id the id of the overlay (see test/resources/overlays) + * @return a test war artifact with the content of the given test overlay + */ + protected ArtifactStub buildWarOverlayStub(String id) { + // Create war file + final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); + if (!destFile.exists()) { + createArchive(new File(OVERLAYS_ROOT_DIR, id), destFile); + } + + return new WarOverlayStub(getBasedir(), id, destFile); + } + + protected File getOverlayFile(String id, String filePath) { + final File overlayDir = new File(OVERLAYS_ROOT_DIR, id); + final File file = new File(overlayDir, filePath); + + // Make sure the file exists + assertTrue( + "Overlay file " + filePath + " does not exist for overlay " + id + " at " + file.getAbsolutePath(), + file.exists()); + return file; + } + + protected void createArchive(final File directory, final File destinationFile) { + try { + JarArchiver archiver = new JarArchiver(); + + archiver.setDestFile(destinationFile); + archiver.addDirectory(directory); + + archiver.createArchive(); + + } catch (ArchiverException e) { + e.printStackTrace(); + fail("Failed to create overlay archive " + e.getMessage()); + } catch (IOException e) { + e.printStackTrace(); + fail("Unexpected exception " + e.getMessage()); + } + } + + class FileFilterImpl implements FileFilter { + + private final List rejectedFilePaths; + + private final int webAppDirIndex; + + FileFilterImpl(File webAppDirectory, String[] rejectedFilePaths) { + if (rejectedFilePaths != null) { + this.rejectedFilePaths = Arrays.asList(rejectedFilePaths); + } else { + this.rejectedFilePaths = new ArrayList<>(); + } + this.webAppDirIndex = webAppDirectory.getAbsolutePath().length() + 1; + } + + public boolean accept(File file) { + String effectiveRelativePath = buildRelativePath(file); + return !(rejectedFilePaths.contains(effectiveRelativePath) || file.isDirectory()); + } + + private String buildRelativePath(File f) { + return f.getAbsolutePath().substring(webAppDirIndex); + } + } } diff --git a/src/test/java/org/apache/maven/plugins/war/WarZipTest.java b/src/test/java/org/apache/maven/plugins/war/WarZipTest.java index a68d2784..e0537187 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarZipTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarZipTest.java @@ -19,20 +19,36 @@ package org.apache.maven.plugins.war; import java.io.File; +import java.io.IOException; +import java.util.Date; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.execution.DefaultMavenExecutionRequest; +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.testing.AbstractMojoTestCase; +import org.apache.maven.plugin.testing.stubs.ArtifactStub; import org.apache.maven.plugins.war.overlay.DefaultOverlay; +import org.apache.maven.plugins.war.stub.MavenProjectBasicStub; import org.apache.maven.plugins.war.stub.MavenZipProject; import org.apache.maven.plugins.war.stub.WarArtifactStub; +import org.apache.maven.plugins.war.stub.WarOverlayStub; import org.apache.maven.plugins.war.stub.ZipArtifactStub; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.archiver.ArchiverException; +import org.codehaus.plexus.archiver.jar.JarArchiver; import org.codehaus.plexus.util.FileUtils; +import org.eclipse.aether.RepositorySystemSession; /** * @author Olivier Lamy * @since 7 Oct 07 */ -public class WarZipTest extends AbstractWarMojoTest { +public class WarZipTest extends AbstractMojoTestCase { + protected static final File OVERLAYS_TEMP_DIR = new File(getBasedir(), "target/test-overlays/"); + protected static final File OVERLAYS_ROOT_DIR = new File(getBasedir(), "target/test-classes/overlays/"); + protected static final String MANIFEST_PATH = "META-INF" + File.separator + "MANIFEST.MF"; WarMojo mojo; private static File pomFile = new File(getBasedir(), "src/test/resources/unit/warziptest/war-with-zip.xml"); @@ -43,6 +59,14 @@ protected File getTestDirectory() { public void setUp() throws Exception { super.setUp(); + + MavenExecutionRequest request = new DefaultMavenExecutionRequest() + .setSystemProperties(System.getProperties()) + .setStartTime(new Date()); + + MavenSession mavenSession = + new MavenSession((PlexusContainer) null, (RepositorySystemSession) null, request, null); + getContainer().addComponent(mavenSession, MavenSession.class.getName()); mojo = (WarMojo) lookupMojo("war", pomFile); } @@ -157,4 +181,242 @@ protected void assertZipContentNotHere(File webAppDirectory) { assertFalse("bar/bar.txt exists", bar.exists()); assertFalse("bar/bar.txt is a file", bar.isFile()); } + + /** + * initialize required parameters + * + * @param mojo The mojo to be tested. + * @param classesDir The classes' directory. + * @param webAppSource The webAppSource. + * @param webAppDir The webAppDir folder. + * @param project The Maven project. + * @throws Exception in case of errors + */ + protected void configureMojo( + AbstractWarMojo mojo, File classesDir, File webAppSource, File webAppDir, MavenProjectBasicStub project) + throws Exception { + setVariableValueToObject(mojo, "outdatedCheckPath", "WEB-INF/lib/"); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDir); + mojo.setProject(project); + } + + /** + * create an isolated xml dir + * + * @param id The id. + * @param xmlFiles array of xml files. + * @return The created file. + * @throws Exception in case of errors. + */ + protected File createXMLConfigDir(String id, String[] xmlFiles) throws Exception { + File xmlConfigDir = new File(getTestDirectory(), "/" + id + "-test-data/xml-config"); + File xmlFile; + + createDir(xmlConfigDir); + + if (xmlFiles != null) { + for (String o : xmlFiles) { + xmlFile = new File(xmlConfigDir, o); + createFile(xmlFile); + } + } + + return xmlConfigDir; + } + + /** + * Returns the webapp source directory for the specified id. + * + * @param id the id of the test + * @return the source directory for that test + * @throws Exception if an exception occurs + */ + protected File getWebAppSource(String id) throws Exception { + return new File(getTestDirectory(), "/" + id + "-test-data/source"); + } + + /** + * create an isolated web source with a sample jsp file + * + * @param id The id. + * @param createSamples Create example files yes or no. + * @return The created file. + * @throws Exception in case of errors. + */ + protected File createWebAppSource(String id, boolean createSamples) throws Exception { + File webAppSource = getWebAppSource(id); + if (createSamples) { + File simpleJSP = new File(webAppSource, "pansit.jsp"); + File jspFile = new File(webAppSource, "org/web/app/last-exile.jsp"); + + createFile(simpleJSP); + createFile(jspFile); + } + return webAppSource; + } + + protected File createWebAppSource(String id) throws Exception { + return createWebAppSource(id, true); + } + + /** + * create a class directory with or without a sample class + * + * @param id The id. + * @param empty true to create a class files false otherwise. + * @return The created class file. + * @throws Exception in case of errors. + */ + protected File createClassesDir(String id, boolean empty) throws Exception { + File classesDir = new File(getTestDirectory() + "/" + id + "-test-data/classes/"); + + createDir(classesDir); + + if (!empty) { + createFile(new File(classesDir + "/sample-servlet.clazz")); + } + + return classesDir; + } + + protected void createDir(File dir) { + if (!dir.exists()) { + assertTrue("can not create test dir: " + dir.toString(), dir.mkdirs()); + } + } + + protected void createFile(File testFile, String body) throws Exception { + createDir(testFile.getParentFile()); + FileUtils.fileWrite(testFile.toString(), body); + + assertTrue("could not create file: " + testFile, testFile.exists()); + } + + protected void createFile(File testFile) throws Exception { + createFile(testFile, testFile.toString()); + } + + /** + * Generates test war. + * Generates war with such a structure: + *
    + *
  • jsp + *
      + *
    • d + *
        + *
      • a.jsp
      • + *
      • b.jsp
      • + *
      • c.jsp
      • + *
      + *
    • + *
    • a.jsp
    • + *
    • b.jsp
    • + *
    • c.jsp
    • + *
    + *
  • + *
  • WEB-INF + *
      + *
    • classes + *
        + *
      • a.clazz
      • + *
      • b.clazz
      • + *
      • c.clazz
      • + *
      + *
    • + *
    • lib + *
        + *
      • a.jar
      • + *
      • b.jar
      • + *
      • c.jar
      • + *
      + *
    • + *
    • web.xml
    • + *
    + *
  • + *
+ * Each of the files will contain: id+'-'+path + * + * @param id the id of the overlay containing the full structure + * @return the war file + * @throws Exception if an error occurs + */ + protected File generateFullOverlayWar(String id) throws Exception { + final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); + if (destFile.exists()) { + return destFile; + } + + // Archive was not yet created for that id so let's create it + final File rootDir = new File(OVERLAYS_ROOT_DIR, id); + rootDir.mkdirs(); + String[] filePaths = new String[] { + "jsp/d/a.jsp", + "jsp/d/b.jsp", + "jsp/d/c.jsp", + "jsp/a.jsp", + "jsp/b.jsp", + "jsp/c.jsp", + "WEB-INF/classes/a.clazz", + "WEB-INF/classes/b.clazz", + "WEB-INF/classes/c.clazz", + "WEB-INF/lib/a.jar", + "WEB-INF/lib/b.jar", + "WEB-INF/lib/c.jar", + "WEB-INF/web.xml" + }; + + for (String filePath : filePaths) { + createFile(new File(rootDir, filePath), id + "-" + filePath); + } + + createArchive(rootDir, destFile); + return destFile; + } + + /** + * Builds a test overlay. + * + * @param id the id of the overlay (see test/resources/overlays) + * @return a test war artifact with the content of the given test overlay + */ + protected ArtifactStub buildWarOverlayStub(String id) { + // Create war file + final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); + if (!destFile.exists()) { + createArchive(new File(OVERLAYS_ROOT_DIR, id), destFile); + } + + return new WarOverlayStub(getBasedir(), id, destFile); + } + + protected File getOverlayFile(String id, String filePath) { + final File overlayDir = new File(OVERLAYS_ROOT_DIR, id); + final File file = new File(overlayDir, filePath); + + // Make sure the file exists + assertTrue( + "Overlay file " + filePath + " does not exist for overlay " + id + " at " + file.getAbsolutePath(), + file.exists()); + return file; + } + + protected void createArchive(final File directory, final File destinationFile) { + try { + JarArchiver archiver = new JarArchiver(); + + archiver.setDestFile(destinationFile); + archiver.addDirectory(directory); + + archiver.createArchive(); + + } catch (ArchiverException e) { + e.printStackTrace(); + fail("Failed to create overlay archive " + e.getMessage()); + } catch (IOException e) { + e.printStackTrace(); + fail("Unexpected exception " + e.getMessage()); + } + } } From 6ee57d8f49108d8ff66430f31a58a180619e4dd4 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 5 Nov 2025 10:14:25 +0100 Subject: [PATCH 02/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarMojoTest --- pom.xml | 12 +- .../apache/maven/plugins/war/WarMojoTest.java | 1059 +++++++++-------- 2 files changed, 554 insertions(+), 517 deletions(-) diff --git a/pom.xml b/pom.xml index 59add894..7be25eff 100644 --- a/pom.xml +++ b/pom.xml @@ -208,12 +208,12 @@ ${mavenVersion} test - - junit - junit - 4.13.2 - test - + + + + + + org.junit.jupiter junit-jupiter-api diff --git a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java index 4e0d0af1..20ffe189 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java @@ -18,81 +18,93 @@ */ package org.apache.maven.plugins.war; +import javax.inject.Inject; + import java.io.File; import java.io.IOException; -import java.util.Date; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; import java.util.jar.JarEntry; import java.util.jar.JarFile; -import org.apache.maven.artifact.Artifact; +import org.apache.maven.api.di.Provides; +import org.apache.maven.api.plugin.testing.InjectMojo; +import org.apache.maven.api.plugin.testing.MojoParameter; +import org.apache.maven.api.plugin.testing.MojoTest; import org.apache.maven.artifact.handler.ArtifactHandler; -import org.apache.maven.execution.DefaultMavenExecutionRequest; -import org.apache.maven.execution.MavenExecutionRequest; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.testing.AbstractMojoTestCase; -import org.apache.maven.plugin.testing.stubs.ArtifactStub; -import org.apache.maven.plugins.war.stub.JarArtifactStub; import org.apache.maven.plugins.war.stub.MavenProject4CopyConstructor; -import org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub; import org.apache.maven.plugins.war.stub.MavenProjectBasicStub; import org.apache.maven.plugins.war.stub.ProjectHelperStub; import org.apache.maven.plugins.war.stub.WarArtifact4CCStub; -import org.apache.maven.plugins.war.stub.WarOverlayStub; -import org.codehaus.plexus.PlexusContainer; +import org.apache.maven.project.MavenProjectHelper; import org.codehaus.plexus.archiver.ArchiverException; import org.codehaus.plexus.archiver.jar.JarArchiver; +import org.codehaus.plexus.testing.PlexusExtension; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; -import org.eclipse.aether.RepositorySystemSession; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * comprehensive test on buildExplodedWebApp is done on WarExplodedMojoTest */ -public class WarMojoTest extends AbstractMojoTestCase { - protected static final File OVERLAYS_TEMP_DIR = new File(getBasedir(), "target/test-overlays/"); - protected static final File OVERLAYS_ROOT_DIR = new File(getBasedir(), "target/test-classes/overlays/"); +@MojoTest +public class WarMojoTest { + + @Inject + private MavenProjectHelper projectHelper; + + @Inject + private ArtifactHandler artifactHandler; + // protected static final File OVERLAYS_TEMP_DIR = new File(getBasedir(), "target/test-overlays/"); + // protected static final File OVERLAYS_ROOT_DIR = new File(getBasedir(), "target/test-classes/overlays/"); protected static final String MANIFEST_PATH = "META-INF" + File.separator + "MANIFEST.MF"; - WarMojo mojo; - private static File pomFile = - new File(getBasedir(), "target/test-classes/unit/warmojotest/plugin-config-primary-artifact.xml"); + // private static File pomFile = + // new File(getBasedir(), "target/test-classes/unit/warmojotest/plugin-config-primary-artifact.xml"); protected File getTestDirectory() { - return new File(getBasedir(), "target/test-classes/unit/warmojotest"); + return new File(PlexusExtension.getBasedir(), "target/test-classes/unit/warmojotest"); } + @BeforeEach public void setUp() throws Exception { - super.setUp(); - - MavenExecutionRequest request = new DefaultMavenExecutionRequest() - .setSystemProperties(System.getProperties()) - .setStartTime(new Date()); - - MavenSession mavenSession = - new MavenSession((PlexusContainer) null, (RepositorySystemSession) null, request, null); - getContainer().addComponent(mavenSession, MavenSession.class.getName()); - mojo = (WarMojo) lookupMojo("war", pomFile); + // MavenExecutionRequest request = new DefaultMavenExecutionRequest() + // .setSystemProperties(System.getProperties()) + // .setStartTime(new Date()); + + // MavenSession mavenSession = + // new MavenSession((PlexusContainer) null, (RepositorySystemSession) null, request, null); + // getContainer().addComponent(mavenSession, MavenSession.class.getName()); + // mojo = (WarMojo) lookupMojo("war", pomFile); } - public void testSimpleWar() throws Exception { + @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") + @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWar-output") + @MojoParameter(name = "warName", value = "simple") + @Test + public void testSimpleWar(WarMojo mojo) throws Exception { String testId = "SimpleWar"; MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - String warName = "simple"; + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(PlexusExtension.getBasedir()); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); project.setArtifact(warArtifact); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "outputDirectory", outputDir); - setVariableValueToObject(mojo, "warName", warName); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); mojo.setWebXml(new File(xmlSource, "web.xml")); mojo.execute(); @@ -112,24 +124,27 @@ public void testSimpleWar() throws Exception { new String[] {null, mojo.getWebXml().toString(), null, null, null, null}); } - public void testSimpleWarPackagingExcludeWithIncludesRegEx() throws Exception { + @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") + @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-output") + @MojoParameter(name = "warName", value = "simple") + @MojoParameter(name = "packagingIncludes", value = "%regex[(.(?!exile))+]") + @Test + public void testSimpleWarPackagingExcludeWithIncludesRegEx(WarMojo mojo) throws Exception { String testId = "SimpleWarPackagingExcludeWithIncludesRegEx"; MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - String warName = "simple"; + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(PlexusExtension.getBasedir()); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); project.setArtifact(warArtifact); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "outputDirectory", outputDir); - setVariableValueToObject(mojo, "warName", warName); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); mojo.setWebXml(new File(xmlSource, "web.xml")); - setVariableValueToObject(mojo, "packagingIncludes", "%regex[(.(?!exile))+]"); - // setVariableValueToObject( mojo, "packagingIncludes", "%regex" ); mojo.execute(); @@ -149,24 +164,27 @@ public void testSimpleWarPackagingExcludeWithIncludesRegEx() throws Exception { }, new String[] {"org/web/app/last-exile.jsp"}); } - - public void testSimpleWarPackagingExcludesWithRegEx() throws Exception { + @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") + @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-output") + @MojoParameter(name = "warName", value = "simple") + @MojoParameter(name = "packagingExcludes", value = "%regex[.+/last-exile.+]") + @Test + public void testSimpleWarPackagingExcludesWithRegEx(WarMojo mojo) throws Exception { String testId = "SimpleWarPackagingExcludesWithRegEx"; MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - String warName = "simple"; + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(PlexusExtension.getBasedir()); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); project.setArtifact(warArtifact); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "outputDirectory", outputDir); - setVariableValueToObject(mojo, "warName", warName); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); mojo.setWebXml(new File(xmlSource, "web.xml")); - setVariableValueToObject(mojo, "packagingExcludes", "%regex[.+/last-exile.+]"); mojo.execute(); @@ -187,24 +205,26 @@ public void testSimpleWarPackagingExcludesWithRegEx() throws Exception { new String[] {"org/web/app/last-exile.jsp"}); } - public void testClassifier() throws Exception { + @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") + @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/Classifier-output") + @MojoParameter(name = "classifier", value = "test-classifier") + @MojoParameter(name = "warName", value = "simple") + @Test + public void testClassifier(WarMojo mojo) throws Exception { String testId = "Classifier"; MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - ProjectHelperStub projectHelper = new ProjectHelperStub(); - String warName = "simple"; + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(PlexusExtension.getBasedir()); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); project.setArtifact(warArtifact); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "projectHelper", projectHelper); - setVariableValueToObject(mojo, "classifier", "test-classifier"); - setVariableValueToObject(mojo, "outputDirectory", outputDir); - setVariableValueToObject(mojo, "warName", warName); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); mojo.setWebXml(new File(xmlSource, "web.xml")); mojo.execute(); @@ -224,344 +244,360 @@ public void testClassifier() throws Exception { new String[] {null, mojo.getWebXml().toString(), null, null, null, null}); } - public void testPrimaryArtifact() throws Exception { - String testId = "PrimaryArtifact"; - MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; - File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - ProjectHelperStub projectHelper = new ProjectHelperStub(); - String warName = "simple"; - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - - warArtifact.setFile(new File("error.war")); - project.setArtifact(warArtifact); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "projectHelper", projectHelper); - setVariableValueToObject(mojo, "outputDirectory", outputDir); - setVariableValueToObject(mojo, "warName", warName); - mojo.setWebXml(new File(xmlSource, "web.xml")); - - mojo.execute(); - - // validate jar file - File expectedJarFile = new File(outputDir, "simple.war"); - assertJarContent( - expectedJarFile, - new String[] { - "META-INF/MANIFEST.MF", - "WEB-INF/web.xml", - "pansit.jsp", - "org/web/app/last-exile.jsp", - "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", - "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" - }, - new String[] {null, mojo.getWebXml().toString(), null, null, null, null}); - } - - public void testNotPrimaryArtifact() throws Exception { - // use a different pom - File pom = new File(getBasedir(), "target/test-classes/unit/warmojotest/not-primary-artifact.xml"); - mojo = (WarMojo) lookupMojo("war", pom); - - String testId = "NotPrimaryArtifact"; - MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; - File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - ProjectHelperStub projectHelper = new ProjectHelperStub(); - String warName = "simple"; - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - - warArtifact.setFile(new File("error.war")); - project.setArtifact(warArtifact); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "projectHelper", projectHelper); - setVariableValueToObject(mojo, "outputDirectory", outputDir); - setVariableValueToObject(mojo, "warName", warName); - mojo.setWebXml(new File(xmlSource, "web.xml")); - - mojo.execute(); - - // validate jar file - File expectedJarFile = new File(outputDir, "simple.war"); - assertJarContent( - expectedJarFile, - new String[] { - "META-INF/MANIFEST.MF", - "WEB-INF/web.xml", - "pansit.jsp", - "org/web/app/last-exile.jsp", - "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", - "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" - }, - new String[] {null, mojo.getWebXml().toString(), null, null, null, null}); - } - - public void testMetaInfContent() throws Exception { - String testId = "SimpleWarWithMetaInfContent"; - MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; - File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - String warName = "simple"; - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - - // Create the sample config.xml - final File configFile = new File(webAppSource, "META-INF/config.xml"); - createFile(configFile, ""); - - project.setArtifact(warArtifact); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "outputDirectory", outputDir); - setVariableValueToObject(mojo, "warName", warName); - mojo.setWebXml(new File(xmlSource, "web.xml")); - - mojo.execute(); - - // validate jar file - File expectedJarFile = new File(outputDir, "simple.war"); - assertJarContent( - expectedJarFile, - new String[] { - "META-INF/MANIFEST.MF", - "META-INF/config.xml", - "WEB-INF/web.xml", - "pansit.jsp", - "org/web/app/last-exile.jsp", - "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", - "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" - }, - new String[] {null, null, mojo.getWebXml().toString(), null, null, null, null}); - } - - public void testMetaInfContentWithContainerConfig() throws Exception { - String testId = "SimpleWarWithContainerConfig"; - MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; - File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - String warName = "simple"; - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - - // Create the sample config.xml - final File configFile = new File(webAppSource, "META-INF/config.xml"); - createFile(configFile, ""); - - project.setArtifact(warArtifact); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "outputDirectory", outputDir); - setVariableValueToObject(mojo, "warName", warName); - mojo.setWebXml(new File(xmlSource, "web.xml")); - mojo.setContainerConfigXML(configFile); - - mojo.execute(); - - // validate jar file - File expectedJarFile = new File(outputDir, "simple.war"); - assertJarContent( - expectedJarFile, - new String[] { - "META-INF/MANIFEST.MF", - "META-INF/config.xml", - "WEB-INF/web.xml", - "pansit.jsp", - "org/web/app/last-exile.jsp", - "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", - "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" - }, - new String[] {null, null, mojo.getWebXml().toString(), null, null, null, null}); - } - - public void testFailOnMissingWebXmlFalse() throws Exception { - - String testId = "SimpleWarMissingWebXmlFalse"; - MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; - File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - String warName = "simple"; - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - - project.setArtifact(warArtifact); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "outputDirectory", outputDir); - setVariableValueToObject(mojo, "warName", warName); - mojo.setFailOnMissingWebXml(false); - mojo.execute(); - - // validate jar file - File expectedJarFile = new File(outputDir, "simple.war"); - final Map jarContent = assertJarContent( - expectedJarFile, - new String[] { - "META-INF/MANIFEST.MF", - "pansit.jsp", - "org/web/app/last-exile.jsp", - "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", - "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" - }, - new String[] {null, null, null, null, null}); - - assertFalse("web.xml should be missing", jarContent.containsKey("WEB-INF/web.xml")); - } - - public void testFailOnMissingWebXmlTrue() throws Exception { - - String testId = "SimpleWarMissingWebXmlTrue"; - MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; - File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - String warName = "simple"; - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - - project.setArtifact(warArtifact); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "outputDirectory", outputDir); - setVariableValueToObject(mojo, "warName", warName); - mojo.setFailOnMissingWebXml(true); - - try { - mojo.execute(); - fail("Building of the war isn't possible because web.xml is missing"); - } catch (MojoExecutionException e) { - // expected behaviour - } - } - - public void testFailOnMissingWebXmlNotSpecifiedAndServlet30Used() throws Exception { - String testId = "SimpleWarUnderServlet30"; - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; - File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - String warName = "simple"; - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - - final ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar"); - JarArtifactStub jarArtifactStub = new JarArtifactStub(getBasedir(), artifactHandler); - jarArtifactStub.setFile( - new File(getBasedir(), "/target/test-classes/unit/sample_wars/javax.servlet-api-3.0.1.jar")); - jarArtifactStub.setScope(Artifact.SCOPE_PROVIDED); - project.addArtifact(jarArtifactStub); - - project.setArtifact(warArtifact); - project.setFile(warArtifact.getFile()); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "outputDirectory", outputDir); - setVariableValueToObject(mojo, "warName", warName); - - mojo.execute(); - - // validate war file - File expectedWarFile = new File(outputDir, "simple.war"); - final Map jarContent = assertJarContent( - expectedWarFile, - new String[] { - "META-INF/MANIFEST.MF", - "pansit.jsp", - "org/web/app/last-exile.jsp", - "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", - "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" - }, - new String[] {null, null, null, null, null}); - - assertFalse("web.xml should be missing", jarContent.containsKey("WEB-INF/web.xml")); + @Provides + private MavenProjectHelper projectHelper() { + return new ProjectHelperStub(); } - - public void testFailOnMissingWebXmlNotSpecifiedAndServlet30NotUsed() throws Exception { - String testId = "SimpleWarNotUnderServlet30"; - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; - File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - String warName = "simple"; - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - - project.setArtifact(warArtifact); - project.setFile(warArtifact.getFile()); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "outputDirectory", outputDir); - setVariableValueToObject(mojo, "warName", warName); - - try { - mojo.execute(); - fail("Building of the war isn't possible because no 'failOnMissingWebXml' policy was set and the project " - + "does not depend on Servlet 3.0"); - } catch (MojoExecutionException e) { - // expected behaviour - } - } - - public void testAttachClasses() throws Exception { - String testId = "AttachClasses"; - MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; - File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - String warName = "simple"; - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, false); - File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - - project.setArtifact(warArtifact); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "outputDirectory", outputDir); - setVariableValueToObject(mojo, "warName", warName); - mojo.setWebXml(new File(xmlSource, "web.xml")); - mojo.setAttachClasses(true); - mojo.setClassesClassifier("classes"); - - mojo.execute(); - - // validate jar file - File expectedJarFile = new File(outputDir, "simple-classes.jar"); - assertJarContent( - expectedJarFile, new String[] {"META-INF/MANIFEST.MF", "sample-servlet.clazz"}, new String[] {null, null - }); - } - - public void testAttachClassesWithCustomClassifier() throws Exception { - String testId = "AttachClassesCustomClassifier"; - MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; - File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - String warName = "simple"; - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, false); - File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - - project.setArtifact(warArtifact); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "outputDirectory", outputDir); - setVariableValueToObject(mojo, "warName", warName); - mojo.setWebXml(new File(xmlSource, "web.xml")); - mojo.setAttachClasses(true); - mojo.setClassesClassifier("mystuff"); - - mojo.execute(); - - // validate jar file - File expectedJarFile = new File(outputDir, "simple-mystuff.jar"); - assertJarContent( - expectedJarFile, new String[] {"META-INF/MANIFEST.MF", "sample-servlet.clazz"}, new String[] {null, null - }); - } - + // + // @MojoParameter(name = "outputDirectory", value = "outputDir") + // @MojoParameter(name = "warName", value = "warName") + // @Test + // public void testPrimaryArtifact() throws Exception { + // String testId = "PrimaryArtifact"; + // MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + // String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + // File webAppDirectory = new File(getTestDirectory(), testId); + // WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + // ProjectHelperStub projectHelper = new ProjectHelperStub(); + // String warName = "simple"; + // File webAppSource = createWebAppSource(testId); + // File classesDir = createClassesDir(testId, true); + // File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); + // + // warArtifact.setFile(new File("error.war")); + // project.setArtifact(warArtifact); + // this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + // setVariableValueToObject(mojo, "projectHelper", projectHelper); + // mojo.setWebXml(new File(xmlSource, "web.xml")); + // + // mojo.execute(); + // + // // validate jar file + // File expectedJarFile = new File(outputDir, "simple.war"); + // assertJarContent( + // expectedJarFile, + // new String[] { + // "META-INF/MANIFEST.MF", + // "WEB-INF/web.xml", + // "pansit.jsp", + // "org/web/app/last-exile.jsp", + // "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", + // "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" + // }, + // new String[] {null, mojo.getWebXml().toString(), null, null, null, null}); + // } + // + // @MojoParameter(name = "outputDirectory", value = "outputDir") + // @MojoParameter(name = "warName", value = "warName") + // @Test + // public void testNotPrimaryArtifact() throws Exception { + // // use a different pom + // File pom = new File(getBasedir(), "target/test-classes/unit/warmojotest/not-primary-artifact.xml"); + // mojo = (WarMojo) lookupMojo("war", pom); + // + // String testId = "NotPrimaryArtifact"; + // MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + // String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + // File webAppDirectory = new File(getTestDirectory(), testId); + // WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + // ProjectHelperStub projectHelper = new ProjectHelperStub(); + // String warName = "simple"; + // File webAppSource = createWebAppSource(testId); + // File classesDir = createClassesDir(testId, true); + // File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); + // + // warArtifact.setFile(new File("error.war")); + // project.setArtifact(warArtifact); + // this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + // setVariableValueToObject(mojo, "projectHelper", projectHelper); + // mojo.setWebXml(new File(xmlSource, "web.xml")); + // + // mojo.execute(); + // + // // validate jar file + // File expectedJarFile = new File(outputDir, "simple.war"); + // assertJarContent( + // expectedJarFile, + // new String[] { + // "META-INF/MANIFEST.MF", + // "WEB-INF/web.xml", + // "pansit.jsp", + // "org/web/app/last-exile.jsp", + // "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", + // "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" + // }, + // new String[] {null, mojo.getWebXml().toString(), null, null, null, null}); + // } + // + // @MojoParameter(name = "outputDirectory", value = "outputDir") + // @MojoParameter(name = "warName", value = "warName") + // @Test + // public void testMetaInfContent() throws Exception { + // String testId = "SimpleWarWithMetaInfContent"; + // MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + // String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + // File webAppDirectory = new File(getTestDirectory(), testId); + // WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + // String warName = "simple"; + // File webAppSource = createWebAppSource(testId); + // File classesDir = createClassesDir(testId, true); + // File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); + // + // // Create the sample config.xml + // final File configFile = new File(webAppSource, "META-INF/config.xml"); + // createFile(configFile, ""); + // + // project.setArtifact(warArtifact); + // this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + // mojo.setWebXml(new File(xmlSource, "web.xml")); + // + // mojo.execute(); + // + // // validate jar file + // File expectedJarFile = new File(outputDir, "simple.war"); + // assertJarContent( + // expectedJarFile, + // new String[] { + // "META-INF/MANIFEST.MF", + // "META-INF/config.xml", + // "WEB-INF/web.xml", + // "pansit.jsp", + // "org/web/app/last-exile.jsp", + // "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", + // "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" + // }, + // new String[] {null, null, mojo.getWebXml().toString(), null, null, null, null}); + // } + // + // @MojoParameter(name = "outputDirectory", value = "outputDir") + // @MojoParameter(name = "warName", value = "warName") + // @Test + // public void testMetaInfContentWithContainerConfig() throws Exception { + // String testId = "SimpleWarWithContainerConfig"; + // MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + // String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + // File webAppDirectory = new File(getTestDirectory(), testId); + // WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + // String warName = "simple"; + // File webAppSource = createWebAppSource(testId); + // File classesDir = createClassesDir(testId, true); + // File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); + // + // // Create the sample config.xml + // final File configFile = new File(webAppSource, "META-INF/config.xml"); + // createFile(configFile, ""); + // + // project.setArtifact(warArtifact); + // this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + // mojo.setWebXml(new File(xmlSource, "web.xml")); + // mojo.setContainerConfigXML(configFile); + // + // mojo.execute(); + // + // // validate jar file + // File expectedJarFile = new File(outputDir, "simple.war"); + // assertJarContent( + // expectedJarFile, + // new String[] { + // "META-INF/MANIFEST.MF", + // "META-INF/config.xml", + // "WEB-INF/web.xml", + // "pansit.jsp", + // "org/web/app/last-exile.jsp", + // "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", + // "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" + // }, + // new String[] {null, null, mojo.getWebXml().toString(), null, null, null, null}); + // } + // + // @MojoParameter(name = "outputDirectory", value = "outputDir") + // @MojoParameter(name = "warName", value = "warName") + // @Test + // public void testFailOnMissingWebXmlFalse() throws Exception { + // + // String testId = "SimpleWarMissingWebXmlFalse"; + // MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + // String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + // File webAppDirectory = new File(getTestDirectory(), testId); + // WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + // String warName = "simple"; + // File webAppSource = createWebAppSource(testId); + // File classesDir = createClassesDir(testId, true); + // + // project.setArtifact(warArtifact); + // this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + // mojo.setFailOnMissingWebXml(false); + // mojo.execute(); + // + // // validate jar file + // File expectedJarFile = new File(outputDir, "simple.war"); + // final Map jarContent = assertJarContent( + // expectedJarFile, + // new String[] { + // "META-INF/MANIFEST.MF", + // "pansit.jsp", + // "org/web/app/last-exile.jsp", + // "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", + // "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" + // }, + // new String[] {null, null, null, null, null}); + // + // assertFalse(jarContent.containsKey("WEB-INF/web.xml"), "web.xml should be missing"); + // } + // + // @MojoParameter(name = "outputDirectory", value = "outputDir") + // @MojoParameter(name = "warName", value = "warName") + // @Test + // public void testFailOnMissingWebXmlTrue() throws Exception { + // + // String testId = "SimpleWarMissingWebXmlTrue"; + // MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + // String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + // File webAppDirectory = new File(getTestDirectory(), testId); + // WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + // String warName = "simple"; + // File webAppSource = createWebAppSource(testId); + // File classesDir = createClassesDir(testId, true); + // + // project.setArtifact(warArtifact); + // this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + // mojo.setFailOnMissingWebXml(true); + // + // try { + // mojo.execute(); + // fail("Building of the war isn't possible because web.xml is missing"); + // } catch (MojoExecutionException e) { + // // expected behaviour + // } + // } + // + // @MojoParameter(name = "outputDirectory", value = "outputDir") + // @MojoParameter(name = "warName", value = "warName") + // @Test + // public void testFailOnMissingWebXmlNotSpecifiedAndServlet30Used() throws Exception { + // String testId = "SimpleWarUnderServlet30"; + // MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + // String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + // File webAppDirectory = new File(getTestDirectory(), testId); + // WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + // String warName = "simple"; + // File webAppSource = createWebAppSource(testId); + // File classesDir = createClassesDir(testId, true); + // JarArtifactStub jarArtifactStub = new JarArtifactStub(getBasedir(), artifactHandler); + // jarArtifactStub.setFile( + // new File(getBasedir(), "/target/test-classes/unit/sample_wars/javax.servlet-api-3.0.1.jar")); + // jarArtifactStub.setScope(Artifact.SCOPE_PROVIDED); + // project.addArtifact(jarArtifactStub); + // + // project.setArtifact(warArtifact); + // project.setFile(warArtifact.getFile()); + // this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + // + // mojo.execute(); + // + // // validate war file + // File expectedWarFile = new File(outputDir, "simple.war"); + // final Map jarContent = assertJarContent( + // expectedWarFile, + // new String[] { + // "META-INF/MANIFEST.MF", + // "pansit.jsp", + // "org/web/app/last-exile.jsp", + // "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", + // "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" + // }, + // new String[] {null, null, null, null, null}); + // + // assertFalse(jarContent.containsKey("WEB-INF/web.xml"), "web.xml should be missing"); + // } + // + // @MojoParameter(name = "outputDirectory", value = "outputDir") + // @MojoParameter(name = "warName", value = "warName") + // @Test + // public void testFailOnMissingWebXmlNotSpecifiedAndServlet30NotUsed() throws Exception { + // String testId = "SimpleWarNotUnderServlet30"; + // MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + // String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + // File webAppDirectory = new File(getTestDirectory(), testId); + // WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + // String warName = "simple"; + // File webAppSource = createWebAppSource(testId); + // File classesDir = createClassesDir(testId, true); + // + // project.setArtifact(warArtifact); + // project.setFile(warArtifact.getFile()); + // this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + // + // try { + // mojo.execute(); + // fail("Building of the war isn't possible because no 'failOnMissingWebXml' policy was set and the + // project " + // + "does not depend on Servlet 3.0"); + // } catch (MojoExecutionException e) { + // // expected behaviour + // } + // } + // + // @MojoParameter(name = "outputDirectory", value = "outputDir") + // @MojoParameter(name = "warName", value = "warName") + // @Test + // public void testAttachClasses() throws Exception { + // String testId = "AttachClasses"; + // MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + // String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + // File webAppDirectory = new File(getTestDirectory(), testId); + // WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + // String warName = "simple"; + // File webAppSource = createWebAppSource(testId); + // File classesDir = createClassesDir(testId, false); + // File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); + // + // project.setArtifact(warArtifact); + // this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + // mojo.setWebXml(new File(xmlSource, "web.xml")); + // mojo.setAttachClasses(true); + // mojo.setClassesClassifier("classes"); + // + // mojo.execute(); + // + // // validate jar file + // File expectedJarFile = new File(outputDir, "simple-classes.jar"); + // assertJarContent( + // expectedJarFile, new String[] {"META-INF/MANIFEST.MF", "sample-servlet.clazz"}, new String[] + // {null, null + // }); + // } + // + // @MojoParameter(name = "outputDirectory", value = "outputDir") + // @MojoParameter(name = "warName", value = "warName") + // @Test + // public void testAttachClassesWithCustomClassifier() throws Exception { + // String testId = "AttachClassesCustomClassifier"; + // MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + // String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + // File webAppDirectory = new File(getTestDirectory(), testId); + // WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + // String warName = "simple"; + // File webAppSource = createWebAppSource(testId); + // File classesDir = createClassesDir(testId, false); + // File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); + // + // project.setArtifact(warArtifact); + // this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + // mojo.setWebXml(new File(xmlSource, "web.xml")); + // mojo.setAttachClasses(true); + // mojo.setClassesClassifier("mystuff"); + // + // mojo.execute(); + // + // // validate jar file + // File expectedJarFile = new File(outputDir, "simple-mystuff.jar"); + // assertJarContent( + // expectedJarFile, new String[] {"META-INF/MANIFEST.MF", "sample-servlet.clazz"}, new String[] + // {null, null + // }); + // } + // protected Map assertJarContent( final File expectedJarFile, final String[] files, final String[] filesContent) throws IOException { return assertJarContent(expectedJarFile, files, filesContent, null); @@ -574,32 +610,32 @@ protected Map assertJarContent( final String[] mustNotBeInJar) throws IOException { // Sanity check - assertEquals("Could not test, files and filesContent length does not match", files.length, filesContent.length); + assertEquals(files.length, filesContent.length, "Could not test, files and filesContent length does not match"); - assertTrue("war file not created: " + expectedJarFile.toString(), expectedJarFile.exists()); + assertTrue(expectedJarFile.exists(), "war file not created: " + expectedJarFile.toString()); final Map jarContent = new HashMap<>(); try (JarFile jarFile = new JarFile(expectedJarFile)) { Enumeration enumeration = jarFile.entries(); while (enumeration.hasMoreElements()) { JarEntry entry = enumeration.nextElement(); Object previousValue = jarContent.put(entry.getName(), entry); - assertNull("Duplicate Entry in Jar File: " + entry.getName(), previousValue); + assertNull(previousValue, "Duplicate Entry in Jar File: " + entry.getName()); } for (int i = 0; i < files.length; i++) { String file = files[i]; - assertTrue("File[" + file + "] not found in archive", jarContent.containsKey(file)); + assertTrue(jarContent.containsKey(file), "File[" + file + "] not found in archive"); if (filesContent[i] != null) { assertEquals( - "Content of file[" + file + "] does not match", filesContent[i], - IOUtil.toString(jarFile.getInputStream(jarContent.get(file)))); + IOUtil.toString(jarFile.getInputStream(jarContent.get(file))), + "Content of file[" + file + "] does not match"); } } if (mustNotBeInJar != null) { for (String file : mustNotBeInJar) { - assertFalse("File[" + file + "] found in archive", jarContent.containsKey(file)); + assertFalse(jarContent.containsKey(file), "File[" + file + "] found in archive"); } } return jarContent; @@ -616,10 +652,10 @@ protected Map assertJarContent( * @param project The Maven project. * @throws Exception in case of errors */ + @MojoParameter(name = "outdatedCheckPath", value = "WEB-INF/lib/") protected void configureMojo( AbstractWarMojo mojo, File classesDir, File webAppSource, File webAppDir, MavenProjectBasicStub project) throws Exception { - setVariableValueToObject(mojo, "outdatedCheckPath", "WEB-INF/lib/"); mojo.setClassesDirectory(classesDir); mojo.setWarSourceDirectory(webAppSource); mojo.setWebappDirectory(webAppDir); @@ -707,7 +743,7 @@ protected File createClassesDir(String id, boolean empty) throws Exception { protected void createDir(File dir) { if (!dir.exists()) { - assertTrue("can not create test dir: " + dir.toString(), dir.mkdirs()); + assertTrue(dir.mkdirs(), "can not create test dir: " + dir.toString()); } } @@ -715,116 +751,117 @@ protected void createFile(File testFile, String body) throws Exception { createDir(testFile.getParentFile()); FileUtils.fileWrite(testFile.toString(), body); - assertTrue("could not create file: " + testFile, testFile.exists()); + assertTrue(testFile.exists(), "could not create file: " + testFile); } protected void createFile(File testFile) throws Exception { createFile(testFile, testFile.toString()); } - /** - * Generates test war. - * Generates war with such a structure: - *
    - *
  • jsp - *
      - *
    • d - *
        - *
      • a.jsp
      • - *
      • b.jsp
      • - *
      • c.jsp
      • - *
      - *
    • - *
    • a.jsp
    • - *
    • b.jsp
    • - *
    • c.jsp
    • - *
    - *
  • - *
  • WEB-INF - *
      - *
    • classes - *
        - *
      • a.clazz
      • - *
      • b.clazz
      • - *
      • c.clazz
      • - *
      - *
    • - *
    • lib - *
        - *
      • a.jar
      • - *
      • b.jar
      • - *
      • c.jar
      • - *
      - *
    • - *
    • web.xml
    • - *
    - *
  • - *
- * Each of the files will contain: id+'-'+path - * - * @param id the id of the overlay containing the full structure - * @return the war file - * @throws Exception if an error occurs - */ - protected File generateFullOverlayWar(String id) throws Exception { - final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); - if (destFile.exists()) { - return destFile; - } - - // Archive was not yet created for that id so let's create it - final File rootDir = new File(OVERLAYS_ROOT_DIR, id); - rootDir.mkdirs(); - String[] filePaths = new String[] { - "jsp/d/a.jsp", - "jsp/d/b.jsp", - "jsp/d/c.jsp", - "jsp/a.jsp", - "jsp/b.jsp", - "jsp/c.jsp", - "WEB-INF/classes/a.clazz", - "WEB-INF/classes/b.clazz", - "WEB-INF/classes/c.clazz", - "WEB-INF/lib/a.jar", - "WEB-INF/lib/b.jar", - "WEB-INF/lib/c.jar", - "WEB-INF/web.xml" - }; - - for (String filePath : filePaths) { - createFile(new File(rootDir, filePath), id + "-" + filePath); - } - - createArchive(rootDir, destFile); - return destFile; - } - - /** - * Builds a test overlay. - * - * @param id the id of the overlay (see test/resources/overlays) - * @return a test war artifact with the content of the given test overlay - */ - protected ArtifactStub buildWarOverlayStub(String id) { - // Create war file - final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); - if (!destFile.exists()) { - createArchive(new File(OVERLAYS_ROOT_DIR, id), destFile); - } - - return new WarOverlayStub(getBasedir(), id, destFile); - } - - protected File getOverlayFile(String id, String filePath) { - final File overlayDir = new File(OVERLAYS_ROOT_DIR, id); - final File file = new File(overlayDir, filePath); - - // Make sure the file exists - assertTrue( - "Overlay file " + filePath + " does not exist for overlay " + id + " at " + file.getAbsolutePath(), - file.exists()); - return file; - } + // /** + // * Generates test war. + // * Generates war with such a structure: + // *
    + // *
  • jsp + // *
      + // *
    • d + // *
        + // *
      • a.jsp
      • + // *
      • b.jsp
      • + // *
      • c.jsp
      • + // *
      + // *
    • + // *
    • a.jsp
    • + // *
    • b.jsp
    • + // *
    • c.jsp
    • + // *
    + // *
  • + // *
  • WEB-INF + // *
      + // *
    • classes + // *
        + // *
      • a.clazz
      • + // *
      • b.clazz
      • + // *
      • c.clazz
      • + // *
      + // *
    • + // *
    • lib + // *
        + // *
      • a.jar
      • + // *
      • b.jar
      • + // *
      • c.jar
      • + // *
      + // *
    • + // *
    • web.xml
    • + // *
    + // *
  • + // *
+ // * Each of the files will contain: id+'-'+path + // * + // * @param id the id of the overlay containing the full structure + // * @return the war file + // * @throws Exception if an error occurs + // */ + // protected File generateFullOverlayWar(String id) throws Exception { + // final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); + // if (destFile.exists()) { + // return destFile; + // } + // + // // Archive was not yet created for that id so let's create it + // final File rootDir = new File(OVERLAYS_ROOT_DIR, id); + // rootDir.mkdirs(); + // String[] filePaths = new String[] { + // "jsp/d/a.jsp", + // "jsp/d/b.jsp", + // "jsp/d/c.jsp", + // "jsp/a.jsp", + // "jsp/b.jsp", + // "jsp/c.jsp", + // "WEB-INF/classes/a.clazz", + // "WEB-INF/classes/b.clazz", + // "WEB-INF/classes/c.clazz", + // "WEB-INF/lib/a.jar", + // "WEB-INF/lib/b.jar", + // "WEB-INF/lib/c.jar", + // "WEB-INF/web.xml" + // }; + // + // for (String filePath : filePaths) { + // createFile(new File(rootDir, filePath), id + "-" + filePath); + // } + // + // createArchive(rootDir, destFile); + // return destFile; + // } + // + // /** + // * Builds a test overlay. + // * + // * @param id the id of the overlay (see test/resources/overlays) + // * @return a test war artifact with the content of the given test overlay + // */ + // protected ArtifactStub buildWarOverlayStub(String id) { + // // Create war file + // final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); + // if (!destFile.exists()) { + // createArchive(new File(OVERLAYS_ROOT_DIR, id), destFile); + // } + // + // return new WarOverlayStub(getBasedir(), id, destFile); + // } + // + // protected File getOverlayFile(String id, String filePath) { + // final File overlayDir = new File(OVERLAYS_ROOT_DIR, id); + // final File file = new File(overlayDir, filePath); + // + // // Make sure the file exists + // assertTrue( + // file.exists(), + // "Overlay file " + filePath + " does not exist for overlay " + id + " at " + + // file.getAbsolutePath()); + // return file; + // } protected void createArchive(final File directory, final File destinationFile) { try { From f1fcd89a863f090003e2a6cfce2936bfa4712a3a Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 5 Nov 2025 10:32:47 +0100 Subject: [PATCH 03/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarMojoTest --- .../apache/maven/plugins/war/WarMojoTest.java | 738 +++++++++--------- 1 file changed, 382 insertions(+), 356 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java index 20ffe189..8cfdf868 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java @@ -32,20 +32,25 @@ import org.apache.maven.api.plugin.testing.InjectMojo; import org.apache.maven.api.plugin.testing.MojoParameter; import org.apache.maven.api.plugin.testing.MojoTest; +import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.war.stub.JarArtifactStub; import org.apache.maven.plugins.war.stub.MavenProject4CopyConstructor; +import org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub; import org.apache.maven.plugins.war.stub.MavenProjectBasicStub; import org.apache.maven.plugins.war.stub.ProjectHelperStub; import org.apache.maven.plugins.war.stub.WarArtifact4CCStub; import org.apache.maven.project.MavenProjectHelper; import org.codehaus.plexus.archiver.ArchiverException; import org.codehaus.plexus.archiver.jar.JarArchiver; -import org.codehaus.plexus.testing.PlexusExtension; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; @@ -71,7 +76,7 @@ public class WarMojoTest { // new File(getBasedir(), "target/test-classes/unit/warmojotest/plugin-config-primary-artifact.xml"); protected File getTestDirectory() { - return new File(PlexusExtension.getBasedir(), "target/test-classes/unit/warmojotest"); + return new File(getBasedir(), "target/test-classes/unit/warmojotest"); } @BeforeEach @@ -95,7 +100,7 @@ public void testSimpleWar(WarMojo mojo) throws Exception { MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(PlexusExtension.getBasedir()); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); @@ -134,7 +139,7 @@ public void testSimpleWarPackagingExcludeWithIncludesRegEx(WarMojo mojo) throws MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(PlexusExtension.getBasedir()); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); @@ -174,7 +179,7 @@ public void testSimpleWarPackagingExcludesWithRegEx(WarMojo mojo) throws Excepti MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(PlexusExtension.getBasedir()); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); @@ -215,7 +220,7 @@ public void testClassifier(WarMojo mojo) throws Exception { MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(PlexusExtension.getBasedir()); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); @@ -248,356 +253,377 @@ public void testClassifier(WarMojo mojo) throws Exception { private MavenProjectHelper projectHelper() { return new ProjectHelperStub(); } - // - // @MojoParameter(name = "outputDirectory", value = "outputDir") - // @MojoParameter(name = "warName", value = "warName") - // @Test - // public void testPrimaryArtifact() throws Exception { - // String testId = "PrimaryArtifact"; - // MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - // String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; - // File webAppDirectory = new File(getTestDirectory(), testId); - // WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - // ProjectHelperStub projectHelper = new ProjectHelperStub(); - // String warName = "simple"; - // File webAppSource = createWebAppSource(testId); - // File classesDir = createClassesDir(testId, true); - // File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - // - // warArtifact.setFile(new File("error.war")); - // project.setArtifact(warArtifact); - // this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - // setVariableValueToObject(mojo, "projectHelper", projectHelper); - // mojo.setWebXml(new File(xmlSource, "web.xml")); - // - // mojo.execute(); - // - // // validate jar file - // File expectedJarFile = new File(outputDir, "simple.war"); - // assertJarContent( - // expectedJarFile, - // new String[] { - // "META-INF/MANIFEST.MF", - // "WEB-INF/web.xml", - // "pansit.jsp", - // "org/web/app/last-exile.jsp", - // "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", - // "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" - // }, - // new String[] {null, mojo.getWebXml().toString(), null, null, null, null}); - // } - // - // @MojoParameter(name = "outputDirectory", value = "outputDir") - // @MojoParameter(name = "warName", value = "warName") - // @Test - // public void testNotPrimaryArtifact() throws Exception { - // // use a different pom - // File pom = new File(getBasedir(), "target/test-classes/unit/warmojotest/not-primary-artifact.xml"); - // mojo = (WarMojo) lookupMojo("war", pom); - // - // String testId = "NotPrimaryArtifact"; - // MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - // String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; - // File webAppDirectory = new File(getTestDirectory(), testId); - // WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - // ProjectHelperStub projectHelper = new ProjectHelperStub(); - // String warName = "simple"; - // File webAppSource = createWebAppSource(testId); - // File classesDir = createClassesDir(testId, true); - // File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - // - // warArtifact.setFile(new File("error.war")); - // project.setArtifact(warArtifact); - // this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - // setVariableValueToObject(mojo, "projectHelper", projectHelper); - // mojo.setWebXml(new File(xmlSource, "web.xml")); - // - // mojo.execute(); - // - // // validate jar file - // File expectedJarFile = new File(outputDir, "simple.war"); - // assertJarContent( - // expectedJarFile, - // new String[] { - // "META-INF/MANIFEST.MF", - // "WEB-INF/web.xml", - // "pansit.jsp", - // "org/web/app/last-exile.jsp", - // "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", - // "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" - // }, - // new String[] {null, mojo.getWebXml().toString(), null, null, null, null}); - // } - // - // @MojoParameter(name = "outputDirectory", value = "outputDir") - // @MojoParameter(name = "warName", value = "warName") - // @Test - // public void testMetaInfContent() throws Exception { - // String testId = "SimpleWarWithMetaInfContent"; - // MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - // String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; - // File webAppDirectory = new File(getTestDirectory(), testId); - // WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - // String warName = "simple"; - // File webAppSource = createWebAppSource(testId); - // File classesDir = createClassesDir(testId, true); - // File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - // - // // Create the sample config.xml - // final File configFile = new File(webAppSource, "META-INF/config.xml"); - // createFile(configFile, ""); - // - // project.setArtifact(warArtifact); - // this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - // mojo.setWebXml(new File(xmlSource, "web.xml")); - // - // mojo.execute(); - // - // // validate jar file - // File expectedJarFile = new File(outputDir, "simple.war"); - // assertJarContent( - // expectedJarFile, - // new String[] { - // "META-INF/MANIFEST.MF", - // "META-INF/config.xml", - // "WEB-INF/web.xml", - // "pansit.jsp", - // "org/web/app/last-exile.jsp", - // "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", - // "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" - // }, - // new String[] {null, null, mojo.getWebXml().toString(), null, null, null, null}); - // } - // - // @MojoParameter(name = "outputDirectory", value = "outputDir") - // @MojoParameter(name = "warName", value = "warName") - // @Test - // public void testMetaInfContentWithContainerConfig() throws Exception { - // String testId = "SimpleWarWithContainerConfig"; - // MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - // String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; - // File webAppDirectory = new File(getTestDirectory(), testId); - // WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - // String warName = "simple"; - // File webAppSource = createWebAppSource(testId); - // File classesDir = createClassesDir(testId, true); - // File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - // - // // Create the sample config.xml - // final File configFile = new File(webAppSource, "META-INF/config.xml"); - // createFile(configFile, ""); - // - // project.setArtifact(warArtifact); - // this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - // mojo.setWebXml(new File(xmlSource, "web.xml")); - // mojo.setContainerConfigXML(configFile); - // - // mojo.execute(); - // - // // validate jar file - // File expectedJarFile = new File(outputDir, "simple.war"); - // assertJarContent( - // expectedJarFile, - // new String[] { - // "META-INF/MANIFEST.MF", - // "META-INF/config.xml", - // "WEB-INF/web.xml", - // "pansit.jsp", - // "org/web/app/last-exile.jsp", - // "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", - // "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" - // }, - // new String[] {null, null, mojo.getWebXml().toString(), null, null, null, null}); - // } - // - // @MojoParameter(name = "outputDirectory", value = "outputDir") - // @MojoParameter(name = "warName", value = "warName") - // @Test - // public void testFailOnMissingWebXmlFalse() throws Exception { - // - // String testId = "SimpleWarMissingWebXmlFalse"; - // MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - // String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; - // File webAppDirectory = new File(getTestDirectory(), testId); - // WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - // String warName = "simple"; - // File webAppSource = createWebAppSource(testId); - // File classesDir = createClassesDir(testId, true); - // - // project.setArtifact(warArtifact); - // this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - // mojo.setFailOnMissingWebXml(false); - // mojo.execute(); - // - // // validate jar file - // File expectedJarFile = new File(outputDir, "simple.war"); - // final Map jarContent = assertJarContent( - // expectedJarFile, - // new String[] { - // "META-INF/MANIFEST.MF", - // "pansit.jsp", - // "org/web/app/last-exile.jsp", - // "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", - // "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" - // }, - // new String[] {null, null, null, null, null}); - // - // assertFalse(jarContent.containsKey("WEB-INF/web.xml"), "web.xml should be missing"); - // } - // - // @MojoParameter(name = "outputDirectory", value = "outputDir") - // @MojoParameter(name = "warName", value = "warName") - // @Test - // public void testFailOnMissingWebXmlTrue() throws Exception { - // - // String testId = "SimpleWarMissingWebXmlTrue"; - // MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - // String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; - // File webAppDirectory = new File(getTestDirectory(), testId); - // WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - // String warName = "simple"; - // File webAppSource = createWebAppSource(testId); - // File classesDir = createClassesDir(testId, true); - // - // project.setArtifact(warArtifact); - // this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - // mojo.setFailOnMissingWebXml(true); - // - // try { - // mojo.execute(); - // fail("Building of the war isn't possible because web.xml is missing"); - // } catch (MojoExecutionException e) { - // // expected behaviour - // } - // } - // - // @MojoParameter(name = "outputDirectory", value = "outputDir") - // @MojoParameter(name = "warName", value = "warName") - // @Test - // public void testFailOnMissingWebXmlNotSpecifiedAndServlet30Used() throws Exception { - // String testId = "SimpleWarUnderServlet30"; - // MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - // String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; - // File webAppDirectory = new File(getTestDirectory(), testId); - // WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - // String warName = "simple"; - // File webAppSource = createWebAppSource(testId); - // File classesDir = createClassesDir(testId, true); - // JarArtifactStub jarArtifactStub = new JarArtifactStub(getBasedir(), artifactHandler); - // jarArtifactStub.setFile( - // new File(getBasedir(), "/target/test-classes/unit/sample_wars/javax.servlet-api-3.0.1.jar")); - // jarArtifactStub.setScope(Artifact.SCOPE_PROVIDED); - // project.addArtifact(jarArtifactStub); - // - // project.setArtifact(warArtifact); - // project.setFile(warArtifact.getFile()); - // this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - // - // mojo.execute(); - // - // // validate war file - // File expectedWarFile = new File(outputDir, "simple.war"); - // final Map jarContent = assertJarContent( - // expectedWarFile, - // new String[] { - // "META-INF/MANIFEST.MF", - // "pansit.jsp", - // "org/web/app/last-exile.jsp", - // "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", - // "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" - // }, - // new String[] {null, null, null, null, null}); - // - // assertFalse(jarContent.containsKey("WEB-INF/web.xml"), "web.xml should be missing"); - // } - // - // @MojoParameter(name = "outputDirectory", value = "outputDir") - // @MojoParameter(name = "warName", value = "warName") - // @Test - // public void testFailOnMissingWebXmlNotSpecifiedAndServlet30NotUsed() throws Exception { - // String testId = "SimpleWarNotUnderServlet30"; - // MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - // String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; - // File webAppDirectory = new File(getTestDirectory(), testId); - // WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - // String warName = "simple"; - // File webAppSource = createWebAppSource(testId); - // File classesDir = createClassesDir(testId, true); - // - // project.setArtifact(warArtifact); - // project.setFile(warArtifact.getFile()); - // this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - // - // try { - // mojo.execute(); - // fail("Building of the war isn't possible because no 'failOnMissingWebXml' policy was set and the - // project " - // + "does not depend on Servlet 3.0"); - // } catch (MojoExecutionException e) { - // // expected behaviour - // } - // } - // - // @MojoParameter(name = "outputDirectory", value = "outputDir") - // @MojoParameter(name = "warName", value = "warName") - // @Test - // public void testAttachClasses() throws Exception { - // String testId = "AttachClasses"; - // MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - // String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; - // File webAppDirectory = new File(getTestDirectory(), testId); - // WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - // String warName = "simple"; - // File webAppSource = createWebAppSource(testId); - // File classesDir = createClassesDir(testId, false); - // File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - // - // project.setArtifact(warArtifact); - // this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - // mojo.setWebXml(new File(xmlSource, "web.xml")); - // mojo.setAttachClasses(true); - // mojo.setClassesClassifier("classes"); - // - // mojo.execute(); - // - // // validate jar file - // File expectedJarFile = new File(outputDir, "simple-classes.jar"); - // assertJarContent( - // expectedJarFile, new String[] {"META-INF/MANIFEST.MF", "sample-servlet.clazz"}, new String[] - // {null, null - // }); - // } - // - // @MojoParameter(name = "outputDirectory", value = "outputDir") - // @MojoParameter(name = "warName", value = "warName") - // @Test - // public void testAttachClassesWithCustomClassifier() throws Exception { - // String testId = "AttachClassesCustomClassifier"; - // MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - // String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; - // File webAppDirectory = new File(getTestDirectory(), testId); - // WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - // String warName = "simple"; - // File webAppSource = createWebAppSource(testId); - // File classesDir = createClassesDir(testId, false); - // File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - // - // project.setArtifact(warArtifact); - // this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - // mojo.setWebXml(new File(xmlSource, "web.xml")); - // mojo.setAttachClasses(true); - // mojo.setClassesClassifier("mystuff"); - // - // mojo.execute(); - // - // // validate jar file - // File expectedJarFile = new File(outputDir, "simple-mystuff.jar"); - // assertJarContent( - // expectedJarFile, new String[] {"META-INF/MANIFEST.MF", "sample-servlet.clazz"}, new String[] - // {null, null - // }); - // } - // + + @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") + @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/PrimaryArtifact-output") + @MojoParameter(name = "warName", value = "simple") + @Test + public void testPrimaryArtifact(WarMojo mojo) throws Exception { + String testId = "PrimaryArtifact"; + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + File webAppDirectory = new File(getTestDirectory(), testId); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + File webAppSource = createWebAppSource(testId); + File classesDir = createClassesDir(testId, true); + File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); + + warArtifact.setFile(new File("error.war")); + project.setArtifact(warArtifact); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); + mojo.setWebXml(new File(xmlSource, "web.xml")); + + mojo.execute(); + + // validate jar file + File expectedJarFile = new File(outputDir, "simple.war"); + assertJarContent( + expectedJarFile, + new String[] { + "META-INF/MANIFEST.MF", + "WEB-INF/web.xml", + "pansit.jsp", + "org/web/app/last-exile.jsp", + "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", + "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" + }, + new String[] {null, mojo.getWebXml().toString(), null, null, null, null}); + } + + @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/not-primary-artifact.xml") + @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/NotPrimaryArtifact-output") + @MojoParameter(name = "warName", value = "simple") + @Test + public void testNotPrimaryArtifact(WarMojo mojo) throws Exception { + String testId = "NotPrimaryArtifact"; + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + File webAppDirectory = new File(getTestDirectory(), testId); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + File webAppSource = createWebAppSource(testId); + File classesDir = createClassesDir(testId, true); + File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); + + warArtifact.setFile(new File("error.war")); + project.setArtifact(warArtifact); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); + mojo.setWebXml(new File(xmlSource, "web.xml")); + + mojo.execute(); + + // validate jar file + File expectedJarFile = new File(outputDir, "simple.war"); + assertJarContent( + expectedJarFile, + new String[] { + "META-INF/MANIFEST.MF", + "WEB-INF/web.xml", + "pansit.jsp", + "org/web/app/last-exile.jsp", + "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", + "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" + }, + new String[] {null, mojo.getWebXml().toString(), null, null, null, null}); + } + + @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") + @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarWithMetaInfContent-output") + @MojoParameter(name = "warName", value = "simple") + @Test + public void testMetaInfContent(WarMojo mojo) throws Exception { + String testId = "SimpleWarWithMetaInfContent"; + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + File webAppDirectory = new File(getTestDirectory(), testId); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + File webAppSource = createWebAppSource(testId); + File classesDir = createClassesDir(testId, true); + File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); + + // Create the sample config.xml + final File configFile = new File(webAppSource, "META-INF/config.xml"); + createFile(configFile, ""); + + project.setArtifact(warArtifact); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); + mojo.setWebXml(new File(xmlSource, "web.xml")); + + mojo.execute(); + + // validate jar file + File expectedJarFile = new File(outputDir, "simple.war"); + assertJarContent( + expectedJarFile, + new String[] { + "META-INF/MANIFEST.MF", + "META-INF/config.xml", + "WEB-INF/web.xml", + "pansit.jsp", + "org/web/app/last-exile.jsp", + "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", + "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" + }, + new String[] {null, null, mojo.getWebXml().toString(), null, null, null, null}); + } + + @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") + @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarWithContainerConfig-output") + @MojoParameter(name = "warName", value = "simple") + @Test + public void testMetaInfContentWithContainerConfig(WarMojo mojo) throws Exception { + String testId = "SimpleWarWithContainerConfig"; + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + File webAppDirectory = new File(getTestDirectory(), testId); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + File webAppSource = createWebAppSource(testId); + File classesDir = createClassesDir(testId, true); + File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); + + // Create the sample config.xml + final File configFile = new File(webAppSource, "META-INF/config.xml"); + createFile(configFile, ""); + + project.setArtifact(warArtifact); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); + mojo.setWebXml(new File(xmlSource, "web.xml")); + mojo.setContainerConfigXML(configFile); + + mojo.execute(); + + // validate jar file + File expectedJarFile = new File(outputDir, "simple.war"); + assertJarContent( + expectedJarFile, + new String[] { + "META-INF/MANIFEST.MF", + "META-INF/config.xml", + "WEB-INF/web.xml", + "pansit.jsp", + "org/web/app/last-exile.jsp", + "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", + "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" + }, + new String[] {null, null, mojo.getWebXml().toString(), null, null, null, null}); + } + + @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") + @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarMissingWebXmlFalse-output") + @MojoParameter(name = "warName", value = "simple") + @Test + public void testFailOnMissingWebXmlFalse(WarMojo mojo) throws Exception { + String testId = "SimpleWarMissingWebXmlFalse"; + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + File webAppDirectory = new File(getTestDirectory(), testId); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + File webAppSource = createWebAppSource(testId); + File classesDir = createClassesDir(testId, true); + + project.setArtifact(warArtifact); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); + mojo.setFailOnMissingWebXml(false); + mojo.execute(); + + // validate jar file + File expectedJarFile = new File(outputDir, "simple.war"); + final Map jarContent = assertJarContent( + expectedJarFile, + new String[] { + "META-INF/MANIFEST.MF", + "pansit.jsp", + "org/web/app/last-exile.jsp", + "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", + "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" + }, + new String[] {null, null, null, null, null}); + + assertFalse(jarContent.containsKey("WEB-INF/web.xml"), "web.xml should be missing"); + } + + @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") + @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarMissingWebXmlTrue-output") + @MojoParameter(name = "warName", value = "simple") + @Test + public void testFailOnMissingWebXmlTrue(WarMojo mojo) throws Exception { + String testId = "SimpleWarMissingWebXmlTrue"; + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + File webAppDirectory = new File(getTestDirectory(), testId); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + File webAppSource = createWebAppSource(testId); + File classesDir = createClassesDir(testId, true); + + project.setArtifact(warArtifact); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); + mojo.setFailOnMissingWebXml(true); + + try { + mojo.execute(); + fail("Building of the war isn't possible because web.xml is missing"); + } catch (MojoExecutionException e) { + // expected behaviour + } + } + + @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") + @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarUnderServlet30-output") + @MojoParameter(name = "warName", value = "simple") + @Test + @Disabled // TODO test failed and error message corresponed to the test case description + public void testFailOnMissingWebXmlNotSpecifiedAndServlet30Used(WarMojo mojo) throws Exception { + String testId = "SimpleWarUnderServlet30"; + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + File webAppDirectory = new File(getTestDirectory(), testId); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + File webAppSource = createWebAppSource(testId); + File classesDir = createClassesDir(testId, true); + JarArtifactStub jarArtifactStub = new JarArtifactStub(getBasedir(), artifactHandler); + jarArtifactStub.setFile( + new File(getBasedir(), "/target/test-classes/unit/sample_wars/javax.servlet-api-3.0.1.jar")); + jarArtifactStub.setScope(Artifact.SCOPE_PROVIDED); + project.addArtifact(jarArtifactStub); + + project.setArtifact(warArtifact); + project.setFile(warArtifact.getFile()); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); + + mojo.execute(); + + // validate war file + File expectedWarFile = new File(outputDir, "simple.war"); + final Map jarContent = assertJarContent( + expectedWarFile, + new String[] { + "META-INF/MANIFEST.MF", + "pansit.jsp", + "org/web/app/last-exile.jsp", + "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", + "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" + }, + new String[] {null, null, null, null, null}); + + assertFalse(jarContent.containsKey("WEB-INF/web.xml"), "web.xml should be missing"); + } + + @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") + @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarUnderServlet30-output") + @MojoParameter(name = "warName", value = "simple") + @Test + public void testFailOnMissingWebXmlNotSpecifiedAndServlet30NotUsed(WarMojo mojo) throws Exception { + String testId = "SimpleWarNotUnderServlet30"; + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + File webAppDirectory = new File(getTestDirectory(), testId); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + File webAppSource = createWebAppSource(testId); + File classesDir = createClassesDir(testId, true); + + project.setArtifact(warArtifact); + project.setFile(warArtifact.getFile()); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); + + try { + mojo.execute(); + fail("Building of the war isn't possible because no 'failOnMissingWebXml' policy was set and the project " + + "does not depend on Servlet 3.0"); + } catch (MojoExecutionException e) { + // expected behaviour + } + } + + @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") + @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/AttachClasses-output") + @MojoParameter(name = "warName", value = "simple") + @Test + public void testAttachClasses(WarMojo mojo) throws Exception { + String testId = "AttachClasses"; + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + File webAppDirectory = new File(getTestDirectory(), testId); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + File webAppSource = createWebAppSource(testId); + File classesDir = createClassesDir(testId, false); + File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); + + project.setArtifact(warArtifact); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); + mojo.setWebXml(new File(xmlSource, "web.xml")); + mojo.setAttachClasses(true); + mojo.setClassesClassifier("classes"); + + mojo.execute(); + + // validate jar file + File expectedJarFile = new File(outputDir, "simple-classes.jar"); + assertJarContent( + expectedJarFile + , new String[] {"META-INF/MANIFEST.MF", "sample-servlet.clazz"} + , new String[] {null, null} + ); + } + + @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") + @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/AttachClassesCustomClassifier-output") + @MojoParameter(name = "warName", value = "simple") + @Test + public void testAttachClassesWithCustomClassifier(WarMojo mojo) throws Exception { + String testId = "AttachClassesCustomClassifier"; + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + File webAppDirectory = new File(getTestDirectory(), testId); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + File webAppSource = createWebAppSource(testId); + File classesDir = createClassesDir(testId, false); + File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); + + project.setArtifact(warArtifact); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); + mojo.setWebXml(new File(xmlSource, "web.xml")); + mojo.setAttachClasses(true); + mojo.setClassesClassifier("mystuff"); + + mojo.execute(); + + // validate jar file + File expectedJarFile = new File(outputDir, "simple-mystuff.jar"); + assertJarContent(expectedJarFile + , new String[] {"META-INF/MANIFEST.MF", "sample-servlet.clazz"} + , new String[] {null, null} + ); + } + protected Map assertJarContent( final File expectedJarFile, final String[] files, final String[] filesContent) throws IOException { return assertJarContent(expectedJarFile, files, filesContent, null); From 1b4e31aa602a8e6ba76368b6804fe9fa89deef34 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 5 Nov 2025 11:27:02 +0100 Subject: [PATCH 04/80] refactor: WarMojoTest --- .../apache/maven/plugins/war/WarMojoTest.java | 470 ++++++------------ 1 file changed, 146 insertions(+), 324 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java index 8cfdf868..6d89865e 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java @@ -30,6 +30,7 @@ import org.apache.maven.api.di.Provides; 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.Artifact; @@ -38,15 +39,11 @@ import org.apache.maven.plugins.war.stub.JarArtifactStub; import org.apache.maven.plugins.war.stub.MavenProject4CopyConstructor; import org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub; -import org.apache.maven.plugins.war.stub.MavenProjectBasicStub; import org.apache.maven.plugins.war.stub.ProjectHelperStub; import org.apache.maven.plugins.war.stub.WarArtifact4CCStub; import org.apache.maven.project.MavenProjectHelper; -import org.codehaus.plexus.archiver.ArchiverException; -import org.codehaus.plexus.archiver.jar.JarArchiver; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -68,27 +65,10 @@ public class WarMojoTest { @Inject private ArtifactHandler artifactHandler; - // protected static final File OVERLAYS_TEMP_DIR = new File(getBasedir(), "target/test-overlays/"); - // protected static final File OVERLAYS_ROOT_DIR = new File(getBasedir(), "target/test-classes/overlays/"); - protected static final String MANIFEST_PATH = "META-INF" + File.separator + "MANIFEST.MF"; - // private static File pomFile = - // new File(getBasedir(), "target/test-classes/unit/warmojotest/plugin-config-primary-artifact.xml"); - - protected File getTestDirectory() { - return new File(getBasedir(), "target/test-classes/unit/warmojotest"); - } - - @BeforeEach - public void setUp() throws Exception { - // MavenExecutionRequest request = new DefaultMavenExecutionRequest() - // .setSystemProperties(System.getProperties()) - // .setStartTime(new Date()); - - // MavenSession mavenSession = - // new MavenSession((PlexusContainer) null, (RepositorySystemSession) null, request, null); - // getContainer().addComponent(mavenSession, MavenSession.class.getName()); - // mojo = (WarMojo) lookupMojo("war", pomFile); + @Provides + private MavenProjectHelper projectHelper() { + return new ProjectHelperStub(); } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") @@ -97,24 +77,19 @@ public void setUp() throws Exception { @Test public void testSimpleWar(WarMojo mojo) throws Exception { String testId = "SimpleWar"; - MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - project.setArtifact(warArtifact); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); - mojo.setWebXml(new File(xmlSource, "web.xml")); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory, xmlSource); mojo.execute(); // validate jar file + String outputDir = MojoExtension.getVariableValueFromObject(mojo, "outputDirectory") + .toString(); File expectedJarFile = new File(outputDir, "simple.war"); assertJarContent( expectedJarFile, @@ -130,30 +105,27 @@ public void testSimpleWar(WarMojo mojo) throws Exception { } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") - @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-output") + @MojoParameter( + name = "outputDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-output") @MojoParameter(name = "warName", value = "simple") @MojoParameter(name = "packagingIncludes", value = "%regex[(.(?!exile))+]") @Test public void testSimpleWarPackagingExcludeWithIncludesRegEx(WarMojo mojo) throws Exception { String testId = "SimpleWarPackagingExcludeWithIncludesRegEx"; - MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - project.setArtifact(warArtifact); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); - mojo.setWebXml(new File(xmlSource, "web.xml")); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory, xmlSource); mojo.execute(); // validate jar file + String outputDir = MojoExtension.getVariableValueFromObject(mojo, "outputDirectory") + .toString(); File expectedJarFile = new File(outputDir, "simple.war"); assertJarContent( expectedJarFile, @@ -169,31 +141,29 @@ public void testSimpleWarPackagingExcludeWithIncludesRegEx(WarMojo mojo) throws }, new String[] {"org/web/app/last-exile.jsp"}); } + @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") - @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-output") + @MojoParameter( + name = "outputDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-output") @MojoParameter(name = "warName", value = "simple") @MojoParameter(name = "packagingExcludes", value = "%regex[.+/last-exile.+]") @Test public void testSimpleWarPackagingExcludesWithRegEx(WarMojo mojo) throws Exception { String testId = "SimpleWarPackagingExcludesWithRegEx"; - MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - project.setArtifact(warArtifact); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); - mojo.setWebXml(new File(xmlSource, "web.xml")); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory, xmlSource); mojo.execute(); // validate jar file + String outputDir = MojoExtension.getVariableValueFromObject(mojo, "outputDirectory") + .toString(); File expectedJarFile = new File(outputDir, "simple.war"); assertJarContent( expectedJarFile, @@ -217,24 +187,19 @@ public void testSimpleWarPackagingExcludesWithRegEx(WarMojo mojo) throws Excepti @Test public void testClassifier(WarMojo mojo) throws Exception { String testId = "Classifier"; - MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - project.setArtifact(warArtifact); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); - mojo.setWebXml(new File(xmlSource, "web.xml")); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory, xmlSource); mojo.execute(); // validate jar file + String outputDir = MojoExtension.getVariableValueFromObject(mojo, "outputDirectory") + .toString(); File expectedJarFile = new File(outputDir, "simple-test-classifier.war"); assertJarContent( expectedJarFile, @@ -249,36 +214,26 @@ public void testClassifier(WarMojo mojo) throws Exception { new String[] {null, mojo.getWebXml().toString(), null, null, null, null}); } - @Provides - private MavenProjectHelper projectHelper() { - return new ProjectHelperStub(); - } - @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/PrimaryArtifact-output") @MojoParameter(name = "warName", value = "simple") @Test public void testPrimaryArtifact(WarMojo mojo) throws Exception { String testId = "PrimaryArtifact"; - MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); warArtifact.setFile(new File("error.war")); - project.setArtifact(warArtifact); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); - mojo.setWebXml(new File(xmlSource, "web.xml")); + configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory, xmlSource); mojo.execute(); // validate jar file + String outputDir = MojoExtension.getVariableValueFromObject(mojo, "outputDirectory") + .toString(); File expectedJarFile = new File(outputDir, "simple.war"); assertJarContent( expectedJarFile, @@ -299,25 +254,20 @@ public void testPrimaryArtifact(WarMojo mojo) throws Exception { @Test public void testNotPrimaryArtifact(WarMojo mojo) throws Exception { String testId = "NotPrimaryArtifact"; - MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); warArtifact.setFile(new File("error.war")); - project.setArtifact(warArtifact); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); - mojo.setWebXml(new File(xmlSource, "web.xml")); + configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory, xmlSource); mojo.execute(); // validate jar file + String outputDir = MojoExtension.getVariableValueFromObject(mojo, "outputDirectory") + .toString(); File expectedJarFile = new File(outputDir, "simple.war"); assertJarContent( expectedJarFile, @@ -333,15 +283,14 @@ public void testNotPrimaryArtifact(WarMojo mojo) throws Exception { } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") - @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarWithMetaInfContent-output") + @MojoParameter( + name = "outputDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarWithMetaInfContent-output") @MojoParameter(name = "warName", value = "simple") @Test public void testMetaInfContent(WarMojo mojo) throws Exception { String testId = "SimpleWarWithMetaInfContent"; - MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); @@ -350,16 +299,14 @@ public void testMetaInfContent(WarMojo mojo) throws Exception { final File configFile = new File(webAppSource, "META-INF/config.xml"); createFile(configFile, ""); - project.setArtifact(warArtifact); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); - mojo.setWebXml(new File(xmlSource, "web.xml")); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory, xmlSource); mojo.execute(); // validate jar file + String outputDir = MojoExtension.getVariableValueFromObject(mojo, "outputDirectory") + .toString(); File expectedJarFile = new File(outputDir, "simple.war"); assertJarContent( expectedJarFile, @@ -376,15 +323,16 @@ public void testMetaInfContent(WarMojo mojo) throws Exception { } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") - @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarWithContainerConfig-output") + @MojoParameter( + name = "outputDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarWithContainerConfig-output") @MojoParameter(name = "warName", value = "simple") @Test public void testMetaInfContentWithContainerConfig(WarMojo mojo) throws Exception { String testId = "SimpleWarWithContainerConfig"; - MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; + String outputDir = MojoExtension.getVariableValueFromObject(mojo, "outputDirectory") + .toString(); File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); @@ -393,12 +341,8 @@ public void testMetaInfContentWithContainerConfig(WarMojo mojo) throws Exception final File configFile = new File(webAppSource, "META-INF/config.xml"); createFile(configFile, ""); - project.setArtifact(warArtifact); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); - mojo.setWebXml(new File(xmlSource, "web.xml")); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory, xmlSource); mojo.setContainerConfigXML(configFile); mojo.execute(); @@ -420,27 +364,25 @@ public void testMetaInfContentWithContainerConfig(WarMojo mojo) throws Exception } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") - @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarMissingWebXmlFalse-output") + @MojoParameter( + name = "outputDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarMissingWebXmlFalse-output") @MojoParameter(name = "warName", value = "simple") @Test public void testFailOnMissingWebXmlFalse(WarMojo mojo) throws Exception { String testId = "SimpleWarMissingWebXmlFalse"; - MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); - project.setArtifact(warArtifact); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory); mojo.setFailOnMissingWebXml(false); mojo.execute(); // validate jar file + String outputDir = MojoExtension.getVariableValueFromObject(mojo, "outputDirectory") + .toString(); File expectedJarFile = new File(outputDir, "simple.war"); final Map jarContent = assertJarContent( expectedJarFile, @@ -457,23 +399,19 @@ public void testFailOnMissingWebXmlFalse(WarMojo mojo) throws Exception { } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") - @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarMissingWebXmlTrue-output") + @MojoParameter( + name = "outputDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarMissingWebXmlTrue-output") @MojoParameter(name = "warName", value = "simple") @Test public void testFailOnMissingWebXmlTrue(WarMojo mojo) throws Exception { String testId = "SimpleWarMissingWebXmlTrue"; - MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); - project.setArtifact(warArtifact); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory); mojo.setFailOnMissingWebXml(true); try { @@ -485,34 +423,31 @@ public void testFailOnMissingWebXmlTrue(WarMojo mojo) throws Exception { } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") - @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarUnderServlet30-output") + @MojoParameter( + name = "outputDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarUnderServlet30-output") @MojoParameter(name = "warName", value = "simple") @Test @Disabled // TODO test failed and error message corresponed to the test case description public void testFailOnMissingWebXmlNotSpecifiedAndServlet30Used(WarMojo mojo) throws Exception { String testId = "SimpleWarUnderServlet30"; - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); - JarArtifactStub jarArtifactStub = new JarArtifactStub(getBasedir(), artifactHandler); - jarArtifactStub.setFile( - new File(getBasedir(), "/target/test-classes/unit/sample_wars/javax.servlet-api-3.0.1.jar")); - jarArtifactStub.setScope(Artifact.SCOPE_PROVIDED); - project.addArtifact(jarArtifactStub); + JarArtifactStub jarArtifactStub = createServletApi3JarArtifact(); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + project.addArtifact(jarArtifactStub); project.setArtifact(warArtifact); project.setFile(warArtifact.getFile()); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + configureMojo(mojo, project, classesDir, webAppSource, webAppDirectory); mojo.execute(); // validate war file + String outputDir = MojoExtension.getVariableValueFromObject(mojo, "outputDirectory") + .toString(); File expectedWarFile = new File(outputDir, "simple.war"); final Map jarContent = assertJarContent( expectedWarFile, @@ -528,25 +463,31 @@ public void testFailOnMissingWebXmlNotSpecifiedAndServlet30Used(WarMojo mojo) th assertFalse(jarContent.containsKey("WEB-INF/web.xml"), "web.xml should be missing"); } + private JarArtifactStub createServletApi3JarArtifact() { + JarArtifactStub jarArtifactStub = new JarArtifactStub(getBasedir(), artifactHandler); + jarArtifactStub.setFile( + new File(getBasedir(), "/target/test-classes/unit/sample_wars/javax.servlet-api-3.0.1.jar")); + jarArtifactStub.setScope(Artifact.SCOPE_PROVIDED); + return jarArtifactStub; + } + @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") - @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarUnderServlet30-output") + @MojoParameter( + name = "outputDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarUnderServlet30-output") @MojoParameter(name = "warName", value = "simple") @Test public void testFailOnMissingWebXmlNotSpecifiedAndServlet30NotUsed(WarMojo mojo) throws Exception { String testId = "SimpleWarNotUnderServlet30"; - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); project.setArtifact(warArtifact); project.setFile(warArtifact.getFile()); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + configureMojo(mojo, project, classesDir, webAppSource, webAppDirectory); try { mojo.execute(); @@ -563,73 +504,97 @@ public void testFailOnMissingWebXmlNotSpecifiedAndServlet30NotUsed(WarMojo mojo) @Test public void testAttachClasses(WarMojo mojo) throws Exception { String testId = "AttachClasses"; - MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, false); File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - project.setArtifact(warArtifact); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); - mojo.setWebXml(new File(xmlSource, "web.xml")); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory, xmlSource); mojo.setAttachClasses(true); mojo.setClassesClassifier("classes"); mojo.execute(); // validate jar file + String outputDir = MojoExtension.getVariableValueFromObject(mojo, "outputDirectory") + .toString(); File expectedJarFile = new File(outputDir, "simple-classes.jar"); assertJarContent( - expectedJarFile - , new String[] {"META-INF/MANIFEST.MF", "sample-servlet.clazz"} - , new String[] {null, null} - ); + expectedJarFile, new String[] {"META-INF/MANIFEST.MF", "sample-servlet.clazz"}, new String[] {null, null + }); } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") - @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/AttachClassesCustomClassifier-output") + @MojoParameter( + name = "outputDirectory", + value = "target/test-classes/unit/warmojotest/AttachClassesCustomClassifier-output") @MojoParameter(name = "warName", value = "simple") @Test public void testAttachClassesWithCustomClassifier(WarMojo mojo) throws Exception { String testId = "AttachClassesCustomClassifier"; - MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output"; File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, false); File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - project.setArtifact(warArtifact); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); - mojo.setWebXml(new File(xmlSource, "web.xml")); + WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); + configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory, xmlSource); mojo.setAttachClasses(true); mojo.setClassesClassifier("mystuff"); mojo.execute(); // validate jar file + String outputDir = MojoExtension.getVariableValueFromObject(mojo, "outputDirectory") + .toString(); File expectedJarFile = new File(outputDir, "simple-mystuff.jar"); - assertJarContent(expectedJarFile - , new String[] {"META-INF/MANIFEST.MF", "sample-servlet.clazz"} - , new String[] {null, null} - ); + assertJarContent( + expectedJarFile, new String[] {"META-INF/MANIFEST.MF", "sample-servlet.clazz"}, new String[] {null, null + }); + } + + private void configureMojo( + WarMojo mojo, + WarArtifact4CCStub warArtifact, + File classesDir, + File webAppSource, + File webAppDirectory, + File xmlSource) + throws Exception { + configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory); + mojo.setWebXml(new File(xmlSource, "web.xml")); + } + + private void configureMojo( + WarMojo mojo, MavenProjectArtifactsStub project, File classesDir, File webAppSource, File webAppDirectory) { + mojo.setProject(project); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + } + + private void configureMojo( + WarMojo mojo, WarArtifact4CCStub warArtifact, File classesDir, File webAppSource, File webAppDirectory) + throws Exception { + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + project.setArtifact(warArtifact); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); + } + + private File getTestDirectory() { + return new File(getBasedir(), "target/test-classes/unit/warmojotest"); } - protected Map assertJarContent( + private Map assertJarContent( final File expectedJarFile, final String[] files, final String[] filesContent) throws IOException { return assertJarContent(expectedJarFile, files, filesContent, null); } - protected Map assertJarContent( + private Map assertJarContent( final File expectedJarFile, final String[] files, final String[] filesContent, @@ -668,26 +633,6 @@ protected Map assertJarContent( } } - /** - * initialize required parameters - * - * @param mojo The mojo to be tested. - * @param classesDir The classes' directory. - * @param webAppSource The webAppSource. - * @param webAppDir The webAppDir folder. - * @param project The Maven project. - * @throws Exception in case of errors - */ - @MojoParameter(name = "outdatedCheckPath", value = "WEB-INF/lib/") - protected void configureMojo( - AbstractWarMojo mojo, File classesDir, File webAppSource, File webAppDir, MavenProjectBasicStub project) - throws Exception { - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDir); - mojo.setProject(project); - } - /** * create an isolated xml dir * @@ -696,7 +641,7 @@ protected void configureMojo( * @return The created file. * @throws Exception in case of errors. */ - protected File createXMLConfigDir(String id, String[] xmlFiles) throws Exception { + private File createXMLConfigDir(String id, String[] xmlFiles) throws Exception { File xmlConfigDir = new File(getTestDirectory(), "/" + id + "-test-data/xml-config"); File xmlFile; @@ -719,7 +664,7 @@ protected File createXMLConfigDir(String id, String[] xmlFiles) throws Exception * @return the source directory for that test * @throws Exception if an exception occurs */ - protected File getWebAppSource(String id) throws Exception { + private File getWebAppSource(String id) throws Exception { return new File(getTestDirectory(), "/" + id + "-test-data/source"); } @@ -731,7 +676,7 @@ protected File getWebAppSource(String id) throws Exception { * @return The created file. * @throws Exception in case of errors. */ - protected File createWebAppSource(String id, boolean createSamples) throws Exception { + private File createWebAppSource(String id, boolean createSamples) throws Exception { File webAppSource = getWebAppSource(id); if (createSamples) { File simpleJSP = new File(webAppSource, "pansit.jsp"); @@ -743,7 +688,7 @@ protected File createWebAppSource(String id, boolean createSamples) throws Excep return webAppSource; } - protected File createWebAppSource(String id) throws Exception { + private File createWebAppSource(String id) throws Exception { return createWebAppSource(id, true); } @@ -755,7 +700,7 @@ protected File createWebAppSource(String id) throws Exception { * @return The created class file. * @throws Exception in case of errors. */ - protected File createClassesDir(String id, boolean empty) throws Exception { + private File createClassesDir(String id, boolean empty) throws Exception { File classesDir = new File(getTestDirectory() + "/" + id + "-test-data/classes/"); createDir(classesDir); @@ -767,143 +712,20 @@ protected File createClassesDir(String id, boolean empty) throws Exception { return classesDir; } - protected void createDir(File dir) { + private void createDir(File dir) { if (!dir.exists()) { assertTrue(dir.mkdirs(), "can not create test dir: " + dir.toString()); } } - protected void createFile(File testFile, String body) throws Exception { + private void createFile(File testFile, String body) throws Exception { createDir(testFile.getParentFile()); FileUtils.fileWrite(testFile.toString(), body); assertTrue(testFile.exists(), "could not create file: " + testFile); } - protected void createFile(File testFile) throws Exception { + private void createFile(File testFile) throws Exception { createFile(testFile, testFile.toString()); } - - // /** - // * Generates test war. - // * Generates war with such a structure: - // *
    - // *
  • jsp - // *
      - // *
    • d - // *
        - // *
      • a.jsp
      • - // *
      • b.jsp
      • - // *
      • c.jsp
      • - // *
      - // *
    • - // *
    • a.jsp
    • - // *
    • b.jsp
    • - // *
    • c.jsp
    • - // *
    - // *
  • - // *
  • WEB-INF - // *
      - // *
    • classes - // *
        - // *
      • a.clazz
      • - // *
      • b.clazz
      • - // *
      • c.clazz
      • - // *
      - // *
    • - // *
    • lib - // *
        - // *
      • a.jar
      • - // *
      • b.jar
      • - // *
      • c.jar
      • - // *
      - // *
    • - // *
    • web.xml
    • - // *
    - // *
  • - // *
- // * Each of the files will contain: id+'-'+path - // * - // * @param id the id of the overlay containing the full structure - // * @return the war file - // * @throws Exception if an error occurs - // */ - // protected File generateFullOverlayWar(String id) throws Exception { - // final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); - // if (destFile.exists()) { - // return destFile; - // } - // - // // Archive was not yet created for that id so let's create it - // final File rootDir = new File(OVERLAYS_ROOT_DIR, id); - // rootDir.mkdirs(); - // String[] filePaths = new String[] { - // "jsp/d/a.jsp", - // "jsp/d/b.jsp", - // "jsp/d/c.jsp", - // "jsp/a.jsp", - // "jsp/b.jsp", - // "jsp/c.jsp", - // "WEB-INF/classes/a.clazz", - // "WEB-INF/classes/b.clazz", - // "WEB-INF/classes/c.clazz", - // "WEB-INF/lib/a.jar", - // "WEB-INF/lib/b.jar", - // "WEB-INF/lib/c.jar", - // "WEB-INF/web.xml" - // }; - // - // for (String filePath : filePaths) { - // createFile(new File(rootDir, filePath), id + "-" + filePath); - // } - // - // createArchive(rootDir, destFile); - // return destFile; - // } - // - // /** - // * Builds a test overlay. - // * - // * @param id the id of the overlay (see test/resources/overlays) - // * @return a test war artifact with the content of the given test overlay - // */ - // protected ArtifactStub buildWarOverlayStub(String id) { - // // Create war file - // final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); - // if (!destFile.exists()) { - // createArchive(new File(OVERLAYS_ROOT_DIR, id), destFile); - // } - // - // return new WarOverlayStub(getBasedir(), id, destFile); - // } - // - // protected File getOverlayFile(String id, String filePath) { - // final File overlayDir = new File(OVERLAYS_ROOT_DIR, id); - // final File file = new File(overlayDir, filePath); - // - // // Make sure the file exists - // assertTrue( - // file.exists(), - // "Overlay file " + filePath + " does not exist for overlay " + id + " at " + - // file.getAbsolutePath()); - // return file; - // } - - protected void createArchive(final File directory, final File destinationFile) { - try { - JarArchiver archiver = new JarArchiver(); - - archiver.setDestFile(destinationFile); - archiver.addDirectory(directory); - - archiver.createArchive(); - - } catch (ArchiverException e) { - e.printStackTrace(); - fail("Failed to create overlay archive " + e.getMessage()); - } catch (IOException e) { - e.printStackTrace(); - fail("Unexpected exception " + e.getMessage()); - } - } } From fdce2c5d92048082ceddde14a9af01951ff4345f Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 5 Nov 2025 11:45:22 +0100 Subject: [PATCH 05/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarInPlaceMojoTest --- .../maven/plugins/war/WarInPlaceMojoTest.java | 257 +++--------------- 1 file changed, 36 insertions(+), 221 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java index bbd931ba..aac12828 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java @@ -18,53 +18,29 @@ */ package org.apache.maven.plugins.war; -import java.io.File; -import java.io.IOException; -import java.util.Date; - -import org.apache.maven.execution.DefaultMavenExecutionRequest; -import org.apache.maven.execution.MavenExecutionRequest; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.testing.AbstractMojoTestCase; -import org.apache.maven.plugin.testing.stubs.ArtifactStub; +import org.apache.maven.api.plugin.testing.InjectMojo; +import org.apache.maven.api.plugin.testing.MojoTest; import org.apache.maven.plugins.war.stub.MavenProjectBasicStub; import org.apache.maven.plugins.war.stub.ResourceStub; -import org.apache.maven.plugins.war.stub.WarOverlayStub; -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.archiver.ArchiverException; -import org.codehaus.plexus.archiver.jar.JarArchiver; import org.codehaus.plexus.util.FileUtils; -import org.eclipse.aether.RepositorySystemSession; - -public class WarInPlaceMojoTest extends AbstractMojoTestCase { - protected static final String POM_FILE_PATH = - getBasedir() + "/target/test-classes/unit/warexplodedinplacemojo/plugin-config.xml"; - protected static final File OVERLAYS_TEMP_DIR = new File(getBasedir(), "target/test-overlays/"); - protected static final File OVERLAYS_ROOT_DIR = new File(getBasedir(), "target/test-classes/overlays/"); - protected static final String MANIFEST_PATH = "META-INF" + File.separator + "MANIFEST.MF"; - - protected File getTestDirectory() throws Exception { - return new File(getBasedir(), "target/test-classes/unit/warexplodedinplacemojo/test-dir"); - } +import org.junit.jupiter.api.Test; - private WarInPlaceMojo mojo; - - public void setUp() throws Exception { - super.setUp(); +import java.io.File; - MavenExecutionRequest request = new DefaultMavenExecutionRequest() - .setSystemProperties(System.getProperties()) - .setStartTime(new Date()); +import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir; +import static org.junit.jupiter.api.Assertions.assertTrue; - MavenSession mavenSession = - new MavenSession((PlexusContainer) null, (RepositorySystemSession) null, request, null); - getContainer().addComponent(mavenSession, MavenSession.class.getName()); +@MojoTest +public class WarInPlaceMojoTest { - mojo = (WarInPlaceMojo) lookupMojo("inplace", POM_FILE_PATH); - assertNotNull(mojo); + private File getTestDirectory() throws Exception { + return new File(getBasedir(), "target/test-classes/unit/warexplodedinplacemojo/test-dir"); } - public void testSimpleExplodedInplaceWar() throws Exception { + + @InjectMojo(goal="inplace", pom = "src/test/resources/unit/warexplodedinplacemojo/plugin-config.xml" ) + @Test + public void testSimpleExplodedInplaceWar(WarInPlaceMojo mojo) throws Exception { // setup test data String testId = "SimpleExplodedInplaceWar"; MavenProjectBasicStub project = new MavenProjectBasicStub(); @@ -72,14 +48,17 @@ public void testSimpleExplodedInplaceWar() throws Exception { File classesDir = createClassesDir(testId, true); File webAppResource = new File(getTestDirectory(), "resources"); File sampleResource = new File(webAppResource, "pix/panis_na.jpg"); - ResourceStub[] resources = new ResourceStub[] {new ResourceStub()}; - createFile(sampleResource); - // configure mojo + ResourceStub[] resources = new ResourceStub[] {new ResourceStub()}; resources[0].setDirectory(webAppResource.getAbsolutePath()); - this.configureMojo(mojo, classesDir, webAppSource, null, project); - setVariableValueToObject(mojo, "webResources", resources); + + // configure mojo + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(null); + mojo.setProject(project); + mojo.setWebResources(resources); mojo.execute(); // validate operation @@ -89,56 +68,14 @@ public void testSimpleExplodedInplaceWar() throws Exception { File expectedWEBINFDir = new File(webAppSource, "WEB-INF"); File expectedMETAINFDir = new File(webAppSource, "META-INF"); - assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); - assertTrue("resources doesn't exist: " + expectedWebResourceFile, expectedWebResourceFile.exists()); - assertTrue("WEB-INF not found", expectedWEBINFDir.exists()); - assertTrue("META-INF not found", expectedMETAINFDir.exists()); + assertTrue(expectedWebSourceFile.exists(), "source files not found: " + expectedWebSourceFile); + assertTrue(expectedWebSource2File.exists(), "source files not found: " + expectedWebSource2File); + assertTrue(expectedWebResourceFile.exists(), "resources doesn't exist: " + expectedWebResourceFile); + assertTrue(expectedWEBINFDir.exists(), "WEB-INF not found"); + assertTrue(expectedMETAINFDir.exists(), "META-INF not found"); } - /** - * initialize required parameters - * - * @param mojo The mojo to be tested. - * @param classesDir The classes' directory. - * @param webAppSource The webAppSource. - * @param webAppDir The webAppDir folder. - * @param project The Maven project. - * @throws Exception in case of errors - */ - protected void configureMojo( - AbstractWarMojo mojo, File classesDir, File webAppSource, File webAppDir, MavenProjectBasicStub project) - throws Exception { - setVariableValueToObject(mojo, "outdatedCheckPath", "WEB-INF/lib/"); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDir); - mojo.setProject(project); - } - /** - * create an isolated xml dir - * - * @param id The id. - * @param xmlFiles array of xml files. - * @return The created file. - * @throws Exception in case of errors. - */ - protected File createXMLConfigDir(String id, String[] xmlFiles) throws Exception { - File xmlConfigDir = new File(getTestDirectory(), "/" + id + "-test-data/xml-config"); - File xmlFile; - - createDir(xmlConfigDir); - - if (xmlFiles != null) { - for (String o : xmlFiles) { - xmlFile = new File(xmlConfigDir, o); - createFile(xmlFile); - } - } - - return xmlConfigDir; - } /** * Returns the webapp source directory for the specified id. @@ -147,7 +84,7 @@ protected File createXMLConfigDir(String id, String[] xmlFiles) throws Exception * @return the source directory for that test * @throws Exception if an exception occurs */ - protected File getWebAppSource(String id) throws Exception { + private File getWebAppSource(String id) throws Exception { return new File(getTestDirectory(), "/" + id + "-test-data/source"); } @@ -159,7 +96,7 @@ protected File getWebAppSource(String id) throws Exception { * @return The created file. * @throws Exception in case of errors. */ - protected File createWebAppSource(String id, boolean createSamples) throws Exception { + private File createWebAppSource(String id, boolean createSamples) throws Exception { File webAppSource = getWebAppSource(id); if (createSamples) { File simpleJSP = new File(webAppSource, "pansit.jsp"); @@ -171,7 +108,7 @@ protected File createWebAppSource(String id, boolean createSamples) throws Excep return webAppSource; } - protected File createWebAppSource(String id) throws Exception { + private File createWebAppSource(String id) throws Exception { return createWebAppSource(id, true); } @@ -183,7 +120,7 @@ protected File createWebAppSource(String id) throws Exception { * @return The created class file. * @throws Exception in case of errors. */ - protected File createClassesDir(String id, boolean empty) throws Exception { + private File createClassesDir(String id, boolean empty) throws Exception { File classesDir = new File(getTestDirectory() + "/" + id + "-test-data/classes/"); createDir(classesDir); @@ -195,142 +132,20 @@ protected File createClassesDir(String id, boolean empty) throws Exception { return classesDir; } - protected void createDir(File dir) { + private void createDir(File dir) { if (!dir.exists()) { - assertTrue("can not create test dir: " + dir.toString(), dir.mkdirs()); + assertTrue(dir.mkdirs(), "can not create test dir: " + dir); } } - protected void createFile(File testFile, String body) throws Exception { + private void createFile(File testFile, String body) throws Exception { createDir(testFile.getParentFile()); FileUtils.fileWrite(testFile.toString(), body); - assertTrue("could not create file: " + testFile, testFile.exists()); + assertTrue(testFile.exists(), "could not create file: " + testFile); } - protected void createFile(File testFile) throws Exception { + private void createFile(File testFile) throws Exception { createFile(testFile, testFile.toString()); } - - /** - * Generates test war. - * Generates war with such a structure: - *
    - *
  • jsp - *
      - *
    • d - *
        - *
      • a.jsp
      • - *
      • b.jsp
      • - *
      • c.jsp
      • - *
      - *
    • - *
    • a.jsp
    • - *
    • b.jsp
    • - *
    • c.jsp
    • - *
    - *
  • - *
  • WEB-INF - *
      - *
    • classes - *
        - *
      • a.clazz
      • - *
      • b.clazz
      • - *
      • c.clazz
      • - *
      - *
    • - *
    • lib - *
        - *
      • a.jar
      • - *
      • b.jar
      • - *
      • c.jar
      • - *
      - *
    • - *
    • web.xml
    • - *
    - *
  • - *
- * Each of the files will contain: id+'-'+path - * - * @param id the id of the overlay containing the full structure - * @return the war file - * @throws Exception if an error occurs - */ - protected File generateFullOverlayWar(String id) throws Exception { - final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); - if (destFile.exists()) { - return destFile; - } - - // Archive was not yet created for that id so let's create it - final File rootDir = new File(OVERLAYS_ROOT_DIR, id); - rootDir.mkdirs(); - String[] filePaths = new String[] { - "jsp/d/a.jsp", - "jsp/d/b.jsp", - "jsp/d/c.jsp", - "jsp/a.jsp", - "jsp/b.jsp", - "jsp/c.jsp", - "WEB-INF/classes/a.clazz", - "WEB-INF/classes/b.clazz", - "WEB-INF/classes/c.clazz", - "WEB-INF/lib/a.jar", - "WEB-INF/lib/b.jar", - "WEB-INF/lib/c.jar", - "WEB-INF/web.xml" - }; - - for (String filePath : filePaths) { - createFile(new File(rootDir, filePath), id + "-" + filePath); - } - - createArchive(rootDir, destFile); - return destFile; - } - - /** - * Builds a test overlay. - * - * @param id the id of the overlay (see test/resources/overlays) - * @return a test war artifact with the content of the given test overlay - */ - protected ArtifactStub buildWarOverlayStub(String id) { - // Create war file - final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); - if (!destFile.exists()) { - createArchive(new File(OVERLAYS_ROOT_DIR, id), destFile); - } - - return new WarOverlayStub(getBasedir(), id, destFile); - } - - protected File getOverlayFile(String id, String filePath) { - final File overlayDir = new File(OVERLAYS_ROOT_DIR, id); - final File file = new File(overlayDir, filePath); - - // Make sure the file exists - assertTrue( - "Overlay file " + filePath + " does not exist for overlay " + id + " at " + file.getAbsolutePath(), - file.exists()); - return file; - } - - protected void createArchive(final File directory, final File destinationFile) { - try { - JarArchiver archiver = new JarArchiver(); - - archiver.setDestFile(destinationFile); - archiver.addDirectory(directory); - - archiver.createArchive(); - - } catch (ArchiverException e) { - e.printStackTrace(); - fail("Failed to create overlay archive " + e.getMessage()); - } catch (IOException e) { - e.printStackTrace(); - fail("Unexpected exception " + e.getMessage()); - } - } } From 4e2bbfb4b45d73caedbe4edae7e4623298753237 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 5 Nov 2025 11:53:01 +0100 Subject: [PATCH 06/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarZipTest --- .../apache/maven/plugins/war/WarZipTest.java | 221 +++++++++++++----- 1 file changed, 159 insertions(+), 62 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarZipTest.java b/src/test/java/org/apache/maven/plugins/war/WarZipTest.java index e0537187..196c25d9 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarZipTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarZipTest.java @@ -18,16 +18,16 @@ */ package org.apache.maven.plugins.war; +import javax.inject.Inject; + import java.io.File; import java.io.IOException; -import java.util.Date; +import org.apache.maven.api.plugin.testing.InjectMojo; +import org.apache.maven.api.plugin.testing.MojoParameter; +import org.apache.maven.api.plugin.testing.MojoTest; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.handler.ArtifactHandler; -import org.apache.maven.execution.DefaultMavenExecutionRequest; -import org.apache.maven.execution.MavenExecutionRequest; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.apache.maven.plugin.testing.stubs.ArtifactStub; import org.apache.maven.plugins.war.overlay.DefaultOverlay; import org.apache.maven.plugins.war.stub.MavenProjectBasicStub; @@ -35,47 +35,54 @@ import org.apache.maven.plugins.war.stub.WarArtifactStub; import org.apache.maven.plugins.war.stub.WarOverlayStub; import org.apache.maven.plugins.war.stub.ZipArtifactStub; -import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.archiver.ArchiverException; import org.codehaus.plexus.archiver.jar.JarArchiver; import org.codehaus.plexus.util.FileUtils; -import org.eclipse.aether.RepositorySystemSession; +import org.junit.jupiter.api.Test; + +import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Olivier Lamy * @since 7 Oct 07 */ -public class WarZipTest extends AbstractMojoTestCase { +@MojoTest +public class WarZipTest { + @Inject + private ArtifactHandler artifactHandler; protected static final File OVERLAYS_TEMP_DIR = new File(getBasedir(), "target/test-overlays/"); protected static final File OVERLAYS_ROOT_DIR = new File(getBasedir(), "target/test-classes/overlays/"); - protected static final String MANIFEST_PATH = "META-INF" + File.separator + "MANIFEST.MF"; - WarMojo mojo; - - private static File pomFile = new File(getBasedir(), "src/test/resources/unit/warziptest/war-with-zip.xml"); protected File getTestDirectory() { return new File(getBasedir(), "target/test-classes/unit/warziptest"); } - public void setUp() throws Exception { - super.setUp(); - - MavenExecutionRequest request = new DefaultMavenExecutionRequest() - .setSystemProperties(System.getProperties()) - .setStartTime(new Date()); - - MavenSession mavenSession = - new MavenSession((PlexusContainer) null, (RepositorySystemSession) null, request, null); - getContainer().addComponent(mavenSession, MavenSession.class.getName()); - mojo = (WarMojo) lookupMojo("war", pomFile); - } +// @BeforeEach +// public void setUp() throws Exception { +// super.setUp(); +// +// MavenExecutionRequest request = new DefaultMavenExecutionRequest() +// .setSystemProperties(System.getProperties()) +// .setStartTime(new Date()); +// +// MavenSession mavenSession = +// new MavenSession((PlexusContainer) null, (RepositorySystemSession) null, request, null); +// getContainer().addComponent(mavenSession, MavenSession.class.getName()); +// mojo = (WarMojo) lookupMojo("war", pomFile); +// } private Artifact buildZipArtifact() throws Exception { - ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar"); File zipFile = new File(getTestDirectory(), "foobar.zip"); return new ZipArtifactStub("src/test/resources/unit/warziptest", artifactHandler, zipFile); } + @MojoParameter( + name = "outputDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-output") + @MojoParameter(name = "warName", value = "simple") private File configureMojo(String testId) throws Exception { MavenZipProject project = new MavenZipProject(); String outputDir = getTestDirectory().getAbsolutePath() + File.separatorChar + testId + "-output"; @@ -86,25 +93,45 @@ private File configureMojo(String testId) throws Exception { } File webAppDirectory = new File(getTestDirectory(), testId); WarArtifactStub warArtifact = new WarArtifactStub(getBasedir()); - String warName = "simple"; File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); project.setArtifact(warArtifact); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "outputDirectory", outputDir); - setVariableValueToObject(mojo, "warName", warName); - setVariableValueToObject(mojo, "workDirectory", new File(getTestDirectory(), "work")); - mojo.setWebXml(new File(xmlSource, "web.xml")); +// this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); +// setVariableValueToObject(mojo, "workDirectory", new File(getTestDirectory(), "work")); +// mojo.setWebXml(new File(xmlSource, "web.xml")); project.getArtifacts().add(buildZipArtifact()); return webAppDirectory; } - public void testOneZipWithNoSkip() throws Exception { - File webAppDirectory = configureMojo("one-zip"); + @InjectMojo(goal="war", pom = "src/test/resources/unit/warziptest/war-with-zip.xml") + @MojoParameter( + name = "outputDirectory", + value = "target/test-classes/unit/warziptest/one-zip-output") + @MojoParameter(name = "warName", value = "simple") + @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/warziptest/work") + @Test + public void testOneZipWithNoSkip(WarMojo mojo) throws Exception { + MavenZipProject project = new MavenZipProject(); + File webAppDirectory1 = new File(getTestDirectory(), "one-zip"); + WarArtifactStub warArtifact = new WarArtifactStub(getBasedir()); + File webAppSource = createWebAppSource("one-zip"); + File classesDir = createClassesDir("one-zip", true); + File xmlSource = createXMLConfigDir("one-zip", new String[] {"web.xml"}); + project.setArtifact(warArtifact); + + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory1); + mojo.setProject(project); + mojo.setWebXml(new File(xmlSource, "web.xml")); + + project.getArtifacts().add(buildZipArtifact()); + + File webAppDirectory = webAppDirectory1; Overlay overlay = new DefaultOverlay(buildZipArtifact()); // overlay.setSkip( false ); @@ -113,20 +140,41 @@ public void testOneZipWithNoSkip() throws Exception { mojo.execute(); File foo = new File(webAppDirectory, "foo.txt"); - assertTrue("foo.txt not exists", foo.exists()); - assertTrue("foo.txt not a file", foo.isFile()); + assertTrue(foo.exists(), "foo.txt not exists"); + assertTrue(foo.isFile(), "foo.txt not a file"); File barDirectory = new File(webAppDirectory, "bar"); - assertTrue("bar directory not exists", barDirectory.exists()); - assertTrue("bar not a directory", barDirectory.isDirectory()); + assertTrue(barDirectory.exists(), "bar directory not exists"); + assertTrue(barDirectory.isDirectory(), "bar not a directory"); File bar = new File(barDirectory, "bar.txt"); - assertTrue("bar/bar.txt not exists", bar.exists()); - assertTrue("bar/bar.txt not a file", bar.isFile()); + assertTrue(bar.exists(), "bar/bar.txt not exists"); + assertTrue(bar.isFile(), "bar/bar.txt not a file"); } - public void testOneZipWithTargetPathOverlay() throws Exception { - File webAppDirectory = configureMojo("one-zip-overlay-targetPath"); + @InjectMojo(goal="war", pom = "src/test/resources/unit/warziptest/war-with-zip.xml") + @MojoParameter( + name = "outputDirectory", + value = "target/test-classes/unit/warziptest/one-zip-output") + @MojoParameter(name = "warName", value = "simple") + @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/warziptest/work") + @Test + public void testOneZipWithTargetPathOverlay(WarMojo mojo) throws Exception { + MavenZipProject project = new MavenZipProject(); + File webAppDirectory = new File(getTestDirectory(), "one-zip-overlay-targetPath"); + WarArtifactStub warArtifact = new WarArtifactStub(getBasedir()); + File webAppSource = createWebAppSource("one-zip-overlay-targetPath"); + File classesDir = createClassesDir("one-zip-overlay-targetPath", true); + File xmlSource = createXMLConfigDir("one-zip-overlay-targetPath", new String[] {"web.xml"}); + project.setArtifact(warArtifact); + + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); + mojo.setWebXml(new File(xmlSource, "web.xml")); + + project.getArtifacts().add(buildZipArtifact()); Overlay overlay = new DefaultOverlay(buildZipArtifact()); overlay.setSkip(false); @@ -137,28 +185,77 @@ public void testOneZipWithTargetPathOverlay() throws Exception { mojo.execute(); File foo = new File(webAppDirectory.getPath() + File.separatorChar + "overridePath", "foo.txt"); - assertTrue("foo.txt not exists", foo.exists()); - assertTrue("foo.txt not a file", foo.isFile()); + assertTrue(foo.exists(), "foo.txt not exists"); + assertTrue(foo.isFile(), "foo.txt not a file"); File barDirectory = new File(webAppDirectory.getPath() + File.separatorChar + "overridePath", "bar"); - assertTrue("bar directory not exists", barDirectory.exists()); - assertTrue("bar not a directory", barDirectory.isDirectory()); + assertTrue(barDirectory.exists(), "bar directory not exists"); + assertTrue(barDirectory.isDirectory(), "bar not a directory"); File bar = new File(barDirectory, "bar.txt"); - assertTrue("bar/bar.txt not exists", bar.exists()); - assertTrue("bar/bar.txt not a file", bar.isFile()); + assertTrue(bar.exists(), "bar/bar.txt not exists"); + assertTrue(bar.isFile(), "bar/bar.txt not a file"); } - public void testOneZipDefaultSkip() throws Exception { - File webAppDirectory = configureMojo("one-zip-overlay-skip"); + @InjectMojo(goal="war", pom = "src/test/resources/unit/warziptest/war-with-zip.xml") + @MojoParameter( + name = "outputDirectory", + value = "target/test-classes/unit/warziptest/one-zip-overlay-skip-output") + @MojoParameter(name = "warName", value = "simple") + @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/warziptest/work") + @Test + public void testOneZipDefaultSkip(WarMojo mojo) throws Exception { + MavenZipProject project = new MavenZipProject(); + File webAppDirectory = new File(getTestDirectory(), "one-zip-overlay-skip"); + WarArtifactStub warArtifact = new WarArtifactStub(getBasedir()); + File webAppSource = createWebAppSource("one-zip-overlay-skip"); + File classesDir = createClassesDir("one-zip-overlay-skip", true); + File xmlSource = createXMLConfigDir("one-zip-overlay-skip", new String[] {"web.xml"}); + project.setArtifact(warArtifact); + + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); + mojo.setWebXml(new File(xmlSource, "web.xml")); + + project.getArtifacts().add(buildZipArtifact()); mojo.execute(); assertZipContentNotHere(webAppDirectory); } - public void testOneZipWithForceSkip() throws Exception { - File webAppDirectory = configureMojo("one-zip-overlay-skip"); + @InjectMojo(goal="war", pom = "src/test/resources/unit/warziptest/war-with-zip.xml") + @MojoParameter( + name = "outputDirectory", + value = "target/test-classes/unit/warziptest/one-zip-overlay-skip-output") + @MojoParameter(name = "warName", value = "simple") + @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/warziptest/work") + @Test + public void testOneZipWithForceSkip(WarMojo mojo) throws Exception { + MavenZipProject project = new MavenZipProject(); + String outputDir = getTestDirectory().getAbsolutePath() + File.separatorChar + "one-zip-overlay-skip" + "-output"; + // clean up + File outputDirFile = new File(outputDir); + if (outputDirFile.exists()) { + FileUtils.deleteDirectory(outputDirFile); + } + File webAppDirectory = new File(getTestDirectory(), "one-zip-overlay-skip"); + WarArtifactStub warArtifact = new WarArtifactStub(getBasedir()); + File webAppSource = createWebAppSource("one-zip-overlay-skip"); + File classesDir = createClassesDir("one-zip-overlay-skip", true); + File xmlSource = createXMLConfigDir("one-zip-overlay-skip", new String[] {"web.xml"}); + project.setArtifact(warArtifact); + + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); + mojo.setWebXml(new File(xmlSource, "web.xml")); + + project.getArtifacts().add(buildZipArtifact()); + Overlay overlay = new DefaultOverlay(buildZipArtifact()); overlay.setSkip(true); overlay.setType("zip"); @@ -170,16 +267,16 @@ public void testOneZipWithForceSkip() throws Exception { protected void assertZipContentNotHere(File webAppDirectory) { File foo = new File(webAppDirectory.getPath() + File.separatorChar + "overridePath", "foo.txt"); - assertFalse("foo.txt exists", foo.exists()); - assertFalse("foo.txt a file", foo.isFile()); + assertFalse(foo.exists(), "foo.txt exists"); + assertFalse(foo.isFile(), "foo.txt a file"); File barDirectory = new File(webAppDirectory.getPath() + File.separatorChar + "overridePath", "bar"); - assertFalse("bar directory exists", barDirectory.exists()); - assertFalse("bar is a directory", barDirectory.isDirectory()); + assertFalse(barDirectory.exists(), "bar directory exists"); + assertFalse(barDirectory.isDirectory(), "bar is a directory"); File bar = new File(barDirectory, "bar.txt"); - assertFalse("bar/bar.txt exists", bar.exists()); - assertFalse("bar/bar.txt is a file", bar.isFile()); + assertFalse(bar.exists(), "bar/bar.txt exists"); + assertFalse(bar.isFile(), "bar/bar.txt is a file"); } /** @@ -192,10 +289,10 @@ protected void assertZipContentNotHere(File webAppDirectory) { * @param project The Maven project. * @throws Exception in case of errors */ + @MojoParameter(name = "outdatedCheckPath", value = "WEB-INF/lib/") protected void configureMojo( AbstractWarMojo mojo, File classesDir, File webAppSource, File webAppDir, MavenProjectBasicStub project) throws Exception { - setVariableValueToObject(mojo, "outdatedCheckPath", "WEB-INF/lib/"); mojo.setClassesDirectory(classesDir); mojo.setWarSourceDirectory(webAppSource); mojo.setWebappDirectory(webAppDir); @@ -283,7 +380,7 @@ protected File createClassesDir(String id, boolean empty) throws Exception { protected void createDir(File dir) { if (!dir.exists()) { - assertTrue("can not create test dir: " + dir.toString(), dir.mkdirs()); + assertTrue(dir.mkdirs(), "can not create test dir: " + dir.toString()); } } @@ -291,7 +388,7 @@ protected void createFile(File testFile, String body) throws Exception { createDir(testFile.getParentFile()); FileUtils.fileWrite(testFile.toString(), body); - assertTrue("could not create file: " + testFile, testFile.exists()); + assertTrue(testFile.exists(), "could not create file: " + testFile); } protected void createFile(File testFile) throws Exception { @@ -397,8 +494,8 @@ protected File getOverlayFile(String id, String filePath) { // Make sure the file exists assertTrue( - "Overlay file " + filePath + " does not exist for overlay " + id + " at " + file.getAbsolutePath(), - file.exists()); + file.exists(), + "Overlay file " + filePath + " does not exist for overlay " + id + " at " + file.getAbsolutePath()); return file; } From d5ade9d21df7d9fc8573d4fe8637fadb1fe4547c Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 5 Nov 2025 12:13:24 +0100 Subject: [PATCH 07/80] refactor: WarZipTest --- .../maven/plugins/war/WarInPlaceMojoTest.java | 9 +- .../apache/maven/plugins/war/WarZipTest.java | 363 ++++-------------- 2 files changed, 75 insertions(+), 297 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java index aac12828..fd303fd6 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java @@ -18,6 +18,8 @@ */ package org.apache.maven.plugins.war; +import java.io.File; + import org.apache.maven.api.plugin.testing.InjectMojo; import org.apache.maven.api.plugin.testing.MojoTest; import org.apache.maven.plugins.war.stub.MavenProjectBasicStub; @@ -25,8 +27,6 @@ import org.codehaus.plexus.util.FileUtils; import org.junit.jupiter.api.Test; -import java.io.File; - import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -37,8 +37,7 @@ private File getTestDirectory() throws Exception { return new File(getBasedir(), "target/test-classes/unit/warexplodedinplacemojo/test-dir"); } - - @InjectMojo(goal="inplace", pom = "src/test/resources/unit/warexplodedinplacemojo/plugin-config.xml" ) + @InjectMojo(goal = "inplace", pom = "src/test/resources/unit/warexplodedinplacemojo/plugin-config.xml") @Test public void testSimpleExplodedInplaceWar(WarInPlaceMojo mojo) throws Exception { // setup test data @@ -75,8 +74,6 @@ public void testSimpleExplodedInplaceWar(WarInPlaceMojo mojo) throws Exception { assertTrue(expectedMETAINFDir.exists(), "META-INF not found"); } - - /** * Returns the webapp source directory for the specified id. * diff --git a/src/test/java/org/apache/maven/plugins/war/WarZipTest.java b/src/test/java/org/apache/maven/plugins/war/WarZipTest.java index 196c25d9..02e44067 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarZipTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarZipTest.java @@ -21,29 +21,22 @@ import javax.inject.Inject; import java.io.File; -import java.io.IOException; import org.apache.maven.api.plugin.testing.InjectMojo; import org.apache.maven.api.plugin.testing.MojoParameter; import org.apache.maven.api.plugin.testing.MojoTest; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.handler.ArtifactHandler; -import org.apache.maven.plugin.testing.stubs.ArtifactStub; import org.apache.maven.plugins.war.overlay.DefaultOverlay; -import org.apache.maven.plugins.war.stub.MavenProjectBasicStub; import org.apache.maven.plugins.war.stub.MavenZipProject; import org.apache.maven.plugins.war.stub.WarArtifactStub; -import org.apache.maven.plugins.war.stub.WarOverlayStub; import org.apache.maven.plugins.war.stub.ZipArtifactStub; -import org.codehaus.plexus.archiver.ArchiverException; -import org.codehaus.plexus.archiver.jar.JarArchiver; import org.codehaus.plexus.util.FileUtils; import org.junit.jupiter.api.Test; import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; /** * @author Olivier Lamy @@ -53,90 +46,23 @@ public class WarZipTest { @Inject private ArtifactHandler artifactHandler; - protected static final File OVERLAYS_TEMP_DIR = new File(getBasedir(), "target/test-overlays/"); - protected static final File OVERLAYS_ROOT_DIR = new File(getBasedir(), "target/test-classes/overlays/"); - protected File getTestDirectory() { - return new File(getBasedir(), "target/test-classes/unit/warziptest"); - } - -// @BeforeEach -// public void setUp() throws Exception { -// super.setUp(); -// -// MavenExecutionRequest request = new DefaultMavenExecutionRequest() -// .setSystemProperties(System.getProperties()) -// .setStartTime(new Date()); -// -// MavenSession mavenSession = -// new MavenSession((PlexusContainer) null, (RepositorySystemSession) null, request, null); -// getContainer().addComponent(mavenSession, MavenSession.class.getName()); -// mojo = (WarMojo) lookupMojo("war", pomFile); -// } - - private Artifact buildZipArtifact() throws Exception { - File zipFile = new File(getTestDirectory(), "foobar.zip"); - return new ZipArtifactStub("src/test/resources/unit/warziptest", artifactHandler, zipFile); - } - - @MojoParameter( - name = "outputDirectory", - value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-output") + @InjectMojo(goal = "war", pom = "src/test/resources/unit/warziptest/war-with-zip.xml") + @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warziptest/one-zip-output") @MojoParameter(name = "warName", value = "simple") - private File configureMojo(String testId) throws Exception { - MavenZipProject project = new MavenZipProject(); - String outputDir = getTestDirectory().getAbsolutePath() + File.separatorChar + testId + "-output"; - // clean up - File outputDirFile = new File(outputDir); - if (outputDirFile.exists()) { - FileUtils.deleteDirectory(outputDirFile); - } + @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/warziptest/work") + @Test + public void testOneZipWithNoSkip(WarMojo mojo) throws Exception { + String testId = "one-zip"; File webAppDirectory = new File(getTestDirectory(), testId); - WarArtifactStub warArtifact = new WarArtifactStub(getBasedir()); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - project.setArtifact(warArtifact); - -// this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); -// setVariableValueToObject(mojo, "workDirectory", new File(getTestDirectory(), "work")); -// mojo.setWebXml(new File(xmlSource, "web.xml")); - - project.getArtifacts().add(buildZipArtifact()); - - return webAppDirectory; - } - - @InjectMojo(goal="war", pom = "src/test/resources/unit/warziptest/war-with-zip.xml") - @MojoParameter( - name = "outputDirectory", - value = "target/test-classes/unit/warziptest/one-zip-output") - @MojoParameter(name = "warName", value = "simple") - @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/warziptest/work") - @Test - public void testOneZipWithNoSkip(WarMojo mojo) throws Exception { - MavenZipProject project = new MavenZipProject(); - File webAppDirectory1 = new File(getTestDirectory(), "one-zip"); - WarArtifactStub warArtifact = new WarArtifactStub(getBasedir()); - File webAppSource = createWebAppSource("one-zip"); - File classesDir = createClassesDir("one-zip", true); - File xmlSource = createXMLConfigDir("one-zip", new String[] {"web.xml"}); - project.setArtifact(warArtifact); - - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory1); - mojo.setProject(project); - mojo.setWebXml(new File(xmlSource, "web.xml")); - - project.getArtifacts().add(buildZipArtifact()); - - File webAppDirectory = webAppDirectory1; Overlay overlay = new DefaultOverlay(buildZipArtifact()); - // overlay.setSkip( false ); overlay.setType("zip"); - mojo.addOverlay(overlay); + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, xmlSource, overlay); + mojo.execute(); File foo = new File(webAppDirectory, "foo.txt"); @@ -152,35 +78,24 @@ public void testOneZipWithNoSkip(WarMojo mojo) throws Exception { assertTrue(bar.isFile(), "bar/bar.txt not a file"); } - @InjectMojo(goal="war", pom = "src/test/resources/unit/warziptest/war-with-zip.xml") - @MojoParameter( - name = "outputDirectory", - value = "target/test-classes/unit/warziptest/one-zip-output") + @InjectMojo(goal = "war", pom = "src/test/resources/unit/warziptest/war-with-zip.xml") + @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warziptest/one-zip-output") @MojoParameter(name = "warName", value = "simple") @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/warziptest/work") @Test public void testOneZipWithTargetPathOverlay(WarMojo mojo) throws Exception { - MavenZipProject project = new MavenZipProject(); - File webAppDirectory = new File(getTestDirectory(), "one-zip-overlay-targetPath"); - WarArtifactStub warArtifact = new WarArtifactStub(getBasedir()); - File webAppSource = createWebAppSource("one-zip-overlay-targetPath"); - File classesDir = createClassesDir("one-zip-overlay-targetPath", true); - File xmlSource = createXMLConfigDir("one-zip-overlay-targetPath", new String[] {"web.xml"}); - project.setArtifact(warArtifact); - - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); - mojo.setWebXml(new File(xmlSource, "web.xml")); - - project.getArtifacts().add(buildZipArtifact()); + String testId = "one-zip-overlay-targetPath"; + File webAppDirectory = new File(getTestDirectory(), testId); + File webAppSource = createWebAppSource(testId); + File classesDir = createClassesDir(testId, true); + File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); Overlay overlay = new DefaultOverlay(buildZipArtifact()); overlay.setSkip(false); overlay.setType("zip"); overlay.setTargetPath("overridePath"); - mojo.addOverlay(overlay); + + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, xmlSource, overlay); mojo.execute(); @@ -197,64 +112,42 @@ public void testOneZipWithTargetPathOverlay(WarMojo mojo) throws Exception { assertTrue(bar.isFile(), "bar/bar.txt not a file"); } - @InjectMojo(goal="war", pom = "src/test/resources/unit/warziptest/war-with-zip.xml") + @InjectMojo(goal = "war", pom = "src/test/resources/unit/warziptest/war-with-zip.xml") @MojoParameter( name = "outputDirectory", - value = "target/test-classes/unit/warziptest/one-zip-overlay-skip-output") + value = "target/test-classes/unit/warziptest/one-zip-overlay-default-skip-output") @MojoParameter(name = "warName", value = "simple") @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/warziptest/work") @Test public void testOneZipDefaultSkip(WarMojo mojo) throws Exception { - MavenZipProject project = new MavenZipProject(); - File webAppDirectory = new File(getTestDirectory(), "one-zip-overlay-skip"); - WarArtifactStub warArtifact = new WarArtifactStub(getBasedir()); - File webAppSource = createWebAppSource("one-zip-overlay-skip"); - File classesDir = createClassesDir("one-zip-overlay-skip", true); - File xmlSource = createXMLConfigDir("one-zip-overlay-skip", new String[] {"web.xml"}); - project.setArtifact(warArtifact); - - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); - mojo.setWebXml(new File(xmlSource, "web.xml")); + String testId = "one-zip-overlay-default-skip"; + File webAppDirectory = new File(getTestDirectory(), testId); + File webAppSource = createWebAppSource(testId); + File classesDir = createClassesDir(testId, true); + File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - project.getArtifacts().add(buildZipArtifact()); + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, xmlSource); mojo.execute(); assertZipContentNotHere(webAppDirectory); } - @InjectMojo(goal="war", pom = "src/test/resources/unit/warziptest/war-with-zip.xml") + @InjectMojo(goal = "war", pom = "src/test/resources/unit/warziptest/war-with-zip.xml") @MojoParameter( name = "outputDirectory", - value = "target/test-classes/unit/warziptest/one-zip-overlay-skip-output") + value = "target/test-classes/unit/warziptest/one-zip-overlay-force-skip-output") @MojoParameter(name = "warName", value = "simple") @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/warziptest/work") @Test public void testOneZipWithForceSkip(WarMojo mojo) throws Exception { - MavenZipProject project = new MavenZipProject(); - String outputDir = getTestDirectory().getAbsolutePath() + File.separatorChar + "one-zip-overlay-skip" + "-output"; - // clean up - File outputDirFile = new File(outputDir); - if (outputDirFile.exists()) { - FileUtils.deleteDirectory(outputDirFile); - } - File webAppDirectory = new File(getTestDirectory(), "one-zip-overlay-skip"); - WarArtifactStub warArtifact = new WarArtifactStub(getBasedir()); - File webAppSource = createWebAppSource("one-zip-overlay-skip"); - File classesDir = createClassesDir("one-zip-overlay-skip", true); - File xmlSource = createXMLConfigDir("one-zip-overlay-skip", new String[] {"web.xml"}); - project.setArtifact(warArtifact); - - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); - mojo.setWebXml(new File(xmlSource, "web.xml")); + String testId = "one-zip-overlay-force-skip"; + File webAppDirectory = new File(getTestDirectory(), testId); + File webAppSource = createWebAppSource(testId); + File classesDir = createClassesDir(testId, true); + File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - project.getArtifacts().add(buildZipArtifact()); + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, xmlSource); Overlay overlay = new DefaultOverlay(buildZipArtifact()); overlay.setSkip(true); @@ -262,10 +155,40 @@ public void testOneZipWithForceSkip(WarMojo mojo) throws Exception { mojo.addOverlay(overlay); mojo.execute(); + assertZipContentNotHere(webAppDirectory); } - protected void assertZipContentNotHere(File webAppDirectory) { + private void configureMojo( + WarMojo mojo, File classesDir, File webAppSource, File webAppDirectory, File xmlSource, Overlay overlay) + throws Exception { + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, xmlSource); + mojo.addOverlay(overlay); + } + + private void configureMojo(WarMojo mojo, File classesDir, File webAppSource, File webAppDirectory, File xmlSource) + throws Exception { + WarArtifactStub warArtifact = new WarArtifactStub(getBasedir()); + MavenZipProject project = new MavenZipProject(); + project.setArtifact(warArtifact); + project.getArtifacts().add(buildZipArtifact()); + mojo.setProject(project); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setWebXml(new File(xmlSource, "web.xml")); + } + + private Artifact buildZipArtifact() throws Exception { + File zipFile = new File(getTestDirectory(), "foobar.zip"); + return new ZipArtifactStub("src/test/resources/unit/warziptest", artifactHandler, zipFile); + } + + private File getTestDirectory() { + return new File(getBasedir(), "target/test-classes/unit/warziptest"); + } + + private void assertZipContentNotHere(File webAppDirectory) { File foo = new File(webAppDirectory.getPath() + File.separatorChar + "overridePath", "foo.txt"); assertFalse(foo.exists(), "foo.txt exists"); assertFalse(foo.isFile(), "foo.txt a file"); @@ -279,26 +202,6 @@ protected void assertZipContentNotHere(File webAppDirectory) { assertFalse(bar.isFile(), "bar/bar.txt is a file"); } - /** - * initialize required parameters - * - * @param mojo The mojo to be tested. - * @param classesDir The classes' directory. - * @param webAppSource The webAppSource. - * @param webAppDir The webAppDir folder. - * @param project The Maven project. - * @throws Exception in case of errors - */ - @MojoParameter(name = "outdatedCheckPath", value = "WEB-INF/lib/") - protected void configureMojo( - AbstractWarMojo mojo, File classesDir, File webAppSource, File webAppDir, MavenProjectBasicStub project) - throws Exception { - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDir); - mojo.setProject(project); - } - /** * create an isolated xml dir * @@ -307,7 +210,7 @@ protected void configureMojo( * @return The created file. * @throws Exception in case of errors. */ - protected File createXMLConfigDir(String id, String[] xmlFiles) throws Exception { + private File createXMLConfigDir(String id, String[] xmlFiles) throws Exception { File xmlConfigDir = new File(getTestDirectory(), "/" + id + "-test-data/xml-config"); File xmlFile; @@ -330,7 +233,7 @@ protected File createXMLConfigDir(String id, String[] xmlFiles) throws Exception * @return the source directory for that test * @throws Exception if an exception occurs */ - protected File getWebAppSource(String id) throws Exception { + private File getWebAppSource(String id) throws Exception { return new File(getTestDirectory(), "/" + id + "-test-data/source"); } @@ -342,7 +245,7 @@ protected File getWebAppSource(String id) throws Exception { * @return The created file. * @throws Exception in case of errors. */ - protected File createWebAppSource(String id, boolean createSamples) throws Exception { + private File createWebAppSource(String id, boolean createSamples) throws Exception { File webAppSource = getWebAppSource(id); if (createSamples) { File simpleJSP = new File(webAppSource, "pansit.jsp"); @@ -354,7 +257,7 @@ protected File createWebAppSource(String id, boolean createSamples) throws Excep return webAppSource; } - protected File createWebAppSource(String id) throws Exception { + private File createWebAppSource(String id) throws Exception { return createWebAppSource(id, true); } @@ -366,7 +269,7 @@ protected File createWebAppSource(String id) throws Exception { * @return The created class file. * @throws Exception in case of errors. */ - protected File createClassesDir(String id, boolean empty) throws Exception { + private File createClassesDir(String id, boolean empty) throws Exception { File classesDir = new File(getTestDirectory() + "/" + id + "-test-data/classes/"); createDir(classesDir); @@ -378,142 +281,20 @@ protected File createClassesDir(String id, boolean empty) throws Exception { return classesDir; } - protected void createDir(File dir) { + private void createDir(File dir) { if (!dir.exists()) { assertTrue(dir.mkdirs(), "can not create test dir: " + dir.toString()); } } - protected void createFile(File testFile, String body) throws Exception { + private void createFile(File testFile, String body) throws Exception { createDir(testFile.getParentFile()); FileUtils.fileWrite(testFile.toString(), body); assertTrue(testFile.exists(), "could not create file: " + testFile); } - protected void createFile(File testFile) throws Exception { + private void createFile(File testFile) throws Exception { createFile(testFile, testFile.toString()); } - - /** - * Generates test war. - * Generates war with such a structure: - *
    - *
  • jsp - *
      - *
    • d - *
        - *
      • a.jsp
      • - *
      • b.jsp
      • - *
      • c.jsp
      • - *
      - *
    • - *
    • a.jsp
    • - *
    • b.jsp
    • - *
    • c.jsp
    • - *
    - *
  • - *
  • WEB-INF - *
      - *
    • classes - *
        - *
      • a.clazz
      • - *
      • b.clazz
      • - *
      • c.clazz
      • - *
      - *
    • - *
    • lib - *
        - *
      • a.jar
      • - *
      • b.jar
      • - *
      • c.jar
      • - *
      - *
    • - *
    • web.xml
    • - *
    - *
  • - *
- * Each of the files will contain: id+'-'+path - * - * @param id the id of the overlay containing the full structure - * @return the war file - * @throws Exception if an error occurs - */ - protected File generateFullOverlayWar(String id) throws Exception { - final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); - if (destFile.exists()) { - return destFile; - } - - // Archive was not yet created for that id so let's create it - final File rootDir = new File(OVERLAYS_ROOT_DIR, id); - rootDir.mkdirs(); - String[] filePaths = new String[] { - "jsp/d/a.jsp", - "jsp/d/b.jsp", - "jsp/d/c.jsp", - "jsp/a.jsp", - "jsp/b.jsp", - "jsp/c.jsp", - "WEB-INF/classes/a.clazz", - "WEB-INF/classes/b.clazz", - "WEB-INF/classes/c.clazz", - "WEB-INF/lib/a.jar", - "WEB-INF/lib/b.jar", - "WEB-INF/lib/c.jar", - "WEB-INF/web.xml" - }; - - for (String filePath : filePaths) { - createFile(new File(rootDir, filePath), id + "-" + filePath); - } - - createArchive(rootDir, destFile); - return destFile; - } - - /** - * Builds a test overlay. - * - * @param id the id of the overlay (see test/resources/overlays) - * @return a test war artifact with the content of the given test overlay - */ - protected ArtifactStub buildWarOverlayStub(String id) { - // Create war file - final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); - if (!destFile.exists()) { - createArchive(new File(OVERLAYS_ROOT_DIR, id), destFile); - } - - return new WarOverlayStub(getBasedir(), id, destFile); - } - - protected File getOverlayFile(String id, String filePath) { - final File overlayDir = new File(OVERLAYS_ROOT_DIR, id); - final File file = new File(overlayDir, filePath); - - // Make sure the file exists - assertTrue( - file.exists(), - "Overlay file " + filePath + " does not exist for overlay " + id + " at " + file.getAbsolutePath()); - return file; - } - - protected void createArchive(final File directory, final File destinationFile) { - try { - JarArchiver archiver = new JarArchiver(); - - archiver.setDestFile(destinationFile); - archiver.addDirectory(directory); - - archiver.createArchive(); - - } catch (ArchiverException e) { - e.printStackTrace(); - fail("Failed to create overlay archive " + e.getMessage()); - } catch (IOException e) { - e.printStackTrace(); - fail("Unexpected exception " + e.getMessage()); - } - } } From b3f18be53760770f7add4dbbdca40cf4c904bfef Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 5 Nov 2025 13:02:40 +0100 Subject: [PATCH 08/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarOverlaysTest --- .../maven/plugins/war/WarOverlaysTest.java | 693 +++++++++++------- 1 file changed, 422 insertions(+), 271 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java index a5f93a49..9cef193f 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java @@ -24,66 +24,78 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.Date; -import java.util.LinkedList; import java.util.List; -import org.apache.maven.execution.DefaultMavenExecutionRequest; -import org.apache.maven.execution.MavenExecutionRequest; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.testing.AbstractMojoTestCase; +import org.apache.maven.api.plugin.testing.InjectMojo; +import org.apache.maven.api.plugin.testing.MojoParameter; +import org.apache.maven.api.plugin.testing.MojoTest; import org.apache.maven.plugin.testing.stubs.ArtifactStub; -import org.apache.maven.plugins.war.overlay.DefaultOverlay; import org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub; import org.apache.maven.plugins.war.stub.MavenProjectBasicStub; import org.apache.maven.plugins.war.stub.WarOverlayStub; -import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.archiver.ArchiverException; import org.codehaus.plexus.archiver.jar.JarArchiver; import org.codehaus.plexus.util.FileUtils; -import org.eclipse.aether.RepositorySystemSession; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Stephane Nicoll */ -public class WarOverlaysTest extends AbstractMojoTestCase { +@MojoTest +public class WarOverlaysTest { protected static final File OVERLAYS_TEMP_DIR = new File(getBasedir(), "target/test-overlays/"); protected static final File OVERLAYS_ROOT_DIR = new File(getBasedir(), "target/test-classes/overlays/"); protected static final String MANIFEST_PATH = "META-INF" + File.separator + "MANIFEST.MF"; - private static File pomFile = new File(getBasedir(), "target/test-classes/unit/waroverlays/default.xml"); - protected WarExplodedMojo mojo; + @BeforeEach public void setUp() throws Exception { - super.setUp(); - - MavenExecutionRequest request = new DefaultMavenExecutionRequest() - .setSystemProperties(System.getProperties()) - .setStartTime(new Date()); - - MavenSession mavenSession = - new MavenSession((PlexusContainer) null, (RepositorySystemSession) null, request, null); - getContainer().addComponent(mavenSession, MavenSession.class.getName()); - mojo = (WarExplodedMojo) lookupMojo("exploded", getPomFile()); +// +// MavenExecutionRequest request = new DefaultMavenExecutionRequest() +// .setSystemProperties(System.getProperties()) +// .setStartTime(new Date()); +// +// MavenSession mavenSession = +// new MavenSession((PlexusContainer) null, (RepositorySystemSession) null, request, null); +// getContainer().addComponent(mavenSession, MavenSession.class.getName()); +// mojo = (WarExplodedMojo) lookupMojo("exploded", getPomFile()); generateFullOverlayWar("overlay-full-1"); generateFullOverlayWar("overlay-full-2"); generateFullOverlayWar("overlay-full-3"); } - protected File getPomFile() { - return pomFile; - } protected File getTestDirectory() { return new File(getBasedir(), "target/test-classes/unit/waroverlays"); } - public void testNoOverlay() throws Exception { + @InjectMojo(goal="exploded", pom ="src/test/resources/unit/waroverlays/default.xml") + @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-no-overlay") + @Test + public void testNoOverlay(WarExplodedMojo mojo) throws Exception { // setup test data final String testId = "no-overlay"; final File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - final File webAppDirectory = setUpMojo(testId, null); + final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + final File webAppDirectory = new File(getTestDirectory(), testId); + + // Create the webapp sources + File webAppSource = createWebAppSource(testId); + + final File classesDir = createClassesDir(testId, true); + + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); + try { mojo.setWebXml(new File(xmlSource, "web.xml")); mojo.execute(); @@ -96,14 +108,33 @@ public void testNoOverlay() throws Exception { } } - public void testDefaultOverlay() throws Exception { + @InjectMojo(goal="exploded", pom ="src/test/resources/unit/waroverlays/default.xml") + @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-default-overlay") + @Test + public void testDefaultOverlay(WarExplodedMojo mojo) throws Exception { // setup test data final String testId = "default-overlay"; // Add an overlay final ArtifactStub overlay = buildWarOverlayStub("overlay-one"); - final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] {overlay}); + ArtifactStub[] artifactStubs = new ArtifactStub[]{overlay}; + final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + final File webAppDirectory = new File(getTestDirectory(), testId); + + // Create the webapp sources + File webAppSource = createWebAppSource(testId); + + final File classesDir = createClassesDir(testId, true); + for (ArtifactStub artifactStub : artifactStubs) { + project.addArtifact(artifactStub); + } + + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); + final List assertedFiles = new ArrayList<>(); try { mojo.execute(); @@ -124,7 +155,10 @@ public void testDefaultOverlay() throws Exception { } } - public void testDefaultOverlays() throws Exception { + @InjectMojo(goal="exploded", pom ="src/test/resources/unit/waroverlays/default.xml") + @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-default-overlays") + @Test + public void testDefaultOverlays(WarExplodedMojo mojo) throws Exception { // setup test data final String testId = "default-overlays"; @@ -132,7 +166,24 @@ public void testDefaultOverlays() throws Exception { final ArtifactStub overlay = buildWarOverlayStub("overlay-one"); final ArtifactStub overlay2 = buildWarOverlayStub("overlay-two"); - final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] {overlay, overlay2}); + ArtifactStub[] artifactStubs = new ArtifactStub[]{overlay, overlay2}; + final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + final File webAppDirectory = new File(getTestDirectory(), testId); + + // Create the webapp sources + File webAppSource = createWebAppSource(testId); + + final File classesDir = createClassesDir(testId, true); + + for (ArtifactStub artifactStub : artifactStubs) { + project.addArtifact(artifactStub); + } + + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); + final List assertedFiles = new ArrayList<>(); try { mojo.execute(); @@ -164,7 +215,10 @@ public void testDefaultOverlays() throws Exception { * * @throws Exception if any error occurs */ - public void testScenarioOneWithDefaulSettings() throws Exception { + @InjectMojo(goal="exploded", pom ="src/test/resources/unit/waroverlays/default.xml") + @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-scenario-one-default-settings") + @Test + public void testScenarioOneWithDefaulSettings(WarExplodedMojo mojo) throws Exception { // setup test data final String testId = "scenario-one-default-settings"; @@ -173,79 +227,106 @@ public void testScenarioOneWithDefaulSettings() throws Exception { final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); - final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] {overlay1, overlay2, overlay3}, new String[] { - "org/sample/company/test.jsp", "jsp/b.jsp" - }); - - assertScenariOne(testId, webAppDirectory); - } - - /** - * Tests that specifying the overlay explicitely has the same behavior as the default (i.e. order, etc). - * - * The default project is not specified in this case so it is processed first by default - * - * @throws Exception if an error occurs - */ - public void testScenarioOneWithOverlaySettings() throws Exception { - // setup test data - final String testId = "scenario-one-overlay-settings"; - - // Add an overlay - final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); - final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); - final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); - - final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] {overlay1, overlay2, overlay3}, new String[] { + ArtifactStub[] artifactStubs = new ArtifactStub[] {overlay1, overlay2, overlay3}; + String[] sourceFiles = new String[] { "org/sample/company/test.jsp", "jsp/b.jsp" - }); - - // Add the tags - final List overlays = new ArrayList<>(); - overlays.add(new DefaultOverlay(overlay1)); - overlays.add(new DefaultOverlay(overlay2)); - overlays.add(new DefaultOverlay(overlay3)); - mojo.setOverlays(overlays); - - // current project ignored. Should be on top of the list - assertScenariOne(testId, webAppDirectory); - } - - /** - * Tests that specifying the overlay explicitely has the same behavior as the default (i.e. order, etc). - * - * The default project is explicitely specified so this should match the default. - * - * @throws Exception if an error occurs - */ - public void testScenarioOneWithFullSettings() throws Exception { - // setup test data - final String testId = "scenario-one-full-settings"; + }; + final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + final File webAppDirectory = new File(getTestDirectory(), testId); - // Add an overlay - final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); - final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); - final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); + // Create the webapp sources + File webAppSource = createWebAppSource(testId, false); + for (String sourceFile : sourceFiles) { + File sample = new File(webAppSource, sourceFile); + createFile(sample); + } - final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] {overlay1, overlay2, overlay3}, new String[] { - "org/sample/company/test.jsp", "jsp/b.jsp" - }); + final File classesDir = createClassesDir(testId, true); + final File workDirectory = new File(getTestDirectory(), "/war/work-" + testId); + createDir(workDirectory); - // Add the tags - final List overlays = new ArrayList<>(); + for (ArtifactStub artifactStub : artifactStubs) { + project.addArtifact(artifactStub); + } - // Add the default project explicitely - overlays.add(mojo.getCurrentProjectOverlay()); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); - // Other overlays - overlays.add(new DefaultOverlay(overlay1)); - overlays.add(new DefaultOverlay(overlay2)); - overlays.add(new DefaultOverlay(overlay3)); - mojo.setOverlays(overlays); + mojo.execute(); - // current project ignored. Should be on top of the list assertScenariOne(testId, webAppDirectory); } +// +// /** +// * Tests that specifying the overlay explicitely has the same behavior as the default (i.e. order, etc). +// * +// * The default project is not specified in this case so it is processed first by default +// * +// * @throws Exception if an error occurs +// */ +// @Test +// public void testScenarioOneWithOverlaySettings() throws Exception { +// // setup test data +// final String testId = "scenario-one-overlay-settings"; +// +// // Add an overlay +// final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); +// final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); +// final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); +// +// final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] {overlay1, overlay2, overlay3}, new String[] { +// "org/sample/company/test.jsp", "jsp/b.jsp" +// }); +// +// // Add the tags +// final List overlays = new ArrayList<>(); +// overlays.add(new DefaultOverlay(overlay1)); +// overlays.add(new DefaultOverlay(overlay2)); +// overlays.add(new DefaultOverlay(overlay3)); +// mojo.setOverlays(overlays); +// +// // current project ignored. Should be on top of the list +// assertScenariOne(testId, webAppDirectory); +// } +// +// /** +// * Tests that specifying the overlay explicitely has the same behavior as the default (i.e. order, etc). +// * +// * The default project is explicitely specified so this should match the default. +// * +// * @throws Exception if an error occurs +// */ +// @Test +// public void testScenarioOneWithFullSettings() throws Exception { +// // setup test data +// final String testId = "scenario-one-full-settings"; +// +// // Add an overlay +// final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); +// final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); +// final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); +// +// final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] {overlay1, overlay2, overlay3}, new String[] { +// "org/sample/company/test.jsp", "jsp/b.jsp" +// }); +// +// // Add the tags +// final List overlays = new ArrayList<>(); +// +// // Add the default project explicitely +// overlays.add(mojo.getCurrentProjectOverlay()); +// +// // Other overlays +// overlays.add(new DefaultOverlay(overlay1)); +// overlays.add(new DefaultOverlay(overlay2)); +// overlays.add(new DefaultOverlay(overlay3)); +// mojo.setOverlays(overlays); +// +// // current project ignored. Should be on top of the list +// assertScenariOne(testId, webAppDirectory); +// } /** * Runs the mojo and asserts a scenerio with 3 overlays and no includes/excludes settings. @@ -257,7 +338,6 @@ public void testScenarioOneWithFullSettings() throws Exception { private void assertScenariOne(String testId, File webAppDirectory) throws Exception { final List assertedFiles = new ArrayList<>(); try { - mojo.execute(); assertedFiles.addAll(assertWebXml(webAppDirectory)); assertedFiles.addAll(assertCustomContent( webAppDirectory, @@ -304,162 +384,230 @@ private void assertScenariOne(String testId, File webAppDirectory) throws Except } } - public void testOverlaysIncludesExcludesWithMultipleDefinitions() throws Exception { - // setup test data - final String testId = "overlays-includes-excludes-multiple-defs"; - - // Add an overlay - final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); - final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); - final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); - - final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] {overlay1, overlay2, overlay3}, new String[] { - "org/sample/company/test.jsp", "jsp/b.jsp" - }); - - Overlay over1 = new DefaultOverlay(overlay3); - over1.setExcludes("**/a.*,**/c.*,**/*.xml"); - - Overlay over2 = new DefaultOverlay(overlay1); - over2.setIncludes("jsp/d/*"); - over2.setExcludes("jsp/d/a.jsp"); - - Overlay over3 = new DefaultOverlay(overlay3); - over3.setIncludes("**/*.jsp"); - - Overlay over4 = new DefaultOverlay(overlay2); - - mojo.setOverlays(new LinkedList<>()); - mojo.addOverlay(over1); - mojo.addOverlay(over2); - mojo.addOverlay(over3); - mojo.addOverlay(mojo.getCurrentProjectOverlay()); - mojo.addOverlay(over4); - - final List assertedFiles = new ArrayList<>(); - try { - mojo.execute(); - assertedFiles.addAll(assertWebXml(webAppDirectory)); - assertedFiles.addAll(assertCustomContent( - webAppDirectory, - new String[] { - "jsp/a.jsp", - "jsp/b.jsp", - "jsp/c.jsp", - "jsp/d/a.jsp", - "jsp/d/b.jsp", - "jsp/d/c.jsp", - "org/sample/company/test.jsp", - "WEB-INF/classes/a.clazz", - "WEB-INF/classes/b.clazz", - "WEB-INF/classes/c.clazz", - "WEB-INF/lib/a.jar", - "WEB-INF/lib/b.jar", - "WEB-INF/lib/c.jar" - }, - "overlay file not found")); - - assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/a.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/b.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/c.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/a.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/b.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/c.jsp"); - assertDefaultFileContent(testId, webAppDirectory, "org/sample/company/test.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/web.xml"); - assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.clazz"); - assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.clazz"); - assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/c.clazz"); - assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/a.jar"); - assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/lib/b.jar"); - assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/c.jar"); - - // Ok now check that there is no more files/directories - final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] {MANIFEST_PATH}); - assertWebAppContent(webAppDirectory, assertedFiles, filter); - } finally { - cleanDirectory(webAppDirectory); - } - } - - public void testOverlaysIncludesExcludesWithMultipleDefinitions2() throws Exception { - // setup test data - final String testId = "overlays-includes-excludes-multiple-defs2"; - - // Add an overlay - final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); - final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); - final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); - - final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] {overlay1, overlay2, overlay3}, new String[] { - "org/sample/company/test.jsp", "jsp/b.jsp" - }); - - Overlay over1 = new DefaultOverlay(overlay3); - over1.setExcludes("**/a.*,**/c.*,**/*.xml,jsp/b.jsp"); - - Overlay over2 = new DefaultOverlay(overlay1); - over2.setIncludes("jsp/d/*"); - over2.setExcludes("jsp/d/a.jsp"); - - Overlay over3 = new DefaultOverlay(overlay3); - over3.setIncludes("**/*.jsp"); - over3.setExcludes("jsp/b.jsp"); - - Overlay over4 = new DefaultOverlay(overlay2); - - mojo.setOverlays(new LinkedList<>()); - mojo.addOverlay(over1); - mojo.addOverlay(over2); - mojo.addOverlay(over3); - mojo.addOverlay(mojo.getCurrentProjectOverlay()); - mojo.addOverlay(over4); - - final List assertedFiles = new ArrayList<>(); - try { - mojo.execute(); - assertedFiles.addAll(assertWebXml(webAppDirectory)); - assertedFiles.addAll(assertCustomContent( - webAppDirectory, - new String[] { - "jsp/a.jsp", - "jsp/b.jsp", - "jsp/c.jsp", - "jsp/d/a.jsp", - "jsp/d/b.jsp", - "jsp/d/c.jsp", - "org/sample/company/test.jsp", - "WEB-INF/classes/a.clazz", - "WEB-INF/classes/b.clazz", - "WEB-INF/classes/c.clazz", - "WEB-INF/lib/a.jar", - "WEB-INF/lib/b.jar", - "WEB-INF/lib/c.jar" - }, - "overlay file not found")); - - assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/a.jsp"); - assertDefaultFileContent(testId, webAppDirectory, "jsp/b.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/c.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/a.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/b.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/c.jsp"); - assertDefaultFileContent(testId, webAppDirectory, "org/sample/company/test.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/web.xml"); - assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.clazz"); - assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.clazz"); - assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/c.clazz"); - assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/a.jar"); - assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/lib/b.jar"); - assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/c.jar"); - - // Ok now check that there is no more files/directories - final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] {MANIFEST_PATH}); - assertWebAppContent(webAppDirectory, assertedFiles, filter); - } finally { - cleanDirectory(webAppDirectory); - } - } +// @Test +// public void testOverlaysIncludesExcludesWithMultipleDefinitions() throws Exception { +// // setup test data +// final String testId = "overlays-includes-excludes-multiple-defs"; +// +// // Add an overlay +// final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); +// final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); +// final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); +// +// ArtifactStub[] artifactStubs = new ArtifactStub[] {overlay1, overlay2, overlay3}; +// String[] sourceFiles = new String[] { +// "org/sample/company/test.jsp", "jsp/b.jsp" +// }; +// final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); +// final File webAppDirectory1 = new File(getTestDirectory(), testId); +// +// // Create the webapp sources +// File webAppSource; +// if (sourceFiles == null) { +// webAppSource = createWebAppSource(testId); +// } else { +// webAppSource = createWebAppSource(testId, false); +// for (String sourceFile : sourceFiles) { +// File sample = new File(webAppSource, sourceFile); +// createFile(sample); +// } +// } +// +// final File classesDir = createClassesDir(testId, true); +// final File workDirectory = new File(getTestDirectory(), "/war/work-" + testId); +// createDir(workDirectory); +// +// if (artifactStubs != null) { +// for (ArtifactStub artifactStub : artifactStubs) { +// project.addArtifact(artifactStub); +// } +// } +// +// mojo.setClassesDirectory(classesDir); +// mojo.setWarSourceDirectory(webAppSource); +// mojo.setWebappDirectory(webAppDirectory1); +// mojo.setProject((MavenProjectBasicStub) project); +// setVariableValueToObject(mojo, "workDirectory", workDirectory); +// +// final File webAppDirectory = webAppDirectory1; +// +// Overlay over1 = new DefaultOverlay(overlay3); +// over1.setExcludes("**/a.*,**/c.*,**/*.xml"); +// +// Overlay over2 = new DefaultOverlay(overlay1); +// over2.setIncludes("jsp/d/*"); +// over2.setExcludes("jsp/d/a.jsp"); +// +// Overlay over3 = new DefaultOverlay(overlay3); +// over3.setIncludes("**/*.jsp"); +// +// Overlay over4 = new DefaultOverlay(overlay2); +// +// mojo.setOverlays(new LinkedList<>()); +// mojo.addOverlay(over1); +// mojo.addOverlay(over2); +// mojo.addOverlay(over3); +// mojo.addOverlay(mojo.getCurrentProjectOverlay()); +// mojo.addOverlay(over4); +// +// final List assertedFiles = new ArrayList<>(); +// try { +// mojo.execute(); +// assertedFiles.addAll(assertWebXml(webAppDirectory)); +// assertedFiles.addAll(assertCustomContent( +// webAppDirectory, +// new String[] { +// "jsp/a.jsp", +// "jsp/b.jsp", +// "jsp/c.jsp", +// "jsp/d/a.jsp", +// "jsp/d/b.jsp", +// "jsp/d/c.jsp", +// "org/sample/company/test.jsp", +// "WEB-INF/classes/a.clazz", +// "WEB-INF/classes/b.clazz", +// "WEB-INF/classes/c.clazz", +// "WEB-INF/lib/a.jar", +// "WEB-INF/lib/b.jar", +// "WEB-INF/lib/c.jar" +// }, +// "overlay file not found")); +// +// assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/a.jsp"); +// assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/b.jsp"); +// assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/c.jsp"); +// assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/a.jsp"); +// assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/b.jsp"); +// assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/c.jsp"); +// assertDefaultFileContent(testId, webAppDirectory, "org/sample/company/test.jsp"); +// assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/web.xml"); +// assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.clazz"); +// assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.clazz"); +// assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/c.clazz"); +// assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/a.jar"); +// assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/lib/b.jar"); +// assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/c.jar"); +// +// // Ok now check that there is no more files/directories +// final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] {MANIFEST_PATH}); +// assertWebAppContent(webAppDirectory, assertedFiles, filter); +// } finally { +// cleanDirectory(webAppDirectory); +// } +// } +// +// @Test +// public void testOverlaysIncludesExcludesWithMultipleDefinitions2() throws Exception { +// // setup test data +// final String testId = "overlays-includes-excludes-multiple-defs2"; +// +// // Add an overlay +// final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); +// final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); +// final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); +// +// ArtifactStub[] artifactStubs = new ArtifactStub[] {overlay1, overlay2, overlay3}; +// String[] sourceFiles = new String[] { +// "org/sample/company/test.jsp", "jsp/b.jsp" +// }; +// final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); +// final File webAppDirectory1 = new File(getTestDirectory(), testId); +// +// // Create the webapp sources +// File webAppSource; +// if (sourceFiles == null) { +// webAppSource = createWebAppSource(testId); +// } else { +// webAppSource = createWebAppSource(testId, false); +// for (String sourceFile : sourceFiles) { +// File sample = new File(webAppSource, sourceFile); +// createFile(sample); +// } +// } +// +// final File classesDir = createClassesDir(testId, true); +// final File workDirectory = new File(getTestDirectory(), "/war/work-" + testId); +// createDir(workDirectory); +// +// if (artifactStubs != null) { +// for (ArtifactStub artifactStub : artifactStubs) { +// project.addArtifact(artifactStub); +// } +// } +// +// mojo.setClassesDirectory(classesDir); +// mojo.setWarSourceDirectory(webAppSource); +// mojo.setWebappDirectory(webAppDirectory1); +// mojo.setProject((MavenProjectBasicStub) project); +// setVariableValueToObject(mojo, "workDirectory", workDirectory); +// +// final File webAppDirectory = webAppDirectory1; +// +// Overlay over1 = new DefaultOverlay(overlay3); +// over1.setExcludes("**/a.*,**/c.*,**/*.xml,jsp/b.jsp"); +// +// Overlay over2 = new DefaultOverlay(overlay1); +// over2.setIncludes("jsp/d/*"); +// over2.setExcludes("jsp/d/a.jsp"); +// +// Overlay over3 = new DefaultOverlay(overlay3); +// over3.setIncludes("**/*.jsp"); +// over3.setExcludes("jsp/b.jsp"); +// +// Overlay over4 = new DefaultOverlay(overlay2); +// +// mojo.setOverlays(new LinkedList<>()); +// mojo.addOverlay(over1); +// mojo.addOverlay(over2); +// mojo.addOverlay(over3); +// mojo.addOverlay(mojo.getCurrentProjectOverlay()); +// mojo.addOverlay(over4); +// +// final List assertedFiles = new ArrayList<>(); +// try { +// mojo.execute(); +// assertedFiles.addAll(assertWebXml(webAppDirectory)); +// assertedFiles.addAll(assertCustomContent( +// webAppDirectory, +// new String[] { +// "jsp/a.jsp", +// "jsp/b.jsp", +// "jsp/c.jsp", +// "jsp/d/a.jsp", +// "jsp/d/b.jsp", +// "jsp/d/c.jsp", +// "org/sample/company/test.jsp", +// "WEB-INF/classes/a.clazz", +// "WEB-INF/classes/b.clazz", +// "WEB-INF/classes/c.clazz", +// "WEB-INF/lib/a.jar", +// "WEB-INF/lib/b.jar", +// "WEB-INF/lib/c.jar" +// }, +// "overlay file not found")); +// +// assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/a.jsp"); +// assertDefaultFileContent(testId, webAppDirectory, "jsp/b.jsp"); +// assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/c.jsp"); +// assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/a.jsp"); +// assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/b.jsp"); +// assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/c.jsp"); +// assertDefaultFileContent(testId, webAppDirectory, "org/sample/company/test.jsp"); +// assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/web.xml"); +// assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.clazz"); +// assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.clazz"); +// assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/c.clazz"); +// assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/a.jar"); +// assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/lib/b.jar"); +// assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/c.jar"); +// +// // Ok now check that there is no more files/directories +// final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] {MANIFEST_PATH}); +// assertWebAppContent(webAppDirectory, assertedFiles, filter); +// } finally { +// cleanDirectory(webAppDirectory); +// } +// } // Helpers @@ -478,9 +626,9 @@ protected void assertOverlayedFile(File webAppDirectory, String overlayId, Strin final File webAppFile = new File(webAppDirectory, filePath); final File overlayFile = getOverlayFile(overlayId, filePath); assertEquals( - "Wrong content for overlayed file " + filePath, FileUtils.fileRead(overlayFile), - FileUtils.fileRead(webAppFile)); + FileUtils.fileRead(webAppFile), + "Wrong content for overlayed file " + filePath); } /** @@ -498,7 +646,7 @@ protected void assertDefaultFileContent(String testId, File webAppDirectory, Str final File webAppFile = new File(webAppDirectory, filePath); final File sourceFile = new File(getWebAppSource(testId), filePath); final String expectedContent = sourceFile.toString(); - assertEquals("Wrong content for file " + filePath, expectedContent, FileUtils.fileRead(webAppFile)); + assertEquals(expectedContent, FileUtils.fileRead(webAppFile), "Wrong content for file " + filePath); } /** @@ -538,8 +686,11 @@ protected File setUpMojo(final String testId, ArtifactStub[] artifactStubs, Stri } } - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "workDirectory", workDirectory); +// mojo.setClassesDirectory(classesDir); +// mojo.setWarSourceDirectory(webAppSource); +// mojo.setWebappDirectory(webAppDirectory); +// mojo.setProject((MavenProjectBasicStub) project); +// setVariableValueToObject(mojo, "workDirectory", workDirectory); return webAppDirectory; } @@ -579,8 +730,8 @@ protected List assertDefaultContent(File webAppDirectory) { File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); - assertTrue("source file not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertTrue("source file not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); + assertTrue(expectedWebSourceFile.exists(), "source file not found: " + expectedWebSourceFile); + assertTrue(expectedWebSource2File.exists(), "source file not found: " + expectedWebSource2File); final List content = new ArrayList<>(); content.add(expectedWebSourceFile); @@ -597,7 +748,7 @@ protected List assertDefaultContent(File webAppDirectory) { */ protected List assertWebXml(File webAppDirectory) { File expectedWEBXMLFile = new File(webAppDirectory, "WEB-INF/web.xml"); - assertTrue("web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists()); + assertTrue(expectedWEBXMLFile.exists(), "web xml not found: " + expectedWEBXMLFile); final List content = new ArrayList<>(); content.add(expectedWEBXMLFile); @@ -618,9 +769,9 @@ protected List assertCustomContent(File webAppDirectory, String[] filePath for (String filePath : filePaths) { final File expectedFile = new File(webAppDirectory, filePath); if (customMessage != null) { - assertTrue(customMessage + " - " + expectedFile.toString(), expectedFile.exists()); + assertTrue(expectedFile.exists(), customMessage + " - " + expectedFile); } else { - assertTrue("source file not found: " + expectedFile.toString(), expectedFile.exists()); + assertTrue(expectedFile.exists(), "source file not found: " + expectedFile); } content.add(expectedFile); } @@ -646,10 +797,10 @@ protected void assertWebAppContent(File webAppDirectory, List expectedFile Collections.sort(expectedFiles); Collections.sort(webAppContent); assertEquals( - "Invalid webapp content, expected " + expectedFiles.size() + "file(s) " + expectedFiles + " but got " - + webAppContent.size() + " file(s) " + webAppContent, expectedFiles, - webAppContent); + webAppContent, + "Invalid webapp content, expected " + expectedFiles.size() + "file(s) " + expectedFiles + " but got " + + webAppContent.size() + " file(s) " + webAppContent); } /** @@ -688,10 +839,10 @@ private void buildFilesList(final File dir, FileFilter filter, final List * @param project The Maven project. * @throws Exception in case of errors */ + @MojoParameter(name = "outdatedCheckPath", value = "WEB-INF/lib/") protected void configureMojo( AbstractWarMojo mojo, File classesDir, File webAppSource, File webAppDir, MavenProjectBasicStub project) throws Exception { - setVariableValueToObject(mojo, "outdatedCheckPath", "WEB-INF/lib/"); mojo.setClassesDirectory(classesDir); mojo.setWarSourceDirectory(webAppSource); mojo.setWebappDirectory(webAppDir); @@ -779,7 +930,7 @@ protected File createClassesDir(String id, boolean empty) throws Exception { protected void createDir(File dir) { if (!dir.exists()) { - assertTrue("can not create test dir: " + dir.toString(), dir.mkdirs()); + assertTrue(dir.mkdirs(), "can not create test dir: " + dir); } } @@ -787,7 +938,7 @@ protected void createFile(File testFile, String body) throws Exception { createDir(testFile.getParentFile()); FileUtils.fileWrite(testFile.toString(), body); - assertTrue("could not create file: " + testFile, testFile.exists()); + assertTrue(testFile.exists(), "could not create file: " + testFile); } protected void createFile(File testFile) throws Exception { @@ -893,8 +1044,8 @@ protected File getOverlayFile(String id, String filePath) { // Make sure the file exists assertTrue( - "Overlay file " + filePath + " does not exist for overlay " + id + " at " + file.getAbsolutePath(), - file.exists()); + file.exists(), + "Overlay file " + filePath + " does not exist for overlay " + id + " at " + file.getAbsolutePath()); return file; } From 93483add53f49c88d21465b82d62977477b93c24 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 5 Nov 2025 13:13:40 +0100 Subject: [PATCH 09/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarOverlaysTest --- .../maven/plugins/war/WarOverlaysTest.java | 91 ++++++++++++------- 1 file changed, 59 insertions(+), 32 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java index 9cef193f..903fd80a 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java @@ -30,6 +30,7 @@ import org.apache.maven.api.plugin.testing.MojoParameter; import org.apache.maven.api.plugin.testing.MojoTest; import org.apache.maven.plugin.testing.stubs.ArtifactStub; +import org.apache.maven.plugins.war.overlay.DefaultOverlay; import org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub; import org.apache.maven.plugins.war.stub.MavenProjectBasicStub; import org.apache.maven.plugins.war.stub.WarOverlayStub; @@ -258,38 +259,64 @@ public void testScenarioOneWithDefaulSettings(WarExplodedMojo mojo) throws Excep assertScenariOne(testId, webAppDirectory); } -// -// /** -// * Tests that specifying the overlay explicitely has the same behavior as the default (i.e. order, etc). -// * -// * The default project is not specified in this case so it is processed first by default -// * -// * @throws Exception if an error occurs -// */ -// @Test -// public void testScenarioOneWithOverlaySettings() throws Exception { -// // setup test data -// final String testId = "scenario-one-overlay-settings"; -// -// // Add an overlay -// final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); -// final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); -// final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); -// -// final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] {overlay1, overlay2, overlay3}, new String[] { -// "org/sample/company/test.jsp", "jsp/b.jsp" -// }); -// -// // Add the tags -// final List overlays = new ArrayList<>(); -// overlays.add(new DefaultOverlay(overlay1)); -// overlays.add(new DefaultOverlay(overlay2)); -// overlays.add(new DefaultOverlay(overlay3)); -// mojo.setOverlays(overlays); -// -// // current project ignored. Should be on top of the list -// assertScenariOne(testId, webAppDirectory); -// } + + /** + * Tests that specifying the overlay explicitely has the same behavior as the default (i.e. order, etc). + * + * The default project is not specified in this case so it is processed first by default + * + * @throws Exception if an error occurs + */ + @InjectMojo(goal="exploded", pom ="src/test/resources/unit/waroverlays/default.xml") + @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-scenario-one-overlay-settings") + @Test + public void testScenarioOneWithOverlaySettings(WarExplodedMojo mojo) throws Exception { + // setup test data + final String testId = "scenario-one-overlay-settings"; + + // Add an overlay + final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); + final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); + final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); + + ArtifactStub[] artifactStubs = new ArtifactStub[] {overlay1, overlay2, overlay3}; + String[] sourceFiles = new String[] { + "org/sample/company/test.jsp", "jsp/b.jsp" + }; + final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + final File webAppDirectory = new File(getTestDirectory(), testId); + + // Create the webapp sources + File webAppSource; + webAppSource = createWebAppSource(testId, false); + for (String sourceFile : sourceFiles) { + File sample = new File(webAppSource, sourceFile); + createFile(sample); + } + + final File classesDir = createClassesDir(testId, true); + + for (ArtifactStub artifactStub : artifactStubs) { + project.addArtifact(artifactStub); + } + + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); + + // Add the tags + final List overlays = new ArrayList<>(); + overlays.add(new DefaultOverlay(overlay1)); + overlays.add(new DefaultOverlay(overlay2)); + overlays.add(new DefaultOverlay(overlay3)); + mojo.setOverlays(overlays); + + mojo.execute(); + + // current project ignored. Should be on top of the list + assertScenariOne(testId, webAppDirectory); + } // // /** // * Tests that specifying the overlay explicitely has the same behavior as the default (i.e. order, etc). From 933b5e1a6bdb63df1bb4cf57e34e4c49de439e62 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 5 Nov 2025 13:15:54 +0100 Subject: [PATCH 10/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarOverlaysTest --- .../maven/plugins/war/WarOverlaysTest.java | 530 +++++++++--------- 1 file changed, 269 insertions(+), 261 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java index 903fd80a..7c730067 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.LinkedList; import java.util.List; import org.apache.maven.api.plugin.testing.InjectMojo; @@ -317,43 +318,69 @@ public void testScenarioOneWithOverlaySettings(WarExplodedMojo mojo) throws Exce // current project ignored. Should be on top of the list assertScenariOne(testId, webAppDirectory); } -// -// /** -// * Tests that specifying the overlay explicitely has the same behavior as the default (i.e. order, etc). -// * -// * The default project is explicitely specified so this should match the default. -// * -// * @throws Exception if an error occurs -// */ -// @Test -// public void testScenarioOneWithFullSettings() throws Exception { -// // setup test data -// final String testId = "scenario-one-full-settings"; -// -// // Add an overlay -// final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); -// final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); -// final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); -// -// final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] {overlay1, overlay2, overlay3}, new String[] { -// "org/sample/company/test.jsp", "jsp/b.jsp" -// }); -// -// // Add the tags -// final List overlays = new ArrayList<>(); -// -// // Add the default project explicitely -// overlays.add(mojo.getCurrentProjectOverlay()); -// -// // Other overlays -// overlays.add(new DefaultOverlay(overlay1)); -// overlays.add(new DefaultOverlay(overlay2)); -// overlays.add(new DefaultOverlay(overlay3)); -// mojo.setOverlays(overlays); -// -// // current project ignored. Should be on top of the list -// assertScenariOne(testId, webAppDirectory); -// } + + /** + * Tests that specifying the overlay explicitely has the same behavior as the default (i.e. order, etc). + * + * The default project is explicitely specified so this should match the default. + * + * @throws Exception if an error occurs + */ + @InjectMojo(goal="exploded", pom ="src/test/resources/unit/waroverlays/default.xml") + @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-scenario-one-full-settings") + @Test + public void testScenarioOneWithFullSettings(WarExplodedMojo mojo) throws Exception { + // setup test data + final String testId = "scenario-one-full-settings"; + + // Add an overlay + final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); + final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); + final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); + + ArtifactStub[] artifactStubs = new ArtifactStub[] {overlay1, overlay2, overlay3}; + String[] sourceFiles = new String[] { + "org/sample/company/test.jsp", "jsp/b.jsp" + }; + final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + final File webAppDirectory = new File(getTestDirectory(), testId); + + // Create the webapp sources + File webAppSource = createWebAppSource(testId, false); + for (String sourceFile : sourceFiles) { + File sample = new File(webAppSource, sourceFile); + createFile(sample); + } + + final File classesDir = createClassesDir(testId, true); + + for (ArtifactStub artifactStub : artifactStubs) { + project.addArtifact(artifactStub); + } + + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); + + + // Add the tags + final List overlays = new ArrayList<>(); + + // Add the default project explicitely + overlays.add(mojo.getCurrentProjectOverlay()); + + // Other overlays + overlays.add(new DefaultOverlay(overlay1)); + overlays.add(new DefaultOverlay(overlay2)); + overlays.add(new DefaultOverlay(overlay3)); + mojo.setOverlays(overlays); + + mojo.execute(); + + // current project ignored. Should be on top of the list + assertScenariOne(testId, webAppDirectory); + } /** * Runs the mojo and asserts a scenerio with 3 overlays and no includes/excludes settings. @@ -411,230 +438,211 @@ private void assertScenariOne(String testId, File webAppDirectory) throws Except } } -// @Test -// public void testOverlaysIncludesExcludesWithMultipleDefinitions() throws Exception { -// // setup test data -// final String testId = "overlays-includes-excludes-multiple-defs"; -// -// // Add an overlay -// final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); -// final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); -// final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); -// -// ArtifactStub[] artifactStubs = new ArtifactStub[] {overlay1, overlay2, overlay3}; -// String[] sourceFiles = new String[] { -// "org/sample/company/test.jsp", "jsp/b.jsp" -// }; -// final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); -// final File webAppDirectory1 = new File(getTestDirectory(), testId); -// -// // Create the webapp sources -// File webAppSource; -// if (sourceFiles == null) { -// webAppSource = createWebAppSource(testId); -// } else { -// webAppSource = createWebAppSource(testId, false); -// for (String sourceFile : sourceFiles) { -// File sample = new File(webAppSource, sourceFile); -// createFile(sample); -// } -// } -// -// final File classesDir = createClassesDir(testId, true); -// final File workDirectory = new File(getTestDirectory(), "/war/work-" + testId); -// createDir(workDirectory); -// -// if (artifactStubs != null) { -// for (ArtifactStub artifactStub : artifactStubs) { -// project.addArtifact(artifactStub); -// } -// } -// -// mojo.setClassesDirectory(classesDir); -// mojo.setWarSourceDirectory(webAppSource); -// mojo.setWebappDirectory(webAppDirectory1); -// mojo.setProject((MavenProjectBasicStub) project); -// setVariableValueToObject(mojo, "workDirectory", workDirectory); -// -// final File webAppDirectory = webAppDirectory1; -// -// Overlay over1 = new DefaultOverlay(overlay3); -// over1.setExcludes("**/a.*,**/c.*,**/*.xml"); -// -// Overlay over2 = new DefaultOverlay(overlay1); -// over2.setIncludes("jsp/d/*"); -// over2.setExcludes("jsp/d/a.jsp"); -// -// Overlay over3 = new DefaultOverlay(overlay3); -// over3.setIncludes("**/*.jsp"); -// -// Overlay over4 = new DefaultOverlay(overlay2); -// -// mojo.setOverlays(new LinkedList<>()); -// mojo.addOverlay(over1); -// mojo.addOverlay(over2); -// mojo.addOverlay(over3); -// mojo.addOverlay(mojo.getCurrentProjectOverlay()); -// mojo.addOverlay(over4); -// -// final List assertedFiles = new ArrayList<>(); -// try { -// mojo.execute(); -// assertedFiles.addAll(assertWebXml(webAppDirectory)); -// assertedFiles.addAll(assertCustomContent( -// webAppDirectory, -// new String[] { -// "jsp/a.jsp", -// "jsp/b.jsp", -// "jsp/c.jsp", -// "jsp/d/a.jsp", -// "jsp/d/b.jsp", -// "jsp/d/c.jsp", -// "org/sample/company/test.jsp", -// "WEB-INF/classes/a.clazz", -// "WEB-INF/classes/b.clazz", -// "WEB-INF/classes/c.clazz", -// "WEB-INF/lib/a.jar", -// "WEB-INF/lib/b.jar", -// "WEB-INF/lib/c.jar" -// }, -// "overlay file not found")); -// -// assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/a.jsp"); -// assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/b.jsp"); -// assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/c.jsp"); -// assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/a.jsp"); -// assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/b.jsp"); -// assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/c.jsp"); -// assertDefaultFileContent(testId, webAppDirectory, "org/sample/company/test.jsp"); -// assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/web.xml"); -// assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.clazz"); -// assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.clazz"); -// assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/c.clazz"); -// assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/a.jar"); -// assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/lib/b.jar"); -// assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/c.jar"); -// -// // Ok now check that there is no more files/directories -// final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] {MANIFEST_PATH}); -// assertWebAppContent(webAppDirectory, assertedFiles, filter); -// } finally { -// cleanDirectory(webAppDirectory); -// } -// } -// -// @Test -// public void testOverlaysIncludesExcludesWithMultipleDefinitions2() throws Exception { -// // setup test data -// final String testId = "overlays-includes-excludes-multiple-defs2"; -// -// // Add an overlay -// final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); -// final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); -// final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); -// -// ArtifactStub[] artifactStubs = new ArtifactStub[] {overlay1, overlay2, overlay3}; -// String[] sourceFiles = new String[] { -// "org/sample/company/test.jsp", "jsp/b.jsp" -// }; -// final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); -// final File webAppDirectory1 = new File(getTestDirectory(), testId); -// -// // Create the webapp sources -// File webAppSource; -// if (sourceFiles == null) { -// webAppSource = createWebAppSource(testId); -// } else { -// webAppSource = createWebAppSource(testId, false); -// for (String sourceFile : sourceFiles) { -// File sample = new File(webAppSource, sourceFile); -// createFile(sample); -// } -// } -// -// final File classesDir = createClassesDir(testId, true); -// final File workDirectory = new File(getTestDirectory(), "/war/work-" + testId); -// createDir(workDirectory); -// -// if (artifactStubs != null) { -// for (ArtifactStub artifactStub : artifactStubs) { -// project.addArtifact(artifactStub); -// } -// } -// -// mojo.setClassesDirectory(classesDir); -// mojo.setWarSourceDirectory(webAppSource); -// mojo.setWebappDirectory(webAppDirectory1); -// mojo.setProject((MavenProjectBasicStub) project); -// setVariableValueToObject(mojo, "workDirectory", workDirectory); -// -// final File webAppDirectory = webAppDirectory1; -// -// Overlay over1 = new DefaultOverlay(overlay3); -// over1.setExcludes("**/a.*,**/c.*,**/*.xml,jsp/b.jsp"); -// -// Overlay over2 = new DefaultOverlay(overlay1); -// over2.setIncludes("jsp/d/*"); -// over2.setExcludes("jsp/d/a.jsp"); -// -// Overlay over3 = new DefaultOverlay(overlay3); -// over3.setIncludes("**/*.jsp"); -// over3.setExcludes("jsp/b.jsp"); -// -// Overlay over4 = new DefaultOverlay(overlay2); -// -// mojo.setOverlays(new LinkedList<>()); -// mojo.addOverlay(over1); -// mojo.addOverlay(over2); -// mojo.addOverlay(over3); -// mojo.addOverlay(mojo.getCurrentProjectOverlay()); -// mojo.addOverlay(over4); -// -// final List assertedFiles = new ArrayList<>(); -// try { -// mojo.execute(); -// assertedFiles.addAll(assertWebXml(webAppDirectory)); -// assertedFiles.addAll(assertCustomContent( -// webAppDirectory, -// new String[] { -// "jsp/a.jsp", -// "jsp/b.jsp", -// "jsp/c.jsp", -// "jsp/d/a.jsp", -// "jsp/d/b.jsp", -// "jsp/d/c.jsp", -// "org/sample/company/test.jsp", -// "WEB-INF/classes/a.clazz", -// "WEB-INF/classes/b.clazz", -// "WEB-INF/classes/c.clazz", -// "WEB-INF/lib/a.jar", -// "WEB-INF/lib/b.jar", -// "WEB-INF/lib/c.jar" -// }, -// "overlay file not found")); -// -// assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/a.jsp"); -// assertDefaultFileContent(testId, webAppDirectory, "jsp/b.jsp"); -// assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/c.jsp"); -// assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/a.jsp"); -// assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/b.jsp"); -// assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/c.jsp"); -// assertDefaultFileContent(testId, webAppDirectory, "org/sample/company/test.jsp"); -// assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/web.xml"); -// assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.clazz"); -// assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.clazz"); -// assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/c.clazz"); -// assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/a.jar"); -// assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/lib/b.jar"); -// assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/c.jar"); -// -// // Ok now check that there is no more files/directories -// final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] {MANIFEST_PATH}); -// assertWebAppContent(webAppDirectory, assertedFiles, filter); -// } finally { -// cleanDirectory(webAppDirectory); -// } -// } + @InjectMojo(goal="exploded", pom ="src/test/resources/unit/waroverlays/default.xml") + @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-overlays-includes-excludes-multiple-defs") + @Test + public void testOverlaysIncludesExcludesWithMultipleDefinitions(WarExplodedMojo mojo) throws Exception { + // setup test data + final String testId = "overlays-includes-excludes-multiple-defs"; + + // Add an overlay + final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); + final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); + final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); + + ArtifactStub[] artifactStubs = new ArtifactStub[] {overlay1, overlay2, overlay3}; + String[] sourceFiles = new String[] { + "org/sample/company/test.jsp", "jsp/b.jsp" + }; + final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + final File webAppDirectory = new File(getTestDirectory(), testId); + + // Create the webapp sources + File webAppSource = createWebAppSource(testId, false); + for (String sourceFile : sourceFiles) { + File sample = new File(webAppSource, sourceFile); + createFile(sample); + } + + final File classesDir = createClassesDir(testId, true); + + for (ArtifactStub artifactStub : artifactStubs) { + project.addArtifact(artifactStub); + } + + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); + + + Overlay over1 = new DefaultOverlay(overlay3); + over1.setExcludes("**/a.*,**/c.*,**/*.xml"); + + Overlay over2 = new DefaultOverlay(overlay1); + over2.setIncludes("jsp/d/*"); + over2.setExcludes("jsp/d/a.jsp"); + + Overlay over3 = new DefaultOverlay(overlay3); + over3.setIncludes("**/*.jsp"); + + Overlay over4 = new DefaultOverlay(overlay2); + + mojo.setOverlays(new LinkedList<>()); + mojo.addOverlay(over1); + mojo.addOverlay(over2); + mojo.addOverlay(over3); + mojo.addOverlay(mojo.getCurrentProjectOverlay()); + mojo.addOverlay(over4); + + final List assertedFiles = new ArrayList<>(); + try { + mojo.execute(); + assertedFiles.addAll(assertWebXml(webAppDirectory)); + assertedFiles.addAll(assertCustomContent( + webAppDirectory, + new String[] { + "jsp/a.jsp", + "jsp/b.jsp", + "jsp/c.jsp", + "jsp/d/a.jsp", + "jsp/d/b.jsp", + "jsp/d/c.jsp", + "org/sample/company/test.jsp", + "WEB-INF/classes/a.clazz", + "WEB-INF/classes/b.clazz", + "WEB-INF/classes/c.clazz", + "WEB-INF/lib/a.jar", + "WEB-INF/lib/b.jar", + "WEB-INF/lib/c.jar" + }, + "overlay file not found")); + + assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/a.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/b.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/c.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/a.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/b.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/c.jsp"); + assertDefaultFileContent(testId, webAppDirectory, "org/sample/company/test.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/web.xml"); + assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.clazz"); + assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.clazz"); + assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/c.clazz"); + assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/a.jar"); + assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/lib/b.jar"); + assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/c.jar"); + + // Ok now check that there is no more files/directories + final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] {MANIFEST_PATH}); + assertWebAppContent(webAppDirectory, assertedFiles, filter); + } finally { + cleanDirectory(webAppDirectory); + } + } + + @InjectMojo(goal="exploded", pom ="src/test/resources/unit/waroverlays/default.xml") + @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-overlays-includes-excludes-multiple-defs2") + @Test + public void testOverlaysIncludesExcludesWithMultipleDefinitions2(WarExplodedMojo mojo) throws Exception { + // setup test data + final String testId = "overlays-includes-excludes-multiple-defs2"; + + // Add an overlay + final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); + final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); + final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); + + ArtifactStub[] artifactStubs = new ArtifactStub[] {overlay1, overlay2, overlay3}; + String[] sourceFiles = new String[] { + "org/sample/company/test.jsp", "jsp/b.jsp" + }; + final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + final File webAppDirectory = new File(getTestDirectory(), testId); + + // Create the webapp sources + File webAppSource = createWebAppSource(testId, false); + for (String sourceFile : sourceFiles) { + File sample = new File(webAppSource, sourceFile); + createFile(sample); + } + + final File classesDir = createClassesDir(testId, true); + + for (ArtifactStub artifactStub : artifactStubs) { + project.addArtifact(artifactStub); + } + + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); + + Overlay over1 = new DefaultOverlay(overlay3); + over1.setExcludes("**/a.*,**/c.*,**/*.xml,jsp/b.jsp"); + + Overlay over2 = new DefaultOverlay(overlay1); + over2.setIncludes("jsp/d/*"); + over2.setExcludes("jsp/d/a.jsp"); + + Overlay over3 = new DefaultOverlay(overlay3); + over3.setIncludes("**/*.jsp"); + over3.setExcludes("jsp/b.jsp"); + + Overlay over4 = new DefaultOverlay(overlay2); + + mojo.setOverlays(new LinkedList<>()); + mojo.addOverlay(over1); + mojo.addOverlay(over2); + mojo.addOverlay(over3); + mojo.addOverlay(mojo.getCurrentProjectOverlay()); + mojo.addOverlay(over4); + + final List assertedFiles = new ArrayList<>(); + try { + mojo.execute(); + assertedFiles.addAll(assertWebXml(webAppDirectory)); + assertedFiles.addAll(assertCustomContent( + webAppDirectory, + new String[] { + "jsp/a.jsp", + "jsp/b.jsp", + "jsp/c.jsp", + "jsp/d/a.jsp", + "jsp/d/b.jsp", + "jsp/d/c.jsp", + "org/sample/company/test.jsp", + "WEB-INF/classes/a.clazz", + "WEB-INF/classes/b.clazz", + "WEB-INF/classes/c.clazz", + "WEB-INF/lib/a.jar", + "WEB-INF/lib/b.jar", + "WEB-INF/lib/c.jar" + }, + "overlay file not found")); + + assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/a.jsp"); + assertDefaultFileContent(testId, webAppDirectory, "jsp/b.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/c.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/a.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/b.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/c.jsp"); + assertDefaultFileContent(testId, webAppDirectory, "org/sample/company/test.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/web.xml"); + assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.clazz"); + assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.clazz"); + assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/c.clazz"); + assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/a.jar"); + assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/lib/b.jar"); + assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/c.jar"); + + // Ok now check that there is no more files/directories + final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] {MANIFEST_PATH}); + assertWebAppContent(webAppDirectory, assertedFiles, filter); + } finally { + cleanDirectory(webAppDirectory); + } + } // Helpers From b38cbbaab15f76200817d2298d2a080d5bf30156 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 5 Nov 2025 13:45:35 +0100 Subject: [PATCH 11/80] refactor: WarOverlaysTest --- .../maven/plugins/war/WarOverlaysTest.java | 766 +++++++----------- 1 file changed, 288 insertions(+), 478 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java index 7c730067..4126c190 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java @@ -33,7 +33,6 @@ import org.apache.maven.plugin.testing.stubs.ArtifactStub; import org.apache.maven.plugins.war.overlay.DefaultOverlay; import org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub; -import org.apache.maven.plugins.war.stub.MavenProjectBasicStub; import org.apache.maven.plugins.war.stub.WarOverlayStub; import org.codehaus.plexus.archiver.ArchiverException; import org.codehaus.plexus.archiver.jar.JarArchiver; @@ -52,162 +51,108 @@ @MojoTest public class WarOverlaysTest { - protected static final File OVERLAYS_TEMP_DIR = new File(getBasedir(), "target/test-overlays/"); - protected static final File OVERLAYS_ROOT_DIR = new File(getBasedir(), "target/test-classes/overlays/"); - protected static final String MANIFEST_PATH = "META-INF" + File.separator + "MANIFEST.MF"; + private static final File OVERLAYS_TEMP_DIR = new File(getBasedir(), "target/test-overlays/"); + private static final File OVERLAYS_ROOT_DIR = new File(getBasedir(), "target/test-classes/overlays/"); + private static final String MANIFEST_PATH = "META-INF" + File.separator + "MANIFEST.MF"; @BeforeEach public void setUp() throws Exception { -// -// MavenExecutionRequest request = new DefaultMavenExecutionRequest() -// .setSystemProperties(System.getProperties()) -// .setStartTime(new Date()); -// -// MavenSession mavenSession = -// new MavenSession((PlexusContainer) null, (RepositorySystemSession) null, request, null); -// getContainer().addComponent(mavenSession, MavenSession.class.getName()); -// mojo = (WarExplodedMojo) lookupMojo("exploded", getPomFile()); generateFullOverlayWar("overlay-full-1"); generateFullOverlayWar("overlay-full-2"); generateFullOverlayWar("overlay-full-3"); } - - protected File getTestDirectory() { + private File getTestDirectory() { return new File(getBasedir(), "target/test-classes/unit/waroverlays"); } - @InjectMojo(goal="exploded", pom ="src/test/resources/unit/waroverlays/default.xml") + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/waroverlays/default.xml") @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-no-overlay") @Test public void testNoOverlay(WarExplodedMojo mojo) throws Exception { // setup test data final String testId = "no-overlay"; final File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - - final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); final File webAppDirectory = new File(getTestDirectory(), testId); - - // Create the webapp sources + final File classesDir = createClassesDir(testId, true); File webAppSource = createWebAppSource(testId); - final File classesDir = createClassesDir(testId, true); + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, xmlSource); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + mojo.execute(); - try { - mojo.setWebXml(new File(xmlSource, "web.xml")); - mojo.execute(); - - // Validate content of the webapp - assertDefaultContent(webAppDirectory); - assertWebXml(webAppDirectory); - } finally { - cleanDirectory(webAppDirectory); - } + // Validate content of the webapp + assertDefaultContent(webAppDirectory); + assertWebXml(webAppDirectory); } - @InjectMojo(goal="exploded", pom ="src/test/resources/unit/waroverlays/default.xml") + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/waroverlays/default.xml") @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-default-overlay") @Test public void testDefaultOverlay(WarExplodedMojo mojo) throws Exception { // setup test data final String testId = "default-overlay"; + final File classesDir = createClassesDir(testId, true); + final File webAppDirectory = new File(getTestDirectory(), testId); + File webAppSource = createWebAppSource(testId); - // Add an overlay final ArtifactStub overlay = buildWarOverlayStub("overlay-one"); + final MavenProjectArtifactsStub project = createProjectWithOverlays(overlay); - ArtifactStub[] artifactStubs = new ArtifactStub[]{overlay}; - final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - final File webAppDirectory = new File(getTestDirectory(), testId); + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - // Create the webapp sources - File webAppSource = createWebAppSource(testId); + mojo.execute(); - final File classesDir = createClassesDir(testId, true); - for (ArtifactStub artifactStub : artifactStubs) { - project.addArtifact(artifactStub); - } + final List assertedFiles = new ArrayList<>(); + assertedFiles.addAll(assertDefaultContent(webAppDirectory)); + assertedFiles.addAll(assertWebXml(webAppDirectory)); + assertedFiles.addAll(assertCustomContent( + webAppDirectory, new String[] {"index.jsp", "login.jsp"}, "overlay file not found")); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + // index and login come from overlay1 + assertOverlayedFile(webAppDirectory, "overlay-one", "index.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-one", "login.jsp"); - final List assertedFiles = new ArrayList<>(); - try { - mojo.execute(); - assertedFiles.addAll(assertDefaultContent(webAppDirectory)); - assertedFiles.addAll(assertWebXml(webAppDirectory)); - assertedFiles.addAll(assertCustomContent( - webAppDirectory, new String[] {"index.jsp", "login.jsp"}, "overlay file not found")); - - // index and login come from overlay1 - assertOverlayedFile(webAppDirectory, "overlay-one", "index.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-one", "login.jsp"); - - // Ok now check that there is no more files/directories - final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] {MANIFEST_PATH}); - assertWebAppContent(webAppDirectory, assertedFiles, filter); - } finally { - cleanDirectory(webAppDirectory); - } + // Ok now check that there is no more files/directories + final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] {MANIFEST_PATH}); + assertWebAppContent(webAppDirectory, assertedFiles, filter); } - @InjectMojo(goal="exploded", pom ="src/test/resources/unit/waroverlays/default.xml") + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/waroverlays/default.xml") @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-default-overlays") @Test public void testDefaultOverlays(WarExplodedMojo mojo) throws Exception { // setup test data final String testId = "default-overlays"; + final File webAppDirectory = new File(getTestDirectory(), testId); + File webAppSource = createWebAppSource(testId); + final File classesDir = createClassesDir(testId, true); - // Add an overlay final ArtifactStub overlay = buildWarOverlayStub("overlay-one"); final ArtifactStub overlay2 = buildWarOverlayStub("overlay-two"); + final MavenProjectArtifactsStub project = createProjectWithOverlays(overlay, overlay2); - ArtifactStub[] artifactStubs = new ArtifactStub[]{overlay, overlay2}; - final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - final File webAppDirectory = new File(getTestDirectory(), testId); + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - // Create the webapp sources - File webAppSource = createWebAppSource(testId); + mojo.execute(); - final File classesDir = createClassesDir(testId, true); + final List assertedFiles = new ArrayList<>(); + assertedFiles.addAll(assertDefaultContent(webAppDirectory)); + assertedFiles.addAll(assertWebXml(webAppDirectory)); + assertedFiles.addAll(assertCustomContent( + webAppDirectory, new String[] {"index.jsp", "login.jsp", "admin.jsp"}, "overlay file not found")); - for (ArtifactStub artifactStub : artifactStubs) { - project.addArtifact(artifactStub); - } + // index and login come from overlay1 + assertOverlayedFile(webAppDirectory, "overlay-one", "index.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-one", "login.jsp"); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + // admin comes from overlay2 + // index and login comes from overlay1 + assertOverlayedFile(webAppDirectory, "overlay-two", "admin.jsp"); - final List assertedFiles = new ArrayList<>(); - try { - mojo.execute(); - assertedFiles.addAll(assertDefaultContent(webAppDirectory)); - assertedFiles.addAll(assertWebXml(webAppDirectory)); - assertedFiles.addAll(assertCustomContent( - webAppDirectory, new String[] {"index.jsp", "login.jsp", "admin.jsp"}, "overlay file not found")); - - // index and login come from overlay1 - assertOverlayedFile(webAppDirectory, "overlay-one", "index.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-one", "login.jsp"); - - // admin comes from overlay2 - // index and login comes from overlay1 - assertOverlayedFile(webAppDirectory, "overlay-two", "admin.jsp"); - - // Ok now check that there is no more files/directories - final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] {MANIFEST_PATH}); - assertWebAppContent(webAppDirectory, assertedFiles, filter); - } finally { - cleanDirectory(webAppDirectory); - } + // Ok now check that there is no more files/directories + final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] {MANIFEST_PATH}); + assertWebAppContent(webAppDirectory, assertedFiles, filter); } /** @@ -217,44 +162,31 @@ public void testDefaultOverlays(WarExplodedMojo mojo) throws Exception { * * @throws Exception if any error occurs */ - @InjectMojo(goal="exploded", pom ="src/test/resources/unit/waroverlays/default.xml") - @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-scenario-one-default-settings") + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/waroverlays/default.xml") + @MojoParameter( + name = "workDirectory", + value = "target/test-classes/unit/waroverlays/war/work-scenario-one-default-settings") @Test public void testScenarioOneWithDefaulSettings(WarExplodedMojo mojo) throws Exception { // setup test data final String testId = "scenario-one-default-settings"; - - // Add an overlay - final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); - final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); - final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); - - ArtifactStub[] artifactStubs = new ArtifactStub[] {overlay1, overlay2, overlay3}; - String[] sourceFiles = new String[] { - "org/sample/company/test.jsp", "jsp/b.jsp" - }; - final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + final File classesDir = createClassesDir(testId, true); final File webAppDirectory = new File(getTestDirectory(), testId); - - // Create the webapp sources File webAppSource = createWebAppSource(testId, false); + String[] sourceFiles = new String[] {"org/sample/company/test.jsp", "jsp/b.jsp"}; for (String sourceFile : sourceFiles) { File sample = new File(webAppSource, sourceFile); createFile(sample); } - final File classesDir = createClassesDir(testId, true); - final File workDirectory = new File(getTestDirectory(), "/war/work-" + testId); - createDir(workDirectory); + // Add an overlay + final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); + final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); + final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); - for (ArtifactStub artifactStub : artifactStubs) { - project.addArtifact(artifactStub); - } + final MavenProjectArtifactsStub project = createProjectWithOverlays(overlay1, overlay2, overlay3); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); mojo.execute(); @@ -268,43 +200,29 @@ public void testScenarioOneWithDefaulSettings(WarExplodedMojo mojo) throws Excep * * @throws Exception if an error occurs */ - @InjectMojo(goal="exploded", pom ="src/test/resources/unit/waroverlays/default.xml") - @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-scenario-one-overlay-settings") + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/waroverlays/default.xml") + @MojoParameter( + name = "workDirectory", + value = "target/test-classes/unit/waroverlays/war/work-scenario-one-overlay-settings") @Test public void testScenarioOneWithOverlaySettings(WarExplodedMojo mojo) throws Exception { // setup test data final String testId = "scenario-one-overlay-settings"; - - // Add an overlay - final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); - final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); - final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); - - ArtifactStub[] artifactStubs = new ArtifactStub[] {overlay1, overlay2, overlay3}; - String[] sourceFiles = new String[] { - "org/sample/company/test.jsp", "jsp/b.jsp" - }; - final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + final File classesDir = createClassesDir(testId, true); final File webAppDirectory = new File(getTestDirectory(), testId); - - // Create the webapp sources - File webAppSource; - webAppSource = createWebAppSource(testId, false); + File webAppSource = createWebAppSource(testId, false); + String[] sourceFiles = new String[] {"org/sample/company/test.jsp", "jsp/b.jsp"}; for (String sourceFile : sourceFiles) { File sample = new File(webAppSource, sourceFile); createFile(sample); } - final File classesDir = createClassesDir(testId, true); - - for (ArtifactStub artifactStub : artifactStubs) { - project.addArtifact(artifactStub); - } + // Add an overlay + final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); + final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); + final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + final MavenProjectArtifactsStub project = createProjectWithOverlays(overlay1, overlay2, overlay3); // Add the tags final List overlays = new ArrayList<>(); @@ -313,9 +231,10 @@ public void testScenarioOneWithOverlaySettings(WarExplodedMojo mojo) throws Exce overlays.add(new DefaultOverlay(overlay3)); mojo.setOverlays(overlays); + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + mojo.execute(); - // current project ignored. Should be on top of the list assertScenariOne(testId, webAppDirectory); } @@ -326,59 +245,44 @@ public void testScenarioOneWithOverlaySettings(WarExplodedMojo mojo) throws Exce * * @throws Exception if an error occurs */ - @InjectMojo(goal="exploded", pom ="src/test/resources/unit/waroverlays/default.xml") - @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-scenario-one-full-settings") + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/waroverlays/default.xml") + @MojoParameter( + name = "workDirectory", + value = "target/test-classes/unit/waroverlays/war/work-scenario-one-full-settings") @Test public void testScenarioOneWithFullSettings(WarExplodedMojo mojo) throws Exception { // setup test data final String testId = "scenario-one-full-settings"; - - // Add an overlay - final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); - final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); - final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); - - ArtifactStub[] artifactStubs = new ArtifactStub[] {overlay1, overlay2, overlay3}; - String[] sourceFiles = new String[] { - "org/sample/company/test.jsp", "jsp/b.jsp" - }; - final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + final File classesDir = createClassesDir(testId, true); final File webAppDirectory = new File(getTestDirectory(), testId); - - // Create the webapp sources File webAppSource = createWebAppSource(testId, false); + String[] sourceFiles = new String[] {"org/sample/company/test.jsp", "jsp/b.jsp"}; for (String sourceFile : sourceFiles) { File sample = new File(webAppSource, sourceFile); createFile(sample); } - final File classesDir = createClassesDir(testId, true); - - for (ArtifactStub artifactStub : artifactStubs) { - project.addArtifact(artifactStub); - } - - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + // Add an overlay + final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); + final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); + final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); + final MavenProjectArtifactsStub project = createProjectWithOverlays(overlay1, overlay2, overlay3); // Add the tags final List overlays = new ArrayList<>(); - // Add the default project explicitely overlays.add(mojo.getCurrentProjectOverlay()); - // Other overlays overlays.add(new DefaultOverlay(overlay1)); overlays.add(new DefaultOverlay(overlay2)); overlays.add(new DefaultOverlay(overlay3)); mojo.setOverlays(overlays); + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + mojo.execute(); - // current project ignored. Should be on top of the list assertScenariOne(testId, webAppDirectory); } @@ -391,90 +295,71 @@ public void testScenarioOneWithFullSettings(WarExplodedMojo mojo) throws Excepti */ private void assertScenariOne(String testId, File webAppDirectory) throws Exception { final List assertedFiles = new ArrayList<>(); - try { - assertedFiles.addAll(assertWebXml(webAppDirectory)); - assertedFiles.addAll(assertCustomContent( - webAppDirectory, - new String[] { - "jsp/a.jsp", - "jsp/b.jsp", - "jsp/c.jsp", - "jsp/d/a.jsp", - "jsp/d/b.jsp", - "jsp/d/c.jsp", - "org/sample/company/test.jsp", - "WEB-INF/classes/a.clazz", - "WEB-INF/classes/b.clazz", - "WEB-INF/classes/c.clazz", - "WEB-INF/lib/a.jar", - "WEB-INF/lib/b.jar", - "WEB-INF/lib/c.jar" - }, - "overlay file not found")); - - // Those files should come from the source webapp without any config - assertDefaultFileContent(testId, webAppDirectory, "jsp/b.jsp"); - assertDefaultFileContent(testId, webAppDirectory, "org/sample/company/test.jsp"); - - // Everything else comes from overlay1 (order of addition in the dependencies) - assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/a.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/c.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/a.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/b.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/c.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-1", "WEB-INF/web.xml"); - assertOverlayedFile(webAppDirectory, "overlay-full-1", "WEB-INF/classes/a.clazz"); - assertOverlayedFile(webAppDirectory, "overlay-full-1", "WEB-INF/classes/b.clazz"); - assertOverlayedFile(webAppDirectory, "overlay-full-1", "WEB-INF/classes/c.clazz"); - assertOverlayedFile(webAppDirectory, "overlay-full-1", "WEB-INF/lib/a.jar"); - assertOverlayedFile(webAppDirectory, "overlay-full-1", "WEB-INF/lib/b.jar"); - assertOverlayedFile(webAppDirectory, "overlay-full-1", "WEB-INF/lib/c.jar"); - - // Ok now check that there is no more files/directories - final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] {MANIFEST_PATH}); - assertWebAppContent(webAppDirectory, assertedFiles, filter); - } finally { - cleanDirectory(webAppDirectory); - } - } - - @InjectMojo(goal="exploded", pom ="src/test/resources/unit/waroverlays/default.xml") - @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-overlays-includes-excludes-multiple-defs") + assertedFiles.addAll(assertWebXml(webAppDirectory)); + assertedFiles.addAll(assertCustomContent( + webAppDirectory, + new String[] { + "jsp/a.jsp", + "jsp/b.jsp", + "jsp/c.jsp", + "jsp/d/a.jsp", + "jsp/d/b.jsp", + "jsp/d/c.jsp", + "org/sample/company/test.jsp", + "WEB-INF/classes/a.clazz", + "WEB-INF/classes/b.clazz", + "WEB-INF/classes/c.clazz", + "WEB-INF/lib/a.jar", + "WEB-INF/lib/b.jar", + "WEB-INF/lib/c.jar" + }, + "overlay file not found")); + + // Those files should come from the source webapp without any config + assertDefaultFileContent(testId, webAppDirectory, "jsp/b.jsp"); + assertDefaultFileContent(testId, webAppDirectory, "org/sample/company/test.jsp"); + + // Everything else comes from overlay1 (order of addition in the dependencies) + assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/a.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/c.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/a.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/b.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/c.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-1", "WEB-INF/web.xml"); + assertOverlayedFile(webAppDirectory, "overlay-full-1", "WEB-INF/classes/a.clazz"); + assertOverlayedFile(webAppDirectory, "overlay-full-1", "WEB-INF/classes/b.clazz"); + assertOverlayedFile(webAppDirectory, "overlay-full-1", "WEB-INF/classes/c.clazz"); + assertOverlayedFile(webAppDirectory, "overlay-full-1", "WEB-INF/lib/a.jar"); + assertOverlayedFile(webAppDirectory, "overlay-full-1", "WEB-INF/lib/b.jar"); + assertOverlayedFile(webAppDirectory, "overlay-full-1", "WEB-INF/lib/c.jar"); + + // Ok now check that there is no more files/directories + final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] {MANIFEST_PATH}); + assertWebAppContent(webAppDirectory, assertedFiles, filter); + } + + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/waroverlays/default.xml") + @MojoParameter( + name = "workDirectory", + value = "target/test-classes/unit/waroverlays/war/work-overlays-includes-excludes-multiple-defs") @Test public void testOverlaysIncludesExcludesWithMultipleDefinitions(WarExplodedMojo mojo) throws Exception { // setup test data final String testId = "overlays-includes-excludes-multiple-defs"; - - // Add an overlay - final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); - final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); - final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); - - ArtifactStub[] artifactStubs = new ArtifactStub[] {overlay1, overlay2, overlay3}; - String[] sourceFiles = new String[] { - "org/sample/company/test.jsp", "jsp/b.jsp" - }; - final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + final File classesDir = createClassesDir(testId, true); final File webAppDirectory = new File(getTestDirectory(), testId); - - // Create the webapp sources File webAppSource = createWebAppSource(testId, false); + String[] sourceFiles = new String[] {"org/sample/company/test.jsp", "jsp/b.jsp"}; for (String sourceFile : sourceFiles) { File sample = new File(webAppSource, sourceFile); createFile(sample); } + // Add an overlay + final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); + final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); + final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); - final File classesDir = createClassesDir(testId, true); - - for (ArtifactStub artifactStub : artifactStubs) { - project.addArtifact(artifactStub); - } - - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); - + final MavenProjectArtifactsStub project = createProjectWithOverlays(overlay1, overlay2, overlay3); Overlay over1 = new DefaultOverlay(overlay3); over1.setExcludes("**/a.*,**/c.*,**/*.xml"); @@ -495,88 +380,73 @@ public void testOverlaysIncludesExcludesWithMultipleDefinitions(WarExplodedMojo mojo.addOverlay(mojo.getCurrentProjectOverlay()); mojo.addOverlay(over4); - final List assertedFiles = new ArrayList<>(); - try { - mojo.execute(); - assertedFiles.addAll(assertWebXml(webAppDirectory)); - assertedFiles.addAll(assertCustomContent( - webAppDirectory, - new String[] { - "jsp/a.jsp", - "jsp/b.jsp", - "jsp/c.jsp", - "jsp/d/a.jsp", - "jsp/d/b.jsp", - "jsp/d/c.jsp", - "org/sample/company/test.jsp", - "WEB-INF/classes/a.clazz", - "WEB-INF/classes/b.clazz", - "WEB-INF/classes/c.clazz", - "WEB-INF/lib/a.jar", - "WEB-INF/lib/b.jar", - "WEB-INF/lib/c.jar" - }, - "overlay file not found")); - - assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/a.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/b.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/c.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/a.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/b.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/c.jsp"); - assertDefaultFileContent(testId, webAppDirectory, "org/sample/company/test.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/web.xml"); - assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.clazz"); - assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.clazz"); - assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/c.clazz"); - assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/a.jar"); - assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/lib/b.jar"); - assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/c.jar"); - - // Ok now check that there is no more files/directories - final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] {MANIFEST_PATH}); - assertWebAppContent(webAppDirectory, assertedFiles, filter); - } finally { - cleanDirectory(webAppDirectory); - } - } + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - @InjectMojo(goal="exploded", pom ="src/test/resources/unit/waroverlays/default.xml") - @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-overlays-includes-excludes-multiple-defs2") + mojo.execute(); + final List assertedFiles = new ArrayList<>(); + assertedFiles.addAll(assertWebXml(webAppDirectory)); + assertedFiles.addAll(assertCustomContent( + webAppDirectory, + new String[] { + "jsp/a.jsp", + "jsp/b.jsp", + "jsp/c.jsp", + "jsp/d/a.jsp", + "jsp/d/b.jsp", + "jsp/d/c.jsp", + "org/sample/company/test.jsp", + "WEB-INF/classes/a.clazz", + "WEB-INF/classes/b.clazz", + "WEB-INF/classes/c.clazz", + "WEB-INF/lib/a.jar", + "WEB-INF/lib/b.jar", + "WEB-INF/lib/c.jar" + }, + "overlay file not found")); + + assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/a.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/b.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/c.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/a.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/b.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/c.jsp"); + assertDefaultFileContent(testId, webAppDirectory, "org/sample/company/test.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/web.xml"); + assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.clazz"); + assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.clazz"); + assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/c.clazz"); + assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/a.jar"); + assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/lib/b.jar"); + assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/c.jar"); + + // Ok now check that there is no more files/directories + final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] {MANIFEST_PATH}); + assertWebAppContent(webAppDirectory, assertedFiles, filter); + } + + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/waroverlays/default.xml") + @MojoParameter( + name = "workDirectory", + value = "target/test-classes/unit/waroverlays/war/work-overlays-includes-excludes-multiple-defs2") @Test public void testOverlaysIncludesExcludesWithMultipleDefinitions2(WarExplodedMojo mojo) throws Exception { // setup test data final String testId = "overlays-includes-excludes-multiple-defs2"; - - // Add an overlay - final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); - final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); - final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); - - ArtifactStub[] artifactStubs = new ArtifactStub[] {overlay1, overlay2, overlay3}; - String[] sourceFiles = new String[] { - "org/sample/company/test.jsp", "jsp/b.jsp" - }; - final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + final File classesDir = createClassesDir(testId, true); final File webAppDirectory = new File(getTestDirectory(), testId); - - // Create the webapp sources File webAppSource = createWebAppSource(testId, false); + String[] sourceFiles = new String[] {"org/sample/company/test.jsp", "jsp/b.jsp"}; for (String sourceFile : sourceFiles) { File sample = new File(webAppSource, sourceFile); createFile(sample); } - final File classesDir = createClassesDir(testId, true); - - for (ArtifactStub artifactStub : artifactStubs) { - project.addArtifact(artifactStub); - } + // Add an overlay + final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); + final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); + final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + final MavenProjectArtifactsStub project = createProjectWithOverlays(overlay1, overlay2, overlay3); Overlay over1 = new DefaultOverlay(overlay3); over1.setExcludes("**/a.*,**/c.*,**/*.xml,jsp/b.jsp"); @@ -598,54 +468,84 @@ public void testOverlaysIncludesExcludesWithMultipleDefinitions2(WarExplodedMojo mojo.addOverlay(mojo.getCurrentProjectOverlay()); mojo.addOverlay(over4); + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + + mojo.execute(); + final List assertedFiles = new ArrayList<>(); - try { - mojo.execute(); - assertedFiles.addAll(assertWebXml(webAppDirectory)); - assertedFiles.addAll(assertCustomContent( - webAppDirectory, - new String[] { - "jsp/a.jsp", - "jsp/b.jsp", - "jsp/c.jsp", - "jsp/d/a.jsp", - "jsp/d/b.jsp", - "jsp/d/c.jsp", - "org/sample/company/test.jsp", - "WEB-INF/classes/a.clazz", - "WEB-INF/classes/b.clazz", - "WEB-INF/classes/c.clazz", - "WEB-INF/lib/a.jar", - "WEB-INF/lib/b.jar", - "WEB-INF/lib/c.jar" - }, - "overlay file not found")); - - assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/a.jsp"); - assertDefaultFileContent(testId, webAppDirectory, "jsp/b.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/c.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/a.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/b.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/c.jsp"); - assertDefaultFileContent(testId, webAppDirectory, "org/sample/company/test.jsp"); - assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/web.xml"); - assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.clazz"); - assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.clazz"); - assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/c.clazz"); - assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/a.jar"); - assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/lib/b.jar"); - assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/c.jar"); - - // Ok now check that there is no more files/directories - final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] {MANIFEST_PATH}); - assertWebAppContent(webAppDirectory, assertedFiles, filter); - } finally { - cleanDirectory(webAppDirectory); - } + assertedFiles.addAll(assertWebXml(webAppDirectory)); + assertedFiles.addAll(assertCustomContent( + webAppDirectory, + new String[] { + "jsp/a.jsp", + "jsp/b.jsp", + "jsp/c.jsp", + "jsp/d/a.jsp", + "jsp/d/b.jsp", + "jsp/d/c.jsp", + "org/sample/company/test.jsp", + "WEB-INF/classes/a.clazz", + "WEB-INF/classes/b.clazz", + "WEB-INF/classes/c.clazz", + "WEB-INF/lib/a.jar", + "WEB-INF/lib/b.jar", + "WEB-INF/lib/c.jar" + }, + "overlay file not found")); + + assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/a.jsp"); + assertDefaultFileContent(testId, webAppDirectory, "jsp/b.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/c.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/a.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/b.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/c.jsp"); + assertDefaultFileContent(testId, webAppDirectory, "org/sample/company/test.jsp"); + assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/web.xml"); + assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.clazz"); + assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.clazz"); + assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/c.clazz"); + assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/a.jar"); + assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/lib/b.jar"); + assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/c.jar"); + + // Ok now check that there is no more files/directories + final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] {MANIFEST_PATH}); + assertWebAppContent(webAppDirectory, assertedFiles, filter); } // Helpers + private void configureMojo( + WarExplodedMojo mojo, + File classesDir, + File webAppSource, + File webAppDirectory, + MavenProjectArtifactsStub project) { + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); + } + + private void configureMojo( + WarExplodedMojo mojo, File classesDir, File webAppSource, File webAppDirectory, File xmlSource) + throws Exception { + final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + mojo.setProject(project); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setWebXml(new File(xmlSource, "web.xml")); + } + + private MavenProjectArtifactsStub createProjectWithOverlays(ArtifactStub... artifactStubs) throws Exception { + final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + for (ArtifactStub artifactStub : artifactStubs) { + project.addArtifact(artifactStub); + } + return project; + } + /** * Asserts that the content of an overlayed file is correct. * @@ -657,7 +557,7 @@ public void testOverlaysIncludesExcludesWithMultipleDefinitions2(WarExplodedMojo * @param filePath the relative path * @throws IOException if an error occurred while reading the files */ - protected void assertOverlayedFile(File webAppDirectory, String overlayId, String filePath) throws IOException { + private void assertOverlayedFile(File webAppDirectory, String overlayId, String filePath) throws IOException { final File webAppFile = new File(webAppDirectory, filePath); final File overlayFile = getOverlayFile(overlayId, filePath); assertEquals( @@ -677,90 +577,20 @@ protected void assertOverlayedFile(File webAppDirectory, String overlayId, Strin * @param filePath the relative path * @throws IOException if an error occurred while reading the files */ - protected void assertDefaultFileContent(String testId, File webAppDirectory, String filePath) throws Exception { + private void assertDefaultFileContent(String testId, File webAppDirectory, String filePath) throws Exception { final File webAppFile = new File(webAppDirectory, filePath); final File sourceFile = new File(getWebAppSource(testId), filePath); final String expectedContent = sourceFile.toString(); assertEquals(expectedContent, FileUtils.fileRead(webAppFile), "Wrong content for file " + filePath); } - /** - * Configures the exploded mojo for the specified test. - * - * If the {@code sourceFiles} parameter is {@code null}, sample JSPs are created by default. - * - * @param testId the id of the test - * @param artifactStubs the dependencies (may be null) - * @param sourceFiles the source files to create (may be null) - * @return the webapp directory - * @throws Exception if an error occurs while configuring the mojo - */ - protected File setUpMojo(final String testId, ArtifactStub[] artifactStubs, String[] sourceFiles) throws Exception { - final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - final File webAppDirectory = new File(getTestDirectory(), testId); - - // Create the webapp sources - File webAppSource; - if (sourceFiles == null) { - webAppSource = createWebAppSource(testId); - } else { - webAppSource = createWebAppSource(testId, false); - for (String sourceFile : sourceFiles) { - File sample = new File(webAppSource, sourceFile); - createFile(sample); - } - } - - final File classesDir = createClassesDir(testId, true); - final File workDirectory = new File(getTestDirectory(), "/war/work-" + testId); - createDir(workDirectory); - - if (artifactStubs != null) { - for (ArtifactStub artifactStub : artifactStubs) { - project.addArtifact(artifactStub); - } - } - -// mojo.setClassesDirectory(classesDir); -// mojo.setWarSourceDirectory(webAppSource); -// mojo.setWebappDirectory(webAppDirectory); -// mojo.setProject((MavenProjectBasicStub) project); -// setVariableValueToObject(mojo, "workDirectory", workDirectory); - - return webAppDirectory; - } - - /** - * Configures the exploded mojo for the specified test. - * - * @param testId the id of the test - * @param artifactStubs the dependencies (may be null) - * @return the webapp directory - * @throws Exception if an error occurs while configuring the mojo - */ - protected File setUpMojo(final String testId, ArtifactStub[] artifactStubs) throws Exception { - return setUpMojo(testId, artifactStubs, null); - } - - /** - * Cleans up a directory. - * - * @param directory the directory to remove - * @throws IOException if an error occurred while removing the directory - */ - protected void cleanDirectory(File directory) throws IOException { - if (directory != null && directory.isDirectory() && directory.exists()) { - FileUtils.deleteDirectory(directory); - } - } - /** * Asserts the default content of the war based on the specified webapp directory. * * @param webAppDirectory the webapp directory * @return a list of File objects that have been asserted */ - protected List assertDefaultContent(File webAppDirectory) { + private List assertDefaultContent(File webAppDirectory) { // Validate content of the webapp File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); @@ -781,7 +611,7 @@ protected List assertDefaultContent(File webAppDirectory) { * @param webAppDirectory the webapp directory * @return a list with the web.xml File object */ - protected List assertWebXml(File webAppDirectory) { + private List assertWebXml(File webAppDirectory) { File expectedWEBXMLFile = new File(webAppDirectory, "WEB-INF/web.xml"); assertTrue(expectedWEBXMLFile.exists(), "web xml not found: " + expectedWEBXMLFile); @@ -799,7 +629,7 @@ protected List assertWebXml(File webAppDirectory) { * @param customMessage a custom message if an assertion fails * @return a list of File objects that have been inspected */ - protected List assertCustomContent(File webAppDirectory, String[] filePaths, String customMessage) { + private List assertCustomContent(File webAppDirectory, String[] filePaths, String customMessage) { final List content = new ArrayList<>(); for (String filePath : filePaths) { final File expectedFile = new File(webAppDirectory, filePath); @@ -820,7 +650,7 @@ protected List assertCustomContent(File webAppDirectory, String[] filePath * @param expectedFiles the expected files * @param filter an optional filter to ignore some resources */ - protected void assertWebAppContent(File webAppDirectory, List expectedFiles, FileFilter filter) { + private void assertWebAppContent(File webAppDirectory, List expectedFiles, FileFilter filter) { final List webAppContent = new ArrayList<>(); if (filter != null) { buildFilesList(webAppDirectory, filter, webAppContent); @@ -864,26 +694,6 @@ private void buildFilesList(final File dir, FileFilter filter, final List } } - /** - * initialize required parameters - * - * @param mojo The mojo to be tested. - * @param classesDir The classes' directory. - * @param webAppSource The webAppSource. - * @param webAppDir The webAppDir folder. - * @param project The Maven project. - * @throws Exception in case of errors - */ - @MojoParameter(name = "outdatedCheckPath", value = "WEB-INF/lib/") - protected void configureMojo( - AbstractWarMojo mojo, File classesDir, File webAppSource, File webAppDir, MavenProjectBasicStub project) - throws Exception { - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDir); - mojo.setProject(project); - } - /** * create an isolated xml dir * @@ -892,7 +702,7 @@ protected void configureMojo( * @return The created file. * @throws Exception in case of errors. */ - protected File createXMLConfigDir(String id, String[] xmlFiles) throws Exception { + private File createXMLConfigDir(String id, String[] xmlFiles) throws Exception { File xmlConfigDir = new File(getTestDirectory(), "/" + id + "-test-data/xml-config"); File xmlFile; @@ -915,7 +725,7 @@ protected File createXMLConfigDir(String id, String[] xmlFiles) throws Exception * @return the source directory for that test * @throws Exception if an exception occurs */ - protected File getWebAppSource(String id) throws Exception { + private File getWebAppSource(String id) throws Exception { return new File(getTestDirectory(), "/" + id + "-test-data/source"); } @@ -927,7 +737,7 @@ protected File getWebAppSource(String id) throws Exception { * @return The created file. * @throws Exception in case of errors. */ - protected File createWebAppSource(String id, boolean createSamples) throws Exception { + private File createWebAppSource(String id, boolean createSamples) throws Exception { File webAppSource = getWebAppSource(id); if (createSamples) { File simpleJSP = new File(webAppSource, "pansit.jsp"); @@ -939,7 +749,7 @@ protected File createWebAppSource(String id, boolean createSamples) throws Excep return webAppSource; } - protected File createWebAppSource(String id) throws Exception { + private File createWebAppSource(String id) throws Exception { return createWebAppSource(id, true); } @@ -951,7 +761,7 @@ protected File createWebAppSource(String id) throws Exception { * @return The created class file. * @throws Exception in case of errors. */ - protected File createClassesDir(String id, boolean empty) throws Exception { + private File createClassesDir(String id, boolean empty) throws Exception { File classesDir = new File(getTestDirectory() + "/" + id + "-test-data/classes/"); createDir(classesDir); @@ -963,20 +773,20 @@ protected File createClassesDir(String id, boolean empty) throws Exception { return classesDir; } - protected void createDir(File dir) { + private void createDir(File dir) { if (!dir.exists()) { assertTrue(dir.mkdirs(), "can not create test dir: " + dir); } } - protected void createFile(File testFile, String body) throws Exception { + private void createFile(File testFile, String body) throws Exception { createDir(testFile.getParentFile()); FileUtils.fileWrite(testFile.toString(), body); assertTrue(testFile.exists(), "could not create file: " + testFile); } - protected void createFile(File testFile) throws Exception { + private void createFile(File testFile) throws Exception { createFile(testFile, testFile.toString()); } @@ -1024,7 +834,7 @@ protected void createFile(File testFile) throws Exception { * @return the war file * @throws Exception if an error occurs */ - protected File generateFullOverlayWar(String id) throws Exception { + private File generateFullOverlayWar(String id) throws Exception { final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); if (destFile.exists()) { return destFile; @@ -1063,7 +873,7 @@ protected File generateFullOverlayWar(String id) throws Exception { * @param id the id of the overlay (see test/resources/overlays) * @return a test war artifact with the content of the given test overlay */ - protected ArtifactStub buildWarOverlayStub(String id) { + private ArtifactStub buildWarOverlayStub(String id) { // Create war file final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); if (!destFile.exists()) { @@ -1073,7 +883,7 @@ protected ArtifactStub buildWarOverlayStub(String id) { return new WarOverlayStub(getBasedir(), id, destFile); } - protected File getOverlayFile(String id, String filePath) { + private File getOverlayFile(String id, String filePath) { final File overlayDir = new File(OVERLAYS_ROOT_DIR, id); final File file = new File(overlayDir, filePath); @@ -1084,7 +894,7 @@ protected File getOverlayFile(String id, String filePath) { return file; } - protected void createArchive(final File directory, final File destinationFile) { + private void createArchive(final File directory, final File destinationFile) { try { JarArchiver archiver = new JarArchiver(); From e87257994964f7fa8af70a25e03be5d325d754d1 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 5 Nov 2025 13:55:04 +0100 Subject: [PATCH 12/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarExplodedMojoTest --- .../plugins/war/WarExplodedMojoTest.java | 995 ++++++------------ 1 file changed, 319 insertions(+), 676 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index da3bc487..f7fffe23 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -18,22 +18,16 @@ */ package org.apache.maven.plugins.war; +import javax.inject.Inject; + import java.io.File; -import java.io.FileFilter; -import java.io.IOException; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Date; -import java.util.List; import java.util.Locale; +import org.apache.maven.api.plugin.testing.InjectMojo; +import org.apache.maven.api.plugin.testing.MojoParameter; +import org.apache.maven.api.plugin.testing.MojoTest; import org.apache.maven.artifact.handler.ArtifactHandler; -import org.apache.maven.execution.DefaultMavenExecutionRequest; -import org.apache.maven.execution.MavenExecutionRequest; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.apache.maven.plugin.testing.stubs.ArtifactStub; import org.apache.maven.plugins.war.stub.AarArtifactStub; import org.apache.maven.plugins.war.stub.EJBArtifactStub; @@ -48,35 +42,30 @@ import org.apache.maven.plugins.war.stub.ResourceStub; import org.apache.maven.plugins.war.stub.TLDArtifactStub; import org.apache.maven.plugins.war.stub.WarArtifactStub; -import org.apache.maven.plugins.war.stub.WarOverlayStub; import org.apache.maven.plugins.war.stub.XarArtifactStub; -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.archiver.ArchiverException; -import org.codehaus.plexus.archiver.jar.JarArchiver; import org.codehaus.plexus.util.FileUtils; -import org.eclipse.aether.RepositorySystemSession; - -import static org.junit.Assert.assertNotEquals; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; -public class WarExplodedMojoTest extends AbstractMojoTestCase { +import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; - protected static final File OVERLAYS_TEMP_DIR = new File(getBasedir(), "target/test-overlays/"); - protected static final File OVERLAYS_ROOT_DIR = new File(getBasedir(), "target/test-classes/overlays/"); - protected static final String MANIFEST_PATH = "META-INF" + File.separator + "MANIFEST.MF"; - protected WarExplodedMojo mojo; +@MojoTest +public class WarExplodedMojoTest { - protected File getPomFile() { - return new File(getBasedir(), "/target/test-classes/unit/warexplodedmojo/plugin-config.xml"); - } + @Inject + private ArtifactHandler artifactHandler; protected File getTestDirectory() { return new File(getBasedir(), "target/test-classes/unit/warexplodedmojo/test-dir"); } - /** - * @throws Exception in case of an error. - */ - public void testSimpleExplodedWar() throws Exception { + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @Test + public void testSimpleExplodedWar(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "SimpleExplodedWar"; MavenProjectBasicStub project = new MavenProjectBasicStub(); @@ -85,16 +74,13 @@ public void testSimpleExplodedWar() throws Exception { File webAppResource = new File(getTestDirectory(), testId + "-resources"); File webAppDirectory = new File(getTestDirectory(), testId); File sampleResource = new File(webAppResource, "pix/panis_na.jpg"); - ResourceStub[] resources = new ResourceStub[] {new ResourceStub()}; - - createFile(sampleResource); + ResourceStub[] resources = createWebResources(sampleResource, webAppResource); - assertTrue("sampeResource not found", sampleResource.exists()); - - // configure mojo - resources[0].setDirectory(webAppResource.getAbsolutePath()); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "webResources", resources); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); + mojo.setWebResources(resources); mojo.execute(); // validate operation @@ -104,11 +90,11 @@ public void testSimpleExplodedWar() throws Exception { File expectedWEBINFDir = new File(webAppDirectory, "WEB-INF"); File expectedMETAINFDir = new File(webAppDirectory, "META-INF"); - assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); - assertTrue("resources doesn't exist: " + expectedWebResourceFile, expectedWebResourceFile.exists()); - assertTrue("WEB-INF not found", expectedWEBINFDir.exists()); - assertTrue("META-INF not found", expectedMETAINFDir.exists()); + assertTrue(expectedWebSourceFile.exists(), "source files not found: " + expectedWebSourceFile); + assertTrue(expectedWebSource2File.exists(), "source files not found: " + expectedWebSource2File); + assertTrue(expectedWebResourceFile.exists(), "resources doesn't exist: " + expectedWebResourceFile); + assertTrue(expectedWEBINFDir.exists(), "WEB-INF not found"); + assertTrue(expectedMETAINFDir.exists(), "META-INF not found"); // housekeeping expectedWebSourceFile.delete(); @@ -116,10 +102,16 @@ public void testSimpleExplodedWar() throws Exception { expectedWebResourceFile.delete(); } - /** - * @throws Exception in case of an error. - */ - public void testSimpleExplodedWarWTargetPath() throws Exception { + private ResourceStub[] createWebResources(File sampleResource, File webAppResource) throws Exception { + ResourceStub[] resources = new ResourceStub[] {new ResourceStub()}; + createFile(sampleResource); + resources[0].setDirectory(webAppResource.getAbsolutePath()); + return resources; + } + + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @Test + public void testSimpleExplodedWarWTargetPath(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "SimpleExplodedWar"; MavenProjectBasicStub project = new MavenProjectBasicStub(); @@ -128,15 +120,14 @@ public void testSimpleExplodedWarWTargetPath() throws Exception { File webAppResource = new File(getTestDirectory(), "resources"); File webAppDirectory = new File(getTestDirectory(), testId); File sampleResource = new File(webAppResource, "pix/panis_na.jpg"); - ResourceStub[] resources = new ResourceStub[] {new ResourceStub()}; - - createFile(sampleResource); - - // configure mojo - resources[0].setDirectory(webAppResource.getAbsolutePath()); + ResourceStub[] resources = createWebResources(sampleResource, webAppResource); resources[0].setTargetPath("targetPath"); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "webResources", resources); + + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); + mojo.setWebResources(resources); mojo.execute(); // validate operation @@ -146,11 +137,11 @@ public void testSimpleExplodedWarWTargetPath() throws Exception { File expectedWEBINFDir = new File(webAppDirectory, "WEB-INF"); File expectedMETAINFDir = new File(webAppDirectory, "META-INF"); - assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); - assertTrue("resources doesn't exist: " + expectedWebResourceFile, expectedWebResourceFile.exists()); - assertTrue("WEB-INF not found", expectedWEBINFDir.exists()); - assertTrue("META-INF not found", expectedMETAINFDir.exists()); + assertTrue(expectedWebSourceFile.exists(), "source files not found: " + expectedWebSourceFile); + assertTrue(expectedWebSource2File.exists(), "source files not found: " + expectedWebSource2File); + assertTrue(expectedWebResourceFile.exists(), "resources doesn't exist: " + expectedWebResourceFile); + assertTrue(expectedWEBINFDir.exists(), "WEB-INF not found"); + assertTrue(expectedMETAINFDir.exists(), "META-INF not found"); // housekeeping expectedWebSourceFile.delete(); @@ -158,10 +149,9 @@ public void testSimpleExplodedWarWTargetPath() throws Exception { expectedWebResourceFile.delete(); } - /** - * @throws Exception in case of an error. - */ - public void testExplodedWarWithCustomWebXML() throws Exception { + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @Test + public void testExplodedWarWithCustomWebXML(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "ExplodedWarWithCustomWebXML"; MavenProjectBasicStub project = new MavenProjectBasicStub(); @@ -171,7 +161,10 @@ public void testExplodedWarWithCustomWebXML() throws Exception { File webAppDirectory = new File(getTestDirectory(), testId); // configure mojo - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); mojo.setWebXml(new File(xmlSource, "web.xml")); mojo.execute(); @@ -181,11 +174,11 @@ public void testExplodedWarWithCustomWebXML() throws Exception { File expectedWEBXMLFile = new File(webAppDirectory, "WEB-INF/web.xml"); File expectedMETAINFDir = new File(webAppDirectory, "META-INF"); - assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); - assertTrue("WEB XML not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists()); - assertTrue("META-INF not found", expectedMETAINFDir.exists()); - assertEquals("WEB XML not correct", mojo.getWebXml().toString(), FileUtils.fileRead(expectedWEBXMLFile)); + assertTrue(expectedWebSourceFile.exists(), "source files not found: " + expectedWebSourceFile); + assertTrue(expectedWebSource2File.exists(), "source files not found: " + expectedWebSource2File); + assertTrue(expectedWEBXMLFile.exists(), "WEB XML not found: " + expectedWEBXMLFile); + assertTrue(expectedMETAINFDir.exists(), "META-INF not found"); + assertEquals(mojo.getWebXml().toString(), FileUtils.fileRead(expectedWEBXMLFile), "WEB XML not correct"); // housekeeping expectedWebSourceFile.delete(); @@ -194,10 +187,9 @@ public void testExplodedWarWithCustomWebXML() throws Exception { expectedMETAINFDir.delete(); } - /** - * @throws Exception in case of an error. - */ - public void testExplodedWarWithContainerConfigXML() throws Exception { + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @Test + public void testExplodedWarWithContainerConfigXML(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "ExplodedWarWithContainerConfigXML"; MavenProjectBasicStub project = new MavenProjectBasicStub(); @@ -207,7 +199,10 @@ public void testExplodedWarWithContainerConfigXML() throws Exception { File webAppDirectory = new File(getTestDirectory(), testId); // configure mojo - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); mojo.setContainerConfigXML(new File(xmlSource, "config.xml")); mojo.execute(); @@ -217,12 +212,12 @@ public void testExplodedWarWithContainerConfigXML() throws Exception { File expectedContainerConfigXMLFile = new File(webAppDirectory, "META-INF/config.xml"); File expectedWEBINFDir = new File(webAppDirectory, "WEB-INF"); - assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); - assertTrue("WEB-INF not found", expectedWEBINFDir.exists()); + assertTrue(expectedWebSourceFile.exists(), "source files not found: " + expectedWebSourceFile); + assertTrue(expectedWebSource2File.exists(), "source files not found: " + expectedWebSource2File); + assertTrue(expectedWEBINFDir.exists(), "WEB-INF not found"); assertTrue( - "Container Config XML not found:" + expectedContainerConfigXMLFile.toString(), - expectedContainerConfigXMLFile.exists()); + expectedContainerConfigXMLFile.exists(), + "Container Config XML not found:" + expectedContainerConfigXMLFile); // housekeeping expectedWebSourceFile.delete(); @@ -234,26 +229,26 @@ public void testExplodedWarWithContainerConfigXML() throws Exception { /** * @throws Exception in case of an error. */ - public void testExplodedWarWithSimpleExternalWARFile() throws Exception { + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @MojoParameter( + name = "workDirectory", + value = "target/test-classes/unit/warexplodedmojo/test-dir/war/work-ExplodedWarWithSimpleExternalWARFile") + @Test + public void testExplodedWarWithSimpleExternalWARFile(WarExplodedMojo mojo) throws Exception { // setup test data - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - WarArtifactStub warArtifact = new WarArtifactStub(getBasedir()); - String testId = "ExplodedWarWithSimpleExternalWARFile"; File webAppDirectory = new File(getTestDirectory(), testId); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); - File workDirectory = new File(getTestDirectory(), "/war/work-" + testId); - File simpleWarFile = warArtifact.getFile(); - - assertTrue("simple war not found: " + simpleWarFile.toString(), simpleWarFile.exists()); - - createDir(workDirectory); // configure mojo + WarArtifactStub warArtifact = new WarArtifactStub(getBasedir()); + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); project.addArtifact(warArtifact); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "workDirectory", workDirectory); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); mojo.execute(); // validate operation - META-INF is automatically excluded so remove the file from the list @@ -262,11 +257,11 @@ public void testExplodedWarWithSimpleExternalWARFile() throws Exception { File expectedWEBXMLFile = new File(webAppDirectory, "WEB-INF/web.xml"); File expectedWARFile = new File(webAppDirectory, "/org/sample/company/test.jsp"); - assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); + assertTrue(expectedWebSourceFile.exists(), "source files not found: " + expectedWebSourceFile); + assertTrue(expectedWebSource2File.exists(), "source files not found: " + expectedWebSource2File); // check simple.war in the unit test dir under resources to verify the list of files - assertTrue("web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists()); - assertTrue("war file not found: " + expectedWARFile.toString(), expectedWARFile.exists()); + assertTrue(expectedWEBXMLFile.exists(), "web xml not found: " + expectedWEBXMLFile); + assertTrue(expectedWARFile.exists(), "war file not found: " + expectedWARFile); // housekeeping expectedWebSourceFile.delete(); @@ -279,33 +274,36 @@ public void testExplodedWarWithSimpleExternalWARFile() throws Exception { * Merge a dependent WAR when a file in the war source directory overrides one found in the WAR. * @throws Exception in case of an error. */ - public void testExplodedWarMergeWarLocalFileOverride() throws Exception { + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @MojoParameter( + name = "workDirectory", + value = + "target/test-classes/unit/warexplodedmojo/test-dir/war/work-testExplodedWarMergeWarLocalFileOverride") + @Test + public void testExplodedWarMergeWarLocalFileOverride(WarExplodedMojo mojo) throws Exception { // setup test data - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - WarArtifactStub warArtifact = new WarArtifactStub(getBasedir()); - String testId = "testExplodedWarMergeWarLocalFileOverride"; File webAppDirectory = new File(getTestDirectory(), testId); File webAppSource = getWebAppSource(testId); File simpleJSP = new File(webAppSource, "org/sample/company/test.jsp"); createFile(simpleJSP); - - File workDirectory = new File(getTestDirectory(), "/war/work-" + testId); - createDir(workDirectory); - File classesDir = createClassesDir(testId, true); // configure mojo + WarArtifactStub warArtifact = new WarArtifactStub(getBasedir()); + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); project.addArtifact(warArtifact); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "workDirectory", workDirectory); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); mojo.execute(); // validate operation File expectedFile = new File(webAppDirectory, "/org/sample/company/test.jsp"); - assertTrue("file not found: " + expectedFile.toString(), expectedFile.exists()); - assertEquals("file incorrect", simpleJSP.toString(), FileUtils.fileRead(expectedFile)); + assertTrue(expectedFile.exists(), "file not found: " + expectedFile); + assertEquals(simpleJSP.toString(), FileUtils.fileRead(expectedFile), "file incorrect"); // check when the merged war file is newer - so set an old time on the local file long time = @@ -314,35 +312,36 @@ public void testExplodedWarMergeWarLocalFileOverride() throws Exception { expectedFile.setLastModified(time); project.addArtifact(warArtifact); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "workDirectory", workDirectory); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); mojo.execute(); - assertTrue("file not found: " + expectedFile.toString(), expectedFile.exists()); - assertEquals("file incorrect", simpleJSP.toString(), FileUtils.fileRead(expectedFile)); + assertTrue(expectedFile.exists(), "file not found: " + expectedFile); + assertEquals(simpleJSP.toString(), FileUtils.fileRead(expectedFile), "file incorrect"); // housekeeping expectedFile.delete(); } - /** - * @throws Exception in case of an error. - */ - public void testExplodedWarWithEJB() throws Exception { + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @Test + public void testExplodedWarWithEJB(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "ExplodedWarWithEJB"; - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); File webAppDirectory = new File(getTestDirectory(), testId); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); EJBArtifactStub ejbArtifact = new EJBArtifactStub(getBasedir()); - File ejbFile = ejbArtifact.getFile(); - - assertTrue("ejb jar not found: " + ejbFile.toString(), ejbFile.exists()); // configure mojo + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); project.addArtifact(ejbArtifact); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); mojo.execute(); // validate operation @@ -351,9 +350,9 @@ public void testExplodedWarWithEJB() throws Exception { // final name form is -. File expectedEJBArtifact = new File(webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test.jar"); - assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); - assertTrue("ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists()); + assertTrue(expectedWebSourceFile.exists(), "source files not found: " + expectedWebSourceFile); + assertTrue(expectedWebSource2File.exists(), "source files not found: " + expectedWebSource2File); + assertTrue(expectedEJBArtifact.exists(), "ejb artifact not found: " + expectedEJBArtifact); // housekeeping expectedWebSourceFile.delete(); @@ -361,22 +360,24 @@ public void testExplodedWarWithEJB() throws Exception { expectedEJBArtifact.delete(); } - public void testExplodedWarWithJar() throws Exception { + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @Test + @Disabled // TODO interpolation of extension does not work + public void testExplodedWarWithJar(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "ExplodedWarWithJar"; - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); File webAppDirectory = new File(getTestDirectory(), testId); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); - ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar"); ArtifactStub jarArtifact = new JarArtifactStub(getBasedir(), artifactHandler); - File jarFile = jarArtifact.getFile(); - - assertTrue("jar not found: " + jarFile.toString(), jarFile.exists()); // configure mojo + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); project.addArtifact(jarArtifact); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); mojo.execute(); // validate operation @@ -385,9 +386,9 @@ public void testExplodedWarWithJar() throws Exception { // final name form is -. File expectedJarArtifact = new File(webAppDirectory, "WEB-INF/lib/jarartifact-0.0-Test.jar"); - assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); - assertTrue("jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists()); + assertTrue(expectedWebSourceFile.exists(), "source files not found: " + expectedWebSourceFile); + assertTrue(expectedWebSource2File.exists(), "source files not found: " + expectedWebSource2File); + assertTrue(expectedJarArtifact.exists(), "jar artifact not found: " + expectedJarArtifact); // housekeeping expectedWebSourceFile.delete(); @@ -398,21 +399,23 @@ public void testExplodedWarWithJar() throws Exception { /** * @throws Exception in case of an error. */ - public void testExplodedWarWithEJBClient() throws Exception { + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @Test + public void testExplodedWarWithEJBClient(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "ExplodedWarWithEJB"; - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); File webAppDirectory = new File(getTestDirectory(), testId); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); EJBClientArtifactStub ejbArtifact = new EJBClientArtifactStub(getBasedir()); - File ejbFile = ejbArtifact.getFile(); - - assertTrue("ejb jar not found: " + ejbFile.toString(), ejbFile.exists()); // configure mojo + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); project.addArtifact(ejbArtifact); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); mojo.execute(); // validate operation @@ -421,9 +424,9 @@ public void testExplodedWarWithEJBClient() throws Exception { // final name form is -. File expectedEJBArtifact = new File(webAppDirectory, "WEB-INF/lib/ejbclientartifact-0.0-Test-client.jar"); - assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); - assertTrue("ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists()); + assertTrue(expectedWebSourceFile.exists(), "source files not found: " + expectedWebSourceFile); + assertTrue(expectedWebSource2File.exists(), "source files not found: " + expectedWebSource2File); + assertTrue(expectedEJBArtifact.exists(), "ejb artifact not found: " + expectedEJBArtifact); // housekeeping expectedWebSourceFile.delete(); @@ -434,21 +437,23 @@ public void testExplodedWarWithEJBClient() throws Exception { /** * @throws Exception in case of an error. */ - public void testExplodedWarWithTLD() throws Exception { + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @Test + public void testExplodedWarWithTLD(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "ExplodedWarWithTLD"; - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); File webAppDirectory = new File(getTestDirectory(), testId); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); TLDArtifactStub tldArtifact = new TLDArtifactStub(getBasedir()); - File tldFile = tldArtifact.getFile(); - - assertTrue("tld jar not found: " + tldFile.getAbsolutePath(), tldFile.exists()); // configure mojo + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); project.addArtifact(tldArtifact); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); mojo.execute(); // validate operation @@ -457,9 +462,9 @@ public void testExplodedWarWithTLD() throws Exception { // final name form is -. File expectedTLDArtifact = new File(webAppDirectory, "WEB-INF/tld/tldartifact-0.0-Test.tld"); - assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); - assertTrue("tld artifact not found: " + expectedTLDArtifact.toString(), expectedTLDArtifact.exists()); + assertTrue(expectedWebSourceFile.exists(), "source files not found: " + expectedWebSourceFile); + assertTrue(expectedWebSource2File.exists(), "source files not found: " + expectedWebSource2File); + assertTrue(expectedTLDArtifact.exists(), "tld artifact not found: " + expectedTLDArtifact); // housekeeping expectedWebSourceFile.delete(); @@ -467,24 +472,23 @@ public void testExplodedWarWithTLD() throws Exception { expectedTLDArtifact.delete(); } - /** - * @throws Exception in case of an error. - */ - public void testExplodedWarWithPAR() throws Exception { + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @Test + public void testExplodedWarWithPAR(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "ExplodedWarWithPAR"; - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); File webAppDirectory = new File(getTestDirectory(), testId); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); PARArtifactStub parartifact = new PARArtifactStub(getBasedir()); - File parFile = parartifact.getFile(); - - assertTrue("par not found: " + parFile.getAbsolutePath(), parFile.exists()); // configure mojo + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); project.addArtifact(parartifact); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); mojo.execute(); // validate operation @@ -493,9 +497,9 @@ public void testExplodedWarWithPAR() throws Exception { // final name form is -. File expectedPARArtifact = new File(webAppDirectory, "WEB-INF/lib/parartifact-0.0-Test.jar"); - assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); - assertTrue("par artifact not found: " + expectedPARArtifact.toString(), expectedPARArtifact.exists()); + assertTrue(expectedWebSourceFile.exists(), "source files not found: " + expectedWebSourceFile); + assertTrue(expectedWebSource2File.exists(), "source files not found: " + expectedWebSource2File); + assertTrue(expectedPARArtifact.exists(), "par artifact not found: " + expectedPARArtifact); // housekeeping expectedWebSourceFile.delete(); @@ -503,26 +507,24 @@ public void testExplodedWarWithPAR() throws Exception { expectedPARArtifact.delete(); } - /** - * @throws Exception in case of an error. - */ - public void testExplodedWarWithAar() throws Exception { + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @Test + @Disabled // TODO interpolation of extension does not work + public void testExplodedWarWithAar(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "ExplodedWarWithAar"; MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); File webAppDirectory = new File(getTestDirectory(), testId); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); - // Fake here since the aar artifact handler does not exist: no biggie - ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar"); ArtifactStub aarArtifact = new AarArtifactStub(getBasedir(), artifactHandler); - File aarFile = aarArtifact.getFile(); - - assertTrue("jar not found: " + aarFile.toString(), aarFile.exists()); // configure mojo project.addArtifact(aarArtifact); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); mojo.execute(); // validate operation @@ -531,9 +533,9 @@ public void testExplodedWarWithAar() throws Exception { // final name form is -. File expectedJarArtifact = new File(webAppDirectory, "WEB-INF/services/aarartifact-0.0-Test.jar"); - assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); - assertTrue("jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists()); + assertTrue(expectedWebSourceFile.exists(), "source files not found: " + expectedWebSourceFile); + assertTrue(expectedWebSource2File.exists(), "source files not found: " + expectedWebSource2File); + assertTrue(expectedJarArtifact.exists(), "jar artifact not found: " + expectedJarArtifact); // housekeeping expectedWebSourceFile.delete(); @@ -541,26 +543,24 @@ public void testExplodedWarWithAar() throws Exception { expectedJarArtifact.delete(); } - /** - * @throws Exception in case of an error. - */ - public void testExplodedWarWithMar() throws Exception { + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @Test + @Disabled // TODO interpolation of extension does not work + public void testExplodedWarWithMar(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "ExplodedWarWithMar"; MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); File webAppDirectory = new File(getTestDirectory(), testId); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); - // Fake here since the mar artifact handler does not exist: no biggie - ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar"); ArtifactStub marArtifact = new MarArtifactStub(getBasedir(), artifactHandler); - File marFile = marArtifact.getFile(); - - assertTrue("jar not found: " + marFile.toString(), marFile.exists()); // configure mojo project.addArtifact(marArtifact); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); mojo.execute(); // validate operation @@ -569,9 +569,9 @@ public void testExplodedWarWithMar() throws Exception { // final name form is -. File expectedJarArtifact = new File(webAppDirectory, "WEB-INF/modules/marartifact-0.0-Test.jar"); - assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); - assertTrue("jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists()); + assertTrue(expectedWebSourceFile.exists(), "source files not found: " + expectedWebSourceFile); + assertTrue(expectedWebSource2File.exists(), "source files not found: " + expectedWebSource2File); + assertTrue(expectedJarArtifact.exists(), "jar artifact not found: " + expectedJarArtifact); // housekeeping expectedWebSourceFile.delete(); @@ -579,26 +579,24 @@ public void testExplodedWarWithMar() throws Exception { expectedJarArtifact.delete(); } - /** - * @throws Exception in case of an error. - */ - public void testExplodedWarWithXar() throws Exception { + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @Test + @Disabled // TODO interpolation of extension does not work + public void testExplodedWarWithXar(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "ExplodedWarWithXar"; MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); File webAppDirectory = new File(getTestDirectory(), testId); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); - // Fake here since the xar artifact handler does not exist: no biggie - ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar"); ArtifactStub xarArtifact = new XarArtifactStub(getBasedir(), artifactHandler); - File xarFile = xarArtifact.getFile(); - - assertTrue("jar not found: " + xarFile.toString(), xarFile.exists()); // configure mojo project.addArtifact(xarArtifact); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); mojo.execute(); // validate operation @@ -607,9 +605,9 @@ public void testExplodedWarWithXar() throws Exception { // final name form is -. File expectedJarArtifact = new File(webAppDirectory, "WEB-INF/extensions/xarartifact-0.0-Test.jar"); - assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); - assertTrue("jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists()); + assertTrue(expectedWebSourceFile.exists(), "source files not found: " + expectedWebSourceFile); + assertTrue(expectedWebSource2File.exists(), "source files not found: " + expectedWebSource2File); + assertTrue(expectedJarArtifact.exists(), "jar artifact not found: " + expectedJarArtifact); // housekeeping expectedWebSourceFile.delete(); @@ -617,29 +615,28 @@ public void testExplodedWarWithXar() throws Exception { expectedJarArtifact.delete(); } - /** - * @throws Exception in case of an error. - */ - public void testExplodedWarWithDuplicateDependencies() throws Exception { + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @Test + public void testExplodedWarWithDuplicateDependencies(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "ExplodedWarWithDuplicateDependencies"; - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); File webAppDirectory = new File(getTestDirectory(), testId); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); EJBArtifactStub ejbArtifact = new EJBArtifactStub(getBasedir()); + ejbArtifact.setGroupId("org.sample.ejb"); EJBArtifactStub ejbArtifactDup = new EJBArtifactStub(getBasedir()); - File ejbFile = ejbArtifact.getFile(); - - // ejbArtifact has a hard coded file, only one assert is needed - assertTrue("ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists()); + ejbArtifactDup.setGroupId("org.dup.ejb"); // configure mojo - ejbArtifact.setGroupId("org.sample.ejb"); - ejbArtifactDup.setGroupId("org.dup.ejb"); + + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); project.addArtifact(ejbArtifact); project.addArtifact(ejbArtifactDup); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); mojo.execute(); // validate operation @@ -649,10 +646,10 @@ public void testExplodedWarWithDuplicateDependencies() throws Exception { File expectedEJBArtifact = new File(webAppDirectory, "WEB-INF/lib/org.sample.ejb-ejbartifact-0.0-Test.jar"); File expectedEJBDupArtifact = new File(webAppDirectory, "WEB-INF/lib/org.dup.ejb-ejbartifact-0.0-Test.jar"); - assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); - assertTrue("ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists()); - assertTrue("ejb dup artifact not found: " + expectedEJBDupArtifact.toString(), expectedEJBDupArtifact.exists()); + assertTrue(expectedWebSourceFile.exists(), "source files not found: " + expectedWebSourceFile); + assertTrue(expectedWebSource2File.exists(), "source files not found: " + expectedWebSource2File); + assertTrue(expectedEJBArtifact.exists(), "ejb artifact not found: " + expectedEJBArtifact); + assertTrue(expectedEJBDupArtifact.exists(), "ejb dup artifact not found: " + expectedEJBDupArtifact); // housekeeping expectedWebSourceFile.delete(); @@ -664,32 +661,29 @@ public void testExplodedWarWithDuplicateDependencies() throws Exception { /** * @throws Exception in case of an error. */ - public void testExplodedWarDuplicateWithClassifier() throws Exception { + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @Test + public void testExplodedWarDuplicateWithClassifier(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "ExplodedWarDuplicateWithClassifier"; - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); File webAppDirectory = new File(getTestDirectory(), testId); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); EJBArtifactStub ejbArtifact = new EJBArtifactStub(getBasedir()); - EJBArtifactStubWithClassifier ejbArtifactDup = new EJBArtifactStubWithClassifier(getBasedir()); - - File ejbFile = ejbArtifact.getFile(); - - // ejbArtifact has a hard coded file, only one assert is needed - assertTrue("ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists()); - - // configure mojo - ejbArtifact.setGroupId("org.sample.ejb"); + EJBArtifactStubWithClassifier ejbArtifactDup = new EJBArtifactStubWithClassifier(getBasedir()); ejbArtifactDup.setGroupId("org.sample.ejb"); - ejbArtifactDup.setClassifier("classifier"); + // configure mojo + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); project.addArtifact(ejbArtifact); project.addArtifact(ejbArtifactDup); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); mojo.execute(); // validate operation @@ -699,10 +693,10 @@ public void testExplodedWarDuplicateWithClassifier() throws Exception { File expectedEJBArtifact = new File(webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test.jar"); File expectedEJBDupArtifact = new File(webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test-classifier.jar"); - assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); - assertTrue("ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists()); - assertTrue("ejb dup artifact not found: " + expectedEJBDupArtifact.toString(), expectedEJBDupArtifact.exists()); + assertTrue(expectedWebSourceFile.exists(), "source files not found: " + expectedWebSourceFile); + assertTrue(expectedWebSource2File.exists(), "source files not found: " + expectedWebSource2File); + assertTrue(expectedEJBArtifact.exists(), "ejb artifact not found: " + expectedEJBArtifact); + assertTrue(expectedEJBDupArtifact.exists(), "ejb dup artifact not found: " + expectedEJBDupArtifact); // housekeeping expectedWebSourceFile.delete(); @@ -714,16 +708,21 @@ public void testExplodedWarDuplicateWithClassifier() throws Exception { /** * @throws Exception in case of an error. */ - public void testExplodedWarWithClasses() throws Exception { + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @Test + public void testExplodedWarWithClasses(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "ExplodedWarWithClasses"; - MavenProjectBasicStub project = new MavenProjectBasicStub(); File webAppDirectory = new File(getTestDirectory(), testId); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, false); // configure mojo - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + MavenProjectBasicStub project = new MavenProjectBasicStub(); + mojo.setProject(project); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); mojo.execute(); // validate operation @@ -732,9 +731,9 @@ public void testExplodedWarWithClasses() throws Exception { // final name form is -. File expectedClass = new File(webAppDirectory, "WEB-INF/classes/sample-servlet.clazz"); - assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); - assertTrue("classes not found: " + expectedClass.toString(), expectedClass.exists()); + assertTrue(expectedWebSourceFile.exists(), "source files not found: " + expectedWebSourceFile); + assertTrue(expectedWebSource2File.exists(), "source files not found: " + expectedWebSource2File); + assertTrue(expectedClass.exists(), "classes not found: " + expectedClass); // housekeeping expectedWebSourceFile.delete(); @@ -742,21 +741,23 @@ public void testExplodedWarWithClasses() throws Exception { expectedClass.delete(); } - /** - * @throws Exception in case of an error. - */ - public void testExplodedWarWithSourceIncludeExclude() throws Exception { + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @MojoParameter(name = "warSourceIncludes", value = "**/*sit.jsp") + @MojoParameter(name = "warSourceExcludes", value = "**/last*.*") + @Test + public void testExplodedWarWithSourceIncludeExclude(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "ExplodedWarWithSourceIncludeExclude"; - MavenProjectBasicStub project = new MavenProjectBasicStub(); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); File webAppDirectory = new File(getTestDirectory(), testId); // configure mojo - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "warSourceIncludes", "**/*sit.jsp"); - setVariableValueToObject(mojo, "warSourceExcludes", "**/last*.*"); + MavenProjectBasicStub project = new MavenProjectBasicStub(); + mojo.setProject(project); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); mojo.execute(); // validate operation @@ -765,10 +766,10 @@ public void testExplodedWarWithSourceIncludeExclude() throws Exception { File expectedWEBXMLDir = new File(webAppDirectory, "WEB-INF"); File expectedMETAINFDir = new File(webAppDirectory, "META-INF"); - assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertFalse("source files found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); - assertTrue("WEB XML not found: " + expectedWEBXMLDir.toString(), expectedWEBXMLDir.exists()); - assertTrue("META-INF not found", expectedMETAINFDir.exists()); + assertTrue(expectedWebSourceFile.exists(), "source files not found: " + expectedWebSourceFile); + assertFalse(expectedWebSource2File.exists(), "source files found: " + expectedWebSource2File); + assertTrue(expectedWEBXMLDir.exists(), "WEB XML not found: " + expectedWEBXMLDir); + assertTrue(expectedMETAINFDir.exists(), "META-INF not found"); // housekeeping expectedWebSourceFile.delete(); @@ -777,30 +778,29 @@ public void testExplodedWarWithSourceIncludeExclude() throws Exception { expectedMETAINFDir.delete(); } - /** - * @throws Exception in case of an error. - */ - public void testExplodedWarWithWarDependencyIncludeExclude() throws Exception { + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @MojoParameter(name = "dependentWarIncludes", value = "**/*Include.jsp,**/*.xml") + @MojoParameter(name = "dependentWarExcludes", value = "**/*Exclude*,**/MANIFEST.MF") + @MojoParameter( + name = "workDirectory", + value = + "target/test-classes/unit/warexplodedmojo/test-dir/war/work-ExplodedWarWithWarDependencyIncludeExclude") + @Test + public void testExplodedWarWithWarDependencyIncludeExclude(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "ExplodedWarWithWarDependencyIncludeExclude"; - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - IncludeExcludeWarArtifactStub includeexcludeWarArtifact = new IncludeExcludeWarArtifactStub(getBasedir()); File webAppDirectory = new File(getTestDirectory(), testId); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); - File workDirectory = new File(getTestDirectory(), "/war/work-" + testId); - File includeExcludeWarFile = includeexcludeWarArtifact.getFile(); - - assertTrue("war not found: " + includeExcludeWarFile.toString(), includeExcludeWarFile.exists()); - - createDir(workDirectory); + IncludeExcludeWarArtifactStub includeexcludeWarArtifact = new IncludeExcludeWarArtifactStub(getBasedir()); // configure mojo + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + mojo.setProject(project); project.addArtifact(includeexcludeWarArtifact); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "dependentWarIncludes", "**/*Include.jsp,**/*.xml"); - setVariableValueToObject(mojo, "dependentWarExcludes", "**/*Exclude*,**/MANIFEST.MF"); - setVariableValueToObject(mojo, "workDirectory", workDirectory); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); mojo.execute(); // validate operation @@ -811,13 +811,13 @@ public void testExplodedWarWithWarDependencyIncludeExclude() throws Exception { File expectedIncludedWARFile = new File(webAppDirectory, "/org/sample/company/testInclude.jsp"); File expectedExcludedWarfile = new File(webAppDirectory, "/org/sample/companyExclude/test.jsp"); - assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); + assertTrue(expectedWebSourceFile.exists(), "source files not found: " + expectedWebSourceFile); + assertTrue(expectedWebSource2File.exists(), "source files not found: " + expectedWebSource2File); // check include-exclude.war in the unit test dir under resources to verify the list of files - assertTrue("web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists()); - assertFalse("manifest file found: " + expectedManifestFile.toString(), expectedManifestFile.exists()); - assertTrue("war file not found: " + expectedIncludedWARFile.toString(), expectedIncludedWARFile.exists()); - assertFalse("war file not found: " + expectedExcludedWarfile.toString(), expectedExcludedWarfile.exists()); + assertTrue(expectedWEBXMLFile.exists(), "web xml not found: " + expectedWEBXMLFile); + assertFalse(expectedManifestFile.exists(), "manifest file found: " + expectedManifestFile); + assertTrue(expectedIncludedWARFile.exists(), "war file not found: " + expectedIncludedWARFile); + assertFalse(expectedExcludedWarfile.exists(), "war file not found: " + expectedExcludedWarfile); // housekeeping expectedWebSourceFile.delete(); @@ -828,19 +828,21 @@ public void testExplodedWarWithWarDependencyIncludeExclude() throws Exception { expectedExcludedWarfile.delete(); } - /** - * @throws Exception in case of an error. - */ - public void testExplodedWarWithSourceModificationCheck() throws Exception { + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @Test + public void testExplodedWarWithSourceModificationCheck(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "ExplodedWarWithSourceModificationCheck"; - MavenProjectBasicStub project = new MavenProjectBasicStub(); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, false); File webAppDirectory = new File(getTestDirectory(), testId); // configure mojo - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + MavenProjectBasicStub project = new MavenProjectBasicStub(); + mojo.setProject(project); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); // destination file is already created manually containing an "error" string // source is newer than the destination file @@ -853,17 +855,17 @@ public void testExplodedWarWithSourceModificationCheck() throws Exception { File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); - assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); - assertTrue("WEB-INF not found", expectedWEBINFDir.exists()); - assertTrue("META-INF not found", expectedMETAINFDir.exists()); + assertTrue(expectedWebSourceFile.exists(), "source files not found: " + expectedWebSourceFile); + assertTrue(expectedWebSource2File.exists(), "source files not found: " + expectedWebSource2File); + assertTrue(expectedWEBINFDir.exists(), "WEB-INF not found"); + assertTrue(expectedMETAINFDir.exists(), "META-INF not found"); // 1st phase destination is older than source // destination starts with a value of error replaced with a blank source assertNotEquals( - "source files not updated with new copy: " + expectedWebSourceFile.toString(), "error", - FileUtils.fileRead(expectedWebSourceFile)); + FileUtils.fileRead(expectedWebSourceFile), + "source files not updated with new copy: " + expectedWebSourceFile); // housekeeping expectedWEBINFDir.delete(); @@ -872,26 +874,25 @@ public void testExplodedWarWithSourceModificationCheck() throws Exception { expectedWebSource2File.delete(); } - /** - * @throws Exception in case of an error. - */ - public void testExplodedWarWithOutputFileNameMapping() throws Exception { + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @Test + @Disabled // TODO interpolation of extension does not work + public void testExplodedWarWithOutputFileNameMapping(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "ExplodedWarWithFileNameMapping"; MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); File webAppDirectory = new File(getTestDirectory(), testId); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); - ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar"); ArtifactStub jarArtifact = new JarArtifactStub(getBasedir(), artifactHandler); - File jarFile = jarArtifact.getFile(); - - assertTrue("jar not found: " + jarFile.toString(), jarFile.exists()); // configure mojo project.addArtifact(jarArtifact); mojo.setOutputFileNameMapping("@{artifactId}@.@{extension}@"); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); mojo.execute(); // validate operation @@ -900,9 +901,9 @@ public void testExplodedWarWithOutputFileNameMapping() throws Exception { // final name form is -. File expectedJarArtifact = new File(webAppDirectory, "WEB-INF/lib/jarartifact.jar"); - assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); - assertTrue("jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists()); + assertTrue(expectedWebSourceFile.exists(), "source files not found: " + expectedWebSourceFile); + assertTrue(expectedWebSource2File.exists(), "source files not found: " + expectedWebSource2File); + assertTrue(expectedJarArtifact.exists(), "jar artifact not found: " + expectedJarArtifact); // housekeeping expectedWebSourceFile.delete(); @@ -910,30 +911,29 @@ public void testExplodedWarWithOutputFileNameMapping() throws Exception { expectedJarArtifact.delete(); } - /** - * @throws Exception in case of an error. - */ - public void testExplodedWarWithOutputFileNameMappingAndDuplicateDependencies() throws Exception { + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @Test + public void testExplodedWarWithOutputFileNameMappingAndDuplicateDependencies(WarExplodedMojo mojo) + throws Exception { // setup test data String testId = "ExplodedWarWithFileNameMappingAndDuplicateDependencies"; - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); File webAppDirectory = new File(getTestDirectory(), testId); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); EJBArtifactStub ejbArtifact = new EJBArtifactStub(getBasedir()); + ejbArtifact.setGroupId("org.sample.ejb"); EJBArtifactStub ejbArtifactDup = new EJBArtifactStub(getBasedir()); - File ejbFile = ejbArtifact.getFile(); - - // ejbArtifact has a hard coded file, only one assert is needed - assertTrue("ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists()); + ejbArtifactDup.setGroupId("org.dup.ejb"); // configure mojo - ejbArtifact.setGroupId("org.sample.ejb"); - ejbArtifactDup.setGroupId("org.dup.ejb"); + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); project.addArtifact(ejbArtifact); project.addArtifact(ejbArtifactDup); mojo.setOutputFileNameMapping("@{artifactId}@.@{extension}@"); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); mojo.execute(); // validate operation @@ -943,10 +943,10 @@ public void testExplodedWarWithOutputFileNameMappingAndDuplicateDependencies() t File expectedEJBArtifact = new File(webAppDirectory, "WEB-INF/lib/org.sample.ejb-ejbartifact.jar"); File expectedEJBDupArtifact = new File(webAppDirectory, "WEB-INF/lib/org.dup.ejb-ejbartifact.jar"); - assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); - assertTrue("ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists()); - assertTrue("ejb dup artifact not found: " + expectedEJBDupArtifact.toString(), expectedEJBDupArtifact.exists()); + assertTrue(expectedWebSourceFile.exists(), "source files not found: " + expectedWebSourceFile); + assertTrue(expectedWebSource2File.exists(), "source files not found: " + expectedWebSource2File); + assertTrue(expectedEJBArtifact.exists(), "ejb artifact not found: " + expectedEJBArtifact); + assertTrue(expectedEJBDupArtifact.exists(), "ejb dup artifact not found: " + expectedEJBDupArtifact); // housekeeping expectedWebSourceFile.delete(); @@ -955,216 +955,6 @@ public void testExplodedWarWithOutputFileNameMappingAndDuplicateDependencies() t expectedEJBDupArtifact.delete(); } - public void setUp() throws Exception { - super.setUp(); - - MavenExecutionRequest request = new DefaultMavenExecutionRequest() - .setSystemProperties(System.getProperties()) - .setStartTime(new Date()); - - MavenSession mavenSession = - new MavenSession((PlexusContainer) null, (RepositorySystemSession) null, request, null); - getContainer().addComponent(mavenSession, MavenSession.class.getName()); - mojo = (WarExplodedMojo) lookupMojo("exploded", getPomFile()); - } - - /** - * Configures the exploded mojo for the specified test. - * - * If the {@code sourceFiles} parameter is {@code null}, sample JSPs are created by default. - * - * @param testId the id of the test - * @param artifactStubs the dependencies (may be null) - * @param sourceFiles the source files to create (may be null) - * @return the webapp directory - * @throws Exception if an error occurs while configuring the mojo - */ - protected File setUpMojo(final String testId, ArtifactStub[] artifactStubs, String[] sourceFiles) throws Exception { - final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - final File webAppDirectory = new File(getTestDirectory(), testId); - - // Create the webapp sources - File webAppSource; - if (sourceFiles == null) { - webAppSource = createWebAppSource(testId); - } else { - webAppSource = createWebAppSource(testId, false); - for (String sourceFile : sourceFiles) { - File sample = new File(webAppSource, sourceFile); - createFile(sample); - } - } - - final File classesDir = createClassesDir(testId, true); - final File workDirectory = new File(getTestDirectory(), "/war/work-" + testId); - createDir(workDirectory); - - if (artifactStubs != null) { - for (ArtifactStub artifactStub : artifactStubs) { - project.addArtifact(artifactStub); - } - } - - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "workDirectory", workDirectory); - - return webAppDirectory; - } - - /** - * Configures the exploded mojo for the specified test. - * - * @param testId the id of the test - * @param artifactStubs the dependencies (may be null) - * @return the webapp directory - * @throws Exception if an error occurs while configuring the mojo - */ - protected File setUpMojo(final String testId, ArtifactStub[] artifactStubs) throws Exception { - return setUpMojo(testId, artifactStubs, null); - } - - /** - * Cleans up a directory. - * - * @param directory the directory to remove - * @throws IOException if an error occurred while removing the directory - */ - protected void cleanDirectory(File directory) throws IOException { - if (directory != null && directory.isDirectory() && directory.exists()) { - FileUtils.deleteDirectory(directory); - } - } - - /** - * Asserts the default content of the war based on the specified webapp directory. - * - * @param webAppDirectory the webapp directory - * @return a list of File objects that have been asserted - */ - protected List assertDefaultContent(File webAppDirectory) { - // Validate content of the webapp - File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); - File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); - - assertTrue("source file not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertTrue("source file not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); - - final List content = new ArrayList<>(); - content.add(expectedWebSourceFile); - content.add(expectedWebSource2File); - - return content; - } - - /** - * Asserts the web.xml file of the war based on the specified webapp directory. - * - * @param webAppDirectory the webapp directory - * @return a list with the web.xml File object - */ - protected List assertWebXml(File webAppDirectory) { - File expectedWEBXMLFile = new File(webAppDirectory, "WEB-INF/web.xml"); - assertTrue("web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists()); - - final List content = new ArrayList<>(); - content.add(expectedWEBXMLFile); - - return content; - } - - /** - * Asserts custom content of the war based on the specified webapp directory. - * - * @param webAppDirectory the webapp directory - * @param filePaths an array of file paths relative to the webapp directory - * @param customMessage a custom message if an assertion fails - * @return a list of File objects that have been inspected - */ - protected List assertCustomContent(File webAppDirectory, String[] filePaths, String customMessage) { - final List content = new ArrayList<>(); - for (String filePath : filePaths) { - final File expectedFile = new File(webAppDirectory, filePath); - if (customMessage != null) { - assertTrue(customMessage + " - " + expectedFile.toString(), expectedFile.exists()); - } else { - assertTrue("source file not found: " + expectedFile.toString(), expectedFile.exists()); - } - content.add(expectedFile); - } - return content; - } - - /** - * Asserts that the webapp contains only the specified files. - * - * @param webAppDirectory the webapp directory - * @param expectedFiles the expected files - * @param filter an optional filter to ignore some resources - */ - protected void assertWebAppContent(File webAppDirectory, List expectedFiles, FileFilter filter) { - final List webAppContent = new ArrayList<>(); - if (filter != null) { - buildFilesList(webAppDirectory, filter, webAppContent); - } else { - buildFilesList(webAppDirectory, new FileFilterImpl(webAppDirectory, null), webAppContent); - } - - // Now we have the files, sort them. - Collections.sort(expectedFiles); - Collections.sort(webAppContent); - assertEquals( - "Invalid webapp content, expected " + expectedFiles.size() + "file(s) " + expectedFiles + " but got " - + webAppContent.size() + " file(s) " + webAppContent, - expectedFiles, - webAppContent); - } - - /** - * Builds the list of files and directories from the specified dir. - * - * Note that the filter is not used the usual way. If the filter does not accept the current file, it's not added - * but yet the subdirectories are added if any. - * - * @param dir the base directory - * @param filter the filter - * @param content the current content, updated recursively - */ - private void buildFilesList(final File dir, FileFilter filter, final List content) { - final File[] files = dir.listFiles(); - - for (File file : files) { - // Add the file if the filter is ok with it - if (filter.accept(file)) { - content.add(file); - } - - // Even if the file is not accepted and is a directory, add it - if (file.isDirectory()) { - buildFilesList(file, filter, content); - } - } - } - - /** - * initialize required parameters - * - * @param mojo The mojo to be tested. - * @param classesDir The classes' directory. - * @param webAppSource The webAppSource. - * @param webAppDir The webAppDir folder. - * @param project The Maven project. - * @throws Exception in case of errors - */ - protected void configureMojo( - AbstractWarMojo mojo, File classesDir, File webAppSource, File webAppDir, MavenProjectBasicStub project) - throws Exception { - setVariableValueToObject(mojo, "outdatedCheckPath", "WEB-INF/lib/"); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDir); - mojo.setProject(project); - } - /** * create an isolated xml dir * @@ -1246,7 +1036,7 @@ protected File createClassesDir(String id, boolean empty) throws Exception { protected void createDir(File dir) { if (!dir.exists()) { - assertTrue("can not create test dir: " + dir.toString(), dir.mkdirs()); + assertTrue(dir.mkdirs(), "can not create test dir: " + dir); } } @@ -1254,157 +1044,10 @@ protected void createFile(File testFile, String body) throws Exception { createDir(testFile.getParentFile()); FileUtils.fileWrite(testFile.toString(), body); - assertTrue("could not create file: " + testFile, testFile.exists()); + assertTrue(testFile.exists(), "could not create file: " + testFile); } protected void createFile(File testFile) throws Exception { createFile(testFile, testFile.toString()); } - - /** - * Generates test war. - * Generates war with such a structure: - *
    - *
  • jsp - *
      - *
    • d - *
        - *
      • a.jsp
      • - *
      • b.jsp
      • - *
      • c.jsp
      • - *
      - *
    • - *
    • a.jsp
    • - *
    • b.jsp
    • - *
    • c.jsp
    • - *
    - *
  • - *
  • WEB-INF - *
      - *
    • classes - *
        - *
      • a.clazz
      • - *
      • b.clazz
      • - *
      • c.clazz
      • - *
      - *
    • - *
    • lib - *
        - *
      • a.jar
      • - *
      • b.jar
      • - *
      • c.jar
      • - *
      - *
    • - *
    • web.xml
    • - *
    - *
  • - *
- * Each of the files will contain: id+'-'+path - * - * @param id the id of the overlay containing the full structure - * @return the war file - * @throws Exception if an error occurs - */ - protected File generateFullOverlayWar(String id) throws Exception { - final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); - if (destFile.exists()) { - return destFile; - } - - // Archive was not yet created for that id so let's create it - final File rootDir = new File(OVERLAYS_ROOT_DIR, id); - rootDir.mkdirs(); - String[] filePaths = new String[] { - "jsp/d/a.jsp", - "jsp/d/b.jsp", - "jsp/d/c.jsp", - "jsp/a.jsp", - "jsp/b.jsp", - "jsp/c.jsp", - "WEB-INF/classes/a.clazz", - "WEB-INF/classes/b.clazz", - "WEB-INF/classes/c.clazz", - "WEB-INF/lib/a.jar", - "WEB-INF/lib/b.jar", - "WEB-INF/lib/c.jar", - "WEB-INF/web.xml" - }; - - for (String filePath : filePaths) { - createFile(new File(rootDir, filePath), id + "-" + filePath); - } - - createArchive(rootDir, destFile); - return destFile; - } - - /** - * Builds a test overlay. - * - * @param id the id of the overlay (see test/resources/overlays) - * @return a test war artifact with the content of the given test overlay - */ - protected ArtifactStub buildWarOverlayStub(String id) { - // Create war file - final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); - if (!destFile.exists()) { - createArchive(new File(OVERLAYS_ROOT_DIR, id), destFile); - } - - return new WarOverlayStub(getBasedir(), id, destFile); - } - - protected File getOverlayFile(String id, String filePath) { - final File overlayDir = new File(OVERLAYS_ROOT_DIR, id); - final File file = new File(overlayDir, filePath); - - // Make sure the file exists - assertTrue( - "Overlay file " + filePath + " does not exist for overlay " + id + " at " + file.getAbsolutePath(), - file.exists()); - return file; - } - - protected void createArchive(final File directory, final File destinationFile) { - try { - JarArchiver archiver = new JarArchiver(); - - archiver.setDestFile(destinationFile); - archiver.addDirectory(directory); - - archiver.createArchive(); - - } catch (ArchiverException e) { - e.printStackTrace(); - fail("Failed to create overlay archive " + e.getMessage()); - } catch (IOException e) { - e.printStackTrace(); - fail("Unexpected exception " + e.getMessage()); - } - } - - class FileFilterImpl implements FileFilter { - - private final List rejectedFilePaths; - - private final int webAppDirIndex; - - FileFilterImpl(File webAppDirectory, String[] rejectedFilePaths) { - if (rejectedFilePaths != null) { - this.rejectedFilePaths = Arrays.asList(rejectedFilePaths); - } else { - this.rejectedFilePaths = new ArrayList<>(); - } - this.webAppDirIndex = webAppDirectory.getAbsolutePath().length() + 1; - } - - public boolean accept(File file) { - String effectiveRelativePath = buildRelativePath(file); - return !(rejectedFilePaths.contains(effectiveRelativePath) || file.isDirectory()); - } - - private String buildRelativePath(File f) { - return f.getAbsolutePath().substring(webAppDirIndex); - } - } } From 751b4d971a6b050cdafaac2c1546cd535414241d Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 5 Nov 2025 15:09:16 +0100 Subject: [PATCH 13/80] refactor: WarExplodedMojoTest --- .../plugins/war/WarExplodedMojoTest.java | 184 ++++++------------ 1 file changed, 55 insertions(+), 129 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index f7fffe23..e7bd7271 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -43,6 +43,7 @@ import org.apache.maven.plugins.war.stub.TLDArtifactStub; import org.apache.maven.plugins.war.stub.WarArtifactStub; import org.apache.maven.plugins.war.stub.XarArtifactStub; +import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.FileUtils; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -68,7 +69,6 @@ protected File getTestDirectory() { public void testSimpleExplodedWar(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "SimpleExplodedWar"; - MavenProjectBasicStub project = new MavenProjectBasicStub(); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, false); File webAppResource = new File(getTestDirectory(), testId + "-resources"); @@ -76,11 +76,7 @@ public void testSimpleExplodedWar(WarExplodedMojo mojo) throws Exception { File sampleResource = new File(webAppResource, "pix/panis_na.jpg"); ResourceStub[] resources = createWebResources(sampleResource, webAppResource); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); - mojo.setWebResources(resources); + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, resources); mojo.execute(); // validate operation @@ -102,19 +98,11 @@ public void testSimpleExplodedWar(WarExplodedMojo mojo) throws Exception { expectedWebResourceFile.delete(); } - private ResourceStub[] createWebResources(File sampleResource, File webAppResource) throws Exception { - ResourceStub[] resources = new ResourceStub[] {new ResourceStub()}; - createFile(sampleResource); - resources[0].setDirectory(webAppResource.getAbsolutePath()); - return resources; - } - @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") @Test public void testSimpleExplodedWarWTargetPath(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "SimpleExplodedWar"; - MavenProjectBasicStub project = new MavenProjectBasicStub(); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, false); File webAppResource = new File(getTestDirectory(), "resources"); @@ -123,11 +111,7 @@ public void testSimpleExplodedWarWTargetPath(WarExplodedMojo mojo) throws Except ResourceStub[] resources = createWebResources(sampleResource, webAppResource); resources[0].setTargetPath("targetPath"); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); - mojo.setWebResources(resources); + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, resources); mojo.execute(); // validate operation @@ -149,22 +133,30 @@ public void testSimpleExplodedWarWTargetPath(WarExplodedMojo mojo) throws Except expectedWebResourceFile.delete(); } + private void configureMojo(WarExplodedMojo mojo, File classesDir, File webAppSource, File webAppDirectory, ResourceStub[] resources) throws Exception { + configureMojo(mojo, classesDir, webAppSource, webAppDirectory); + mojo.setWebResources(resources); + } + + private ResourceStub[] createWebResources(File sampleResource, File webAppResource) throws Exception { + ResourceStub[] resources = new ResourceStub[] {new ResourceStub()}; + createFile(sampleResource); + resources[0].setDirectory(webAppResource.getAbsolutePath()); + return resources; + } + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") @Test public void testExplodedWarWithCustomWebXML(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "ExplodedWarWithCustomWebXML"; - MavenProjectBasicStub project = new MavenProjectBasicStub(); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); File webAppDirectory = new File(getTestDirectory(), testId); // configure mojo - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + configureMojo(mojo, classesDir, webAppSource, webAppDirectory); mojo.setWebXml(new File(xmlSource, "web.xml")); mojo.execute(); @@ -192,17 +184,13 @@ public void testExplodedWarWithCustomWebXML(WarExplodedMojo mojo) throws Excepti public void testExplodedWarWithContainerConfigXML(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "ExplodedWarWithContainerConfigXML"; - MavenProjectBasicStub project = new MavenProjectBasicStub(); File classesDir = createClassesDir(testId, true); File webAppSource = createWebAppSource(testId); File xmlSource = createXMLConfigDir(testId, new String[] {"config.xml"}); File webAppDirectory = new File(getTestDirectory(), testId); // configure mojo - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + configureMojo(mojo, classesDir, webAppSource, webAppDirectory); mojo.setContainerConfigXML(new File(xmlSource, "config.xml")); mojo.execute(); @@ -243,12 +231,7 @@ public void testExplodedWarWithSimpleExternalWARFile(WarExplodedMojo mojo) throw // configure mojo WarArtifactStub warArtifact = new WarArtifactStub(getBasedir()); - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - project.addArtifact(warArtifact); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory); mojo.execute(); // validate operation - META-INF is automatically excluded so remove the file from the list @@ -293,10 +276,7 @@ public void testExplodedWarMergeWarLocalFileOverride(WarExplodedMojo mojo) throw WarArtifactStub warArtifact = new WarArtifactStub(getBasedir()); MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); project.addArtifact(warArtifact); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); mojo.execute(); // validate operation @@ -312,10 +292,7 @@ public void testExplodedWarMergeWarLocalFileOverride(WarExplodedMojo mojo) throw expectedFile.setLastModified(time); project.addArtifact(warArtifact); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); mojo.execute(); assertTrue(expectedFile.exists(), "file not found: " + expectedFile); @@ -336,12 +313,7 @@ public void testExplodedWarWithEJB(WarExplodedMojo mojo) throws Exception { EJBArtifactStub ejbArtifact = new EJBArtifactStub(getBasedir()); // configure mojo - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - project.addArtifact(ejbArtifact); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + configureMojo(mojo, ejbArtifact, classesDir, webAppSource, webAppDirectory); mojo.execute(); // validate operation @@ -372,12 +344,7 @@ public void testExplodedWarWithJar(WarExplodedMojo mojo) throws Exception { ArtifactStub jarArtifact = new JarArtifactStub(getBasedir(), artifactHandler); // configure mojo - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - project.addArtifact(jarArtifact); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + configureMojo(mojo, jarArtifact, classesDir, webAppSource, webAppDirectory); mojo.execute(); // validate operation @@ -410,12 +377,7 @@ public void testExplodedWarWithEJBClient(WarExplodedMojo mojo) throws Exception EJBClientArtifactStub ejbArtifact = new EJBClientArtifactStub(getBasedir()); // configure mojo - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - project.addArtifact(ejbArtifact); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + configureMojo(mojo,ejbArtifact, classesDir, webAppSource, webAppDirectory); mojo.execute(); // validate operation @@ -448,12 +410,7 @@ public void testExplodedWarWithTLD(WarExplodedMojo mojo) throws Exception { TLDArtifactStub tldArtifact = new TLDArtifactStub(getBasedir()); // configure mojo - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - project.addArtifact(tldArtifact); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + configureMojo(mojo,tldArtifact, classesDir, webAppSource, webAppDirectory); mojo.execute(); // validate operation @@ -483,12 +440,7 @@ public void testExplodedWarWithPAR(WarExplodedMojo mojo) throws Exception { PARArtifactStub parartifact = new PARArtifactStub(getBasedir()); // configure mojo - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - project.addArtifact(parartifact); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + configureMojo(mojo, parartifact, classesDir, webAppSource, webAppDirectory); mojo.execute(); // validate operation @@ -520,11 +472,7 @@ public void testExplodedWarWithAar(WarExplodedMojo mojo) throws Exception { ArtifactStub aarArtifact = new AarArtifactStub(getBasedir(), artifactHandler); // configure mojo - project.addArtifact(aarArtifact); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + configureMojo(mojo, aarArtifact, classesDir, webAppSource, webAppDirectory); mojo.execute(); // validate operation @@ -549,18 +497,13 @@ public void testExplodedWarWithAar(WarExplodedMojo mojo) throws Exception { public void testExplodedWarWithMar(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "ExplodedWarWithMar"; - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); File webAppDirectory = new File(getTestDirectory(), testId); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); ArtifactStub marArtifact = new MarArtifactStub(getBasedir(), artifactHandler); // configure mojo - project.addArtifact(marArtifact); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + configureMojo(mojo,marArtifact, classesDir, webAppSource, webAppDirectory); mojo.execute(); // validate operation @@ -585,18 +528,13 @@ public void testExplodedWarWithMar(WarExplodedMojo mojo) throws Exception { public void testExplodedWarWithXar(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "ExplodedWarWithXar"; - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); File webAppDirectory = new File(getTestDirectory(), testId); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); ArtifactStub xarArtifact = new XarArtifactStub(getBasedir(), artifactHandler); // configure mojo - project.addArtifact(xarArtifact); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + configureMojo(mojo, xarArtifact,classesDir, webAppSource, webAppDirectory); mojo.execute(); // validate operation @@ -633,10 +571,7 @@ public void testExplodedWarWithDuplicateDependencies(WarExplodedMojo mojo) throw MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); project.addArtifact(ejbArtifact); project.addArtifact(ejbArtifactDup); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); mojo.execute(); // validate operation @@ -680,10 +615,7 @@ public void testExplodedWarDuplicateWithClassifier(WarExplodedMojo mojo) throws project.addArtifact(ejbArtifact); project.addArtifact(ejbArtifactDup); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); mojo.execute(); // validate operation @@ -718,11 +650,7 @@ public void testExplodedWarWithClasses(WarExplodedMojo mojo) throws Exception { File classesDir = createClassesDir(testId, false); // configure mojo - MavenProjectBasicStub project = new MavenProjectBasicStub(); - mojo.setProject(project); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); + configureMojo(mojo, classesDir, webAppSource, webAppDirectory); mojo.execute(); // validate operation @@ -753,11 +681,7 @@ public void testExplodedWarWithSourceIncludeExclude(WarExplodedMojo mojo) throws File webAppDirectory = new File(getTestDirectory(), testId); // configure mojo - MavenProjectBasicStub project = new MavenProjectBasicStub(); - mojo.setProject(project); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); + configureMojo(mojo, classesDir, webAppSource, webAppDirectory); mojo.execute(); // validate operation @@ -795,12 +719,7 @@ public void testExplodedWarWithWarDependencyIncludeExclude(WarExplodedMojo mojo) IncludeExcludeWarArtifactStub includeexcludeWarArtifact = new IncludeExcludeWarArtifactStub(getBasedir()); // configure mojo - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - mojo.setProject(project); - project.addArtifact(includeexcludeWarArtifact); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); + configureMojo(mojo, includeexcludeWarArtifact, classesDir, webAppSource, webAppDirectory); mojo.execute(); // validate operation @@ -838,11 +757,7 @@ public void testExplodedWarWithSourceModificationCheck(WarExplodedMojo mojo) thr File webAppDirectory = new File(getTestDirectory(), testId); // configure mojo - MavenProjectBasicStub project = new MavenProjectBasicStub(); - mojo.setProject(project); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); + configureMojo(mojo, classesDir, webAppSource, webAppDirectory); // destination file is already created manually containing an "error" string // source is newer than the destination file @@ -880,19 +795,14 @@ public void testExplodedWarWithSourceModificationCheck(WarExplodedMojo mojo) thr public void testExplodedWarWithOutputFileNameMapping(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "ExplodedWarWithFileNameMapping"; - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); File webAppDirectory = new File(getTestDirectory(), testId); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); ArtifactStub jarArtifact = new JarArtifactStub(getBasedir(), artifactHandler); // configure mojo - project.addArtifact(jarArtifact); mojo.setOutputFileNameMapping("@{artifactId}@.@{extension}@"); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + configureMojo(mojo, jarArtifact, classesDir, webAppSource, webAppDirectory); mojo.execute(); // validate operation @@ -930,10 +840,7 @@ public void testExplodedWarWithOutputFileNameMappingAndDuplicateDependencies(War project.addArtifact(ejbArtifact); project.addArtifact(ejbArtifactDup); mojo.setOutputFileNameMapping("@{artifactId}@.@{extension}@"); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); mojo.execute(); // validate operation @@ -955,6 +862,25 @@ public void testExplodedWarWithOutputFileNameMappingAndDuplicateDependencies(War expectedEJBDupArtifact.delete(); } + private void configureMojo(WarExplodedMojo mojo, File classesDir, File webAppSource, File webAppDirectory) throws Exception { + MavenProjectBasicStub project = new MavenProjectBasicStub(); + configureMojo(mojo,classesDir,webAppSource,webAppDirectory, project); + } + + private void configureMojo(WarExplodedMojo mojo, ArtifactStub artifact, File classesDir, File webAppSource, File webAppDirectory) throws Exception { + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + project.addArtifact(artifact); + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + } + + private void configureMojo(WarExplodedMojo mojo, File classesDir, File webAppSource, File webAppDirectory, MavenProject project) { + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); + } + + /** * create an isolated xml dir * From 7ee5c95b24fa369ab9855d46473df3e7b2bd6e73 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 5 Nov 2025 15:58:58 +0100 Subject: [PATCH 14/80] chore (wip): migrate AbstractMojoTestCase based tests to use MojoTest - WarExplodedMojoFilteringTest --- .../war/WarExplodedMojoFilteringTest.java | 578 ++++-------------- 1 file changed, 114 insertions(+), 464 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java index dff8578f..cd72aee8 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java @@ -18,68 +18,82 @@ */ package org.apache.maven.plugins.war; +/* + * 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 org.apache.maven.api.di.Provides; +import org.apache.maven.api.plugin.testing.InjectMojo; +import org.apache.maven.api.plugin.testing.MojoTest; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugins.war.stub.MavenProjectBasicStub; +import org.apache.maven.plugins.war.stub.ResourceStub; +import org.codehaus.plexus.util.FileUtils; +import org.junit.jupiter.api.Test; + +import javax.inject.Inject; import java.io.BufferedReader; import java.io.File; -import java.io.FileFilter; -import java.io.IOException; import java.io.StringReader; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Date; -import java.util.LinkedList; import java.util.List; +import java.util.Properties; -import org.apache.maven.execution.DefaultMavenExecutionRequest; -import org.apache.maven.execution.MavenExecutionRequest; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.testing.AbstractMojoTestCase; -import org.apache.maven.plugin.testing.stubs.ArtifactStub; -import org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub; -import org.apache.maven.plugins.war.stub.MavenProjectBasicStub; -import org.apache.maven.plugins.war.stub.ResourceStub; -import org.apache.maven.plugins.war.stub.WarOverlayStub; -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.archiver.ArchiverException; -import org.codehaus.plexus.archiver.jar.JarArchiver; -import org.codehaus.plexus.util.FileUtils; -import org.eclipse.aether.RepositorySystemSession; +import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.when; /** * @author Olivier Lamy * @since 21 juil. 2008 */ -public class WarExplodedMojoFilteringTest extends AbstractMojoTestCase { +@MojoTest +public class WarExplodedMojoFilteringTest { - protected static final File OVERLAYS_TEMP_DIR = new File(getBasedir(), "target/test-overlays/"); - protected static final File OVERLAYS_ROOT_DIR = new File(getBasedir(), "target/test-classes/overlays/"); - protected static final String MANIFEST_PATH = "META-INF" + File.separator + "MANIFEST.MF"; - protected WarExplodedMojo mojo; + @Inject + private List filters; - protected File getPomFile() { - return new File(getBasedir(), "/target/test-classes/unit/warexplodedmojo/plugin-config.xml"); - } + @Inject + private MavenSession mavenSession; protected File getTestDirectory() { return new File(getBasedir(), "target/test-classes/unit/warexplodedmojo/test-dir"); } - /** - * @throws Exception in case of an error. - */ - @SuppressWarnings("checkstyle:MethodLength") - public void testExplodedWarWithResourceFiltering() throws Exception { + @Provides + List filters() { + List filtersList = new ArrayList<>(); + filtersList.add("test-filter"); //only for demo, it is temporary + return filtersList; + } + + @InjectMojo(goal="exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @Test + public void testExplodedWarWithResourceFiltering(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "ExplodedWarWithResourceFiltering"; - MavenProjectBasicStub project = new MavenProjectBasicStub(); File webAppDirectory = new File(getTestDirectory(), testId); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, false); File webAppResource = new File(getTestDirectory(), testId + "-test-data/resources"); File sampleResource = new File(webAppResource, "custom-setting.cfg"); File sampleResourceWDir = new File(webAppResource, "custom-config/custom-setting.cfg"); - List filterList = new LinkedList<>(); - ResourceStub[] resources = new ResourceStub[] {new ResourceStub()}; createFile(sampleResource); createFile(sampleResourceWDir); @@ -99,15 +113,18 @@ public void testExplodedWarWithResourceFiltering() throws Exception { FileUtils.fileWrite(sampleResourceWDir.getAbsolutePath(), content); FileUtils.fileWrite(sampleResource.getAbsolutePath(), content); - lookup(MavenSession.class).getSystemProperties().setProperty("system.property", "system-property-value"); + Properties systemProperties = System.getProperties(); + systemProperties.put("system.property", "system-property-value"); + when(mavenSession.getSystemProperties()).thenReturn(systemProperties); // configure mojo + MavenProjectBasicStub project = new MavenProjectBasicStub(); project.addProperty("is_this_simple", "i_think_so"); + ResourceStub[] resources = new ResourceStub[] {new ResourceStub()}; resources[0].setDirectory(webAppResource.getAbsolutePath()); resources[0].setFiltering(true); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "webResources", resources); - setVariableValueToObject(mojo, "filters", filterList); + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + mojo.setWebResources(resources); mojo.execute(); @@ -117,44 +134,49 @@ public void testExplodedWarWithResourceFiltering() throws Exception { File expectedResourceFile = new File(webAppDirectory, "custom-setting.cfg"); File expectedResourceWDirFile = new File(webAppDirectory, "custom-config/custom-setting.cfg"); - assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); - assertTrue("resource file not found:" + expectedResourceFile.toString(), expectedResourceFile.exists()); + assertTrue(expectedWebSourceFile.exists(), "source files not found: " + expectedWebSourceFile); + assertTrue(expectedWebSource2File.exists(), "source files not found: " + expectedWebSource2File); + assertTrue(expectedResourceFile.exists(), "resource file not found:" + expectedResourceFile); assertTrue( - "resource file with dir not found:" + expectedResourceWDirFile.toString(), - expectedResourceWDirFile.exists()); + expectedResourceWDirFile.exists(), + "resource file with dir not found:" + expectedResourceWDirFile); // validate filtered file content = FileUtils.fileRead(expectedResourceWDirFile); BufferedReader reader = new BufferedReader(new StringReader(content)); - assertEquals("error in filtering using System Properties", comment, reader.readLine()); + assertEquals(comment, reader.readLine(), "error in filtering using System Properties"); String line = reader.readLine(); + System.out.println(" line " + line); + System.out.println(" need " + System.getProperty("user.dir")); assertEquals( - "error in filtering using System properties", "system_key_1=" + System.getProperty("user.dir"), line); + "system_key_1=" + System.getProperty("user.dir"), line, "error in filtering using System properties"); line = reader.readLine(); + System.out.println(" line " + line); assertEquals( - "error in filtering using System properties", "system_key_2=" + System.getProperty("user.dir"), line); + "system_key_2=" + System.getProperty("user.dir"), line, "error in filtering using System properties"); - assertEquals("error in filtering using project properties", "project_key_1=i_think_so", reader.readLine()); - assertEquals("error in filtering using project properties", "project_key_2=i_think_so", reader.readLine()); + assertEquals("project_key_1=i_think_so", reader.readLine(), "error in filtering using project properties"); + assertEquals("project_key_2=i_think_so", reader.readLine(), "error in filtering using project properties"); - assertEquals("error in filtering using project properties", "project_name_1=Test Project ", reader.readLine()); - assertEquals("error in filtering using project properties", "project_name_2=Test Project ", reader.readLine()); + assertEquals("project_name_1=Test Project ", reader.readLine(), "error in filtering using project properties"); + assertEquals("project_name_2=Test Project ", reader.readLine(), "error in filtering using project properties"); assertEquals( - "error in filtering using System properties", "system_property_1=system-property-value", - reader.readLine()); + reader.readLine(), + "error in filtering using System properties"); assertEquals( - "error in filtering using System properties", "system_property_2=system-property-value", - reader.readLine()); + reader.readLine(), + "error in filtering using System properties"); // update property, and generate again - lookup(MavenSession.class).getSystemProperties().setProperty("system.property", "new-system-property-value"); - this.configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + systemProperties.put("system.property", "new-system-property-value"); + when(mavenSession.getSystemProperties()).thenReturn(systemProperties); + + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); mojo.execute(); @@ -162,36 +184,36 @@ public void testExplodedWarWithResourceFiltering() throws Exception { content = FileUtils.fileRead(expectedResourceWDirFile); reader = new BufferedReader(new StringReader(content)); - assertEquals("error in filtering using System Properties", comment, reader.readLine()); + assertEquals(comment, reader.readLine(), "error in filtering using System Properties"); assertEquals( - "error in filtering using System properties", "system_key_1=" + System.getProperty("user.dir"), - reader.readLine()); + reader.readLine(), + "error in filtering using System properties"); assertEquals( - "error in filtering using System properties", "system_key_2=" + System.getProperty("user.dir"), - reader.readLine()); + reader.readLine(), + "error in filtering using System properties"); - assertEquals("error in filtering using project properties", "project_key_1=i_think_so", reader.readLine()); - assertEquals("error in filtering using project properties", "project_key_2=i_think_so", reader.readLine()); + assertEquals("project_key_1=i_think_so", reader.readLine(), "error in filtering using project properties"); + assertEquals("project_key_2=i_think_so", reader.readLine(), "error in filtering using project properties"); - assertEquals("error in filtering using project properties", "project_name_1=Test Project ", reader.readLine()); - assertEquals("error in filtering using project properties", "project_name_2=Test Project ", reader.readLine()); + assertEquals("project_name_1=Test Project ", reader.readLine(), "error in filtering using project properties"); + assertEquals("project_name_2=Test Project ", reader.readLine(), "error in filtering using project properties"); assertEquals( - "error in filtering using System properties", "system_property_1=new-system-property-value", - reader.readLine()); + reader.readLine(), + "error in filtering using System properties"); assertEquals( - "error in filtering using System properties", "system_property_2=new-system-property-value", - reader.readLine()); + reader.readLine(), + "error in filtering using System properties"); // update property, and generate again File filterFile = new File(getTestDirectory(), testId + "-test-data/filters/filter.properties"); createFile(filterFile); - filterList.add(filterFile.getAbsolutePath()); + filters.add(filterFile.getAbsolutePath()); content += "resource_key_1=${resource_value_1}\n"; content += "resource_key_2=@resource_value_2@\n" + content; FileUtils.fileWrite(sampleResourceWDir.getAbsolutePath(), content); @@ -206,276 +228,50 @@ public void testExplodedWarWithResourceFiltering() throws Exception { content = FileUtils.fileRead(expectedResourceWDirFile); reader = new BufferedReader(new StringReader(content)); - assertEquals("error in filtering using System Properties", comment, reader.readLine()); + assertEquals(comment, reader.readLine(), "error in filtering using System Properties"); assertEquals( - "error in filtering using System properties", "system_key_1=" + System.getProperty("user.dir"), - reader.readLine()); + reader.readLine(), + "error in filtering using System properties"); assertEquals( - "error in filtering using System properties", "system_key_2=" + System.getProperty("user.dir"), - reader.readLine()); + reader.readLine(), + "error in filtering using System properties"); - assertEquals("error in filtering using project properties", "project_key_1=i_think_so", reader.readLine()); - assertEquals("error in filtering using project properties", "project_key_2=i_think_so", reader.readLine()); + assertEquals("project_key_1=i_think_so", reader.readLine(), "error in filtering using project properties"); + assertEquals("project_key_2=i_think_so", reader.readLine(), "error in filtering using project properties"); - assertEquals("error in filtering using project properties", "project_name_1=Test Project ", reader.readLine()); - assertEquals("error in filtering using project properties", "project_name_2=Test Project ", reader.readLine()); + assertEquals("project_name_1=Test Project ", reader.readLine(), "error in filtering using project properties"); + assertEquals("project_name_2=Test Project ", reader.readLine(), "error in filtering using project properties"); assertEquals( - "error in filtering using System properties", "system_property_1=new-system-property-value", - reader.readLine()); + reader.readLine(), + "error in filtering using System properties"); assertEquals( - "error in filtering using System properties", "system_property_2=new-system-property-value", - reader.readLine()); + reader.readLine(), + "error in filtering using System properties"); - assertEquals("error in filtering using filter files", "resource_key_1=this_is_filtered", reader.readLine()); - assertEquals("error in filtering using filter files", "resource_key_2=this_is_filtered", reader.readLine()); + assertEquals("resource_key_1=this_is_filtered", reader.readLine(), "error in filtering using filter files"); + assertEquals("resource_key_2=this_is_filtered", reader.readLine(), "error in filtering using filter files"); - // house-keeping + // house keeping expectedWebSourceFile.delete(); expectedWebSource2File.delete(); expectedResourceFile.delete(); expectedResourceWDirFile.delete(); } - public void setUp() throws Exception { - super.setUp(); - - MavenExecutionRequest request = new DefaultMavenExecutionRequest() - .setSystemProperties(System.getProperties()) - .setStartTime(new Date()); - - MavenSession mavenSession = - new MavenSession((PlexusContainer) null, (RepositorySystemSession) null, request, null); - getContainer().addComponent(mavenSession, MavenSession.class.getName()); - mojo = (WarExplodedMojo) lookupMojo("exploded", getPomFile()); - } - - /** - * Configures the exploded mojo for the specified test. - * - * If the {@code sourceFiles} parameter is {@code null}, sample JSPs are created by default. - * - * @param testId the id of the test - * @param artifactStubs the dependencies (may be null) - * @param sourceFiles the source files to create (may be null) - * @return the webapp directory - * @throws Exception if an error occurs while configuring the mojo - */ - protected File setUpMojo(final String testId, ArtifactStub[] artifactStubs, String[] sourceFiles) throws Exception { - final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - final File webAppDirectory = new File(getTestDirectory(), testId); - - // Create the webapp sources - File webAppSource; - if (sourceFiles == null) { - webAppSource = createWebAppSource(testId); - } else { - webAppSource = createWebAppSource(testId, false); - for (String sourceFile : sourceFiles) { - File sample = new File(webAppSource, sourceFile); - createFile(sample); - } - } - - final File classesDir = createClassesDir(testId, true); - final File workDirectory = new File(getTestDirectory(), "/war/work-" + testId); - createDir(workDirectory); - - if (artifactStubs != null) { - for (ArtifactStub artifactStub : artifactStubs) { - project.addArtifact(artifactStub); - } - } - - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - setVariableValueToObject(mojo, "workDirectory", workDirectory); - - return webAppDirectory; - } - - /** - * Configures the exploded mojo for the specified test. - * - * @param testId the id of the test - * @param artifactStubs the dependencies (may be null) - * @return the webapp directory - * @throws Exception if an error occurs while configuring the mojo - */ - protected File setUpMojo(final String testId, ArtifactStub[] artifactStubs) throws Exception { - return setUpMojo(testId, artifactStubs, null); - } - - /** - * Cleans up a directory. - * - * @param directory the directory to remove - * @throws IOException if an error occurred while removing the directory - */ - protected void cleanDirectory(File directory) throws IOException { - if (directory != null && directory.isDirectory() && directory.exists()) { - FileUtils.deleteDirectory(directory); - } - } - - /** - * Asserts the default content of the war based on the specified webapp directory. - * - * @param webAppDirectory the webapp directory - * @return a list of File objects that have been asserted - */ - protected List assertDefaultContent(File webAppDirectory) { - // Validate content of the webapp - File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); - File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); - - assertTrue("source file not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists()); - assertTrue("source file not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists()); - - final List content = new ArrayList<>(); - content.add(expectedWebSourceFile); - content.add(expectedWebSource2File); - - return content; - } - - /** - * Asserts the web.xml file of the war based on the specified webapp directory. - * - * @param webAppDirectory the webapp directory - * @return a list with the web.xml File object - */ - protected List assertWebXml(File webAppDirectory) { - File expectedWEBXMLFile = new File(webAppDirectory, "WEB-INF/web.xml"); - assertTrue("web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists()); - - final List content = new ArrayList<>(); - content.add(expectedWEBXMLFile); - - return content; - } - - /** - * Asserts custom content of the war based on the specified webapp directory. - * - * @param webAppDirectory the webapp directory - * @param filePaths an array of file paths relative to the webapp directory - * @param customMessage a custom message if an assertion fails - * @return a list of File objects that have been inspected - */ - protected List assertCustomContent(File webAppDirectory, String[] filePaths, String customMessage) { - final List content = new ArrayList<>(); - for (String filePath : filePaths) { - final File expectedFile = new File(webAppDirectory, filePath); - if (customMessage != null) { - assertTrue(customMessage + " - " + expectedFile.toString(), expectedFile.exists()); - } else { - assertTrue("source file not found: " + expectedFile.toString(), expectedFile.exists()); - } - content.add(expectedFile); - } - return content; - } - - /** - * Asserts that the webapp contains only the specified files. - * - * @param webAppDirectory the webapp directory - * @param expectedFiles the expected files - * @param filter an optional filter to ignore some resources - */ - protected void assertWebAppContent(File webAppDirectory, List expectedFiles, FileFilter filter) { - final List webAppContent = new ArrayList<>(); - if (filter != null) { - buildFilesList(webAppDirectory, filter, webAppContent); - } else { - buildFilesList(webAppDirectory, new FileFilterImpl(webAppDirectory, null), webAppContent); - } - - // Now we have the files, sort them. - Collections.sort(expectedFiles); - Collections.sort(webAppContent); - assertEquals( - "Invalid webapp content, expected " + expectedFiles.size() + "file(s) " + expectedFiles + " but got " - + webAppContent.size() + " file(s) " + webAppContent, - expectedFiles, - webAppContent); - } - /** - * Builds the list of files and directories from the specified dir. - * - * Note that the filter is not used the usual way. If the filter does not accept the current file, it's not added - * but yet the subdirectories are added if any. - * - * @param dir the base directory - * @param filter the filter - * @param content the current content, updated recursively - */ - private void buildFilesList(final File dir, FileFilter filter, final List content) { - final File[] files = dir.listFiles(); - - for (File file : files) { - // Add the file if the filter is ok with it - if (filter.accept(file)) { - content.add(file); - } - - // Even if the file is not accepted and is a directory, add it - if (file.isDirectory()) { - buildFilesList(file, filter, content); - } - } - } - - /** - * initialize required parameters - * - * @param mojo The mojo to be tested. - * @param classesDir The classes' directory. - * @param webAppSource The webAppSource. - * @param webAppDir The webAppDir folder. - * @param project The Maven project. - * @throws Exception in case of errors - */ - protected void configureMojo( - AbstractWarMojo mojo, File classesDir, File webAppSource, File webAppDir, MavenProjectBasicStub project) - throws Exception { - setVariableValueToObject(mojo, "outdatedCheckPath", "WEB-INF/lib/"); + private void configureMojo(WarExplodedMojo mojo, File classesDir, File webAppSource, File webAppDirectory, MavenProjectBasicStub project) { mojo.setClassesDirectory(classesDir); mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDir); + mojo.setWebappDirectory(webAppDirectory); mojo.setProject(project); } - /** - * create an isolated xml dir - * - * @param id The id. - * @param xmlFiles array of xml files. - * @return The created file. - * @throws Exception in case of errors. - */ - protected File createXMLConfigDir(String id, String[] xmlFiles) throws Exception { - File xmlConfigDir = new File(getTestDirectory(), "/" + id + "-test-data/xml-config"); - File xmlFile; - - createDir(xmlConfigDir); - - if (xmlFiles != null) { - for (String o : xmlFiles) { - xmlFile = new File(xmlConfigDir, o); - createFile(xmlFile); - } - } - - return xmlConfigDir; - } - /** * Returns the webapp source directory for the specified id. * @@ -533,7 +329,7 @@ protected File createClassesDir(String id, boolean empty) throws Exception { protected void createDir(File dir) { if (!dir.exists()) { - assertTrue("can not create test dir: " + dir.toString(), dir.mkdirs()); + assertTrue(dir.mkdirs(), "can not create test dir: " + dir); } } @@ -541,157 +337,11 @@ protected void createFile(File testFile, String body) throws Exception { createDir(testFile.getParentFile()); FileUtils.fileWrite(testFile.toString(), body); - assertTrue("could not create file: " + testFile, testFile.exists()); + assertTrue(testFile.exists(), "could not create file: " + testFile); } protected void createFile(File testFile) throws Exception { createFile(testFile, testFile.toString()); } - /** - * Generates test war. - * Generates war with such a structure: - *
    - *
  • jsp - *
      - *
    • d - *
        - *
      • a.jsp
      • - *
      • b.jsp
      • - *
      • c.jsp
      • - *
      - *
    • - *
    • a.jsp
    • - *
    • b.jsp
    • - *
    • c.jsp
    • - *
    - *
  • - *
  • WEB-INF - *
      - *
    • classes - *
        - *
      • a.clazz
      • - *
      • b.clazz
      • - *
      • c.clazz
      • - *
      - *
    • - *
    • lib - *
        - *
      • a.jar
      • - *
      • b.jar
      • - *
      • c.jar
      • - *
      - *
    • - *
    • web.xml
    • - *
    - *
  • - *
- * Each of the files will contain: id+'-'+path - * - * @param id the id of the overlay containing the full structure - * @return the war file - * @throws Exception if an error occurs - */ - protected File generateFullOverlayWar(String id) throws Exception { - final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); - if (destFile.exists()) { - return destFile; - } - - // Archive was not yet created for that id so let's create it - final File rootDir = new File(OVERLAYS_ROOT_DIR, id); - rootDir.mkdirs(); - String[] filePaths = new String[] { - "jsp/d/a.jsp", - "jsp/d/b.jsp", - "jsp/d/c.jsp", - "jsp/a.jsp", - "jsp/b.jsp", - "jsp/c.jsp", - "WEB-INF/classes/a.clazz", - "WEB-INF/classes/b.clazz", - "WEB-INF/classes/c.clazz", - "WEB-INF/lib/a.jar", - "WEB-INF/lib/b.jar", - "WEB-INF/lib/c.jar", - "WEB-INF/web.xml" - }; - - for (String filePath : filePaths) { - createFile(new File(rootDir, filePath), id + "-" + filePath); - } - - createArchive(rootDir, destFile); - return destFile; - } - - /** - * Builds a test overlay. - * - * @param id the id of the overlay (see test/resources/overlays) - * @return a test war artifact with the content of the given test overlay - */ - protected ArtifactStub buildWarOverlayStub(String id) { - // Create war file - final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); - if (!destFile.exists()) { - createArchive(new File(OVERLAYS_ROOT_DIR, id), destFile); - } - - return new WarOverlayStub(getBasedir(), id, destFile); - } - - protected File getOverlayFile(String id, String filePath) { - final File overlayDir = new File(OVERLAYS_ROOT_DIR, id); - final File file = new File(overlayDir, filePath); - - // Make sure the file exists - assertTrue( - "Overlay file " + filePath + " does not exist for overlay " + id + " at " + file.getAbsolutePath(), - file.exists()); - return file; - } - - protected void createArchive(final File directory, final File destinationFile) { - try { - JarArchiver archiver = new JarArchiver(); - - archiver.setDestFile(destinationFile); - archiver.addDirectory(directory); - - archiver.createArchive(); - - } catch (ArchiverException e) { - e.printStackTrace(); - fail("Failed to create overlay archive " + e.getMessage()); - } catch (IOException e) { - e.printStackTrace(); - fail("Unexpected exception " + e.getMessage()); - } - } - - class FileFilterImpl implements FileFilter { - - private final List rejectedFilePaths; - - private final int webAppDirIndex; - - FileFilterImpl(File webAppDirectory, String[] rejectedFilePaths) { - if (rejectedFilePaths != null) { - this.rejectedFilePaths = Arrays.asList(rejectedFilePaths); - } else { - this.rejectedFilePaths = new ArrayList<>(); - } - this.webAppDirIndex = webAppDirectory.getAbsolutePath().length() + 1; - } - - public boolean accept(File file) { - String effectiveRelativePath = buildRelativePath(file); - return !(rejectedFilePaths.contains(effectiveRelativePath) || file.isDirectory()); - } - - private String buildRelativePath(File f) { - return f.getAbsolutePath().substring(webAppDirIndex); - } - } } From f6e1750ee258b2f2316daf20736ae87681b9bb88 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 5 Nov 2025 16:04:40 +0100 Subject: [PATCH 15/80] fix: checkstyle rules --- .../war/WarExplodedMojoFilteringTest.java | 35 ++++++++++--------- .../plugins/war/WarExplodedMojoTest.java | 26 ++++++++------ 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java index cd72aee8..5ab68221 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java @@ -37,6 +37,15 @@ * under the License. */ +import javax.inject.Inject; + +import java.io.BufferedReader; +import java.io.File; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + import org.apache.maven.api.di.Provides; import org.apache.maven.api.plugin.testing.InjectMojo; import org.apache.maven.api.plugin.testing.MojoTest; @@ -46,14 +55,6 @@ import org.codehaus.plexus.util.FileUtils; import org.junit.jupiter.api.Test; -import javax.inject.Inject; -import java.io.BufferedReader; -import java.io.File; -import java.io.StringReader; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; - import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -79,11 +80,12 @@ protected File getTestDirectory() { @Provides List filters() { List filtersList = new ArrayList<>(); - filtersList.add("test-filter"); //only for demo, it is temporary + filtersList.add("test-filter"); // only for demo, it is temporary return filtersList; } - @InjectMojo(goal="exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @SuppressWarnings("checkstyle:MethodLength") + @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") @Test public void testExplodedWarWithResourceFiltering(WarExplodedMojo mojo) throws Exception { // setup test data @@ -137,9 +139,7 @@ public void testExplodedWarWithResourceFiltering(WarExplodedMojo mojo) throws Ex assertTrue(expectedWebSourceFile.exists(), "source files not found: " + expectedWebSourceFile); assertTrue(expectedWebSource2File.exists(), "source files not found: " + expectedWebSource2File); assertTrue(expectedResourceFile.exists(), "resource file not found:" + expectedResourceFile); - assertTrue( - expectedResourceWDirFile.exists(), - "resource file with dir not found:" + expectedResourceWDirFile); + assertTrue(expectedResourceWDirFile.exists(), "resource file with dir not found:" + expectedResourceWDirFile); // validate filtered file content = FileUtils.fileRead(expectedResourceWDirFile); @@ -264,8 +264,12 @@ public void testExplodedWarWithResourceFiltering(WarExplodedMojo mojo) throws Ex expectedResourceWDirFile.delete(); } - - private void configureMojo(WarExplodedMojo mojo, File classesDir, File webAppSource, File webAppDirectory, MavenProjectBasicStub project) { + private void configureMojo( + WarExplodedMojo mojo, + File classesDir, + File webAppSource, + File webAppDirectory, + MavenProjectBasicStub project) { mojo.setClassesDirectory(classesDir); mojo.setWarSourceDirectory(webAppSource); mojo.setWebappDirectory(webAppDirectory); @@ -343,5 +347,4 @@ protected void createFile(File testFile, String body) throws Exception { protected void createFile(File testFile) throws Exception { createFile(testFile, testFile.toString()); } - } diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index e7bd7271..32db3485 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -133,7 +133,9 @@ public void testSimpleExplodedWarWTargetPath(WarExplodedMojo mojo) throws Except expectedWebResourceFile.delete(); } - private void configureMojo(WarExplodedMojo mojo, File classesDir, File webAppSource, File webAppDirectory, ResourceStub[] resources) throws Exception { + private void configureMojo( + WarExplodedMojo mojo, File classesDir, File webAppSource, File webAppDirectory, ResourceStub[] resources) + throws Exception { configureMojo(mojo, classesDir, webAppSource, webAppDirectory); mojo.setWebResources(resources); } @@ -377,7 +379,7 @@ public void testExplodedWarWithEJBClient(WarExplodedMojo mojo) throws Exception EJBClientArtifactStub ejbArtifact = new EJBClientArtifactStub(getBasedir()); // configure mojo - configureMojo(mojo,ejbArtifact, classesDir, webAppSource, webAppDirectory); + configureMojo(mojo, ejbArtifact, classesDir, webAppSource, webAppDirectory); mojo.execute(); // validate operation @@ -410,7 +412,7 @@ public void testExplodedWarWithTLD(WarExplodedMojo mojo) throws Exception { TLDArtifactStub tldArtifact = new TLDArtifactStub(getBasedir()); // configure mojo - configureMojo(mojo,tldArtifact, classesDir, webAppSource, webAppDirectory); + configureMojo(mojo, tldArtifact, classesDir, webAppSource, webAppDirectory); mojo.execute(); // validate operation @@ -465,7 +467,6 @@ public void testExplodedWarWithPAR(WarExplodedMojo mojo) throws Exception { public void testExplodedWarWithAar(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "ExplodedWarWithAar"; - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); File webAppDirectory = new File(getTestDirectory(), testId); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); @@ -503,7 +504,7 @@ public void testExplodedWarWithMar(WarExplodedMojo mojo) throws Exception { ArtifactStub marArtifact = new MarArtifactStub(getBasedir(), artifactHandler); // configure mojo - configureMojo(mojo,marArtifact, classesDir, webAppSource, webAppDirectory); + configureMojo(mojo, marArtifact, classesDir, webAppSource, webAppDirectory); mojo.execute(); // validate operation @@ -534,7 +535,7 @@ public void testExplodedWarWithXar(WarExplodedMojo mojo) throws Exception { ArtifactStub xarArtifact = new XarArtifactStub(getBasedir(), artifactHandler); // configure mojo - configureMojo(mojo, xarArtifact,classesDir, webAppSource, webAppDirectory); + configureMojo(mojo, xarArtifact, classesDir, webAppSource, webAppDirectory); mojo.execute(); // validate operation @@ -862,25 +863,28 @@ public void testExplodedWarWithOutputFileNameMappingAndDuplicateDependencies(War expectedEJBDupArtifact.delete(); } - private void configureMojo(WarExplodedMojo mojo, File classesDir, File webAppSource, File webAppDirectory) throws Exception { + private void configureMojo(WarExplodedMojo mojo, File classesDir, File webAppSource, File webAppDirectory) + throws Exception { MavenProjectBasicStub project = new MavenProjectBasicStub(); - configureMojo(mojo,classesDir,webAppSource,webAppDirectory, project); + configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); } - private void configureMojo(WarExplodedMojo mojo, ArtifactStub artifact, File classesDir, File webAppSource, File webAppDirectory) throws Exception { + private void configureMojo( + WarExplodedMojo mojo, ArtifactStub artifact, File classesDir, File webAppSource, File webAppDirectory) + throws Exception { MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); project.addArtifact(artifact); configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); } - private void configureMojo(WarExplodedMojo mojo, File classesDir, File webAppSource, File webAppDirectory, MavenProject project) { + private void configureMojo( + WarExplodedMojo mojo, File classesDir, File webAppSource, File webAppDirectory, MavenProject project) { mojo.setClassesDirectory(classesDir); mojo.setWarSourceDirectory(webAppSource); mojo.setWebappDirectory(webAppDirectory); mojo.setProject(project); } - /** * create an isolated xml dir * From 3118afdbc7af35684baf581a004c82e4578fafa5 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Tue, 25 Nov 2025 16:40:25 +0100 Subject: [PATCH 16/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarExplodedMojoFilteringTest --- .../war/WarExplodedMojoFilteringTest.java | 220 +++++------------- .../classes/sample-servlet.clazz | 1 + .../filters/filter.properties | 2 + .../custom-config/custom-setting.cfg | 11 + .../resources/custom-setting.cfg | 11 + .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + .../classes/sample-servlet.clazz | 1 + .../custom-config/custom-setting.cfg | 9 + .../resources/custom-setting.cfg | 9 + .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + 12 files changed, 105 insertions(+), 163 deletions(-) create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/classes/sample-servlet.clazz create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/filters/filter.properties create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/resources/custom-config/custom-setting.cfg create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/resources/custom-setting.cfg create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/source/pansit.jsp create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/classes/sample-servlet.clazz create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/resources/custom-config/custom-setting.cfg create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/resources/custom-setting.cfg create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/source/pansit.jsp diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java index 5ab68221..6f1bab6d 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java @@ -37,25 +37,25 @@ * under the License. */ -import javax.inject.Inject; - -import java.io.BufferedReader; -import java.io.File; -import java.io.StringReader; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; - import org.apache.maven.api.di.Provides; +import org.apache.maven.api.plugin.testing.Basedir; 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.execution.MavenSession; import org.apache.maven.plugins.war.stub.MavenProjectBasicStub; import org.apache.maven.plugins.war.stub.ResourceStub; +import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.FileUtils; import org.junit.jupiter.api.Test; -import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir; +import javax.inject.Inject; +import java.io.BufferedReader; +import java.io.File; +import java.io.StringReader; +import java.util.Properties; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.when; @@ -68,73 +68,43 @@ public class WarExplodedMojoFilteringTest { @Inject - private List filters; + private MavenProject project; @Inject private MavenSession mavenSession; - protected File getTestDirectory() { - return new File(getBasedir(), "target/test-classes/unit/warexplodedmojo/test-dir"); - } - @Provides - List filters() { - List filtersList = new ArrayList<>(); - filtersList.add("test-filter"); // only for demo, it is temporary - return filtersList; + MavenProject project() throws Exception { + MavenProjectBasicStub project = new MavenProjectBasicStub(); + project.addProperty("is_this_simple", "i_think_so"); + return project; } + @SuppressWarnings("checkstyle:MethodLength") - @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @InjectMojo(goal = "exploded", pom = "plugin-config.xml") + @Basedir("src/test/resources/unit/warexplodedmojo/") + @MojoParameter(name = "classesDirectory", value ="target/test-classes/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/classes/" ) + @MojoParameter(name = "warSourceDirectory", value ="target/test-classes/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/source/" ) + @MojoParameter(name = "webappDirectory", value ="target/test-classes/unit/warexplodedmojo/ExplodedWarWithResourceFiltering" ) + @MojoParameter(name = "outdatedCheckPath", value ="WEB-INF/lib/" ) @Test public void testExplodedWarWithResourceFiltering(WarExplodedMojo mojo) throws Exception { - // setup test data - String testId = "ExplodedWarWithResourceFiltering"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, false); - File webAppResource = new File(getTestDirectory(), testId + "-test-data/resources"); - File sampleResource = new File(webAppResource, "custom-setting.cfg"); - File sampleResourceWDir = new File(webAppResource, "custom-config/custom-setting.cfg"); - - createFile(sampleResource); - createFile(sampleResourceWDir); - - String ls = System.getProperty("line.separator"); - final String comment = "# this is comment created by author@somewhere@"; - // prepare web resources - String content = comment + ls; - content += "system_key_1=${user.dir}" + ls; - content += "system_key_2=@user.dir@" + ls; - content += "project_key_1=${is_this_simple}" + ls; - content += "project_key_2=@is_this_simple@" + ls; - content += "project_name_1=${project.name}" + ls; - content += "project_name_2=@project.name@" + ls; - content += "system_property_1=${system.property}" + ls; - content += "system_property_2=@system.property@" + ls; - FileUtils.fileWrite(sampleResourceWDir.getAbsolutePath(), content); - FileUtils.fileWrite(sampleResource.getAbsolutePath(), content); - Properties systemProperties = System.getProperties(); systemProperties.put("system.property", "system-property-value"); when(mavenSession.getSystemProperties()).thenReturn(systemProperties); - // configure mojo - MavenProjectBasicStub project = new MavenProjectBasicStub(); - project.addProperty("is_this_simple", "i_think_so"); ResourceStub[] resources = new ResourceStub[] {new ResourceStub()}; - resources[0].setDirectory(webAppResource.getAbsolutePath()); + resources[0].setDirectory(MojoExtension.getBasedir() + "/ExplodedWarWithResourceFiltering-test-data/resources/"); resources[0].setFiltering(true); - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); mojo.setWebResources(resources); - mojo.execute(); // validate operation - File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); - File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); - File expectedResourceFile = new File(webAppDirectory, "custom-setting.cfg"); - File expectedResourceWDirFile = new File(webAppDirectory, "custom-config/custom-setting.cfg"); + File expectedWebSourceFile = new File(mojo.getWebappDirectory(), "pansit.jsp"); + File expectedWebSource2File = new File(mojo.getWebappDirectory(), "org/web/app/last-exile.jsp"); + File expectedResourceFile = new File(mojo.getWebappDirectory(), "custom-setting.cfg"); + File expectedResourceWDirFile = new File(mojo.getWebappDirectory(), "custom-config/custom-setting.cfg"); assertTrue(expectedWebSourceFile.exists(), "source files not found: " + expectedWebSourceFile); assertTrue(expectedWebSource2File.exists(), "source files not found: " + expectedWebSource2File); @@ -142,9 +112,9 @@ public void testExplodedWarWithResourceFiltering(WarExplodedMojo mojo) throws Ex assertTrue(expectedResourceWDirFile.exists(), "resource file with dir not found:" + expectedResourceWDirFile); // validate filtered file - content = FileUtils.fileRead(expectedResourceWDirFile); + String content = FileUtils.fileRead(expectedResourceWDirFile); BufferedReader reader = new BufferedReader(new StringReader(content)); - + final String comment = "# this is comment created by author@somewhere@"; assertEquals(comment, reader.readLine(), "error in filtering using System Properties"); String line = reader.readLine(); @@ -176,8 +146,6 @@ public void testExplodedWarWithResourceFiltering(WarExplodedMojo mojo) throws Ex systemProperties.put("system.property", "new-system-property-value"); when(mavenSession.getSystemProperties()).thenReturn(systemProperties); - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - mojo.execute(); // validate filtered file @@ -209,25 +177,39 @@ public void testExplodedWarWithResourceFiltering(WarExplodedMojo mojo) throws Ex "system_property_2=new-system-property-value", reader.readLine(), "error in filtering using System properties"); + } - // update property, and generate again - File filterFile = new File(getTestDirectory(), testId + "-test-data/filters/filter.properties"); - createFile(filterFile); - filters.add(filterFile.getAbsolutePath()); - content += "resource_key_1=${resource_value_1}\n"; - content += "resource_key_2=@resource_value_2@\n" + content; - FileUtils.fileWrite(sampleResourceWDir.getAbsolutePath(), content); - FileUtils.fileWrite(sampleResource.getAbsolutePath(), content); - String filterContent = "resource_value_1=this_is_filtered\n"; - filterContent += "resource_value_2=this_is_filtered"; - FileUtils.fileWrite(filterFile.getAbsolutePath(), filterContent); + @SuppressWarnings("checkstyle:MethodLength") + @InjectMojo(goal = "exploded", pom = "plugin-config.xml") + @Basedir("src/test/resources/unit/warexplodedmojo/") + @MojoParameter(name = "classesDirectory", value ="target/test-classes/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/classes/" ) + @MojoParameter(name = "warSourceDirectory", value ="target/test-classes/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/source/" ) + @MojoParameter(name = "webappDirectory", value ="target/test-classes/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering" ) + @MojoParameter(name = "outdatedCheckPath", value ="WEB-INF/lib/" ) + @MojoParameter(name="filters", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/filters/filter.properties") + @Test + public void testExplodedWarWithResourceFileFiltering(WarExplodedMojo mojo) throws Exception { + Properties systemProperties = System.getProperties(); + systemProperties.put("system.property", "system-property-value"); + when(mavenSession.getSystemProperties()).thenReturn(systemProperties); + + ResourceStub[] resources = new ResourceStub[] {new ResourceStub()}; + resources[0].setDirectory(MojoExtension.getBasedir() + "/ExplodedWarWithResourceFileFiltering-test-data/resources/"); + resources[0].setFiltering(true); + mojo.setWebResources(resources); mojo.execute(); + File expectedResourceWDirFile = new File(mojo.getWebappDirectory(), "custom-config/custom-setting.cfg"); + assertTrue(expectedResourceWDirFile.exists(), "resource file with dir not found:" + expectedResourceWDirFile); + + // validate filtered file + String content = FileUtils.fileRead(expectedResourceWDirFile); content = FileUtils.fileRead(expectedResourceWDirFile); - reader = new BufferedReader(new StringReader(content)); + BufferedReader reader = new BufferedReader(new StringReader(content)); + final String comment = "# this is comment created by author@somewhere@"; assertEquals(comment, reader.readLine(), "error in filtering using System Properties"); assertEquals( @@ -246,105 +228,17 @@ public void testExplodedWarWithResourceFiltering(WarExplodedMojo mojo) throws Ex assertEquals("project_name_2=Test Project ", reader.readLine(), "error in filtering using project properties"); assertEquals( - "system_property_1=new-system-property-value", + "system_property_1=system-property-value", reader.readLine(), "error in filtering using System properties"); assertEquals( - "system_property_2=new-system-property-value", + "system_property_2=system-property-value", reader.readLine(), "error in filtering using System properties"); assertEquals("resource_key_1=this_is_filtered", reader.readLine(), "error in filtering using filter files"); assertEquals("resource_key_2=this_is_filtered", reader.readLine(), "error in filtering using filter files"); - - // house keeping - expectedWebSourceFile.delete(); - expectedWebSource2File.delete(); - expectedResourceFile.delete(); - expectedResourceWDirFile.delete(); - } - - private void configureMojo( - WarExplodedMojo mojo, - File classesDir, - File webAppSource, - File webAppDirectory, - MavenProjectBasicStub project) { - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); } - /** - * Returns the webapp source directory for the specified id. - * - * @param id the id of the test - * @return the source directory for that test - * @throws Exception if an exception occurs - */ - protected File getWebAppSource(String id) throws Exception { - return new File(getTestDirectory(), "/" + id + "-test-data/source"); - } - - /** - * create an isolated web source with a sample jsp file - * - * @param id The id. - * @param createSamples Create example files yes or no. - * @return The created file. - * @throws Exception in case of errors. - */ - protected File createWebAppSource(String id, boolean createSamples) throws Exception { - File webAppSource = getWebAppSource(id); - if (createSamples) { - File simpleJSP = new File(webAppSource, "pansit.jsp"); - File jspFile = new File(webAppSource, "org/web/app/last-exile.jsp"); - - createFile(simpleJSP); - createFile(jspFile); - } - return webAppSource; - } - - protected File createWebAppSource(String id) throws Exception { - return createWebAppSource(id, true); - } - - /** - * create a class directory with or without a sample class - * - * @param id The id. - * @param empty true to create a class files false otherwise. - * @return The created class file. - * @throws Exception in case of errors. - */ - protected File createClassesDir(String id, boolean empty) throws Exception { - File classesDir = new File(getTestDirectory() + "/" + id + "-test-data/classes/"); - - createDir(classesDir); - - if (!empty) { - createFile(new File(classesDir + "/sample-servlet.clazz")); - } - return classesDir; - } - - protected void createDir(File dir) { - if (!dir.exists()) { - assertTrue(dir.mkdirs(), "can not create test dir: " + dir); - } - } - - protected void createFile(File testFile, String body) throws Exception { - createDir(testFile.getParentFile()); - FileUtils.fileWrite(testFile.toString(), body); - - assertTrue(testFile.exists(), "could not create file: " + testFile); - } - - protected void createFile(File testFile) throws Exception { - createFile(testFile, testFile.toString()); - } } diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/classes/sample-servlet.clazz b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/classes/sample-servlet.clazz new file mode 100644 index 00000000..3f0cdff4 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/classes/sample-servlet.clazz @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithResourceFiltering-test-data/classes/sample-servlet.clazz \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/filters/filter.properties b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/filters/filter.properties new file mode 100644 index 00000000..98329225 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/filters/filter.properties @@ -0,0 +1,2 @@ +resource_value_1=this_is_filtered +resource_value_2=this_is_filtered \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/resources/custom-config/custom-setting.cfg b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/resources/custom-config/custom-setting.cfg new file mode 100644 index 00000000..032d0e8d --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/resources/custom-config/custom-setting.cfg @@ -0,0 +1,11 @@ +# this is comment created by author@somewhere@ +system_key_1=${user.dir} +system_key_2=@user.dir@ +project_key_1=${is_this_simple} +project_key_2=@is_this_simple@ +project_name_1=${project.name} +project_name_2=@project.name@ +system_property_1=${system.property} +system_property_2=@system.property@ +resource_key_1=${resource_value_1} +resource_key_2=@resource_value_2@ diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/resources/custom-setting.cfg b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/resources/custom-setting.cfg new file mode 100644 index 00000000..2dff87b3 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/resources/custom-setting.cfg @@ -0,0 +1,11 @@ +# this is comment created by author@somewhere@ +system_key_1=${user.dir} +system_key_2=@user.dir@ +project_key_1=${is_this_simple} +project_key_2=@is_this_simple@ +project_name_1=${project.name} +project_name_2=@project.name@ +system_property_1=${system.property} +system_property_2=@system.property@ +resource_key_1=${resource_value_1} +resource_key_2=@resource_value_2@ \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..ddb271bd --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithResourceFiltering-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/source/pansit.jsp new file mode 100644 index 00000000..9fe68751 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/source/pansit.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithResourceFiltering-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/classes/sample-servlet.clazz b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/classes/sample-servlet.clazz new file mode 100644 index 00000000..3f0cdff4 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/classes/sample-servlet.clazz @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithResourceFiltering-test-data/classes/sample-servlet.clazz \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/resources/custom-config/custom-setting.cfg b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/resources/custom-config/custom-setting.cfg new file mode 100644 index 00000000..df8f4150 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/resources/custom-config/custom-setting.cfg @@ -0,0 +1,9 @@ +# this is comment created by author@somewhere@ +system_key_1=${user.dir} +system_key_2=@user.dir@ +project_key_1=${is_this_simple} +project_key_2=@is_this_simple@ +project_name_1=${project.name} +project_name_2=@project.name@ +system_property_1=${system.property} +system_property_2=@system.property@ diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/resources/custom-setting.cfg b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/resources/custom-setting.cfg new file mode 100644 index 00000000..df8f4150 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/resources/custom-setting.cfg @@ -0,0 +1,9 @@ +# this is comment created by author@somewhere@ +system_key_1=${user.dir} +system_key_2=@user.dir@ +project_key_1=${is_this_simple} +project_key_2=@is_this_simple@ +project_name_1=${project.name} +project_name_2=@project.name@ +system_property_1=${system.property} +system_property_2=@system.property@ diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..ddb271bd --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithResourceFiltering-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/source/pansit.jsp new file mode 100644 index 00000000..9fe68751 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/source/pansit.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithResourceFiltering-test-data/source/pansit.jsp \ No newline at end of file From 1ddfb0398acbf3eb7bdfd4904affbd85dfb944d7 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 26 Nov 2025 08:49:44 +0100 Subject: [PATCH 17/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarOverlaysTest --- .../maven/plugins/war/WarOverlaysTest.java | 86 ++++++++++--------- .../source/org/web/app/last-exile.jsp | 1 + .../no-overlay-test-data/source/pansit.jsp | 1 + .../no-overlay-test-data/xml-config/web.xml | 1 + 4 files changed, 50 insertions(+), 39 deletions(-) create mode 100644 src/test/resources/unit/waroverlays/no-overlay-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/waroverlays/no-overlay-test-data/source/pansit.jsp create mode 100644 src/test/resources/unit/waroverlays/no-overlay-test-data/xml-config/web.xml diff --git a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java index 4126c190..591931a0 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java @@ -27,6 +27,7 @@ import java.util.LinkedList; import java.util.List; +import org.apache.maven.api.di.Provides; import org.apache.maven.api.plugin.testing.InjectMojo; import org.apache.maven.api.plugin.testing.MojoParameter; import org.apache.maven.api.plugin.testing.MojoTest; @@ -34,13 +35,17 @@ import org.apache.maven.plugins.war.overlay.DefaultOverlay; import org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub; import org.apache.maven.plugins.war.stub.WarOverlayStub; +import org.apache.maven.project.MavenProject; import org.codehaus.plexus.archiver.ArchiverException; import org.codehaus.plexus.archiver.jar.JarArchiver; import org.codehaus.plexus.util.FileUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import javax.inject.Inject; + import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir; +import static org.apache.maven.api.plugin.testing.MojoExtension.getVariableValueFromObject; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -51,15 +56,23 @@ @MojoTest public class WarOverlaysTest { - private static final File OVERLAYS_TEMP_DIR = new File(getBasedir(), "target/test-overlays/"); + private static final File OVERLAYS_TEMP_DIR = new File(getBasedir(), "target/test-classes/unit/waroverlays/test-overlays/"); private static final File OVERLAYS_ROOT_DIR = new File(getBasedir(), "target/test-classes/overlays/"); private static final String MANIFEST_PATH = "META-INF" + File.separator + "MANIFEST.MF"; + @Inject + private MavenProject project; + + @Provides + MavenProject project() throws Exception { + return new MavenProjectArtifactsStub(); + } + @BeforeEach public void setUp() throws Exception { - generateFullOverlayWar("overlay-full-1"); - generateFullOverlayWar("overlay-full-2"); - generateFullOverlayWar("overlay-full-3"); +// generateFullOverlayWar("overlay-full-1"); +// generateFullOverlayWar("overlay-full-2"); +// generateFullOverlayWar("overlay-full-3"); } private File getTestDirectory() { @@ -68,22 +81,17 @@ private File getTestDirectory() { @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/waroverlays/default.xml") @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-no-overlay") + @MojoParameter(name = "classesDirectory", value = "target/test-classes/unit/waroverlays/no-overlay-test-data/classes") + @MojoParameter(name = "warSourceDirectory", value ="target/test-classes/unit/waroverlays/no-overlay-test-data/source/" ) + @MojoParameter(name = "webappDirectory", value ="target/test-classes/unit/waroverlays/no-overlay" ) + @MojoParameter(name = "webXml", value ="target/test-classes/unit/waroverlays/no-overlay-test-data/xml-config/web.xml" ) @Test public void testNoOverlay(WarExplodedMojo mojo) throws Exception { - // setup test data - final String testId = "no-overlay"; - final File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - final File webAppDirectory = new File(getTestDirectory(), testId); - final File classesDir = createClassesDir(testId, true); - File webAppSource = createWebAppSource(testId); - - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, xmlSource); - mojo.execute(); // Validate content of the webapp - assertDefaultContent(webAppDirectory); - assertWebXml(webAppDirectory); + assertDefaultContent((File) getVariableValueFromObject(mojo, "webappDirectory")); + assertWebXml((File) getVariableValueFromObject(mojo, "webappDirectory")); } @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/waroverlays/default.xml") @@ -668,6 +676,30 @@ private void assertWebAppContent(File webAppDirectory, List expectedFiles, + webAppContent.size() + " file(s) " + webAppContent); } + /** + * create an isolated xml dir + * + * @param id The id. + * @param xmlFiles array of xml files. + * @return The created file. + * @throws Exception in case of errors. + */ + private File createXMLConfigDir(String id, String[] xmlFiles) throws Exception { + File xmlConfigDir = new File(getTestDirectory(), "/" + id + "-test-data/xml-config"); + File xmlFile; + + createDir(xmlConfigDir); + + if (xmlFiles != null) { + for (String o : xmlFiles) { + xmlFile = new File(xmlConfigDir, o); + createFile(xmlFile); + } + } + + return xmlConfigDir; + } + /** * Builds the list of files and directories from the specified dir. * @@ -694,30 +726,6 @@ private void buildFilesList(final File dir, FileFilter filter, final List } } - /** - * create an isolated xml dir - * - * @param id The id. - * @param xmlFiles array of xml files. - * @return The created file. - * @throws Exception in case of errors. - */ - private File createXMLConfigDir(String id, String[] xmlFiles) throws Exception { - File xmlConfigDir = new File(getTestDirectory(), "/" + id + "-test-data/xml-config"); - File xmlFile; - - createDir(xmlConfigDir); - - if (xmlFiles != null) { - for (String o : xmlFiles) { - xmlFile = new File(xmlConfigDir, o); - createFile(xmlFile); - } - } - - return xmlConfigDir; - } - /** * Returns the webapp source directory for the specified id. * diff --git a/src/test/resources/unit/waroverlays/no-overlay-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/waroverlays/no-overlay-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..d2169459 --- /dev/null +++ b/src/test/resources/unit/waroverlays/no-overlay-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/waroverlays/no-overlay-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/no-overlay-test-data/source/pansit.jsp b/src/test/resources/unit/waroverlays/no-overlay-test-data/source/pansit.jsp new file mode 100644 index 00000000..80f13df2 --- /dev/null +++ b/src/test/resources/unit/waroverlays/no-overlay-test-data/source/pansit.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/waroverlays/no-overlay-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/no-overlay-test-data/xml-config/web.xml b/src/test/resources/unit/waroverlays/no-overlay-test-data/xml-config/web.xml new file mode 100644 index 00000000..a99b1d46 --- /dev/null +++ b/src/test/resources/unit/waroverlays/no-overlay-test-data/xml-config/web.xml @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/waroverlays/no-overlay-test-data/xml-config/web.xml \ No newline at end of file From eb2e38672de4a873775400bcc0771beb3b16cd1b Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 26 Nov 2025 10:31:10 +0100 Subject: [PATCH 18/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarOverlaysTest --- .../maven/plugins/war/WarOverlaysTest.java | 27 +++++++++--------- .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + .../waroverlays/test-overlays/overlay-one.war | Bin 0 -> 2116 bytes 4 files changed, 15 insertions(+), 14 deletions(-) create mode 100644 src/test/resources/unit/waroverlays/default-overlay-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/waroverlays/default-overlay-test-data/source/pansit.jsp create mode 100644 src/test/resources/unit/waroverlays/test-overlays/overlay-one.war diff --git a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java index 591931a0..0d660a79 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java @@ -27,8 +27,8 @@ import java.util.LinkedList; import java.util.List; -import org.apache.maven.api.di.Provides; 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.plugin.testing.stubs.ArtifactStub; @@ -60,13 +60,7 @@ public class WarOverlaysTest { private static final File OVERLAYS_ROOT_DIR = new File(getBasedir(), "target/test-classes/overlays/"); private static final String MANIFEST_PATH = "META-INF" + File.separator + "MANIFEST.MF"; - @Inject - private MavenProject project; - @Provides - MavenProject project() throws Exception { - return new MavenProjectArtifactsStub(); - } @BeforeEach public void setUp() throws Exception { @@ -87,6 +81,7 @@ private File getTestDirectory() { @MojoParameter(name = "webXml", value ="target/test-classes/unit/waroverlays/no-overlay-test-data/xml-config/web.xml" ) @Test public void testNoOverlay(WarExplodedMojo mojo) throws Exception { + mojo.setProject(new MavenProjectArtifactsStub()); mojo.execute(); // Validate content of the webapp @@ -96,22 +91,26 @@ public void testNoOverlay(WarExplodedMojo mojo) throws Exception { @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/waroverlays/default.xml") @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-default-overlay") + @MojoParameter(name = "classesDirectory", value = "target/test-classes/unit/waroverlays/default-overlay-test-data/classes") + @MojoParameter(name = "warSourceDirectory", value ="target/test-classes/unit/waroverlays/default-overlay-test-data/source/" ) + @MojoParameter(name = "webappDirectory", value ="target/test-classes/unit/waroverlays/default-overlay" ) @Test public void testDefaultOverlay(WarExplodedMojo mojo) throws Exception { - // setup test data - final String testId = "default-overlay"; - final File classesDir = createClassesDir(testId, true); - final File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); + // Create war file + final File destFile = new File(OVERLAYS_TEMP_DIR, "overlay-one" + ".war"); + if (!destFile.exists()) { + createArchive(new File(OVERLAYS_ROOT_DIR, "overlay-one"), destFile); + } - final ArtifactStub overlay = buildWarOverlayStub("overlay-one"); + final ArtifactStub overlay = new WarOverlayStub(MojoExtension.getBasedir(), "overlay-one", destFile); final MavenProjectArtifactsStub project = createProjectWithOverlays(overlay); - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + mojo.setProject(project); mojo.execute(); final List assertedFiles = new ArrayList<>(); + File webAppDirectory = (File) getVariableValueFromObject(mojo, "webappDirectory"); assertedFiles.addAll(assertDefaultContent(webAppDirectory)); assertedFiles.addAll(assertWebXml(webAppDirectory)); assertedFiles.addAll(assertCustomContent( diff --git a/src/test/resources/unit/waroverlays/default-overlay-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/waroverlays/default-overlay-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..a30c88c8 --- /dev/null +++ b/src/test/resources/unit/waroverlays/default-overlay-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/waroverlays/default-overlay-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/default-overlay-test-data/source/pansit.jsp b/src/test/resources/unit/waroverlays/default-overlay-test-data/source/pansit.jsp new file mode 100644 index 00000000..e3d61edd --- /dev/null +++ b/src/test/resources/unit/waroverlays/default-overlay-test-data/source/pansit.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/waroverlays/default-overlay-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/test-overlays/overlay-one.war b/src/test/resources/unit/waroverlays/test-overlays/overlay-one.war new file mode 100644 index 0000000000000000000000000000000000000000..070d1bd3fa75d7979bb49a1c6a1844a790f54660 GIT binary patch literal 2116 zcmWIWW@h1HVBlb2cxhD?&42_rfoxyb5Jz24KR5jVpfVAlG7hk^0QC#c?19p@KnxT` zDD!pn^K^3!4$<><`|Nw>w2!y0-bG$-U9EFx&TkGfxMKX^X_20nua2kh#nM$DE70*ecS6ToH^|_kvB?GFXHOqJWnutX2yxdlGEPp^0}u9DrpLMU5Ubgfd5Px#jt2bkA1 zzP*`da=-38OVpCN44?n}{#_QosKfTO(A2|Rd)V$PEpeOj<-x9Ri#Kqv+ph4cSSfmE z$)5u5FP&mroR;Z+ndRoScF)x32QNF8w=!RhI3hQ-+>pV2&W6v)6K&rtoF==;Yu9Vl zMRH5?GaalXw*KWceb}*TQe#Mof~f45$t-Cb1-DIFr5IGaaZ{%4i@=4YYfX-Xu(1Ex zaH1gmO6P<>v0n^M$6L;2zHvz3iPLQVvGM|E<{abyx9-%{g!DvjxB0*}oBGG$HHwlli2>v#V+ zlYY^~?K<<62?05ii%$Gtt6O68IJ)9&*Yd~SjO$;%obt?d+w%gOgNF_4&vd<+arrvq zr9ZuY&wM(rtFY8r@&mzZ+FY#Nn-ZVMh z_7*=?ykza7Z`CiCw-&y!w>RuwRJ|>`_WoVtZQjeK*CWy)D8lWNIhVfyMz|X^!ZY(y zQY#=49uJIgf%@;ucRX7;)oI1I9j;R&X0ON)oyZh>#hsmRLt4&tv&A*P=W=FFR8x#R z@bmlkZRUYT;#@jUC9=jf=L-rQ_O>dD{oNSdviDu+(Y+VA@+Q~Rvw!IV$9M@i#zmjs zyUbqM$b2v22;bCl=?0m?L+AKhf9+_F@<^FlFx}h5mgD}Vh600(-|Sh39)_wiX--!V zsePfwc_!&_u4;($lC&+0fHCd}jBx`{jQ{+nbvQOa-RYD0tGa3X3#`~TwB2tJ%Bj13 z=ddpChO2+FOTQ=Yy7f_T%C`&Fe-5$!(YRO<RH04v+w(%plQzqcPL7#+E2DP$qtM04Zs+` zb|%(3uI%H~^P$3$v3vneF&jfCInP@EAbryEpHhCAA8RUfA54+y_Y7OITZYfQ!Y0K( zbE2G4)otfVdpE{se%r#fq@;tzzK8dg=K_wCiCb?>)vk_c3urTr=!%+>;%RD|FCg_- zd@a}RgbQVdT0hBTu3qui??+~$%<-h(@TkR8sE~V1ReH_j$EtH zdRf>*MP51ThxE4I%mV52(;sm@mPbtzrS{pmPk~9o8JHyakxGj4)Fi!%+?>=Pc*1xJ zOc*nO31ec$>JEUwnta>V)cTl4rNypV?w|dESJxz=Sa^ev*sLs;(`|rJ5QG zR8HuG{h9bofUSf@`tob3W+SOQqn$fh?ItlV_LN|s`*7l^7Z0xNl@65>J=M+3j}u~7dvxh)oE5*T;b@U{;i{Lp zPnN%*>2Zd%3s3$8My6>kX5Kk7<%jVrj}!m=mhC^Wzo?2cf$w~eP;OmxO{=t=z~%lk7pA7o=4#=!K&d@Bt za9rTccN5vR#Ky%ZS_^%xD!t?_k2tLp7SlR1Iqzh3!I$0PeVgyhXV5*pqTu|aC>e!i zlD8$a)1DnH+_Y;Zw|!~N-J|Jtlhw?sY!7fQ6x;0Mq?cYW{bbC!hpPJZdGoz0PL}On zqw#rb%Uiy8+mAZOJ-glHFMXmb{G+zM+%tzce3LKiE)BHi4l%S`wZ1GhssFUV=?~Mi zN&`frFZuTKIwt>{aJf)iXQ$uKh Date: Wed, 26 Nov 2025 10:38:08 +0100 Subject: [PATCH 19/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarOverlaysTest --- .../maven/plugins/war/WarOverlaysTest.java | 17 ++++++----------- .../waroverlays/test-overlays/overlay-two.war | Bin 0 -> 2119 bytes 2 files changed, 6 insertions(+), 11 deletions(-) create mode 100644 src/test/resources/unit/waroverlays/test-overlays/overlay-two.war diff --git a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java index 0d660a79..557f5e15 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java @@ -35,15 +35,12 @@ import org.apache.maven.plugins.war.overlay.DefaultOverlay; import org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub; import org.apache.maven.plugins.war.stub.WarOverlayStub; -import org.apache.maven.project.MavenProject; import org.codehaus.plexus.archiver.ArchiverException; import org.codehaus.plexus.archiver.jar.JarArchiver; import org.codehaus.plexus.util.FileUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import javax.inject.Inject; - import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir; import static org.apache.maven.api.plugin.testing.MojoExtension.getVariableValueFromObject; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -127,22 +124,20 @@ public void testDefaultOverlay(WarExplodedMojo mojo) throws Exception { @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/waroverlays/default.xml") @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-default-overlays") + @MojoParameter(name = "classesDirectory", value = "target/test-classes/unit/waroverlays/default-overlays-test-data/classes") + @MojoParameter(name = "warSourceDirectory", value ="target/test-classes/unit/waroverlays/default-overlays-test-data/source/" ) + @MojoParameter(name = "webappDirectory", value ="target/test-classes/unit/waroverlays/default-overlays" ) @Test public void testDefaultOverlays(WarExplodedMojo mojo) throws Exception { - // setup test data - final String testId = "default-overlays"; - final File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - final File classesDir = createClassesDir(testId, true); - - final ArtifactStub overlay = buildWarOverlayStub("overlay-one"); + final ArtifactStub overlay = buildWarOverlayStub("overlay-one"); final ArtifactStub overlay2 = buildWarOverlayStub("overlay-two"); final MavenProjectArtifactsStub project = createProjectWithOverlays(overlay, overlay2); - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + mojo.setProject(project); mojo.execute(); + File webAppDirectory = (File) getVariableValueFromObject(mojo, "webappDirectory"); final List assertedFiles = new ArrayList<>(); assertedFiles.addAll(assertDefaultContent(webAppDirectory)); assertedFiles.addAll(assertWebXml(webAppDirectory)); diff --git a/src/test/resources/unit/waroverlays/test-overlays/overlay-two.war b/src/test/resources/unit/waroverlays/test-overlays/overlay-two.war new file mode 100644 index 0000000000000000000000000000000000000000..7da1c1bae00a69ad7ac2a10f64a7fdee76f6bdf2 GIT binary patch literal 2119 zcmZ`)c|2SB7QYc=-)c{r=<*n5ngoxQwmcG*N`j{7BC0`aNkyd9qD}EkYhT6^qf=X% z6pf`y8cS=dQiIwJT6;z7jcSo9&oXnvyz=_#ocp==o_l}i`#I;2@A-a7M5w3~07wA9 z^x^AHz_ySCa~n$s3<__H(%mt1LoVLV%F_y4uq@Sfd0|5XW6aa+NQ|TAn1JM`#818n%^fW!? znosuWQ=AlRzJH}<%9*r$FO@_Q=U$??oXd-WVjtYK6@*gvJ{xQ)ExwlG>zfl<9jTbo zAoWCSbf0E;DtEGK5n3+694?4vW~&T+ySy&v6{E_<=Ay3L!4Zm{sJt2J34Kxr@kP2t zv^($y^|ex-_1<}sa0_2 zfM0)ns`CxLU*Az&DwL&gnwBz|FtvZ_=SgZ!xINiq_c>`}t>@>HRHo4p4LdaC2kpu1 zh**E7RjJY9{ui0Q{hKA1I2Q2`b3{^k@1a6fUw(^*hJ{W83~7lXl(O$+8cD>h$D9f) zcj@$h8a5B77UZwlE=|`PFJ@)Q#^i|ee1f#8hkn1vZZsjybm-g*Pv(`9DN?z*30D8Y z1$P?JcJ+)M%+zgEYBJkms*nb#ZO&WrdFavx5vP*3D$E#?-N^(JASL-VDZvk zy58JaQCW4@x|N^A4n%!ZY*pjk*zhzgogVt*WSy5{Q@u+CTmP`}quo%7!1o<+f(2FWz))N=VTB;us;<PHKfQW{lMtW_D-2S z)0>(8pLmFM@8s$U$5WhSXl13#Qh9Omo|Pj%&&7uD1@Jm}W(Bcy*?kU1uP|?Guk|P& z&CP>mnx_H3SYHyR%T{3_5;87u&|D4{Hv zG*#3|UUog3N-^Qf!`-y{VK=4b@|p7*@HLH;*T_%W=B?_ov#{dl65qWrjH5m)gd?;I z9#?)yg;6>t{*fiEw5u9Dc8e6_xHp?+uyn53u6?|+Fod?-I}q*vIET~v=+-;ASzcd| zW9qBul@7C2Yt=eb)oeE4bSRg$bz_i!Wvg@$s1vm-_D}e|1PBLFp0DVwq*Aoc z&ieGnw{_6M(079#hNHn9qGWaku&}za;!nwmG;RH#Ot5h*!C2MeFC`MUU5k?twCKSpCtO z?1Aw}PEx4Dl|3p5L9(dF!yUXN&R#pehow~0w@yxUx zfs>#sKkJn{xdCJ`VIC6uSbP0Z5KPvW-Pg0}(y!GCx8@m%pP3IgU+Cv-7ZgN@t zWs#=|v3BYBv)VWbYWTt2=%{O4R^dfn8w&B@@lu;-*HK(Ql$AiDC0}k{5({RVymktF z5uNv%2zf9)&6=|0y4$W$#;vu@KS%AkXQ8=7r*+zjxLe5;^c5p# zTwz#PyUTapj!9a5GC3G80fqbh%nz7XM70(_c2UkEb2=~V(u|pzeoPLN=N&XUY``Pt zriPG+5D{hQ-y0h!1z;!u?=ZsmHk%W|{@&<>#lm2RYJ<iab(+e85XH?#&!Kl|Edv(0h8rgmGfE|INfe`(*B;4img3p^zX0H1e+MEpif Pcq9g1WN?Z4H@^M^x&} Date: Wed, 26 Nov 2025 13:58:34 +0100 Subject: [PATCH 20/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarOverlaysTest --- .../maven/plugins/war/WarOverlaysTest.java | 21 ++++++------------ .../overlay-full-1/WEB-INF/classes/a.clazz | 1 + .../overlay-full-1/WEB-INF/classes/b.clazz | 1 + .../overlay-full-1/WEB-INF/classes/c.clazz | 1 + .../overlays/overlay-full-1/WEB-INF/lib/a.jar | 1 + .../overlays/overlay-full-1/WEB-INF/lib/b.jar | 1 + .../overlays/overlay-full-1/WEB-INF/lib/c.jar | 1 + .../overlays/overlay-full-1/WEB-INF/web.xml | 1 + .../overlays/overlay-full-1/jsp/a.jsp | 1 + .../overlays/overlay-full-1/jsp/b.jsp | 1 + .../overlays/overlay-full-1/jsp/c.jsp | 1 + .../overlays/overlay-full-1/jsp/d/a.jsp | 1 + .../overlays/overlay-full-1/jsp/d/b.jsp | 1 + .../overlays/overlay-full-1/jsp/d/c.jsp | 1 + .../overlay-full-2/WEB-INF/classes/a.clazz | 1 + .../overlay-full-2/WEB-INF/classes/b.clazz | 1 + .../overlay-full-2/WEB-INF/classes/c.clazz | 1 + .../overlays/overlay-full-2/WEB-INF/lib/a.jar | 1 + .../overlays/overlay-full-2/WEB-INF/lib/b.jar | 1 + .../overlays/overlay-full-2/WEB-INF/lib/c.jar | 1 + .../overlays/overlay-full-2/WEB-INF/web.xml | 1 + .../overlays/overlay-full-2/jsp/a.jsp | 1 + .../overlays/overlay-full-2/jsp/b.jsp | 1 + .../overlays/overlay-full-2/jsp/c.jsp | 1 + .../overlays/overlay-full-2/jsp/d/a.jsp | 1 + .../overlays/overlay-full-2/jsp/d/b.jsp | 1 + .../overlays/overlay-full-2/jsp/d/c.jsp | 1 + .../overlay-full-3/WEB-INF/classes/a.clazz | 1 + .../overlay-full-3/WEB-INF/classes/b.clazz | 1 + .../overlay-full-3/WEB-INF/classes/c.clazz | 1 + .../overlays/overlay-full-3/WEB-INF/lib/a.jar | 1 + .../overlays/overlay-full-3/WEB-INF/lib/b.jar | 1 + .../overlays/overlay-full-3/WEB-INF/lib/c.jar | 1 + .../overlays/overlay-full-3/WEB-INF/web.xml | 1 + .../overlays/overlay-full-3/jsp/a.jsp | 1 + .../overlays/overlay-full-3/jsp/b.jsp | 1 + .../overlays/overlay-full-3/jsp/c.jsp | 1 + .../overlays/overlay-full-3/jsp/d/a.jsp | 1 + .../overlays/overlay-full-3/jsp/d/b.jsp | 1 + .../overlays/overlay-full-3/jsp/d/c.jsp | 1 + .../test-overlays/overlay-full-1.war | Bin 0 -> 2543 bytes .../test-overlays/overlay-full-2.war | Bin 0 -> 2543 bytes .../test-overlays/overlay-full-3.war | Bin 0 -> 2543 bytes 43 files changed, 46 insertions(+), 14 deletions(-) create mode 100644 src/test/resources/overlays/overlay-full-1/WEB-INF/classes/a.clazz create mode 100644 src/test/resources/overlays/overlay-full-1/WEB-INF/classes/b.clazz create mode 100644 src/test/resources/overlays/overlay-full-1/WEB-INF/classes/c.clazz create mode 100644 src/test/resources/overlays/overlay-full-1/WEB-INF/lib/a.jar create mode 100644 src/test/resources/overlays/overlay-full-1/WEB-INF/lib/b.jar create mode 100644 src/test/resources/overlays/overlay-full-1/WEB-INF/lib/c.jar create mode 100644 src/test/resources/overlays/overlay-full-1/WEB-INF/web.xml create mode 100644 src/test/resources/overlays/overlay-full-1/jsp/a.jsp create mode 100644 src/test/resources/overlays/overlay-full-1/jsp/b.jsp create mode 100644 src/test/resources/overlays/overlay-full-1/jsp/c.jsp create mode 100644 src/test/resources/overlays/overlay-full-1/jsp/d/a.jsp create mode 100644 src/test/resources/overlays/overlay-full-1/jsp/d/b.jsp create mode 100644 src/test/resources/overlays/overlay-full-1/jsp/d/c.jsp create mode 100644 src/test/resources/overlays/overlay-full-2/WEB-INF/classes/a.clazz create mode 100644 src/test/resources/overlays/overlay-full-2/WEB-INF/classes/b.clazz create mode 100644 src/test/resources/overlays/overlay-full-2/WEB-INF/classes/c.clazz create mode 100644 src/test/resources/overlays/overlay-full-2/WEB-INF/lib/a.jar create mode 100644 src/test/resources/overlays/overlay-full-2/WEB-INF/lib/b.jar create mode 100644 src/test/resources/overlays/overlay-full-2/WEB-INF/lib/c.jar create mode 100644 src/test/resources/overlays/overlay-full-2/WEB-INF/web.xml create mode 100644 src/test/resources/overlays/overlay-full-2/jsp/a.jsp create mode 100644 src/test/resources/overlays/overlay-full-2/jsp/b.jsp create mode 100644 src/test/resources/overlays/overlay-full-2/jsp/c.jsp create mode 100644 src/test/resources/overlays/overlay-full-2/jsp/d/a.jsp create mode 100644 src/test/resources/overlays/overlay-full-2/jsp/d/b.jsp create mode 100644 src/test/resources/overlays/overlay-full-2/jsp/d/c.jsp create mode 100644 src/test/resources/overlays/overlay-full-3/WEB-INF/classes/a.clazz create mode 100644 src/test/resources/overlays/overlay-full-3/WEB-INF/classes/b.clazz create mode 100644 src/test/resources/overlays/overlay-full-3/WEB-INF/classes/c.clazz create mode 100644 src/test/resources/overlays/overlay-full-3/WEB-INF/lib/a.jar create mode 100644 src/test/resources/overlays/overlay-full-3/WEB-INF/lib/b.jar create mode 100644 src/test/resources/overlays/overlay-full-3/WEB-INF/lib/c.jar create mode 100644 src/test/resources/overlays/overlay-full-3/WEB-INF/web.xml create mode 100644 src/test/resources/overlays/overlay-full-3/jsp/a.jsp create mode 100644 src/test/resources/overlays/overlay-full-3/jsp/b.jsp create mode 100644 src/test/resources/overlays/overlay-full-3/jsp/c.jsp create mode 100644 src/test/resources/overlays/overlay-full-3/jsp/d/a.jsp create mode 100644 src/test/resources/overlays/overlay-full-3/jsp/d/b.jsp create mode 100644 src/test/resources/overlays/overlay-full-3/jsp/d/c.jsp create mode 100644 src/test/resources/unit/waroverlays/test-overlays/overlay-full-1.war create mode 100644 src/test/resources/unit/waroverlays/test-overlays/overlay-full-2.war create mode 100644 src/test/resources/unit/waroverlays/test-overlays/overlay-full-3.war diff --git a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java index 557f5e15..0cc7470e 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java @@ -168,19 +168,11 @@ public void testDefaultOverlays(WarExplodedMojo mojo) throws Exception { @MojoParameter( name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-scenario-one-default-settings") + @MojoParameter(name = "classesDirectory", value = "target/test-classes/unit/waroverlays/scenario-one-default-settings-test-data/classes") + @MojoParameter(name = "warSourceDirectory", value ="target/test-classes/unit/waroverlays/scenario-one-default-settings-test-data/source/" ) + @MojoParameter(name = "webappDirectory", value ="target/test-classes/unit/waroverlays/scenario-one-default-settings" ) @Test public void testScenarioOneWithDefaulSettings(WarExplodedMojo mojo) throws Exception { - // setup test data - final String testId = "scenario-one-default-settings"; - final File classesDir = createClassesDir(testId, true); - final File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId, false); - String[] sourceFiles = new String[] {"org/sample/company/test.jsp", "jsp/b.jsp"}; - for (String sourceFile : sourceFiles) { - File sample = new File(webAppSource, sourceFile); - createFile(sample); - } - // Add an overlay final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); @@ -188,11 +180,12 @@ public void testScenarioOneWithDefaulSettings(WarExplodedMojo mojo) throws Excep final MavenProjectArtifactsStub project = createProjectWithOverlays(overlay1, overlay2, overlay3); - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + mojo.setProject(project); mojo.execute(); - assertScenariOne(testId, webAppDirectory); + File webAppDirectory = (File) getVariableValueFromObject(mojo, "webappDirectory"); + assertScenariOne("scenario-one-default-settings", webAppDirectory); } /** @@ -225,6 +218,7 @@ public void testScenarioOneWithOverlaySettings(WarExplodedMojo mojo) throws Exce final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); final MavenProjectArtifactsStub project = createProjectWithOverlays(overlay1, overlay2, overlay3); + mojo.setProject(project); // Add the tags final List overlays = new ArrayList<>(); @@ -233,7 +227,6 @@ public void testScenarioOneWithOverlaySettings(WarExplodedMojo mojo) throws Exce overlays.add(new DefaultOverlay(overlay3)); mojo.setOverlays(overlays); - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); mojo.execute(); diff --git a/src/test/resources/overlays/overlay-full-1/WEB-INF/classes/a.clazz b/src/test/resources/overlays/overlay-full-1/WEB-INF/classes/a.clazz new file mode 100644 index 00000000..833a1f77 --- /dev/null +++ b/src/test/resources/overlays/overlay-full-1/WEB-INF/classes/a.clazz @@ -0,0 +1 @@ +overlay-full-1-WEB-INF/classes/a.clazz \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-1/WEB-INF/classes/b.clazz b/src/test/resources/overlays/overlay-full-1/WEB-INF/classes/b.clazz new file mode 100644 index 00000000..8abf8486 --- /dev/null +++ b/src/test/resources/overlays/overlay-full-1/WEB-INF/classes/b.clazz @@ -0,0 +1 @@ +overlay-full-1-WEB-INF/classes/b.clazz \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-1/WEB-INF/classes/c.clazz b/src/test/resources/overlays/overlay-full-1/WEB-INF/classes/c.clazz new file mode 100644 index 00000000..72edfee9 --- /dev/null +++ b/src/test/resources/overlays/overlay-full-1/WEB-INF/classes/c.clazz @@ -0,0 +1 @@ +overlay-full-1-WEB-INF/classes/c.clazz \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-1/WEB-INF/lib/a.jar b/src/test/resources/overlays/overlay-full-1/WEB-INF/lib/a.jar new file mode 100644 index 00000000..6c817050 --- /dev/null +++ b/src/test/resources/overlays/overlay-full-1/WEB-INF/lib/a.jar @@ -0,0 +1 @@ +overlay-full-1-WEB-INF/lib/a.jar \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-1/WEB-INF/lib/b.jar b/src/test/resources/overlays/overlay-full-1/WEB-INF/lib/b.jar new file mode 100644 index 00000000..ab750a03 --- /dev/null +++ b/src/test/resources/overlays/overlay-full-1/WEB-INF/lib/b.jar @@ -0,0 +1 @@ +overlay-full-1-WEB-INF/lib/b.jar \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-1/WEB-INF/lib/c.jar b/src/test/resources/overlays/overlay-full-1/WEB-INF/lib/c.jar new file mode 100644 index 00000000..84171a8c --- /dev/null +++ b/src/test/resources/overlays/overlay-full-1/WEB-INF/lib/c.jar @@ -0,0 +1 @@ +overlay-full-1-WEB-INF/lib/c.jar \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-1/WEB-INF/web.xml b/src/test/resources/overlays/overlay-full-1/WEB-INF/web.xml new file mode 100644 index 00000000..4ad46bcc --- /dev/null +++ b/src/test/resources/overlays/overlay-full-1/WEB-INF/web.xml @@ -0,0 +1 @@ +overlay-full-1-WEB-INF/web.xml \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-1/jsp/a.jsp b/src/test/resources/overlays/overlay-full-1/jsp/a.jsp new file mode 100644 index 00000000..ef0c4af6 --- /dev/null +++ b/src/test/resources/overlays/overlay-full-1/jsp/a.jsp @@ -0,0 +1 @@ +overlay-full-1-jsp/a.jsp \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-1/jsp/b.jsp b/src/test/resources/overlays/overlay-full-1/jsp/b.jsp new file mode 100644 index 00000000..f0a05c5c --- /dev/null +++ b/src/test/resources/overlays/overlay-full-1/jsp/b.jsp @@ -0,0 +1 @@ +overlay-full-1-jsp/b.jsp \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-1/jsp/c.jsp b/src/test/resources/overlays/overlay-full-1/jsp/c.jsp new file mode 100644 index 00000000..1347a94c --- /dev/null +++ b/src/test/resources/overlays/overlay-full-1/jsp/c.jsp @@ -0,0 +1 @@ +overlay-full-1-jsp/c.jsp \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-1/jsp/d/a.jsp b/src/test/resources/overlays/overlay-full-1/jsp/d/a.jsp new file mode 100644 index 00000000..da976ba4 --- /dev/null +++ b/src/test/resources/overlays/overlay-full-1/jsp/d/a.jsp @@ -0,0 +1 @@ +overlay-full-1-jsp/d/a.jsp \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-1/jsp/d/b.jsp b/src/test/resources/overlays/overlay-full-1/jsp/d/b.jsp new file mode 100644 index 00000000..7609ccaa --- /dev/null +++ b/src/test/resources/overlays/overlay-full-1/jsp/d/b.jsp @@ -0,0 +1 @@ +overlay-full-1-jsp/d/b.jsp \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-1/jsp/d/c.jsp b/src/test/resources/overlays/overlay-full-1/jsp/d/c.jsp new file mode 100644 index 00000000..49fa1a22 --- /dev/null +++ b/src/test/resources/overlays/overlay-full-1/jsp/d/c.jsp @@ -0,0 +1 @@ +overlay-full-1-jsp/d/c.jsp \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-2/WEB-INF/classes/a.clazz b/src/test/resources/overlays/overlay-full-2/WEB-INF/classes/a.clazz new file mode 100644 index 00000000..77320848 --- /dev/null +++ b/src/test/resources/overlays/overlay-full-2/WEB-INF/classes/a.clazz @@ -0,0 +1 @@ +overlay-full-2-WEB-INF/classes/a.clazz \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-2/WEB-INF/classes/b.clazz b/src/test/resources/overlays/overlay-full-2/WEB-INF/classes/b.clazz new file mode 100644 index 00000000..f2012525 --- /dev/null +++ b/src/test/resources/overlays/overlay-full-2/WEB-INF/classes/b.clazz @@ -0,0 +1 @@ +overlay-full-2-WEB-INF/classes/b.clazz \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-2/WEB-INF/classes/c.clazz b/src/test/resources/overlays/overlay-full-2/WEB-INF/classes/c.clazz new file mode 100644 index 00000000..9d4a0724 --- /dev/null +++ b/src/test/resources/overlays/overlay-full-2/WEB-INF/classes/c.clazz @@ -0,0 +1 @@ +overlay-full-2-WEB-INF/classes/c.clazz \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-2/WEB-INF/lib/a.jar b/src/test/resources/overlays/overlay-full-2/WEB-INF/lib/a.jar new file mode 100644 index 00000000..0778aee3 --- /dev/null +++ b/src/test/resources/overlays/overlay-full-2/WEB-INF/lib/a.jar @@ -0,0 +1 @@ +overlay-full-2-WEB-INF/lib/a.jar \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-2/WEB-INF/lib/b.jar b/src/test/resources/overlays/overlay-full-2/WEB-INF/lib/b.jar new file mode 100644 index 00000000..29721d4a --- /dev/null +++ b/src/test/resources/overlays/overlay-full-2/WEB-INF/lib/b.jar @@ -0,0 +1 @@ +overlay-full-2-WEB-INF/lib/b.jar \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-2/WEB-INF/lib/c.jar b/src/test/resources/overlays/overlay-full-2/WEB-INF/lib/c.jar new file mode 100644 index 00000000..31b8bb4f --- /dev/null +++ b/src/test/resources/overlays/overlay-full-2/WEB-INF/lib/c.jar @@ -0,0 +1 @@ +overlay-full-2-WEB-INF/lib/c.jar \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-2/WEB-INF/web.xml b/src/test/resources/overlays/overlay-full-2/WEB-INF/web.xml new file mode 100644 index 00000000..56b5cf2b --- /dev/null +++ b/src/test/resources/overlays/overlay-full-2/WEB-INF/web.xml @@ -0,0 +1 @@ +overlay-full-2-WEB-INF/web.xml \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-2/jsp/a.jsp b/src/test/resources/overlays/overlay-full-2/jsp/a.jsp new file mode 100644 index 00000000..c6c7fe8e --- /dev/null +++ b/src/test/resources/overlays/overlay-full-2/jsp/a.jsp @@ -0,0 +1 @@ +overlay-full-2-jsp/a.jsp \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-2/jsp/b.jsp b/src/test/resources/overlays/overlay-full-2/jsp/b.jsp new file mode 100644 index 00000000..b2122c75 --- /dev/null +++ b/src/test/resources/overlays/overlay-full-2/jsp/b.jsp @@ -0,0 +1 @@ +overlay-full-2-jsp/b.jsp \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-2/jsp/c.jsp b/src/test/resources/overlays/overlay-full-2/jsp/c.jsp new file mode 100644 index 00000000..bb474c11 --- /dev/null +++ b/src/test/resources/overlays/overlay-full-2/jsp/c.jsp @@ -0,0 +1 @@ +overlay-full-2-jsp/c.jsp \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-2/jsp/d/a.jsp b/src/test/resources/overlays/overlay-full-2/jsp/d/a.jsp new file mode 100644 index 00000000..ace22e52 --- /dev/null +++ b/src/test/resources/overlays/overlay-full-2/jsp/d/a.jsp @@ -0,0 +1 @@ +overlay-full-2-jsp/d/a.jsp \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-2/jsp/d/b.jsp b/src/test/resources/overlays/overlay-full-2/jsp/d/b.jsp new file mode 100644 index 00000000..a52148b8 --- /dev/null +++ b/src/test/resources/overlays/overlay-full-2/jsp/d/b.jsp @@ -0,0 +1 @@ +overlay-full-2-jsp/d/b.jsp \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-2/jsp/d/c.jsp b/src/test/resources/overlays/overlay-full-2/jsp/d/c.jsp new file mode 100644 index 00000000..71fcda2a --- /dev/null +++ b/src/test/resources/overlays/overlay-full-2/jsp/d/c.jsp @@ -0,0 +1 @@ +overlay-full-2-jsp/d/c.jsp \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-3/WEB-INF/classes/a.clazz b/src/test/resources/overlays/overlay-full-3/WEB-INF/classes/a.clazz new file mode 100644 index 00000000..420cc767 --- /dev/null +++ b/src/test/resources/overlays/overlay-full-3/WEB-INF/classes/a.clazz @@ -0,0 +1 @@ +overlay-full-3-WEB-INF/classes/a.clazz \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-3/WEB-INF/classes/b.clazz b/src/test/resources/overlays/overlay-full-3/WEB-INF/classes/b.clazz new file mode 100644 index 00000000..9b99907f --- /dev/null +++ b/src/test/resources/overlays/overlay-full-3/WEB-INF/classes/b.clazz @@ -0,0 +1 @@ +overlay-full-3-WEB-INF/classes/b.clazz \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-3/WEB-INF/classes/c.clazz b/src/test/resources/overlays/overlay-full-3/WEB-INF/classes/c.clazz new file mode 100644 index 00000000..375bb5cb --- /dev/null +++ b/src/test/resources/overlays/overlay-full-3/WEB-INF/classes/c.clazz @@ -0,0 +1 @@ +overlay-full-3-WEB-INF/classes/c.clazz \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-3/WEB-INF/lib/a.jar b/src/test/resources/overlays/overlay-full-3/WEB-INF/lib/a.jar new file mode 100644 index 00000000..58d33d62 --- /dev/null +++ b/src/test/resources/overlays/overlay-full-3/WEB-INF/lib/a.jar @@ -0,0 +1 @@ +overlay-full-3-WEB-INF/lib/a.jar \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-3/WEB-INF/lib/b.jar b/src/test/resources/overlays/overlay-full-3/WEB-INF/lib/b.jar new file mode 100644 index 00000000..06c4ef1f --- /dev/null +++ b/src/test/resources/overlays/overlay-full-3/WEB-INF/lib/b.jar @@ -0,0 +1 @@ +overlay-full-3-WEB-INF/lib/b.jar \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-3/WEB-INF/lib/c.jar b/src/test/resources/overlays/overlay-full-3/WEB-INF/lib/c.jar new file mode 100644 index 00000000..f7f92e69 --- /dev/null +++ b/src/test/resources/overlays/overlay-full-3/WEB-INF/lib/c.jar @@ -0,0 +1 @@ +overlay-full-3-WEB-INF/lib/c.jar \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-3/WEB-INF/web.xml b/src/test/resources/overlays/overlay-full-3/WEB-INF/web.xml new file mode 100644 index 00000000..214df434 --- /dev/null +++ b/src/test/resources/overlays/overlay-full-3/WEB-INF/web.xml @@ -0,0 +1 @@ +overlay-full-3-WEB-INF/web.xml \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-3/jsp/a.jsp b/src/test/resources/overlays/overlay-full-3/jsp/a.jsp new file mode 100644 index 00000000..e6e59e7c --- /dev/null +++ b/src/test/resources/overlays/overlay-full-3/jsp/a.jsp @@ -0,0 +1 @@ +overlay-full-3-jsp/a.jsp \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-3/jsp/b.jsp b/src/test/resources/overlays/overlay-full-3/jsp/b.jsp new file mode 100644 index 00000000..3911b1c7 --- /dev/null +++ b/src/test/resources/overlays/overlay-full-3/jsp/b.jsp @@ -0,0 +1 @@ +overlay-full-3-jsp/b.jsp \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-3/jsp/c.jsp b/src/test/resources/overlays/overlay-full-3/jsp/c.jsp new file mode 100644 index 00000000..473a3fd1 --- /dev/null +++ b/src/test/resources/overlays/overlay-full-3/jsp/c.jsp @@ -0,0 +1 @@ +overlay-full-3-jsp/c.jsp \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-3/jsp/d/a.jsp b/src/test/resources/overlays/overlay-full-3/jsp/d/a.jsp new file mode 100644 index 00000000..1b7236d0 --- /dev/null +++ b/src/test/resources/overlays/overlay-full-3/jsp/d/a.jsp @@ -0,0 +1 @@ +overlay-full-3-jsp/d/a.jsp \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-3/jsp/d/b.jsp b/src/test/resources/overlays/overlay-full-3/jsp/d/b.jsp new file mode 100644 index 00000000..e5aea58b --- /dev/null +++ b/src/test/resources/overlays/overlay-full-3/jsp/d/b.jsp @@ -0,0 +1 @@ +overlay-full-3-jsp/d/b.jsp \ No newline at end of file diff --git a/src/test/resources/overlays/overlay-full-3/jsp/d/c.jsp b/src/test/resources/overlays/overlay-full-3/jsp/d/c.jsp new file mode 100644 index 00000000..8d451808 --- /dev/null +++ b/src/test/resources/overlays/overlay-full-3/jsp/d/c.jsp @@ -0,0 +1 @@ +overlay-full-3-jsp/d/c.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/test-overlays/overlay-full-1.war b/src/test/resources/unit/waroverlays/test-overlays/overlay-full-1.war new file mode 100644 index 0000000000000000000000000000000000000000..f2682509ecc42901d7d80f96bdbff7906adf6087 GIT binary patch literal 2543 zcma);Pe>F|9LGm@l}(cj#H2$=L59xEN?QBxQip`vRSzy3iGx{ovU6SX z;;B;zZZ1T5@(>+5tgioN8ukzb5hw^72o@b8>i6c)zUj9!qYoZDoZsg=zxU?t2UB7o z*u*d)hS|M5eTQ+3Be0fYgHcXM#=|KnYlE_oQI_i3+PMOc`(VOfX_*vF3h~&@L0*dQ zOKYWmk>k}Ck?Y=A+k7|Bt4F?WPw)we6(n^szcdgk3Wamrt#LN7QDjAKpjVAt*oy3I zf7`BS$P3;3f>xQ^v8&a#+^bq0Rl~WoqKqoWCfuu!I;wMH8K24^RA!ZNpNdASVgw!9 z>dVJ`CpWZKDEi*)gC~B`!-tD5yF?35_bPtT z>BB|qF41RZ*wvA2Nq(&4T0)RAj<&kq&2P!&zzg)9n|`kts1t{cx#L<5 z{&{BXI(|DGv^%cX;O&2dH%>y+WHwvPk9fDQ!Ui<7f%)>tWNn1!7F4+HIO5^r$Mdxj zp4(7m-H52GZwt7KgnS2cv@+kLWaUsO!RQ6U616zy)l8QYb0{?>dcT-h(HyPJpXeMc zZNKcS|g44nnrq*-rH)8f}0f#3hR$j{W~s zv1M&+X=Vr*yFbgh7{*qm@PY%jkH&H=4#EDUA;EgufgNJm6o+6_(vZ6@A(l6B2zDY3 zS$2d}4T*7VK#Dg9=tc-`_z>gRcN8B&xM4qxW4lqj0C?4P7{gYhSjEB&L0}BqjAA`- ySIOH9DPRm+jAB^}vz&%O>@Erxs-SD5*jNXYtqHKOJLC`)5o}1kC#?vI*g$tME{Qf!j=Jv

tJ3u>#xca;~Go(}cu;ZG|Q!hjqSWpy$?JLE5lg+u(Q@z6lI7?Sv*UNzje z99~`dywb>#7drO^t#YUPPt@9St_s?!Qkg_HJC-#z;at7NR-L(!^r&ot%5-+zqoRdY zjG{w}z4~&c1D@@JxecbZhpDloaQR}U)Fbh)#Yei_y*RHP)>@|~wd$Yjn;u2h9u^lH zj00g`;F?hVb`V0y+-(c9wwe@RmCLz=DrGSw#Q2J$`JUwSC^~%LYRoG-wXx`mLv(xJ z-gjQniH$|;4$;?l=7#sfL3F^}ZaWb2H4{QQG2wC)OY?)8qL&6j=9Ob7eCE>o9d3ci z^#V1Az#q{$!7VVgUSP!`@cFDXvj?_HCi$_FYY9QwakSONE@4@z_->)^9Jtqg7vr!o zXI!hpKYYFM5#w;s&bVHOzr9_qwnNio259r6?(M6v0S#^7{M_SWeT3^4RJiRp;@Qis zH|rx@x1lP!5z)}t=5rPa`3~j?az7(vWm71@*agE9r5rai-D$^cN{vhIFD6zrN09p) zxdThfFJ2U}q&W!n0+tqKiNuR0)-(s9*I;SUrbFGkB^EUYA$K)cPIV_*EPx}#5lRrp z{(q|2vKBTwJpzo?A9XHNyQzPrZ3ZXW|A=s2GjT#<0a0mZlhW8V0eu7+9!*j*VhtG4NLnq^&j^znM1p5A8lY3OAF|f2b~P AqyPW_ literal 0 HcmV?d00001 diff --git a/src/test/resources/unit/waroverlays/test-overlays/overlay-full-3.war b/src/test/resources/unit/waroverlays/test-overlays/overlay-full-3.war new file mode 100644 index 0000000000000000000000000000000000000000..9637a9bc956ceaec9067893023cc391ae67d3c89 GIT binary patch literal 2543 zcma);&1(}u7>74srL{&Q#Bb2z!In0=DMTR%K~hK|*=`bI(SQ|6(jJTvN<*nc5sD|T zg3>>r3RZim_2Qu?mDDt8c3pCoLJDGwf_hL8d}lv0>zm!Q0|P_%eSZ7S?BtW!*|yvcJB486JmV!e42b5ROMjBUi>bVf2Tv zQ5oY|PIU9^U~Oabb!u1+d~VKgF~JuV#M!0QRChVLJiuO^_Qh&tAJ3+S#lVGnV7s~1 zv@_&|=6yk{%(ci!t1a^?kD)48$P|lHMP(D_)dvmLga@D3B2>k+& z)*cAwA%x81hA@4rSq@gEl0|5u7WHv)wvmt=D@#i#I`pRJYp3Yk{-PTu(cZI%mJn2&Mq8~8a`i;R@fdyQ%E+@c#$jXTxYUN9 z4!X`_91hwXm)r0gvGl+xXqwDkt@%mo_C?r$gf_673m$Ecu-t+Ow;e}>PA;U{BP_Qe zCS)bTX7@VGMMA!VIy}s7n5+y6B^bS6SfU!oEY9~EF@sW*y!DHT71iNk{)QJ|sr#i9 zMJ%ZfLao74r*x5YqKP%tLFgS=>a^-m>u!lf)j`N(Hr=V#M3)XQga~Q`aqR!6iY=>S ztMe1U=>2KV#W1!ig Date: Mon, 1 Dec 2025 13:09:52 +0100 Subject: [PATCH 21/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarOverlaysTest --- .../java/org/apache/maven/plugins/war/WarOverlaysTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java index 0cc7470e..c07f398c 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java @@ -199,6 +199,9 @@ public void testScenarioOneWithDefaulSettings(WarExplodedMojo mojo) throws Excep @MojoParameter( name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-scenario-one-overlay-settings") + @MojoParameter(name = "classesDirectory", value = "target/test-classes/unit/waroverlays/scenario-one-overlay-settings-test-data/classes") + @MojoParameter(name = "warSourceDirectory", value ="target/test-classes/unit/waroverlays/scenario-one-overlay-settings-test-data/source/" ) + @MojoParameter(name = "webappDirectory", value ="target/test-classes/unit/waroverlays/scenario-one-overlay-settings" ) @Test public void testScenarioOneWithOverlaySettings(WarExplodedMojo mojo) throws Exception { // setup test data @@ -230,7 +233,7 @@ public void testScenarioOneWithOverlaySettings(WarExplodedMojo mojo) throws Exce mojo.execute(); - assertScenariOne(testId, webAppDirectory); + assertScenariOne("scenario-one-overlay-settings", webAppDirectory); } /** From 7bcae5e2bede3f118c024c9dcd401e85b7a0f33b Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Tue, 2 Dec 2025 14:34:04 +0100 Subject: [PATCH 22/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarOverlaysTest --- .../maven/plugins/war/WarOverlaysTest.java | 93 ++++++++++++------- .../source/jsp/b.jsp | 1 + .../source/org/sample/company/test.jsp | 1 + 3 files changed, 60 insertions(+), 35 deletions(-) create mode 100644 src/test/resources/unit/waroverlays/scenario-one-overlay-settings-test-data/source/jsp/b.jsp create mode 100644 src/test/resources/unit/waroverlays/scenario-one-overlay-settings-test-data/source/org/sample/company/test.jsp diff --git a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java index c07f398c..a2b77836 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java @@ -53,17 +53,16 @@ @MojoTest public class WarOverlaysTest { - private static final File OVERLAYS_TEMP_DIR = new File(getBasedir(), "target/test-classes/unit/waroverlays/test-overlays/"); + private static final File OVERLAYS_TEMP_DIR = + new File(getBasedir(), "target/test-classes/unit/waroverlays/test-overlays/"); private static final File OVERLAYS_ROOT_DIR = new File(getBasedir(), "target/test-classes/overlays/"); private static final String MANIFEST_PATH = "META-INF" + File.separator + "MANIFEST.MF"; - - @BeforeEach public void setUp() throws Exception { -// generateFullOverlayWar("overlay-full-1"); -// generateFullOverlayWar("overlay-full-2"); -// generateFullOverlayWar("overlay-full-3"); + // generateFullOverlayWar("overlay-full-1"); + // generateFullOverlayWar("overlay-full-2"); + // generateFullOverlayWar("overlay-full-3"); } private File getTestDirectory() { @@ -72,10 +71,16 @@ private File getTestDirectory() { @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/waroverlays/default.xml") @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-no-overlay") - @MojoParameter(name = "classesDirectory", value = "target/test-classes/unit/waroverlays/no-overlay-test-data/classes") - @MojoParameter(name = "warSourceDirectory", value ="target/test-classes/unit/waroverlays/no-overlay-test-data/source/" ) - @MojoParameter(name = "webappDirectory", value ="target/test-classes/unit/waroverlays/no-overlay" ) - @MojoParameter(name = "webXml", value ="target/test-classes/unit/waroverlays/no-overlay-test-data/xml-config/web.xml" ) + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/waroverlays/no-overlay-test-data/classes") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/waroverlays/no-overlay-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/waroverlays/no-overlay") + @MojoParameter( + name = "webXml", + value = "target/test-classes/unit/waroverlays/no-overlay-test-data/xml-config/web.xml") @Test public void testNoOverlay(WarExplodedMojo mojo) throws Exception { mojo.setProject(new MavenProjectArtifactsStub()); @@ -88,9 +93,13 @@ public void testNoOverlay(WarExplodedMojo mojo) throws Exception { @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/waroverlays/default.xml") @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-default-overlay") - @MojoParameter(name = "classesDirectory", value = "target/test-classes/unit/waroverlays/default-overlay-test-data/classes") - @MojoParameter(name = "warSourceDirectory", value ="target/test-classes/unit/waroverlays/default-overlay-test-data/source/" ) - @MojoParameter(name = "webappDirectory", value ="target/test-classes/unit/waroverlays/default-overlay" ) + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/waroverlays/default-overlay-test-data/classes") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/waroverlays/default-overlay-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/waroverlays/default-overlay") @Test public void testDefaultOverlay(WarExplodedMojo mojo) throws Exception { // Create war file @@ -124,12 +133,16 @@ public void testDefaultOverlay(WarExplodedMojo mojo) throws Exception { @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/waroverlays/default.xml") @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-default-overlays") - @MojoParameter(name = "classesDirectory", value = "target/test-classes/unit/waroverlays/default-overlays-test-data/classes") - @MojoParameter(name = "warSourceDirectory", value ="target/test-classes/unit/waroverlays/default-overlays-test-data/source/" ) - @MojoParameter(name = "webappDirectory", value ="target/test-classes/unit/waroverlays/default-overlays" ) + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/waroverlays/default-overlays-test-data/classes") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/waroverlays/default-overlays-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/waroverlays/default-overlays") @Test public void testDefaultOverlays(WarExplodedMojo mojo) throws Exception { - final ArtifactStub overlay = buildWarOverlayStub("overlay-one"); + final ArtifactStub overlay = buildWarOverlayStub("overlay-one"); final ArtifactStub overlay2 = buildWarOverlayStub("overlay-two"); final MavenProjectArtifactsStub project = createProjectWithOverlays(overlay, overlay2); @@ -168,9 +181,15 @@ public void testDefaultOverlays(WarExplodedMojo mojo) throws Exception { @MojoParameter( name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-scenario-one-default-settings") - @MojoParameter(name = "classesDirectory", value = "target/test-classes/unit/waroverlays/scenario-one-default-settings-test-data/classes") - @MojoParameter(name = "warSourceDirectory", value ="target/test-classes/unit/waroverlays/scenario-one-default-settings-test-data/source/" ) - @MojoParameter(name = "webappDirectory", value ="target/test-classes/unit/waroverlays/scenario-one-default-settings" ) + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/waroverlays/scenario-one-default-settings-test-data/classes") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/waroverlays/scenario-one-default-settings-test-data/source/") + @MojoParameter( + name = "webappDirectory", + value = "target/test-classes/unit/waroverlays/scenario-one-default-settings") @Test public void testScenarioOneWithDefaulSettings(WarExplodedMojo mojo) throws Exception { // Add an overlay @@ -199,22 +218,17 @@ public void testScenarioOneWithDefaulSettings(WarExplodedMojo mojo) throws Excep @MojoParameter( name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-scenario-one-overlay-settings") - @MojoParameter(name = "classesDirectory", value = "target/test-classes/unit/waroverlays/scenario-one-overlay-settings-test-data/classes") - @MojoParameter(name = "warSourceDirectory", value ="target/test-classes/unit/waroverlays/scenario-one-overlay-settings-test-data/source/" ) - @MojoParameter(name = "webappDirectory", value ="target/test-classes/unit/waroverlays/scenario-one-overlay-settings" ) + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/waroverlays/scenario-one-overlay-settings-test-data/classes") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/waroverlays/scenario-one-overlay-settings-test-data/source/") + @MojoParameter( + name = "webappDirectory", + value = "target/test-classes/unit/waroverlays/scenario-one-overlay-settings") @Test public void testScenarioOneWithOverlaySettings(WarExplodedMojo mojo) throws Exception { - // setup test data - final String testId = "scenario-one-overlay-settings"; - final File classesDir = createClassesDir(testId, true); - final File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId, false); - String[] sourceFiles = new String[] {"org/sample/company/test.jsp", "jsp/b.jsp"}; - for (String sourceFile : sourceFiles) { - File sample = new File(webAppSource, sourceFile); - createFile(sample); - } - // Add an overlay final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); @@ -230,9 +244,9 @@ public void testScenarioOneWithOverlaySettings(WarExplodedMojo mojo) throws Exce overlays.add(new DefaultOverlay(overlay3)); mojo.setOverlays(overlays); - mojo.execute(); + File webAppDirectory = (File) getVariableValueFromObject(mojo, "webappDirectory"); assertScenariOne("scenario-one-overlay-settings", webAppDirectory); } @@ -247,6 +261,15 @@ public void testScenarioOneWithOverlaySettings(WarExplodedMojo mojo) throws Exce @MojoParameter( name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-scenario-one-full-settings") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/waroverlays/scenario-one-overlay-settings-test-data/classes") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/waroverlays/scenario-one-overlay-settings-test-data/source/") + @MojoParameter( + name = "webappDirectory", + value = "target/test-classes/unit/waroverlays/scenario-one-overlay-settings") @Test public void testScenarioOneWithFullSettings(WarExplodedMojo mojo) throws Exception { // setup test data diff --git a/src/test/resources/unit/waroverlays/scenario-one-overlay-settings-test-data/source/jsp/b.jsp b/src/test/resources/unit/waroverlays/scenario-one-overlay-settings-test-data/source/jsp/b.jsp new file mode 100644 index 00000000..d6b5d01a --- /dev/null +++ b/src/test/resources/unit/waroverlays/scenario-one-overlay-settings-test-data/source/jsp/b.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/maven-war-plugin/target/test-classes/unit/waroverlays/scenario-one-overlay-settings-test-data/source/jsp/b.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/scenario-one-overlay-settings-test-data/source/org/sample/company/test.jsp b/src/test/resources/unit/waroverlays/scenario-one-overlay-settings-test-data/source/org/sample/company/test.jsp new file mode 100644 index 00000000..ac0554b3 --- /dev/null +++ b/src/test/resources/unit/waroverlays/scenario-one-overlay-settings-test-data/source/org/sample/company/test.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/maven-war-plugin/target/test-classes/unit/waroverlays/scenario-one-overlay-settings-test-data/source/org/sample/company/test.jsp \ No newline at end of file From ee8216349236993721a555ac41e422176167bc91 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 3 Dec 2025 13:12:16 +0100 Subject: [PATCH 23/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarOverlaysTest --- .../maven/plugins/war/WarOverlaysTest.java | 23 +++++-------------- .../source/jsp/b.jsp | 1 + .../source/org/sample/company/test.jsp | 1 + 3 files changed, 8 insertions(+), 17 deletions(-) create mode 100644 src/test/resources/unit/waroverlays/scenario-one-full-settings-test-data/source/jsp/b.jsp create mode 100644 src/test/resources/unit/waroverlays/scenario-one-full-settings-test-data/source/org/sample/company/test.jsp diff --git a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java index a2b77836..cd6625a0 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java @@ -263,32 +263,22 @@ public void testScenarioOneWithOverlaySettings(WarExplodedMojo mojo) throws Exce value = "target/test-classes/unit/waroverlays/war/work-scenario-one-full-settings") @MojoParameter( name = "classesDirectory", - value = "target/test-classes/unit/waroverlays/scenario-one-overlay-settings-test-data/classes") + value = "target/test-classes/unit/waroverlays/scenario-one-full-settings-test-data/classes") @MojoParameter( name = "warSourceDirectory", - value = "target/test-classes/unit/waroverlays/scenario-one-overlay-settings-test-data/source/") + value = "target/test-classes/unit/waroverlays/scenario-one-full-settings-test-data/source/") @MojoParameter( name = "webappDirectory", - value = "target/test-classes/unit/waroverlays/scenario-one-overlay-settings") + value = "target/test-classes/unit/waroverlays/scenario-one-full-settings") @Test public void testScenarioOneWithFullSettings(WarExplodedMojo mojo) throws Exception { - // setup test data - final String testId = "scenario-one-full-settings"; - final File classesDir = createClassesDir(testId, true); - final File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId, false); - String[] sourceFiles = new String[] {"org/sample/company/test.jsp", "jsp/b.jsp"}; - for (String sourceFile : sourceFiles) { - File sample = new File(webAppSource, sourceFile); - createFile(sample); - } - // Add an overlay final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); final MavenProjectArtifactsStub project = createProjectWithOverlays(overlay1, overlay2, overlay3); + mojo.setProject(project); // Add the tags final List overlays = new ArrayList<>(); @@ -300,11 +290,10 @@ public void testScenarioOneWithFullSettings(WarExplodedMojo mojo) throws Excepti overlays.add(new DefaultOverlay(overlay3)); mojo.setOverlays(overlays); - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - mojo.execute(); - assertScenariOne(testId, webAppDirectory); + File webAppDirectory = (File) getVariableValueFromObject(mojo, "webappDirectory"); + assertScenariOne("scenario-one-full-settings", webAppDirectory); } /** diff --git a/src/test/resources/unit/waroverlays/scenario-one-full-settings-test-data/source/jsp/b.jsp b/src/test/resources/unit/waroverlays/scenario-one-full-settings-test-data/source/jsp/b.jsp new file mode 100644 index 00000000..b67d138f --- /dev/null +++ b/src/test/resources/unit/waroverlays/scenario-one-full-settings-test-data/source/jsp/b.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/maven-war-plugin/target/test-classes/unit/waroverlays/scenario-one-full-settings-test-data/source/jsp/b.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/scenario-one-full-settings-test-data/source/org/sample/company/test.jsp b/src/test/resources/unit/waroverlays/scenario-one-full-settings-test-data/source/org/sample/company/test.jsp new file mode 100644 index 00000000..276ac954 --- /dev/null +++ b/src/test/resources/unit/waroverlays/scenario-one-full-settings-test-data/source/org/sample/company/test.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/maven-war-plugin/target/test-classes/unit/waroverlays/scenario-one-full-settings-test-data/source/org/sample/company/test.jsp \ No newline at end of file From 5426d493abe995727ef18a1823b6706b142ebd9f Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 3 Dec 2025 13:25:59 +0100 Subject: [PATCH 24/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarOverlaysTest --- .../maven/plugins/war/WarOverlaysTest.java | 26 ++++++++++--------- .../source/jsp/b.jsp | 1 + .../source/org/sample/company/test.jsp | 1 + 3 files changed, 16 insertions(+), 12 deletions(-) create mode 100644 src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs-test-data/source/jsp/b.jsp create mode 100644 src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs-test-data/source/org/sample/company/test.jsp diff --git a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java index cd6625a0..9ac36821 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java @@ -352,24 +352,25 @@ private void assertScenariOne(String testId, File webAppDirectory) throws Except @MojoParameter( name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-overlays-includes-excludes-multiple-defs") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/waroverlays/overlays-includes-excludes-multiple-defs-test-data/classes") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/waroverlays/overlays-includes-excludes-multiple-defs-test-data/source/") + @MojoParameter( + name = "webappDirectory", + value = "target/test-classes/unit/waroverlays/overlays-includes-excludes-multiple-defs") @Test public void testOverlaysIncludesExcludesWithMultipleDefinitions(WarExplodedMojo mojo) throws Exception { - // setup test data - final String testId = "overlays-includes-excludes-multiple-defs"; - final File classesDir = createClassesDir(testId, true); - final File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId, false); - String[] sourceFiles = new String[] {"org/sample/company/test.jsp", "jsp/b.jsp"}; - for (String sourceFile : sourceFiles) { - File sample = new File(webAppSource, sourceFile); - createFile(sample); - } // Add an overlay final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); final MavenProjectArtifactsStub project = createProjectWithOverlays(overlay1, overlay2, overlay3); + mojo.setProject(project); + Overlay over1 = new DefaultOverlay(overlay3); over1.setExcludes("**/a.*,**/c.*,**/*.xml"); @@ -390,9 +391,10 @@ public void testOverlaysIncludesExcludesWithMultipleDefinitions(WarExplodedMojo mojo.addOverlay(mojo.getCurrentProjectOverlay()); mojo.addOverlay(over4); - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); mojo.execute(); + + File webAppDirectory = (File) getVariableValueFromObject(mojo, "webappDirectory"); final List assertedFiles = new ArrayList<>(); assertedFiles.addAll(assertWebXml(webAppDirectory)); assertedFiles.addAll(assertCustomContent( @@ -420,7 +422,7 @@ public void testOverlaysIncludesExcludesWithMultipleDefinitions(WarExplodedMojo assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/a.jsp"); assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/b.jsp"); assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/c.jsp"); - assertDefaultFileContent(testId, webAppDirectory, "org/sample/company/test.jsp"); + assertDefaultFileContent("overlays-includes-excludes-multiple-defs", webAppDirectory, "org/sample/company/test.jsp"); assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/web.xml"); assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.clazz"); assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.clazz"); diff --git a/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs-test-data/source/jsp/b.jsp b/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs-test-data/source/jsp/b.jsp new file mode 100644 index 00000000..653fe9f9 --- /dev/null +++ b/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs-test-data/source/jsp/b.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/maven-war-plugin/target/test-classes/unit/waroverlays/overlays-includes-excludes-multiple-defs-test-data/source/jsp/b.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs-test-data/source/org/sample/company/test.jsp b/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs-test-data/source/org/sample/company/test.jsp new file mode 100644 index 00000000..898777b5 --- /dev/null +++ b/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs-test-data/source/org/sample/company/test.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/maven-war-plugin/target/test-classes/unit/waroverlays/overlays-includes-excludes-multiple-defs-test-data/source/org/sample/company/test.jsp \ No newline at end of file From 95f933b9c3fb1ba88b94f261f424c77d1e1349b5 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 3 Dec 2025 13:41:14 +0100 Subject: [PATCH 25/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarOverlaysTest --- .../maven/plugins/war/WarOverlaysTest.java | 28 +++++++++---------- .../source/jsp/b.jsp | 1 + .../source/org/sample/company/test.jsp | 1 + 3 files changed, 15 insertions(+), 15 deletions(-) create mode 100644 src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs2-test-data/source/jsp/b.jsp create mode 100644 src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs2-test-data/source/org/sample/company/test.jsp diff --git a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java index 9ac36821..f419a35f 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java @@ -440,25 +440,24 @@ public void testOverlaysIncludesExcludesWithMultipleDefinitions(WarExplodedMojo @MojoParameter( name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-overlays-includes-excludes-multiple-defs2") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/waroverlays/overlays-overlays-includes-excludes-multiple-defs2-test-data/classes") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/waroverlays/overlays-overlays-includes-excludes-multiple-defs2-test-data/source/") + @MojoParameter( + name = "webappDirectory", + value = "target/test-classes/unit/waroverlays/overlays-includes-excludes-multiple-defs2") @Test public void testOverlaysIncludesExcludesWithMultipleDefinitions2(WarExplodedMojo mojo) throws Exception { - // setup test data - final String testId = "overlays-includes-excludes-multiple-defs2"; - final File classesDir = createClassesDir(testId, true); - final File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId, false); - String[] sourceFiles = new String[] {"org/sample/company/test.jsp", "jsp/b.jsp"}; - for (String sourceFile : sourceFiles) { - File sample = new File(webAppSource, sourceFile); - createFile(sample); - } - // Add an overlay final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1"); final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2"); final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3"); final MavenProjectArtifactsStub project = createProjectWithOverlays(overlay1, overlay2, overlay3); + mojo.setProject(project); Overlay over1 = new DefaultOverlay(overlay3); over1.setExcludes("**/a.*,**/c.*,**/*.xml,jsp/b.jsp"); @@ -480,10 +479,9 @@ public void testOverlaysIncludesExcludesWithMultipleDefinitions2(WarExplodedMojo mojo.addOverlay(mojo.getCurrentProjectOverlay()); mojo.addOverlay(over4); - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - mojo.execute(); + File webAppDirectory = (File) getVariableValueFromObject(mojo, "webappDirectory"); final List assertedFiles = new ArrayList<>(); assertedFiles.addAll(assertWebXml(webAppDirectory)); assertedFiles.addAll(assertCustomContent( @@ -506,12 +504,12 @@ public void testOverlaysIncludesExcludesWithMultipleDefinitions2(WarExplodedMojo "overlay file not found")); assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/a.jsp"); - assertDefaultFileContent(testId, webAppDirectory, "jsp/b.jsp"); + assertDefaultFileContent("overlays-includes-excludes-multiple-defs2", webAppDirectory, "jsp/b.jsp"); assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/c.jsp"); assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/a.jsp"); assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/b.jsp"); assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/c.jsp"); - assertDefaultFileContent(testId, webAppDirectory, "org/sample/company/test.jsp"); + assertDefaultFileContent("overlays-includes-excludes-multiple-defs2", webAppDirectory, "org/sample/company/test.jsp"); assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/web.xml"); assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.clazz"); assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.clazz"); diff --git a/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs2-test-data/source/jsp/b.jsp b/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs2-test-data/source/jsp/b.jsp new file mode 100644 index 00000000..51c2c0b7 --- /dev/null +++ b/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs2-test-data/source/jsp/b.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/maven-war-plugin/target/test-classes/unit/waroverlays/overlays-includes-excludes-multiple-defs2-test-data/source/jsp/b.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs2-test-data/source/org/sample/company/test.jsp b/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs2-test-data/source/org/sample/company/test.jsp new file mode 100644 index 00000000..b832bc40 --- /dev/null +++ b/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs2-test-data/source/org/sample/company/test.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/maven-war-plugin/target/test-classes/unit/waroverlays/overlays-includes-excludes-multiple-defs2-test-data/source/org/sample/company/test.jsp \ No newline at end of file From 5d6deb4aa34ab1758a825f4c7d135313fefed060 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 10 Dec 2025 14:22:47 +0100 Subject: [PATCH 26/80] refactor: remove unused code --- .../war/WarExplodedMojoFilteringTest.java | 60 ++++++++++++------- .../maven/plugins/war/WarOverlaysTest.java | 23 ------- 2 files changed, 37 insertions(+), 46 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java index 6f1bab6d..9c6b750d 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoFilteringTest.java @@ -37,6 +37,13 @@ * under the License. */ +import javax.inject.Inject; + +import java.io.BufferedReader; +import java.io.File; +import java.io.StringReader; +import java.util.Properties; + import org.apache.maven.api.di.Provides; import org.apache.maven.api.plugin.testing.Basedir; import org.apache.maven.api.plugin.testing.InjectMojo; @@ -50,12 +57,6 @@ import org.codehaus.plexus.util.FileUtils; import org.junit.jupiter.api.Test; -import javax.inject.Inject; -import java.io.BufferedReader; -import java.io.File; -import java.io.StringReader; -import java.util.Properties; - import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.when; @@ -75,19 +76,24 @@ public class WarExplodedMojoFilteringTest { @Provides MavenProject project() throws Exception { - MavenProjectBasicStub project = new MavenProjectBasicStub(); + MavenProjectBasicStub project = new MavenProjectBasicStub(); project.addProperty("is_this_simple", "i_think_so"); - return project; + return project; } - @SuppressWarnings("checkstyle:MethodLength") @InjectMojo(goal = "exploded", pom = "plugin-config.xml") @Basedir("src/test/resources/unit/warexplodedmojo/") - @MojoParameter(name = "classesDirectory", value ="target/test-classes/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/classes/" ) - @MojoParameter(name = "warSourceDirectory", value ="target/test-classes/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/source/" ) - @MojoParameter(name = "webappDirectory", value ="target/test-classes/unit/warexplodedmojo/ExplodedWarWithResourceFiltering" ) - @MojoParameter(name = "outdatedCheckPath", value ="WEB-INF/lib/" ) + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/source/") + @MojoParameter( + name = "webappDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithResourceFiltering") + @MojoParameter(name = "outdatedCheckPath", value = "WEB-INF/lib/") @Test public void testExplodedWarWithResourceFiltering(WarExplodedMojo mojo) throws Exception { Properties systemProperties = System.getProperties(); @@ -95,7 +101,8 @@ public void testExplodedWarWithResourceFiltering(WarExplodedMojo mojo) throws Ex when(mavenSession.getSystemProperties()).thenReturn(systemProperties); ResourceStub[] resources = new ResourceStub[] {new ResourceStub()}; - resources[0].setDirectory(MojoExtension.getBasedir() + "/ExplodedWarWithResourceFiltering-test-data/resources/"); + resources[0].setDirectory( + MojoExtension.getBasedir() + "/ExplodedWarWithResourceFiltering-test-data/resources/"); resources[0].setFiltering(true); mojo.setWebResources(resources); mojo.execute(); @@ -182,11 +189,20 @@ public void testExplodedWarWithResourceFiltering(WarExplodedMojo mojo) throws Ex @SuppressWarnings("checkstyle:MethodLength") @InjectMojo(goal = "exploded", pom = "plugin-config.xml") @Basedir("src/test/resources/unit/warexplodedmojo/") - @MojoParameter(name = "classesDirectory", value ="target/test-classes/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/classes/" ) - @MojoParameter(name = "warSourceDirectory", value ="target/test-classes/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/source/" ) - @MojoParameter(name = "webappDirectory", value ="target/test-classes/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering" ) - @MojoParameter(name = "outdatedCheckPath", value ="WEB-INF/lib/" ) - @MojoParameter(name="filters", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/filters/filter.properties") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/source/") + @MojoParameter( + name = "webappDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering") + @MojoParameter(name = "outdatedCheckPath", value = "WEB-INF/lib/") + @MojoParameter( + name = "filters", + value = + "target/test-classes/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/filters/filter.properties") @Test public void testExplodedWarWithResourceFileFiltering(WarExplodedMojo mojo) throws Exception { Properties systemProperties = System.getProperties(); @@ -194,7 +210,8 @@ public void testExplodedWarWithResourceFileFiltering(WarExplodedMojo mojo) throw when(mavenSession.getSystemProperties()).thenReturn(systemProperties); ResourceStub[] resources = new ResourceStub[] {new ResourceStub()}; - resources[0].setDirectory(MojoExtension.getBasedir() + "/ExplodedWarWithResourceFileFiltering-test-data/resources/"); + resources[0].setDirectory( + MojoExtension.getBasedir() + "/ExplodedWarWithResourceFileFiltering-test-data/resources/"); resources[0].setFiltering(true); mojo.setWebResources(resources); @@ -203,7 +220,6 @@ public void testExplodedWarWithResourceFileFiltering(WarExplodedMojo mojo) throw File expectedResourceWDirFile = new File(mojo.getWebappDirectory(), "custom-config/custom-setting.cfg"); assertTrue(expectedResourceWDirFile.exists(), "resource file with dir not found:" + expectedResourceWDirFile); - // validate filtered file String content = FileUtils.fileRead(expectedResourceWDirFile); content = FileUtils.fileRead(expectedResourceWDirFile); @@ -239,6 +255,4 @@ public void testExplodedWarWithResourceFileFiltering(WarExplodedMojo mojo) throw assertEquals("resource_key_1=this_is_filtered", reader.readLine(), "error in filtering using filter files"); assertEquals("resource_key_2=this_is_filtered", reader.readLine(), "error in filtering using filter files"); } - - } diff --git a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java index f419a35f..94c1b285 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java @@ -525,29 +525,6 @@ public void testOverlaysIncludesExcludesWithMultipleDefinitions2(WarExplodedMojo // Helpers - private void configureMojo( - WarExplodedMojo mojo, - File classesDir, - File webAppSource, - File webAppDirectory, - MavenProjectArtifactsStub project) { - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); - } - - private void configureMojo( - WarExplodedMojo mojo, File classesDir, File webAppSource, File webAppDirectory, File xmlSource) - throws Exception { - final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - mojo.setProject(project); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setWebXml(new File(xmlSource, "web.xml")); - } - private MavenProjectArtifactsStub createProjectWithOverlays(ArtifactStub... artifactStubs) throws Exception { final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); for (ArtifactStub artifactStub : artifactStubs) { From beafd97f7c830ec24f9af031d8d629c5f160268e Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 10 Dec 2025 15:31:34 +0100 Subject: [PATCH 27/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarOverlaysTest --- .../maven/plugins/war/WarOverlaysTest.java | 18 +++++++++--------- .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + .../source/jsp/b.jsp | 1 + .../source/org/sample/company/test.jsp | 1 + 5 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 src/test/resources/unit/waroverlays/default-overlays-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/waroverlays/default-overlays-test-data/source/pansit.jsp create mode 100644 src/test/resources/unit/waroverlays/scenario-one-default-settings-test-data/source/jsp/b.jsp create mode 100644 src/test/resources/unit/waroverlays/scenario-one-default-settings-test-data/source/org/sample/company/test.jsp diff --git a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java index 94c1b285..35ae0364 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java @@ -267,9 +267,7 @@ public void testScenarioOneWithOverlaySettings(WarExplodedMojo mojo) throws Exce @MojoParameter( name = "warSourceDirectory", value = "target/test-classes/unit/waroverlays/scenario-one-full-settings-test-data/source/") - @MojoParameter( - name = "webappDirectory", - value = "target/test-classes/unit/waroverlays/scenario-one-full-settings") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/waroverlays/scenario-one-full-settings") @Test public void testScenarioOneWithFullSettings(WarExplodedMojo mojo) throws Exception { // Add an overlay @@ -371,7 +369,6 @@ public void testOverlaysIncludesExcludesWithMultipleDefinitions(WarExplodedMojo final MavenProjectArtifactsStub project = createProjectWithOverlays(overlay1, overlay2, overlay3); mojo.setProject(project); - Overlay over1 = new DefaultOverlay(overlay3); over1.setExcludes("**/a.*,**/c.*,**/*.xml"); @@ -391,7 +388,6 @@ public void testOverlaysIncludesExcludesWithMultipleDefinitions(WarExplodedMojo mojo.addOverlay(mojo.getCurrentProjectOverlay()); mojo.addOverlay(over4); - mojo.execute(); File webAppDirectory = (File) getVariableValueFromObject(mojo, "webappDirectory"); @@ -422,7 +418,8 @@ public void testOverlaysIncludesExcludesWithMultipleDefinitions(WarExplodedMojo assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/a.jsp"); assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/b.jsp"); assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/c.jsp"); - assertDefaultFileContent("overlays-includes-excludes-multiple-defs", webAppDirectory, "org/sample/company/test.jsp"); + assertDefaultFileContent( + "overlays-includes-excludes-multiple-defs", webAppDirectory, "org/sample/company/test.jsp"); assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/web.xml"); assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.clazz"); assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.clazz"); @@ -442,10 +439,12 @@ public void testOverlaysIncludesExcludesWithMultipleDefinitions(WarExplodedMojo value = "target/test-classes/unit/waroverlays/war/work-overlays-includes-excludes-multiple-defs2") @MojoParameter( name = "classesDirectory", - value = "target/test-classes/unit/waroverlays/overlays-overlays-includes-excludes-multiple-defs2-test-data/classes") + value = + "target/test-classes/unit/waroverlays/overlays-includes-excludes-multiple-defs2-test-data/classes") @MojoParameter( name = "warSourceDirectory", - value = "target/test-classes/unit/waroverlays/overlays-overlays-includes-excludes-multiple-defs2-test-data/source/") + value = + "target/test-classes/unit/waroverlays/overlays-includes-excludes-multiple-defs2-test-data/source/") @MojoParameter( name = "webappDirectory", value = "target/test-classes/unit/waroverlays/overlays-includes-excludes-multiple-defs2") @@ -509,7 +508,8 @@ public void testOverlaysIncludesExcludesWithMultipleDefinitions2(WarExplodedMojo assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/a.jsp"); assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/b.jsp"); assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/c.jsp"); - assertDefaultFileContent("overlays-includes-excludes-multiple-defs2", webAppDirectory, "org/sample/company/test.jsp"); + assertDefaultFileContent( + "overlays-includes-excludes-multiple-defs2", webAppDirectory, "org/sample/company/test.jsp"); assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/web.xml"); assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.clazz"); assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.clazz"); diff --git a/src/test/resources/unit/waroverlays/default-overlays-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/waroverlays/default-overlays-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..c3701626 --- /dev/null +++ b/src/test/resources/unit/waroverlays/default-overlays-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/waroverlays/default-overlays-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/default-overlays-test-data/source/pansit.jsp b/src/test/resources/unit/waroverlays/default-overlays-test-data/source/pansit.jsp new file mode 100644 index 00000000..a8dfe165 --- /dev/null +++ b/src/test/resources/unit/waroverlays/default-overlays-test-data/source/pansit.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/waroverlays/default-overlays-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/scenario-one-default-settings-test-data/source/jsp/b.jsp b/src/test/resources/unit/waroverlays/scenario-one-default-settings-test-data/source/jsp/b.jsp new file mode 100644 index 00000000..f53d7fe2 --- /dev/null +++ b/src/test/resources/unit/waroverlays/scenario-one-default-settings-test-data/source/jsp/b.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/maven-war-plugin/target/test-classes/unit/waroverlays/scenario-one-default-settings-test-data/source/jsp/b.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/scenario-one-default-settings-test-data/source/org/sample/company/test.jsp b/src/test/resources/unit/waroverlays/scenario-one-default-settings-test-data/source/org/sample/company/test.jsp new file mode 100644 index 00000000..4468eded --- /dev/null +++ b/src/test/resources/unit/waroverlays/scenario-one-default-settings-test-data/source/org/sample/company/test.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/maven-war-plugin/target/test-classes/unit/waroverlays/scenario-one-default-settings-test-data/source/org/sample/company/test.jsp \ No newline at end of file From 2eaf70ddaa3db6d8ad6418bdf31e887fd0b99e95 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 10 Dec 2025 15:50:32 +0100 Subject: [PATCH 28/80] chore: spotless --- .../java/org/apache/maven/plugins/war/WarOverlaysTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java index 35ae0364..aac4b6a9 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java @@ -439,12 +439,10 @@ public void testOverlaysIncludesExcludesWithMultipleDefinitions(WarExplodedMojo value = "target/test-classes/unit/waroverlays/war/work-overlays-includes-excludes-multiple-defs2") @MojoParameter( name = "classesDirectory", - value = - "target/test-classes/unit/waroverlays/overlays-includes-excludes-multiple-defs2-test-data/classes") + value = "target/test-classes/unit/waroverlays/overlays-includes-excludes-multiple-defs2-test-data/classes") @MojoParameter( name = "warSourceDirectory", - value = - "target/test-classes/unit/waroverlays/overlays-includes-excludes-multiple-defs2-test-data/source/") + value = "target/test-classes/unit/waroverlays/overlays-includes-excludes-multiple-defs2-test-data/source/") @MojoParameter( name = "webappDirectory", value = "target/test-classes/unit/waroverlays/overlays-includes-excludes-multiple-defs2") From 08939da76d805785e9d1ab55a3a5c2d057ccda3d Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 10 Dec 2025 15:50:48 +0100 Subject: [PATCH 29/80] chore: exclude test file for rat --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 7be25eff..66df0dbf 100644 --- a/pom.xml +++ b/pom.xml @@ -250,6 +250,7 @@ ! No possibilities to add license information into a MANIFEST --> src/it/MWAR-167/src/main/resources/MANIFEST.MF + src/test/resources/** From 04069032d1c02c998412394b9837636a7843726e Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 10 Dec 2025 15:56:09 +0100 Subject: [PATCH 30/80] chore: clean up --- pom.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pom.xml b/pom.xml index 66df0dbf..d5b84148 100644 --- a/pom.xml +++ b/pom.xml @@ -208,12 +208,6 @@ ${mavenVersion} test - - - - - - org.junit.jupiter junit-jupiter-api From 8c1dfc2b474d0ed117b2ccac51cb71a5a0d0c5d0 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 10 Dec 2025 16:42:05 +0100 Subject: [PATCH 31/80] fix: absolute paths in tests --- .../java/org/apache/maven/plugins/war/WarOverlaysTest.java | 4 ++-- .../source/jsp/b.jsp | 2 +- .../source/org/sample/company/test.jsp | 2 +- .../source/jsp/b.jsp | 2 +- .../source/org/sample/company/test.jsp | 2 +- .../scenario-one-default-settings-test-data/source/jsp/b.jsp | 2 +- .../source/org/sample/company/test.jsp | 2 +- .../scenario-one-full-settings-test-data/source/jsp/b.jsp | 2 +- .../source/org/sample/company/test.jsp | 2 +- .../scenario-one-overlay-settings-test-data/source/jsp/b.jsp | 2 +- .../source/org/sample/company/test.jsp | 2 +- 11 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java index aac4b6a9..05083163 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java @@ -564,8 +564,8 @@ private void assertOverlayedFile(File webAppDirectory, String overlayId, String */ private void assertDefaultFileContent(String testId, File webAppDirectory, String filePath) throws Exception { final File webAppFile = new File(webAppDirectory, filePath); - final File sourceFile = new File(getWebAppSource(testId), filePath); - final String expectedContent = sourceFile.toString(); + // final File sourceFile = new File(getWebAppSource(testId), filePath); + final String expectedContent = filePath; assertEquals(expectedContent, FileUtils.fileRead(webAppFile), "Wrong content for file " + filePath); } diff --git a/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs-test-data/source/jsp/b.jsp b/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs-test-data/source/jsp/b.jsp index 653fe9f9..0f7cc91d 100644 --- a/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs-test-data/source/jsp/b.jsp +++ b/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs-test-data/source/jsp/b.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/maven-war-plugin/target/test-classes/unit/waroverlays/overlays-includes-excludes-multiple-defs-test-data/source/jsp/b.jsp \ No newline at end of file +target/test-classes/unit/waroverlays/overlays-includes-excludes-multiple-defs-test-data/source/jsp/b.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs-test-data/source/org/sample/company/test.jsp b/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs-test-data/source/org/sample/company/test.jsp index 898777b5..48214ce0 100644 --- a/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs-test-data/source/org/sample/company/test.jsp +++ b/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs-test-data/source/org/sample/company/test.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/maven-war-plugin/target/test-classes/unit/waroverlays/overlays-includes-excludes-multiple-defs-test-data/source/org/sample/company/test.jsp \ No newline at end of file +org/sample/company/test.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs2-test-data/source/jsp/b.jsp b/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs2-test-data/source/jsp/b.jsp index 51c2c0b7..43edc7e6 100644 --- a/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs2-test-data/source/jsp/b.jsp +++ b/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs2-test-data/source/jsp/b.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/maven-war-plugin/target/test-classes/unit/waroverlays/overlays-includes-excludes-multiple-defs2-test-data/source/jsp/b.jsp \ No newline at end of file +jsp/b.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs2-test-data/source/org/sample/company/test.jsp b/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs2-test-data/source/org/sample/company/test.jsp index b832bc40..48214ce0 100644 --- a/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs2-test-data/source/org/sample/company/test.jsp +++ b/src/test/resources/unit/waroverlays/overlays-includes-excludes-multiple-defs2-test-data/source/org/sample/company/test.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/maven-war-plugin/target/test-classes/unit/waroverlays/overlays-includes-excludes-multiple-defs2-test-data/source/org/sample/company/test.jsp \ No newline at end of file +org/sample/company/test.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/scenario-one-default-settings-test-data/source/jsp/b.jsp b/src/test/resources/unit/waroverlays/scenario-one-default-settings-test-data/source/jsp/b.jsp index f53d7fe2..43edc7e6 100644 --- a/src/test/resources/unit/waroverlays/scenario-one-default-settings-test-data/source/jsp/b.jsp +++ b/src/test/resources/unit/waroverlays/scenario-one-default-settings-test-data/source/jsp/b.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/maven-war-plugin/target/test-classes/unit/waroverlays/scenario-one-default-settings-test-data/source/jsp/b.jsp \ No newline at end of file +jsp/b.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/scenario-one-default-settings-test-data/source/org/sample/company/test.jsp b/src/test/resources/unit/waroverlays/scenario-one-default-settings-test-data/source/org/sample/company/test.jsp index 4468eded..48214ce0 100644 --- a/src/test/resources/unit/waroverlays/scenario-one-default-settings-test-data/source/org/sample/company/test.jsp +++ b/src/test/resources/unit/waroverlays/scenario-one-default-settings-test-data/source/org/sample/company/test.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/maven-war-plugin/target/test-classes/unit/waroverlays/scenario-one-default-settings-test-data/source/org/sample/company/test.jsp \ No newline at end of file +org/sample/company/test.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/scenario-one-full-settings-test-data/source/jsp/b.jsp b/src/test/resources/unit/waroverlays/scenario-one-full-settings-test-data/source/jsp/b.jsp index b67d138f..43edc7e6 100644 --- a/src/test/resources/unit/waroverlays/scenario-one-full-settings-test-data/source/jsp/b.jsp +++ b/src/test/resources/unit/waroverlays/scenario-one-full-settings-test-data/source/jsp/b.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/maven-war-plugin/target/test-classes/unit/waroverlays/scenario-one-full-settings-test-data/source/jsp/b.jsp \ No newline at end of file +jsp/b.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/scenario-one-full-settings-test-data/source/org/sample/company/test.jsp b/src/test/resources/unit/waroverlays/scenario-one-full-settings-test-data/source/org/sample/company/test.jsp index 276ac954..48214ce0 100644 --- a/src/test/resources/unit/waroverlays/scenario-one-full-settings-test-data/source/org/sample/company/test.jsp +++ b/src/test/resources/unit/waroverlays/scenario-one-full-settings-test-data/source/org/sample/company/test.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/maven-war-plugin/target/test-classes/unit/waroverlays/scenario-one-full-settings-test-data/source/org/sample/company/test.jsp \ No newline at end of file +org/sample/company/test.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/scenario-one-overlay-settings-test-data/source/jsp/b.jsp b/src/test/resources/unit/waroverlays/scenario-one-overlay-settings-test-data/source/jsp/b.jsp index d6b5d01a..43edc7e6 100644 --- a/src/test/resources/unit/waroverlays/scenario-one-overlay-settings-test-data/source/jsp/b.jsp +++ b/src/test/resources/unit/waroverlays/scenario-one-overlay-settings-test-data/source/jsp/b.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/maven-war-plugin/target/test-classes/unit/waroverlays/scenario-one-overlay-settings-test-data/source/jsp/b.jsp \ No newline at end of file +jsp/b.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/scenario-one-overlay-settings-test-data/source/org/sample/company/test.jsp b/src/test/resources/unit/waroverlays/scenario-one-overlay-settings-test-data/source/org/sample/company/test.jsp index ac0554b3..48214ce0 100644 --- a/src/test/resources/unit/waroverlays/scenario-one-overlay-settings-test-data/source/org/sample/company/test.jsp +++ b/src/test/resources/unit/waroverlays/scenario-one-overlay-settings-test-data/source/org/sample/company/test.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/maven-war-plugin/target/test-classes/unit/waroverlays/scenario-one-overlay-settings-test-data/source/org/sample/company/test.jsp \ No newline at end of file +org/sample/company/test.jsp \ No newline at end of file From 22ab68558b14c35a7316b8e2b6f664d077e5bcca Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Thu, 11 Dec 2025 13:25:09 +0100 Subject: [PATCH 32/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarExplodedMojoTest --- .../plugins/war/WarExplodedMojoTest.java | 34 +++++++++++++------ .../classes/sample-servlet.clazz | 1 + .../resources/pix/panis_na.jpg | 1 + .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + 5 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/classes/sample-servlet.clazz create mode 100644 src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/resources/pix/panis_na.jpg create mode 100644 src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/source/pansit.jsp diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index 32db3485..0d7f456a 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -24,7 +24,9 @@ import java.text.SimpleDateFormat; import java.util.Locale; +import org.apache.maven.api.plugin.testing.Basedir; 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.ArtifactHandler; @@ -65,21 +67,26 @@ protected File getTestDirectory() { } @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/SimpleExplodedWar") @Test public void testSimpleExplodedWar(WarExplodedMojo mojo) throws Exception { - // setup test data - String testId = "SimpleExplodedWar"; - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, false); - File webAppResource = new File(getTestDirectory(), testId + "-resources"); - File webAppDirectory = new File(getTestDirectory(), testId); - File sampleResource = new File(webAppResource, "pix/panis_na.jpg"); - ResourceStub[] resources = createWebResources(sampleResource, webAppResource); - - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, resources); + MavenProjectBasicStub project = new MavenProjectBasicStub(); + mojo.setProject(project); + ResourceStub[] resources = new ResourceStub[] {new ResourceStub()}; + resources[0].setDirectory(MojoExtension.getBasedir() + "/target/test-classes/unit/warexplodedmojo/SimpleExplodedWar-test-data/resources/"); + mojo.setWebResources(resources); mojo.execute(); // validate operation + File webAppDirectory = mojo.getWebappDirectory(); File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); File expectedWebResourceFile = new File(webAppDirectory, "pix/panis_na.jpg"); @@ -803,7 +810,12 @@ public void testExplodedWarWithOutputFileNameMapping(WarExplodedMojo mojo) throw // configure mojo mojo.setOutputFileNameMapping("@{artifactId}@.@{extension}@"); - configureMojo(mojo, jarArtifact, classesDir, webAppSource, webAppDirectory); + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + project.addArtifact(jarArtifact); + mojo.setClassesDirectory(classesDir); + mojo.setWarSourceDirectory(webAppSource); + mojo.setWebappDirectory(webAppDirectory); + mojo.setProject(project); mojo.execute(); // validate operation diff --git a/src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/classes/sample-servlet.clazz b/src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/classes/sample-servlet.clazz new file mode 100644 index 00000000..f6aa6393 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/classes/sample-servlet.clazz @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/SimpleExplodedWar-test-data/classes/sample-servlet.clazz \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/resources/pix/panis_na.jpg b/src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/resources/pix/panis_na.jpg new file mode 100644 index 00000000..d4ccd920 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/resources/pix/panis_na.jpg @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/SimpleExplodedWar-resources/pix/panis_na.jpg \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..f633b0fa --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/SimpleExplodedWar-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/source/pansit.jsp new file mode 100644 index 00000000..5fbfe8e8 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/source/pansit.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/SimpleExplodedWar-test-data/source/pansit.jsp \ No newline at end of file From 4a95489d330c232da70c04685e2e7f388ed130db Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Thu, 11 Dec 2025 13:39:36 +0100 Subject: [PATCH 33/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarExplodedMojoTest --- .../plugins/war/WarExplodedMojoTest.java | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index 0d7f456a..7bad1585 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -24,7 +24,6 @@ import java.text.SimpleDateFormat; import java.util.Locale; -import org.apache.maven.api.plugin.testing.Basedir; import org.apache.maven.api.plugin.testing.InjectMojo; import org.apache.maven.api.plugin.testing.MojoExtension; import org.apache.maven.api.plugin.testing.MojoParameter; @@ -73,15 +72,14 @@ protected File getTestDirectory() { @MojoParameter( name = "warSourceDirectory", value = "target/test-classes/unit/warexplodedmojo/SimpleExplodedWar-test-data/source/") - @MojoParameter( - name = "webappDirectory", - value = "target/test-classes/unit/warexplodedmojo/SimpleExplodedWar") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/SimpleExplodedWar") @Test public void testSimpleExplodedWar(WarExplodedMojo mojo) throws Exception { MavenProjectBasicStub project = new MavenProjectBasicStub(); mojo.setProject(project); ResourceStub[] resources = new ResourceStub[] {new ResourceStub()}; - resources[0].setDirectory(MojoExtension.getBasedir() + "/target/test-classes/unit/warexplodedmojo/SimpleExplodedWar-test-data/resources/"); + resources[0].setDirectory(MojoExtension.getBasedir() + + "/target/test-classes/unit/warexplodedmojo/SimpleExplodedWar-test-data/resources/"); mojo.setWebResources(resources); mojo.execute(); @@ -106,22 +104,27 @@ public void testSimpleExplodedWar(WarExplodedMojo mojo) throws Exception { } @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/SimpleExplodedWar") @Test public void testSimpleExplodedWarWTargetPath(WarExplodedMojo mojo) throws Exception { - // setup test data - String testId = "SimpleExplodedWar"; - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, false); - File webAppResource = new File(getTestDirectory(), "resources"); - File webAppDirectory = new File(getTestDirectory(), testId); - File sampleResource = new File(webAppResource, "pix/panis_na.jpg"); - ResourceStub[] resources = createWebResources(sampleResource, webAppResource); + ResourceStub[] resources = new ResourceStub[] {new ResourceStub()}; + resources[0].setDirectory(MojoExtension.getBasedir() + + "/target/test-classes/unit/warexplodedmojo/SimpleExplodedWar-test-data/resources/"); resources[0].setTargetPath("targetPath"); + mojo.setWebResources(resources); - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, resources); + MavenProjectBasicStub project = new MavenProjectBasicStub(); + mojo.setProject(project); mojo.execute(); // validate operation + File webAppDirectory = mojo.getWebappDirectory(); File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); File expectedWebResourceFile = new File(webAppDirectory, "targetPath/pix/panis_na.jpg"); From 4a925e27ccf6a49e84d95264531959599f83cbca Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Thu, 11 Dec 2025 13:45:06 +0100 Subject: [PATCH 34/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarExplodedMojoTest --- .../plugins/war/WarExplodedMojoTest.java | 37 +++++++------------ .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + .../xml-config/web.xml | 1 + 4 files changed, 17 insertions(+), 23 deletions(-) create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithCustomWebXML-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithCustomWebXML-test-data/source/pansit.jsp create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithCustomWebXML-test-data/xml-config/web.xml diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index 7bad1585..3a5ab9a1 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -143,36 +143,27 @@ public void testSimpleExplodedWarWTargetPath(WarExplodedMojo mojo) throws Except expectedWebResourceFile.delete(); } - private void configureMojo( - WarExplodedMojo mojo, File classesDir, File webAppSource, File webAppDirectory, ResourceStub[] resources) - throws Exception { - configureMojo(mojo, classesDir, webAppSource, webAppDirectory); - mojo.setWebResources(resources); - } - - private ResourceStub[] createWebResources(File sampleResource, File webAppResource) throws Exception { - ResourceStub[] resources = new ResourceStub[] {new ResourceStub()}; - createFile(sampleResource); - resources[0].setDirectory(webAppResource.getAbsolutePath()); - return resources; - } - @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithCustomWebXML-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithCustomWebXML-test-data/source/") + @MojoParameter( + name = "webXml", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithCustomWebXML-test-data/xml-config/web.xml") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithCustomWebXML") @Test public void testExplodedWarWithCustomWebXML(WarExplodedMojo mojo) throws Exception { - // setup test data - String testId = "ExplodedWarWithCustomWebXML"; - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - File webAppDirectory = new File(getTestDirectory(), testId); // configure mojo - configureMojo(mojo, classesDir, webAppSource, webAppDirectory); - mojo.setWebXml(new File(xmlSource, "web.xml")); + MavenProjectBasicStub project = new MavenProjectBasicStub(); + mojo.setProject(project); mojo.execute(); // validate operation + File webAppDirectory = mojo.getWebappDirectory(); File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); File expectedWEBXMLFile = new File(webAppDirectory, "WEB-INF/web.xml"); @@ -182,7 +173,7 @@ public void testExplodedWarWithCustomWebXML(WarExplodedMojo mojo) throws Excepti assertTrue(expectedWebSource2File.exists(), "source files not found: " + expectedWebSource2File); assertTrue(expectedWEBXMLFile.exists(), "WEB XML not found: " + expectedWEBXMLFile); assertTrue(expectedMETAINFDir.exists(), "META-INF not found"); - assertEquals(mojo.getWebXml().toString(), FileUtils.fileRead(expectedWEBXMLFile), "WEB XML not correct"); + assertEquals(mojo.getWebXml().getName(), FileUtils.fileRead(expectedWEBXMLFile), "WEB XML not correct"); // housekeeping expectedWebSourceFile.delete(); diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithCustomWebXML-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithCustomWebXML-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..52cd3e52 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithCustomWebXML-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithCustomWebXML-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithCustomWebXML-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithCustomWebXML-test-data/source/pansit.jsp new file mode 100644 index 00000000..ed172e27 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithCustomWebXML-test-data/source/pansit.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithCustomWebXML-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithCustomWebXML-test-data/xml-config/web.xml b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithCustomWebXML-test-data/xml-config/web.xml new file mode 100644 index 00000000..d188dff5 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithCustomWebXML-test-data/xml-config/web.xml @@ -0,0 +1 @@ +web.xml \ No newline at end of file From 387e5c46421dba150117feb480f28322d62362e8 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Thu, 11 Dec 2025 13:49:02 +0100 Subject: [PATCH 35/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarExplodedMojoTest --- .../plugins/war/WarExplodedMojoTest.java | 22 +++++++++++-------- .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + .../xml-config/config.xml | 1 + 4 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML-test-data/source/pansit.jsp create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML-test-data/xml-config/config.xml diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index 3a5ab9a1..26c9b318 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -183,21 +183,25 @@ public void testExplodedWarWithCustomWebXML(WarExplodedMojo mojo) throws Excepti } @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML-test-data/source/") + @MojoParameter( + name = "containerConfigXML", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML-test-data/xml-config/config.xml") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML") @Test public void testExplodedWarWithContainerConfigXML(WarExplodedMojo mojo) throws Exception { - // setup test data - String testId = "ExplodedWarWithContainerConfigXML"; - File classesDir = createClassesDir(testId, true); - File webAppSource = createWebAppSource(testId); - File xmlSource = createXMLConfigDir(testId, new String[] {"config.xml"}); - File webAppDirectory = new File(getTestDirectory(), testId); - // configure mojo - configureMojo(mojo, classesDir, webAppSource, webAppDirectory); - mojo.setContainerConfigXML(new File(xmlSource, "config.xml")); + MavenProjectBasicStub project = new MavenProjectBasicStub(); + mojo.setProject(project); mojo.execute(); // validate operation + File webAppDirectory = mojo.getWebappDirectory(); File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); File expectedContainerConfigXMLFile = new File(webAppDirectory, "META-INF/config.xml"); diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..cbcdaad0 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithContainerConfigXML-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML-test-data/source/pansit.jsp new file mode 100644 index 00000000..212eb3eb --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML-test-data/source/pansit.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithContainerConfigXML-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML-test-data/xml-config/config.xml b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML-test-data/xml-config/config.xml new file mode 100644 index 00000000..22885586 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML-test-data/xml-config/config.xml @@ -0,0 +1 @@ +config.xml \ No newline at end of file From 2cb920587a46bf20147a2f2b34d899360650801e Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Thu, 11 Dec 2025 14:25:38 +0100 Subject: [PATCH 36/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarExplodedMojoTest --- .../plugins/war/WarExplodedMojoTest.java | 20 ++++++++++++------- .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + 3 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithSimpleExternalWARFile-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithSimpleExternalWARFile-test-data/source/pansit.jsp diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index 26c9b318..49f267a8 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -225,23 +225,29 @@ public void testExplodedWarWithContainerConfigXML(WarExplodedMojo mojo) throws E * @throws Exception in case of an error. */ @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithSimpleExternalWARFile-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithSimpleExternalWARFile-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithSimpleExternalWARFile") @MojoParameter( name = "workDirectory", value = "target/test-classes/unit/warexplodedmojo/test-dir/war/work-ExplodedWarWithSimpleExternalWARFile") @Test public void testExplodedWarWithSimpleExternalWARFile(WarExplodedMojo mojo) throws Exception { - // setup test data - String testId = "ExplodedWarWithSimpleExternalWARFile"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - // configure mojo WarArtifactStub warArtifact = new WarArtifactStub(getBasedir()); - configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory); + File simpleWarFile = warArtifact.getFile(); + assertTrue(simpleWarFile.exists(), "simple war not found: " + simpleWarFile.toString()); + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + project.addArtifact(warArtifact); + mojo.setProject(project); mojo.execute(); // validate operation - META-INF is automatically excluded so remove the file from the list + File webAppDirectory = mojo.getWebappDirectory(); File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); File expectedWEBXMLFile = new File(webAppDirectory, "WEB-INF/web.xml"); diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithSimpleExternalWARFile-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithSimpleExternalWARFile-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..dabd1956 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithSimpleExternalWARFile-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithSimpleExternalWARFile-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithSimpleExternalWARFile-test-data/source/pansit.jsp new file mode 100644 index 00000000..27b3fb80 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithSimpleExternalWARFile-test-data/source/pansit.jsp @@ -0,0 +1 @@ +pansit.jsp \ No newline at end of file From 6b57fd70bfebcec1cbe317b6646dedf984b58aa8 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Thu, 11 Dec 2025 14:38:51 +0100 Subject: [PATCH 37/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarExplodedMojoTest --- .../plugins/war/WarExplodedMojoTest.java | 32 ++++++++----------- .../source/org/sample/company/test.jsp | 1 + 2 files changed, 15 insertions(+), 18 deletions(-) create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarMergeWarLocalFileOverride-test-data/source/org/sample/company/test.jsp diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index 49f267a8..a75a3698 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -239,8 +239,6 @@ public void testExplodedWarWithContainerConfigXML(WarExplodedMojo mojo) throws E public void testExplodedWarWithSimpleExternalWARFile(WarExplodedMojo mojo) throws Exception { // configure mojo WarArtifactStub warArtifact = new WarArtifactStub(getBasedir()); - File simpleWarFile = warArtifact.getFile(); - assertTrue(simpleWarFile.exists(), "simple war not found: " + simpleWarFile.toString()); MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); project.addArtifact(warArtifact); mojo.setProject(project); @@ -271,45 +269,43 @@ public void testExplodedWarWithSimpleExternalWARFile(WarExplodedMojo mojo) throw * @throws Exception in case of an error. */ @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarMergeWarLocalFileOverride-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarMergeWarLocalFileOverride-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarMergeWarLocalFileOverride") @MojoParameter( name = "workDirectory", value = - "target/test-classes/unit/warexplodedmojo/test-dir/war/work-testExplodedWarMergeWarLocalFileOverride") + "target/test-classes/unit/warexplodedmojo/test-dir/war/work-ExplodedWarMergeWarLocalFileOverride") @Test public void testExplodedWarMergeWarLocalFileOverride(WarExplodedMojo mojo) throws Exception { - // setup test data - String testId = "testExplodedWarMergeWarLocalFileOverride"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = getWebAppSource(testId); - File simpleJSP = new File(webAppSource, "org/sample/company/test.jsp"); - createFile(simpleJSP); - File classesDir = createClassesDir(testId, true); - // configure mojo WarArtifactStub warArtifact = new WarArtifactStub(getBasedir()); MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); project.addArtifact(warArtifact); - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + mojo.setProject(project); mojo.execute(); // validate operation + File webAppDirectory = mojo.getWebappDirectory(); File expectedFile = new File(webAppDirectory, "/org/sample/company/test.jsp"); assertTrue(expectedFile.exists(), "file not found: " + expectedFile); - assertEquals(simpleJSP.toString(), FileUtils.fileRead(expectedFile), "file incorrect"); + assertEquals("org/sample/company/test.jsp", FileUtils.fileRead(expectedFile), "file incorrect"); // check when the merged war file is newer - so set an old time on the local file + File simpleJSP = new File(MojoExtension.getBasedir(), "target/test-classes/unit/warexplodedmojo/testExplodedWarMergeWarLocalFileOverride-test-data/source/org/sample/company/test.jsp"); long time = new SimpleDateFormat("yyyy-MM-dd", Locale.US).parse("2005-1-1").getTime(); simpleJSP.setLastModified(time); - expectedFile.setLastModified(time); - - project.addArtifact(warArtifact); - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); mojo.execute(); + expectedFile.setLastModified(time); assertTrue(expectedFile.exists(), "file not found: " + expectedFile); - assertEquals(simpleJSP.toString(), FileUtils.fileRead(expectedFile), "file incorrect"); + assertEquals("org/sample/company/test.jsp", FileUtils.fileRead(expectedFile), "file incorrect"); // housekeeping expectedFile.delete(); diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarMergeWarLocalFileOverride-test-data/source/org/sample/company/test.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarMergeWarLocalFileOverride-test-data/source/org/sample/company/test.jsp new file mode 100644 index 00000000..48214ce0 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarMergeWarLocalFileOverride-test-data/source/org/sample/company/test.jsp @@ -0,0 +1 @@ +org/sample/company/test.jsp \ No newline at end of file From eebd8a90150a9fd99c080c55ca6790c8889eb7a2 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Thu, 11 Dec 2025 14:41:11 +0100 Subject: [PATCH 38/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarExplodedMojoTest --- .../plugins/war/WarExplodedMojoTest.java | 20 +++++++++++-------- .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + 3 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithEJB-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithEJB-test-data/source/pansit.jsp diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index a75a3698..0915cb2e 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -312,20 +312,24 @@ public void testExplodedWarMergeWarLocalFileOverride(WarExplodedMojo mojo) throw } @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithEJB-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithEJB-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithEJB") @Test public void testExplodedWarWithEJB(WarExplodedMojo mojo) throws Exception { - // setup test data - String testId = "ExplodedWarWithEJB"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - EJBArtifactStub ejbArtifact = new EJBArtifactStub(getBasedir()); - // configure mojo - configureMojo(mojo, ejbArtifact, classesDir, webAppSource, webAppDirectory); + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + EJBArtifactStub ejbArtifact = new EJBArtifactStub(getBasedir()); + project.addArtifact(ejbArtifact); + mojo.setProject(project); mojo.execute(); // validate operation + File webAppDirectory = mojo.getWebappDirectory(); File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); // final name form is -. diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithEJB-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithEJB-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..dabd1956 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithEJB-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithEJB-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithEJB-test-data/source/pansit.jsp new file mode 100644 index 00000000..27b3fb80 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithEJB-test-data/source/pansit.jsp @@ -0,0 +1 @@ +pansit.jsp \ No newline at end of file From 544a109d3a3951302a68b6ecbd2c41a1629fa631 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Thu, 11 Dec 2025 14:58:42 +0100 Subject: [PATCH 39/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarExplodedMojoTest --- .../plugins/war/WarExplodedMojoTest.java | 22 +++++++++++-------- .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + 3 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithJar-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithJar-test-data/source/pansit.jsp diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index 0915cb2e..945b9515 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -29,6 +29,7 @@ import org.apache.maven.api.plugin.testing.MojoParameter; import org.apache.maven.api.plugin.testing.MojoTest; import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.handler.DefaultArtifactHandler; import org.apache.maven.plugin.testing.stubs.ArtifactStub; import org.apache.maven.plugins.war.stub.AarArtifactStub; import org.apache.maven.plugins.war.stub.EJBArtifactStub; @@ -346,21 +347,24 @@ public void testExplodedWarWithEJB(WarExplodedMojo mojo) throws Exception { } @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithJar-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithJar-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithJar") @Test - @Disabled // TODO interpolation of extension does not work public void testExplodedWarWithJar(WarExplodedMojo mojo) throws Exception { - // setup test data - String testId = "ExplodedWarWithJar"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - ArtifactStub jarArtifact = new JarArtifactStub(getBasedir(), artifactHandler); - // configure mojo - configureMojo(mojo, jarArtifact, classesDir, webAppSource, webAppDirectory); + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + ArtifactStub jarArtifact = new JarArtifactStub(getBasedir(), new DefaultArtifactHandler("jar")); + project.addArtifact(jarArtifact); + mojo.setProject(project); mojo.execute(); // validate operation + File webAppDirectory = mojo.getWebappDirectory(); File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); // final name form is -. diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithJar-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithJar-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..dabd1956 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithJar-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithJar-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithJar-test-data/source/pansit.jsp new file mode 100644 index 00000000..27b3fb80 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithJar-test-data/source/pansit.jsp @@ -0,0 +1 @@ +pansit.jsp \ No newline at end of file From bd49ffb69e499a56107aed203eb8cb7535abf1e1 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Thu, 11 Dec 2025 15:00:15 +0100 Subject: [PATCH 40/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarExplodedMojoTest --- .../plugins/war/WarExplodedMojoTest.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index 945b9515..200014ae 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -384,20 +384,24 @@ public void testExplodedWarWithJar(WarExplodedMojo mojo) throws Exception { * @throws Exception in case of an error. */ @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithEJB-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithEJB-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithEJB") @Test public void testExplodedWarWithEJBClient(WarExplodedMojo mojo) throws Exception { - // setup test data - String testId = "ExplodedWarWithEJB"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - EJBClientArtifactStub ejbArtifact = new EJBClientArtifactStub(getBasedir()); - // configure mojo - configureMojo(mojo, ejbArtifact, classesDir, webAppSource, webAppDirectory); + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + EJBClientArtifactStub ejbArtifact = new EJBClientArtifactStub(getBasedir()); + project.addArtifact(ejbArtifact); + mojo.setProject(project); mojo.execute(); // validate operation + File webAppDirectory = mojo.getWebappDirectory(); File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); // final name form is -. From d8402da0b2e37c2e2345c487dc7586ef47052596 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Thu, 11 Dec 2025 15:03:10 +0100 Subject: [PATCH 41/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarExplodedMojoTest --- .../plugins/war/WarExplodedMojoTest.java | 20 +++++++++++-------- .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + 3 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithTLD-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithTLD-test-data/source/pansit.jsp diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index 200014ae..fc1afd2a 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -421,20 +421,24 @@ public void testExplodedWarWithEJBClient(WarExplodedMojo mojo) throws Exception * @throws Exception in case of an error. */ @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithTLD-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithTLD-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithTLD") @Test public void testExplodedWarWithTLD(WarExplodedMojo mojo) throws Exception { - // setup test data - String testId = "ExplodedWarWithTLD"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - TLDArtifactStub tldArtifact = new TLDArtifactStub(getBasedir()); - // configure mojo - configureMojo(mojo, tldArtifact, classesDir, webAppSource, webAppDirectory); + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + TLDArtifactStub tldArtifact = new TLDArtifactStub(getBasedir()); + project.addArtifact(tldArtifact); + mojo.setProject(project); mojo.execute(); // validate operation + File webAppDirectory = mojo.getWebappDirectory(); File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); // final name form is -. diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithTLD-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithTLD-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..dabd1956 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithTLD-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithTLD-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithTLD-test-data/source/pansit.jsp new file mode 100644 index 00000000..27b3fb80 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithTLD-test-data/source/pansit.jsp @@ -0,0 +1 @@ +pansit.jsp \ No newline at end of file From c88919e1c4582c2c3e557bf52494479810a113d8 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Thu, 11 Dec 2025 15:10:17 +0100 Subject: [PATCH 42/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarExplodedMojoTest --- .../plugins/war/WarExplodedMojoTest.java | 20 +++++++++++-------- .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + 3 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithPAR-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithPAR-test-data/source/pansit.jsp diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index fc1afd2a..9b663b37 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -455,20 +455,24 @@ public void testExplodedWarWithTLD(WarExplodedMojo mojo) throws Exception { } @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithPAR-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithPAR-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithPAR") @Test public void testExplodedWarWithPAR(WarExplodedMojo mojo) throws Exception { - // setup test data - String testId = "ExplodedWarWithPAR"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - PARArtifactStub parartifact = new PARArtifactStub(getBasedir()); - // configure mojo - configureMojo(mojo, parartifact, classesDir, webAppSource, webAppDirectory); + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + PARArtifactStub parartifact = new PARArtifactStub(getBasedir()); + project.addArtifact(parartifact); + mojo.setProject(project); mojo.execute(); // validate operation + File webAppDirectory = mojo.getWebappDirectory(); File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); // final name form is -. diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithPAR-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithPAR-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..dabd1956 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithPAR-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithPAR-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithPAR-test-data/source/pansit.jsp new file mode 100644 index 00000000..27b3fb80 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithPAR-test-data/source/pansit.jsp @@ -0,0 +1 @@ +pansit.jsp \ No newline at end of file From b57bb961a356932fcb8bbf8a41f95ad75b7ab3d1 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Thu, 11 Dec 2025 15:12:42 +0100 Subject: [PATCH 43/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarExplodedMojoTest --- .../plugins/war/WarExplodedMojoTest.java | 20 +++++++++++-------- .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + 3 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithAar-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithAar-test-data/source/pansit.jsp diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index 9b663b37..72fd1058 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -489,21 +489,25 @@ public void testExplodedWarWithPAR(WarExplodedMojo mojo) throws Exception { } @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithAar-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithAar-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithAar") @Test - @Disabled // TODO interpolation of extension does not work public void testExplodedWarWithAar(WarExplodedMojo mojo) throws Exception { - // setup test data - String testId = "ExplodedWarWithAar"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - ArtifactStub aarArtifact = new AarArtifactStub(getBasedir(), artifactHandler); // configure mojo - configureMojo(mojo, aarArtifact, classesDir, webAppSource, webAppDirectory); + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + ArtifactStub aarArtifact = new AarArtifactStub(getBasedir(), new DefaultArtifactHandler("jar")); + project.addArtifact(aarArtifact); + mojo.setProject(project); mojo.execute(); // validate operation + File webAppDirectory = mojo.getWebappDirectory(); File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); // final name form is -. diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithAar-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithAar-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..dabd1956 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithAar-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithAar-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithAar-test-data/source/pansit.jsp new file mode 100644 index 00000000..27b3fb80 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithAar-test-data/source/pansit.jsp @@ -0,0 +1 @@ +pansit.jsp \ No newline at end of file From d08a2bf7b07318a4ef551b4266d47f3563bc022a Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Thu, 11 Dec 2025 15:14:38 +0100 Subject: [PATCH 44/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarExplodedMojoTest --- .../plugins/war/WarExplodedMojoTest.java | 22 ++++++++++--------- .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + 3 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithMar-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithMar-test-data/source/pansit.jsp diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index 72fd1058..7918fb62 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -498,7 +498,6 @@ public void testExplodedWarWithPAR(WarExplodedMojo mojo) throws Exception { @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithAar") @Test public void testExplodedWarWithAar(WarExplodedMojo mojo) throws Exception { - // configure mojo MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); ArtifactStub aarArtifact = new AarArtifactStub(getBasedir(), new DefaultArtifactHandler("jar")); @@ -524,21 +523,24 @@ public void testExplodedWarWithAar(WarExplodedMojo mojo) throws Exception { } @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithMar-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithMar-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithMar") @Test - @Disabled // TODO interpolation of extension does not work public void testExplodedWarWithMar(WarExplodedMojo mojo) throws Exception { - // setup test data - String testId = "ExplodedWarWithMar"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - ArtifactStub marArtifact = new MarArtifactStub(getBasedir(), artifactHandler); - // configure mojo - configureMojo(mojo, marArtifact, classesDir, webAppSource, webAppDirectory); + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + ArtifactStub marArtifact = new MarArtifactStub(getBasedir(), new DefaultArtifactHandler("jar")); + project.addArtifact(marArtifact); + mojo.setProject(project); mojo.execute(); // validate operation + File webAppDirectory = mojo.getWebappDirectory(); File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); // final name form is -. diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithMar-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithMar-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..dabd1956 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithMar-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithMar-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithMar-test-data/source/pansit.jsp new file mode 100644 index 00000000..27b3fb80 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithMar-test-data/source/pansit.jsp @@ -0,0 +1 @@ +pansit.jsp \ No newline at end of file From e9c7d891a3ba2257a151fbf4218afb518ce88773 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Thu, 11 Dec 2025 15:16:55 +0100 Subject: [PATCH 45/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarExplodedMojoTest --- .../plugins/war/WarExplodedMojoTest.java | 21 +++++++++++-------- .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + 3 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithXar-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithXar-test-data/source/pansit.jsp diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index 7918fb62..dde5a33f 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -557,21 +557,24 @@ public void testExplodedWarWithMar(WarExplodedMojo mojo) throws Exception { } @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithXar-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithXar-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithXar") @Test - @Disabled // TODO interpolation of extension does not work public void testExplodedWarWithXar(WarExplodedMojo mojo) throws Exception { - // setup test data - String testId = "ExplodedWarWithXar"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - ArtifactStub xarArtifact = new XarArtifactStub(getBasedir(), artifactHandler); - // configure mojo - configureMojo(mojo, xarArtifact, classesDir, webAppSource, webAppDirectory); + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + ArtifactStub xarArtifact = new XarArtifactStub(getBasedir(), new DefaultArtifactHandler("jar")); + project.addArtifact(xarArtifact); + mojo.setProject(project); mojo.execute(); // validate operation + File webAppDirectory = mojo.getWebappDirectory(); File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); // final name form is -. diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithXar-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithXar-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..dabd1956 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithXar-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithXar-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithXar-test-data/source/pansit.jsp new file mode 100644 index 00000000..27b3fb80 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithXar-test-data/source/pansit.jsp @@ -0,0 +1 @@ +pansit.jsp \ No newline at end of file From 0e79997cec82c45791409363799d3ebd696a2b5e Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Thu, 11 Dec 2025 15:19:06 +0100 Subject: [PATCH 46/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarExplodedMojoTest --- .../maven/plugins/war/WarExplodedMojoTest.java | 16 +++++++++++----- .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + 3 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithDuplicateDependencies-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithDuplicateDependencies-test-data/source/pansit.jsp diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index dde5a33f..f1124f0b 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -591,27 +591,33 @@ public void testExplodedWarWithXar(WarExplodedMojo mojo) throws Exception { } @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithDuplicateDependencies-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithDuplicateDependencies-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithDuplicateDependencies") @Test public void testExplodedWarWithDuplicateDependencies(WarExplodedMojo mojo) throws Exception { // setup test data String testId = "ExplodedWarWithDuplicateDependencies"; - File webAppDirectory = new File(getTestDirectory(), testId); File webAppSource = createWebAppSource(testId); File classesDir = createClassesDir(testId, true); + + // configure mojo EJBArtifactStub ejbArtifact = new EJBArtifactStub(getBasedir()); ejbArtifact.setGroupId("org.sample.ejb"); EJBArtifactStub ejbArtifactDup = new EJBArtifactStub(getBasedir()); ejbArtifactDup.setGroupId("org.dup.ejb"); - - // configure mojo - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); project.addArtifact(ejbArtifact); project.addArtifact(ejbArtifactDup); - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + mojo.setProject(project); mojo.execute(); // validate operation + File webAppDirectory = mojo.getWebappDirectory(); File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); // final name form is -. diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithDuplicateDependencies-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithDuplicateDependencies-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..dabd1956 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithDuplicateDependencies-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithDuplicateDependencies-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithDuplicateDependencies-test-data/source/pansit.jsp new file mode 100644 index 00000000..27b3fb80 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithDuplicateDependencies-test-data/source/pansit.jsp @@ -0,0 +1 @@ +pansit.jsp \ No newline at end of file From f4fdf98ff783ab8987c6e373b7594e8f5d08ed79 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Thu, 11 Dec 2025 15:26:41 +0100 Subject: [PATCH 47/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarExplodedMojoTest --- .../plugins/war/WarExplodedMojoTest.java | 38 ++++++++++--------- .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + .../classes/sample-servlet.clazz | 1 + .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + 6 files changed, 26 insertions(+), 17 deletions(-) create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarDuplicateWithClassifier-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarDuplicateWithClassifier-test-data/source/pansit.jsp create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithClasses-test-data/classes/sample-servlet.clazz create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithClasses-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithClasses-test-data/source/pansit.jsp diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index f1124f0b..6dcf2e22 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -640,28 +640,29 @@ public void testExplodedWarWithDuplicateDependencies(WarExplodedMojo mojo) throw * @throws Exception in case of an error. */ @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarDuplicateWithClassifier-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarDuplicateWithClassifier-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarDuplicateWithClassifier") @Test public void testExplodedWarDuplicateWithClassifier(WarExplodedMojo mojo) throws Exception { - // setup test data - String testId = "ExplodedWarDuplicateWithClassifier"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); + // configure mojo + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); EJBArtifactStub ejbArtifact = new EJBArtifactStub(getBasedir()); ejbArtifact.setGroupId("org.sample.ejb"); EJBArtifactStubWithClassifier ejbArtifactDup = new EJBArtifactStubWithClassifier(getBasedir()); ejbArtifactDup.setGroupId("org.sample.ejb"); ejbArtifactDup.setClassifier("classifier"); - - // configure mojo - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); project.addArtifact(ejbArtifact); project.addArtifact(ejbArtifactDup); - - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + mojo.setProject(project); mojo.execute(); // validate operation + File webAppDirectory = mojo.getWebappDirectory(); File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); // final name form is -. @@ -684,19 +685,22 @@ public void testExplodedWarDuplicateWithClassifier(WarExplodedMojo mojo) throws * @throws Exception in case of an error. */ @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithClasses-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithClasses-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithClasses") @Test public void testExplodedWarWithClasses(WarExplodedMojo mojo) throws Exception { - // setup test data - String testId = "ExplodedWarWithClasses"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, false); - // configure mojo - configureMojo(mojo, classesDir, webAppSource, webAppDirectory); + MavenProjectBasicStub project = new MavenProjectBasicStub(); + mojo.setProject(project); mojo.execute(); // validate operation + File webAppDirectory = mojo.getWebappDirectory(); File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); // final name form is -. diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarDuplicateWithClassifier-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarDuplicateWithClassifier-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..dabd1956 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarDuplicateWithClassifier-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarDuplicateWithClassifier-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarDuplicateWithClassifier-test-data/source/pansit.jsp new file mode 100644 index 00000000..27b3fb80 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarDuplicateWithClassifier-test-data/source/pansit.jsp @@ -0,0 +1 @@ +pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithClasses-test-data/classes/sample-servlet.clazz b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithClasses-test-data/classes/sample-servlet.clazz new file mode 100644 index 00000000..6840e3fd --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithClasses-test-data/classes/sample-servlet.clazz @@ -0,0 +1 @@ +sample-servlet.clazz \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithClasses-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithClasses-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..dabd1956 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithClasses-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithClasses-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithClasses-test-data/source/pansit.jsp new file mode 100644 index 00000000..27b3fb80 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithClasses-test-data/source/pansit.jsp @@ -0,0 +1 @@ +pansit.jsp \ No newline at end of file From 2a5d82c5b0a463c6bbe2575f4f02f114ed577f22 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Thu, 11 Dec 2025 15:28:37 +0100 Subject: [PATCH 48/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarExplodedMojoTest --- .../maven/plugins/war/WarExplodedMojoTest.java | 17 ++++++++++------- .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + 3 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithSourceIncludeExclude-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithSourceIncludeExclude-test-data/source/pansit.jsp diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index 6dcf2e22..a7ceccb3 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -717,21 +717,24 @@ public void testExplodedWarWithClasses(WarExplodedMojo mojo) throws Exception { } @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithSourceIncludeExclude-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithSourceIncludeExclude-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithSourceIncludeExclude") @MojoParameter(name = "warSourceIncludes", value = "**/*sit.jsp") @MojoParameter(name = "warSourceExcludes", value = "**/last*.*") @Test public void testExplodedWarWithSourceIncludeExclude(WarExplodedMojo mojo) throws Exception { - // setup test data - String testId = "ExplodedWarWithSourceIncludeExclude"; - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - File webAppDirectory = new File(getTestDirectory(), testId); - // configure mojo - configureMojo(mojo, classesDir, webAppSource, webAppDirectory); + MavenProjectBasicStub project = new MavenProjectBasicStub(); + mojo.setProject(project); mojo.execute(); // validate operation + File webAppDirectory = mojo.getWebappDirectory(); File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); File expectedWEBXMLDir = new File(webAppDirectory, "WEB-INF"); diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithSourceIncludeExclude-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithSourceIncludeExclude-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..dabd1956 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithSourceIncludeExclude-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithSourceIncludeExclude-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithSourceIncludeExclude-test-data/source/pansit.jsp new file mode 100644 index 00000000..27b3fb80 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithSourceIncludeExclude-test-data/source/pansit.jsp @@ -0,0 +1 @@ +pansit.jsp \ No newline at end of file From 56b9986eec5f6579a7876c0b849a1416be6b28b2 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Thu, 11 Dec 2025 15:31:50 +0100 Subject: [PATCH 49/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarExplodedMojoTest --- .../plugins/war/WarExplodedMojoTest.java | 20 +++++++++++-------- .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + 3 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithWarDependencyIncludeExclude-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithWarDependencyIncludeExclude-test-data/source/pansit.jsp diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index a7ceccb3..0784c3c1 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -753,6 +753,13 @@ public void testExplodedWarWithSourceIncludeExclude(WarExplodedMojo mojo) throws } @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithWarDependencyIncludeExclude-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithWarDependencyIncludeExclude-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithWarDependencyIncludeExclude") @MojoParameter(name = "dependentWarIncludes", value = "**/*Include.jsp,**/*.xml") @MojoParameter(name = "dependentWarExcludes", value = "**/*Exclude*,**/MANIFEST.MF") @MojoParameter( @@ -761,18 +768,15 @@ public void testExplodedWarWithSourceIncludeExclude(WarExplodedMojo mojo) throws "target/test-classes/unit/warexplodedmojo/test-dir/war/work-ExplodedWarWithWarDependencyIncludeExclude") @Test public void testExplodedWarWithWarDependencyIncludeExclude(WarExplodedMojo mojo) throws Exception { - // setup test data - String testId = "ExplodedWarWithWarDependencyIncludeExclude"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - - IncludeExcludeWarArtifactStub includeexcludeWarArtifact = new IncludeExcludeWarArtifactStub(getBasedir()); // configure mojo - configureMojo(mojo, includeexcludeWarArtifact, classesDir, webAppSource, webAppDirectory); + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + IncludeExcludeWarArtifactStub includeexcludeWarArtifact = new IncludeExcludeWarArtifactStub(getBasedir()); + project.addArtifact(includeexcludeWarArtifact); + mojo.setProject(project); mojo.execute(); // validate operation + File webAppDirectory = mojo.getWebappDirectory(); File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); File expectedManifestFile = new File(webAppDirectory, "META-INF/MANIFEST.MF"); diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithWarDependencyIncludeExclude-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithWarDependencyIncludeExclude-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..dabd1956 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithWarDependencyIncludeExclude-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithWarDependencyIncludeExclude-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithWarDependencyIncludeExclude-test-data/source/pansit.jsp new file mode 100644 index 00000000..27b3fb80 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithWarDependencyIncludeExclude-test-data/source/pansit.jsp @@ -0,0 +1 @@ +pansit.jsp \ No newline at end of file From aa12c7d017f319c776f200308c35b23cc7894cce Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Thu, 11 Dec 2025 15:37:03 +0100 Subject: [PATCH 50/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarExplodedMojoTest --- .../maven/plugins/war/WarExplodedMojoTest.java | 18 ++++++++++-------- .../classes/sample-servlet.clazz | 1 + .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + 4 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithSourceModificationCheck-test-data/classes/sample-servlet.clazz create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithSourceModificationCheck-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithSourceModificationCheck-test-data/source/pansit.jsp diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index 0784c3c1..67e081a6 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -802,23 +802,25 @@ public void testExplodedWarWithWarDependencyIncludeExclude(WarExplodedMojo mojo) } @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithSourceModificationCheck-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithSourceModificationCheck-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithSourceModificationCheck") @Test public void testExplodedWarWithSourceModificationCheck(WarExplodedMojo mojo) throws Exception { - // setup test data - String testId = "ExplodedWarWithSourceModificationCheck"; - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, false); - File webAppDirectory = new File(getTestDirectory(), testId); - // configure mojo - configureMojo(mojo, classesDir, webAppSource, webAppDirectory); + MavenProjectBasicStub project = new MavenProjectBasicStub(); + mojo.setProject(project); // destination file is already created manually containing an "error" string // source is newer than the destination file mojo.execute(); // validate operation - + File webAppDirectory = mojo.getWebappDirectory(); File expectedWEBINFDir = new File(webAppDirectory, "WEB-INF"); File expectedMETAINFDir = new File(webAppDirectory, "META-INF"); File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithSourceModificationCheck-test-data/classes/sample-servlet.clazz b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithSourceModificationCheck-test-data/classes/sample-servlet.clazz new file mode 100644 index 00000000..6840e3fd --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithSourceModificationCheck-test-data/classes/sample-servlet.clazz @@ -0,0 +1 @@ +sample-servlet.clazz \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithSourceModificationCheck-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithSourceModificationCheck-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..dabd1956 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithSourceModificationCheck-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithSourceModificationCheck-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithSourceModificationCheck-test-data/source/pansit.jsp new file mode 100644 index 00000000..27b3fb80 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithSourceModificationCheck-test-data/source/pansit.jsp @@ -0,0 +1 @@ +pansit.jsp \ No newline at end of file From aca9bce7ebc1ba217825c561d076e7f68d3b4497 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Thu, 11 Dec 2025 15:41:45 +0100 Subject: [PATCH 51/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarExplodedMojoTest --- .../plugins/war/WarExplodedMojoTest.java | 22 +++++++++---------- .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + 3 files changed, 12 insertions(+), 12 deletions(-) create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithFileNameMapping-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithFileNameMapping-test-data/source/pansit.jsp diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index 67e081a6..6debafe4 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -846,27 +846,25 @@ public void testExplodedWarWithSourceModificationCheck(WarExplodedMojo mojo) thr } @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithFileNameMapping-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithFileNameMapping-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithFileNameMapping") + @MojoParameter(name = "outputFileNameMapping", value = "@{artifactId}@.@{extension}@") @Test - @Disabled // TODO interpolation of extension does not work public void testExplodedWarWithOutputFileNameMapping(WarExplodedMojo mojo) throws Exception { - // setup test data - String testId = "ExplodedWarWithFileNameMapping"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - ArtifactStub jarArtifact = new JarArtifactStub(getBasedir(), artifactHandler); - // configure mojo - mojo.setOutputFileNameMapping("@{artifactId}@.@{extension}@"); MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); + ArtifactStub jarArtifact = new JarArtifactStub(getBasedir(), new DefaultArtifactHandler("jar")); project.addArtifact(jarArtifact); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); mojo.setProject(project); mojo.execute(); // validate operation + File webAppDirectory = mojo.getWebappDirectory(); File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); // final name form is -. diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithFileNameMapping-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithFileNameMapping-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..7c7d8b57 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithFileNameMapping-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithFileNameMapping-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithFileNameMapping-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithFileNameMapping-test-data/source/pansit.jsp new file mode 100644 index 00000000..27b3fb80 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithFileNameMapping-test-data/source/pansit.jsp @@ -0,0 +1 @@ +pansit.jsp \ No newline at end of file From f44985236590feb413f68272db96c928ee3077c1 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Thu, 11 Dec 2025 15:43:53 +0100 Subject: [PATCH 52/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarExplodedMojoTest --- .../plugins/war/WarExplodedMojoTest.java | 23 ++++++++++--------- .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + 3 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithFileNameMappingAndDuplicateDependencies-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warexplodedmojo/ExplodedWarWithFileNameMappingAndDuplicateDependencies-test-data/source/pansit.jsp diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index 6debafe4..803084c0 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -47,7 +47,6 @@ import org.apache.maven.plugins.war.stub.XarArtifactStub; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.FileUtils; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir; @@ -881,28 +880,30 @@ public void testExplodedWarWithOutputFileNameMapping(WarExplodedMojo mojo) throw } @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithFileNameMappingAndDuplicateDependencies-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithFileNameMappingAndDuplicateDependencies-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithFileNameMappingAndDuplicateDependencies") + @MojoParameter(name = "outputFileNameMapping", value = "@{artifactId}@.@{extension}@") @Test public void testExplodedWarWithOutputFileNameMappingAndDuplicateDependencies(WarExplodedMojo mojo) throws Exception { - // setup test data - String testId = "ExplodedWarWithFileNameMappingAndDuplicateDependencies"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); + // configure mojo + MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); EJBArtifactStub ejbArtifact = new EJBArtifactStub(getBasedir()); ejbArtifact.setGroupId("org.sample.ejb"); EJBArtifactStub ejbArtifactDup = new EJBArtifactStub(getBasedir()); ejbArtifactDup.setGroupId("org.dup.ejb"); - - // configure mojo - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); project.addArtifact(ejbArtifact); project.addArtifact(ejbArtifactDup); - mojo.setOutputFileNameMapping("@{artifactId}@.@{extension}@"); - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); + mojo.setProject(project); mojo.execute(); // validate operation + File webAppDirectory = mojo.getWebappDirectory(); File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp"); File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp"); // final name form is -. diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithFileNameMappingAndDuplicateDependencies-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithFileNameMappingAndDuplicateDependencies-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..dabd1956 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithFileNameMappingAndDuplicateDependencies-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithFileNameMappingAndDuplicateDependencies-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithFileNameMappingAndDuplicateDependencies-test-data/source/pansit.jsp new file mode 100644 index 00000000..27b3fb80 --- /dev/null +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithFileNameMappingAndDuplicateDependencies-test-data/source/pansit.jsp @@ -0,0 +1 @@ +pansit.jsp \ No newline at end of file From 4e9070c392af1cef600cafa9a09bd20de5719af6 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Thu, 11 Dec 2025 15:46:00 +0100 Subject: [PATCH 53/80] refactor: clean up --- .../plugins/war/WarExplodedMojoTest.java | 133 ------------------ 1 file changed, 133 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index 803084c0..61b404c4 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -18,8 +18,6 @@ */ package org.apache.maven.plugins.war; -import javax.inject.Inject; - import java.io.File; import java.text.SimpleDateFormat; import java.util.Locale; @@ -28,7 +26,6 @@ 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.ArtifactHandler; import org.apache.maven.artifact.handler.DefaultArtifactHandler; import org.apache.maven.plugin.testing.stubs.ArtifactStub; import org.apache.maven.plugins.war.stub.AarArtifactStub; @@ -45,7 +42,6 @@ import org.apache.maven.plugins.war.stub.TLDArtifactStub; import org.apache.maven.plugins.war.stub.WarArtifactStub; import org.apache.maven.plugins.war.stub.XarArtifactStub; -import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.FileUtils; import org.junit.jupiter.api.Test; @@ -58,13 +54,6 @@ @MojoTest public class WarExplodedMojoTest { - @Inject - private ArtifactHandler artifactHandler; - - protected File getTestDirectory() { - return new File(getBasedir(), "target/test-classes/unit/warexplodedmojo/test-dir"); - } - @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") @MojoParameter( name = "classesDirectory", @@ -599,11 +588,6 @@ public void testExplodedWarWithXar(WarExplodedMojo mojo) throws Exception { @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithDuplicateDependencies") @Test public void testExplodedWarWithDuplicateDependencies(WarExplodedMojo mojo) throws Exception { - // setup test data - String testId = "ExplodedWarWithDuplicateDependencies"; - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - // configure mojo EJBArtifactStub ejbArtifact = new EJBArtifactStub(getBasedir()); ejbArtifact.setGroupId("org.sample.ejb"); @@ -922,121 +906,4 @@ public void testExplodedWarWithOutputFileNameMappingAndDuplicateDependencies(War expectedEJBDupArtifact.delete(); } - private void configureMojo(WarExplodedMojo mojo, File classesDir, File webAppSource, File webAppDirectory) - throws Exception { - MavenProjectBasicStub project = new MavenProjectBasicStub(); - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - } - - private void configureMojo( - WarExplodedMojo mojo, ArtifactStub artifact, File classesDir, File webAppSource, File webAppDirectory) - throws Exception { - MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); - project.addArtifact(artifact); - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, project); - } - - private void configureMojo( - WarExplodedMojo mojo, File classesDir, File webAppSource, File webAppDirectory, MavenProject project) { - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); - } - - /** - * create an isolated xml dir - * - * @param id The id. - * @param xmlFiles array of xml files. - * @return The created file. - * @throws Exception in case of errors. - */ - protected File createXMLConfigDir(String id, String[] xmlFiles) throws Exception { - File xmlConfigDir = new File(getTestDirectory(), "/" + id + "-test-data/xml-config"); - File xmlFile; - - createDir(xmlConfigDir); - - if (xmlFiles != null) { - for (String o : xmlFiles) { - xmlFile = new File(xmlConfigDir, o); - createFile(xmlFile); - } - } - - return xmlConfigDir; - } - - /** - * Returns the webapp source directory for the specified id. - * - * @param id the id of the test - * @return the source directory for that test - * @throws Exception if an exception occurs - */ - protected File getWebAppSource(String id) throws Exception { - return new File(getTestDirectory(), "/" + id + "-test-data/source"); - } - - /** - * create an isolated web source with a sample jsp file - * - * @param id The id. - * @param createSamples Create example files yes or no. - * @return The created file. - * @throws Exception in case of errors. - */ - protected File createWebAppSource(String id, boolean createSamples) throws Exception { - File webAppSource = getWebAppSource(id); - if (createSamples) { - File simpleJSP = new File(webAppSource, "pansit.jsp"); - File jspFile = new File(webAppSource, "org/web/app/last-exile.jsp"); - - createFile(simpleJSP); - createFile(jspFile); - } - return webAppSource; - } - - protected File createWebAppSource(String id) throws Exception { - return createWebAppSource(id, true); - } - - /** - * create a class directory with or without a sample class - * - * @param id The id. - * @param empty true to create a class files false otherwise. - * @return The created class file. - * @throws Exception in case of errors. - */ - protected File createClassesDir(String id, boolean empty) throws Exception { - File classesDir = new File(getTestDirectory() + "/" + id + "-test-data/classes/"); - - createDir(classesDir); - - if (!empty) { - createFile(new File(classesDir + "/sample-servlet.clazz")); - } - - return classesDir; - } - - protected void createDir(File dir) { - if (!dir.exists()) { - assertTrue(dir.mkdirs(), "can not create test dir: " + dir); - } - } - - protected void createFile(File testFile, String body) throws Exception { - createDir(testFile.getParentFile()); - FileUtils.fileWrite(testFile.toString(), body); - - assertTrue(testFile.exists(), "could not create file: " + testFile); - } - - protected void createFile(File testFile) throws Exception { - createFile(testFile, testFile.toString()); - } } From a050f9b579ff82b11789c3583c203a9e624bcd75 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Thu, 11 Dec 2025 15:46:32 +0100 Subject: [PATCH 54/80] refactor: spotless --- .../plugins/war/WarExplodedMojoTest.java | 70 +++++++++++++------ 1 file changed, 49 insertions(+), 21 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java index 61b404c4..fda13e50 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarExplodedMojoTest.java @@ -142,7 +142,9 @@ public void testSimpleExplodedWarWTargetPath(WarExplodedMojo mojo) throws Except @MojoParameter( name = "webXml", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithCustomWebXML-test-data/xml-config/web.xml") - @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithCustomWebXML") + @MojoParameter( + name = "webappDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithCustomWebXML") @Test public void testExplodedWarWithCustomWebXML(WarExplodedMojo mojo) throws Exception { @@ -180,8 +182,11 @@ public void testExplodedWarWithCustomWebXML(WarExplodedMojo mojo) throws Excepti value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML-test-data/source/") @MojoParameter( name = "containerConfigXML", - value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML-test-data/xml-config/config.xml") - @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML") + value = + "target/test-classes/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML-test-data/xml-config/config.xml") + @MojoParameter( + name = "webappDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML") @Test public void testExplodedWarWithContainerConfigXML(WarExplodedMojo mojo) throws Exception { // configure mojo @@ -220,7 +225,9 @@ public void testExplodedWarWithContainerConfigXML(WarExplodedMojo mojo) throws E @MojoParameter( name = "warSourceDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithSimpleExternalWARFile-test-data/source/") - @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithSimpleExternalWARFile") + @MojoParameter( + name = "webappDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithSimpleExternalWARFile") @MojoParameter( name = "workDirectory", value = "target/test-classes/unit/warexplodedmojo/test-dir/war/work-ExplodedWarWithSimpleExternalWARFile") @@ -264,11 +271,12 @@ public void testExplodedWarWithSimpleExternalWARFile(WarExplodedMojo mojo) throw @MojoParameter( name = "warSourceDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarMergeWarLocalFileOverride-test-data/source/") - @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarMergeWarLocalFileOverride") + @MojoParameter( + name = "webappDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarMergeWarLocalFileOverride") @MojoParameter( name = "workDirectory", - value = - "target/test-classes/unit/warexplodedmojo/test-dir/war/work-ExplodedWarMergeWarLocalFileOverride") + value = "target/test-classes/unit/warexplodedmojo/test-dir/war/work-ExplodedWarMergeWarLocalFileOverride") @Test public void testExplodedWarMergeWarLocalFileOverride(WarExplodedMojo mojo) throws Exception { // configure mojo @@ -286,7 +294,9 @@ public void testExplodedWarMergeWarLocalFileOverride(WarExplodedMojo mojo) throw assertEquals("org/sample/company/test.jsp", FileUtils.fileRead(expectedFile), "file incorrect"); // check when the merged war file is newer - so set an old time on the local file - File simpleJSP = new File(MojoExtension.getBasedir(), "target/test-classes/unit/warexplodedmojo/testExplodedWarMergeWarLocalFileOverride-test-data/source/org/sample/company/test.jsp"); + File simpleJSP = new File( + MojoExtension.getBasedir(), + "target/test-classes/unit/warexplodedmojo/testExplodedWarMergeWarLocalFileOverride-test-data/source/org/sample/company/test.jsp"); long time = new SimpleDateFormat("yyyy-MM-dd", Locale.US).parse("2005-1-1").getTime(); simpleJSP.setLastModified(time); @@ -585,7 +595,9 @@ public void testExplodedWarWithXar(WarExplodedMojo mojo) throws Exception { @MojoParameter( name = "warSourceDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithDuplicateDependencies-test-data/source/") - @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithDuplicateDependencies") + @MojoParameter( + name = "webappDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithDuplicateDependencies") @Test public void testExplodedWarWithDuplicateDependencies(WarExplodedMojo mojo) throws Exception { // configure mojo @@ -629,7 +641,9 @@ public void testExplodedWarWithDuplicateDependencies(WarExplodedMojo mojo) throw @MojoParameter( name = "warSourceDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarDuplicateWithClassifier-test-data/source/") - @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarDuplicateWithClassifier") + @MojoParameter( + name = "webappDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarDuplicateWithClassifier") @Test public void testExplodedWarDuplicateWithClassifier(WarExplodedMojo mojo) throws Exception { // configure mojo @@ -706,7 +720,9 @@ public void testExplodedWarWithClasses(WarExplodedMojo mojo) throws Exception { @MojoParameter( name = "warSourceDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithSourceIncludeExclude-test-data/source/") - @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithSourceIncludeExclude") + @MojoParameter( + name = "webappDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithSourceIncludeExclude") @MojoParameter(name = "warSourceIncludes", value = "**/*sit.jsp") @MojoParameter(name = "warSourceExcludes", value = "**/last*.*") @Test @@ -738,11 +754,15 @@ public void testExplodedWarWithSourceIncludeExclude(WarExplodedMojo mojo) throws @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") @MojoParameter( name = "classesDirectory", - value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithWarDependencyIncludeExclude-test-data/classes/") + value = + "target/test-classes/unit/warexplodedmojo/ExplodedWarWithWarDependencyIncludeExclude-test-data/classes/") @MojoParameter( name = "warSourceDirectory", - value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithWarDependencyIncludeExclude-test-data/source/") - @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithWarDependencyIncludeExclude") + value = + "target/test-classes/unit/warexplodedmojo/ExplodedWarWithWarDependencyIncludeExclude-test-data/source/") + @MojoParameter( + name = "webappDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithWarDependencyIncludeExclude") @MojoParameter(name = "dependentWarIncludes", value = "**/*Include.jsp,**/*.xml") @MojoParameter(name = "dependentWarExcludes", value = "**/*Exclude*,**/MANIFEST.MF") @MojoParameter( @@ -787,11 +807,14 @@ public void testExplodedWarWithWarDependencyIncludeExclude(WarExplodedMojo mojo) @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") @MojoParameter( name = "classesDirectory", - value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithSourceModificationCheck-test-data/classes/") + value = + "target/test-classes/unit/warexplodedmojo/ExplodedWarWithSourceModificationCheck-test-data/classes/") @MojoParameter( name = "warSourceDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithSourceModificationCheck-test-data/source/") - @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithSourceModificationCheck") + @MojoParameter( + name = "webappDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithSourceModificationCheck") @Test public void testExplodedWarWithSourceModificationCheck(WarExplodedMojo mojo) throws Exception { // configure mojo @@ -835,7 +858,9 @@ public void testExplodedWarWithSourceModificationCheck(WarExplodedMojo mojo) thr @MojoParameter( name = "warSourceDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithFileNameMapping-test-data/source/") - @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithFileNameMapping") + @MojoParameter( + name = "webappDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithFileNameMapping") @MojoParameter(name = "outputFileNameMapping", value = "@{artifactId}@.@{extension}@") @Test public void testExplodedWarWithOutputFileNameMapping(WarExplodedMojo mojo) throws Exception { @@ -866,11 +891,15 @@ public void testExplodedWarWithOutputFileNameMapping(WarExplodedMojo mojo) throw @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/warexplodedmojo/plugin-config.xml") @MojoParameter( name = "classesDirectory", - value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithFileNameMappingAndDuplicateDependencies-test-data/classes/") + value = + "target/test-classes/unit/warexplodedmojo/ExplodedWarWithFileNameMappingAndDuplicateDependencies-test-data/classes/") @MojoParameter( name = "warSourceDirectory", - value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithFileNameMappingAndDuplicateDependencies-test-data/source/") - @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithFileNameMappingAndDuplicateDependencies") + value = + "target/test-classes/unit/warexplodedmojo/ExplodedWarWithFileNameMappingAndDuplicateDependencies-test-data/source/") + @MojoParameter( + name = "webappDirectory", + value = "target/test-classes/unit/warexplodedmojo/ExplodedWarWithFileNameMappingAndDuplicateDependencies") @MojoParameter(name = "outputFileNameMapping", value = "@{artifactId}@.@{extension}@") @Test public void testExplodedWarWithOutputFileNameMappingAndDuplicateDependencies(WarExplodedMojo mojo) @@ -905,5 +934,4 @@ public void testExplodedWarWithOutputFileNameMappingAndDuplicateDependencies(War expectedEJBArtifact.delete(); expectedEJBDupArtifact.delete(); } - } From 1425304650fe31a74717ba02c1cefe42c74ed442 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Thu, 11 Dec 2025 16:05:18 +0100 Subject: [PATCH 55/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarInPlaceMojoTest --- .../maven/plugins/war/WarInPlaceMojoTest.java | 29 +++++++++---------- .../resources/pix/panis_na.jpg | 1 + .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + .../source/pix/panis_na.jpg | 1 + 5 files changed, 17 insertions(+), 16 deletions(-) create mode 100644 src/test/resources/unit/warexplodedinplacemojo/SimpleExplodedInplaceWar-test-data/resources/pix/panis_na.jpg create mode 100644 src/test/resources/unit/warexplodedinplacemojo/SimpleExplodedInplaceWar-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warexplodedinplacemojo/SimpleExplodedInplaceWar-test-data/source/pansit.jsp create mode 100644 src/test/resources/unit/warexplodedinplacemojo/SimpleExplodedInplaceWar-test-data/source/pix/panis_na.jpg diff --git a/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java index fd303fd6..8acd34ec 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java @@ -21,6 +21,7 @@ import java.io.File; import org.apache.maven.api.plugin.testing.InjectMojo; +import org.apache.maven.api.plugin.testing.MojoParameter; import org.apache.maven.api.plugin.testing.MojoTest; import org.apache.maven.plugins.war.stub.MavenProjectBasicStub; import org.apache.maven.plugins.war.stub.ResourceStub; @@ -38,29 +39,25 @@ private File getTestDirectory() throws Exception { } @InjectMojo(goal = "inplace", pom = "src/test/resources/unit/warexplodedinplacemojo/plugin-config.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warexplodedinplacemojo/SimpleExplodedInplaceWar-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warexplodedinplacemojo/SimpleExplodedInplaceWar-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedinplacemojo/SimpleExplodedInplaceWar") @Test public void testSimpleExplodedInplaceWar(WarInPlaceMojo mojo) throws Exception { - // setup test data - String testId = "SimpleExplodedInplaceWar"; - MavenProjectBasicStub project = new MavenProjectBasicStub(); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - File webAppResource = new File(getTestDirectory(), "resources"); - File sampleResource = new File(webAppResource, "pix/panis_na.jpg"); - createFile(sampleResource); - - ResourceStub[] resources = new ResourceStub[] {new ResourceStub()}; - resources[0].setDirectory(webAppResource.getAbsolutePath()); - // configure mojo - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(null); - mojo.setProject(project); + ResourceStub[] resources = new ResourceStub[] {new ResourceStub()}; + resources[0].setDirectory(getBasedir() + "/target/test-classes/unit/warexplodedinplacemojo/SimpleExplodedInplaceWar-test-data/resources"); mojo.setWebResources(resources); + MavenProjectBasicStub project = new MavenProjectBasicStub(); + mojo.setProject(project); mojo.execute(); // validate operation + File webAppSource = mojo.getWarSourceDirectory(); File expectedWebSourceFile = new File(webAppSource, "pansit.jsp"); File expectedWebSource2File = new File(webAppSource, "org/web/app/last-exile.jsp"); File expectedWebResourceFile = new File(webAppSource, "pix/panis_na.jpg"); diff --git a/src/test/resources/unit/warexplodedinplacemojo/SimpleExplodedInplaceWar-test-data/resources/pix/panis_na.jpg b/src/test/resources/unit/warexplodedinplacemojo/SimpleExplodedInplaceWar-test-data/resources/pix/panis_na.jpg new file mode 100644 index 00000000..6d8d698d --- /dev/null +++ b/src/test/resources/unit/warexplodedinplacemojo/SimpleExplodedInplaceWar-test-data/resources/pix/panis_na.jpg @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedinplacemojo/test-dir/resources/pix/panis_na.jpg \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedinplacemojo/SimpleExplodedInplaceWar-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedinplacemojo/SimpleExplodedInplaceWar-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..dabd1956 --- /dev/null +++ b/src/test/resources/unit/warexplodedinplacemojo/SimpleExplodedInplaceWar-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedinplacemojo/SimpleExplodedInplaceWar-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedinplacemojo/SimpleExplodedInplaceWar-test-data/source/pansit.jsp new file mode 100644 index 00000000..27b3fb80 --- /dev/null +++ b/src/test/resources/unit/warexplodedinplacemojo/SimpleExplodedInplaceWar-test-data/source/pansit.jsp @@ -0,0 +1 @@ +pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedinplacemojo/SimpleExplodedInplaceWar-test-data/source/pix/panis_na.jpg b/src/test/resources/unit/warexplodedinplacemojo/SimpleExplodedInplaceWar-test-data/source/pix/panis_na.jpg new file mode 100644 index 00000000..6d8d698d --- /dev/null +++ b/src/test/resources/unit/warexplodedinplacemojo/SimpleExplodedInplaceWar-test-data/source/pix/panis_na.jpg @@ -0,0 +1 @@ +/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedinplacemojo/test-dir/resources/pix/panis_na.jpg \ No newline at end of file From 250f7447ae75cf5304c3958d0ca076436c1b69cc Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Thu, 11 Dec 2025 16:07:28 +0100 Subject: [PATCH 56/80] refactor: clean up --- .../maven/plugins/war/WarInPlaceMojoTest.java | 77 +------------------ 1 file changed, 1 insertion(+), 76 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java index 8acd34ec..a67bfe43 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java @@ -23,9 +23,9 @@ import org.apache.maven.api.plugin.testing.InjectMojo; import org.apache.maven.api.plugin.testing.MojoParameter; import org.apache.maven.api.plugin.testing.MojoTest; +import org.apache.maven.plugin.testing.stubs.MavenProjectStub; import org.apache.maven.plugins.war.stub.MavenProjectBasicStub; import org.apache.maven.plugins.war.stub.ResourceStub; -import org.codehaus.plexus.util.FileUtils; import org.junit.jupiter.api.Test; import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir; @@ -34,10 +34,6 @@ @MojoTest public class WarInPlaceMojoTest { - private File getTestDirectory() throws Exception { - return new File(getBasedir(), "target/test-classes/unit/warexplodedinplacemojo/test-dir"); - } - @InjectMojo(goal = "inplace", pom = "src/test/resources/unit/warexplodedinplacemojo/plugin-config.xml") @MojoParameter( name = "classesDirectory", @@ -71,75 +67,4 @@ public void testSimpleExplodedInplaceWar(WarInPlaceMojo mojo) throws Exception { assertTrue(expectedMETAINFDir.exists(), "META-INF not found"); } - /** - * Returns the webapp source directory for the specified id. - * - * @param id the id of the test - * @return the source directory for that test - * @throws Exception if an exception occurs - */ - private File getWebAppSource(String id) throws Exception { - return new File(getTestDirectory(), "/" + id + "-test-data/source"); - } - - /** - * create an isolated web source with a sample jsp file - * - * @param id The id. - * @param createSamples Create example files yes or no. - * @return The created file. - * @throws Exception in case of errors. - */ - private File createWebAppSource(String id, boolean createSamples) throws Exception { - File webAppSource = getWebAppSource(id); - if (createSamples) { - File simpleJSP = new File(webAppSource, "pansit.jsp"); - File jspFile = new File(webAppSource, "org/web/app/last-exile.jsp"); - - createFile(simpleJSP); - createFile(jspFile); - } - return webAppSource; - } - - private File createWebAppSource(String id) throws Exception { - return createWebAppSource(id, true); - } - - /** - * create a class directory with or without a sample class - * - * @param id The id. - * @param empty true to create a class files false otherwise. - * @return The created class file. - * @throws Exception in case of errors. - */ - private File createClassesDir(String id, boolean empty) throws Exception { - File classesDir = new File(getTestDirectory() + "/" + id + "-test-data/classes/"); - - createDir(classesDir); - - if (!empty) { - createFile(new File(classesDir + "/sample-servlet.clazz")); - } - - return classesDir; - } - - private void createDir(File dir) { - if (!dir.exists()) { - assertTrue(dir.mkdirs(), "can not create test dir: " + dir); - } - } - - private void createFile(File testFile, String body) throws Exception { - createDir(testFile.getParentFile()); - FileUtils.fileWrite(testFile.toString(), body); - - assertTrue(testFile.exists(), "could not create file: " + testFile); - } - - private void createFile(File testFile) throws Exception { - createFile(testFile, testFile.toString()); - } } From ebf194cd6930de5251fbd63ee1daa4dab1c974ad Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Fri, 12 Dec 2025 07:23:53 +0100 Subject: [PATCH 57/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarMojoTest --- .../apache/maven/plugins/war/WarMojoTest.java | 21 +++++++++++-------- .../source/org/web/app/last-exile.jsp | 2 +- .../source/pansit.jsp | 2 +- .../source/org/web/app/last-exile.jsp | 2 +- .../source/pansit.jsp | 2 +- .../source/org/web/app/last-exile.jsp | 2 +- .../classes/sample-servlet.clazz | 2 +- .../source/org/web/app/last-exile.jsp | 2 +- .../source/pansit.jsp | 2 +- .../classes/sample-servlet.clazz | 2 +- .../source/org/web/app/last-exile.jsp | 2 +- .../source/pansit.jsp | 2 +- .../classes/sample-servlet.clazz | 2 +- .../source/org/web/app/last-exile.jsp | 2 +- .../source/pansit.jsp | 2 +- .../classes/sample-servlet.clazz | 1 + .../source/org/web/app/last-exile.jsp | 1 + .../AttachClasses-test-data/source/pansit.jsp | 1 + .../xml-config/web.xml | 1 + .../classes/sample-servlet.clazz | 1 + .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + .../xml-config/web.xml | 1 + .../source/org/web/app/last-exile.jsp | 1 + .../Classifier-test-data/source/pansit.jsp | 1 + .../Classifier-test-data/xml-config/web.xml | 1 + .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + .../xml-config/web.xml | 1 + .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + .../xml-config/web.xml | 1 + .../source/org/web/app/last-exile.jsp | 1 + .../SimpleWar-test-data/source/pansit.jsp | 1 + .../SimpleWar-test-data/xml-config/web.xml | 1 + .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + .../xml-config/web.xml | 1 + .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + .../xml-config/web.xml | 1 + .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + .../source/META-INF/config.xml | 1 + .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + .../xml-config/web.xml | 1 + .../source/META-INF/config.xml | 1 + .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + .../xml-config/web.xml | 1 + .../source/org/web/app/last-exile.jsp | 2 +- .../source/pansit.jsp | 2 +- .../source/org/web/app/last-exile.jsp | 2 +- .../source/pansit.jsp | 2 +- .../source/org/web/app/last-exile.jsp | 2 +- .../no-overlay-test-data/source/pansit.jsp | 2 +- .../no-overlay-test-data/xml-config/web.xml | 2 +- 64 files changed, 75 insertions(+), 30 deletions(-) create mode 100644 src/test/resources/unit/warmojotest/AttachClasses-test-data/classes/sample-servlet.clazz create mode 100644 src/test/resources/unit/warmojotest/AttachClasses-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warmojotest/AttachClasses-test-data/source/pansit.jsp create mode 100644 src/test/resources/unit/warmojotest/AttachClasses-test-data/xml-config/web.xml create mode 100644 src/test/resources/unit/warmojotest/AttachClassesCustomClassifier-test-data/classes/sample-servlet.clazz create mode 100644 src/test/resources/unit/warmojotest/AttachClassesCustomClassifier-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warmojotest/AttachClassesCustomClassifier-test-data/source/pansit.jsp create mode 100644 src/test/resources/unit/warmojotest/AttachClassesCustomClassifier-test-data/xml-config/web.xml create mode 100644 src/test/resources/unit/warmojotest/Classifier-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warmojotest/Classifier-test-data/source/pansit.jsp create mode 100644 src/test/resources/unit/warmojotest/Classifier-test-data/xml-config/web.xml create mode 100644 src/test/resources/unit/warmojotest/NotPrimaryArtifact-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warmojotest/NotPrimaryArtifact-test-data/source/pansit.jsp create mode 100644 src/test/resources/unit/warmojotest/NotPrimaryArtifact-test-data/xml-config/web.xml create mode 100644 src/test/resources/unit/warmojotest/PrimaryArtifact-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warmojotest/PrimaryArtifact-test-data/source/pansit.jsp create mode 100644 src/test/resources/unit/warmojotest/PrimaryArtifact-test-data/xml-config/web.xml create mode 100644 src/test/resources/unit/warmojotest/SimpleWar-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warmojotest/SimpleWar-test-data/source/pansit.jsp create mode 100644 src/test/resources/unit/warmojotest/SimpleWar-test-data/xml-config/web.xml create mode 100644 src/test/resources/unit/warmojotest/SimpleWarMissingWebXmlFalse-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warmojotest/SimpleWarMissingWebXmlFalse-test-data/source/pansit.jsp create mode 100644 src/test/resources/unit/warmojotest/SimpleWarMissingWebXmlTrue-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warmojotest/SimpleWarMissingWebXmlTrue-test-data/source/pansit.jsp create mode 100644 src/test/resources/unit/warmojotest/SimpleWarNotUnderServlet30-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warmojotest/SimpleWarNotUnderServlet30-test-data/source/pansit.jsp create mode 100644 src/test/resources/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/source/pansit.jsp create mode 100644 src/test/resources/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/xml-config/web.xml create mode 100644 src/test/resources/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-test-data/source/pansit.jsp create mode 100644 src/test/resources/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-test-data/xml-config/web.xml create mode 100644 src/test/resources/unit/warmojotest/SimpleWarUnderServlet30-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warmojotest/SimpleWarUnderServlet30-test-data/source/pansit.jsp create mode 100644 src/test/resources/unit/warmojotest/SimpleWarWithContainerConfig-test-data/source/META-INF/config.xml create mode 100644 src/test/resources/unit/warmojotest/SimpleWarWithContainerConfig-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warmojotest/SimpleWarWithContainerConfig-test-data/source/pansit.jsp create mode 100644 src/test/resources/unit/warmojotest/SimpleWarWithContainerConfig-test-data/xml-config/web.xml create mode 100644 src/test/resources/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/source/META-INF/config.xml create mode 100644 src/test/resources/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/source/pansit.jsp create mode 100644 src/test/resources/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/xml-config/web.xml diff --git a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java index 6d89865e..15084057 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java @@ -72,19 +72,22 @@ private MavenProjectHelper projectHelper() { } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWar-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWar-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warmojotest/SimpleWar") @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWar-output") @MojoParameter(name = "warName", value = "simple") + @MojoParameter(name = "webXml", value = "target/test-classes/unit/warmojotest/SimpleWar-test-data/xml-config/web.xml") @Test public void testSimpleWar(WarMojo mojo) throws Exception { - String testId = "SimpleWar"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory, xmlSource); - + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + project.setArtifact(warArtifact); + mojo.setProject(project); mojo.execute(); // validate jar file @@ -101,7 +104,7 @@ public void testSimpleWar(WarMojo mojo) throws Exception { "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, - new String[] {null, mojo.getWebXml().toString(), null, null, null, null}); + new String[] {null, mojo.getWebXml().getName(), null, null, null, null}); } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML-test-data/source/org/web/app/last-exile.jsp index cbcdaad0..3f13f97f 100644 --- a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML-test-data/source/org/web/app/last-exile.jsp +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML-test-data/source/org/web/app/last-exile.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithContainerConfigXML-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file +target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithContainerConfigXML-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML-test-data/source/pansit.jsp index 212eb3eb..23d675d6 100644 --- a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML-test-data/source/pansit.jsp +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithContainerConfigXML-test-data/source/pansit.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithContainerConfigXML-test-data/source/pansit.jsp \ No newline at end of file +target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithContainerConfigXML-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithCustomWebXML-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithCustomWebXML-test-data/source/org/web/app/last-exile.jsp index 52cd3e52..4cbadb6e 100644 --- a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithCustomWebXML-test-data/source/org/web/app/last-exile.jsp +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithCustomWebXML-test-data/source/org/web/app/last-exile.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithCustomWebXML-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file +target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithCustomWebXML-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithCustomWebXML-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithCustomWebXML-test-data/source/pansit.jsp index ed172e27..f9d4cd96 100644 --- a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithCustomWebXML-test-data/source/pansit.jsp +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithCustomWebXML-test-data/source/pansit.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithCustomWebXML-test-data/source/pansit.jsp \ No newline at end of file +target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithCustomWebXML-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithFileNameMapping-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithFileNameMapping-test-data/source/org/web/app/last-exile.jsp index 7c7d8b57..80d44d3a 100644 --- a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithFileNameMapping-test-data/source/org/web/app/last-exile.jsp +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithFileNameMapping-test-data/source/org/web/app/last-exile.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithFileNameMapping-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file +target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithFileNameMapping-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/classes/sample-servlet.clazz b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/classes/sample-servlet.clazz index 3f0cdff4..10a158f7 100644 --- a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/classes/sample-servlet.clazz +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/classes/sample-servlet.clazz @@ -1 +1 @@ -/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithResourceFiltering-test-data/classes/sample-servlet.clazz \ No newline at end of file +target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithResourceFiltering-test-data/classes/sample-servlet.clazz \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/source/org/web/app/last-exile.jsp index ddb271bd..7ad2efbb 100644 --- a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/source/org/web/app/last-exile.jsp +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/source/org/web/app/last-exile.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithResourceFiltering-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file +target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithResourceFiltering-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/source/pansit.jsp index 9fe68751..2ad87bd4 100644 --- a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/source/pansit.jsp +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFileFiltering-test-data/source/pansit.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithResourceFiltering-test-data/source/pansit.jsp \ No newline at end of file +target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithResourceFiltering-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/classes/sample-servlet.clazz b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/classes/sample-servlet.clazz index 3f0cdff4..10a158f7 100644 --- a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/classes/sample-servlet.clazz +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/classes/sample-servlet.clazz @@ -1 +1 @@ -/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithResourceFiltering-test-data/classes/sample-servlet.clazz \ No newline at end of file +target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithResourceFiltering-test-data/classes/sample-servlet.clazz \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/source/org/web/app/last-exile.jsp index ddb271bd..7ad2efbb 100644 --- a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/source/org/web/app/last-exile.jsp +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/source/org/web/app/last-exile.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithResourceFiltering-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file +target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithResourceFiltering-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/source/pansit.jsp index 9fe68751..2ad87bd4 100644 --- a/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/source/pansit.jsp +++ b/src/test/resources/unit/warexplodedmojo/ExplodedWarWithResourceFiltering-test-data/source/pansit.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithResourceFiltering-test-data/source/pansit.jsp \ No newline at end of file +target/test-classes/unit/warexplodedmojo/test-dir/ExplodedWarWithResourceFiltering-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/classes/sample-servlet.clazz b/src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/classes/sample-servlet.clazz index f6aa6393..3e3777cb 100644 --- a/src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/classes/sample-servlet.clazz +++ b/src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/classes/sample-servlet.clazz @@ -1 +1 @@ -/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/SimpleExplodedWar-test-data/classes/sample-servlet.clazz \ No newline at end of file +target/test-classes/unit/warexplodedmojo/test-dir/SimpleExplodedWar-test-data/classes/sample-servlet.clazz \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/source/org/web/app/last-exile.jsp index f633b0fa..e74b72fb 100644 --- a/src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/source/org/web/app/last-exile.jsp +++ b/src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/source/org/web/app/last-exile.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/SimpleExplodedWar-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file +target/test-classes/unit/warexplodedmojo/test-dir/SimpleExplodedWar-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/source/pansit.jsp b/src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/source/pansit.jsp index 5fbfe8e8..76bf48ce 100644 --- a/src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/source/pansit.jsp +++ b/src/test/resources/unit/warexplodedmojo/SimpleExplodedWar-test-data/source/pansit.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/warexplodedmojo/test-dir/SimpleExplodedWar-test-data/source/pansit.jsp \ No newline at end of file +target/test-classes/unit/warexplodedmojo/test-dir/SimpleExplodedWar-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/AttachClasses-test-data/classes/sample-servlet.clazz b/src/test/resources/unit/warmojotest/AttachClasses-test-data/classes/sample-servlet.clazz new file mode 100644 index 00000000..536dc9f6 --- /dev/null +++ b/src/test/resources/unit/warmojotest/AttachClasses-test-data/classes/sample-servlet.clazz @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/AttachClasses-test-data/classes/sample-servlet.clazz \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/AttachClasses-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warmojotest/AttachClasses-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..cd9000ee --- /dev/null +++ b/src/test/resources/unit/warmojotest/AttachClasses-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/AttachClasses-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/AttachClasses-test-data/source/pansit.jsp b/src/test/resources/unit/warmojotest/AttachClasses-test-data/source/pansit.jsp new file mode 100644 index 00000000..eecac692 --- /dev/null +++ b/src/test/resources/unit/warmojotest/AttachClasses-test-data/source/pansit.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/AttachClasses-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/AttachClasses-test-data/xml-config/web.xml b/src/test/resources/unit/warmojotest/AttachClasses-test-data/xml-config/web.xml new file mode 100644 index 00000000..b56e8b50 --- /dev/null +++ b/src/test/resources/unit/warmojotest/AttachClasses-test-data/xml-config/web.xml @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/AttachClasses-test-data/xml-config/web.xml \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/AttachClassesCustomClassifier-test-data/classes/sample-servlet.clazz b/src/test/resources/unit/warmojotest/AttachClassesCustomClassifier-test-data/classes/sample-servlet.clazz new file mode 100644 index 00000000..63cf1e02 --- /dev/null +++ b/src/test/resources/unit/warmojotest/AttachClassesCustomClassifier-test-data/classes/sample-servlet.clazz @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/AttachClassesCustomClassifier-test-data/classes/sample-servlet.clazz \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/AttachClassesCustomClassifier-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warmojotest/AttachClassesCustomClassifier-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..cce64211 --- /dev/null +++ b/src/test/resources/unit/warmojotest/AttachClassesCustomClassifier-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/AttachClassesCustomClassifier-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/AttachClassesCustomClassifier-test-data/source/pansit.jsp b/src/test/resources/unit/warmojotest/AttachClassesCustomClassifier-test-data/source/pansit.jsp new file mode 100644 index 00000000..decfdc12 --- /dev/null +++ b/src/test/resources/unit/warmojotest/AttachClassesCustomClassifier-test-data/source/pansit.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/AttachClassesCustomClassifier-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/AttachClassesCustomClassifier-test-data/xml-config/web.xml b/src/test/resources/unit/warmojotest/AttachClassesCustomClassifier-test-data/xml-config/web.xml new file mode 100644 index 00000000..667973a8 --- /dev/null +++ b/src/test/resources/unit/warmojotest/AttachClassesCustomClassifier-test-data/xml-config/web.xml @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/AttachClassesCustomClassifier-test-data/xml-config/web.xml \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/Classifier-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warmojotest/Classifier-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..a3762798 --- /dev/null +++ b/src/test/resources/unit/warmojotest/Classifier-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/Classifier-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/Classifier-test-data/source/pansit.jsp b/src/test/resources/unit/warmojotest/Classifier-test-data/source/pansit.jsp new file mode 100644 index 00000000..93a2fa92 --- /dev/null +++ b/src/test/resources/unit/warmojotest/Classifier-test-data/source/pansit.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/Classifier-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/Classifier-test-data/xml-config/web.xml b/src/test/resources/unit/warmojotest/Classifier-test-data/xml-config/web.xml new file mode 100644 index 00000000..2b56bab3 --- /dev/null +++ b/src/test/resources/unit/warmojotest/Classifier-test-data/xml-config/web.xml @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/Classifier-test-data/xml-config/web.xml \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/NotPrimaryArtifact-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warmojotest/NotPrimaryArtifact-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..7a64fcf1 --- /dev/null +++ b/src/test/resources/unit/warmojotest/NotPrimaryArtifact-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/NotPrimaryArtifact-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/NotPrimaryArtifact-test-data/source/pansit.jsp b/src/test/resources/unit/warmojotest/NotPrimaryArtifact-test-data/source/pansit.jsp new file mode 100644 index 00000000..8646727c --- /dev/null +++ b/src/test/resources/unit/warmojotest/NotPrimaryArtifact-test-data/source/pansit.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/NotPrimaryArtifact-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/NotPrimaryArtifact-test-data/xml-config/web.xml b/src/test/resources/unit/warmojotest/NotPrimaryArtifact-test-data/xml-config/web.xml new file mode 100644 index 00000000..4267382a --- /dev/null +++ b/src/test/resources/unit/warmojotest/NotPrimaryArtifact-test-data/xml-config/web.xml @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/NotPrimaryArtifact-test-data/xml-config/web.xml \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/PrimaryArtifact-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warmojotest/PrimaryArtifact-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..5c665dd8 --- /dev/null +++ b/src/test/resources/unit/warmojotest/PrimaryArtifact-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/PrimaryArtifact-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/PrimaryArtifact-test-data/source/pansit.jsp b/src/test/resources/unit/warmojotest/PrimaryArtifact-test-data/source/pansit.jsp new file mode 100644 index 00000000..89806759 --- /dev/null +++ b/src/test/resources/unit/warmojotest/PrimaryArtifact-test-data/source/pansit.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/PrimaryArtifact-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/PrimaryArtifact-test-data/xml-config/web.xml b/src/test/resources/unit/warmojotest/PrimaryArtifact-test-data/xml-config/web.xml new file mode 100644 index 00000000..e5506074 --- /dev/null +++ b/src/test/resources/unit/warmojotest/PrimaryArtifact-test-data/xml-config/web.xml @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/PrimaryArtifact-test-data/xml-config/web.xml \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/SimpleWar-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warmojotest/SimpleWar-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..12c099d4 --- /dev/null +++ b/src/test/resources/unit/warmojotest/SimpleWar-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/SimpleWar-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/SimpleWar-test-data/source/pansit.jsp b/src/test/resources/unit/warmojotest/SimpleWar-test-data/source/pansit.jsp new file mode 100644 index 00000000..bf51217d --- /dev/null +++ b/src/test/resources/unit/warmojotest/SimpleWar-test-data/source/pansit.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/SimpleWar-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/SimpleWar-test-data/xml-config/web.xml b/src/test/resources/unit/warmojotest/SimpleWar-test-data/xml-config/web.xml new file mode 100644 index 00000000..d188dff5 --- /dev/null +++ b/src/test/resources/unit/warmojotest/SimpleWar-test-data/xml-config/web.xml @@ -0,0 +1 @@ +web.xml \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/SimpleWarMissingWebXmlFalse-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warmojotest/SimpleWarMissingWebXmlFalse-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..c36f8207 --- /dev/null +++ b/src/test/resources/unit/warmojotest/SimpleWarMissingWebXmlFalse-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/SimpleWarMissingWebXmlFalse-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/SimpleWarMissingWebXmlFalse-test-data/source/pansit.jsp b/src/test/resources/unit/warmojotest/SimpleWarMissingWebXmlFalse-test-data/source/pansit.jsp new file mode 100644 index 00000000..9c314580 --- /dev/null +++ b/src/test/resources/unit/warmojotest/SimpleWarMissingWebXmlFalse-test-data/source/pansit.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/SimpleWarMissingWebXmlFalse-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/SimpleWarMissingWebXmlTrue-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warmojotest/SimpleWarMissingWebXmlTrue-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..cf9cdf30 --- /dev/null +++ b/src/test/resources/unit/warmojotest/SimpleWarMissingWebXmlTrue-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/SimpleWarMissingWebXmlTrue-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/SimpleWarMissingWebXmlTrue-test-data/source/pansit.jsp b/src/test/resources/unit/warmojotest/SimpleWarMissingWebXmlTrue-test-data/source/pansit.jsp new file mode 100644 index 00000000..5b8df294 --- /dev/null +++ b/src/test/resources/unit/warmojotest/SimpleWarMissingWebXmlTrue-test-data/source/pansit.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/SimpleWarMissingWebXmlTrue-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/SimpleWarNotUnderServlet30-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warmojotest/SimpleWarNotUnderServlet30-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..3612a543 --- /dev/null +++ b/src/test/resources/unit/warmojotest/SimpleWarNotUnderServlet30-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/SimpleWarNotUnderServlet30-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/SimpleWarNotUnderServlet30-test-data/source/pansit.jsp b/src/test/resources/unit/warmojotest/SimpleWarNotUnderServlet30-test-data/source/pansit.jsp new file mode 100644 index 00000000..adedc9a4 --- /dev/null +++ b/src/test/resources/unit/warmojotest/SimpleWarNotUnderServlet30-test-data/source/pansit.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/SimpleWarNotUnderServlet30-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..5e582fe7 --- /dev/null +++ b/src/test/resources/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/source/pansit.jsp b/src/test/resources/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/source/pansit.jsp new file mode 100644 index 00000000..13f36f85 --- /dev/null +++ b/src/test/resources/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/source/pansit.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/xml-config/web.xml b/src/test/resources/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/xml-config/web.xml new file mode 100644 index 00000000..dbec5fb6 --- /dev/null +++ b/src/test/resources/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/xml-config/web.xml @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/xml-config/web.xml \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..91e5d05d --- /dev/null +++ b/src/test/resources/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-test-data/source/pansit.jsp b/src/test/resources/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-test-data/source/pansit.jsp new file mode 100644 index 00000000..03820336 --- /dev/null +++ b/src/test/resources/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-test-data/source/pansit.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-test-data/xml-config/web.xml b/src/test/resources/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-test-data/xml-config/web.xml new file mode 100644 index 00000000..93d685b4 --- /dev/null +++ b/src/test/resources/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-test-data/xml-config/web.xml @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-test-data/xml-config/web.xml \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/SimpleWarUnderServlet30-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warmojotest/SimpleWarUnderServlet30-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..4abef2bd --- /dev/null +++ b/src/test/resources/unit/warmojotest/SimpleWarUnderServlet30-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/SimpleWarUnderServlet30-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/SimpleWarUnderServlet30-test-data/source/pansit.jsp b/src/test/resources/unit/warmojotest/SimpleWarUnderServlet30-test-data/source/pansit.jsp new file mode 100644 index 00000000..4854fd6d --- /dev/null +++ b/src/test/resources/unit/warmojotest/SimpleWarUnderServlet30-test-data/source/pansit.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/SimpleWarUnderServlet30-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/SimpleWarWithContainerConfig-test-data/source/META-INF/config.xml b/src/test/resources/unit/warmojotest/SimpleWarWithContainerConfig-test-data/source/META-INF/config.xml new file mode 100644 index 00000000..bf3a57c3 --- /dev/null +++ b/src/test/resources/unit/warmojotest/SimpleWarWithContainerConfig-test-data/source/META-INF/config.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/SimpleWarWithContainerConfig-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warmojotest/SimpleWarWithContainerConfig-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..c1b9eea9 --- /dev/null +++ b/src/test/resources/unit/warmojotest/SimpleWarWithContainerConfig-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/SimpleWarWithContainerConfig-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/SimpleWarWithContainerConfig-test-data/source/pansit.jsp b/src/test/resources/unit/warmojotest/SimpleWarWithContainerConfig-test-data/source/pansit.jsp new file mode 100644 index 00000000..3477e685 --- /dev/null +++ b/src/test/resources/unit/warmojotest/SimpleWarWithContainerConfig-test-data/source/pansit.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/SimpleWarWithContainerConfig-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/SimpleWarWithContainerConfig-test-data/xml-config/web.xml b/src/test/resources/unit/warmojotest/SimpleWarWithContainerConfig-test-data/xml-config/web.xml new file mode 100644 index 00000000..f6392350 --- /dev/null +++ b/src/test/resources/unit/warmojotest/SimpleWarWithContainerConfig-test-data/xml-config/web.xml @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/SimpleWarWithContainerConfig-test-data/xml-config/web.xml \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/source/META-INF/config.xml b/src/test/resources/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/source/META-INF/config.xml new file mode 100644 index 00000000..bf3a57c3 --- /dev/null +++ b/src/test/resources/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/source/META-INF/config.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..337be7a2 --- /dev/null +++ b/src/test/resources/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/source/pansit.jsp b/src/test/resources/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/source/pansit.jsp new file mode 100644 index 00000000..cf418910 --- /dev/null +++ b/src/test/resources/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/source/pansit.jsp @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/xml-config/web.xml b/src/test/resources/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/xml-config/web.xml new file mode 100644 index 00000000..a6d60504 --- /dev/null +++ b/src/test/resources/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/xml-config/web.xml @@ -0,0 +1 @@ +target/test-classes/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/xml-config/web.xml \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/default-overlay-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/waroverlays/default-overlay-test-data/source/org/web/app/last-exile.jsp index a30c88c8..c9fcb4f7 100644 --- a/src/test/resources/unit/waroverlays/default-overlay-test-data/source/org/web/app/last-exile.jsp +++ b/src/test/resources/unit/waroverlays/default-overlay-test-data/source/org/web/app/last-exile.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/waroverlays/default-overlay-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file +target/test-classes/unit/waroverlays/default-overlay-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/default-overlay-test-data/source/pansit.jsp b/src/test/resources/unit/waroverlays/default-overlay-test-data/source/pansit.jsp index e3d61edd..fb28db4f 100644 --- a/src/test/resources/unit/waroverlays/default-overlay-test-data/source/pansit.jsp +++ b/src/test/resources/unit/waroverlays/default-overlay-test-data/source/pansit.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/waroverlays/default-overlay-test-data/source/pansit.jsp \ No newline at end of file +target/test-classes/unit/waroverlays/default-overlay-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/default-overlays-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/waroverlays/default-overlays-test-data/source/org/web/app/last-exile.jsp index c3701626..93eef701 100644 --- a/src/test/resources/unit/waroverlays/default-overlays-test-data/source/org/web/app/last-exile.jsp +++ b/src/test/resources/unit/waroverlays/default-overlays-test-data/source/org/web/app/last-exile.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/waroverlays/default-overlays-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file +target/test-classes/unit/waroverlays/default-overlays-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/default-overlays-test-data/source/pansit.jsp b/src/test/resources/unit/waroverlays/default-overlays-test-data/source/pansit.jsp index a8dfe165..bce1d623 100644 --- a/src/test/resources/unit/waroverlays/default-overlays-test-data/source/pansit.jsp +++ b/src/test/resources/unit/waroverlays/default-overlays-test-data/source/pansit.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/waroverlays/default-overlays-test-data/source/pansit.jsp \ No newline at end of file +target/test-classes/unit/waroverlays/default-overlays-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/no-overlay-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/waroverlays/no-overlay-test-data/source/org/web/app/last-exile.jsp index d2169459..a8781fd1 100644 --- a/src/test/resources/unit/waroverlays/no-overlay-test-data/source/org/web/app/last-exile.jsp +++ b/src/test/resources/unit/waroverlays/no-overlay-test-data/source/org/web/app/last-exile.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/waroverlays/no-overlay-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file +target/test-classes/unit/waroverlays/no-overlay-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/no-overlay-test-data/source/pansit.jsp b/src/test/resources/unit/waroverlays/no-overlay-test-data/source/pansit.jsp index 80f13df2..32708211 100644 --- a/src/test/resources/unit/waroverlays/no-overlay-test-data/source/pansit.jsp +++ b/src/test/resources/unit/waroverlays/no-overlay-test-data/source/pansit.jsp @@ -1 +1 @@ -/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/waroverlays/no-overlay-test-data/source/pansit.jsp \ No newline at end of file +target/test-classes/unit/waroverlays/no-overlay-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/waroverlays/no-overlay-test-data/xml-config/web.xml b/src/test/resources/unit/waroverlays/no-overlay-test-data/xml-config/web.xml index a99b1d46..fc10e9de 100644 --- a/src/test/resources/unit/waroverlays/no-overlay-test-data/xml-config/web.xml +++ b/src/test/resources/unit/waroverlays/no-overlay-test-data/xml-config/web.xml @@ -1 +1 @@ -/home/sparsick/dev/workspace/m-war-plugin-master/target/test-classes/unit/waroverlays/no-overlay-test-data/xml-config/web.xml \ No newline at end of file +target/test-classes/unit/waroverlays/no-overlay-test-data/xml-config/web.xml \ No newline at end of file From 0d86356988c584840ed7071aef1a875af377060c Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Fri, 12 Dec 2025 07:26:35 +0100 Subject: [PATCH 58/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarMojoTest --- .../apache/maven/plugins/war/WarMojoTest.java | 20 +++++++++++-------- .../xml-config/web.xml | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java index 15084057..0994026f 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java @@ -108,22 +108,26 @@ public void testSimpleWar(WarMojo mojo) throws Exception { } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx") @MojoParameter( name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-output") + @MojoParameter(name = "webXml", value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/xml-config/web.xml") @MojoParameter(name = "warName", value = "simple") @MojoParameter(name = "packagingIncludes", value = "%regex[(.(?!exile))+]") @Test public void testSimpleWarPackagingExcludeWithIncludesRegEx(WarMojo mojo) throws Exception { - String testId = "SimpleWarPackagingExcludeWithIncludesRegEx"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory, xmlSource); - + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + project.setArtifact(warArtifact); + mojo.setProject(project); mojo.execute(); // validate jar file @@ -140,7 +144,7 @@ public void testSimpleWarPackagingExcludeWithIncludesRegEx(WarMojo mojo) throws "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { - null, mojo.getWebXml().toString(), null, null, null, + null, mojo.getWebXml().getName(), null, null, null, }, new String[] {"org/web/app/last-exile.jsp"}); } diff --git a/src/test/resources/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/xml-config/web.xml b/src/test/resources/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/xml-config/web.xml index dbec5fb6..d188dff5 100644 --- a/src/test/resources/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/xml-config/web.xml +++ b/src/test/resources/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/xml-config/web.xml @@ -1 +1 @@ -target/test-classes/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/xml-config/web.xml \ No newline at end of file +web.xml \ No newline at end of file From c90fc56bdecaea59df10d129ed109f17e5463975 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Fri, 12 Dec 2025 07:28:16 +0100 Subject: [PATCH 59/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarMojoTest --- .../apache/maven/plugins/war/WarMojoTest.java | 20 +++++++++++-------- .../xml-config/web.xml | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java index 0994026f..31910b70 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java @@ -150,21 +150,25 @@ public void testSimpleWarPackagingExcludeWithIncludesRegEx(WarMojo mojo) throws } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx") @MojoParameter( name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-output") + @MojoParameter(name = "webXml", value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-test-data/xml-config/web.xml") @MojoParameter(name = "warName", value = "simple") @MojoParameter(name = "packagingExcludes", value = "%regex[.+/last-exile.+]") @Test public void testSimpleWarPackagingExcludesWithRegEx(WarMojo mojo) throws Exception { - String testId = "SimpleWarPackagingExcludesWithRegEx"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory, xmlSource); + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + project.setArtifact(warArtifact); + mojo.setProject(project); mojo.execute(); @@ -182,7 +186,7 @@ public void testSimpleWarPackagingExcludesWithRegEx(WarMojo mojo) throws Excepti "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { - null, mojo.getWebXml().toString(), null, null, null, + null, mojo.getWebXml().getName(), null, null, null, }, new String[] {"org/web/app/last-exile.jsp"}); } diff --git a/src/test/resources/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-test-data/xml-config/web.xml b/src/test/resources/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-test-data/xml-config/web.xml index 93d685b4..d188dff5 100644 --- a/src/test/resources/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-test-data/xml-config/web.xml +++ b/src/test/resources/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-test-data/xml-config/web.xml @@ -1 +1 @@ -target/test-classes/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-test-data/xml-config/web.xml \ No newline at end of file +web.xml \ No newline at end of file From cfcc08ce278ce4a1be7bc8212aa7ca7c7132925e Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Fri, 12 Dec 2025 07:29:49 +0100 Subject: [PATCH 60/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarMojoTest --- .../apache/maven/plugins/war/WarMojoTest.java | 24 ++++++++++++------- .../Classifier-test-data/xml-config/web.xml | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java index 31910b70..6c2de526 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java @@ -192,19 +192,25 @@ public void testSimpleWarPackagingExcludesWithRegEx(WarMojo mojo) throws Excepti } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") - @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/Classifier-output") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warmojotest/Classifier-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warmojotest/Classifier-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warmojotest/Classifier") + @MojoParameter( + name = "outputDirectory", + value = "target/test-classes/unit/warmojotest/Classifier-output") + @MojoParameter(name = "webXml", value = "target/test-classes/unit/warmojotest/Classifier-test-data/xml-config/web.xml") @MojoParameter(name = "classifier", value = "test-classifier") @MojoParameter(name = "warName", value = "simple") @Test public void testClassifier(WarMojo mojo) throws Exception { - String testId = "Classifier"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory, xmlSource); + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + project.setArtifact(warArtifact); + mojo.setProject(project); mojo.execute(); @@ -222,7 +228,7 @@ public void testClassifier(WarMojo mojo) throws Exception { "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, - new String[] {null, mojo.getWebXml().toString(), null, null, null, null}); + new String[] {null, mojo.getWebXml().getName(), null, null, null, null}); } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") diff --git a/src/test/resources/unit/warmojotest/Classifier-test-data/xml-config/web.xml b/src/test/resources/unit/warmojotest/Classifier-test-data/xml-config/web.xml index 2b56bab3..d188dff5 100644 --- a/src/test/resources/unit/warmojotest/Classifier-test-data/xml-config/web.xml +++ b/src/test/resources/unit/warmojotest/Classifier-test-data/xml-config/web.xml @@ -1 +1 @@ -target/test-classes/unit/warmojotest/Classifier-test-data/xml-config/web.xml \ No newline at end of file +web.xml \ No newline at end of file From be54524bb0a752efefe5e8b3db0a8f293b21bb39 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Fri, 12 Dec 2025 07:31:50 +0100 Subject: [PATCH 61/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarMojoTest --- .../apache/maven/plugins/war/WarMojoTest.java | 24 ++++++++++++------- .../xml-config/web.xml | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java index 6c2de526..d7fdda79 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java @@ -232,19 +232,25 @@ public void testClassifier(WarMojo mojo) throws Exception { } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") - @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/PrimaryArtifact-output") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warmojotest/PrimaryArtifact-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warmojotest/PrimaryArtifact-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warmojotest/PrimaryArtifact") + @MojoParameter( + name = "outputDirectory", + value = "target/test-classes/unit/warmojotest/PrimaryArtifact-output") + @MojoParameter(name = "webXml", value = "target/test-classes/unit/warmojotest/PrimaryArtifact-test-data/xml-config/web.xml") @MojoParameter(name = "warName", value = "simple") @Test public void testPrimaryArtifact(WarMojo mojo) throws Exception { - String testId = "PrimaryArtifact"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); warArtifact.setFile(new File("error.war")); - configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory, xmlSource); + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + project.setArtifact(warArtifact); + mojo.setProject(project); mojo.execute(); @@ -262,7 +268,7 @@ public void testPrimaryArtifact(WarMojo mojo) throws Exception { "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, - new String[] {null, mojo.getWebXml().toString(), null, null, null, null}); + new String[] {null, mojo.getWebXml().getName(), null, null, null, null}); } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/not-primary-artifact.xml") diff --git a/src/test/resources/unit/warmojotest/PrimaryArtifact-test-data/xml-config/web.xml b/src/test/resources/unit/warmojotest/PrimaryArtifact-test-data/xml-config/web.xml index e5506074..d188dff5 100644 --- a/src/test/resources/unit/warmojotest/PrimaryArtifact-test-data/xml-config/web.xml +++ b/src/test/resources/unit/warmojotest/PrimaryArtifact-test-data/xml-config/web.xml @@ -1 +1 @@ -target/test-classes/unit/warmojotest/PrimaryArtifact-test-data/xml-config/web.xml \ No newline at end of file +web.xml \ No newline at end of file From f5a2b59991ed23e7b029c36d0880d93db8eaacb3 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Fri, 12 Dec 2025 07:33:23 +0100 Subject: [PATCH 62/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarMojoTest --- .../apache/maven/plugins/war/WarMojoTest.java | 24 ++++++++++++------- .../xml-config/web.xml | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java index d7fdda79..f0b9351e 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java @@ -272,19 +272,25 @@ public void testPrimaryArtifact(WarMojo mojo) throws Exception { } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/not-primary-artifact.xml") - @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/NotPrimaryArtifact-output") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warmojotest/NotPrimaryArtifact-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warmojotest/NotPrimaryArtifact-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warmojotest/NotPrimaryArtifact") + @MojoParameter( + name = "outputDirectory", + value = "target/test-classes/unit/warmojotest/NotPrimaryArtifact-output") + @MojoParameter(name = "webXml", value = "target/test-classes/unit/warmojotest/NotPrimaryArtifact-test-data/xml-config/web.xml") @MojoParameter(name = "warName", value = "simple") @Test public void testNotPrimaryArtifact(WarMojo mojo) throws Exception { - String testId = "NotPrimaryArtifact"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); warArtifact.setFile(new File("error.war")); - configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory, xmlSource); + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + project.setArtifact(warArtifact); + mojo.setProject(project); mojo.execute(); @@ -302,7 +308,7 @@ public void testNotPrimaryArtifact(WarMojo mojo) throws Exception { "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, - new String[] {null, mojo.getWebXml().toString(), null, null, null, null}); + new String[] {null, mojo.getWebXml().getName(), null, null, null, null}); } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") diff --git a/src/test/resources/unit/warmojotest/NotPrimaryArtifact-test-data/xml-config/web.xml b/src/test/resources/unit/warmojotest/NotPrimaryArtifact-test-data/xml-config/web.xml index 4267382a..d188dff5 100644 --- a/src/test/resources/unit/warmojotest/NotPrimaryArtifact-test-data/xml-config/web.xml +++ b/src/test/resources/unit/warmojotest/NotPrimaryArtifact-test-data/xml-config/web.xml @@ -1 +1 @@ -target/test-classes/unit/warmojotest/NotPrimaryArtifact-test-data/xml-config/web.xml \ No newline at end of file +web.xml \ No newline at end of file From c58fddbf22f52039563e03fffbc0f22b1056189f Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Fri, 12 Dec 2025 07:36:53 +0100 Subject: [PATCH 63/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarMojoTest --- .../apache/maven/plugins/war/WarMojoTest.java | 24 +++++++++---------- .../xml-config/web.xml | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java index f0b9351e..680de3b2 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java @@ -312,24 +312,24 @@ public void testNotPrimaryArtifact(WarMojo mojo) throws Exception { } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarWithMetaInfContent") @MojoParameter( name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarWithMetaInfContent-output") + @MojoParameter(name = "webXml", value = "target/test-classes/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/xml-config/web.xml") @MojoParameter(name = "warName", value = "simple") @Test public void testMetaInfContent(WarMojo mojo) throws Exception { - String testId = "SimpleWarWithMetaInfContent"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - - // Create the sample config.xml - final File configFile = new File(webAppSource, "META-INF/config.xml"); - createFile(configFile, ""); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory, xmlSource); + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + project.setArtifact(warArtifact); + mojo.setProject(project); mojo.execute(); @@ -348,7 +348,7 @@ public void testMetaInfContent(WarMojo mojo) throws Exception { "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, - new String[] {null, null, mojo.getWebXml().toString(), null, null, null, null}); + new String[] {null, null, mojo.getWebXml().getName(), null, null, null, null}); } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") diff --git a/src/test/resources/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/xml-config/web.xml b/src/test/resources/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/xml-config/web.xml index a6d60504..d188dff5 100644 --- a/src/test/resources/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/xml-config/web.xml +++ b/src/test/resources/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/xml-config/web.xml @@ -1 +1 @@ -target/test-classes/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/xml-config/web.xml \ No newline at end of file +web.xml \ No newline at end of file From 0dc2a1c7e5098a91b1ab0ae903f2000ef49c19c6 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Fri, 12 Dec 2025 07:39:58 +0100 Subject: [PATCH 64/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarMojoTest --- .../apache/maven/plugins/war/WarMojoTest.java | 30 +++++++++---------- .../xml-config/web.xml | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java index 680de3b2..19f950c0 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java @@ -352,31 +352,31 @@ public void testMetaInfContent(WarMojo mojo) throws Exception { } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarWithContainerConfig-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarWithContainerConfig-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarWithContainerConfig") @MojoParameter( name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarWithContainerConfig-output") + @MojoParameter(name = "webXml", value = "target/test-classes/unit/warmojotest/SimpleWarWithContainerConfig-test-data/xml-config/web.xml") + @MojoParameter(name = "containerConfigXML", value = "target/test-classes/unit/warmojotest/SimpleWarWithContainerConfig-test-data/source/META-INF/config.xml") @MojoParameter(name = "warName", value = "simple") @Test public void testMetaInfContentWithContainerConfig(WarMojo mojo) throws Exception { - String testId = "SimpleWarWithContainerConfig"; - String outputDir = MojoExtension.getVariableValueFromObject(mojo, "outputDirectory") - .toString(); - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - - // Create the sample config.xml - final File configFile = new File(webAppSource, "META-INF/config.xml"); - createFile(configFile, ""); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory, xmlSource); - mojo.setContainerConfigXML(configFile); + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + project.setArtifact(warArtifact); + mojo.setProject(project); mojo.execute(); // validate jar file + String outputDir = MojoExtension.getVariableValueFromObject(mojo, "outputDirectory") + .toString(); File expectedJarFile = new File(outputDir, "simple.war"); assertJarContent( expectedJarFile, @@ -389,7 +389,7 @@ public void testMetaInfContentWithContainerConfig(WarMojo mojo) throws Exception "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, - new String[] {null, null, mojo.getWebXml().toString(), null, null, null, null}); + new String[] {null, null, mojo.getWebXml().getName(), null, null, null, null}); } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") diff --git a/src/test/resources/unit/warmojotest/SimpleWarWithContainerConfig-test-data/xml-config/web.xml b/src/test/resources/unit/warmojotest/SimpleWarWithContainerConfig-test-data/xml-config/web.xml index f6392350..d188dff5 100644 --- a/src/test/resources/unit/warmojotest/SimpleWarWithContainerConfig-test-data/xml-config/web.xml +++ b/src/test/resources/unit/warmojotest/SimpleWarWithContainerConfig-test-data/xml-config/web.xml @@ -1 +1 @@ -target/test-classes/unit/warmojotest/SimpleWarWithContainerConfig-test-data/xml-config/web.xml \ No newline at end of file +web.xml \ No newline at end of file From b5d529bc16577991a793a0ca2f27e94753997feb Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Fri, 12 Dec 2025 07:42:08 +0100 Subject: [PATCH 65/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarMojoTest --- .../apache/maven/plugins/war/WarMojoTest.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java index 19f950c0..e8799de9 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java @@ -393,20 +393,25 @@ public void testMetaInfContentWithContainerConfig(WarMojo mojo) throws Exception } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarMissingWebXmlFalse-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarMissingWebXmlFalse-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarMissingWebXmlFalse") @MojoParameter( name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarMissingWebXmlFalse-output") + @MojoParameter(name = "webXml", value = "target/test-classes/unit/warmojotest/SimpleWarMissingWebXmlFalse-test-data/xml-config/web.xml") + @MojoParameter(name = "failOnMissingWebXml", value = "false") @MojoParameter(name = "warName", value = "simple") @Test public void testFailOnMissingWebXmlFalse(WarMojo mojo) throws Exception { - String testId = "SimpleWarMissingWebXmlFalse"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory); - mojo.setFailOnMissingWebXml(false); + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + project.setArtifact(warArtifact); + mojo.setProject(project); mojo.execute(); // validate jar file From 0e628ed57d4238ffd6a85304d787aca5fe55dd24 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Fri, 12 Dec 2025 07:43:27 +0100 Subject: [PATCH 66/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarMojoTest --- .../apache/maven/plugins/war/WarMojoTest.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java index e8799de9..61e4acb1 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java @@ -433,20 +433,26 @@ public void testFailOnMissingWebXmlFalse(WarMojo mojo) throws Exception { } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarMissingWebXmlTrue-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarMissingWebXmlTrue-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarMissingWebXmlTrue") @MojoParameter( name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarMissingWebXmlTrue-output") @MojoParameter(name = "warName", value = "simple") + @MojoParameter(name = "failOnMissingWebXml", value = "true") + @Test public void testFailOnMissingWebXmlTrue(WarMojo mojo) throws Exception { - String testId = "SimpleWarMissingWebXmlTrue"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory); - mojo.setFailOnMissingWebXml(true); + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + project.setArtifact(warArtifact); + mojo.setProject(project); try { mojo.execute(); From bf68e4653f3898147ef78fe8c1a1e5e1e9add473 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Fri, 12 Dec 2025 08:17:08 +0100 Subject: [PATCH 67/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarMojoTest --- .../apache/maven/plugins/war/WarMojoTest.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java index 61e4acb1..20636c16 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java @@ -35,6 +35,7 @@ import org.apache.maven.api.plugin.testing.MojoTest; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.handler.DefaultArtifactHandler; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.war.stub.JarArtifactStub; import org.apache.maven.plugins.war.stub.MavenProject4CopyConstructor; @@ -44,7 +45,6 @@ import org.apache.maven.project.MavenProjectHelper; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir; @@ -445,7 +445,6 @@ public void testFailOnMissingWebXmlFalse(WarMojo mojo) throws Exception { value = "target/test-classes/unit/warmojotest/SimpleWarMissingWebXmlTrue-output") @MojoParameter(name = "warName", value = "simple") @MojoParameter(name = "failOnMissingWebXml", value = "true") - @Test public void testFailOnMissingWebXmlTrue(WarMojo mojo) throws Exception { @@ -463,25 +462,26 @@ public void testFailOnMissingWebXmlTrue(WarMojo mojo) throws Exception { } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarUnderServlet30-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarUnderServlet30-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarUnderServlet30") @MojoParameter( name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarUnderServlet30-output") @MojoParameter(name = "warName", value = "simple") @Test - @Disabled // TODO test failed and error message corresponed to the test case description public void testFailOnMissingWebXmlNotSpecifiedAndServlet30Used(WarMojo mojo) throws Exception { - String testId = "SimpleWarUnderServlet30"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); JarArtifactStub jarArtifactStub = createServletApi3JarArtifact(); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); project.addArtifact(jarArtifactStub); project.setArtifact(warArtifact); project.setFile(warArtifact.getFile()); - configureMojo(mojo, project, classesDir, webAppSource, webAppDirectory); + mojo.setProject(project); mojo.execute(); @@ -504,7 +504,9 @@ public void testFailOnMissingWebXmlNotSpecifiedAndServlet30Used(WarMojo mojo) th } private JarArtifactStub createServletApi3JarArtifact() { - JarArtifactStub jarArtifactStub = new JarArtifactStub(getBasedir(), artifactHandler); + DefaultArtifactHandler jarArtifactHandler = new DefaultArtifactHandler("jar"); + jarArtifactHandler.setAddedToClasspath(true); + JarArtifactStub jarArtifactStub = new JarArtifactStub(getBasedir(), jarArtifactHandler); jarArtifactStub.setFile( new File(getBasedir(), "/target/test-classes/unit/sample_wars/javax.servlet-api-3.0.1.jar")); jarArtifactStub.setScope(Artifact.SCOPE_PROVIDED); From b11d525c60d3af1c26399cbe2a9491591ea3607b Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Fri, 12 Dec 2025 08:18:24 +0100 Subject: [PATCH 68/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarMojoTest --- .../apache/maven/plugins/war/WarMojoTest.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java index 20636c16..4e031398 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java @@ -514,22 +514,24 @@ private JarArtifactStub createServletApi3JarArtifact() { } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarNotUnderServlet30-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarNotUnderServlet30-test-data/source/") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarNotUnderServlet30") @MojoParameter( name = "outputDirectory", - value = "target/test-classes/unit/warmojotest/SimpleWarUnderServlet30-output") + value = "target/test-classes/unit/warmojotest/SimpleWarNotUnderServlet30-output") @MojoParameter(name = "warName", value = "simple") @Test public void testFailOnMissingWebXmlNotSpecifiedAndServlet30NotUsed(WarMojo mojo) throws Exception { - String testId = "SimpleWarNotUnderServlet30"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); MavenProjectArtifactsStub project = new MavenProjectArtifactsStub(); project.setArtifact(warArtifact); project.setFile(warArtifact.getFile()); - configureMojo(mojo, project, classesDir, webAppSource, webAppDirectory); + mojo.setProject(project); try { mojo.execute(); From e739a1164d84402254354adb6c4236dc68e4ea8d Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Fri, 12 Dec 2025 08:21:00 +0100 Subject: [PATCH 69/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarMojoTest --- .../apache/maven/plugins/war/WarMojoTest.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java index 4e031398..8905a089 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java @@ -543,20 +543,24 @@ public void testFailOnMissingWebXmlNotSpecifiedAndServlet30NotUsed(WarMojo mojo) } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warmojotest/AttachClasses-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warmojotest/AttachClasses-test-data/source/") + @MojoParameter(name = "webXml", value = "target/test-classes/unit/warmojotest/AttachClasses-test-data/xml-config/web.xml") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warmojotest/AttachClasses") @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/AttachClasses-output") @MojoParameter(name = "warName", value = "simple") + @MojoParameter(name = "attachClasses", value = "true") + @MojoParameter(name = "classesClassifier", value = "classes") @Test public void testAttachClasses(WarMojo mojo) throws Exception { - String testId = "AttachClasses"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, false); - File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory, xmlSource); - mojo.setAttachClasses(true); - mojo.setClassesClassifier("classes"); + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + project.setArtifact(warArtifact); + mojo.setProject(project); mojo.execute(); From 3e9a07bc4dd1da97f0cc500315b748f99d0f11a8 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Fri, 12 Dec 2025 08:24:13 +0100 Subject: [PATCH 70/80] refactor: remove unused code --- .../apache/maven/plugins/war/WarMojoTest.java | 165 ++---------------- 1 file changed, 13 insertions(+), 152 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java index 8905a089..dae215e0 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java @@ -43,7 +43,6 @@ import org.apache.maven.plugins.war.stub.ProjectHelperStub; import org.apache.maven.plugins.war.stub.WarArtifact4CCStub; import org.apache.maven.project.MavenProjectHelper; -import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; import org.junit.jupiter.api.Test; @@ -60,16 +59,6 @@ @MojoTest public class WarMojoTest { - @Inject - private MavenProjectHelper projectHelper; - - @Inject - private ArtifactHandler artifactHandler; - - @Provides - private MavenProjectHelper projectHelper() { - return new ProjectHelperStub(); - } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") @MojoParameter( @@ -575,21 +564,23 @@ public void testAttachClasses(WarMojo mojo) throws Exception { @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") @MojoParameter( - name = "outputDirectory", - value = "target/test-classes/unit/warmojotest/AttachClassesCustomClassifier-output") + name = "classesDirectory", + value = "target/test-classes/unit/warmojotest/AttachClassesCustomClassifier-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warmojotest/AttachClassesCustomClassifier-test-data/source/") + @MojoParameter(name = "webXml", value = "target/test-classes/unit/warmojotest/AttachClassesCustomClassifier-test-data/xml-config/web.xml") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warmojotest/AttachClassesCustomClassifier") + @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/AttachClassesCustomClassifier-output") @MojoParameter(name = "warName", value = "simple") + @MojoParameter(name = "attachClasses", value = "true") + @MojoParameter(name = "classesClassifier", value = "mystuff") @Test public void testAttachClassesWithCustomClassifier(WarMojo mojo) throws Exception { - String testId = "AttachClassesCustomClassifier"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, false); - File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); - configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory, xmlSource); - mojo.setAttachClasses(true); - mojo.setClassesClassifier("mystuff"); + MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); + project.setArtifact(warArtifact); + mojo.setProject(project); mojo.execute(); @@ -602,41 +593,6 @@ public void testAttachClassesWithCustomClassifier(WarMojo mojo) throws Exception }); } - private void configureMojo( - WarMojo mojo, - WarArtifact4CCStub warArtifact, - File classesDir, - File webAppSource, - File webAppDirectory, - File xmlSource) - throws Exception { - configureMojo(mojo, warArtifact, classesDir, webAppSource, webAppDirectory); - mojo.setWebXml(new File(xmlSource, "web.xml")); - } - - private void configureMojo( - WarMojo mojo, MavenProjectArtifactsStub project, File classesDir, File webAppSource, File webAppDirectory) { - mojo.setProject(project); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - } - - private void configureMojo( - WarMojo mojo, WarArtifact4CCStub warArtifact, File classesDir, File webAppSource, File webAppDirectory) - throws Exception { - MavenProject4CopyConstructor project = new MavenProject4CopyConstructor(); - project.setArtifact(warArtifact); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setProject(project); - } - - private File getTestDirectory() { - return new File(getBasedir(), "target/test-classes/unit/warmojotest"); - } - private Map assertJarContent( final File expectedJarFile, final String[] files, final String[] filesContent) throws IOException { return assertJarContent(expectedJarFile, files, filesContent, null); @@ -681,99 +637,4 @@ private Map assertJarContent( } } - /** - * create an isolated xml dir - * - * @param id The id. - * @param xmlFiles array of xml files. - * @return The created file. - * @throws Exception in case of errors. - */ - private File createXMLConfigDir(String id, String[] xmlFiles) throws Exception { - File xmlConfigDir = new File(getTestDirectory(), "/" + id + "-test-data/xml-config"); - File xmlFile; - - createDir(xmlConfigDir); - - if (xmlFiles != null) { - for (String o : xmlFiles) { - xmlFile = new File(xmlConfigDir, o); - createFile(xmlFile); - } - } - - return xmlConfigDir; - } - - /** - * Returns the webapp source directory for the specified id. - * - * @param id the id of the test - * @return the source directory for that test - * @throws Exception if an exception occurs - */ - private File getWebAppSource(String id) throws Exception { - return new File(getTestDirectory(), "/" + id + "-test-data/source"); - } - - /** - * create an isolated web source with a sample jsp file - * - * @param id The id. - * @param createSamples Create example files yes or no. - * @return The created file. - * @throws Exception in case of errors. - */ - private File createWebAppSource(String id, boolean createSamples) throws Exception { - File webAppSource = getWebAppSource(id); - if (createSamples) { - File simpleJSP = new File(webAppSource, "pansit.jsp"); - File jspFile = new File(webAppSource, "org/web/app/last-exile.jsp"); - - createFile(simpleJSP); - createFile(jspFile); - } - return webAppSource; - } - - private File createWebAppSource(String id) throws Exception { - return createWebAppSource(id, true); - } - - /** - * create a class directory with or without a sample class - * - * @param id The id. - * @param empty true to create a class files false otherwise. - * @return The created class file. - * @throws Exception in case of errors. - */ - private File createClassesDir(String id, boolean empty) throws Exception { - File classesDir = new File(getTestDirectory() + "/" + id + "-test-data/classes/"); - - createDir(classesDir); - - if (!empty) { - createFile(new File(classesDir + "/sample-servlet.clazz")); - } - - return classesDir; - } - - private void createDir(File dir) { - if (!dir.exists()) { - assertTrue(dir.mkdirs(), "can not create test dir: " + dir.toString()); - } - } - - private void createFile(File testFile, String body) throws Exception { - createDir(testFile.getParentFile()); - FileUtils.fileWrite(testFile.toString(), body); - - assertTrue(testFile.exists(), "could not create file: " + testFile); - } - - private void createFile(File testFile) throws Exception { - createFile(testFile, testFile.toString()); - } } From ba11f870a387d66e3c84a5538b94d59cf990109d Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Fri, 12 Dec 2025 08:24:48 +0100 Subject: [PATCH 71/80] refactor: spotless --- .../maven/plugins/war/WarInPlaceMojoTest.java | 9 +- .../apache/maven/plugins/war/WarMojoTest.java | 88 ++++++++++++------- 2 files changed, 61 insertions(+), 36 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java index a67bfe43..787ef1fa 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarInPlaceMojoTest.java @@ -23,7 +23,6 @@ import org.apache.maven.api.plugin.testing.InjectMojo; import org.apache.maven.api.plugin.testing.MojoParameter; import org.apache.maven.api.plugin.testing.MojoTest; -import org.apache.maven.plugin.testing.stubs.MavenProjectStub; import org.apache.maven.plugins.war.stub.MavenProjectBasicStub; import org.apache.maven.plugins.war.stub.ResourceStub; import org.junit.jupiter.api.Test; @@ -41,12 +40,15 @@ public class WarInPlaceMojoTest { @MojoParameter( name = "warSourceDirectory", value = "target/test-classes/unit/warexplodedinplacemojo/SimpleExplodedInplaceWar-test-data/source/") - @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warexplodedinplacemojo/SimpleExplodedInplaceWar") + @MojoParameter( + name = "webappDirectory", + value = "target/test-classes/unit/warexplodedinplacemojo/SimpleExplodedInplaceWar") @Test public void testSimpleExplodedInplaceWar(WarInPlaceMojo mojo) throws Exception { // configure mojo ResourceStub[] resources = new ResourceStub[] {new ResourceStub()}; - resources[0].setDirectory(getBasedir() + "/target/test-classes/unit/warexplodedinplacemojo/SimpleExplodedInplaceWar-test-data/resources"); + resources[0].setDirectory(getBasedir() + + "/target/test-classes/unit/warexplodedinplacemojo/SimpleExplodedInplaceWar-test-data/resources"); mojo.setWebResources(resources); MavenProjectBasicStub project = new MavenProjectBasicStub(); mojo.setProject(project); @@ -66,5 +68,4 @@ public void testSimpleExplodedInplaceWar(WarInPlaceMojo mojo) throws Exception { assertTrue(expectedWEBINFDir.exists(), "WEB-INF not found"); assertTrue(expectedMETAINFDir.exists(), "META-INF not found"); } - } diff --git a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java index dae215e0..195f4808 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarMojoTest.java @@ -18,8 +18,6 @@ */ package org.apache.maven.plugins.war; -import javax.inject.Inject; - import java.io.File; import java.io.IOException; import java.util.Enumeration; @@ -28,21 +26,17 @@ import java.util.jar.JarEntry; import java.util.jar.JarFile; -import org.apache.maven.api.di.Provides; 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.Artifact; -import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.DefaultArtifactHandler; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.war.stub.JarArtifactStub; import org.apache.maven.plugins.war.stub.MavenProject4CopyConstructor; import org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub; -import org.apache.maven.plugins.war.stub.ProjectHelperStub; import org.apache.maven.plugins.war.stub.WarArtifact4CCStub; -import org.apache.maven.project.MavenProjectHelper; import org.codehaus.plexus.util.IOUtil; import org.junit.jupiter.api.Test; @@ -59,7 +53,6 @@ @MojoTest public class WarMojoTest { - @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") @MojoParameter( name = "classesDirectory", @@ -70,7 +63,9 @@ public class WarMojoTest { @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warmojotest/SimpleWar") @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWar-output") @MojoParameter(name = "warName", value = "simple") - @MojoParameter(name = "webXml", value = "target/test-classes/unit/warmojotest/SimpleWar-test-data/xml-config/web.xml") + @MojoParameter( + name = "webXml", + value = "target/test-classes/unit/warmojotest/SimpleWar-test-data/xml-config/web.xml") @Test public void testSimpleWar(WarMojo mojo) throws Exception { WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir()); @@ -99,15 +94,21 @@ public void testSimpleWar(WarMojo mojo) throws Exception { @InjectMojo(goal = "war", pom = "src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml") @MojoParameter( name = "classesDirectory", - value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/classes/") + value = + "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/classes/") @MojoParameter( name = "warSourceDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/source/") - @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx") + @MojoParameter( + name = "webappDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx") @MojoParameter( name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-output") - @MojoParameter(name = "webXml", value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/xml-config/web.xml") + @MojoParameter( + name = "webXml", + value = + "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludeWithIncludesRegEx-test-data/xml-config/web.xml") @MojoParameter(name = "warName", value = "simple") @MojoParameter(name = "packagingIncludes", value = "%regex[(.(?!exile))+]") @Test @@ -145,11 +146,16 @@ public void testSimpleWarPackagingExcludeWithIncludesRegEx(WarMojo mojo) throws @MojoParameter( name = "warSourceDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-test-data/source/") - @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx") + @MojoParameter( + name = "webappDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx") @MojoParameter( name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-output") - @MojoParameter(name = "webXml", value = "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-test-data/xml-config/web.xml") + @MojoParameter( + name = "webXml", + value = + "target/test-classes/unit/warmojotest/SimpleWarPackagingExcludesWithRegEx-test-data/xml-config/web.xml") @MojoParameter(name = "warName", value = "simple") @MojoParameter(name = "packagingExcludes", value = "%regex[.+/last-exile.+]") @Test @@ -188,10 +194,10 @@ public void testSimpleWarPackagingExcludesWithRegEx(WarMojo mojo) throws Excepti name = "warSourceDirectory", value = "target/test-classes/unit/warmojotest/Classifier-test-data/source/") @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warmojotest/Classifier") + @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/Classifier-output") @MojoParameter( - name = "outputDirectory", - value = "target/test-classes/unit/warmojotest/Classifier-output") - @MojoParameter(name = "webXml", value = "target/test-classes/unit/warmojotest/Classifier-test-data/xml-config/web.xml") + name = "webXml", + value = "target/test-classes/unit/warmojotest/Classifier-test-data/xml-config/web.xml") @MojoParameter(name = "classifier", value = "test-classifier") @MojoParameter(name = "warName", value = "simple") @Test @@ -228,10 +234,10 @@ public void testClassifier(WarMojo mojo) throws Exception { name = "warSourceDirectory", value = "target/test-classes/unit/warmojotest/PrimaryArtifact-test-data/source/") @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warmojotest/PrimaryArtifact") + @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/PrimaryArtifact-output") @MojoParameter( - name = "outputDirectory", - value = "target/test-classes/unit/warmojotest/PrimaryArtifact-output") - @MojoParameter(name = "webXml", value = "target/test-classes/unit/warmojotest/PrimaryArtifact-test-data/xml-config/web.xml") + name = "webXml", + value = "target/test-classes/unit/warmojotest/PrimaryArtifact-test-data/xml-config/web.xml") @MojoParameter(name = "warName", value = "simple") @Test public void testPrimaryArtifact(WarMojo mojo) throws Exception { @@ -268,10 +274,10 @@ public void testPrimaryArtifact(WarMojo mojo) throws Exception { name = "warSourceDirectory", value = "target/test-classes/unit/warmojotest/NotPrimaryArtifact-test-data/source/") @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warmojotest/NotPrimaryArtifact") + @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/NotPrimaryArtifact-output") @MojoParameter( - name = "outputDirectory", - value = "target/test-classes/unit/warmojotest/NotPrimaryArtifact-output") - @MojoParameter(name = "webXml", value = "target/test-classes/unit/warmojotest/NotPrimaryArtifact-test-data/xml-config/web.xml") + name = "webXml", + value = "target/test-classes/unit/warmojotest/NotPrimaryArtifact-test-data/xml-config/web.xml") @MojoParameter(name = "warName", value = "simple") @Test public void testNotPrimaryArtifact(WarMojo mojo) throws Exception { @@ -311,7 +317,9 @@ public void testNotPrimaryArtifact(WarMojo mojo) throws Exception { @MojoParameter( name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarWithMetaInfContent-output") - @MojoParameter(name = "webXml", value = "target/test-classes/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/xml-config/web.xml") + @MojoParameter( + name = "webXml", + value = "target/test-classes/unit/warmojotest/SimpleWarWithMetaInfContent-test-data/xml-config/web.xml") @MojoParameter(name = "warName", value = "simple") @Test public void testMetaInfContent(WarMojo mojo) throws Exception { @@ -347,12 +355,19 @@ public void testMetaInfContent(WarMojo mojo) throws Exception { @MojoParameter( name = "warSourceDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarWithContainerConfig-test-data/source/") - @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarWithContainerConfig") + @MojoParameter( + name = "webappDirectory", + value = "target/test-classes/unit/warmojotest/SimpleWarWithContainerConfig") @MojoParameter( name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarWithContainerConfig-output") - @MojoParameter(name = "webXml", value = "target/test-classes/unit/warmojotest/SimpleWarWithContainerConfig-test-data/xml-config/web.xml") - @MojoParameter(name = "containerConfigXML", value = "target/test-classes/unit/warmojotest/SimpleWarWithContainerConfig-test-data/source/META-INF/config.xml") + @MojoParameter( + name = "webXml", + value = "target/test-classes/unit/warmojotest/SimpleWarWithContainerConfig-test-data/xml-config/web.xml") + @MojoParameter( + name = "containerConfigXML", + value = + "target/test-classes/unit/warmojotest/SimpleWarWithContainerConfig-test-data/source/META-INF/config.xml") @MojoParameter(name = "warName", value = "simple") @Test public void testMetaInfContentWithContainerConfig(WarMojo mojo) throws Exception { @@ -392,7 +407,9 @@ public void testMetaInfContentWithContainerConfig(WarMojo mojo) throws Exception @MojoParameter( name = "outputDirectory", value = "target/test-classes/unit/warmojotest/SimpleWarMissingWebXmlFalse-output") - @MojoParameter(name = "webXml", value = "target/test-classes/unit/warmojotest/SimpleWarMissingWebXmlFalse-test-data/xml-config/web.xml") + @MojoParameter( + name = "webXml", + value = "target/test-classes/unit/warmojotest/SimpleWarMissingWebXmlFalse-test-data/xml-config/web.xml") @MojoParameter(name = "failOnMissingWebXml", value = "false") @MojoParameter(name = "warName", value = "simple") @Test @@ -538,7 +555,9 @@ public void testFailOnMissingWebXmlNotSpecifiedAndServlet30NotUsed(WarMojo mojo) @MojoParameter( name = "warSourceDirectory", value = "target/test-classes/unit/warmojotest/AttachClasses-test-data/source/") - @MojoParameter(name = "webXml", value = "target/test-classes/unit/warmojotest/AttachClasses-test-data/xml-config/web.xml") + @MojoParameter( + name = "webXml", + value = "target/test-classes/unit/warmojotest/AttachClasses-test-data/xml-config/web.xml") @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warmojotest/AttachClasses") @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/AttachClasses-output") @MojoParameter(name = "warName", value = "simple") @@ -569,9 +588,15 @@ public void testAttachClasses(WarMojo mojo) throws Exception { @MojoParameter( name = "warSourceDirectory", value = "target/test-classes/unit/warmojotest/AttachClassesCustomClassifier-test-data/source/") - @MojoParameter(name = "webXml", value = "target/test-classes/unit/warmojotest/AttachClassesCustomClassifier-test-data/xml-config/web.xml") - @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warmojotest/AttachClassesCustomClassifier") - @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warmojotest/AttachClassesCustomClassifier-output") + @MojoParameter( + name = "webXml", + value = "target/test-classes/unit/warmojotest/AttachClassesCustomClassifier-test-data/xml-config/web.xml") + @MojoParameter( + name = "webappDirectory", + value = "target/test-classes/unit/warmojotest/AttachClassesCustomClassifier") + @MojoParameter( + name = "outputDirectory", + value = "target/test-classes/unit/warmojotest/AttachClassesCustomClassifier-output") @MojoParameter(name = "warName", value = "simple") @MojoParameter(name = "attachClasses", value = "true") @MojoParameter(name = "classesClassifier", value = "mystuff") @@ -636,5 +661,4 @@ private Map assertJarContent( return jarContent; } } - } From 07fe3c624587a2efed6594cc6e254e6f036028a4 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Fri, 12 Dec 2025 08:27:31 +0100 Subject: [PATCH 72/80] refactor: remove unused code --- .../maven/plugins/war/WarOverlaysTest.java | 184 ------------------ 1 file changed, 184 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java index 05083163..8c99d109 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java @@ -38,7 +38,6 @@ import org.codehaus.plexus.archiver.ArchiverException; import org.codehaus.plexus.archiver.jar.JarArchiver; import org.codehaus.plexus.util.FileUtils; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir; @@ -58,16 +57,6 @@ public class WarOverlaysTest { private static final File OVERLAYS_ROOT_DIR = new File(getBasedir(), "target/test-classes/overlays/"); private static final String MANIFEST_PATH = "META-INF" + File.separator + "MANIFEST.MF"; - @BeforeEach - public void setUp() throws Exception { - // generateFullOverlayWar("overlay-full-1"); - // generateFullOverlayWar("overlay-full-2"); - // generateFullOverlayWar("overlay-full-3"); - } - - private File getTestDirectory() { - return new File(getBasedir(), "target/test-classes/unit/waroverlays"); - } @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/waroverlays/default.xml") @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-no-overlay") @@ -653,30 +642,6 @@ private void assertWebAppContent(File webAppDirectory, List expectedFiles, + webAppContent.size() + " file(s) " + webAppContent); } - /** - * create an isolated xml dir - * - * @param id The id. - * @param xmlFiles array of xml files. - * @return The created file. - * @throws Exception in case of errors. - */ - private File createXMLConfigDir(String id, String[] xmlFiles) throws Exception { - File xmlConfigDir = new File(getTestDirectory(), "/" + id + "-test-data/xml-config"); - File xmlFile; - - createDir(xmlConfigDir); - - if (xmlFiles != null) { - for (String o : xmlFiles) { - xmlFile = new File(xmlConfigDir, o); - createFile(xmlFile); - } - } - - return xmlConfigDir; - } - /** * Builds the list of files and directories from the specified dir. * @@ -703,155 +668,6 @@ private void buildFilesList(final File dir, FileFilter filter, final List } } - /** - * Returns the webapp source directory for the specified id. - * - * @param id the id of the test - * @return the source directory for that test - * @throws Exception if an exception occurs - */ - private File getWebAppSource(String id) throws Exception { - return new File(getTestDirectory(), "/" + id + "-test-data/source"); - } - - /** - * create an isolated web source with a sample jsp file - * - * @param id The id. - * @param createSamples Create example files yes or no. - * @return The created file. - * @throws Exception in case of errors. - */ - private File createWebAppSource(String id, boolean createSamples) throws Exception { - File webAppSource = getWebAppSource(id); - if (createSamples) { - File simpleJSP = new File(webAppSource, "pansit.jsp"); - File jspFile = new File(webAppSource, "org/web/app/last-exile.jsp"); - - createFile(simpleJSP); - createFile(jspFile); - } - return webAppSource; - } - - private File createWebAppSource(String id) throws Exception { - return createWebAppSource(id, true); - } - - /** - * create a class directory with or without a sample class - * - * @param id The id. - * @param empty true to create a class files false otherwise. - * @return The created class file. - * @throws Exception in case of errors. - */ - private File createClassesDir(String id, boolean empty) throws Exception { - File classesDir = new File(getTestDirectory() + "/" + id + "-test-data/classes/"); - - createDir(classesDir); - - if (!empty) { - createFile(new File(classesDir + "/sample-servlet.clazz")); - } - - return classesDir; - } - - private void createDir(File dir) { - if (!dir.exists()) { - assertTrue(dir.mkdirs(), "can not create test dir: " + dir); - } - } - - private void createFile(File testFile, String body) throws Exception { - createDir(testFile.getParentFile()); - FileUtils.fileWrite(testFile.toString(), body); - - assertTrue(testFile.exists(), "could not create file: " + testFile); - } - - private void createFile(File testFile) throws Exception { - createFile(testFile, testFile.toString()); - } - - /** - * Generates test war. - * Generates war with such a structure: - *

    - *
  • jsp - *
      - *
    • d - *
        - *
      • a.jsp
      • - *
      • b.jsp
      • - *
      • c.jsp
      • - *
      - *
    • - *
    • a.jsp
    • - *
    • b.jsp
    • - *
    • c.jsp
    • - *
    - *
  • - *
  • WEB-INF - *
      - *
    • classes - *
        - *
      • a.clazz
      • - *
      • b.clazz
      • - *
      • c.clazz
      • - *
      - *
    • - *
    • lib - *
        - *
      • a.jar
      • - *
      • b.jar
      • - *
      • c.jar
      • - *
      - *
    • - *
    • web.xml
    • - *
    - *
  • - *
- * Each of the files will contain: id+'-'+path - * - * @param id the id of the overlay containing the full structure - * @return the war file - * @throws Exception if an error occurs - */ - private File generateFullOverlayWar(String id) throws Exception { - final File destFile = new File(OVERLAYS_TEMP_DIR, id + ".war"); - if (destFile.exists()) { - return destFile; - } - - // Archive was not yet created for that id so let's create it - final File rootDir = new File(OVERLAYS_ROOT_DIR, id); - rootDir.mkdirs(); - String[] filePaths = new String[] { - "jsp/d/a.jsp", - "jsp/d/b.jsp", - "jsp/d/c.jsp", - "jsp/a.jsp", - "jsp/b.jsp", - "jsp/c.jsp", - "WEB-INF/classes/a.clazz", - "WEB-INF/classes/b.clazz", - "WEB-INF/classes/c.clazz", - "WEB-INF/lib/a.jar", - "WEB-INF/lib/b.jar", - "WEB-INF/lib/c.jar", - "WEB-INF/web.xml" - }; - - for (String filePath : filePaths) { - createFile(new File(rootDir, filePath), id + "-" + filePath); - } - - createArchive(rootDir, destFile); - return destFile; - } - /** * Builds a test overlay. * From 2ff6a08fcbb52f0be22372f8abf6de4c7295f809 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Fri, 12 Dec 2025 08:30:46 +0100 Subject: [PATCH 73/80] refactor: spotless --- src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java index 8c99d109..7cb6163b 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarOverlaysTest.java @@ -57,7 +57,6 @@ public class WarOverlaysTest { private static final File OVERLAYS_ROOT_DIR = new File(getBasedir(), "target/test-classes/overlays/"); private static final String MANIFEST_PATH = "META-INF" + File.separator + "MANIFEST.MF"; - @InjectMojo(goal = "exploded", pom = "src/test/resources/unit/waroverlays/default.xml") @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/waroverlays/war/work-no-overlay") @MojoParameter( From 876a0ac32711ddf12ee0957f08563bb2430911de Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Fri, 12 Dec 2025 10:32:06 +0100 Subject: [PATCH 74/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarZipTest --- .../apache/maven/plugins/war/WarZipTest.java | 19 ++++++++++++------- .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + .../xml-config/web.xml | 1 + .../source/org/web/app/last-exile.jsp | 1 + .../source/pansit.jsp | 1 + .../xml-config/web.xml | 1 + .../source/org/web/app/last-exile.jsp | 1 + .../one-zip-test-data/source/pansit.jsp | 1 + .../one-zip-test-data/xml-config/web.xml | 1 + 10 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 src/test/resources/unit/warziptest/one-zip-overlay-skip-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warziptest/one-zip-overlay-skip-test-data/source/pansit.jsp create mode 100644 src/test/resources/unit/warziptest/one-zip-overlay-skip-test-data/xml-config/web.xml create mode 100644 src/test/resources/unit/warziptest/one-zip-overlay-targetPath-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warziptest/one-zip-overlay-targetPath-test-data/source/pansit.jsp create mode 100644 src/test/resources/unit/warziptest/one-zip-overlay-targetPath-test-data/xml-config/web.xml create mode 100644 src/test/resources/unit/warziptest/one-zip-test-data/source/org/web/app/last-exile.jsp create mode 100644 src/test/resources/unit/warziptest/one-zip-test-data/source/pansit.jsp create mode 100644 src/test/resources/unit/warziptest/one-zip-test-data/xml-config/web.xml diff --git a/src/test/java/org/apache/maven/plugins/war/WarZipTest.java b/src/test/java/org/apache/maven/plugins/war/WarZipTest.java index 02e44067..6e458042 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarZipTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarZipTest.java @@ -48,23 +48,28 @@ public class WarZipTest { private ArtifactHandler artifactHandler; @InjectMojo(goal = "war", pom = "src/test/resources/unit/warziptest/war-with-zip.xml") + @MojoParameter(name = "classesDirectory", value = "target/test-classes/unit/warziptest/one-zip-test-data/classes/") + @MojoParameter(name = "warSourceDirectory", value = "target/test-classes/unit/warziptest/one-zip-test-data/source/") + @MojoParameter(name = "webXml", value = "target/test-classes/unit/warziptest/one-zip-test-data/xml-config/web.xml") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warziptest/one-zip") @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warziptest/one-zip-output") @MojoParameter(name = "warName", value = "simple") @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/warziptest/work") @Test public void testOneZipWithNoSkip(WarMojo mojo) throws Exception { - String testId = "one-zip"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - Overlay overlay = new DefaultOverlay(buildZipArtifact()); overlay.setType("zip"); - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, xmlSource, overlay); + mojo.addOverlay(overlay); + + WarArtifactStub warArtifact = new WarArtifactStub(getBasedir()); + MavenZipProject project = new MavenZipProject(); + project.setArtifact(warArtifact); + project.getArtifacts().add(buildZipArtifact()); + mojo.setProject(project); mojo.execute(); + File webAppDirectory = mojo.getWebappDirectory(); File foo = new File(webAppDirectory, "foo.txt"); assertTrue(foo.exists(), "foo.txt not exists"); assertTrue(foo.isFile(), "foo.txt not a file"); diff --git a/src/test/resources/unit/warziptest/one-zip-overlay-skip-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warziptest/one-zip-overlay-skip-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..7453d86e --- /dev/null +++ b/src/test/resources/unit/warziptest/one-zip-overlay-skip-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +one-zip-overlay-skip-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warziptest/one-zip-overlay-skip-test-data/source/pansit.jsp b/src/test/resources/unit/warziptest/one-zip-overlay-skip-test-data/source/pansit.jsp new file mode 100644 index 00000000..60538912 --- /dev/null +++ b/src/test/resources/unit/warziptest/one-zip-overlay-skip-test-data/source/pansit.jsp @@ -0,0 +1 @@ +one-zip-overlay-skip-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warziptest/one-zip-overlay-skip-test-data/xml-config/web.xml b/src/test/resources/unit/warziptest/one-zip-overlay-skip-test-data/xml-config/web.xml new file mode 100644 index 00000000..80d42e3a --- /dev/null +++ b/src/test/resources/unit/warziptest/one-zip-overlay-skip-test-data/xml-config/web.xml @@ -0,0 +1 @@ +one-zip-overlay-skip-test-data/xml-config/web.xml \ No newline at end of file diff --git a/src/test/resources/unit/warziptest/one-zip-overlay-targetPath-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warziptest/one-zip-overlay-targetPath-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..820d8d48 --- /dev/null +++ b/src/test/resources/unit/warziptest/one-zip-overlay-targetPath-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +one-zip-overlay-targetPath-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warziptest/one-zip-overlay-targetPath-test-data/source/pansit.jsp b/src/test/resources/unit/warziptest/one-zip-overlay-targetPath-test-data/source/pansit.jsp new file mode 100644 index 00000000..f17b1b9b --- /dev/null +++ b/src/test/resources/unit/warziptest/one-zip-overlay-targetPath-test-data/source/pansit.jsp @@ -0,0 +1 @@ +one-zip-overlay-targetPath-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warziptest/one-zip-overlay-targetPath-test-data/xml-config/web.xml b/src/test/resources/unit/warziptest/one-zip-overlay-targetPath-test-data/xml-config/web.xml new file mode 100644 index 00000000..e23d626b --- /dev/null +++ b/src/test/resources/unit/warziptest/one-zip-overlay-targetPath-test-data/xml-config/web.xml @@ -0,0 +1 @@ +one-zip-overlay-targetPath-test-data/xml-config/web.xml \ No newline at end of file diff --git a/src/test/resources/unit/warziptest/one-zip-test-data/source/org/web/app/last-exile.jsp b/src/test/resources/unit/warziptest/one-zip-test-data/source/org/web/app/last-exile.jsp new file mode 100644 index 00000000..bcdcc58f --- /dev/null +++ b/src/test/resources/unit/warziptest/one-zip-test-data/source/org/web/app/last-exile.jsp @@ -0,0 +1 @@ +one-zip-test-data/source/org/web/app/last-exile.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warziptest/one-zip-test-data/source/pansit.jsp b/src/test/resources/unit/warziptest/one-zip-test-data/source/pansit.jsp new file mode 100644 index 00000000..cd4513e5 --- /dev/null +++ b/src/test/resources/unit/warziptest/one-zip-test-data/source/pansit.jsp @@ -0,0 +1 @@ +one-zip-test-data/source/pansit.jsp \ No newline at end of file diff --git a/src/test/resources/unit/warziptest/one-zip-test-data/xml-config/web.xml b/src/test/resources/unit/warziptest/one-zip-test-data/xml-config/web.xml new file mode 100644 index 00000000..f3689c2b --- /dev/null +++ b/src/test/resources/unit/warziptest/one-zip-test-data/xml-config/web.xml @@ -0,0 +1 @@ +one-zip-test-data/xml-config/web.xml \ No newline at end of file From 09e82cb0db0d8c4831036830b128cf8fde34debf Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Fri, 12 Dec 2025 10:36:20 +0100 Subject: [PATCH 75/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarZipTest --- .../apache/maven/plugins/war/WarZipTest.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarZipTest.java b/src/test/java/org/apache/maven/plugins/war/WarZipTest.java index 6e458042..e273eb21 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarZipTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarZipTest.java @@ -21,6 +21,7 @@ import javax.inject.Inject; import java.io.File; +import java.net.URI; import org.apache.maven.api.plugin.testing.InjectMojo; import org.apache.maven.api.plugin.testing.MojoParameter; @@ -84,26 +85,30 @@ public void testOneZipWithNoSkip(WarMojo mojo) throws Exception { } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warziptest/war-with-zip.xml") - @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warziptest/one-zip-output") + @MojoParameter(name = "classesDirectory", value = "target/test-classes/unit/warziptest/one-zip-overlay-targetPath-test-data/classes/") + @MojoParameter(name = "warSourceDirectory", value = "target/test-classes/unit/warziptest/one-zip-overlay-targetPath-test-data/source/") + @MojoParameter(name = "webXml", value = "target/test-classes/unit/warziptest/one-zip-overlay-targetPath-test-data/xml-config/web.xml") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warziptest/one-zip-overlay-targetPath") + @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warziptest/one-zip-overlay-targetPath-output") @MojoParameter(name = "warName", value = "simple") @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/warziptest/work") @Test public void testOneZipWithTargetPathOverlay(WarMojo mojo) throws Exception { - String testId = "one-zip-overlay-targetPath"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - Overlay overlay = new DefaultOverlay(buildZipArtifact()); overlay.setSkip(false); overlay.setType("zip"); overlay.setTargetPath("overridePath"); + mojo.addOverlay(overlay); - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, xmlSource, overlay); + WarArtifactStub warArtifact = new WarArtifactStub(getBasedir()); + MavenZipProject project = new MavenZipProject(); + project.setArtifact(warArtifact); + project.getArtifacts().add(buildZipArtifact()); + mojo.setProject(project); mojo.execute(); + File webAppDirectory = mojo.getWebappDirectory(); File foo = new File(webAppDirectory.getPath() + File.separatorChar + "overridePath", "foo.txt"); assertTrue(foo.exists(), "foo.txt not exists"); assertTrue(foo.isFile(), "foo.txt not a file"); From f6d64454c7477d9af23ed079675ec0ff10b7b01a Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Fri, 12 Dec 2025 10:45:34 +0100 Subject: [PATCH 76/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarZipTest --- .../apache/maven/plugins/war/WarZipTest.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarZipTest.java b/src/test/java/org/apache/maven/plugins/war/WarZipTest.java index e273eb21..f26a6c94 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarZipTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarZipTest.java @@ -21,7 +21,6 @@ import javax.inject.Inject; import java.io.File; -import java.net.URI; import org.apache.maven.api.plugin.testing.InjectMojo; import org.apache.maven.api.plugin.testing.MojoParameter; @@ -123,24 +122,24 @@ public void testOneZipWithTargetPathOverlay(WarMojo mojo) throws Exception { } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warziptest/war-with-zip.xml") - @MojoParameter( - name = "outputDirectory", - value = "target/test-classes/unit/warziptest/one-zip-overlay-default-skip-output") + @MojoParameter(name = "classesDirectory", value = "target/test-classes/unit/warziptest/one-zip-overlay-skip-test-data/classes/") + @MojoParameter(name = "warSourceDirectory", value = "target/test-classes/unit/warziptest/one-zip-overlay-skip-test-data/source/") + @MojoParameter(name = "webXml", value = "target/test-classes/unit/warziptest/one-zip-overlay-skip-test-data/xml-config/web.xml") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warziptest/one-zip-overlay-skip") + @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warziptest/one-zip-overlay-skip-output") @MojoParameter(name = "warName", value = "simple") @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/warziptest/work") @Test public void testOneZipDefaultSkip(WarMojo mojo) throws Exception { - String testId = "one-zip-overlay-default-skip"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, xmlSource); + WarArtifactStub warArtifact = new WarArtifactStub(getBasedir()); + MavenZipProject project = new MavenZipProject(); + project.setArtifact(warArtifact); + project.getArtifacts().add(buildZipArtifact()); + mojo.setProject(project); mojo.execute(); - assertZipContentNotHere(webAppDirectory); + assertZipContentNotHere(mojo.getWebappDirectory()); } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warziptest/war-with-zip.xml") From 119278604c1a9497e0eaf82f9f95a854fde37bd3 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Fri, 12 Dec 2025 10:48:06 +0100 Subject: [PATCH 77/80] chore: migrate AbstractMojoTestCase based tests to use MojoTest - WarZipTest --- .../apache/maven/plugins/war/WarZipTest.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarZipTest.java b/src/test/java/org/apache/maven/plugins/war/WarZipTest.java index f26a6c94..0d95f05c 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarZipTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarZipTest.java @@ -143,6 +143,10 @@ public void testOneZipDefaultSkip(WarMojo mojo) throws Exception { } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warziptest/war-with-zip.xml") + @MojoParameter(name = "classesDirectory", value = "target/test-classes/unit/warziptest/one-zip-overlay-skip-test-data/classes/") + @MojoParameter(name = "warSourceDirectory", value = "target/test-classes/unit/warziptest/one-zip-overlay-skip-test-data/source/") + @MojoParameter(name = "webXml", value = "target/test-classes/unit/warziptest/one-zip-overlay-skip-test-data/xml-config/web.xml") + @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warziptest/one-zip-overlay-skip") @MojoParameter( name = "outputDirectory", value = "target/test-classes/unit/warziptest/one-zip-overlay-force-skip-output") @@ -150,13 +154,12 @@ public void testOneZipDefaultSkip(WarMojo mojo) throws Exception { @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/warziptest/work") @Test public void testOneZipWithForceSkip(WarMojo mojo) throws Exception { - String testId = "one-zip-overlay-force-skip"; - File webAppDirectory = new File(getTestDirectory(), testId); - File webAppSource = createWebAppSource(testId); - File classesDir = createClassesDir(testId, true); - File xmlSource = createXMLConfigDir(testId, new String[] {"web.xml"}); - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, xmlSource); + WarArtifactStub warArtifact = new WarArtifactStub(getBasedir()); + MavenZipProject project = new MavenZipProject(); + project.setArtifact(warArtifact); + project.getArtifacts().add(buildZipArtifact()); + mojo.setProject(project); Overlay overlay = new DefaultOverlay(buildZipArtifact()); overlay.setSkip(true); @@ -165,7 +168,7 @@ public void testOneZipWithForceSkip(WarMojo mojo) throws Exception { mojo.execute(); - assertZipContentNotHere(webAppDirectory); + assertZipContentNotHere(mojo.getWebappDirectory()); } private void configureMojo( From b8a05feb05f386074e81e40eacd9afe154fa17a8 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Fri, 12 Dec 2025 10:50:22 +0100 Subject: [PATCH 78/80] refactor: spotless --- .../apache/maven/plugins/war/WarZipTest.java | 165 ++++-------------- 1 file changed, 33 insertions(+), 132 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/war/WarZipTest.java b/src/test/java/org/apache/maven/plugins/war/WarZipTest.java index 0d95f05c..33da0f3a 100644 --- a/src/test/java/org/apache/maven/plugins/war/WarZipTest.java +++ b/src/test/java/org/apache/maven/plugins/war/WarZipTest.java @@ -23,6 +23,7 @@ import java.io.File; 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.Artifact; @@ -31,7 +32,6 @@ import org.apache.maven.plugins.war.stub.MavenZipProject; import org.apache.maven.plugins.war.stub.WarArtifactStub; import org.apache.maven.plugins.war.stub.ZipArtifactStub; -import org.codehaus.plexus.util.FileUtils; import org.junit.jupiter.api.Test; import static org.apache.maven.api.plugin.testing.MojoExtension.getBasedir; @@ -84,11 +84,19 @@ public void testOneZipWithNoSkip(WarMojo mojo) throws Exception { } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warziptest/war-with-zip.xml") - @MojoParameter(name = "classesDirectory", value = "target/test-classes/unit/warziptest/one-zip-overlay-targetPath-test-data/classes/") - @MojoParameter(name = "warSourceDirectory", value = "target/test-classes/unit/warziptest/one-zip-overlay-targetPath-test-data/source/") - @MojoParameter(name = "webXml", value = "target/test-classes/unit/warziptest/one-zip-overlay-targetPath-test-data/xml-config/web.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warziptest/one-zip-overlay-targetPath-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warziptest/one-zip-overlay-targetPath-test-data/source/") + @MojoParameter( + name = "webXml", + value = "target/test-classes/unit/warziptest/one-zip-overlay-targetPath-test-data/xml-config/web.xml") @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warziptest/one-zip-overlay-targetPath") - @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warziptest/one-zip-overlay-targetPath-output") + @MojoParameter( + name = "outputDirectory", + value = "target/test-classes/unit/warziptest/one-zip-overlay-targetPath-output") @MojoParameter(name = "warName", value = "simple") @MojoParameter(name = "workDirectory", value = "target/test-classes/unit/warziptest/work") @Test @@ -122,9 +130,15 @@ public void testOneZipWithTargetPathOverlay(WarMojo mojo) throws Exception { } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warziptest/war-with-zip.xml") - @MojoParameter(name = "classesDirectory", value = "target/test-classes/unit/warziptest/one-zip-overlay-skip-test-data/classes/") - @MojoParameter(name = "warSourceDirectory", value = "target/test-classes/unit/warziptest/one-zip-overlay-skip-test-data/source/") - @MojoParameter(name = "webXml", value = "target/test-classes/unit/warziptest/one-zip-overlay-skip-test-data/xml-config/web.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warziptest/one-zip-overlay-skip-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warziptest/one-zip-overlay-skip-test-data/source/") + @MojoParameter( + name = "webXml", + value = "target/test-classes/unit/warziptest/one-zip-overlay-skip-test-data/xml-config/web.xml") @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warziptest/one-zip-overlay-skip") @MojoParameter(name = "outputDirectory", value = "target/test-classes/unit/warziptest/one-zip-overlay-skip-output") @MojoParameter(name = "warName", value = "simple") @@ -143,9 +157,15 @@ public void testOneZipDefaultSkip(WarMojo mojo) throws Exception { } @InjectMojo(goal = "war", pom = "src/test/resources/unit/warziptest/war-with-zip.xml") - @MojoParameter(name = "classesDirectory", value = "target/test-classes/unit/warziptest/one-zip-overlay-skip-test-data/classes/") - @MojoParameter(name = "warSourceDirectory", value = "target/test-classes/unit/warziptest/one-zip-overlay-skip-test-data/source/") - @MojoParameter(name = "webXml", value = "target/test-classes/unit/warziptest/one-zip-overlay-skip-test-data/xml-config/web.xml") + @MojoParameter( + name = "classesDirectory", + value = "target/test-classes/unit/warziptest/one-zip-overlay-skip-test-data/classes/") + @MojoParameter( + name = "warSourceDirectory", + value = "target/test-classes/unit/warziptest/one-zip-overlay-skip-test-data/source/") + @MojoParameter( + name = "webXml", + value = "target/test-classes/unit/warziptest/one-zip-overlay-skip-test-data/xml-config/web.xml") @MojoParameter(name = "webappDirectory", value = "target/test-classes/unit/warziptest/one-zip-overlay-skip") @MojoParameter( name = "outputDirectory", @@ -171,35 +191,12 @@ public void testOneZipWithForceSkip(WarMojo mojo) throws Exception { assertZipContentNotHere(mojo.getWebappDirectory()); } - private void configureMojo( - WarMojo mojo, File classesDir, File webAppSource, File webAppDirectory, File xmlSource, Overlay overlay) - throws Exception { - configureMojo(mojo, classesDir, webAppSource, webAppDirectory, xmlSource); - mojo.addOverlay(overlay); - } - - private void configureMojo(WarMojo mojo, File classesDir, File webAppSource, File webAppDirectory, File xmlSource) - throws Exception { - WarArtifactStub warArtifact = new WarArtifactStub(getBasedir()); - MavenZipProject project = new MavenZipProject(); - project.setArtifact(warArtifact); - project.getArtifacts().add(buildZipArtifact()); - mojo.setProject(project); - mojo.setClassesDirectory(classesDir); - mojo.setWarSourceDirectory(webAppSource); - mojo.setWebappDirectory(webAppDirectory); - mojo.setWebXml(new File(xmlSource, "web.xml")); - } - private Artifact buildZipArtifact() throws Exception { - File zipFile = new File(getTestDirectory(), "foobar.zip"); + File zipFile = + new File(new File(MojoExtension.getBasedir(), "target/test-classes/unit/warziptest"), "foobar.zip"); return new ZipArtifactStub("src/test/resources/unit/warziptest", artifactHandler, zipFile); } - private File getTestDirectory() { - return new File(getBasedir(), "target/test-classes/unit/warziptest"); - } - private void assertZipContentNotHere(File webAppDirectory) { File foo = new File(webAppDirectory.getPath() + File.separatorChar + "overridePath", "foo.txt"); assertFalse(foo.exists(), "foo.txt exists"); @@ -213,100 +210,4 @@ private void assertZipContentNotHere(File webAppDirectory) { assertFalse(bar.exists(), "bar/bar.txt exists"); assertFalse(bar.isFile(), "bar/bar.txt is a file"); } - - /** - * create an isolated xml dir - * - * @param id The id. - * @param xmlFiles array of xml files. - * @return The created file. - * @throws Exception in case of errors. - */ - private File createXMLConfigDir(String id, String[] xmlFiles) throws Exception { - File xmlConfigDir = new File(getTestDirectory(), "/" + id + "-test-data/xml-config"); - File xmlFile; - - createDir(xmlConfigDir); - - if (xmlFiles != null) { - for (String o : xmlFiles) { - xmlFile = new File(xmlConfigDir, o); - createFile(xmlFile); - } - } - - return xmlConfigDir; - } - - /** - * Returns the webapp source directory for the specified id. - * - * @param id the id of the test - * @return the source directory for that test - * @throws Exception if an exception occurs - */ - private File getWebAppSource(String id) throws Exception { - return new File(getTestDirectory(), "/" + id + "-test-data/source"); - } - - /** - * create an isolated web source with a sample jsp file - * - * @param id The id. - * @param createSamples Create example files yes or no. - * @return The created file. - * @throws Exception in case of errors. - */ - private File createWebAppSource(String id, boolean createSamples) throws Exception { - File webAppSource = getWebAppSource(id); - if (createSamples) { - File simpleJSP = new File(webAppSource, "pansit.jsp"); - File jspFile = new File(webAppSource, "org/web/app/last-exile.jsp"); - - createFile(simpleJSP); - createFile(jspFile); - } - return webAppSource; - } - - private File createWebAppSource(String id) throws Exception { - return createWebAppSource(id, true); - } - - /** - * create a class directory with or without a sample class - * - * @param id The id. - * @param empty true to create a class files false otherwise. - * @return The created class file. - * @throws Exception in case of errors. - */ - private File createClassesDir(String id, boolean empty) throws Exception { - File classesDir = new File(getTestDirectory() + "/" + id + "-test-data/classes/"); - - createDir(classesDir); - - if (!empty) { - createFile(new File(classesDir + "/sample-servlet.clazz")); - } - - return classesDir; - } - - private void createDir(File dir) { - if (!dir.exists()) { - assertTrue(dir.mkdirs(), "can not create test dir: " + dir.toString()); - } - } - - private void createFile(File testFile, String body) throws Exception { - createDir(testFile.getParentFile()); - FileUtils.fileWrite(testFile.toString(), body); - - assertTrue(testFile.exists(), "could not create file: " + testFile); - } - - private void createFile(File testFile) throws Exception { - createFile(testFile, testFile.toString()); - } } From eac328bc5ff60b70fdde53306fe555c4de0b46d6 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Wed, 17 Dec 2025 14:44:58 +0100 Subject: [PATCH 79/80] fix(ci): ensure that a git clone on windows does not chane eol --- .gitattributes | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..c329e496 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,18 @@ +# +# 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. +# + +* text=auto eol=lf \ No newline at end of file From 73911e546980ed4bdbb4e280c2b643b3806b6bd7 Mon Sep 17 00:00:00 2001 From: Sandra Parsick Date: Mon, 5 Jan 2026 08:31:14 +0100 Subject: [PATCH 80/80] fix(ci): ensure that a git clone on windows does not chane eol --- .gitattributes | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitattributes b/.gitattributes index c329e496..c2ed5060 100644 --- a/.gitattributes +++ b/.gitattributes @@ -14,5 +14,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # - -* text=auto eol=lf \ No newline at end of file +*.jsp text eol=lf \ No newline at end of file