From c2bac2e749b1348bb725b12b5afc54db013356b3 Mon Sep 17 00:00:00 2001 From: Scott Kurz Date: Wed, 9 Aug 2023 17:04:49 -0400 Subject: [PATCH 01/13] Fix 1572 Signed-off-by: Scott Kurz --- .../maven/applications/DeployMojoSupport.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java index b8a0b4bc0..96fe48a30 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java @@ -150,20 +150,27 @@ protected void installLooseConfigWar(MavenProject proj, LooseConfigData config, getLog().warn("Exploded WAR functionality is enabled. Please use maven-war-plugin version 3.3.1 or greater for best results."); } - // If I'm filtering web.xml, etc., I want to monitor from the exploded dir, not via a source dir + // Don't especially need to run it exactly here, but in debugger we can see what we have + runExplodedMojo(); + + // 1. source dir, but if DD filtering is enabled we want to exclude this and add only the exploded (filtered) contents if (!looseWar.isFilteringDeploymentDescriptors()) { looseWar.addSourceDir(); } - // Add source paths for non-filtered web resources. - // We'll already have the runtime application monitor watching for file changes, and we - // don't want to set up the more expensive dev mode type of watching. + // 2. Add source paths for non-filtered web resources. + // We'll already have the runtime application monitor watching for file changes, and we don't want to set up the more expensive + // dev mode type of watching. looseWar.addNonFilteredWebResourcesConfigurationPaths(); - // Don't especially need to run it exactly here, but in debugger we can see what we have - runExplodedMojo(); + // 3. target classes - this allows non-deploy mode cases (e.g. non-deploy cases such as `mvn compile` or m2e update in Eclipse) + // to pick up Java class updates + // upon compilation. + looseWar.addOutputDir(looseWar.getDocumentRoot(), new File(proj.getBuild().getOutputDirectory()), "/WEB-INF/classes"); ////////////////////////// + // 4. Finally add the exploded dir + // // Per doc: https://www.ibm.com/docs/en/was-liberty/base?topic=liberty-loose-applications // ".. If you have two files with the same target location in the loose archive, the first occurrence of the file is used. // The first occurrence is based on a top-down approach to reading the elements of the loose application configuration file..." From 21edfd1babb075f6e53401ba9b433e464fd8bc2d Mon Sep 17 00:00:00 2001 From: Scott Kurz Date: Thu, 10 Aug 2023 15:19:54 -0400 Subject: [PATCH 02/13] Run resources:resources on any resource change, to provide filter updates in non-exploded case Signed-off-by: Scott Kurz --- .../tools/maven/server/DevMojo.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java index 02a42d1ee..ea5f76156 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java @@ -811,20 +811,30 @@ protected void resourceDirectoryCreated() throws IOException { @Override protected void resourceModifiedOrCreated(File fileChanged, File resourceParent, File outputDirectory) throws IOException { - if (project.getPackaging().equals("war") && LooseWarApplication.isExploded(project)) { - try { - runMojo("org.apache.maven.plugins", "maven-resources-plugin", "resources"); - runExplodedMojo(); - } catch (MojoExecutionException e) { - getLog().error("Failed to run goal(s)", e); - } - } else { - copyFile(fileChanged, resourceParent, outputDirectory, null); + /** + * There is an asymmetry here that we take advantage of in the exploded case. For multi-mod, this would be a copyFile, which + * does not apply Maven filters. + */ + try { + runMojo("org.apache.maven.plugins", "maven-resources-plugin", "resources"); + } catch (MojoExecutionException e) { + getLog().error("Failed to run goal(s)", e); } } @Override protected void resourceDeleted(File fileChanged, File resourceParent, File outputDirectory) throws IOException { + + /** + * Why is this so asymmetric compared to resourceModifiedOrCreated() above? For two reasons: 1. The resources:resources plugin + * goal doesn't update the target/output directory with deletions, so we have to use our own custom deleteFile() method 2. In + * the case of the exploded loose app format, even having deleted the file from the outputDirectory ('target/classes'), the + * resource would typically also have been collected into the exploded 'webapp' directory. Even though it would take precedence + * in 'target/classes' when it ends up in both locations, it will still be present in the 'webapp' directory. So we re-run the + * exploded goal to force an "outdated" update cleaning this file from this location. Another approach might have been to do a + * delteFile() in the 'webapp' directory. + */ + deleteFile(fileChanged, resourceParent, outputDirectory, null); if (project.getPackaging().equals("war") && LooseWarApplication.isExploded(project)) { try { From 1bbb49fd04f96e4af378a9bd9c24bcd145b51624 Mon Sep 17 00:00:00 2001 From: Scott Kurz Date: Thu, 10 Aug 2023 16:21:26 -0400 Subject: [PATCH 03/13] Default outdatedCheckPath based on v3.3.1 or v3.3.2+ of maven-war-plugin but delegate to user config if present Signed-off-by: Scott Kurz --- docs/dev.md | 3 ++- .../tools/maven/applications/DeployMojoSupport.java | 5 +++-- .../java/io/openliberty/tools/maven/server/DevMojo.java | 5 +++-- .../tools/maven/server/StartDebugMojoSupport.java | 9 +++++++-- .../openliberty/tools/maven/utils/ExecuteMojoUtil.java | 2 +- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/docs/dev.md b/docs/dev.md index 19a8b9576..4f1bff42b 100644 --- a/docs/dev.md +++ b/docs/dev.md @@ -6,7 +6,8 @@ Start a Liberty instance in dev mode. This goal also invokes the `create`, `inst Starting in version 3.6.1, dev mode invokes the `generate-features` goal when the `generateFeatures` configuration parameter is set to `true`. **This goal modifies the source configuration directory of your application.** See [generate-features](generate-features.md) for details. The default value for the `generateFeatures` parameter is `false`. When auto-generation of features is turned on, dev mode has a runtime dependency on IBM WebSphere Application Server Migration Toolkit for Application Binaries, which is separately licensed under IBM License Agreement for Non-Warranted Programs. For more information, see the [license](https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/license/wamt). -Additionally, starting in 3.5.2-SNAPSHOT, [resource variable filtering](https://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html) and [WAR overlays](https://maven.apache.org/plugins/maven-war-plugin/overlays.html) are supported for loose WAR applications. This is done by automatically detecting appropriate Maven WAR plugin configuration and calling the WAR plugin's `exploded` goal and the Maven Resource plugin's `resource` goal when appropriate. Behavior for updating/deleting resources is delegated via the Maven WAR plugin configuration, including the `outdatedCheckPath` parameter enhanced in plugin version 3.3.2. +Additionally, starting in version 3.5.2, [resource variable filtering](https://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html) and [WAR overlays](https://maven.apache.org/plugins/maven-war-plugin/overlays.html) are supported for loose WAR applications. This is done by automatically detecting appropriate Maven WAR plugin configuration and calling the WAR plugin's [`exploded`](https://maven.apache.org/plugins/maven-war-plugin/exploded-mojo.html) goal and the Maven Resource plugin's [`resource`](https://maven.apache.org/plugins/maven-resources-plugin/resources-mojo.html) goal when appropriate. Behavior for updating/deleting resources can be configured via the [`outdatedCheckPath`](https://maven.apache.org/plugins/maven-war-plugin/exploded-mojo.html#outdatedCheckPath) parameter introduced and then enhanced in maven-war-plugin versions 3.3.1, 3.3.2. + To start the server in a container, see the [devc](#devc-container-mode) section below. diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java index 96fe48a30..1dd7598b0 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java @@ -146,8 +146,9 @@ protected void installLooseConfigWar(MavenProject proj, LooseConfigData config, // Validate maven-war-plugin version Plugin warPlugin = getPlugin("org.apache.maven.plugins", "maven-war-plugin"); - if (!validatePluginVersion(warPlugin.getVersion(), "3.3.1")) { - getLog().warn("Exploded WAR functionality is enabled. Please use maven-war-plugin version 3.3.1 or greater for best results."); + if (!validatePluginVersion(warPlugin.getVersion(), "3.3.2")) { + getLog().warn( + "Exploded WAR functionality is enabled. Please use maven-war-plugin version 3.3.2 or greater for best results."); } // Don't especially need to run it exactly here, but in debugger we can see what we have diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java index ea5f76156..88c70d024 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java @@ -773,8 +773,9 @@ protected void updateLooseApp() throws PluginExecutionException { // Validate maven-war-plugin version Plugin warPlugin = getPlugin("org.apache.maven.plugins", "maven-war-plugin"); - if (!validatePluginVersion(warPlugin.getVersion(), "3.3.1")) { - getLog().warn("Exploded WAR functionality is enabled. Please use maven-war-plugin version 3.3.1 or greater for best results."); + if (!validatePluginVersion(warPlugin.getVersion(), "3.3.2")) { + getLog().warn( + "Exploded WAR functionality is enabled. Please use maven-war-plugin version 3.3.2 or greater for best results."); } redeployApp(); diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/StartDebugMojoSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/StartDebugMojoSupport.java index 4199d251f..c8fdce107 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/StartDebugMojoSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/StartDebugMojoSupport.java @@ -207,9 +207,14 @@ protected void runExplodedMojo() throws MojoExecutionException { Plugin warPlugin = getPlugin("org.apache.maven.plugins", "maven-war-plugin"); Xpp3Dom explodedConfig = ExecuteMojoUtil.getPluginGoalConfig(warPlugin, "exploded", getLog()); - if (validatePluginVersion(warPlugin.getVersion(), "3.3.1")) { - explodedConfig.addChild(element(name("outdatedCheckPath"), "WEB-INF").toDom()); + if (explodedConfig.getChild("outdatedCheckPath") == null) { + if (validatePluginVersion(warPlugin.getVersion(), "3.3.2")) { + explodedConfig.addChild(element(name("outdatedCheckPath"), "/").toDom()); + } else if (validatePluginVersion(warPlugin.getVersion(), "3.3.1")) { + explodedConfig.addChild(element(name("outdatedCheckPath"), "WEB-INF").toDom()); + } } + getLog().info("Running maven-war-plugin:exploded"); getLog().debug("configuration:\n" + explodedConfig); session.getRequest().setStartTime(new Date()); diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/utils/ExecuteMojoUtil.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/utils/ExecuteMojoUtil.java index 2627503b3..6f633aecd 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/utils/ExecuteMojoUtil.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/utils/ExecuteMojoUtil.java @@ -141,7 +141,7 @@ public class ExecuteMojoUtil { // https://maven.apache.org/plugins/maven-war-plugin/exploded-mojo.html private static final ArrayList EXPLODED_PARAMS = new ArrayList<>(Arrays.asList( "filteringDeploymentDescriptors", "warSourceDirectory", "webappDirectory", "workDirectory", "filters", - "overlays", "webResources" + "outdatedCheckPath", "overlays", "webResources" )); // https://maven.apache.org/plugins/maven-ear-plugin/ear-mojo.html From 743f730c4633ed5b26c4f0ff30f73ed2c372d2ed Mon Sep 17 00:00:00 2001 From: Scott Kurz Date: Thu, 10 Aug 2023 19:35:05 -0400 Subject: [PATCH 04/13] Avoid duplication when war source dir is configured as webResource, while only writing non-filtered directories into loose WAR XML Signed-off-by: Scott Kurz --- .../maven/applications/DeployMojoSupport.java | 45 ++++--- .../applications/LooseWarApplication.java | 116 +++++++++++++++--- 2 files changed, 133 insertions(+), 28 deletions(-) diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java index 1dd7598b0..7efb85bc5 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java @@ -154,27 +154,38 @@ protected void installLooseConfigWar(MavenProject proj, LooseConfigData config, // Don't especially need to run it exactly here, but in debugger we can see what we have runExplodedMojo(); - // 1. source dir, but if DD filtering is enabled we want to exclude this and add only the exploded (filtered) contents - if (!looseWar.isFilteringDeploymentDescriptors()) { - looseWar.addSourceDir(); - } + //////////////////////////////////// + // The order matters and establishes a well-defined precedence as documented: + //////////////////////////////////// https://www.ibm.com/docs/en/was-liberty/base?topic=liberty-loose-applications + // + // ".. If you have two files with the same target location in the loose archive, the first occurrence of the file is used. + // The first occurrence is based on a top-down approach to reading the elements of the loose application configuration file..." + // + // Because the flow is so complicated we may have cases where we are applying filtering where one location contains a filtered + //////////////////////////////////// version + // of a file and another potentially has an unfiltered one, and in such cases we need to make sure the filtered version takes + //////////////////////////////////// precedence. + // + // In certain cases, like step 1. below we avoid writing a location into the loose app XML because we don't want an unfiltered + //////////////////////////////////// version + // to take precedence and prevent the filtered value from taking effect. + // + //////////////////////////////////// - // 2. Add source paths for non-filtered web resources. + // 1. Add source paths for the source dir and non-filtered web resources. Since there could be overlap, i.e. the source dir + // could also be configured as a web resource, we combine these into a single step. + // // We'll already have the runtime application monitor watching for file changes, and we don't want to set up the more expensive // dev mode type of watching. - looseWar.addNonFilteredWebResourcesConfigurationPaths(); + looseWar.addNonFilteredSourceAndWebResourcesPaths(); - // 3. target classes - this allows non-deploy mode cases (e.g. non-deploy cases such as `mvn compile` or m2e update in Eclipse) + // 2. target classes - this allows non-deploy mode cases (e.g. non-deploy cases such as `mvn compile` or m2e update in Eclipse) // to pick up Java class updates // upon compilation. looseWar.addOutputDir(looseWar.getDocumentRoot(), new File(proj.getBuild().getOutputDirectory()), "/WEB-INF/classes"); ////////////////////////// - // 4. Finally add the exploded dir - // - // Per doc: https://www.ibm.com/docs/en/was-liberty/base?topic=liberty-loose-applications - // ".. If you have two files with the same target location in the loose archive, the first occurrence of the file is used. - // The first occurrence is based on a top-down approach to reading the elements of the loose application configuration file..." + // 3. Finally add the exploded dir // // In order to dynamically reflect changes in non-filtered web app source, this needs to go AFTER the unfiltered source entries above, since // changes in these un-monitored directories will NOT cause a new 'exploded' goal execution, so the updated content in the unmonitored source will @@ -189,14 +200,20 @@ protected void installLooseConfigWar(MavenProject proj, LooseConfigData config, } else { + // 1. looseWar.addSourceDir(); + // 2. looseWar.addOutputDir(looseWar.getDocumentRoot(), new File(proj.getBuild().getOutputDirectory()), "/WEB-INF/classes"); - // retrieve the directories defined as resources in the maven war plugin + // 3. retrieve the directories defined as resources in the maven war plugin + // + // TODO - It would be cleaner to avoid duplicating the source dir in the case it also appears as a web resource, like we do in the exploded case. + // If this ever became an issue we could combine this with step 1. above. However at the moment it doesn't seem worth the risk of making a change + // in such a key area. looseWar.addAllWebResourcesConfigurationPaths(); - // retrieves dependent library jar files + // 4. retrieves dependent library jar files addEmbeddedLib(looseWar.getDocumentRoot(), proj, looseWar, "/WEB-INF/lib/"); } diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/LooseWarApplication.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/LooseWarApplication.java index a4b9a95f3..e66719330 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/LooseWarApplication.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/LooseWarApplication.java @@ -102,10 +102,36 @@ private Path getWebAppDirectory(MavenProject project) { } } + /** + * @param project + * + * @return A list of directory Path(s) including each web source directory that has filtering applied, including the war source + * directory (if so configured) or webResources entries + */ public static List getFilteredWebSourceDirectories(MavenProject project) { - List retVal = new ArrayList(); + Set filteredWebResources = getFilteredWebResourcesConfigurations(project); + + List retVal = new ArrayList(filteredWebResources); + + Path warSourceDir = getWarSourceDirectory(project); + // Need to add warSourceDir if DD filtering enabled, unless it's already in the list having its own webResources config + if (isFilteringDeploymentDescriptors(project) && !filteredWebResources.contains(warSourceDir)) { + retVal.add(warSourceDir); + } + + return retVal; + } + + /** + * @param project + * + * @return List of webResources/resource configurations with filtering enabled, whether they happen to be the war source directory + * or not + */ + private static Set getFilteredWebResourcesConfigurations(MavenProject project) { + Set retVal = new HashSet(); Path baseDirPath = Paths.get(project.getBasedir().getAbsolutePath()); for (Xpp3Dom resource : getWebResourcesConfigurations(project)) { @@ -119,18 +145,21 @@ public static List getFilteredWebSourceDirectories(MavenProject project) { } } - // Now add warSourceDir - if (isFilteringDeploymentDescriptors(project)) { - retVal.add(getWarSourceDirectory(project)); - } - return retVal; } - - public List getFilteredWebSourceDirectories() { - return getFilteredWebSourceDirectories(project); + + public boolean isSourceDirFiltered() { + + if (isFilteringDeploymentDescriptors()) { + return true; + } + + Path warSourceDir = getWarSourceDirectory(project); + + return getFilteredWebResourcesConfigurations(project).contains(warSourceDir); } - + + private static boolean isFilteringDeploymentDescriptors(MavenProject project) { Boolean retVal = false; Xpp3Dom dom = project.getGoalConfiguration("org.apache.maven.plugins", "maven-war-plugin", null, null); @@ -260,17 +289,76 @@ private void addWebResourcesConfigurationPaths(boolean onlyUnfiltered) throws DO } /* + * Add loose app XML elements for each directory within a maven-war-plugin configuration/webResources/resource/directory element + * * @return * @throws IOException * @throws DOMException */ - public void addAllWebResourcesConfigurationPaths() throws DOMException, IOException { - addWebResourcesConfigurationPaths(false); + Set handled = new HashSet(); + + Path baseDirPath = Paths.get(project.getBasedir().getAbsolutePath()); + + for (Xpp3Dom resource : getWebResourcesConfigurations(project)) { + Xpp3Dom dir = resource.getChild("directory"); + Xpp3Dom target = resource.getChild("targetPath"); + Path resolvedDir = baseDirPath.resolve(dir.getValue()); + if (handled.contains(resolvedDir)) { + log.warn("Ignoring webResources dir: " + dir.getValue() + ", already have entry for path: " + resolvedDir); + } else { + String targetPath = "/"; + if (target != null) { + targetPath = "/" + target.getValue(); + } + addOutputDir(getDocumentRoot(), resolvedDir.toFile(), targetPath); + handled.add(resolvedDir); + } + } } - public void addNonFilteredWebResourcesConfigurationPaths() throws DOMException, IOException { - addWebResourcesConfigurationPaths(true); + /* + * Add loose app XML elements for the WAR source directory, as long as it is not filtered, and for each non-filtered + * maven-war-plugin configuration/webResources/resource/directory element + * + * @return + * @throws IOException + * @throws DOMException + */ + public void addNonFilteredSourceAndWebResourcesPaths() throws DOMException, IOException { + + Path warSourceDir = getWarSourceDirectory(); + + Set handled = new HashSet(); + + // Write the source dir first, out of tradition/precedence + if (!isSourceDirFiltered()) { + addSourceDir(); + handled.add(warSourceDir); + } + + Path baseDirPath = Paths.get(project.getBasedir().getAbsolutePath()); + + for (Xpp3Dom resource : getWebResourcesConfigurations(project)) { + Xpp3Dom dir = resource.getChild("directory"); + Xpp3Dom target = resource.getChild("targetPath"); + Xpp3Dom filtering = resource.getChild("filtering"); + Path resolvedDir = baseDirPath.resolve(dir.getValue()); + if (filtering != null && Boolean.parseBoolean(filtering.getValue())) { + continue; + } else { + if (handled.contains(resolvedDir)) { + log.warn("Ignoring webResources dir: " + dir.getValue() + ", already have entry for path: " + resolvedDir); + } else { + String targetPath = "/"; + if (target != null) { + targetPath = "/" + target.getValue(); + } + addOutputDir(getDocumentRoot(), resolvedDir.toFile(), targetPath); + handled.add(resolvedDir); + } + } + } } public Path getWebAppDirectory() { From 846e516b67a4d7336abea73399fac061e67cbc42 Mon Sep 17 00:00:00 2001 From: Scott Kurz Date: Fri, 11 Aug 2023 15:55:13 -0400 Subject: [PATCH 05/13] Redeploy app on war-plugin config change Signed-off-by: Scott Kurz --- .../tools/maven/applications/DeployMojoSupport.java | 12 ++++-------- .../io/openliberty/tools/maven/server/DevMojo.java | 7 +++++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java index 7efb85bc5..e1df929ed 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java @@ -155,19 +155,16 @@ protected void installLooseConfigWar(MavenProject proj, LooseConfigData config, runExplodedMojo(); //////////////////////////////////// - // The order matters and establishes a well-defined precedence as documented: - //////////////////////////////////// https://www.ibm.com/docs/en/was-liberty/base?topic=liberty-loose-applications + // The order matters and establishes a well-defined precedence as documented: https://www.ibm.com/docs/en/was-liberty/base?topic=liberty-loose-applications // // ".. If you have two files with the same target location in the loose archive, the first occurrence of the file is used. // The first occurrence is based on a top-down approach to reading the elements of the loose application configuration file..." // // Because the flow is so complicated we may have cases where we are applying filtering where one location contains a filtered - //////////////////////////////////// version - // of a file and another potentially has an unfiltered one, and in such cases we need to make sure the filtered version takes - //////////////////////////////////// precedence. + // version of a file and another potentially has an unfiltered one, and in such cases we need to make sure the filtered version takes + // precedence. // // In certain cases, like step 1. below we avoid writing a location into the loose app XML because we don't want an unfiltered - //////////////////////////////////// version // to take precedence and prevent the filtered value from taking effect. // //////////////////////////////////// @@ -180,8 +177,7 @@ protected void installLooseConfigWar(MavenProject proj, LooseConfigData config, looseWar.addNonFilteredSourceAndWebResourcesPaths(); // 2. target classes - this allows non-deploy mode cases (e.g. non-deploy cases such as `mvn compile` or m2e update in Eclipse) - // to pick up Java class updates - // upon compilation. + // to pick up Java class updates upon compilation. looseWar.addOutputDir(looseWar.getDocumentRoot(), new File(proj.getBuild().getOutputDirectory()), "/WEB-INF/classes"); ////////////////////////// diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java index 88c70d024..618bf140f 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java @@ -872,10 +872,12 @@ public boolean recompileBuildFile(File buildFile, Set compileArtifactPat // set the updated project in current session; Plugin backupLibertyPlugin = getLibertyPlugin(); + Plugin backupWarPlugin = getPluginForProject("org.apache.maven.plugins", "maven-war-plugin", project); MavenProject backupProject = project; project = build.getProject(); session.setCurrentProject(project); Plugin libertyPlugin = getLibertyPlugin(); + Plugin warPlugin = getPluginForProject("org.apache.maven.plugins", "maven-war-plugin", project); try { // TODO rebuild the corresponding module if the compiler options have changed @@ -917,6 +919,11 @@ public boolean recompileBuildFile(File buildFile, Set compileArtifactPat if (!Objects.equals(config, oldConfig)) { redeployApp = true; } + config = ExecuteMojoUtil.getPluginGoalConfig(warPlugin, "exploded", getLog()); + oldConfig = ExecuteMojoUtil.getPluginGoalConfig(backupWarPlugin, "exploded", getLog()); + if (!Objects.equals(config, oldConfig)) { + redeployApp = true; + } config = ExecuteMojoUtil.getPluginGoalConfig(libertyPlugin, "generate-features", getLog()); oldConfig = ExecuteMojoUtil.getPluginGoalConfig(backupLibertyPlugin, "generate-features", getLog()); if (!Objects.equals(config, oldConfig)) { From d03d9e62cfd4e5296c192268094a3457b7e94459 Mon Sep 17 00:00:00 2001 From: Scott Kurz Date: Fri, 11 Aug 2023 17:35:36 -0400 Subject: [PATCH 06/13] Fix case where warSourceDirectory configured in webResources Signed-off-by: Scott Kurz --- .../applications/LooseWarApplication.java | 83 +++++-------------- .../tools/maven/server/DevMojo.java | 2 +- 2 files changed, 20 insertions(+), 65 deletions(-) diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/LooseWarApplication.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/LooseWarApplication.java index e66719330..910d1a4c4 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/LooseWarApplication.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/LooseWarApplication.java @@ -36,42 +36,34 @@ public class LooseWarApplication extends LooseApplication { protected final MavenProject project; + + protected final Path warSourceDirectory; protected final Log log; public LooseWarApplication(MavenProject project, LooseConfigData config, Log log) { super(project.getBuild().getDirectory(), config); this.project = project; + this.warSourceDirectory = getWarSourceDirectory(project); this.log = log; } public static boolean isExploded(MavenProject project) { - boolean isExplodedWar = false; - - // Check if filtering is enabled - List dynamicWebResources = getFilteredWebSourceDirectories(project); - - if (!dynamicWebResources.isEmpty() || isUsingOverlays(project)) { - isExplodedWar = true; - } - - // TODO: Check additional filtering options (properties?) - - return isExplodedWar; + if (isUsingOverlays(project)) { + return true; + } else if (!getWebSourceDirectoriesToMonitor(project).isEmpty()) { + return true; + } else { + return false; + } } - public boolean isExploded() { return isExploded(project); } public void addSourceDir() throws IOException { - Path warSourceDir = getWarSourceDirectory(); - config.addDir(warSourceDir.toFile(), "/"); - } - - public Path getWarSourceDirectory() { - return getWarSourceDirectory(project); + config.addDir(warSourceDirectory.toFile(), "/"); } private static Path getWarSourceDirectory(MavenProject project) { @@ -108,7 +100,7 @@ private Path getWebAppDirectory(MavenProject project) { * @return A list of directory Path(s) including each web source directory that has filtering applied, including the war source * directory (if so configured) or webResources entries */ - public static List getFilteredWebSourceDirectories(MavenProject project) { + public static List getWebSourceDirectoriesToMonitor(MavenProject project) { Set filteredWebResources = getFilteredWebResourcesConfigurations(project); @@ -117,7 +109,7 @@ public static List getFilteredWebSourceDirectories(MavenProject project) { Path warSourceDir = getWarSourceDirectory(project); // Need to add warSourceDir if DD filtering enabled, unless it's already in the list having its own webResources config - if (isFilteringDeploymentDescriptors(project) && !filteredWebResources.contains(warSourceDir)) { + if (!filteredWebResources.contains(warSourceDir) && isFilteringDeploymentDescriptors(project)) { retVal.add(warSourceDir); } @@ -148,16 +140,6 @@ private static Set getFilteredWebResourcesConfigurations(MavenProject proj return retVal; } - public boolean isSourceDirFiltered() { - - if (isFilteringDeploymentDescriptors()) { - return true; - } - - Path warSourceDir = getWarSourceDirectory(project); - - return getFilteredWebResourcesConfigurations(project).contains(warSourceDir); - } private static boolean isFilteringDeploymentDescriptors(MavenProject project) { @@ -261,33 +243,6 @@ public static List getWebResourcesConfigurations(MavenProject project) return retVal; } - private void addWebResourcesConfigurationPaths(boolean onlyUnfiltered) throws DOMException, IOException { - Set handled = new HashSet(); - - Path baseDirPath = Paths.get(project.getBasedir().getAbsolutePath()); - - for (Xpp3Dom resource : getWebResourcesConfigurations(project)) { - Xpp3Dom dir = resource.getChild("directory"); - Xpp3Dom target = resource.getChild("targetPath"); - Xpp3Dom filtering = resource.getChild("filtering"); - Path resolvedDir = baseDirPath.resolve(dir.getValue()); - if (handled.contains(resolvedDir)) { - log.warn("Ignoring webResources dir: " + dir.getValue() + ", already have entry for path: " + resolvedDir); - } else { - if (onlyUnfiltered && filtering != null && Boolean.parseBoolean(filtering.getValue())) { - continue; - } else { - String targetPath = "/"; - if (target != null) { - targetPath = "/" + target.getValue(); - } - addOutputDir(getDocumentRoot(), resolvedDir.toFile(), targetPath); - handled.add(resolvedDir); - } - } - } - } - /* * Add loose app XML elements for each directory within a maven-war-plugin configuration/webResources/resource/directory element * @@ -327,23 +282,23 @@ public void addAllWebResourcesConfigurationPaths() throws DOMException, IOExcept */ public void addNonFilteredSourceAndWebResourcesPaths() throws DOMException, IOException { - Path warSourceDir = getWarSourceDirectory(); - - Set handled = new HashSet(); - // Write the source dir first, out of tradition/precedence - if (!isSourceDirFiltered()) { + if (!isFilteringDeploymentDescriptors() && !getFilteredWebResourcesConfigurations(project).contains(warSourceDirectory)) { addSourceDir(); - handled.add(warSourceDir); } Path baseDirPath = Paths.get(project.getBasedir().getAbsolutePath()); + Set handled = new HashSet(); // Use to warn for duplicate entries for (Xpp3Dom resource : getWebResourcesConfigurations(project)) { Xpp3Dom dir = resource.getChild("directory"); Xpp3Dom target = resource.getChild("targetPath"); Xpp3Dom filtering = resource.getChild("filtering"); Path resolvedDir = baseDirPath.resolve(dir.getValue()); + if (resolvedDir.equals(warSourceDirectory)) { + // We have already decided to write the source dir or not above + continue; + } if (filtering != null && Boolean.parseBoolean(filtering.getValue())) { continue; } else { diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java index 618bf140f..eaa45bf21 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java @@ -1363,7 +1363,7 @@ private void doDevMode() throws MojoExecutionException { // resource directories List resourceDirs = getResourceDirectories(project, outputDirectory); - List webResourceDirs = LooseWarApplication.getFilteredWebSourceDirectories(project); + List webResourceDirs = LooseWarApplication.getWebSourceDirectoriesToMonitor(project); JavaCompilerOptions compilerOptions = getMavenCompilerOptions(project); From 40f475179140ea2e0ae2bf580c821c5c5a4fbe13 Mon Sep 17 00:00:00 2001 From: Scott Kurz Date: Mon, 14 Aug 2023 09:17:03 -0400 Subject: [PATCH 07/13] Add exploded parms to pass-thru config Signed-off-by: Scott Kurz --- .../tools/maven/utils/ExecuteMojoUtil.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/utils/ExecuteMojoUtil.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/utils/ExecuteMojoUtil.java index 6f633aecd..bb6560d2c 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/utils/ExecuteMojoUtil.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/utils/ExecuteMojoUtil.java @@ -139,9 +139,17 @@ public class ExecuteMojoUtil { private static final ArrayList FAILSAFE_REPORT_ONLY_PARAMS = REPORT_ONLY_PARAMS; // https://maven.apache.org/plugins/maven-war-plugin/exploded-mojo.html + // as of Version: 3.4.1-SNAPSHOT, 2023-06-11 private static final ArrayList EXPLODED_PARAMS = new ArrayList<>(Arrays.asList( - "filteringDeploymentDescriptors", "warSourceDirectory", "webappDirectory", "workDirectory", "filters", - "outdatedCheckPath", "overlays", "webResources" + // Required + "warSourceDirectory", "webappDirectory", "workDirectory", + // Optional - skip archive* options which may not make sense with our loose app approach + "containerConfigXML", "delimiters", "dependentWarExcludes", + "dependentWarIncludes", "escapedBackslashesInFilePath", "escapeString", "failOnMissingWebXml", + "filteringDeploymentDescriptors", "filters", "includeEmptyDirectories", "nonFilteredFileExtensions", + "outdatedCheckPath", "outputFileNameMapping", "outputTimestamp", "overlays", "propertiesEncoding", "recompressZippedFiles", + "resourceEncoding", "supportMultiLineFiltering", "useDefaultDelimiters", "useJvmChmod", "warSourceExcludes", "warSourceIncludes", + "webResources", "webXml" )); // https://maven.apache.org/plugins/maven-ear-plugin/ear-mojo.html From 890da07bd9353ac85bad36ce0d46f2944a5ef3c1 Mon Sep 17 00:00:00 2001 From: Scott Kurz Date: Mon, 14 Aug 2023 10:01:47 -0400 Subject: [PATCH 08/13] Detect different webRes dirs Signed-off-by: Scott Kurz --- .../tools/maven/server/DevMojo.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java index eaa45bf21..06ba70786 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java @@ -25,6 +25,7 @@ import java.io.File; import java.io.IOException; import java.nio.file.Path; +import java.nio.file.Paths; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; @@ -975,6 +976,25 @@ public boolean recompileBuildFile(File buildFile, Set compileArtifactPat } } + + // We don't currently have the ability to dynamically add new directories to be watched + // There is so much that we are dynamically able to do that this could be surprising. + // For now issue a warning + Set oldMonitoredWebResourceDirs = new HashSet(this.monitoredWebResourceDirs); + Set newMonitoredWebResourceDirs = new HashSet(LooseWarApplication.getWebSourceDirectoriesToMonitor(project)); + if (!oldMonitoredWebResourceDirs.equals(newMonitoredWebResourceDirs)) { + getLog().warn("Change detected in the set of filtered web resource directories, since dev mode was first launched. Adding/deleting a web resource directory has no change on the set of directories monitored by dev mode. Changing the watch list will require a dev mode restart"); + } + + // convert to Path, which seems to offer more reliable cross-platform, relative path comparison, then compare + Set oldResourceDirs = new HashSet(); + this.resourceDirs.forEach(r -> oldResourceDirs.add(r.toPath())); + Set newResourceDirs = new HashSet(); + project.getResources().forEach(r -> newResourceDirs.add(Paths.get(r.getDirectory()))); + if (!oldResourceDirs.equals(newResourceDirs)) { + getLog().warn("Change detected in the set of resource directories, since dev mode was first launched. Adding/deleting a resource directory has no change on the set of directories monitored by dev mode. Changing the watch list will require a dev mode restart"); + } + if (restartServer) { // - stop Server // - create server or runBoostMojo From 92a3efa51792058d38b08518a055d66722084085 Mon Sep 17 00:00:00 2001 From: Scott Kurz Date: Mon, 14 Aug 2023 15:42:18 -0400 Subject: [PATCH 09/13] Redeploy on MWAR change Signed-off-by: Scott Kurz --- .../main/java/io/openliberty/tools/maven/server/DevMojo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java index 06ba70786..376bdb0ab 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java @@ -922,7 +922,7 @@ public boolean recompileBuildFile(File buildFile, Set compileArtifactPat } config = ExecuteMojoUtil.getPluginGoalConfig(warPlugin, "exploded", getLog()); oldConfig = ExecuteMojoUtil.getPluginGoalConfig(backupWarPlugin, "exploded", getLog()); - if (!Objects.equals(config, oldConfig)) { + if (!Objects.equals(config, oldConfig) || warPlugin.getVersion() != backupWarPlugin.getVersion()) { redeployApp = true; } config = ExecuteMojoUtil.getPluginGoalConfig(libertyPlugin, "generate-features", getLog()); From 53b9e4bdfd81bdf9019d278f9f5fdc241eaa6d4b Mon Sep 17 00:00:00 2001 From: Scott Kurz Date: Thu, 17 Aug 2023 22:57:57 -0400 Subject: [PATCH 10/13] fix-new-mwar Signed-off-by: Scott Kurz --- .../main/java/io/openliberty/tools/maven/server/DevMojo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java index 376bdb0ab..5ae542a1a 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java @@ -922,7 +922,7 @@ public boolean recompileBuildFile(File buildFile, Set compileArtifactPat } config = ExecuteMojoUtil.getPluginGoalConfig(warPlugin, "exploded", getLog()); oldConfig = ExecuteMojoUtil.getPluginGoalConfig(backupWarPlugin, "exploded", getLog()); - if (!Objects.equals(config, oldConfig) || warPlugin.getVersion() != backupWarPlugin.getVersion()) { + if (!Objects.equals(config, oldConfig) || !warPlugin.getVersion().equals(backupWarPlugin.getVersion())) { redeployApp = true; } config = ExecuteMojoUtil.getPluginGoalConfig(libertyPlugin, "generate-features", getLog()); From a3edaefae1e0c61f46a16c86c905496cdc04a93e Mon Sep 17 00:00:00 2001 From: Scott Kurz Date: Thu, 17 Aug 2023 22:58:09 -0400 Subject: [PATCH 11/13] New IT Signed-off-by: Scott Kurz --- .../META-INF/MANIFEST.MF | 3 + .../invoker.properties | 4 + .../deploy-loose-config-exploded-it/pom.xml | 318 ++++++++++++++++++ .../src/main/java/mypkg/HelloServlet.java | 44 +++ .../src/main/liberty/config/server.xml | 22 ++ .../src/main/resource1/keepalive.txt | 1 + .../src/main/resource2/keepalive.txt | 1 + .../src/main/webapp/WEB-INF/web.xml | 10 + .../src/main/webapp/index.html | Bin 0 -> 199289 bytes .../java/mypkg/ExplodedFilteredDDTest.java | 77 +++++ .../src/test/java/mypkg/ExplodedTest.java | 81 +++++ .../src/test/java/mypkg/NonExplodedTest.java | 93 +++++ .../java/mypkg/utils/LooseConfigUtils.java | 62 ++++ 13 files changed, 716 insertions(+) create mode 100644 liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/META-INF/MANIFEST.MF create mode 100644 liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/invoker.properties create mode 100644 liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/pom.xml create mode 100644 liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/main/java/mypkg/HelloServlet.java create mode 100644 liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/main/liberty/config/server.xml create mode 100644 liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/main/resource1/keepalive.txt create mode 100644 liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/main/resource2/keepalive.txt create mode 100644 liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/main/webapp/WEB-INF/web.xml create mode 100644 liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/main/webapp/index.html create mode 100644 liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/test/java/mypkg/ExplodedFilteredDDTest.java create mode 100644 liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/test/java/mypkg/ExplodedTest.java create mode 100644 liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/test/java/mypkg/NonExplodedTest.java create mode 100644 liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/test/java/mypkg/utils/LooseConfigUtils.java diff --git a/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/META-INF/MANIFEST.MF b/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/META-INF/MANIFEST.MF new file mode 100644 index 000000000..8836a83e2 --- /dev/null +++ b/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Created-By: 17.0.3 (IBM Corporation) + diff --git a/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/invoker.properties b/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/invoker.properties new file mode 100644 index 000000000..baf93bcbf --- /dev/null +++ b/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/invoker.properties @@ -0,0 +1,4 @@ +invoker.goals.1 = -Poverlay clean compile liberty:create liberty:install-feature liberty:deploy verify +invoker.goals.2 = -Pnon-exploded clean compile liberty:create liberty:install-feature liberty:deploy verify +invoker.goals.3 = -Pfiltered-web-resource clean compile liberty:create liberty:install-feature liberty:deploy verify +invoker.goals.4 = -Pfiltered-dd clean compile liberty:create liberty:install-feature liberty:deploy verify diff --git a/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/pom.xml b/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/pom.xml new file mode 100644 index 000000000..772f967b0 --- /dev/null +++ b/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/pom.xml @@ -0,0 +1,318 @@ + + + 4.0.0 + + + io.openliberty.tools.it + tests + 1.0-SNAPSHOT + + + deploy-loose-config-exploded-it + war + + + UTF-8 + UTF-8 + 1.7 + 1.7 + + + + + + io.openliberty.features + features-bom + RUNTIME_VERSION + pom + import + + + + + + + + io.openliberty.features + jaxrs-2.1 + esa + provided + + + io.openliberty.features + jsonp-1.1 + esa + provided + + + io.openliberty.features + cdi-2.0 + esa + provided + + + io.openliberty.features + mpConfig-1.3 + esa + provided + + + io.openliberty.features + mpRestClient-1.2 + esa + provided + + + + junit + junit + 4.13.1 + test + + + org.apache.cxf + cxf-rt-rs-client + 3.2.6 + test + + + org.apache.cxf + cxf-rt-rs-extension-providers + 3.2.6 + test + + + org.glassfish + javax.json + 1.0.4 + test + + + + org.apache.commons + commons-lang3 + 3.0 + + + + javax.xml.bind + jaxb-api + 2.3.1 + + + com.sun.xml.bind + jaxb-core + 2.3.0.1 + + + com.sun.xml.bind + jaxb-impl + 2.3.2 + + + javax.activation + activation + 1.1.1 + + + + org.slf4j + slf4j-api + 1.7.25 + + + ch.qos.logback + logback-classic + 1.2.3 + runtime + + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.1.2 + + + **/*.java + + + + + org.apache.maven.plugins + maven-war-plugin + 3.4.0 + + false + pom.xml + + + + ${project.basedir}/src/main/resource1 + false + + + false + + + + + + io.openliberty.tools + liberty-maven-plugin + SUB_VERSION + + + io.openliberty + openliberty-kernel + RUNTIME_VERSION + zip + + true + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.1.2 + + + integration-test + integration-test + + integration-test + + + + verify-results + + verify + + + + + + ${project.build.directory}/test-reports/it/failsafe-summary.xml + ${project.build.directory}/test-reports/it + + + + + + + non-exploded + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + **/NonExplodedTest.java + + + **/ExplodedTest.java + + + + + + + + + overlay + + + + org.apache.maven.plugins + maven-war-plugin + + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + **/ExplodedTest.java + + + **/ExplodedFilteredDDTest.java + **/NonExplodedTest.java + + + + + + + + filtered-web-resource + + + + org.apache.maven.plugins + maven-war-plugin + + + + ${project.basedir}/src/main/resource2 + true + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + **/ExplodedTest.java + + + **/ExplodedFilteredDDTest.java + **/NonExplodedTest.java + + + + + + + + filtered-dd + + + + org.apache.maven.plugins + maven-war-plugin + +true + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + **/ExplodedFilteredDDTest.java + + + **/ExplodedTest.java + **/NonExplodedTest.java + + + + + + + + diff --git a/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/main/java/mypkg/HelloServlet.java b/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/main/java/mypkg/HelloServlet.java new file mode 100644 index 000000000..7bb82878b --- /dev/null +++ b/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/main/java/mypkg/HelloServlet.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * (c) Copyright IBM Corporation 2019. + * + * Licensed 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 mypkg; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(urlPatterns="/servlet") +public class HelloServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + String msg = "greeting"; + response.getWriter().append(msg); + } + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + doGet(request, response); + } +} diff --git a/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/main/liberty/config/server.xml b/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/main/liberty/config/server.xml new file mode 100644 index 000000000..6050da10a --- /dev/null +++ b/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/main/liberty/config/server.xml @@ -0,0 +1,22 @@ + + + + jsp-2.3 + + + + diff --git a/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/main/resource1/keepalive.txt b/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/main/resource1/keepalive.txt new file mode 100644 index 000000000..f7d55cf9a --- /dev/null +++ b/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/main/resource1/keepalive.txt @@ -0,0 +1 @@ +r1 diff --git a/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/main/resource2/keepalive.txt b/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/main/resource2/keepalive.txt new file mode 100644 index 000000000..9a6c8d12d --- /dev/null +++ b/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/main/resource2/keepalive.txt @@ -0,0 +1 @@ +r2 diff --git a/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/main/webapp/WEB-INF/web.xml b/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..baddd26c0 --- /dev/null +++ b/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,10 @@ + + + Hello Servlet + + + index.html + + diff --git a/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/main/webapp/index.html b/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/main/webapp/index.html new file mode 100644 index 0000000000000000000000000000000000000000..06dbf46357573bd7f20e7c9159f55879b2721f69 GIT binary patch literal 199289 zcmeIuF;2r!3h{XKJ!otqLT#B1iypSq9RpR!fDhpRYpBE3de_3Cd+FXaO zye;qFTbmw+*Q|$S&S*-|<(j46 z57*-{TkK<8Gu!ENjN`h@(Wd+xdf%1)yro`q``;h>+e>$f009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N Z0t5&UAV7cs0RjXF5FkK+0D=E1@B", 4, nodes.getLength()); + + expression = "/archive/dir"; + nodes = (NodeList) xPath.compile(expression).evaluate(inputDoc, XPathConstants.NODESET); + Assert.assertEquals("Number of element ==>", 3, nodes.getLength()); + + // 1. validate: + // + validateSrcResourceRoot(nodes.item(0), "src" + File.separator + "main" + File.separator + "resource1"); + + // 2. validate: + // + validateTargetClasses(nodes.item(1)); + + // 3. validate: + // + validateWebAppDirRoot(nodes.item(2), "deploy-loose-config-exploded-it-1.0-SNAPSHOT"); + } +} diff --git a/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/test/java/mypkg/ExplodedTest.java b/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/test/java/mypkg/ExplodedTest.java new file mode 100644 index 000000000..5fa493ad1 --- /dev/null +++ b/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/test/java/mypkg/ExplodedTest.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * (c) Copyright IBM Corporation 2023. + * + * Licensed 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 mypkg; + +import static mypkg.utils.LooseConfigUtils.*; + +import java.io.File; +import java.io.FileInputStream; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathFactory; + +import org.junit.Assert; +import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; + +/** + * Web application test case + */ +public class ExplodedTest { + + @Test + public void testExplodedLooseAppFormat() throws Exception { + File in = new File("target/liberty/wlp/usr/servers/defaultServer/dropins/deploy-loose-config-exploded-it.war.xml"); + FileInputStream input = new FileInputStream(in); + + // get input XML Document + DocumentBuilderFactory inputBuilderFactory = DocumentBuilderFactory.newInstance(); + inputBuilderFactory.setIgnoringComments(true); + inputBuilderFactory.setCoalescing(true); + inputBuilderFactory.setIgnoringElementContentWhitespace(true); + inputBuilderFactory.setValidating(false); + DocumentBuilder inputBuilder = inputBuilderFactory.newDocumentBuilder(); + Document inputDoc=inputBuilder.parse(input); + + // parse input XML Document + XPath xPath = XPathFactory.newInstance().newXPath(); + + String expression = "/archive//*"; + NodeList nodes = (NodeList) xPath.compile(expression).evaluate(inputDoc, XPathConstants.NODESET); + Assert.assertEquals("Number of archive elements ==>", 5, nodes.getLength()); + + expression = "/archive/dir"; + nodes = (NodeList) xPath.compile(expression).evaluate(inputDoc, XPathConstants.NODESET); + Assert.assertEquals("Number of element ==>", 4, nodes.getLength()); + + // 1. validate: + // + validateSrcMainWebAppRoot(nodes.item(0)); + + // 2. validate: + // + validateSrcResourceRoot(nodes.item(1), "src" + File.separator + "main" + File.separator + "resource1"); + + // 3. validate: + // + validateTargetClasses(nodes.item(2)); + + // 4. validate: + // + validateWebAppDirRoot(nodes.item(3), "deploy-loose-config-exploded-it-1.0-SNAPSHOT"); + } + +} diff --git a/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/test/java/mypkg/NonExplodedTest.java b/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/test/java/mypkg/NonExplodedTest.java new file mode 100644 index 000000000..867a9671e --- /dev/null +++ b/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/test/java/mypkg/NonExplodedTest.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * (c) Copyright IBM Corporation 2023. + * + * Licensed 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 mypkg; + +import static mypkg.utils.LooseConfigUtils.validateSrcMainWebAppRoot; +import static mypkg.utils.LooseConfigUtils.validateTargetClasses; + +import java.io.File; +import java.io.FileInputStream; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathFactory; + +import org.junit.Assert; +import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * Web application test case + */ +public class NonExplodedTest { + + @Test + public void testNonExplodedLooseAppFormat() throws Exception { + File in = new File("target/liberty/wlp/usr/servers/defaultServer/dropins/deploy-loose-config-exploded-it.war.xml"); + FileInputStream input = new FileInputStream(in); + + // get input XML Document + DocumentBuilderFactory inputBuilderFactory = DocumentBuilderFactory.newInstance(); + inputBuilderFactory.setIgnoringComments(true); + inputBuilderFactory.setCoalescing(true); + inputBuilderFactory.setIgnoringElementContentWhitespace(true); + inputBuilderFactory.setValidating(false); + DocumentBuilder inputBuilder = inputBuilderFactory.newDocumentBuilder(); + Document inputDoc=inputBuilder.parse(input); + + // parse input XML Document + XPath xPath = XPathFactory.newInstance().newXPath(); + + String expression = "/archive//*"; + NodeList nodes = (NodeList) xPath.compile(expression).evaluate(inputDoc, XPathConstants.NODESET); + Assert.assertEquals("Number of archive elements ==>", 13, nodes.getLength()); + + expression = "/archive/dir"; + nodes = (NodeList) xPath.compile(expression).evaluate(inputDoc, XPathConstants.NODESET); + Assert.assertEquals("Number of element ==>", 3, nodes.getLength()); + + // validate: + // + validateSrcMainWebAppRoot(nodes.item(0)); + + // validate: + // + validateTargetClasses(nodes.item(1)); + + expression = "/archive/file"; + nodes = (NodeList) xPath.compile(expression).evaluate(inputDoc, XPathConstants.NODESET); + + // validate: + // + String commonsLangBaseName = "commons-lang3-3.0.jar"; + boolean foundCommonsLangJar = false; + for (int i = 0; i < nodes.getLength() && !foundCommonsLangJar; i++) { + Node node = nodes.item(i); + String srcVal = node.getAttributes().getNamedItem("sourceOnDisk").getNodeValue(); + String targetVal = node.getAttributes().getNamedItem("targetInArchive").getNodeValue(); + if (srcVal.endsWith(commonsLangBaseName) && targetVal.endsWith(commonsLangBaseName)) { + foundCommonsLangJar = true; + } + } + Assert.assertTrue("Didn't find commons lang JAR in loose app XML ending with: " + commonsLangBaseName, foundCommonsLangJar); + } + +} diff --git a/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/test/java/mypkg/utils/LooseConfigUtils.java b/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/test/java/mypkg/utils/LooseConfigUtils.java new file mode 100644 index 000000000..8efc190cd --- /dev/null +++ b/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/src/test/java/mypkg/utils/LooseConfigUtils.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * (c) Copyright IBM Corporation 2023. + * + * Licensed 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 mypkg.utils; + +import java.io.File; + +import org.junit.Assert; +import org.w3c.dom.Node; + +public class LooseConfigUtils { + + public static void validateSrcMainWebAppRoot(Node archiveElem) { + // validate: + // + String s1 = archiveElem.getAttributes().getNamedItem("sourceOnDisk").getNodeValue(); + Assert.assertTrue("Bad node: " + s1, s1.endsWith("src" + File.separator + "main" + File.separator + "webapp")); + String t1 = archiveElem.getAttributes().getNamedItem("targetInArchive").getNodeValue(); + Assert.assertEquals("Bad node: " + t1, "/", t1); + } + + public static void validateSrcResourceRoot(Node archiveElem, String resourcePath) { + + // validate: + // + String s1 = archiveElem.getAttributes().getNamedItem("sourceOnDisk").getNodeValue(); + Assert.assertTrue("Bad node: " + s1, s1.endsWith(resourcePath)); + String t1 = archiveElem.getAttributes().getNamedItem("targetInArchive").getNodeValue(); + Assert.assertEquals("Bad node: " + t1, "/", t1); + } + + public static void validateWebAppDirRoot(Node archiveElem, String webAppName) { + + // validate: + // + String s1 = archiveElem.getAttributes().getNamedItem("sourceOnDisk").getNodeValue(); + Assert.assertTrue("Bad node: " + s1, s1.endsWith(webAppName)); + String t1 = archiveElem.getAttributes().getNamedItem("targetInArchive").getNodeValue(); + Assert.assertEquals("Bad node: " + t1, "/", t1); + } + + // validate: + // + public static void validateTargetClasses(Node archiveElem) { + String s1 = archiveElem.getAttributes().getNamedItem("sourceOnDisk").getNodeValue(); + Assert.assertTrue("Bad node: " + s1, s1.endsWith("target" + File.separator + "classes")); + String t1 = archiveElem.getAttributes().getNamedItem("targetInArchive").getNodeValue(); + Assert.assertEquals("Bad node: " + t1, "/WEB-INF/classes", t1); + } +} From 9fd2618c58cf48c0b44e658d1fe72fc23b827238 Mon Sep 17 00:00:00 2001 From: Scott Kurz Date: Thu, 17 Aug 2023 22:58:34 -0400 Subject: [PATCH 12/13] Remove old IT Signed-off-by: Scott Kurz --- .../resources/exploded-war-project/pom.xml | 251 ------------------ .../src/main/java/com/demo/HelloLogger.java | 37 --- .../src/main/java/com/demo/HelloServlet.java | 39 --- .../src/main/java/com/demo/HelloWorld.java | 23 -- .../src/main/liberty/config/server.xml | 9 - .../src/main/resources/placeHolder.txt | 0 .../test/dev/it/ExplodedLooseWarAppTest.java | 154 ----------- 7 files changed, 513 deletions(-) delete mode 100755 liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/pom.xml delete mode 100755 liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/src/main/java/com/demo/HelloLogger.java delete mode 100644 liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/src/main/java/com/demo/HelloServlet.java delete mode 100755 liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/src/main/java/com/demo/HelloWorld.java delete mode 100755 liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/src/main/liberty/config/server.xml delete mode 100644 liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/src/main/resources/placeHolder.txt delete mode 100644 liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/ExplodedLooseWarAppTest.java diff --git a/liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/pom.xml b/liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/pom.xml deleted file mode 100755 index 4654d6c19..000000000 --- a/liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/pom.xml +++ /dev/null @@ -1,251 +0,0 @@ - - - - 4.0.0 - - dev-it-tests - exploded-war-proj - 1.0-SNAPSHOT - war - - - UTF-8 - UTF-8 - 1.7 - 1.7 - LibertyProject - - 9080 - 9443 - - usr - - - - - - io.openliberty.features - features-bom - RUNTIME_VERSION - pom - import - - - - - - - - io.openliberty.features - jaxrs-2.1 - esa - provided - - - io.openliberty.features - jsonp-1.1 - esa - provided - - - io.openliberty.features - cdi-2.0 - esa - provided - - - io.openliberty.features - mpConfig-1.3 - esa - provided - - - io.openliberty.features - mpRestClient-1.2 - esa - provided - - - - junit - junit - 4.13.1 - test - - - org.apache.cxf - cxf-rt-rs-client - 3.2.6 - test - - - org.apache.cxf - cxf-rt-rs-extension-providers - 3.2.6 - test - - - org.glassfish - javax.json - 1.0.4 - test - - - - org.apache.commons - commons-lang3 - 3.0 - - - - javax.xml.bind - jaxb-api - 2.3.1 - - - com.sun.xml.bind - jaxb-core - 2.3.0.1 - - - com.sun.xml.bind - jaxb-impl - 2.3.2 - - - javax.activation - activation - 1.1.1 - - - - org.slf4j - slf4j-api - 1.7.25 - - - ch.qos.logback - logback-classic - 1.2.3 - runtime - - - - - - - - - - org.apache.maven.plugins - maven-war-plugin - 3.4.0 - - false - pom.xml - - - - - false - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.1.2 - - - test - default-test - - - **/it/** - - ${project.build.directory}/test-reports/unit - - - - - - - io.openliberty.tools - liberty-maven-plugin - SUB_VERSION - - - io.openliberty - openliberty-kernel - RUNTIME_VERSION - zip - - ${app.name} - ${packaging.type} - - ${testServerHttpPort} - ${testServerHttpsPort} - json - - - - - - - org.apache.maven.plugins - maven-failsafe-plugin - 3.1.2 - - - integration-test - integration-test - - integration-test - - - - **/it/**/*.java - - - - ${testServerHttpPort} - - - - - - verify-results - - verify - - - - - ${project.build.directory}/test-reports/it/failsafe-summary.xml - ${project.build.directory}/test-reports/it - - - - - diff --git a/liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/src/main/java/com/demo/HelloLogger.java b/liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/src/main/java/com/demo/HelloLogger.java deleted file mode 100755 index d717d81a5..000000000 --- a/liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/src/main/java/com/demo/HelloLogger.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * (c) Copyright IBM Corporation 2021. - * - * Licensed 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 com.demo; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; - -import static javax.ws.rs.core.MediaType.TEXT_PLAIN; - -@Path("/show-log") -public class HelloLogger { - private static final Logger log = LoggerFactory.getLogger(HelloLogger.class); - - @GET - @Produces(TEXT_PLAIN) - public String showLog() { - log.info("Here is the Log"); - return "Log has been shown"; - } -} diff --git a/liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/src/main/java/com/demo/HelloServlet.java b/liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/src/main/java/com/demo/HelloServlet.java deleted file mode 100644 index 01cc44f09..000000000 --- a/liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/src/main/java/com/demo/HelloServlet.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * (c) Copyright IBM Corporation 2021. - * - * Licensed 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 com.demo; - -import java.io.IOException; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.servlet.ServletException; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -@WebServlet(urlPatterns="/servlet") -public class HelloServlet extends HttpServlet { - private static final long serialVersionUID = 1L; - - private static final Logger log = LoggerFactory.getLogger(HelloLogger.class); - - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - log.info("SLF4J Logger is ready for messages."); - response.getWriter().append("hello world"); - } -} \ No newline at end of file diff --git a/liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/src/main/java/com/demo/HelloWorld.java b/liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/src/main/java/com/demo/HelloWorld.java deleted file mode 100755 index 937240b5c..000000000 --- a/liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/src/main/java/com/demo/HelloWorld.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * (c) Copyright IBM Corporation 2021. - * - * Licensed 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 com.demo; - -public class HelloWorld { - - public String helloWorld() { - return "helloWorld"; - } -} diff --git a/liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/src/main/liberty/config/server.xml b/liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/src/main/liberty/config/server.xml deleted file mode 100755 index fdad620d8..000000000 --- a/liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/src/main/liberty/config/server.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - jaxrs-2.1 - - - - diff --git a/liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/src/main/resources/placeHolder.txt b/liberty-maven-plugin/src/it/dev-it/resources/exploded-war-project/src/main/resources/placeHolder.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/ExplodedLooseWarAppTest.java b/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/ExplodedLooseWarAppTest.java deleted file mode 100644 index dbe139af8..000000000 --- a/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/ExplodedLooseWarAppTest.java +++ /dev/null @@ -1,154 +0,0 @@ -/******************************************************************************* - * (c) Copyright IBM Corporation 2021. - * - * Licensed 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 net.wasdev.wlp.test.dev.it; - -import static org.junit.Assert.*; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.nio.file.Files; -import java.util.Scanner; - -import org.apache.commons.io.FileUtils; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -public class ExplodedLooseWarAppTest extends BaseDevTest { - private final String projectArtifact = "exploded-war-proj-1.0-SNAPSHOT"; - private final String appsDir = "target/liberty/wlp/usr/servers/defaultServer/dropins/"; - - @BeforeClass - public static void setUpBeforeClass() throws Exception { - setUpBeforeClass(null, "../resources/exploded-war-project"); - } - - @AfterClass - public static void cleanUpAfterClass() throws Exception { - BaseDevTest.cleanUpAfterClass(); - } - - @Ignore // TODO enable this test - @Test - public void configureWebXmlFiltering() throws Exception { - int appDeployedCount = countOccurrences("Running liberty:deploy", logFile); - // Add deployment descriptor filtering config to pom war plugin - replaceString("false", - "true", pom); - - // Verify exploded goal running and redeploy - assertTrue(getLogTail(), verifyLogMessageExists("Running liberty:deploy", 4000, logFile, ++appDeployedCount)); - assertTrue(getLogTail(), verifyLogMessageExists("Running maven-war-plugin:exploded", 2000)); - - // Verify loose app xml is correct - verifyExplodedLooseApp(); - - // Remove filtering config - replaceString("true", - "false", pom); - - // Verify redeploy - assertTrue(getLogTail(), verifyLogMessageExists("Running liberty:deploy", 2000)); - - // Verify loose app xml is back to how it was - verifyNonExplodedLooseApp(); - } - - @Ignore // TODO enable this test - @Test - public void configureFilteredResource() throws Exception { - // Add filtering config to pom war plugin (directory) - replaceString("", pom); - - replaceString("Filtered directory end -->", - "", pom); - - // Verify exploded goal running and redeploy - assertTrue(getLogTail(), verifyLogMessageExists("Running liberty:deploy", 2000)); - assertTrue(getLogTail(), verifyLogMessageExists("Running maven-war-plugin:exploded", 2000)); - - // Verify loose app xml is correct - verifyExplodedLooseApp(); - - // Remove filtering config - replaceString("", - "", - "Filtered directory end -->", pom); - - // Verify redeploy - assertTrue(getLogTail(), verifyLogMessageExists("Running liberty:deploy", 2000)); - - // Verify loose app xml is back to how it was - verifyNonExplodedLooseApp(); - } - - @Ignore // TODO enable this test - @Test - public void configureWarOverlay() throws Exception { - // Add filtering config to pom war plugin (directory) - replaceString("", pom); - - replaceString("Overlay configuration end -->", - "", pom); - - // Verify exploded goal running and redeploy - assertTrue(getLogTail(), verifyLogMessageExists("Running liberty:deploy", 2000)); - assertTrue(getLogTail(), verifyLogMessageExists("Running maven-war-plugin:exploded", 2000)); - - // Verify loose app xml is correct - verifyExplodedLooseApp(); - - // Remove filtering config - replaceString("", - "", - "Overlay configuration end -->", pom); - - // Verify redeploy - assertTrue(getLogTail(), verifyLogMessageExists("Running liberty:deploy", 2000)); - - // Verify loose app xml is back to how it was - verifyNonExplodedLooseApp(); - } - - private void verifyExplodedLooseApp() throws Exception { - String looseAppXml = tempProj.getAbsolutePath() + "/" + appsDir + projectArtifact + ".war.xml"; - - // Verify the target/ entry - String explodedWar = basicDevProj.getAbsolutePath() + "/target/" + projectArtifact; - assertTrue(getLogTail(), verifyFileExists(new File(looseAppXml), 3000)); - assertTrue(getLogTail(), verifyLogMessageExists("", 3000, new File(looseAppXml))); - } - - private void verifyNonExplodedLooseApp() throws Exception { - String looseAppXml = tempProj.getAbsolutePath() + "/" + appsDir + projectArtifact + ".war.xml"; - - // Verify the src/main/webapp entry - String srcMain = basicDevProj.getAbsolutePath() + "/src/main/webapp"; - assertTrue(getLogTail(), verifyLogMessageExists("", 3000, new File(looseAppXml))); - - // Verify the target/classes entry - String targetClasses = basicDevProj.getAbsolutePath() + "/target/classes"; - assertTrue(getLogTail(), verifyLogMessageExists("", 3000, new File(looseAppXml))); - } -} From 604e420d6489d5e8c9e837c6c8e80ebb3179a91f Mon Sep 17 00:00:00 2001 From: Scott Kurz Date: Fri, 18 Aug 2023 08:25:17 -0400 Subject: [PATCH 13/13] Fix new IT version parameterization Signed-off-by: Scott Kurz --- .../deploy-loose-config-exploded-it/pom.xml | 58 +++---------------- 1 file changed, 7 insertions(+), 51 deletions(-) diff --git a/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/pom.xml b/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/pom.xml index 772f967b0..8db7438b8 100644 --- a/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/pom.xml +++ b/liberty-maven-plugin/src/it/deploy-loose-config-exploded-it/pom.xml @@ -19,51 +19,13 @@ 1.7 1.7 - - - - - io.openliberty.features - features-bom - RUNTIME_VERSION - pom - import - - - - - - - io.openliberty.features - jaxrs-2.1 - esa - provided - - - io.openliberty.features - jsonp-1.1 - esa - provided - - - io.openliberty.features - cdi-2.0 - esa - provided - - - io.openliberty.features - mpConfig-1.3 - esa - provided - - - io.openliberty.features - mpRestClient-1.2 - esa - provided - + + javax.servlet + javax.servlet-api + 3.1.0 + provided + junit @@ -166,14 +128,8 @@ io.openliberty.tools liberty-maven-plugin - SUB_VERSION + @pom.version@ - - io.openliberty - openliberty-kernel - RUNTIME_VERSION - zip - true