From ee79ac2407f33386481fff929f0f2e23aa40344f Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Thu, 30 Mar 2023 13:50:17 -0500 Subject: [PATCH 01/12] Resolve variables in app location and fix app configuration validation logic --- .../src/it/alt-outputdir-it/pom.xml | 28 +++ .../invoker.properties | 2 + .../pom.xml | 231 ++++++++++++++++++ .../src/main/WEB-INF/web.xml | 19 ++ .../src/main/filtered-config/environment.xml | 4 + .../src/main/filters/test.properties | 1 + .../wasdev/wlp/test/servlet/TestServlet.java | 24 ++ .../src/main/liberty/config/server.xml | 10 + .../src/main/webapp/index.jsp | 11 + .../maven/test/app/PluginConfigXmlTest.java | 86 +++++++ .../openliberty/tools/maven/BasicSupport.java | 27 +- .../tools/maven/ServerFeatureSupport.java | 12 +- .../tools/maven/applications/DeployMojo.java | 4 +- .../maven/applications/DeployMojoSupport.java | 43 ++-- .../maven/applications/UndeployAppMojo.java | 10 +- .../maven/server/PluginConfigSupport.java | 16 +- 16 files changed, 495 insertions(+), 33 deletions(-) create mode 100644 liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/invoker.properties create mode 100644 liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/pom.xml create mode 100644 liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/main/WEB-INF/web.xml create mode 100644 liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/main/filtered-config/environment.xml create mode 100644 liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/main/filters/test.properties create mode 100644 liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/main/java/net/wasdev/wlp/test/servlet/TestServlet.java create mode 100644 liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/main/liberty/config/server.xml create mode 100644 liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/main/webapp/index.jsp create mode 100644 liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/test/java/net/wasdev/wlp/maven/test/app/PluginConfigXmlTest.java diff --git a/liberty-maven-plugin/src/it/alt-outputdir-it/pom.xml b/liberty-maven-plugin/src/it/alt-outputdir-it/pom.xml index b68115214..254ecdcea 100644 --- a/liberty-maven-plugin/src/it/alt-outputdir-it/pom.xml +++ b/liberty-maven-plugin/src/it/alt-outputdir-it/pom.xml @@ -46,6 +46,9 @@ + + ${project.basedir}/src/main/filters/test.properties + org.apache.maven.plugins @@ -56,6 +59,31 @@ pom.xml + + org.apache.maven.plugins + maven-resources-plugin + 3.2.0 + + + default-cli + none + + copy-resources + + + true + + target/liberty/wlp/usr/shared/config + + + src/main/filtered-config + true + + + + + + io.openliberty.tools liberty-maven-plugin diff --git a/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/invoker.properties b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/invoker.properties new file mode 100644 index 000000000..51198c7cb --- /dev/null +++ b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/invoker.properties @@ -0,0 +1,2 @@ +# prove the variables in server.xml can be resolved correctly +invoker.goals.1 = clean liberty:create resources:copy-resources install \ No newline at end of file diff --git a/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/pom.xml b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/pom.xml new file mode 100644 index 000000000..eacfbfc0b --- /dev/null +++ b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/pom.xml @@ -0,0 +1,231 @@ + + + 4.0.0 + + + io.openliberty.tools.it + tests + 1.0-SNAPSHOT + + + appsdirectory-apps-configured-variables-include-it + war + + + + org.apache.geronimo.specs + geronimo-servlet_3.0_spec + 1.0 + provided + + + commons-logging + commons-logging + 1.0.4 + test + + + junit + junit + 4.13.1 + test + + + + + ${project.artifactId} + + ${project.basedir}/src/main/filters/test.properties + + + + + + org.apache.maven.plugins + maven-war-plugin + 3.3.2 + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.5 + + + org.apache.maven.plugins + maven-surefire-plugin + 2.5 + + + org.apache.felix + maven-bundle-plugin + 2.3.7 + + + + + + maven-war-plugin + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + + org.apache.felix + maven-bundle-plugin + + + bundle-manifest + process-classes + + manifest + + + + + + war + + + /test-wab + WEB-INF/classes + + javax.servlet.jsp.el, + javax.servlet.jsp, + javax.servlet.jsp.tagext, + * + + + + + + io.openliberty.tools + liberty-maven-plugin + @pom.version@ + true + + true + + ${project.groupId} + assembly-server + ${project.version} + zip + + test + false + + + + + install-artifact + package + + deploy + + + false + apps + true + + + + start-server + pre-integration-test + + start + + + + clean-server + post-integration-test + + stop + + + + false + false + false + + + + + + org.apache.maven.plugins + maven-resources-plugin + 3.2.0 + + + default-cli + none + + copy-resources + + + true + + target/liberty/usr/shared/config + + + src/main/filtered-config + true + + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + true + once + 300 + -enableassertions + ${project.build.directory} + + **/*Test.java + + + + + integration-test + + integration-test + + + + verify + verify + + verify + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + + diff --git a/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/main/WEB-INF/web.xml b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/main/WEB-INF/web.xml new file mode 100644 index 000000000..a86f6162f --- /dev/null +++ b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/main/WEB-INF/web.xml @@ -0,0 +1,19 @@ + + + + TestServlet + TestServlet + net.wasdev.wlp.test.servlet.TestServlet + + + + TestServlet + /TestServlet + /TestServlet/* + + + diff --git a/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/main/filtered-config/environment.xml b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/main/filtered-config/environment.xml new file mode 100644 index 000000000..58447aa4d --- /dev/null +++ b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/main/filtered-config/environment.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/main/filters/test.properties b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/main/filters/test.properties new file mode 100644 index 000000000..d10998e4a --- /dev/null +++ b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/main/filters/test.properties @@ -0,0 +1 @@ +tidal.url=http://test.ibm.com:9080 \ No newline at end of file diff --git a/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/main/java/net/wasdev/wlp/test/servlet/TestServlet.java b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/main/java/net/wasdev/wlp/test/servlet/TestServlet.java new file mode 100644 index 000000000..9f162afa5 --- /dev/null +++ b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/main/java/net/wasdev/wlp/test/servlet/TestServlet.java @@ -0,0 +1,24 @@ +package net.wasdev.wlp.test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class TestServlet extends HttpServlet { + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + doPost(request,response); + } + + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + PrintWriter out = response.getWriter(); + out.println("Sample Wab Application Bundle"); + out.println("

