Clean up example execution

Motivation:

- example/pom.xml has quite a bit of duplication.
- We expect that we depend on npn-boot in more than one module in the
  near future. (e.g. handler, codec-http, and codec-http2)

Modification:

- Deduplicate the profiles in example/pom.xml
- Move the build configuration related with npn-boot to the parent pom.
- Add run-example.sh that helps a user launch an example easily

Result:

- Cleaner build files
- Easier to add a new example
- Easier to launch an example
- Easier to run the tests that relies on npn-boot in the future
This commit is contained in:
Trustin Lee 2014-05-20 19:46:19 +09:00
parent c4fc6b7043
commit c77375cf54
5 changed files with 219 additions and 193 deletions

View File

@ -29,9 +29,6 @@
<name>Netty/Example</name> <name>Netty/Example</name>
<properties>
<npn.version>1.1.6.v20130911</npn.version>
</properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
@ -72,6 +69,10 @@
<artifactId>netty-tcnative</artifactId> <artifactId>netty-tcnative</artifactId>
<classifier>${os.detected.classifier}</classifier> <classifier>${os.detected.classifier}</classifier>
</dependency> </dependency>
<dependency>
<groupId>org.eclipse.jetty.npn</groupId>
<artifactId>npn-api</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.jcraft</groupId> <groupId>com.jcraft</groupId>
<artifactId>jzlib</artifactId> <artifactId>jzlib</artifactId>
@ -82,10 +83,6 @@
<artifactId>javassist</artifactId> <artifactId>javassist</artifactId>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency>
<groupId>org.eclipse.jetty.npn</groupId>
<artifactId>npn-api</artifactId>
</dependency>
<!-- see https://github.com/netty/netty/issues/874 --> <!-- see https://github.com/netty/netty/issues/874 -->
<dependency> <dependency>
@ -104,179 +101,39 @@
</dependency> </dependency>
</dependencies> </dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>generate-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.mortbay.jetty.npn</groupId>
<artifactId>npn-boot</artifactId>
<version>${npn.version}</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/npn</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles> <profiles>
<profile> <profile>
<id>spdy-server</id> <id>spdy-server</id>
<build> <properties>
<plugins> <exampleClass>io.netty.example.spdy.server.SpdyServer</exampleClass>
<plugin> </properties>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<executable>${java.home}/bin/java</executable>
<arguments>
<argument>-Xbootclasspath/p:${project.build.directory}/npn/npn-boot-${npn.version}.jar</argument>
<argument>-classpath</argument>
<classpath/>
<argument>io.netty.example.spdy.server.SpdyServer</argument>
</arguments>
<classpathScope>runtime</classpathScope>
</configuration>
</plugin>
</plugins>
</build>
</profile> </profile>
<profile> <profile>
<id>spdy-client</id> <id>spdy-client</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<executable>${java.home}/bin/java</executable>
<arguments>
<argument>-Xbootclasspath/p:${project.build.directory}/npn/npn-boot-${npn.version}.jar</argument>
<argument>-classpath</argument>
<classpath/>
<argument>io.netty.example.spdy.client.SpdyClient</argument>
</arguments>
<classpathScope>runtime</classpathScope>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<!--
profiles for the various npn vs OpenJDK version as found on:
http://www.eclipse.org/jetty/documentation/current/npn-chapter.html#npn-versions
-->
<profile>
<id>7u9</id>
<activation>
<property>
<name>java.version</name>
<value>1.7.0_9</value>
</property>
</activation>
<properties> <properties>
<npn.version>1.1.3.v20130313</npn.version> <exampleClass>io.netty.example.spdy.client.SpdyClient</exampleClass>
</properties>
</profile>
<profile>
<id>7u10</id>
<activation>
<property>
<name>java.version</name>
<value>1.7.0_10</value>
</property>
</activation>
<properties>
<npn.version>1.1.3.v20130313</npn.version>
</properties>
</profile>
<profile>
<id>7u11</id>
<activation>
<property>
<name>java.version</name>
<value>1.7.0_11</value>
</property>
</activation>
<properties>
<npn.version>1.1.3.v20130313</npn.version>
</properties>
</profile>
<profile>
<id>7u13</id>
<activation>
<property>
<name>java.version</name>
<value>1.7.0_13</value>
</property>
</activation>
<properties>
<npn.version>1.1.4.v20130313</npn.version>
</properties>
</profile>
<profile>
<id>7u15</id>
<activation>
<property>
<name>java.version</name>
<value>1.7.0_15</value>
</property>
</activation>
<properties>
<npn.version>1.1.5.v20130313</npn.version>
</properties>
</profile>
<profile>
<id>7u17</id>
<activation>
<property>
<name>java.version</name>
<value>1.7.0_17</value>
</property>
</activation>
<properties>
<npn.version>1.1.5.v20130313</npn.version>
</properties>
</profile>
<profile>
<id>7u21</id>
<activation>
<property>
<name>java.version</name>
<value>1.7.0_21</value>
</property>
</activation>
<properties>
<npn.version>1.1.5.v20130313</npn.version>
</properties>
</profile>
<profile>
<id>7u25</id>
<activation>
<property>
<name>java.version</name>
<value>1.7.0_25</value>
</property>
</activation>
<properties>
<npn.version>1.1.5.v20130313</npn.version>
</properties> </properties>
</profile> </profile>
</profiles> </profiles>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<executable>${java.home}/bin/java</executable>
<commandlineArgs>
${argLine.common}
${argLine.leak}
${argLine.coverage}
-classpath %classpath
${exampleClass}
</commandlineArgs>
<classpathScope>runtime</classpathScope>
</configuration>
</plugin>
</plugins>
</build>
</project> </project>

