From 1167f4baa07f08bacf33f199d375501d59189bce Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Fri, 3 May 2024 17:24:10 -0500 Subject: [PATCH 1/5] Handle Java source versions other than 8 for compile-jsp --- .github/workflows/maven.yml | 9 +- liberty-maven-plugin/pom.xml | 6 +- .../src/it/compile-jsp-it/pom.xml | 6 + .../wlp/maven/test/app/CompileJSPTest.java | 11 ++ .../src/it/compile-jsp-source-17-it/pom.xml | 185 ++++++++++++++++++ .../wlp/maven/test/app/CompileJSPTest.java | 82 ++++++++ .../src/test/resources/server.xml | 5 + .../compile-jsp-source-17-it/webapp/index.jsp | 10 + .../tools/maven/jsp/CompileJspMojo.java | 40 +++- 9 files changed, 346 insertions(+), 8 deletions(-) create mode 100644 liberty-maven-plugin/src/it/compile-jsp-source-17-it/pom.xml create mode 100644 liberty-maven-plugin/src/it/compile-jsp-source-17-it/src/test/java/net/wasdev/wlp/maven/test/app/CompileJSPTest.java create mode 100644 liberty-maven-plugin/src/it/compile-jsp-source-17-it/src/test/resources/server.xml create mode 100644 liberty-maven-plugin/src/it/compile-jsp-source-17-it/webapp/index.jsp diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 5c5bb1be0..11a0bb794 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -53,7 +53,8 @@ jobs: - name: Checkout ci.ant uses: actions/checkout@v3 with: - repository: OpenLiberty/ci.ant + repository: cherylking/ci.ant + ref: updateCompileJsp path: ci.ant - name: Set up Maven uses: stCarolas/setup-maven@v4.5 @@ -67,7 +68,7 @@ jobs: # Run tests that require a minimum of Java 17 or later - name: Run tests that require a minimum of Java 17 or later if: ${{ matrix.java == '17' || matrix.java == '21'}} - run: ./mvnw -V verify --batch-mode --no-transfer-progress --errors -DtrimStackTrace=false -Ponline-its -D"invoker.streamLogsOnFailures"=true -D"invoker.test"="*setup*,*springboot-3-*" -Druntime=${{ matrix.RUNTIME }} -DruntimeVersion="${{ matrix.RUNTIME_VERSION }}" + run: ./mvnw -V verify --batch-mode --no-transfer-progress --errors -DtrimStackTrace=false -Ponline-its -D"invoker.streamLogsOnFailures"=true -D"invoker.test"="*setup*,*springboot-3-*,*compile-jsp-source-17-*" -Druntime=${{ matrix.RUNTIME }} -DruntimeVersion="${{ matrix.RUNTIME_VERSION }}" # Run tests - name: Run tests run: ./mvnw -V verify --batch-mode --no-transfer-progress --errors -DtrimStackTrace=false -Ponline-its -D"invoker.streamLogsOnFailures"=true -Druntime=${{ matrix.RUNTIME }} -DruntimeVersion="${{ matrix.RUNTIME_VERSION }}" @@ -103,7 +104,7 @@ jobs: 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/OpenLiberty/ci.ant.git C:/ci.ant + git clone https://github.com/cherylking/ci.ant.git --branch updateCompileJsp --single-branch C:/ci.ant - name: Set up Maven uses: stCarolas/setup-maven@v4.5 with: @@ -119,7 +120,7 @@ jobs: # Run tests that require a minimum of Java 17 or later - name: Run tests that require a minimum of Java 17 or later if: ${{ matrix.java == '17' || matrix.java == '21'}} - run: .\mvnw.cmd -V verify -Ponline-its --batch-mode --no-transfer-progress --errors -DtrimStackTrace=false -D"invoker.streamLogsOnFailures"=true -D"invoker.test"="*setup*,*springboot-3-*" -Druntime=${{ matrix.RUNTIME }} -DruntimeVersion="${{ matrix.RUNTIME_VERSION }}" + run: .\mvnw.cmd -V verify -Ponline-its --batch-mode --no-transfer-progress --errors -DtrimStackTrace=false -D"invoker.streamLogsOnFailures"=true -D"invoker.test"="*setup*,*springboot-3-*,*compile-jsp-source-17-*" -Druntime=${{ matrix.RUNTIME }} -DruntimeVersion="${{ matrix.RUNTIME_VERSION }}" # Run tests - name: Run tests working-directory: C:/ci.maven diff --git a/liberty-maven-plugin/pom.xml b/liberty-maven-plugin/pom.xml index 3267fc772..7bd68ec5d 100644 --- a/liberty-maven-plugin/pom.xml +++ b/liberty-maven-plugin/pom.xml @@ -37,7 +37,7 @@ io.openliberty.tools liberty-ant-tasks - 1.9.14 + 1.9.15-SNAPSHOT org.apache.maven @@ -225,6 +225,7 @@ binary-scanner-it/pom.xml springboot-3-tests/pom.xml dev-container-it/pom.xml + compile-jsp-source-17-it/pom.xml @@ -266,6 +267,7 @@ binary-scanner-it/pom.xml springboot-3-tests/pom.xml dev-container-it/pom.xml + compile-jsp-source-17-it/pom.xml @@ -306,6 +308,7 @@ generate-features-it/pom.xml binary-scanner-it/pom.xml springboot-3-tests/pom.xml + compile-jsp-source-17-it/pom.xml @@ -351,6 +354,7 @@ generate-features-it/pom.xml binary-scanner-it/pom.xml springboot-3-tests/pom.xml + compile-jsp-source-17-it/pom.xml diff --git a/liberty-maven-plugin/src/it/compile-jsp-it/pom.xml b/liberty-maven-plugin/src/it/compile-jsp-it/pom.xml index 7da8c6cac..67888838c 100644 --- a/liberty-maven-plugin/src/it/compile-jsp-it/pom.xml +++ b/liberty-maven-plugin/src/it/compile-jsp-it/pom.xml @@ -27,6 +27,12 @@ + + UTF-8 + UTF-8 + 8 + + diff --git a/liberty-maven-plugin/src/it/compile-jsp-it/src/test/java/net/wasdev/wlp/maven/test/app/CompileJSPTest.java b/liberty-maven-plugin/src/it/compile-jsp-it/src/test/java/net/wasdev/wlp/maven/test/app/CompileJSPTest.java index 6382291a8..5a58a75d6 100644 --- a/liberty-maven-plugin/src/it/compile-jsp-it/src/test/java/net/wasdev/wlp/maven/test/app/CompileJSPTest.java +++ b/liberty-maven-plugin/src/it/compile-jsp-it/src/test/java/net/wasdev/wlp/maven/test/app/CompileJSPTest.java @@ -66,6 +66,17 @@ public void testXmlElements() throws Exception { Assert.assertTrue("ejbLite-3.2 found ==>", features.contains("ejbLite-3.2")); Assert.assertTrue("mongodb-2.0 found ==>", features.contains("mongodb-2.0")); Assert.assertTrue("jsp-2.3 found ==>", features.contains("jsp-2.3")); + + // parse input XML Document + String expression2 = "/server/jspEngine"; + nodes = (NodeList) xPath.compile(expression2).evaluate(inputDoc, XPathConstants.NODESET); + Assert.assertEquals("Number of elements ==>", 1, nodes.getLength()); + + if (nodes.item(0) instanceof Element) { + Element child = (Element) nodes.item(0); + String nodeValue = child.getAttribute("javaSourceLevel"); + Assert.assertTrue("Unexpected javaSourceLevel ==>"+nodeValue, nodeValue.equals("18")); + } } } } diff --git a/liberty-maven-plugin/src/it/compile-jsp-source-17-it/pom.xml b/liberty-maven-plugin/src/it/compile-jsp-source-17-it/pom.xml new file mode 100644 index 000000000..6c51e2fea --- /dev/null +++ b/liberty-maven-plugin/src/it/compile-jsp-source-17-it/pom.xml @@ -0,0 +1,185 @@ + + + 4.0.0 + + + io.openliberty.tools.it + tests + 1.0-SNAPSHOT + + + compile-jsp-source-17-it + war + + + + commons-logging + commons-logging + 1.0.4 + test + + + junit + junit + 4.13.1 + test + + + + + UTF-8 + UTF-8 + 17 + + + + + + + org.apache.maven.plugins + maven-war-plugin + 3.4.0 + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.1.2 + + + org.apache.maven.plugins + maven-surefire-plugin + 3.1.2 + + + + + + maven-war-plugin + + false + + + + io.openliberty.tools + liberty-maven-plugin + @pom.version@ + true + + true + test + src/test/resources/server.xml + project + false + + + + install-liberty + package + + install-server + + + + create-liberty-server + package + + create + + + + install-artifact + package + + deploy + + + true + + + + start-liberty-server + pre-integration-test + + install-feature + start + compile-jsp + + + + true + mongodb-2.0 + ejbLite-3.2 + + true + 40 + + + + check-liberty-server + pre-integration-test + + status + + + + stop-liberty-server + post-integration-test + + stop + + + + clean-server + post-integration-test + + clean + + + false + false + false + false + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + true + once + 300 + -enableassertions + ${project.build.directory} + + **/*CompileJSPTest.java + + + + + integration-test + + integration-test + + + + verify + verify + + verify + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + + diff --git a/liberty-maven-plugin/src/it/compile-jsp-source-17-it/src/test/java/net/wasdev/wlp/maven/test/app/CompileJSPTest.java b/liberty-maven-plugin/src/it/compile-jsp-source-17-it/src/test/java/net/wasdev/wlp/maven/test/app/CompileJSPTest.java new file mode 100644 index 000000000..048c15e13 --- /dev/null +++ b/liberty-maven-plugin/src/it/compile-jsp-source-17-it/src/test/java/net/wasdev/wlp/maven/test/app/CompileJSPTest.java @@ -0,0 +1,82 @@ +package net.wasdev.wlp.maven.test.app; + +import java.awt.List; +import java.util.ArrayList; +import java.io.File; +import java.io.FileInputStream; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathFactory; + +import org.junit.Assert; +import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; +import org.w3c.dom.Node; +import org.w3c.dom.Element; + + +/** + * + * Web application test case + * + */ + +public class CompileJSPTest { + + public final String COMPILE_JSP_SEVER_XML = "compileJsp/servers/defaultServer/server.xml"; + + @Test + public void testServerXMLPropFileExist() throws Exception { + File f = new File(COMPILE_JSP_SEVER_XML); + Assert.assertTrue(f.getCanonicalFile() + " doesn't exist", f.exists()); + } + + @Test + public void testXmlElements() throws Exception { + File in = new File(COMPILE_JSP_SEVER_XML); + try (FileInputStream input = new FileInputStream(in);) { + + // get input XML Document + DocumentBuilderFactory inputBuilderFactory = DocumentBuilderFactory.newInstance(); + inputBuilderFactory.setIgnoringComments(true); + inputBuilderFactory.setCoalescing(true); + inputBuilderFactory.setIgnoringElementContentWhitespace(true); + inputBuilderFactory.setValidating(false); + inputBuilderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); + inputBuilderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); + DocumentBuilder inputBuilder = inputBuilderFactory.newDocumentBuilder(); + Document inputDoc=inputBuilder.parse(input); + + // parse input XML Document + XPath xPath = XPathFactory.newInstance().newXPath(); + String expression = "/server/featureManager/feature[text()]"; + NodeList nodes = (NodeList) xPath.compile(expression).evaluate(inputDoc, XPathConstants.NODESET); + Assert.assertEquals("Number of elements ==>", 3, nodes.getLength()); + + ArrayList features = new ArrayList(); + + for(int i = 0; i < nodes.getLength(); i++) { + features.add(nodes.item(i).getTextContent().trim()); + } + + Assert.assertTrue("ejbLite-3.2 found ==>", features.contains("ejbLite-3.2")); + Assert.assertTrue("mongodb-2.0 found ==>", features.contains("mongodb-2.0")); + Assert.assertTrue("jsp-2.3 found ==>", features.contains("jsp-2.3")); + + // parse input XML Document + String expression2 = "/server/jspEngine"; + nodes = (NodeList) xPath.compile(expression2).evaluate(inputDoc, XPathConstants.NODESET); + Assert.assertEquals("Number of elements ==>", 1, nodes.getLength()); + + if (nodes.item(0) instanceof Element) { + Element child = (Element) nodes.item(0); + String nodeValue = child.getAttribute("javaSourceLevel"); + Assert.assertTrue("Unexpected javaSourceLevel ==>"+nodeValue, nodeValue.equals("17")); + } + } + } +} diff --git a/liberty-maven-plugin/src/it/compile-jsp-source-17-it/src/test/resources/server.xml b/liberty-maven-plugin/src/it/compile-jsp-source-17-it/src/test/resources/server.xml new file mode 100644 index 000000000..f3b493111 --- /dev/null +++ b/liberty-maven-plugin/src/it/compile-jsp-source-17-it/src/test/resources/server.xml @@ -0,0 +1,5 @@ + + + jsp-2.3 + + diff --git a/liberty-maven-plugin/src/it/compile-jsp-source-17-it/webapp/index.jsp b/liberty-maven-plugin/src/it/compile-jsp-source-17-it/webapp/index.jsp new file mode 100644 index 000000000..1153e9e08 --- /dev/null +++ b/liberty-maven-plugin/src/it/compile-jsp-source-17-it/webapp/index.jsp @@ -0,0 +1,10 @@ +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + Maven test install artifact + + +

