-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix compileJSP task to work with later versions of Java
- Loading branch information
1 parent
9660bc4
commit e46c3b4
Showing
7 changed files
with
257 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
src/test/groovy/io/openliberty/tools/gradle/TestCompileJSPSource17.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package io.openliberty.tools.gradle; | ||
|
||
import org.junit.AfterClass | ||
import org.junit.BeforeClass | ||
import org.junit.Test | ||
|
||
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.BeforeClass | ||
import org.junit.FixMethodOrder | ||
import org.junit.Test | ||
import org.junit.runners.MethodSorters | ||
import org.junit.Assert; | ||
import org.w3c.dom.Document; | ||
import org.w3c.dom.NodeList; | ||
import org.w3c.dom.Node; | ||
import org.w3c.dom.Element; | ||
|
||
@FixMethodOrder(MethodSorters.NAME_ASCENDING) | ||
public class TestCompileJSPSource17 extends AbstractIntegrationTest{ | ||
static File resourceDir = new File("build/resources/test/sampleJSP.servlet") | ||
static File buildDir = new File(integTestDir, "/test-compile-jsp-source-17") | ||
static String buildFilename = "testCompileJSP17.gradle" | ||
|
||
@BeforeClass | ||
public static void setup() { | ||
createDir(buildDir) | ||
createTestProject(buildDir, resourceDir, buildFilename) | ||
runTasks(buildDir, 'installFeature') | ||
runTasks(buildDir, 'compileJsp') | ||
} | ||
|
||
@Test | ||
public void check_for_jsp() { | ||
assert new File('build/testBuilds/test-compile-jsp-source-17/src/main/webapp/index.jsp').exists() : 'index.jsp not found!' | ||
} | ||
|
||
@Test | ||
public void test_1() { | ||
|
||
assert new File('build/testBuilds/test-compile-jsp-source-17/build/compileJsp').exists() : 'compileJsp Directory not found!' | ||
} | ||
|
||
@Test | ||
public void test_2() { | ||
assert new File('build/testBuilds/test-compile-jsp-source-17/build/classes/java/_index.class').exists() : '_index.class not found!' | ||
} | ||
|
||
@Test | ||
public void check_jsp_server_xml_exists() { | ||
assert new File('build/testBuilds/test-compile-jsp-source-17/build/compileJsp/servers/defaultServer/server.xml').exists() : 'server.xml not found!' | ||
} | ||
|
||
@Test | ||
public void check_jsp_server_xml_contains_features() { | ||
File serverXml = new File("build/testBuilds/test-compile-jsp-source-17/build/compileJsp/servers/defaultServer/server.xml") | ||
FileInputStream input = new FileInputStream(serverXml) | ||
|
||
// 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 ==>", 2, 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("servlet-3.1 <feature/> found ==>", features.contains("servlet-3.1")) | ||
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")) | ||
} | ||
} | ||
|
||
|
||
} |
98 changes: 98 additions & 0 deletions
98
src/test/resources/sampleJSP.servlet/testCompileJSP17.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
This test checks whether the compileJsp task was able to compile the index.jsp file from the test | ||
project | ||
*/ | ||
group = 'liberty.gradle' | ||
|
||
buildscript { | ||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
maven { | ||
name = 'Sonatype Nexus Snapshots' | ||
url = 'https://oss.sonatype.org/content/repositories/snapshots/' | ||
} | ||
} | ||
dependencies { | ||
classpath "io.openliberty.tools:liberty-gradle-plugin:$lgpVersion" | ||
} | ||
} | ||
|
||
apply plugin: 'war' | ||
apply plugin: 'liberty' | ||
|
||
compileJava.options.release = 17 | ||
|
||
compileJava.options.encoding = 'UTF-8' | ||
|
||
ext { | ||
// Liberty server properties | ||
wlpServerName = 'LibertyProjectServer' | ||
serverDirectory = "${project.buildDir}/wlp/usr/servers/${wlpServerName}" | ||
testServerHttpPort = 9080 | ||
testServerHttpsPort = 9443 | ||
|
||
// This is set in the ibm-web-ext.xml file | ||
warContext = 'sampleJSP.servlet' | ||
|
||
} | ||
|
||
liberty { | ||
server{ | ||
serverXmlFile = file("src/resources/server.xml") | ||
name = 'LibertyProjectServer' | ||
deploy { | ||
apps = [war] | ||
} | ||
looseApplication = false | ||
stripVersion = true | ||
} | ||
jsp { | ||
jspCompileTimeout = 35 | ||
} | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
testImplementation group: 'commons-logging', name: 'commons-logging', version:'1.0.4' | ||
testImplementation group: 'junit', name: 'junit', version:'4.13.1' | ||
providedCompile group: 'org.apache.geronimo.specs', name: 'geronimo-servlet_3.0_spec', version:'1.0' | ||
testImplementation 'junit:junit:4.13.1' | ||
providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version:'3.1.0' | ||
libertyRuntime group: runtimeGroup, name: runtimeArtifactId, version: runtimeVersion | ||
} | ||
|
||
test { | ||
println 'inside the test block' | ||
reports.html.outputLocation = file("$buildDir/reports/unit") | ||
reports.junitXml.outputLocation = file("$buildDir/test-results/unit") | ||
exclude '**/it/**' | ||
} | ||
|
||
|
||
task integrationTest(type: Test) { | ||
group 'Verification' | ||
description 'Runs the integration tests.' | ||
reports.html.outputLocation = file("$buildDir/reports/it") | ||
reports.junitXml.outputLocation = file("$buildDir/test-results/it") | ||
include '**/it/**' | ||
exclude '**/unit/**' | ||
|
||
systemProperties = ['liberty.test.port': testServerHttpPort, 'war.name': warContext] | ||
} | ||
|
||
task printMessageAboutRunningServer { | ||
doLast { | ||
println "The server is now running at http://localhost:${testServerHttpPort}/${warContext}" | ||
println "To stop the server run 'gradle libertyStop'" | ||
} | ||
} | ||
|
||
deploy.dependsOn 'war' | ||
war.dependsOn 'compileJSP' | ||
integrationTest.dependsOn 'libertyStart', 'testClasses' | ||
integrationTest.finalizedBy 'libertyStop' | ||
libertyStart.finalizedBy 'printMessageAboutRunningServer' |