"); + out.println("Web Application Bundle"); + out.println("

"); + } + +} diff --git a/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/main/liberty/config/server.xml b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/main/liberty/config/server.xml new file mode 100644 index 000000000..09eb1c975 --- /dev/null +++ b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/main/liberty/config/server.xml @@ -0,0 +1,10 @@ + + + jsp-2.3 + + + + + + + diff --git a/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/main/webapp/index.jsp b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/main/webapp/index.jsp new file mode 100644 index 000000000..06d826034 --- /dev/null +++ b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/main/webapp/index.jsp @@ -0,0 +1,11 @@ +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + + Hello IBM WebSphere Application Server Liberty + + +

Welcome to IBM Liberty

+

Congratulations on running this very simple demo application on ${datetime}.

+ + diff --git a/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/test/java/net/wasdev/wlp/maven/test/app/PluginConfigXmlTest.java b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/test/java/net/wasdev/wlp/maven/test/app/PluginConfigXmlTest.java new file mode 100644 index 000000000..730c3cc6d --- /dev/null +++ b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/src/test/java/net/wasdev/wlp/maven/test/app/PluginConfigXmlTest.java @@ -0,0 +1,86 @@ +package net.wasdev.wlp.maven.test.app; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.InputStreamReader; + +import java.util.Scanner; +import java.util.regex.Pattern; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; + +import org.junit.Test; + +/** + * + * Web application test case + * + */ + +public class PluginConfigXmlTest { + + public final String CONFIG_DROPINS_XML="liberty/usr/servers/test/configDropins/defaults/install_apps_configuration_1491924271.xml"; + public final String APP_WAR="liberty/usr/servers/test/apps/appsdirectory-apps-configured-variables-include-it.war"; + + public final String MESSAGES_LOG = "liberty/usr/servers/test/logs/messages.log"; + public final String INCLUDE_REGEX_MESSAGE = ".* CWWKG0028A: Processing included configuration resource: .*/|\\\\target/|\\\\liberty/|\\\\usr/|\\\\shared/|\\\\config/|\\\\environment\\.xml"; + public final String APP_STARTED_MESSAGE = ".* CWWKZ0001I: Application appsdirectory-apps-configured-variables-include-it started.*"; + + @Test + public void testMessagesLogFileExist() throws Exception { + File f = new File(MESSAGES_LOG); + assertTrue(f.getCanonicalFile() + " doesn't exist", f.exists()); + } + + @Test + public void testApplicationConfiguredInApps() throws Exception { + File in = new File(CONFIG_DROPINS_XML); + assertFalse("config dropins xml file exists when it should not", in.exists()); + + File warFile = new File(APP_WAR); + assertTrue("war file is not in correct location in apps folder", warFile.exists()); + } + + @Test + public void checkMessagesLogFor() throws Exception { + File messagesLog = new File(MESSAGES_LOG); + + InputStream serverOutput = null; + InputStreamReader in = null; + Scanner s = null; + + boolean includeFound = false; + boolean appStartedFound = false; + + try { + // Read file and search + serverOutput = new FileInputStream(messagesLog); + in = new InputStreamReader(serverOutput); + s = new Scanner(in); + + String foundString = null; + Pattern pattern1 = Pattern.compile(INCLUDE_REGEX_MESSAGE); + Pattern pattern2 = Pattern.compile(APP_STARTED_MESSAGE); + + while (s.hasNextLine()) { + String line = s.nextLine(); + if (pattern1.matcher(line).find()) { + includeFound = true; + } else if (pattern2.matcher(line).find()) { + appStartedFound = true; + } + } + } catch (Exception e) { + + } + s.close(); + serverOutput.close(); + in.close(); + + assertTrue("Did not find include file processed message in messages.log", includeFound); + assertTrue("Did not find app started message in messages.log", appStartedFound); + + } +} diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/BasicSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/BasicSupport.java index 197256d04..8cec9c06e 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/BasicSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/BasicSupport.java @@ -556,6 +556,31 @@ protected void installLicense() throws MojoExecutionException, IOException { } } } + + /* + * Handle cleaning up all three possible locations for applications, and check for both stripped and non-stripped file name in + * case that setting has been modified. + */ + protected void deleteApplication(File serverDirectory, File artifactFile, File destFile) throws IOException { + String destFileName = destFile.getName(); + String artifactFileName = artifactFile.getName(); + boolean namesAreDifferent = !destFileName.equals(artifactFileName); + + deleteApplication(new File(serverDirectory, "apps"), artifactFile); + deleteApplication(new File(serverDirectory, "dropins"), artifactFile); + // application can be expanded if server.xml configure with + deleteApplication(new File(serverDirectory, "apps/expanded"), artifactFile); + + if (namesAreDifferent) { + deleteApplication(new File(serverDirectory, "apps"), destFile); + deleteApplication(new File(serverDirectory, "dropins"), destFile); + // application can be expanded if server.xml configure with + deleteApplication(new File(serverDirectory, "apps/expanded"), destFile); + } + + } protected void deleteApplication(File parent, File artifactFile) throws IOException { deleteApplication(parent, artifactFile.getName()); @@ -571,7 +596,7 @@ protected void deleteApplication(File parent, String filename) throws IOExceptio if (application.isDirectory()) { // application can be installed with expanded format FileUtils.deleteDirectory(application); - } else { + } else if (application.exists()) { application.delete(); } } diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/ServerFeatureSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/ServerFeatureSupport.java index 989ead496..36b1689c5 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/ServerFeatureSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/ServerFeatureSupport.java @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corporation 2021. + * (C) Copyright IBM Corporation 2021, 2023. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -71,6 +71,16 @@ public void info(String msg) { public void error(String msg, Throwable e) { log.error(msg, e); } + + @Override + public void error(String msg) { + log.error(msg); + } + + @Override + public boolean isDebugEnabled() { + return log.isDebugEnabled(); + } } private void createNewServerFeatureUtil() { diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojo.java index 6237329eb..a78ab20e4 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojo.java @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corporation 2014, 2020. + * (C) Copyright IBM Corporation 2014, 2023. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -108,7 +108,7 @@ private void installSpringBootApp() throws Exception { File thinArchiveTarget = getThinArchiveTarget(fatArchiveSrc); File libIndexCacheTarget = getLibIndexCacheTarget(); - validateAppConfig(thinArchiveTarget.getName(), project.getArtifactId(), true); + validateAppConfig(thinArchiveTarget.getCanonicalPath(), thinArchiveTarget.getName(), project.getArtifactId(), true); invokeSpringBootUtilCommand(installDirectory, fatArchiveSrc.getCanonicalPath(), thinArchiveTarget.getCanonicalPath(), libIndexCacheTarget.getCanonicalPath()); } else { throw new MojoExecutionException(fatArchiveSrc.getCanonicalPath() +" file is not an executable archive. " 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 e82175f55..700dbee4b 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 @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corporation 2016, 2022. + * (C) Copyright IBM Corporation 2016, 2023. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -80,11 +80,15 @@ protected void installApp(Artifact artifact) throws Exception { log.info(MessageFormat.format(messages.getString("info.install.app"), artifact.getFile().getCanonicalPath())); Copy copyFile = (Copy) ant.createTask("copy"); - copyFile.setFile(artifact.getFile()); - String fileName = artifact.getFile().getName(); + File fileToCopy = artifact.getFile(); + copyFile.setFile(fileToCopy); + String originalFileName = fileToCopy.getName(); + File destFile = new File(destDir, originalFileName); + String destFileName = originalFileName; if (stripVersion) { - fileName = stripVersionFromName(fileName, artifact.getBaseVersion()); - copyFile.setTofile(new File(destDir, fileName)); + destFileName = stripVersionFromName(originalFileName, artifact.getBaseVersion()); + destFile = new File(destDir, destFileName); // fileName should have changed after stripping version so recreate destFile + copyFile.setTofile(destFile); } else { copyFile.setTodir(destDir); } @@ -92,16 +96,13 @@ protected void installApp(Artifact artifact) throws Exception { // validate application configuration if appsDirectory="dropins" or inject // webApplication // to target server.xml if not found for appsDirectory="apps" - validateAppConfig(fileName, artifact.getArtifactId()); + validateAppConfig(destFile.getCanonicalPath(), destFileName, artifact.getArtifactId()); - deleteApplication(new File(serverDirectory, "apps"), artifact.getFile()); - deleteApplication(new File(serverDirectory, "dropins"), artifact.getFile()); - // application can be expanded if server.xml configure with - deleteApplication(new File(serverDirectory, "apps/expanded"), artifact.getFile()); + deleteApplication(serverDirectory, fileToCopy, destFile); + copyFile.execute(); - verifyAppStarted(fileName); + verifyAppStarted(destFileName); } private void setLooseProjectRootForContainer(MavenProject proj, LooseConfigData config) throws MojoExecutionException { @@ -275,11 +276,12 @@ protected void verifyAppStarted(String appFile) throws MojoExecutionException { File serverXML = new File(serverDirectory, "server.xml"); try { + Map libertyDirPropertyFiles = getLibertyDirectoryPropertyFiles(); scd = ServerConfigDocument.getInstance(CommonLogger.getInstance(), serverXML, configDirectory, - bootstrapPropertiesFile, combinedBootstrapProperties, serverEnvFile, false); + bootstrapPropertiesFile, combinedBootstrapProperties, serverEnvFile, false, libertyDirPropertyFiles); //appName will be set to a name derived from appFile if no name can be found. - appName = scd.findNameForLocation(appFile); + appName = ServerConfigDocument.findNameForLocation(appFile); } catch (Exception e) { log.warn(e.getLocalizedMessage()); log.debug(e); @@ -380,15 +382,20 @@ private boolean containsJavaSource(File dir) { } protected void validateAppConfig(String fileName, String artifactId) throws Exception { - validateAppConfig(fileName, artifactId, false); + validateAppConfig(null, fileName, artifactId, false); } - protected void validateAppConfig(String fileName, String artifactId, boolean isSpringBootApp) throws Exception { + protected void validateAppConfig(String fullyQualifiedFileName, String fileName, String artifactId) throws Exception { + validateAppConfig(fullyQualifiedFileName, fileName, artifactId, false); + } + + protected void validateAppConfig(String fullyQualifiedFileName, String fileName, String artifactId, boolean isSpringBootApp) throws Exception { String appsDir = getAppsDirectory(); - if (appsDir.equalsIgnoreCase("apps") && !isAppConfiguredInSourceServerXml(fileName)) { + if (appsDir.equalsIgnoreCase("apps") && !isAppConfiguredInSourceServerXml(fullyQualifiedFileName, fileName)) { // add application configuration + log.info("Could not find application "+fileName+" in server.xml locations."); applicationXml.createApplicationElement(fileName, artifactId, isSpringBootApp); - } else if (appsDir.equalsIgnoreCase("dropins") && isAppConfiguredInSourceServerXml(fileName)) + } else if (appsDir.equalsIgnoreCase("dropins") && isAppConfiguredInSourceServerXml(fullyQualifiedFileName, fileName)) throw new MojoExecutionException(messages.getString("error.install.app.dropins.directory")); } diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/UndeployAppMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/UndeployAppMojo.java index af7773109..98436c6c6 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/UndeployAppMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/UndeployAppMojo.java @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corporation 2014, 2020. + * (C) Copyright IBM Corporation 2014, 2023. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,11 @@ package io.openliberty.tools.maven.applications; import java.io.File; -import java.io.IOException; import java.text.MessageFormat; +import java.util.Map; import java.util.Set; import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.MojoExecutionException; @@ -136,11 +135,12 @@ protected void undeployApp(File file) throws MojoExecutionException { try { File serverXML = new File(serverDirectory.getCanonicalPath(), "server.xml"); + Map libertyDirPropertyFiles = getLibertyDirectoryPropertyFiles(); scd = ServerConfigDocument.getInstance(CommonLogger.getInstance(), serverXML, configDirectory, - bootstrapPropertiesFile, combinedBootstrapProperties, serverEnvFile, false); + bootstrapPropertiesFile, combinedBootstrapProperties, serverEnvFile, false, libertyDirPropertyFiles); //appName will be set to a name derived from file if no name can be found. - appName = scd.findNameForLocation(appName); + appName = ServerConfigDocument.findNameForLocation(appName); } catch (Exception e) { log.warn(e.getLocalizedMessage()); } diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java index 3fe51776b..de108bfb7 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corporation 2017, 2019. + * (C) Copyright IBM Corporation 2017, 2023. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ import java.text.MessageFormat; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import org.apache.maven.artifact.Artifact; @@ -278,14 +279,15 @@ protected String stripVersionFromName(String name, String version) { } } - protected boolean isAppConfiguredInSourceServerXml(String fileName) { + protected boolean isAppConfiguredInSourceServerXml(String fullyQualifiedFileName, String fileName) { Set locations = getAppConfigLocationsFromSourceServerXml(); - if (locations.contains(fileName)) { - log.debug("Application configuration is found in server.xml : " + fileName); + if (locations.contains(fileName) || ((fullyQualifiedFileName != null) && locations.contains(fullyQualifiedFileName))) { + log.info("Application configuration is found in server.xml : " + fileName); return true; } else { + log.info("Application configuration is not found in server.xml : " + fileName); return false; } } @@ -310,8 +312,10 @@ protected Set getAppConfigLocationsFromSourceServerXml() { if (serverXML != null && serverXML.exists()) { try { - scd = ServerConfigDocument.getInstance(CommonLogger.getInstance(), serverXML, configDirectory, - bootstrapPropertiesFile, combinedBootstrapProperties, serverEnvFile, false); + Map libertyDirPropertyFiles = getLibertyDirectoryPropertyFiles(); + scd = ServerConfigDocument.getInstance(CommonLogger.getInstance(), serverXML, configDirectory, + bootstrapPropertiesFile, combinedBootstrapProperties, serverEnvFile, false, + libertyDirPropertyFiles); } catch (Exception e) { log.warn(e.getLocalizedMessage()); log.debug(e); From 1d5d5d26397cc2b6571809b89395fd2a1c586d1b Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Thu, 30 Mar 2023 14:39:21 -0500 Subject: [PATCH 02/12] Use my common branch --- .github/workflows/maven.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 2eff7c0ff..23cb092c1 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -43,7 +43,8 @@ jobs: - name: Checkout ci.common uses: actions/checkout@v3 with: - repository: OpenLiberty/ci.common + repository: cherylking/ci.common + ref: resolveVars path: ci.common - name: Checkout ci.ant uses: actions/checkout@v3 @@ -98,7 +99,7 @@ jobs: - name: Clone ci.ant, ci.common, ci.maven repos to C drive run: | cp -r D:/a/ci.maven/ci.maven C:/ci.maven - git clone https://github.com/OpenLiberty/ci.common.git C:/ci.common + git clone https://github.com/cherylking/ci.common.git --branch resolveVars --single-branch C:/ci.common git clone https://github.com/OpenLiberty/ci.ant.git C:/ci.ant - name: Cache maven packages uses: actions/cache@v3 From a0218479796e81dfb9106615de3e6f4e1284ade2 Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Thu, 30 Mar 2023 18:34:53 -0500 Subject: [PATCH 03/12] Remove accidental changes from alt-output-dir pom.xml --- .../src/it/alt-outputdir-it/pom.xml | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/liberty-maven-plugin/src/it/alt-outputdir-it/pom.xml b/liberty-maven-plugin/src/it/alt-outputdir-it/pom.xml index 254ecdcea..b68115214 100644 --- a/liberty-maven-plugin/src/it/alt-outputdir-it/pom.xml +++ b/liberty-maven-plugin/src/it/alt-outputdir-it/pom.xml @@ -46,9 +46,6 @@ - - ${project.basedir}/src/main/filters/test.properties - org.apache.maven.plugins @@ -59,31 +56,6 @@ pom.xml - - org.apache.maven.plugins - maven-resources-plugin - 3.2.0 - - - default-cli - none - - copy-resources - - - true - - target/liberty/wlp/usr/shared/config - - - src/main/filtered-config - true - - - - - - io.openliberty.tools liberty-maven-plugin From 04eda4d18ebe179a1906bc35313c478e3c49f6d2 Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Thu, 30 Mar 2023 19:00:42 -0500 Subject: [PATCH 04/12] Change needed for Windows --- .../io/openliberty/tools/maven/server/PluginConfigSupport.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java index de108bfb7..bf7a2fd1b 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java @@ -283,6 +283,9 @@ protected boolean isAppConfiguredInSourceServerXml(String fullyQualifiedFileName Set locations = getAppConfigLocationsFromSourceServerXml(); + // For Windows, modify fully qualified file name to use forward slashes since resolved app locations were stored that way + fullyQualifiedFileName = fullyQualifiedFileName == null ? null : fullyQualifiedFileName.replace("\\","/"); + if (locations.contains(fileName) || ((fullyQualifiedFileName != null) && locations.contains(fullyQualifiedFileName))) { log.info("Application configuration is found in server.xml : " + fileName); return true; From e095811fa4de472300b8dfb67cdb2ae1febda494 Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Fri, 31 Mar 2023 08:34:14 -0500 Subject: [PATCH 05/12] Update versions in yml file --- .github/workflows/maven.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 23cb092c1..1b5f786fa 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -22,13 +22,13 @@ jobs: matrix: # test against latest update of each major Java version, as well as specific updates of LTS versions: RUNTIME: [ol, wlp] - RUNTIME_VERSION: [22.0.0.6, 22.0.0.9] + RUNTIME_VERSION: [22.0.0.12, 22.0.0.9] java: [17, 11, 8] exclude: - java: 8 - RUNTIME_VERSION: 22.0.0.6 + RUNTIME_VERSION: 22.0.0.9 - java: 17 - RUNTIME_VERSION: 22.0.0.6 + RUNTIME_VERSION: 22.0.0.9 name: ${{ matrix.RUNTIME }} ${{ matrix.RUNTIME_VERSION }}, Java ${{ matrix.java }}, Linux steps: # Checkout repos @@ -77,13 +77,13 @@ jobs: matrix: # test against latest update of each major Java version, as well as specific updates of LTS versions: RUNTIME: [ol, wlp] - RUNTIME_VERSION: [22.0.0.6, 22.0.0.9] + RUNTIME_VERSION: [22.0.0.12, 22.0.0.9] java: [17, 11, 8] exclude: - java: 8 - RUNTIME_VERSION: 22.0.0.6 + RUNTIME_VERSION: 22.0.0.9 - java: 17 - RUNTIME_VERSION: 22.0.0.6 + RUNTIME_VERSION: 22.0.0.9 name: ${{ matrix.RUNTIME }} ${{ matrix.RUNTIME_VERSION }}, Java ${{ matrix.java }}, Windows steps: # Checkout repos From ad0e722c049757292e6beec70c43911e28954aef Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Fri, 31 Mar 2023 08:35:05 -0500 Subject: [PATCH 06/12] Remove backward slash workaround --- .../io/openliberty/tools/maven/server/PluginConfigSupport.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java index bf7a2fd1b..e2efd3b82 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java @@ -284,7 +284,7 @@ protected boolean isAppConfiguredInSourceServerXml(String fullyQualifiedFileName Set locations = getAppConfigLocationsFromSourceServerXml(); // For Windows, modify fully qualified file name to use forward slashes since resolved app locations were stored that way - fullyQualifiedFileName = fullyQualifiedFileName == null ? null : fullyQualifiedFileName.replace("\\","/"); + //fullyQualifiedFileName = fullyQualifiedFileName == null ? null : fullyQualifiedFileName.replace("\\","/"); if (locations.contains(fileName) || ((fullyQualifiedFileName != null) && locations.contains(fullyQualifiedFileName))) { log.info("Application configuration is found in server.xml : " + fileName); From 10198e8d7e8c9bbc996e55193adebb9625fcb04d Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Fri, 31 Mar 2023 09:31:58 -0500 Subject: [PATCH 07/12] Put Windows fix back in --- .../io/openliberty/tools/maven/server/PluginConfigSupport.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java index e2efd3b82..bf7a2fd1b 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java @@ -284,7 +284,7 @@ protected boolean isAppConfiguredInSourceServerXml(String fullyQualifiedFileName Set locations = getAppConfigLocationsFromSourceServerXml(); // For Windows, modify fully qualified file name to use forward slashes since resolved app locations were stored that way - //fullyQualifiedFileName = fullyQualifiedFileName == null ? null : fullyQualifiedFileName.replace("\\","/"); + fullyQualifiedFileName = fullyQualifiedFileName == null ? null : fullyQualifiedFileName.replace("\\","/"); if (locations.contains(fileName) || ((fullyQualifiedFileName != null) && locations.contains(fullyQualifiedFileName))) { log.info("Application configuration is found in server.xml : " + fileName); From f2409d55bfc69ca288fb7342243b1856e9c1101e Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Mon, 3 Apr 2023 09:45:28 -0500 Subject: [PATCH 08/12] Fix for loose app config validation --- .../openliberty/tools/maven/applications/DeployMojo.java | 7 ++++--- .../tools/maven/applications/DeployMojoSupport.java | 4 ---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojo.java index a78ab20e4..56cdfcd1c 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojo.java @@ -196,6 +196,7 @@ private void installLooseApplication(MavenProject proj) throws Exception { String application = looseConfigFileName.substring(0, looseConfigFileName.length() - 4); File destDir = new File(serverDirectory, getAppsDirectory()); File looseConfigFile = new File(destDir, looseConfigFileName); + File applicationFullPath = new File(destDir, application); File devcDestDir = new File(new File(project.getBuild().getDirectory(), DevUtil.DEVC_HIDDEN_FOLDER), getAppsDirectory()); File devcLooseConfigFile = new File(devcDestDir, looseConfigFileName); @@ -204,7 +205,7 @@ private void installLooseApplication(MavenProject proj) throws Exception { switch (proj.getPackaging()) { case "war": - validateAppConfig(application, proj.getArtifactId()); + validateAppConfig(applicationFullPath.getCanonicalPath(), application, proj.getArtifactId()); log.info(MessageFormat.format(messages.getString("info.install.app"), looseConfigFileName)); installLooseConfigWar(proj, config, false); installAndVerifyApp(config, looseConfigFile, application); @@ -216,7 +217,7 @@ private void installLooseApplication(MavenProject proj) throws Exception { } break; case "ear": - validateAppConfig(application, proj.getArtifactId()); + validateAppConfig(applicationFullPath.getCanonicalPath(), application, proj.getArtifactId()); log.info(MessageFormat.format(messages.getString("info.install.app"), looseConfigFileName)); installLooseConfigEar(proj, config, false); installAndVerifyApp(config, looseConfigFile, application); @@ -229,7 +230,7 @@ private void installLooseApplication(MavenProject proj) throws Exception { break; case "liberty-assembly": if (mavenWarPluginExists(proj) || new File(proj.getBasedir(), "src/main/webapp").exists()) { - validateAppConfig(application, proj.getArtifactId()); + validateAppConfig(applicationFullPath.getCanonicalPath(), application, proj.getArtifactId()); log.info(MessageFormat.format(messages.getString("info.install.app"), looseConfigFileName)); installLooseConfigWar(proj, config, false); installAndVerifyApp(config, looseConfigFile, application); 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 700dbee4b..135a4272d 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 @@ -381,10 +381,6 @@ private boolean containsJavaSource(File dir) { return false; } - protected void validateAppConfig(String fileName, String artifactId) throws Exception { - validateAppConfig(null, fileName, artifactId, false); - } - protected void validateAppConfig(String fullyQualifiedFileName, String fileName, String artifactId) throws Exception { validateAppConfig(fullyQualifiedFileName, fileName, artifactId, false); } From f072ada4e21798bd23954ee4d8b12e3fd2e729c4 Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Mon, 3 Apr 2023 11:57:09 -0500 Subject: [PATCH 09/12] Fix for debug messages always showing up --- .../tools/maven/ServerFeatureSupport.java | 16 +++++++++++----- .../tools/maven/utils/CommonLogger.java | 12 +++++++++--- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/ServerFeatureSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/ServerFeatureSupport.java index 36b1689c5..9a8d3d4c8 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/ServerFeatureSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/ServerFeatureSupport.java @@ -36,17 +36,23 @@ protected class ServerFeatureMojoUtil extends ServerFeatureUtil { @Override public void debug(String msg) { - log.debug(msg); + if (isDebugEnabled()) { + log.debug(msg); + } } @Override public void debug(String msg, Throwable e) { - log.debug(msg, e); + if (isDebugEnabled()) { + log.debug(msg, e); + } } @Override public void debug(Throwable e) { - log.debug(e); + if (isDebugEnabled()) { + log.debug(e); + } } @Override @@ -54,7 +60,7 @@ public void warn(String msg) { if (!suppressLogs) { log.warn(msg); } else { - log.debug(msg); + debug(msg); } } @@ -63,7 +69,7 @@ public void info(String msg) { if (!suppressLogs) { log.info(msg); } else { - log.debug(msg); + debug(msg); } } diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/utils/CommonLogger.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/utils/CommonLogger.java index 64bcc1724..76f5f5e00 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/utils/CommonLogger.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/utils/CommonLogger.java @@ -32,17 +32,23 @@ public static CommonLogger getInstance() { @Override public void debug(String msg) { - getLog().debug(msg); + if (isDebugEnabled()) { + getLog().debug(msg); + } } @Override public void debug(String msg, Throwable e) { - getLog().debug(msg, e); + if (isDebugEnabled()) { + getLog().debug(msg, e); + } } @Override public void debug(Throwable e) { - getLog().debug(e); + if (isDebugEnabled()) { + getLog().debug(e); + } } @Override From 887d73691ea3070d67d3c29da742c515a0cc2717 Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Mon, 3 Apr 2023 13:35:39 -0500 Subject: [PATCH 10/12] Add test for loose application configured in server.xml --- .../pom.xml | 14 -- .../invoker.properties | 2 + .../pom.xml | 217 ++++++++++++++++++ .../src/main/WEB-INF/web.xml | 19 ++ .../src/main/filtered-config/environment.xml | 4 + .../src/main/filters/test.properties | 1 + .../wasdev/wlp/test/servlet/TestServlet.java | 24 ++ .../src/main/liberty/config/server.xml | 10 + .../src/main/webapp/index.jsp | 11 + .../maven/test/app/PluginConfigXmlTest.java | 90 ++++++++ 10 files changed, 378 insertions(+), 14 deletions(-) create mode 100644 liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/invoker.properties create mode 100644 liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/pom.xml create mode 100644 liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/main/WEB-INF/web.xml create mode 100644 liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/main/filtered-config/environment.xml create mode 100644 liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/main/filters/test.properties create mode 100644 liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/main/java/net/wasdev/wlp/test/servlet/TestServlet.java create mode 100644 liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/main/liberty/config/server.xml create mode 100644 liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/main/webapp/index.jsp create mode 100644 liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/test/java/net/wasdev/wlp/maven/test/app/PluginConfigXmlTest.java diff --git a/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/pom.xml b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/pom.xml index eacfbfc0b..146cc7fa6 100644 --- a/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/pom.xml +++ b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/pom.xml @@ -117,20 +117,6 @@ false - install-artifact package diff --git a/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/invoker.properties b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/invoker.properties new file mode 100644 index 000000000..51198c7cb --- /dev/null +++ b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/invoker.properties @@ -0,0 +1,2 @@ +# prove the variables in server.xml can be resolved correctly +invoker.goals.1 = clean liberty:create resources:copy-resources install \ No newline at end of file diff --git a/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/pom.xml b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/pom.xml new file mode 100644 index 000000000..fe10cadb0 --- /dev/null +++ b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/pom.xml @@ -0,0 +1,217 @@ + + + 4.0.0 + + + io.openliberty.tools.it + tests + 1.0-SNAPSHOT + + + appsdirectory-apps-configured-variables-include-looseapp-it + war + + + + org.apache.geronimo.specs + geronimo-servlet_3.0_spec + 1.0 + provided + + + commons-logging + commons-logging + 1.0.4 + test + + + junit + junit + 4.13.1 + test + + + + + ${project.artifactId} + + ${project.basedir}/src/main/filters/test.properties + + + + + + org.apache.maven.plugins + maven-war-plugin + 3.3.2 + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.5 + + + org.apache.maven.plugins + maven-surefire-plugin + 2.5 + + + org.apache.felix + maven-bundle-plugin + 2.3.7 + + + + + + maven-war-plugin + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + + org.apache.felix + maven-bundle-plugin + + + bundle-manifest + process-classes + + manifest + + + + + + war + + + /test-wab + WEB-INF/classes + + javax.servlet.jsp.el, + javax.servlet.jsp, + javax.servlet.jsp.tagext, + * + + + + + + io.openliberty.tools + liberty-maven-plugin + @pom.version@ + true + + true + + ${project.groupId} + assembly-server + ${project.version} + zip + + test + true + + + + install-artifact + package + + deploy + + + true + apps + true + + + + start-server + pre-integration-test + + start + + + + clean-server + post-integration-test + + stop + + + + false + false + false + + + + + + org.apache.maven.plugins + maven-resources-plugin + 3.2.0 + + + default-cli + none + + copy-resources + + + true + + target/liberty/usr/shared/config + + + src/main/filtered-config + true + + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + true + once + 300 + -enableassertions + ${project.build.directory} + + **/*Test.java + + + + + integration-test + + integration-test + + + + verify + verify + + verify + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + + diff --git a/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/main/WEB-INF/web.xml b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/main/WEB-INF/web.xml new file mode 100644 index 000000000..a86f6162f --- /dev/null +++ b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/main/WEB-INF/web.xml @@ -0,0 +1,19 @@ + + + + TestServlet + TestServlet + net.wasdev.wlp.test.servlet.TestServlet + + + + TestServlet + /TestServlet + /TestServlet/* + + + diff --git a/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/main/filtered-config/environment.xml b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/main/filtered-config/environment.xml new file mode 100644 index 000000000..58447aa4d --- /dev/null +++ b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/main/filtered-config/environment.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/main/filters/test.properties b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/main/filters/test.properties new file mode 100644 index 000000000..d10998e4a --- /dev/null +++ b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/main/filters/test.properties @@ -0,0 +1 @@ +tidal.url=http://test.ibm.com:9080 \ No newline at end of file diff --git a/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/main/java/net/wasdev/wlp/test/servlet/TestServlet.java b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/main/java/net/wasdev/wlp/test/servlet/TestServlet.java new file mode 100644 index 000000000..9f162afa5 --- /dev/null +++ b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/main/java/net/wasdev/wlp/test/servlet/TestServlet.java @@ -0,0 +1,24 @@ +package net.wasdev.wlp.test.servlet; + +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class TestServlet extends HttpServlet { + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + doPost(request,response); + } + + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + PrintWriter out = response.getWriter(); + out.println("Sample Wab Application Bundle"); + out.println("

"); + out.println("Web Application Bundle"); + out.println("

"); + } + +} diff --git a/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/main/liberty/config/server.xml b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/main/liberty/config/server.xml new file mode 100644 index 000000000..09eb1c975 --- /dev/null +++ b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/main/liberty/config/server.xml @@ -0,0 +1,10 @@ + + + jsp-2.3 + + + + + + + diff --git a/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/main/webapp/index.jsp b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/main/webapp/index.jsp new file mode 100644 index 000000000..06d826034 --- /dev/null +++ b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/main/webapp/index.jsp @@ -0,0 +1,11 @@ +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + + Hello IBM WebSphere Application Server Liberty + + +

Welcome to IBM Liberty

+

Congratulations on running this very simple demo application on ${datetime}.

+ + diff --git a/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/test/java/net/wasdev/wlp/maven/test/app/PluginConfigXmlTest.java b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/test/java/net/wasdev/wlp/maven/test/app/PluginConfigXmlTest.java new file mode 100644 index 000000000..92da6cdc3 --- /dev/null +++ b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-looseapp-it/src/test/java/net/wasdev/wlp/maven/test/app/PluginConfigXmlTest.java @@ -0,0 +1,90 @@ +package net.wasdev.wlp.maven.test.app; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.InputStreamReader; + +import java.util.Scanner; +import java.util.regex.Pattern; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; + +import org.junit.Test; + +/** + * + * Web application test case + * + */ + +public class PluginConfigXmlTest { + + public final String CONFIG_DROPINS_XML="liberty/usr/servers/test/configDropins/defaults/install_apps_configuration_1491924271.xml"; + public final String APP_WAR="liberty/usr/servers/test/apps/appsdirectory-apps-configured-variables-include-looseapp-it.war"; + public final String APP_WAR_XML= APP_WAR + ".xml"; + + public final String MESSAGES_LOG = "liberty/usr/servers/test/logs/messages.log"; + public final String INCLUDE_REGEX_MESSAGE = ".* CWWKG0028A: Processing included configuration resource: .*/|\\\\target/|\\\\liberty/|\\\\usr/|\\\\shared/|\\\\config/|\\\\environment\\.xml"; + public final String APP_STARTED_MESSAGE = ".* CWWKZ0001I: Application appsdirectory-apps-configured-variables-include-looseapp-it started.*"; + + @Test + public void testMessagesLogFileExist() throws Exception { + File f = new File(MESSAGES_LOG); + assertTrue(f.getCanonicalFile() + " doesn't exist", f.exists()); + } + + @Test + public void testLooseApplicationConfiguredInApps() throws Exception { + File in = new File(CONFIG_DROPINS_XML); + assertFalse("config dropins xml file exists when it should not", in.exists()); + + File warFile = new File(APP_WAR); + assertFalse("war file exists in apps folder when it should not", warFile.exists()); + + File looseAppFile = new File(APP_WAR_XML); + assertTrue("loose app file is not in correct location in apps folder", looseAppFile.exists()); + } + + @Test + public void checkMessagesLogFor() throws Exception { + File messagesLog = new File(MESSAGES_LOG); + + InputStream serverOutput = null; + InputStreamReader in = null; + Scanner s = null; + + boolean includeFound = false; + boolean appStartedFound = false; + + try { + // Read file and search + serverOutput = new FileInputStream(messagesLog); + in = new InputStreamReader(serverOutput); + s = new Scanner(in); + + String foundString = null; + Pattern pattern1 = Pattern.compile(INCLUDE_REGEX_MESSAGE); + Pattern pattern2 = Pattern.compile(APP_STARTED_MESSAGE); + + while (s.hasNextLine()) { + String line = s.nextLine(); + if (pattern1.matcher(line).find()) { + includeFound = true; + } else if (pattern2.matcher(line).find()) { + appStartedFound = true; + } + } + } catch (Exception e) { + + } + s.close(); + serverOutput.close(); + in.close(); + + assertTrue("Did not find include file processed message in messages.log", includeFound); + assertTrue("Did not find app started message in messages.log", appStartedFound); + + } +} From 57313d397b12ecc94b78e9b19c71f2b9b1b8de22 Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Mon, 3 Apr 2023 14:17:36 -0500 Subject: [PATCH 11/12] Another log fix --- .../maven/applications/DeployMojoSupport.java | 2 +- .../maven/applications/UndeployAppMojo.java | 2 +- .../tools/maven/server/PluginConfigSupport.java | 2 +- .../tools/maven/utils/CommonLogger.java | 16 ++++++++++++++-- 4 files changed, 17 insertions(+), 5 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 135a4272d..72f63f13e 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 @@ -277,7 +277,7 @@ protected void verifyAppStarted(String appFile) throws MojoExecutionException { try { Map libertyDirPropertyFiles = getLibertyDirectoryPropertyFiles(); - scd = ServerConfigDocument.getInstance(CommonLogger.getInstance(), serverXML, configDirectory, + scd = ServerConfigDocument.getInstance(CommonLogger.getInstance(log), serverXML, configDirectory, bootstrapPropertiesFile, combinedBootstrapProperties, serverEnvFile, false, libertyDirPropertyFiles); //appName will be set to a name derived from appFile if no name can be found. diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/UndeployAppMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/UndeployAppMojo.java index 98436c6c6..196bf9aac 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/UndeployAppMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/UndeployAppMojo.java @@ -136,7 +136,7 @@ protected void undeployApp(File file) throws MojoExecutionException { File serverXML = new File(serverDirectory.getCanonicalPath(), "server.xml"); Map libertyDirPropertyFiles = getLibertyDirectoryPropertyFiles(); - scd = ServerConfigDocument.getInstance(CommonLogger.getInstance(), serverXML, configDirectory, + scd = ServerConfigDocument.getInstance(CommonLogger.getInstance(log), serverXML, configDirectory, bootstrapPropertiesFile, combinedBootstrapProperties, serverEnvFile, false, libertyDirPropertyFiles); //appName will be set to a name derived from file if no name can be found. diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java index bf7a2fd1b..efa803268 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/PluginConfigSupport.java @@ -316,7 +316,7 @@ protected Set getAppConfigLocationsFromSourceServerXml() { if (serverXML != null && serverXML.exists()) { try { Map libertyDirPropertyFiles = getLibertyDirectoryPropertyFiles(); - scd = ServerConfigDocument.getInstance(CommonLogger.getInstance(), serverXML, configDirectory, + scd = ServerConfigDocument.getInstance(CommonLogger.getInstance(log), serverXML, configDirectory, bootstrapPropertiesFile, combinedBootstrapProperties, serverEnvFile, false, libertyDirPropertyFiles); } catch (Exception e) { diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/utils/CommonLogger.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/utils/CommonLogger.java index 76f5f5e00..6f16af14e 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/utils/CommonLogger.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/utils/CommonLogger.java @@ -15,6 +15,7 @@ */ package io.openliberty.tools.maven.utils; +import org.apache.maven.plugin.logging.Log; import org.codehaus.mojo.pluginsupport.MojoSupport; import io.openliberty.tools.common.CommonLoggerI; @@ -23,13 +24,24 @@ public class CommonLogger extends MojoSupport implements CommonLoggerI { private static CommonLogger logger = null; - public static CommonLogger getInstance() { + public static CommonLogger getInstance(Log mojoLogger) { if (logger == null) { - logger = new CommonLogger(); + logger = new CommonLogger(mojoLogger); + } else { + logger.setLogger(mojoLogger); } + return logger; } + private CommonLogger(Log mojoLogger) { + setLog(mojoLogger); + } + + private void setLogger(Log mojoLogger) { + setLog(mojoLogger); + } + @Override public void debug(String msg) { if (isDebugEnabled()) { From d656b2afac21ec2d9fe8561c3f2e518e368eef99 Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Mon, 3 Apr 2023 17:23:25 -0500 Subject: [PATCH 12/12] Revert back to ci.common main branch --- .github/workflows/maven.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 1b5f786fa..c0f195f03 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -43,8 +43,7 @@ jobs: - name: Checkout ci.common uses: actions/checkout@v3 with: - repository: cherylking/ci.common - ref: resolveVars + repository: OpenLiberty/ci.common path: ci.common - name: Checkout ci.ant uses: actions/checkout@v3 @@ -99,7 +98,7 @@ jobs: - name: Clone ci.ant, ci.common, ci.maven repos to C drive run: | cp -r D:/a/ci.maven/ci.maven C:/ci.maven - git clone https://github.com/cherylking/ci.common.git --branch resolveVars --single-branch C:/ci.common + git clone https://github.com/OpenLiberty/ci.common.git C:/ci.common git clone https://github.com/OpenLiberty/ci.ant.git C:/ci.ant - name: Cache maven packages uses: actions/cache@v3