diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 2eff7c0ff..c0f195f03 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 @@ -76,13 +76,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 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..146cc7fa6 --- /dev/null +++ b/liberty-maven-plugin/src/it/appsdirectory-apps-configured-variables-include-it/pom.xml @@ -0,0 +1,217 @@ + + + 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/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); + + } +} 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..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 @@ -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. @@ -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); } } @@ -71,6 +77,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..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 @@ -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. " @@ -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 e82175f55..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 @@ -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 { - scd = ServerConfigDocument.getInstance(CommonLogger.getInstance(), serverXML, configDirectory, - bootstrapPropertiesFile, combinedBootstrapProperties, serverEnvFile, false); + Map libertyDirPropertyFiles = getLibertyDirectoryPropertyFiles(); + 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. - appName = scd.findNameForLocation(appFile); + appName = ServerConfigDocument.findNameForLocation(appFile); } catch (Exception e) { log.warn(e.getLocalizedMessage()); log.debug(e); @@ -379,16 +381,17 @@ private boolean containsJavaSource(File dir) { return false; } - protected void validateAppConfig(String fileName, String artifactId) throws Exception { - validateAppConfig(fileName, artifactId, false); + protected void validateAppConfig(String fullyQualifiedFileName, String fileName, String artifactId) throws Exception { + validateAppConfig(fullyQualifiedFileName, fileName, artifactId, false); } - protected void validateAppConfig(String fileName, String artifactId, boolean isSpringBootApp) throws Exception { + 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..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 @@ -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"); - scd = ServerConfigDocument.getInstance(CommonLogger.getInstance(), serverXML, configDirectory, - bootstrapPropertiesFile, combinedBootstrapProperties, serverEnvFile, false); + Map libertyDirPropertyFiles = getLibertyDirectoryPropertyFiles(); + 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. - 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..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 @@ -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,18 @@ 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); + // 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; } else { + log.info("Application configuration is not found in server.xml : " + fileName); return false; } } @@ -310,8 +315,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(log), serverXML, configDirectory, + bootstrapPropertiesFile, combinedBootstrapProperties, serverEnvFile, false, + libertyDirPropertyFiles); } catch (Exception e) { log.warn(e.getLocalizedMessage()); log.debug(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 64bcc1724..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,26 +24,43 @@ 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) { - 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