Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure we only register native methods once #10876

Merged
merged 1 commit into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
76 changes: 75 additions & 1 deletion all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,27 @@
<dependencies>
<!-- Depend on all our native jars -->
<!-- As this is executed on either macOS or Linux we directly need to specify the classifier -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-transport-native-unix-common</artifactId>
<classifier>linux-x86_64</classifier>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-transport-native-unix-common</artifactId>
<classifier>linux-aarch_64</classifier>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-transport-native-unix-common</artifactId>
<classifier>osx-x86_64</classifier>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
Expand Down Expand Up @@ -97,6 +118,27 @@
<dependencies>
<!-- Depend on all our native jars -->
<!-- As this is executed on either macOS or Linux we directly need to specify the classifier -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-transport-native-unix-common</artifactId>
<classifier>linux-x86_64</classifier>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-transport-native-unix-common</artifactId>
<classifier>linux-aarch_64</classifier>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-transport-native-unix-common</artifactId>
<classifier>osx-x86_64</classifier>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
Expand Down Expand Up @@ -128,7 +170,7 @@
</dependencies>
</profile>

<!-- The linux profile will only include the native jar for epol to the all jar.
<!-- The linux profile will only include the native jar for epoll to the all jar.
If you want to also include the native jar for kqueue use -Puber.
-->
<profile>
Expand All @@ -140,6 +182,14 @@
</activation>
<dependencies>
<!-- All release modules -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-transport-native-unix-common</artifactId>
<version>${project.version}</version>
<classifier>${jni.classifier}</classifier>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
Expand Down Expand Up @@ -175,6 +225,14 @@
</activation>
<dependencies>
<!-- All release modules -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-transport-native-unix-common</artifactId>
<version>${project.version}</version>
<classifier>${jni.classifier}</classifier>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-transport-native-kqueue</artifactId>
Expand Down Expand Up @@ -209,6 +267,14 @@
</activation>
<dependencies>
<!-- All release modules -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-transport-native-unix-common</artifactId>
<version>${project.version}</version>
<classifier>${jni.classifier}</classifier>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-transport-native-kqueue</artifactId>
Expand Down Expand Up @@ -236,6 +302,14 @@
</activation>
<dependencies>
<!-- All release modules -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-transport-native-unix-common</artifactId>
<version>${project.version}</version>
<classifier>${jni.classifier}</classifier>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-transport-native-kqueue</artifactId>
Expand Down
27 changes: 27 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,33 @@

<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.2.2</version>
<executions>
<!-- enable flattening -->
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<!-- ensure proper cleanup -->
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
<configuration>
<flattenMode>oss</flattenMode>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</plugin>
<!-- keep surefire and failsafe in sync -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down
33 changes: 23 additions & 10 deletions resolver-dns-native-macos/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,23 @@
<artifactId>netty-transport-native-unix-common</artifactId>
<version>${project.version}</version>
<classifier>${jni.classifier}</classifier>
<!--
The unix-common with classifier dependency is optional because it is not a runtime dependency, but a build time
dependency to get the static library which is built directly into the shared library generated by this project.
-->
<optional>true</optional>
</dependency>
</dependencies>
</profile>
<profile>
<!--
For non-classifier native builds we should depend on netty-transport-native-unix-common without the
classifier. This profile will be disabled by the other profiles when the native bits will be build.
-->
<id>non-native</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-unix-common</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</profile>
Expand Down Expand Up @@ -156,15 +168,16 @@
<artifactId>netty-resolver-dns</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-unix-common</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<!-- We need to use the flatten plugin so the classifier portion of the dependency is resolved-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
</plugin>

<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.netty.resolver.dns.macos;

import io.netty.channel.unix.Unix;
import io.netty.resolver.dns.DnsServerAddressStream;
import io.netty.resolver.dns.DnsServerAddressStreamProvider;
import io.netty.resolver.dns.DnsServerAddressStreamProviders;
Expand Down Expand Up @@ -53,6 +54,7 @@ public final class MacOSDnsServerAddressStreamProvider implements DnsServerAddre
static {
Throwable cause = null;
try {
Unix.ensureAvailability();
loadNativeLibrary();
} catch (Throwable error) {
cause = error;
Expand Down
1 change: 1 addition & 0 deletions testsuite-osgi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@
<dependencySet>
<scope>test</scope>
</dependencySet>
<separator>${line.separator}</separator>
</configuration>
</execution>
</executions>
Expand Down
37 changes: 22 additions & 15 deletions transport-native-epoll/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,6 @@
<artifactId>netty-transport-native-unix-common</artifactId>
<version>${project.version}</version>
<classifier>${jni.classifier}</classifier>
<!--
The unix-common with classifier dependency is optional because it is not a runtime dependency, but a build time
dependency to get the static library which is built directly into the shared library generated by this project.
-->
<optional>true</optional>
</dependency>
</dependencies>
</profile>
Expand Down Expand Up @@ -351,11 +346,23 @@
<artifactId>netty-transport-native-unix-common</artifactId>
<version>${project.version}</version>
<classifier>${jni.classifier}</classifier>
<!--
The unix-common with classifier dependency is optional because it is not a runtime dependency, but a build time
dependency to get the static library which is built directly into the shared library generated by this project.
-->
<optional>true</optional>
</dependency>
</dependencies>
</profile>
<profile>
<!--
For non-classifier native builds we should depend on netty-transport-native-unix-common without the
classifier. This profile will be disabled by the other profiles when the native bits will be build.
-->
<id>non-native</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-unix-common</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</profile>
Expand All @@ -377,11 +384,6 @@
<artifactId>netty-transport</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-unix-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-testsuite</artifactId>
Expand All @@ -405,6 +407,11 @@

<build>
<plugins>
<!-- We need to use the flatten plugin so the classifier portion of the dependency is resolved-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
</plugin>
<!-- Also include c files in source jar -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.netty.channel.epoll;

import io.netty.channel.unix.FileDescriptor;
import io.netty.channel.unix.Unix;
import io.netty.util.internal.SystemPropertyUtil;

/**
Expand All @@ -36,6 +37,7 @@ public final class Epoll {
FileDescriptor epollFd = null;
FileDescriptor eventFd = null;
try {
Unix.ensureAvailability();
epollFd = Native.newEpollCreate();
eventFd = Native.newEventFd();
} catch (Throwable t) {
Expand Down