From b0b97f281590af3636620e08ea0daa45e198b216 Mon Sep 17 00:00:00 2001 From: Gaurav Gupta Date: Thu, 3 Jan 2019 16:37:18 +0530 Subject: [PATCH] NetBeans plugin JDK 11 support --- .../util/logging/resources/logging.properties | 46 +++++++++++++++++++ payara.tooling/nbproject/project.xml | 9 ++++ .../payara/tooling/data/StartupArgs.java | 5 +- .../tooling/data/StartupArgsEntity.java | 31 ++++++++++++- .../modules/payara/tooling/server/JDK.java | 16 ++++--- .../payara/tooling/server/ServerTasks.java | 8 +++- 6 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 payara.common/src/sun/util/logging/resources/logging.properties diff --git a/payara.common/src/sun/util/logging/resources/logging.properties b/payara.common/src/sun/util/logging/resources/logging.properties new file mode 100644 index 0000000..1e8d446 --- /dev/null +++ b/payara.common/src/sun/util/logging/resources/logging.properties @@ -0,0 +1,46 @@ +# +# Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# This code is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 only, as +# published by the Free Software Foundation. Oracle designates this +# particular file as subject to the "Classpath" exception as provided +# by Oracle in the LICENSE file that accompanied this code. +# +# This code is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# version 2 for more details (a copy is included in the LICENSE file that +# accompanied this code). +# +# You should have received a copy of the GNU General Public License version +# 2 along with this work; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA +# or visit www.oracle.com if you need additional information or have any +# questions. +# + +# Localizations for Level names. For the US locale +# these are the same as the non-localized level name. + +# The following ALL CAPS words should be translated. +ALL=All +# The following ALL CAPS words should be translated. +SEVERE=Severe +# The following ALL CAPS words should be translated. +WARNING=Warning +# The following ALL CAPS words should be translated. +INFO=Info +# The following ALL CAPS words should be translated. +CONFIG= Config +# The following ALL CAPS words should be translated. +FINE=Fine +# The following ALL CAPS words should be translated. +FINER=Finer +# The following ALL CAPS words should be translated. +FINEST=Finest +# The following ALL CAPS words should be translated. +OFF=Off diff --git a/payara.tooling/nbproject/project.xml b/payara.tooling/nbproject/project.xml index a0b9663..2f30bbf 100644 --- a/payara.tooling/nbproject/project.xml +++ b/payara.tooling/nbproject/project.xml @@ -24,6 +24,15 @@ 0.10 + + org.netbeans.modules.xml.jaxb.api + + + + 1 + 1.29.1 + + org.openide.util diff --git a/payara.tooling/src/org/netbeans/modules/payara/tooling/data/StartupArgs.java b/payara.tooling/src/org/netbeans/modules/payara/tooling/data/StartupArgs.java index 1da1ac4..3fd10ff 100644 --- a/payara.tooling/src/org/netbeans/modules/payara/tooling/data/StartupArgs.java +++ b/payara.tooling/src/org/netbeans/modules/payara/tooling/data/StartupArgs.java @@ -37,12 +37,13 @@ * * Contributor(s): */ -// Portions Copyright [2017] [Payara Foundation and/or its affiliates] +// Portions Copyright [2017-2019] [Payara Foundation and/or its affiliates] package org.netbeans.modules.payara.tooling.data; import java.util.List; import java.util.Map; +import org.netbeans.modules.payara.tooling.server.JDK.Version; /** * This interface provides IDE and user specific arguments for starting the server. @@ -59,4 +60,6 @@ public interface StartupArgs { public String getJavaHome(); + public Version getJavaVersion(); + } diff --git a/payara.tooling/src/org/netbeans/modules/payara/tooling/data/StartupArgsEntity.java b/payara.tooling/src/org/netbeans/modules/payara/tooling/data/StartupArgsEntity.java index ac0e270..460ec77 100644 --- a/payara.tooling/src/org/netbeans/modules/payara/tooling/data/StartupArgsEntity.java +++ b/payara.tooling/src/org/netbeans/modules/payara/tooling/data/StartupArgsEntity.java @@ -37,12 +37,19 @@ * * Contributor(s): */ -// Portions Copyright [2017] [Payara Foundation and/or its affiliates] +// Portions Copyright [2017-2019] [Payara Foundation and/or its affiliates] package org.netbeans.modules.payara.tooling.data; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; import java.util.List; import java.util.Map; +import org.netbeans.modules.payara.tooling.server.JDK; +import org.netbeans.modules.payara.tooling.server.JDK.Version; +import org.openide.util.Exceptions; /** * Payara Server Entity. @@ -69,6 +76,9 @@ public class StartupArgsEntity implements StartupArgs { /** Installation home of Java SDK used to run Payara. */ private String javaHome; + /** Version of Java SDK used to run Payara. */ + private Version javaVersion; + //////////////////////////////////////////////////////////////////////////// // Constructors // //////////////////////////////////////////////////////////////////////////// @@ -176,4 +186,23 @@ public void getJavaHome(String javaHome) { this.javaHome = javaHome; } + /** + * Get version of Java SDK used to run Payara. + *