View File

@ -22,6 +22,7 @@ import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.ssl.SslContext; import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslProvider;
import io.netty.handler.ssl.util.SelfSignedCertificate; import io.netty.handler.ssl.util.SelfSignedCertificate;
/** /**
@ -85,7 +86,7 @@ public class SpdyServer {
// Configure SSL. // Configure SSL.
SelfSignedCertificate ssc = new SelfSignedCertificate(); SelfSignedCertificate ssc = new SelfSignedCertificate();
SslContext sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey()); SslContext sslCtx = SslContext.newServerContext(SslProvider.JDK, ssc.certificate(), ssc.privateKey());
new SpdyServer(sslCtx, port).run(); new SpdyServer(sslCtx, port).run();
} }

View File

@ -41,7 +41,7 @@ public class SpdyServerInitializer extends ChannelInitializer<SocketChannel> {
SslHandler sslHandler = sslCtx.newHandler(ch.alloc()); SslHandler sslHandler = sslCtx.newHandler(ch.alloc());
SSLEngine engine = sslHandler.engine(); SSLEngine engine = sslHandler.engine();
p.addLast("ssl", new SslHandler(engine)); p.addLast("ssl", sslHandler);
// Setup NextProtoNego with our server provider // Setup NextProtoNego with our server provider
NextProtoNego.put(engine, new SpdyServerProvider()); NextProtoNego.put(engine, new SpdyServerProvider());

193
pom.xml
View File

@ -71,24 +71,13 @@
<profile> <profile>
<id>leak</id> <id>leak</id>
<properties> <properties>
<test.jvm.argLine> <argLine.leak>-Dio.netty.leakDetectionLevel=paranoid</argLine.leak>
-server
-dsa -da -ea:io.netty...
-XX:+AggressiveOpts
-XX:+TieredCompilation
-XX:+UseBiasedLocking
-XX:+UseFastAccessorMethods
-XX:+OptimizeStringConcat
-XX:+HeapDumpOnOutOfMemoryError
-Dio.netty.leakDetectionLevel=3
-verbose:gc
</test.jvm.argLine>
</properties> </properties>
</profile> </profile>
<profile> <profile>
<id>coverage</id> <id>coverage</id>
<properties> <properties>
<test.jvm.argLine.coverage>${jacoco.argLine}</test.jvm.argLine.coverage> <argLine.coverage>${jacoco.argLine}</argLine.coverage>
</properties> </properties>
<build> <build>
<plugins> <plugins>
@ -179,15 +168,154 @@
</plugins> </plugins>
</build> </build>
</profile> </profile>
<!--
Profiles that assigns proper Jetty npn-boot version.
See: http://www.eclipse.org/jetty/documentation/current/npn-chapter.html#npn-versions
-->
<profile>
<id>npn-7u9</id>
<activation>
<property>
<name>java.version</name>
<value>1.7.0_9</value>
</property>
</activation>
<properties>
<jetty.npn.version>1.1.3.v20130313</jetty.npn.version>
</properties>
</profile>
<profile>
<id>npn-7u10</id>
<activation>
<property>
<name>java.version</name>
<value>1.7.0_10</value>
</property>
</activation>
<properties>
<jetty.npn.version>1.1.3.v20130313</jetty.npn.version>
</properties>
</profile>
<profile>
<id>npn-7u11</id>
<activation>
<property>
<name>java.version</name>
<value>1.7.0_11</value>
</property>
</activation>
<properties>
<jetty.npn.version>1.1.3.v20130313</jetty.npn.version>
</properties>
</profile>
<profile>
<id>npn-7u13</id>
<activation>
<property>
<name>java.version</name>
<value>1.7.0_13</value>
</property>
</activation>
<properties>
<jetty.npn.version>1.1.4.v20130313</jetty.npn.version>
</properties>
</profile>
<profile>
<id>npn-7u15</id>
<activation>
<property>
<name>java.version</name>
<value>1.7.0_15</value>
</property>
</activation>
<properties>
<jetty.npn.version>1.1.5.v20130313</jetty.npn.version>
</properties>
</profile>
<profile>
<id>npn-7u17</id>
<activation>
<property>
<name>java.version</name>
<value>1.7.0_17</value>
</property>
</activation>
<properties>
<jetty.npn.version>1.1.5.v20130313</jetty.npn.version>
</properties>
</profile>
<profile>
<id>npn-7u21</id>
<activation>
<property>
<name>java.version</name>
<value>1.7.0_21</value>
</property>
</activation>
<properties>
<jetty.npn.version>1.1.5.v20130313</jetty.npn.version>
</properties>
</profile>
<profile>
<id>npn-7u25</id>
<activation>
<property>
<name>java.version</name>
<value>1.7.0_25</value>
</property>
</activation>
<properties>
<jetty.npn.version>1.1.5.v20130313</jetty.npn.version>
</properties>
</profile>
<profile>
<id>npn-7u40</id>
<activation>
<property>
<name>java.version</name>
<value>1.7.0_40</value>
</property>
</activation>
<properties>
<jetty.npn.version>1.1.6.v20130911</jetty.npn.version>
</properties>
</profile>
<profile>
<id>npn-7u45</id>
<activation>
<property>
<name>java.version</name>
<value>1.7.0_45</value>
</property>
</activation>
<properties>
<jetty.npn.version>1.1.6.v20130911</jetty.npn.version>
</properties>
</profile>
<profile>
<id>npn-7u51</id>
<activation>
<property>
<name>java.version</name>
<value>1.7.0_51</value>
</property>
</activation>
<properties>
<jetty.npn.version>1.1.6.v20130911</jetty.npn.version>
</properties>
</profile>
</profiles> </profiles>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<jboss.marshalling.version>1.3.18.GA</jboss.marshalling.version> <jboss.marshalling.version>1.3.18.GA</jboss.marshalling.version>
<test.jvm.argLine.coverage></test.jvm.argLine.coverage> <!-- Set when 'coverage' profile is active --> <jetty.npn.version>1.1.7.v20140316</jetty.npn.version>
<test.jvm.argLine> <jetty.npn.path>${settings.localRepository}/org/mortbay/jetty/npn/npn-boot/${jetty.npn.version}/npn-boot-${jetty.npn.version}.jar</jetty.npn.path>
-server <argLine.common>
-Xbootclasspath/p:${jetty.npn.path}
-server
-dsa -da -ea:io.netty... -dsa -da -ea:io.netty...
-XX:+AggressiveOpts -XX:+AggressiveOpts
-XX:+TieredCompilation -XX:+TieredCompilation
@ -196,7 +324,9 @@
-XX:+OptimizeStringConcat -XX:+OptimizeStringConcat
-XX:+HeapDumpOnOutOfMemoryError -XX:+HeapDumpOnOutOfMemoryError
-verbose:gc -verbose:gc
</test.jvm.argLine> </argLine.common>
<argLine.leak>-D_</argLine.leak> <!-- Set when 'leak' profile is active -->
<argLine.coverage>-D_</argLine.coverage> <!-- Set when 'coverage' profile is active -->
</properties> </properties>
<modules> <modules>
@ -238,12 +368,17 @@
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<!-- SPDY Example - completely optional --> <!-- SPDY and HTTP/2 - completely optional -->
<dependency> <dependency>
<groupId>org.eclipse.jetty.npn</groupId> <groupId>org.eclipse.jetty.npn</groupId>
<artifactId>npn-api</artifactId> <artifactId>npn-api</artifactId>
<version>1.1.0.v20120525</version> <version>1.1.0.v20120525</version>
</dependency> </dependency>
<dependency>
<groupId>org.mortbay.jetty.npn</groupId>
<artifactId>npn-boot</artifactId>
<version>${jetty.npn.version}</version>
</dependency>
<!-- Google Protocol Buffers - completely optional --> <!-- Google Protocol Buffers - completely optional -->
<dependency> <dependency>
@ -567,6 +702,24 @@
</dependency> </dependency>
</dependencies> </dependencies>
</plugin> </plugin>
<!-- Download the npn-boot.jar in advance to add it to the boot classpath. -->
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>get-npn-boot</id>
<phase>validate</phase>
<goals>
<goal>get</goal>
</goals>
<configuration>
<groupId>org.mortbay.jetty.npn</groupId>
<artifactId>npn-boot</artifactId>
<version>${jetty.npn.version}</version>
</configuration>
</execution>
</executions>
</plugin>
<plugin> <plugin>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<configuration> <configuration>
@ -579,7 +732,7 @@
<exclude>**/TestUtil*</exclude> <exclude>**/TestUtil*</exclude>
</excludes> </excludes>
<runOrder>random</runOrder> <runOrder>random</runOrder>
<argLine>${test.jvm.argLine.coverage} ${test.jvm.argLine}</argLine> <argLine>${argLine.common} ${argLine.leak} ${argLine.coverage}</argLine>
</configuration> </configuration>
</plugin> </plugin>
<!-- always produce osgi bundles --> <!-- always produce osgi bundles -->
@ -907,7 +1060,7 @@
<plugin> <plugin>
<groupId>org.codehaus.mojo</groupId> <groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId> <artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version> <version>1.3</version>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.fusesource.hawtjni</groupId> <groupId>org.fusesource.hawtjni</groupId>

15
run-example.sh Executable file
View File

@ -0,0 +1,15 @@
#!/bin/bash -e
cd "`dirname "$0"`"/example
if [[ $# -ne 1 ]]; then
echo "Usage: $0 <example-name>" >&2
echo >&2
echo "Available examples:" >&2
grep -E '^ <id>[-a-z0-9]*</id>' pom.xml | sed -e 's#\(^.*<id>\|</id>.*$\)##g' | sed -e 's#^# #' >&2
exit 1
fi
EXAMPLE_NAME="$1"
echo "[INFO] Running: $EXAMPLE_NAME"
mvn -X -P "$EXAMPLE_NAME" compile exec:exec