From 4ddd1a1a8c7ced537fdb470113e520b37a033a2c Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 22 Oct 2020 12:20:58 -0500 Subject: [PATCH 1/4] Issue #5492 - Adding java.features.* start properties + Simplifying alpn start modules in the process. (from 11 to 3) Signed-off-by: Joakim Erdfelt --- .../src/main/config/modules/alpn-impl.mod | 7 ------- .../src/main/config/modules/alpn-impl/alpn-10.mod | 4 ---- .../src/main/config/modules/alpn-impl/alpn-11.mod | 4 ---- .../src/main/config/modules/alpn-impl/alpn-12.mod | 4 ---- .../src/main/config/modules/alpn-impl/alpn-13.mod | 4 ---- .../src/main/config/modules/alpn-impl/alpn-14.mod | 4 ---- .../src/main/config/modules/alpn-impl/alpn-15.mod | 4 ---- .../alpn-impl/{alpn-8.mod => alpn-available-false.mod} | 0 .../alpn-impl/{alpn-9.mod => alpn-available-true.mod} | 0 .../jetty-alpn-server/src/main/config/modules/alpn.mod | 2 +- .../src/main/java/org/eclipse/jetty/start/StartArgs.java | 6 ++++++ 11 files changed, 7 insertions(+), 32 deletions(-) delete mode 100644 jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl.mod delete mode 100644 jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-10.mod delete mode 100644 jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-11.mod delete mode 100644 jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-12.mod delete mode 100644 jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-13.mod delete mode 100644 jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-14.mod delete mode 100644 jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-15.mod rename jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/{alpn-8.mod => alpn-available-false.mod} (100%) rename jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/{alpn-9.mod => alpn-available-true.mod} (100%) diff --git a/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl.mod b/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl.mod deleted file mode 100644 index 0cc101702ccf..000000000000 --- a/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl.mod +++ /dev/null @@ -1,7 +0,0 @@ -# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[description] -Selects an ALPN (Application Layer Protocol Negotiation) implementation by java version. - -[depend] -alpn-impl/alpn-${java.version.platform} diff --git a/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-10.mod b/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-10.mod deleted file mode 100644 index a3dbcb0e7c9d..000000000000 --- a/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-10.mod +++ /dev/null @@ -1,4 +0,0 @@ -# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[depend] -alpn-impl/alpn-9 diff --git a/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-11.mod b/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-11.mod deleted file mode 100644 index a3dbcb0e7c9d..000000000000 --- a/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-11.mod +++ /dev/null @@ -1,4 +0,0 @@ -# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[depend] -alpn-impl/alpn-9 diff --git a/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-12.mod b/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-12.mod deleted file mode 100644 index 4dbcf25f5839..000000000000 --- a/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-12.mod +++ /dev/null @@ -1,4 +0,0 @@ -# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[depend] -alpn-impl/alpn-11 diff --git a/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-13.mod b/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-13.mod deleted file mode 100644 index 4dbcf25f5839..000000000000 --- a/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-13.mod +++ /dev/null @@ -1,4 +0,0 @@ -# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[depend] -alpn-impl/alpn-11 diff --git a/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-14.mod b/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-14.mod deleted file mode 100644 index 4dbcf25f5839..000000000000 --- a/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-14.mod +++ /dev/null @@ -1,4 +0,0 @@ -# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[depend] -alpn-impl/alpn-11 diff --git a/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-15.mod b/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-15.mod deleted file mode 100644 index 4dbcf25f5839..000000000000 --- a/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-15.mod +++ /dev/null @@ -1,4 +0,0 @@ -# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html - -[depend] -alpn-impl/alpn-11 diff --git a/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-8.mod b/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-available-false.mod similarity index 100% rename from jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-8.mod rename to jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-available-false.mod diff --git a/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-9.mod b/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-available-true.mod similarity index 100% rename from jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-9.mod rename to jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn-impl/alpn-available-true.mod diff --git a/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn.mod b/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn.mod index dc765d13b021..256ed05d56a9 100644 --- a/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn.mod +++ b/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn.mod @@ -5,7 +5,7 @@ Enables the ALPN (Application Layer Protocol Negotiation) TLS extension. [depend] ssl -alpn-impl +alpn-impl/alpn-available-${java.feature.alpn} [lib] lib/jetty-alpn-client-${jetty.version}.jar diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java index 7161387a2883..dd51d36e148d 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java @@ -1505,6 +1505,12 @@ public void setProperty(String key, String value, String source) { JavaVersion ver = JavaVersion.parse(value); properties.setProperty("java.version.platform", Integer.toString(ver.getPlatform()), source); + + // features built into java. + properties.setProperty("java.feature.alpn", Boolean.toString(ver.getPlatform() >= 9), source); + properties.setProperty("java.feature.jpms", Boolean.toString(ver.getPlatform() >= 9), source); + properties.setProperty("java.feature.loom", Boolean.toString(ver.getPlatform() >= 16), source); + // @deprecated - below will be removed in Jetty 10.x properties.setProperty("java.version.major", Integer.toString(ver.getMajor()), "Deprecated"); properties.setProperty("java.version.minor", Integer.toString(ver.getMinor()), "Deprecated"); From 1b15c1e4a33cfe23ebcb5bae1aea34ed885389d9 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Mon, 15 Feb 2021 13:09:24 -0600 Subject: [PATCH 2/4] Issue #5492 - Changing from "java.feature.*" to "runtime.feature.*" Signed-off-by: Joakim Erdfelt --- .../src/main/config/modules/alpn.mod | 2 +- .../org/eclipse/jetty/start/StartArgs.java | 33 +++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn.mod b/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn.mod index 256ed05d56a9..bd99ae571c2a 100644 --- a/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn.mod +++ b/jetty-alpn/jetty-alpn-server/src/main/config/modules/alpn.mod @@ -5,7 +5,7 @@ Enables the ALPN (Application Layer Protocol Negotiation) TLS extension. [depend] ssl -alpn-impl/alpn-available-${java.feature.alpn} +alpn-impl/alpn-available-${runtime.feature.alpn} [lib] lib/jetty-alpn-client-${jetty.version}.jar diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java index b3353978fd0e..ef74db738ebc 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java @@ -1507,9 +1507,10 @@ public void setProperty(String key, String value, String source) properties.setProperty("java.version.platform", Integer.toString(ver.getPlatform()), source); // features built into java. - properties.setProperty("java.feature.alpn", Boolean.toString(ver.getPlatform() >= 9), source); - properties.setProperty("java.feature.jpms", Boolean.toString(ver.getPlatform() >= 9), source); - properties.setProperty("java.feature.loom", Boolean.toString(ver.getPlatform() >= 16), source); + // TODO: Remove in Jetty 10+ + properties.setProperty("runtime.feature.alpn", Boolean.toString(isMethodAvailable(javax.net.ssl.SSLParameters.class, "getApplicationProtocols", null)), source); + // TODO: Remove in Jetty 10+ + properties.setProperty("runtime.feature.jpms", Boolean.toString(isClassAvailable("java.lang.ModuleLayer")), source); // @deprecated - below will be removed in Jetty 10.x properties.setProperty("java.version.major", Integer.toString(ver.getMajor()), "Deprecated"); @@ -1531,6 +1532,32 @@ public void setProperty(String key, String value, String source) } } + private boolean isMethodAvailable(Class clazz, String methodName, Class[] params) + { + try + { + clazz.getMethod(methodName, params); + return true; + } + catch (NoSuchMethodException e) + { + return false; + } + } + + private boolean isClassAvailable(String clazzname) + { + try + { + Class.forName(clazzname, false, this.getClass().getClassLoader()); + return true; + } + catch (ClassNotFoundException e) + { + return false; + } + } + public void setRun(boolean run) { this.run = run; From 7ed68d068133cc8ce54d68cda4f8ce8cf27f3827 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Mon, 15 Feb 2021 14:25:09 -0600 Subject: [PATCH 3/4] Issue #5492 - Updating jetty-start property test expectations Signed-off-by: Joakim Erdfelt --- .../src/main/java/org/eclipse/jetty/start/StartArgs.java | 4 ++-- .../java/org/eclipse/jetty/start/ConfigurationAssert.java | 1 + .../src/test/java/org/eclipse/jetty/start/MainTest.java | 7 +++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java index ef74db738ebc..a1d1c76fbe8d 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java @@ -1507,9 +1507,9 @@ public void setProperty(String key, String value, String source) properties.setProperty("java.version.platform", Integer.toString(ver.getPlatform()), source); // features built into java. - // TODO: Remove in Jetty 10+ + // In Jetty 10+ these will always be true, but still need to stick around for users that + // want to move between Jetty 9.4.x and 10.0.x+ properties.setProperty("runtime.feature.alpn", Boolean.toString(isMethodAvailable(javax.net.ssl.SSLParameters.class, "getApplicationProtocols", null)), source); - // TODO: Remove in Jetty 10+ properties.setProperty("runtime.feature.jpms", Boolean.toString(isClassAvailable("java.lang.ModuleLayer")), source); // @deprecated - below will be removed in Jetty 10.x diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigurationAssert.java b/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigurationAssert.java index c552d8385de8..25cad5adeb21 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigurationAssert.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/ConfigurationAssert.java @@ -143,6 +143,7 @@ public static void assertConfiguration(BaseHome baseHome, StartArgs args, String "jetty.base.uri".equals(name) || "user.dir".equals(name) || prop.source.equals(Props.ORIGIN_SYSPROP) || + name.startsWith("runtime.feature.") || name.startsWith("java.")) { // strip these out from assertion, to make assertions easier. diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java index eb5a51c487cc..a52769b0a793 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java @@ -225,8 +225,11 @@ public void testJettyHomeWithSpaces() throws Exception { Path distPath = MavenTestingUtils.getTestResourceDir("dist-home").toPath().toRealPath(); Path homePath = MavenTestingUtils.getTargetTestingPath().resolve("dist home with spaces"); - IO.copy(distPath.toFile(), homePath.toFile()); - Files.createFile(homePath.resolve("lib/a library.jar")); + if (!Files.exists(homePath)) + { + IO.copy(distPath.toFile(), homePath.toFile()); + Files.createFile(homePath.resolve("lib/a library.jar")); + } List cmdLineArgs = new ArrayList<>(); cmdLineArgs.add("user.dir=" + homePath); From f2bed1368bfea82ad48311e74c027c4c20b122a6 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 18 Feb 2021 11:14:54 -0600 Subject: [PATCH 4/4] Issue #5492 - changed from review Signed-off-by: Joakim Erdfelt --- .../org/eclipse/jetty/start/StartArgs.java | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java index a1d1c76fbe8d..f1040ec8b462 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java @@ -1506,16 +1506,13 @@ public void setProperty(String key, String value, String source) JavaVersion ver = JavaVersion.parse(value); properties.setProperty("java.version.platform", Integer.toString(ver.getPlatform()), source); - // features built into java. - // In Jetty 10+ these will always be true, but still need to stick around for users that - // want to move between Jetty 9.4.x and 10.0.x+ - properties.setProperty("runtime.feature.alpn", Boolean.toString(isMethodAvailable(javax.net.ssl.SSLParameters.class, "getApplicationProtocols", null)), source); - properties.setProperty("runtime.feature.jpms", Boolean.toString(isClassAvailable("java.lang.ModuleLayer")), source); - // @deprecated - below will be removed in Jetty 10.x properties.setProperty("java.version.major", Integer.toString(ver.getMajor()), "Deprecated"); properties.setProperty("java.version.minor", Integer.toString(ver.getMinor()), "Deprecated"); properties.setProperty("java.version.micro", Integer.toString(ver.getMicro()), "Deprecated"); + + // ALPN feature exists + properties.setProperty("runtime.feature.alpn", Boolean.toString(isMethodAvailable(javax.net.ssl.SSLParameters.class, "getApplicationProtocols", null)), source); } catch (Throwable x) { @@ -1545,19 +1542,6 @@ private boolean isMethodAvailable(Class clazz, String methodName, Class[] } } - private boolean isClassAvailable(String clazzname) - { - try - { - Class.forName(clazzname, false, this.getClass().getClassLoader()); - return true; - } - catch (ClassNotFoundException e) - { - return false; - } - } - public void setRun(boolean run) { this.run = run;