Skip to content

Commit

Permalink
Issue #5492 - Changing from "java.feature.*" to "runtime.feature.*"
Browse files Browse the repository at this point in the history
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
  • Loading branch information
joakime committed Feb 15, 2021
1 parent de5b8bc commit 1b15c1e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
Expand Up @@ -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
Expand Down
33 changes: 30 additions & 3 deletions jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java
Expand Up @@ -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");
Expand All @@ -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;
Expand Down

0 comments on commit 1b15c1e

Please sign in to comment.