diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c6edf522..5276c681 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,13 +18,13 @@ jobs: matrix: # test against latest update of each major Java version, as well as specific updates of LTS versions: os: [ubuntu-latest, windows-latest] - WLP_VERSION: [23.0.0_12] + WLP_VERSION: [24.0.0_03] java: [21, 17, 11, 8] include: # match up licenses to WLP versions # http://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/downloads/wlp/index.yml - - WLP_VERSION: 23.0.0_12 - WLP_LICENSE: L-FBWC-95ADJK + - WLP_VERSION: 24.0.0_03 + WLP_LICENSE: L-KZJT-27HQXL runs-on: ${{ matrix.os }} name: WL ${{ matrix.WLP_VERSION }}, Java ${{ matrix.java }}, ${{ matrix.os }} diff --git a/src/main/java/io/openliberty/tools/ant/jsp/CompileJSPs.java b/src/main/java/io/openliberty/tools/ant/jsp/CompileJSPs.java index e5a293ea..46166099 100644 --- a/src/main/java/io/openliberty/tools/ant/jsp/CompileJSPs.java +++ b/src/main/java/io/openliberty/tools/ant/jsp/CompileJSPs.java @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corporation 2014, 2020. + * (C) Copyright IBM Corporation 2014, 2024. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Properties; import java.util.Set; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -59,6 +60,7 @@ public class CompileJSPs extends Task { private String classpath = ""; private String classpathRef; private String source; + private boolean useJdkSourceLevel = false; // By default allow 30 seconds to compile the jsps private int timeout = 30; @@ -365,7 +367,54 @@ private ServerTask createServerTask(File usrDir) { return server; } + private boolean isVersion24xxOrLater(String version) { + boolean flag = false; + + if (version != null && version.contains(".")) { + String majorVersion = version.substring(0,version.indexOf(".")); + try { + Integer majorVersionInt = new Integer(majorVersion); + if (majorVersionInt.intValue() >= 24) { + flag = true; + } + } catch (NumberFormatException e) { + } + } + + return flag; + } + + private String determineSourceAttribute(File serverDir) { + String sourceAttrToUse = "jdkSourceLevel"; + File f = new File(wlpHome,"lib/versions/openliberty.properties"); + + if (f.exists()) { + try (FileInputStream input = new FileInputStream(f);) { + Properties libertyProductProperties = new Properties(); + + libertyProductProperties.load(input); + String version = libertyProductProperties.getProperty("com.ibm.websphere.productVersion"); + if (isVersion24xxOrLater(version)) { + if (useJdkSourceLevel && source.equals("18")) { + // change source 18 to 8 and use javaSourceLevel instead + source = "8"; + useJdkSourceLevel = false; + sourceAttrToUse = "javaSourceLevel"; + } else if (!useJdkSourceLevel) { + sourceAttrToUse = "javaSourceLevel"; + } + } + } catch (IOException e) { + } + } + return sourceAttrToUse; + } + private void writeServerXML(File serverDir) throws FileNotFoundException { + // Need to determine the version of Liberty installed. For versions prior to 24.0.0.1, use the jdkSourceLevel attribute + // on the jspEngine element. For versions 24.0.0.1 and later, use the javaSourceLevel attribute. + String sourceAttribute = determineSourceAttribute(serverDir); + PrintStream ps = new PrintStream(new File(serverDir, "server.xml")); ps.println(""); ps.println(""); @@ -384,7 +433,7 @@ private void writeServerXML(File serverDir) throws FileNotFoundException { ps.println(""); } ps.println(""); - ps.print(""); + ps.println(""); ps.println(""); ps.println(""); ps.println(""); @@ -489,6 +538,8 @@ public void setClasspathRef(String classpathRef) { } public void setSource(String src) { + useJdkSourceLevel = false; + source = null; if ("1.3".equals(src)) { source = "13"; } else if ("1.4".equals(src)) { @@ -502,6 +553,12 @@ public void setSource(String src) { } else if ("1.8".equals(src) || "8".equals(src)) { source = "18"; } + + if (source != null) { + useJdkSourceLevel = true; + } else { // for Java 11 and beyond + source = src; + } } public void setTimeout(int timeout) {