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>
<properties>
<npn.version>1.1.6.v20130911</npn.version>
</properties>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
@ -72,6 +69,10 @@
<artifactId>netty-tcnative</artifactId>
<classifier>${os.detected.classifier}</classifier>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.npn</groupId>
<artifactId>npn-api</artifactId>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jzlib</artifactId>
@ -82,10 +83,6 @@
<artifactId>javassist</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.npn</groupId>
<artifactId>npn-api</artifactId>
</dependency>
<!-- see https://github.com/netty/netty/issues/874 -->
<dependency>
@ -104,179 +101,39 @@
</dependency>
</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>
<profile>
<id>spdy-server</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.server.SpdyServer</argument>
</arguments>
<classpathScope>runtime</classpathScope>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<exampleClass>io.netty.example.spdy.server.SpdyServer</exampleClass>
</properties>
</profile>
<profile>
<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>
<npn.version>1.1.3.v20130313</npn.version>
</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>
<exampleClass>io.netty.example.spdy.client.SpdyClient</exampleClass>
</properties>
</profile>
</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>

View File

@ -22,6 +22,7 @@ import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslProvider;
import io.netty.handler.ssl.util.SelfSignedCertificate;
/**
@ -85,7 +86,7 @@ public class SpdyServer {
// Configure SSL.
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();
}

View File

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

193
pom.xml
View File

@ -71,24 +71,13 @@
<profile>
<id>leak</id>
<properties>
<test.jvm.argLine>
-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>
<argLine.leak>-Dio.netty.leakDetectionLevel=paranoid</argLine.leak>
</properties>
</profile>
<profile>
<id>coverage</id>
<properties>
<test.jvm.argLine.coverage>${jacoco.argLine}</test.jvm.argLine.coverage>
<argLine.coverage>${jacoco.argLine}</argLine.coverage>
</properties>
<build>
<plugins>
@ -179,15 +168,154 @@
</plugins>
</build>
</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>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<jboss.marshalling.version>1.3.18.GA</jboss.marshalling.version>
<test.jvm.argLine.coverage></test.jvm.argLine.coverage> <!-- Set when 'coverage' profile is active -->
<test.jvm.argLine>
-server
<jetty.npn.version>1.1.7.v20140316</jetty.npn.version>
<jetty.npn.path>${settings.localRepository}/org/mortbay/jetty/npn/npn-boot/${jetty.npn.version}/npn-boot-${jetty.npn.version}.jar</jetty.npn.path>
<argLine.common>
-Xbootclasspath/p:${jetty.npn.path}
-server
-dsa -da -ea:io.netty...
-XX:+AggressiveOpts
-XX:+TieredCompilation
@ -196,7 +324,9 @@
-XX:+OptimizeStringConcat
-XX:+HeapDumpOnOutOfMemoryError
-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>
<modules>
@ -238,12 +368,17 @@
<optional>true</optional>
</dependency>
<!-- SPDY Example - completely optional -->
<!-- SPDY and HTTP/2 - completely optional -->
<dependency>
<groupId>org.eclipse.jetty.npn</groupId>
<artifactId>npn-api</artifactId>
<version>1.1.0.v20120525</version>
</dependency>
<dependency>
<groupId>org.mortbay.jetty.npn</groupId>
<artifactId>npn-boot</artifactId>
<version>${jetty.npn.version}</version>
</dependency>
<!-- Google Protocol Buffers - completely optional -->
<dependency>
@ -567,6 +702,24 @@
</dependency>
</dependencies>
</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>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
@ -579,7 +732,7 @@
<exclude>**/TestUtil*</exclude>
</excludes>
<runOrder>random</runOrder>
<argLine>${test.jvm.argLine.coverage} ${test.jvm.argLine}</argLine>
<argLine>${argLine.common} ${argLine.leak} ${argLine.coverage}</argLine>
</configuration>
</plugin>
<!-- always produce osgi bundles -->
@ -907,7 +1060,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<version>1.3</version>
</plugin>
<plugin>
<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