Successful installation of war

+

Maven test war has been successfully installed into the server.

+ + diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/jsp/CompileJspMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/jsp/CompileJspMojo.java index 92c523d77..ae124fa61 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/jsp/CompileJspMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/jsp/CompileJspMojo.java @@ -18,6 +18,7 @@ import java.io.File; import java.text.MessageFormat; import java.util.List; +import java.util.Properties; import java.util.Set; import java.util.TreeSet; @@ -83,15 +84,28 @@ private void doCompileJsps() throws MojoExecutionException { // don't delete temporary server dir compile.setCleanup(false); + boolean sourceSet = false; + List plugins = getProject().getBuildPlugins(); for (Plugin plugin : plugins) { if ("org.apache.maven.plugins:maven-compiler-plugin".equals(plugin.getKey())) { Object config = plugin.getConfiguration(); if (config instanceof Xpp3Dom) { Xpp3Dom dom = (Xpp3Dom) config; - Xpp3Dom val = dom.getChild("source"); - if (val != null) { - compile.setSource(val.getValue()); + Xpp3Dom child = dom.getChild("release"); + if (child != null && child.getValue() != null) { + String value = child.getValue(); + getLog().debug("compile-jsp using maven.compiler.release value: "+value+" for javaSourceLevel."); + compile.setSource(value); + sourceSet = true; + } else { + child = dom.getChild("source"); + if (child != null && child.getValue() != null) { + String value = child.getValue(); + getLog().debug("compile-jsp using maven.compiler.source value: "+value+" for javaSourceLevel."); + compile.setSource(value); + sourceSet = true; + } } } break; @@ -107,6 +121,26 @@ private void doCompileJsps() throws MojoExecutionException { } } + if (!sourceSet) { + // look for Maven properties + Properties props = getProject().getProperties(); + if (props.containsKey("maven.compiler.release")) { + String value = props.getProperty("maven.compiler.release"); + if (value != null) { + getLog().debug("compile-jsp using maven.compiler.release value: "+value+" for javaSourceLevel."); + compile.setSource(value); + sourceSet = true; + } + } else if (props.containsKey("maven.compiler.source")) { + String value = props.getProperty("maven.compiler.release"); + if (value != null) { + getLog().debug("compile-jsp using maven.compiler.source value: "+value+" for javaSourceLevel."); + compile.setSource(value); + sourceSet = true; + } + } + } + Set classpath = new TreeSet(); // first add target/classes (or whatever is configured) From b99426cb1dee3c0b1673845709923f0d7b4746bf Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Fri, 3 May 2024 20:15:04 -0500 Subject: [PATCH 2/5] Fix typo in property name --- .../java/io/openliberty/tools/maven/jsp/CompileJspMojo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/jsp/CompileJspMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/jsp/CompileJspMojo.java index ae124fa61..1db2b1237 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/jsp/CompileJspMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/jsp/CompileJspMojo.java @@ -132,7 +132,7 @@ private void doCompileJsps() throws MojoExecutionException { sourceSet = true; } } else if (props.containsKey("maven.compiler.source")) { - String value = props.getProperty("maven.compiler.release"); + String value = props.getProperty("maven.compiler.source"); if (value != null) { getLog().debug("compile-jsp using maven.compiler.source value: "+value+" for javaSourceLevel."); compile.setSource(value); From d840084e3487c9e9ca9a69aeb5de6193abbf30f2 Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Sat, 4 May 2024 11:21:12 -0500 Subject: [PATCH 3/5] Fix test case --- liberty-maven-plugin/src/it/compile-jsp-it/pom.xml | 2 +- .../test/java/net/wasdev/wlp/maven/test/app/CompileJSPTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/liberty-maven-plugin/src/it/compile-jsp-it/pom.xml b/liberty-maven-plugin/src/it/compile-jsp-it/pom.xml index 67888838c..51c1498c1 100644 --- a/liberty-maven-plugin/src/it/compile-jsp-it/pom.xml +++ b/liberty-maven-plugin/src/it/compile-jsp-it/pom.xml @@ -30,7 +30,7 @@ UTF-8 UTF-8 - 8 + 1.8 diff --git a/liberty-maven-plugin/src/it/compile-jsp-it/src/test/java/net/wasdev/wlp/maven/test/app/CompileJSPTest.java b/liberty-maven-plugin/src/it/compile-jsp-it/src/test/java/net/wasdev/wlp/maven/test/app/CompileJSPTest.java index 5a58a75d6..1286ac59c 100644 --- a/liberty-maven-plugin/src/it/compile-jsp-it/src/test/java/net/wasdev/wlp/maven/test/app/CompileJSPTest.java +++ b/liberty-maven-plugin/src/it/compile-jsp-it/src/test/java/net/wasdev/wlp/maven/test/app/CompileJSPTest.java @@ -75,7 +75,7 @@ public void testXmlElements() throws Exception { if (nodes.item(0) instanceof Element) { Element child = (Element) nodes.item(0); String nodeValue = child.getAttribute("javaSourceLevel"); - Assert.assertTrue("Unexpected javaSourceLevel ==>"+nodeValue, nodeValue.equals("18")); + Assert.assertTrue("Unexpected javaSourceLevel ==>"+nodeValue, nodeValue.equals("8")); } } } From 2f456f16f2f40aa451a0727b3bb7e95dfb624bc0 Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Sat, 4 May 2024 13:38:32 -0500 Subject: [PATCH 4/5] Update to recent Liberty version for testing --- .github/workflows/maven.yml | 4 ++-- liberty-maven-plugin/src/it/compile-jsp-it/pom.xml | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 11a0bb794..c43980d35 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -22,7 +22,7 @@ jobs: matrix: # test against latest update of each major Java version, as well as specific updates of LTS versions: RUNTIME: [ol, wlp] - RUNTIME_VERSION: [23.0.0.12] + RUNTIME_VERSION: [24.0.0.3] java: [21, 17, 11, 8] exclude: - java: 8 @@ -81,7 +81,7 @@ jobs: matrix: # test against latest update of each major Java version, as well as specific updates of LTS versions: RUNTIME: [ol, wlp] - RUNTIME_VERSION: [23.0.0.12] + RUNTIME_VERSION: [24.0.0.3] java: [21, 17, 11, 8] exclude: - java: 8 diff --git a/liberty-maven-plugin/src/it/compile-jsp-it/pom.xml b/liberty-maven-plugin/src/it/compile-jsp-it/pom.xml index 51c1498c1..3013e844b 100644 --- a/liberty-maven-plugin/src/it/compile-jsp-it/pom.xml +++ b/liberty-maven-plugin/src/it/compile-jsp-it/pom.xml @@ -28,8 +28,6 @@ - UTF-8 - UTF-8 1.8 From 9a238c4f0268bc380f45d35ab08e1dcbab2cda28 Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Mon, 6 May 2024 15:03:57 -0500 Subject: [PATCH 5/5] Undo yaml changes for specific 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 c43980d35..ee3ae9504 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -53,8 +53,7 @@ jobs: - name: Checkout ci.ant uses: actions/checkout@v3 with: - repository: cherylking/ci.ant - ref: updateCompileJsp + repository: OpenLiberty/ci.ant path: ci.ant - name: Set up Maven uses: stCarolas/setup-maven@v4.5 @@ -104,7 +103,7 @@ jobs: 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.ant.git --branch updateCompileJsp --single-branch C:/ci.ant + git clone https://github.com/OpenLiberty/ci.ant.git C:/ci.ant - name: Set up Maven uses: stCarolas/setup-maven@v4.5 with: