Skip to content
This repository has been archived by the owner on Jun 7, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Stuff integration tests under either -Pintegs-plugin or -Pintegs-uber…
…jar.
  • Loading branch information
bobmcwhirter committed Nov 20, 2015
1 parent 9116ee4 commit 5690259
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 60 deletions.
15 changes: 3 additions & 12 deletions integs/jaxrs/pom.xml
Expand Up @@ -37,23 +37,14 @@
<artifactId>wildfly-swarm-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>package</id>
</execution>
<execution>
<id>start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
<configuration>
<stdoutFile>target/stdout.log</stdoutFile>
<stderrFile>target/stderr.log</stderrFile>
</configuration>
</execution>
<execution>
<id>stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
Expand Down
24 changes: 2 additions & 22 deletions integs/messaging/pom.xml
Expand Up @@ -27,39 +27,19 @@
<plugin>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-plugin</artifactId>
<version>${project.version}</version>
<configuration>
<mainClass>org.wildfly.swarm.examples.messaging.Main</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>
<id>package</id>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
<configuration>
<stdoutFile>target/stdout.log</stdoutFile>
<stderrFile>target/stderr.log</stderrFile>
</configuration>
</execution>
<execution>
<id>stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
Expand Down
54 changes: 54 additions & 0 deletions integs/pom.xml
Expand Up @@ -53,4 +53,58 @@
<module>messaging</module>
</modules>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>package</id>
<goals>
<goal>package</goal>
</goals>
</execution>
<execution>
<id>start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
<configuration>
<stdoutFile>target/stdout.log</stdoutFile>
<stderrFile>target/stderr.log</stderrFile>
</configuration>
</execution>
<execution>
<id>stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>

<profiles>
<profile>
<id>integs-plugin</id>
<properties>
<wildfly-swarm.useUberJar>false</wildfly-swarm.useUberJar>
</properties>
</profile>

<profile>
<id>integs-uberjar</id>
<properties>
<wildfly-swarm.useUberJar>true</wildfly-swarm.useUberJar>
</properties>
</profile>
</profiles>

</project>
98 changes: 73 additions & 25 deletions plugin/src/main/java/org/wildfly/swarm/plugin/maven/StartMojo.java
Expand Up @@ -84,6 +84,9 @@ public class StartMojo extends AbstractMojo {
@Parameter(alias = "stderrFile")
private File stderrFile;

@Parameter(alias = "useUberJar", defaultValue = "${wildfly-swarm.useUberJar}")
private boolean useUberJar;

boolean waitForProcess;

@Override
Expand All @@ -107,7 +110,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}

