Skip to content

Commit

Permalink
Merge pull request #39 from kaido207/38
Browse files Browse the repository at this point in the history
Fix #38 JSPC compile fails on JDK11 without compilerSourceVM and compilerTargetVM options.
  • Loading branch information
arjantijms authored May 9, 2022
2 parents c61c91e + e569c34 commit 18445b1
Showing 1 changed file with 36 additions and 39 deletions.
75 changes: 36 additions & 39 deletions src/main/java/org/glassfish/wasp/JspC.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (c) 2022, 2022 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright 2004 The Apache Software Foundation
* Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -97,20 +98,6 @@
*/
public class JspC implements Options {

private static final String JAVA_1_1 = "1.1";
private static final String JAVA_1_2 = "1.2";
private static final String JAVA_1_3 = "1.3";
private static final String JAVA_1_4 = "1.4";
private static final String JAVA_1_5 = "1.5";
private static final String JAVA_1_6 = "1.6";
private static final String JAVA_1_7 = "1.7";
private static final String JAVA_1_8 = "1.8";
private static final String JAVA_5 = "5";
private static final String JAVA_6 = "6";
private static final String JAVA_7 = "7";
private static final String JAVA_8 = "8";
// END SJSAS 6402545

// Logger
private static Logger log = Logger.getLogger(JspC.class.getName());

Expand Down Expand Up @@ -154,6 +141,8 @@ public class JspC implements Options {
"<error-page>", "<taglib>", "<resource-env-ref>", "<resource-ref>", "<security-constraint>", "<login-config>", "<security-role>", "<env-entry>",
"<ejb-ref>", "<ejb-local-ref>" };

private static final String runtimeJavaVersion = System.getProperty("java.specification.version");

private int dieLevel;
private String classPath;
private String sysClassPath;
Expand All @@ -177,8 +166,8 @@ public class JspC implements Options {

private String compiler;

private String compilerTargetVM = JAVA_1_5;
private String compilerSourceVM = JAVA_1_5;
private String compilerTargetVM = runtimeJavaVersion;
private String compilerSourceVM = runtimeJavaVersion;

private boolean classDebugInfo = true;

Expand Down Expand Up @@ -592,28 +581,21 @@ public String getCompilerTargetVM() {
}

public void setCompilerTargetVM(String vm) {
// START SJSAS 6402545
String tvm = vm;
if (JAVA_5.equals(vm)) {
vm = JAVA_1_5;
} else if (JAVA_6.equals(vm)) {
vm = JAVA_1_6;
} else if (JAVA_7.equals(vm)) {
vm = JAVA_1_7;
} else if (JAVA_8.equals(vm)) {
vm = JAVA_1_8;
}
if (!JAVA_1_1.equals(vm) && !JAVA_1_2.equals(vm) && !JAVA_1_3.equals(vm) && !JAVA_1_4.equals(vm) && !JAVA_1_5.equals(vm) && !JAVA_1_6.equals(vm)
&& !JAVA_1_7.equals(vm) && !JAVA_1_8.equals(vm)) {
throw new IllegalArgumentException(Localizer.getMessage("jspc.illegalCompilerTargetVM", tvm));
int version = getJVMMajorVersion(vm);

if (version == -1) {
throw new IllegalArgumentException(Localizer.getMessage("jspc.illegalCompilerTargetVM", vm));
}
// END SJSAS 6402545
// START SJSAS 6403017
Double targetVersion = Double.valueOf(vm);
if (targetVersion.compareTo(Double.valueOf(myJavaVersion)) > 0) {
if (version > getJVMMajorVersion(runtimeJavaVersion)) {
throw new IllegalArgumentException(Localizer.getMessage("jspc.compilerTargetVMTooHigh", vm));
}
// END SJSAS 6403017

if (version <= 8) {
vm = "1." + Integer.toString(version);
} else {
vm = Integer.toString(version);
}

compilerTargetVM = vm;
}

Expand All @@ -629,15 +611,30 @@ public String getCompilerSourceVM() {
* @see Options#getCompilerSourceVM
*/
public void setCompilerSourceVM(String vm) {
// START SJSAS 6402545
if (!JAVA_1_3.equals(vm) && !JAVA_1_4.equals(vm) && !JAVA_1_5.equals(vm) && !JAVA_5.equals(vm) && !JAVA_1_6.equals(vm) && !JAVA_6.equals(vm)
&& !JAVA_1_7.equals(vm) && !JAVA_7.equals(vm) && !JAVA_1_8.equals(vm) && !JAVA_8.equals(vm)) {
int version = getJVMMajorVersion(vm);
if (version == -1) {
throw new IllegalArgumentException(Localizer.getMessage("jspc.illegalCompilerSourceVM", vm));
}
// END SJSAS 6402545

if (version <= 8) {
vm = "1." + Integer.toString(version);
} else {
vm = Integer.toString(version);
}

compilerSourceVM = vm;
}

private int getJVMMajorVersion(String vm) {
if (vm.matches("1\\.[0-9]|1\\.10")) {
return Integer.parseInt(vm.substring(2));
}
if (vm.matches("[1-9][0-9]*")) {
return Integer.parseInt(vm);
}
return -1;
}

/**
* @see Options#getCompilerClassName
*/
Expand Down

0 comments on commit 18445b1

Please # to comment.