Skip to content

Commit d67d639

Browse files
authored
Add integration test for shading native libraries. (netty#8123)
Motivation: It's easy to break the support for shading native libs as shown in netty#8090. We should have some testing to ensure all works as expected. Modification: Add new testsuite which verifies that shading our native transports work as expected. Result: Include test to verify shading of native code.
1 parent 38d5ae9 commit d67d639

File tree

3 files changed

+289
-0
lines changed

3 files changed

+289
-0
lines changed

pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@
273273
<module>testsuite-autobahn</module>
274274
<module>testsuite-http2</module>
275275
<module>testsuite-osgi</module>
276+
<module>testsuite-shading</module>
276277
<module>microbench</module>
277278
<module>bom</module>
278279
</modules>

testsuite-shading/pom.xml

+252
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2018 The Netty Project
4+
~
5+
~ The Netty Project licenses this file to you under the Apache License,
6+
~ version 2.0 (the "License"); you may not use this file except in compliance
7+
~ with the License. You may obtain a copy of the License at:
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
~ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
~ License for the specific language governing permissions and limitations
15+
~ under the License.
16+
-->
17+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
18+
19+
<modelVersion>4.0.0</modelVersion>
20+
<parent>
21+
<groupId>io.netty</groupId>
22+
<artifactId>netty-parent</artifactId>
23+
<version>4.1.27.Final-SNAPSHOT</version>
24+
</parent>
25+
26+
<artifactId>netty-testsuite-shading</artifactId>
27+
<packaging>jar</packaging>
28+
29+
<name>Netty/Testsuite/Shading</name>
30+
31+
<properties>
32+
<generatedSourceDir>${project.build.directory}/src</generatedSourceDir>
33+
<dependencyVersionsDir>${project.build.directory}/versions</dependencyVersionsDir>
34+
<classesShadedDir>${project.build.directory}/classes-shaded</classesShadedDir>
35+
<classesShadedNativeDir>${classesShadedDir}/META-INF/native</classesShadedNativeDir>
36+
<shadingPrefix>shaded</shadingPrefix>
37+
<jarName>${project.artifactId}-${project.version}.jar</jarName>
38+
<shadedPackagePrefix>io.netty.</shadedPackagePrefix>
39+
</properties>
40+
41+
<build>
42+
<extensions>
43+
<extension>
44+
<groupId>kr.motd.maven</groupId>
45+
<artifactId>os-maven-plugin</artifactId>
46+
<version>1.6.0</version>
47+
</extension>
48+
</extensions>
49+
<plugins>
50+
<!-- Do not deploy this module -->
51+
<plugin>
52+
<artifactId>maven-deploy-plugin</artifactId>
53+
<configuration>
54+
<skip>true</skip>
55+
</configuration>
56+
</plugin>
57+
</plugins>
58+
</build>
59+
<dependencies>
60+
<dependency>
61+
<groupId>junit</groupId>
62+
<artifactId>junit</artifactId>
63+
</dependency>
64+
</dependencies>
65+
<profiles>
66+
<profile>
67+
<id>mac</id>
68+
<activation>
69+
<os>
70+
<family>mac</family>
71+
</os>
72+
</activation>
73+
<properties>
74+
<nativeLib>netty_transport_native_kqueue_${os.detected.arch}.jnilib</nativeLib>
75+
</properties>
76+
<dependencies>
77+
<dependency>
78+
<groupId>${project.groupId}</groupId>
79+
<artifactId>netty-transport-native-kqueue</artifactId>
80+
<version>${project.version}</version>
81+
<classifier>${jni.classifier}</classifier>
82+
<scope>compile</scope>
83+
</dependency>
84+
</dependencies>
85+
86+
<build>
87+
<plugins>
88+
<plugin>
89+
<artifactId>maven-shade-plugin</artifactId>
90+
<executions>
91+
<execution>
92+
<phase>package</phase>
93+
<goals>
94+
<goal>shade</goal>
95+
</goals>
96+
<configuration>
97+
<artifactSet>
98+
<includes>
99+
<include>${project.groupId}</include>
100+
</includes>
101+
</artifactSet>
102+
<relocations>
103+
<relocation>
104+
<pattern>${shadedPackagePrefix}</pattern>
105+
<shadedPattern>${shadingPrefix}.${shadedPackagePrefix}</shadedPattern>
106+
</relocation>
107+
</relocations>
108+
</configuration>
109+
</execution>
110+
</executions>
111+
</plugin>
112+
<plugin>
113+
<groupId>org.apache.maven.plugins</groupId>
114+
<artifactId>maven-antrun-plugin</artifactId>
115+
<executions>
116+
<execution>
117+
<id>unpack-jar-features</id>
118+
<phase>package</phase>
119+
<goals>
120+
<goal>run</goal>
121+
</goals>
122+
<configuration>
123+
<target>
124+
<unzip dest="${classesShadedDir}/">
125+
<fileset dir="${project.build.directory}/">
126+
<include name="${jarName}" />
127+
</fileset>
128+
</unzip>
129+
<move file="${classesShadedNativeDir}/lib${nativeLib}" tofile="${classesShadedNativeDir}/lib${shadingPrefix}_${nativeLib}" />
130+
<jar destfile="${project.build.directory}/${jarName}"
131+
basedir="${classesShadedDir}"/>
132+
<delete dir="${classesShadedDir}"/>
133+
</target>
134+
</configuration>
135+
</execution>
136+
</executions>
137+
</plugin>
138+
<plugin>
139+
<groupId>org.apache.maven.plugins</groupId>
140+
<artifactId>maven-failsafe-plugin</artifactId>
141+
<configuration>
142+
<systemPropertyVariables>
143+
<shadingPrefix>${shadingPrefix}</shadingPrefix>
144+
</systemPropertyVariables>
145+
</configuration>
146+
<executions>
147+
<execution>
148+
<phase>package</phase>
149+
<goals>
150+
<goal>integration-test</goal>
151+
</goals>
152+
</execution>
153+
</executions>
154+
</plugin>
155+
</plugins>
156+
</build>
157+
</profile>
158+
<profile>
159+
<id>linux</id>
160+
<activation>
161+
<os>
162+
<family>linux</family>
163+
</os>
164+
</activation>
165+
<properties>
166+
<nativeLib>netty_transport_native_epoll_${os.detected.arch}.so</nativeLib>
167+
</properties>
168+
<dependencies>
169+
<dependency>
170+
<groupId>${project.groupId}</groupId>
171+
<artifactId>netty-transport-native-epoll</artifactId>
172+
<version>${project.version}</version>
173+
<classifier>${jni.classifier}</classifier>
174+
<scope>compile</scope>
175+
</dependency>
176+
</dependencies>
177+
178+
<build>
179+
<plugins>
180+
<plugin>
181+
<artifactId>maven-shade-plugin</artifactId>
182+
<executions>
183+
<execution>
184+
<phase>package</phase>
185+
<goals>
186+
<goal>shade</goal>
187+
</goals>
188+
<configuration>
189+
<artifactSet>
190+
<includes>
191+
<include>${project.groupId}</include>
192+
</includes>
193+
</artifactSet>
194+
<relocations>
195+
<relocation>
196+
<pattern>${shadedPackagePrefix}</pattern>
197+
<shadedPattern>${shadingPrefix}.${shadedPackagePrefix}</shadedPattern>
198+
</relocation>
199+
</relocations>
200+
</configuration>
201+
</execution>
202+
</executions>
203+
</plugin>
204+
<plugin>
205+
<groupId>org.apache.maven.plugins</groupId>
206+
<artifactId>maven-antrun-plugin</artifactId>
207+
<executions>
208+
<execution>
209+
<id>unpack-jar-features</id>
210+
<phase>package</phase>
211+
<goals>
212+
<goal>run</goal>
213+
</goals>
214+
<configuration>
215+
<target>
216+
<unzip dest="${classesShadedDir}/">
217+
<fileset dir="${project.build.directory}/">
218+
<include name="${jarName}" />
219+
</fileset>
220+
</unzip>
221+
<move file="${classesShadedNativeDir}/lib${nativeLib}" tofile="${classesShadedNativeDir}/lib${shadingPrefix}_${nativeLib}" />
222+
<jar destfile="${project.build.directory}/${jarName}"
223+
basedir="${classesShadedDir}"/>
224+
<delete dir="${classesShadedDir}"/>
225+
</target>
226+
</configuration>
227+
</execution>
228+
</executions>
229+
</plugin>
230+
<plugin>
231+
<groupId>org.apache.maven.plugins</groupId>
232+
<artifactId>maven-failsafe-plugin</artifactId>
233+
<configuration>
234+
<systemPropertyVariables>
235+
<shadingPrefix>${shadingPrefix}</shadingPrefix>
236+
</systemPropertyVariables>
237+
</configuration>
238+
<executions>
239+
<execution>
240+
<phase>package</phase>
241+
<goals>
242+
<goal>integration-test</goal>
243+
</goals>
244+
</execution>
245+
</executions>
246+
</plugin>
247+
</plugins>
248+
</build>
249+
</profile>
250+
</profiles>
251+
</project>
252+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2018 The Netty Project
3+
*
4+
* The Netty Project licenses this file to you under the Apache License,
5+
* version 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at:
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
package io.netty.testsuite.shading;
17+
18+
import io.netty.util.internal.PlatformDependent;
19+
import org.junit.Test;
20+
21+
import java.lang.reflect.Method;
22+
23+
public class ShadingIT {
24+
25+
@Test
26+
public void testShadingNativeLibs() throws Exception {
27+
String shadingPrefix = System.getProperty("shadingPrefix");
28+
final Class<?> clazz = Class.forName(shadingPrefix + '.' + className());
29+
Method method = clazz.getMethod("ensureAvailability");
30+
method.invoke(null);
31+
}
32+
33+
private static String className() {
34+
return PlatformDependent.isOsx() ? "io.netty.channel.kqueue.KQueue" : "io.netty.channel.epoll.Epoll";
35+
}
36+
}

0 commit comments

Comments
 (0)