+ * @return version of Java SDK used to run Payara. + */ + @Override + public Version getJavaVersion() { + if(javaVersion == null && javaHome != null) { + try (BufferedReader bufferedReader + = new BufferedReader(new FileReader(new File(javaHome, "release")));) { + String version = bufferedReader.readLine(); + javaVersion = JDK.getVersion(version.substring(version.indexOf("\"") + 1, version.lastIndexOf("\""))); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + return javaVersion; + } + } diff --git a/payara.tooling/src/org/netbeans/modules/payara/tooling/server/JDK.java b/payara.tooling/src/org/netbeans/modules/payara/tooling/server/JDK.java index be17ef5..9574fc2 100644 --- a/payara.tooling/src/org/netbeans/modules/payara/tooling/server/JDK.java +++ b/payara.tooling/src/org/netbeans/modules/payara/tooling/server/JDK.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2018] [Payara Foundation and/or its affiliates] +// Portions Copyright [2018-2019] [Payara Foundation and/or its affiliates] package org.netbeans.modules.payara.tooling.server; @@ -239,17 +239,21 @@ public static Version getVersion() { return new Version(); } - public static boolean isCorrectJDK(Optional minVersion, Optional maxVersion) { + public static boolean isCorrectJDK(Version jdkVersion, Optional minVersion, Optional maxVersion) { boolean correctJDK = true; if (minVersion.isPresent()) { - correctJDK = JDK_VERSION.newerOrEquals(minVersion.get()); + correctJDK = jdkVersion.newerOrEquals(minVersion.get()); } if (correctJDK && maxVersion.isPresent()) { - correctJDK = JDK_VERSION.olderOrEquals(maxVersion.get()); + correctJDK = jdkVersion.olderOrEquals(maxVersion.get()); } return correctJDK; } + public static boolean isCorrectJDK(Optional minVersion, Optional maxVersion) { + return isCorrectJDK(IDE_JDK_VERSION, minVersion, maxVersion); + } + /** * No instances are allowed so it is pointless to override toString * @return Parsed version numbers @@ -271,7 +275,7 @@ public static String toStringStatic() { private static int minor; private static int subminor; private static int update; - private static Version JDK_VERSION; + public static Version IDE_JDK_VERSION; // silently fall back to ridiculous defaults if something is crazily wrong... private static void initialize() { @@ -337,6 +341,6 @@ private static void initialize() { // ignore -- use defaults } - JDK_VERSION = new Version(); + IDE_JDK_VERSION = new Version(); } } diff --git a/payara.tooling/src/org/netbeans/modules/payara/tooling/server/ServerTasks.java b/payara.tooling/src/org/netbeans/modules/payara/tooling/server/ServerTasks.java index e42c352..624f2e7 100644 --- a/payara.tooling/src/org/netbeans/modules/payara/tooling/server/ServerTasks.java +++ b/payara.tooling/src/org/netbeans/modules/payara/tooling/server/ServerTasks.java @@ -37,7 +37,7 @@ * * Contributor(s): */ -// Portions Copyright [2017-2018] [Payara Foundation and/or its affiliates] +// Portions Copyright [2017-2019] [Payara Foundation and/or its affiliates] package org.netbeans.modules.payara.tooling.server; @@ -61,6 +61,8 @@ import org.netbeans.modules.payara.tooling.utils.ServerUtils; import org.netbeans.modules.payara.tooling.utils.Utils; import org.netbeans.modules.payara.tooling.data.PayaraServer; +import static org.netbeans.modules.payara.tooling.server.JDK.IDE_JDK_VERSION; +import org.netbeans.modules.payara.tooling.server.JDK.Version; import org.netbeans.modules.payara.tooling.server.parser.JvmConfigReader.JvmOption; /** @@ -184,10 +186,12 @@ public static ResultProcess startServer(PayaraServer server, METHOD, "readXMLerror"), domainXmlPath); } } + + Version javaVersion = args.getJavaVersion() != null ? args.getJavaVersion() : IDE_JDK_VERSION; List optList = jvmConfigReader.getJvmOptions() .stream() - .filter(fullOption -> JDK.isCorrectJDK(fullOption.minVersion, fullOption.maxVersion)) + .filter(fullOption -> JDK.isCorrectJDK(javaVersion, fullOption.minVersion, fullOption.maxVersion)) .map(fullOption -> fullOption.option) .collect(toList());