SwarmProcess process = null;
if (this.project.getPackaging().equals("war")) {

if (this.useUberJar) {
process = executeUberJar();
} else if (this.project.getPackaging().equals("war")) {
process = executeWar();
} else if (this.project.getPackaging().equals("jar")) {
process = executeJar();
Expand All @@ -125,37 +131,78 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
}

protected SwarmProcess executeUberJar() throws MojoFailureException {
getLog().info( "Starting -swarm.jar" );

String finalName = this.project.getBuild().getFinalName();

if (finalName.endsWith(".war") || finalName.endsWith(".jar")) {
finalName = finalName.substring(0, finalName.length() - 4);
}

String uberJarName = finalName + "-swarm.jar";

Path uberJar = Paths.get(this.projectBuildDir, uberJarName);

try {
SwarmProcess process = new SwarmExecutor()
.withDefaultSystemProperties()
.withProperties(this.properties)
.withEnvironment(this.environment)
.withStdoutFile(this.stdoutFile.toPath())
.withStderrFile(this.stderrFile.toPath())
.withExecutableJar(uberJar)
.execute();

process.awaitDeploy(2, TimeUnit.MINUTES);

if (!process.isAlive()) {
throw new MojoFailureException("Process failed to start");
}
if (process.getError() != null) {
throw new MojoFailureException("Error starting process", process.getError());
}

return process;
} catch (IOException e) {
throw new MojoFailureException("unable to execute uberjar", e);
} catch (InterruptedException e) {
throw new MojoFailureException("Error waiting for deployment", e);
}
}

protected SwarmProcess executeWar() throws MojoFailureException {
getLog().info( "Starting .war" );

SwarmExecutor executor = new SwarmExecutor();
executor.withDefaultSystemProperties();
executor.withClassPathEntries( dependencies(false));
executor.withClassPathEntries(dependencies(false));

try {

String finalName = this.project.getBuild().getFinalName();
if (!finalName.endsWith(".war")) {
finalName = finalName + ".war";
}
executor.withProperty( "wildfly.swarm.app.path", Paths.get(this.projectBuildDir, finalName).toString() );
executor.withProperties( this.properties );
executor.withProperty( "wildfly.swarm.context.path", this.contextPath );
executor.withProperty("wildfly.swarm.app.path", Paths.get(this.projectBuildDir, finalName).toString());
executor.withProperties(this.properties);
executor.withProperty("wildfly.swarm.context.path", this.contextPath);
executor.withDefaultMainClass();

executor.withEnvironment( this.environment );
executor.withEnvironment(this.environment);

executor.withStdoutFile( this.stdoutFile.toPath() );
executor.withStderrFile( this.stderrFile.toPath() );
executor.withStdoutFile(this.stdoutFile.toPath());
executor.withStderrFile(this.stderrFile.toPath());

SwarmProcess process = executor.execute();

process.awaitDeploy( 2, TimeUnit.MINUTES );
process.awaitDeploy(2, TimeUnit.MINUTES);

if ( ! process.isAlive() ) {
throw new MojoFailureException( "Process failed to start" );
if (!process.isAlive()) {
throw new MojoFailureException("Process failed to start");
}
if ( process.getError() != null ) {
throw new MojoFailureException( "Error starting process", process.getError() );
if (process.getError() != null) {
throw new MojoFailureException("Error starting process", process.getError());
}
return process;
} catch (IOException e) {
Expand All @@ -166,35 +213,36 @@ protected SwarmProcess executeWar() throws MojoFailureException {
}

protected SwarmProcess executeJar() throws MojoFailureException {
getLog().info( "Starting .jar" );

SwarmExecutor executor = new SwarmExecutor();
executor.withDefaultSystemProperties();

try {
executor.withClassPathEntries( dependencies(true) );
executor.withClassPathEntries(dependencies(true));
executor.withProperties(this.properties);
executor.withProperty( "wildfly.swarm.context.path", this.contextPath );
executor.withProperty("wildfly.swarm.context.path", this.contextPath);

if (this.mainClass != null) {
executor.withMainClass( this.mainClass );
executor.withMainClass(this.mainClass);
} else {
executor.withDefaultMainClass();
}

executor.withEnvironment( this.environment );
executor.withEnvironment(this.environment);

executor.withStdoutFile( this.stdoutFile.toPath() );
executor.withStderrFile( this.stderrFile.toPath() );
executor.withStdoutFile(this.stdoutFile.toPath());
executor.withStderrFile(this.stderrFile.toPath());

SwarmProcess process = executor.execute();

process.awaitDeploy( 2, TimeUnit.MINUTES );
process.awaitDeploy(2, TimeUnit.MINUTES);

if ( ! process.isAlive() ) {
throw new MojoFailureException( "Process failed to start" );
if (!process.isAlive()) {
throw new MojoFailureException("Process failed to start");
}
if ( process.getError() != null ) {
throw new MojoFailureException( "Error starting process", process.getError() );
if (process.getError() != null) {
throw new MojoFailureException("Error starting process", process.getError());
}
return process;
} catch (IOException e) {
Expand All @@ -215,7 +263,7 @@ List<Path> dependencies(boolean includeProjectArtifact) {
}

if (includeProjectArtifact) {
elements.add(Paths.get( this.project.getBuild().getOutputDirectory()) );
elements.add(Paths.get(this.project.getBuild().getOutputDirectory()));
}

return elements;
Expand Down
14 changes: 13 additions & 1 deletion pom.xml
Expand Up @@ -535,7 +535,6 @@
<module>servo</module>

<module>integration-tests</module>
<module>integs</module>
</modules>

<distributionManagement>
Expand All @@ -550,6 +549,19 @@
</distributionManagement>

<profiles>
<profile>
<id>integs-plugin</id>
<modules>
<module>integs</module>
</modules>
</profile>
<profile>
<id>integs-uberjar</id>
<modules>
<module>integs</module>
</modules>
</profile>

<profile>
<id>release</id>
<build>
Expand Down

0 comments on commit 5690259

Please sign in to comment.