Skip to content

Commit

Permalink
Handle Java source versions other than 8 for compile-jsp
Browse files Browse the repository at this point in the history
  • Loading branch information
cherylking committed May 3, 2024
1 parent 9b96fb6 commit a5ab4ac
Show file tree
Hide file tree
Showing 9 changed files with 348 additions and 10 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
Expand All @@ -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 }}"
Expand Down Expand Up @@ -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/[email protected]
with:
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion liberty-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<dependency>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-ant-tasks</artifactId>
<version>1.9.14</version>
<version>1.9.15-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
Expand Down Expand Up @@ -225,6 +225,7 @@
<pomExclude>binary-scanner-it/pom.xml</pomExclude>
<pomExclude>springboot-3-tests/pom.xml</pomExclude>
<pomExclude>dev-container-it/pom.xml</pomExclude>
<pomExclude>compile-jsp-source-17-it/pom.xml</pomExclude>
</pomExcludes>
</configuration>
</plugin>
Expand Down Expand Up @@ -266,6 +267,7 @@
<pomExclude>binary-scanner-it/pom.xml</pomExclude>
<pomExclude>springboot-3-tests/pom.xml</pomExclude>
<pomExclude>dev-container-it/pom.xml</pomExclude>
<pomExclude>compile-jsp-source-17-it/pom.xml</pomExclude>
</pomExcludes>
</configuration>
</plugin>
Expand Down Expand Up @@ -306,6 +308,7 @@
<pomExclude>generate-features-it/pom.xml</pomExclude>
<pomExclude>binary-scanner-it/pom.xml</pomExclude>
<pomExclude>springboot-3-tests/pom.xml</pomExclude>
<pomExclude>compile-jsp-source-17-it/pom.xml</pomExclude>
</pomExcludes>
</configuration>
</plugin>
Expand Down Expand Up @@ -351,6 +354,7 @@
<pomExclude>generate-features-it/pom.xml</pomExclude>
<pomExclude>binary-scanner-it/pom.xml</pomExclude>
<pomExclude>springboot-3-tests/pom.xml</pomExclude>
<pomExclude>compile-jsp-source-17-it/pom.xml</pomExclude>
</pomExcludes>
</configuration>
</plugin>
Expand Down
10 changes: 8 additions & 2 deletions liberty-maven-plugin/src/it/compile-jsp-it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
</dependency>
</dependencies>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.release>8</maven.compiler.release>
</properties>

<build>
<pluginManagement>
<plugins>
Expand Down Expand Up @@ -130,8 +136,8 @@
<goal>clean</goal>
</goals>
<configuration>
<cleanDropins>true</cleanDropins>
<cleanApps>true</cleanApps>
<cleanDropins>false</cleanDropins>
<cleanApps>false</cleanApps>
<cleanLogs>false</cleanLogs>
<cleanWorkarea>false</cleanWorkarea>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ public void testXmlElements() throws Exception {
Assert.assertTrue("ejbLite-3.2 <feature/> found ==>", features.contains("ejbLite-3.2"));
Assert.assertTrue("mongodb-2.0 <feature/> found ==>", features.contains("mongodb-2.0"));
Assert.assertTrue("jsp-2.3 <feature/> 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 <jspEngine/> 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"));
}
}
}
}
185 changes: 185 additions & 0 deletions liberty-maven-plugin/src/it/compile-jsp-source-17-it/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.openliberty.tools.it</groupId>
<artifactId>tests</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>compile-jsp-source-17-it</artifactId>
<packaging>war</packaging>

<dependencies>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.release>17</maven.compiler.release>
</properties>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.4.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>@pom.version@</version>
<extensions>true</extensions>
<configuration>
<stripVersion>true</stripVersion>
<serverName>test</serverName>
<serverXmlFile>src/test/resources/server.xml</serverXmlFile>
<deployPackages>project</deployPackages>
<looseApplication>false</looseApplication>
</configuration>
<executions>
<execution>
<id>install-liberty</id>
<phase>package</phase>
<goals>
<goal>install-server</goal>
</goals>
</execution>
<execution>
<id>create-liberty-server</id>
<phase>package</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
<execution>
<id>install-artifact</id>
<phase>package</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<stripVersion>true</stripVersion>
</configuration>
</execution>
<execution>
<id>start-liberty-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>install-feature</goal>
<goal>start</goal>
<goal>compile-jsp</goal>
</goals>
<configuration>
<features>
<acceptLicense>true</acceptLicense>
<feature>mongodb-2.0</feature>
<feature>ejbLite-3.2</feature>
</features>
<background>true</background>
<verifyTimeout>40</verifyTimeout>
</configuration>
</execution>
<execution>
<id>check-liberty-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>status</goal>
</goals>
</execution>
<execution>
<id>stop-liberty-server</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
<execution>
<id>clean-server</id>
<phase>post-integration-test</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<cleanDropins>false</cleanDropins>
<cleanApps>false</cleanApps>
<cleanLogs>false</cleanLogs>
<cleanWorkarea>false</cleanWorkarea>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<forkMode>once</forkMode>
<forkedProcessTimeoutInSeconds>300</forkedProcessTimeoutInSeconds>
<argLine>-enableassertions</argLine>
<workingDirectory>${project.build.directory}</workingDirectory>
<includes>
<include>**/*CompileJSPTest.java</include>
</includes>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<phase>verify</phase>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -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 <feature/> elements ==>", 3, nodes.getLength());

ArrayList<String> features = new ArrayList<String>();

for(int i = 0; i < nodes.getLength(); i++) {
features.add(nodes.item(i).getTextContent().trim());
}

Assert.assertTrue("ejbLite-3.2 <feature/> found ==>", features.contains("ejbLite-3.2"));
Assert.assertTrue("mongodb-2.0 <feature/> found ==>", features.contains("mongodb-2.0"));
Assert.assertTrue("jsp-2.3 <feature/> 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 <jspEngine/> 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"));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<server description="default server">
<featureManager>
<feature>jsp-2.3</feature>
</featureManager>
</server>
Loading

0 comments on commit a5ab4ac

Please sign in to comment.