From f332a00e1a1b131d866dc2b86916d97f3a1bcf17 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Thu, 1 Dec 2016 09:20:14 +0100 Subject: [PATCH] Support compiling netty with Java9 Motivation: Java9 will be released soon so we should ensure we can compile netty with Java9 and run all our tests. This will help to make sure Netty will be usable with Java9. Modification: - Add some workarounds to be able to compile with Java9, note that the full profile is not supported with Java9 atm. - Remove some usage of internal APIs to be able to compile on java9 - Not support Alpn / Npn and so not run the tests when using Java9 for now. We will do a follow up PR to add support. Result: Its possible to build netty and run its testsuite with Java9. --- all/pom.xml | 156 ++++++++++-------- common/pom.xml | 24 +++ .../netty/handler/ssl/JdkAlpnSslEngine.java | 4 +- .../io/netty/handler/ssl/SslErrorTest.java | 12 +- pom.xml | 28 +++- 5 files changed, 147 insertions(+), 77 deletions(-) diff --git a/all/pom.xml b/all/pom.xml index df03ccde6f..c344dced37 100644 --- a/all/pom.xml +++ b/all/pom.xml @@ -29,7 +29,6 @@ Netty/All-in-One - true ${project.build.directory}/src ${project.build.directory}/versions @@ -37,9 +36,91 @@ full - - false - + + + + + + + + maven-jxr-plugin + + + generate-xref + package + + jxr + + + + + true + ${project.build.directory}/xref + ${project.build.directory}/api + Netty Source Xref (${project.version}) + Netty Source Xref (${project.version}) + + + + ${project.groupId} + netty-build + 19 + + + + + com.puppycrawl.tools + checkstyle + + + + + com.puppycrawl.tools + checkstyle + 7.3 + + + + + + + maven-javadoc-plugin + + + attach-javadocs + + jar + + + + + ${quickbuild} + *.internal,*.example + true + ${project.build.directory}/api + ${project.basedir}/src/javadoc/overview.html + Netty API Reference (${project.version}) + Netty API Reference (${project.version}) + false + + -link http://docs.oracle.com/javase/7/docs/api/ + -link http://code.google.com/apis/protocolbuffers/docs/reference/java/ + -link http://docs.oracle.com/javaee/6/api/ + -link http://www.slf4j.org/apidocs/ + -link https://commons.apache.org/proper/commons-logging/apidocs/ + -link http://logging.apache.org/log4j/1.2/apidocs/ + + -group "Low-level data representation" io.netty.buffer* + -group "Central interface for all I/O operations" io.netty.channel* + -group "Client & Server bootstrapping utilities" io.netty.bootstrap* + -group "Reusable I/O event interceptors" io.netty.handler* + -group "Miscellaneous" io.netty.util* + + en_US + + + + coverage @@ -513,73 +594,6 @@ - - - - maven-jxr-plugin - - - generate-xref - package - - jxr - - - - - ${quickbuild} - true - ${project.build.directory}/xref - ${project.build.directory}/api - Netty Source Xref (${project.version}) - Netty Source Xref (${project.version}) - - - - ${project.groupId} - netty-build - 19 - - - - - - - maven-javadoc-plugin - - - attach-javadocs - - jar - - - - - ${quickbuild} - *.internal,*.example - true - ${project.build.directory}/api - ${project.basedir}/src/javadoc/overview.html - Netty API Reference (${project.version}) - Netty API Reference (${project.version}) - false - - -link http://docs.oracle.com/javase/7/docs/api/ - -link http://code.google.com/apis/protocolbuffers/docs/reference/java/ - -link http://docs.oracle.com/javaee/6/api/ - -link http://www.slf4j.org/apidocs/ - -link https://commons.apache.org/proper/commons-logging/apidocs/ - -link http://logging.apache.org/log4j/1.2/apidocs/ - - -group "Low-level data representation" io.netty.buffer* - -group "Central interface for all I/O operations" io.netty.channel* - -group "Client & Server bootstrapping utilities" io.netty.bootstrap* - -group "Reusable I/O event interceptors" io.netty.handler* - -group "Miscellaneous" io.netty.util* - - en_US - - diff --git a/common/pom.xml b/common/pom.xml index 0df84287e4..f7b73821a1 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -105,6 +105,30 @@ + + + + + org.ow2.asm + asm + ${asm.version} + + + org.ow2.asm + asm-commons + ${asm.version} + + + org.ow2.asm + asm-analysis + ${asm.version} + + + org.ow2.asm + asm-util + ${asm.version} + + diff --git a/handler/src/main/java/io/netty/handler/ssl/JdkAlpnSslEngine.java b/handler/src/main/java/io/netty/handler/ssl/JdkAlpnSslEngine.java index bdf3aca146..799c6f939d 100644 --- a/handler/src/main/java/io/netty/handler/ssl/JdkAlpnSslEngine.java +++ b/handler/src/main/java/io/netty/handler/ssl/JdkAlpnSslEngine.java @@ -26,6 +26,7 @@ import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLException; import javax.net.ssl.SSLHandshakeException; +import io.netty.util.internal.PlatformDependent; import org.eclipse.jetty.alpn.ALPN; import org.eclipse.jetty.alpn.ALPN.ClientProvider; import org.eclipse.jetty.alpn.ALPN.ServerProvider; @@ -39,7 +40,8 @@ final class JdkAlpnSslEngine extends JdkSslEngine { } private static void updateAvailability() { - if (available) { + // TODO: Add support for ALPN when using Java9 and still be able to configure it the Netty way. + if (available || PlatformDependent.javaVersion() > 8) { return; } diff --git a/handler/src/test/java/io/netty/handler/ssl/SslErrorTest.java b/handler/src/test/java/io/netty/handler/ssl/SslErrorTest.java index d3c238b5a9..87e4919eb6 100644 --- a/handler/src/test/java/io/netty/handler/ssl/SslErrorTest.java +++ b/handler/src/test/java/io/netty/handler/ssl/SslErrorTest.java @@ -37,7 +37,6 @@ import org.junit.Assume; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import sun.security.validator.ValidatorException; import javax.net.ssl.ManagerFactoryParameters; import javax.net.ssl.SSLException; @@ -103,7 +102,7 @@ public class SslErrorTest { } private static CertificateException newCertificateException(CertPathValidatorException.Reason reason) { - return new ValidatorException("Test exception", + return new TestCertificateException( new CertPathValidatorException("x", null, null, -1, reason)); } @@ -197,7 +196,7 @@ public class SslErrorTest { // Unwrap as its wrapped by a DecoderException Throwable unwrappedCause = cause.getCause(); if (unwrappedCause instanceof SSLException) { - if (exception instanceof ValidatorException) { + if (exception instanceof TestCertificateException) { CertPathValidatorException.Reason reason = ((CertPathValidatorException) exception.getCause()).getReason(); if (reason == CertPathValidatorException.BasicReason.EXPIRED) { @@ -245,4 +244,11 @@ public class SslErrorTest { promise.setFailure(new AssertionError("message not contains '" + messagePart + "': " + message)); } } + + private static final class TestCertificateException extends CertificateException { + + public TestCertificateException(Throwable cause) { + super(cause); + } + } } diff --git a/pom.xml b/pom.xml index 06f506dc4d..2700b8e514 100644 --- a/pom.xml +++ b/pom.xml @@ -68,6 +68,24 @@ + + + java9 + + + --add-modules java.xml.bind --add-exports java.base/sun.security.x509=ALL-UNNAMED + + + + + + 6.0_ALPHA + + + 9 + + + leak @@ -220,6 +238,7 @@ -D_ -D_ -D_ + fedora @@ -230,6 +249,7 @@ ${project.basedir}/../common/src/test/resources/logback-test.xml debug 2.6.2 + 5.1 @@ -680,7 +700,7 @@ org.ow2.asm asm-all - 5.1 + ${asm.version} @@ -732,6 +752,10 @@ java.util.zip.CRC32 java.util.zip.Adler32 + + + java.nio.ByteBuffer + java.nio.CharBuffer @@ -830,7 +854,7 @@ ${logging.config} ${logging.logLevel} - ${argLine.common} ${argLine.alpnAgent} ${argLine.leak} ${argLine.coverage} ${argLine.noUnsafe} + ${argLine.common} ${argLine.alpnAgent} ${argLine.leak} ${argLine.coverage} ${argLine.noUnsafe} ${argLine.java9} listener