Skip to content

Commit

Permalink
#782: added hawtio:camel maven goal
Browse files Browse the repository at this point in the history
  • Loading branch information
davsclaus committed Nov 30, 2013
1 parent 3a338b7 commit 123c5c3
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 18 deletions.
12 changes: 3 additions & 9 deletions hawtio-maven-plugin/pom.xml
Expand Up @@ -14,6 +14,7 @@

<dependencies>

<!-- maven plugin dependencies -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
Expand All @@ -36,20 +37,13 @@
<version>2.0</version>
</dependency>

<!-- logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j-version}</version>
<scope>provided</scope>
</dependency>
<!-- to embed hawtio app -->
<dependency>
<groupId>io.hawt</groupId>
<artifactId>hawtio-core</artifactId>
<artifactId>hawtio-app</artifactId>
<version>${project.version}</version>
</dependency>


</dependencies>

</project>
37 changes: 37 additions & 0 deletions hawtio-maven-plugin/src/main/java/io/hawt/maven/CamelMojo.java
@@ -0,0 +1,37 @@
package io.hawt.maven;

import java.util.List;

import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;

@Mojo(name = "camel", defaultPhase = LifecyclePhase.TEST_COMPILE, requiresDependencyResolution = ResolutionScope.RUNTIME)
public class CamelMojo extends RunMojo {

@Parameter(property = "camel.applicationContextUri")
private String applicationContextUri;

@Parameter(property = "camel.fileApplicationContextUri")
private String fileApplicationContextUri;

@Override
protected void addCustomArguments(List<String> args) {
if (applicationContextUri != null) {
args.add("-ac");
args.add(applicationContextUri);
} else if (fileApplicationContextUri != null) {
args.add("-fa");
args.add(fileApplicationContextUri);
}

if (mainClass != null) {
getLog().info("Using custom " + mainClass + " to initiate a CamelContext");
} else {
// use spring by default
getLog().info("Using org.apache.camel.spring.Main to initiate a CamelContext");
mainClass = "org.apache.camel.spring.Main";
}
}
}
Expand Up @@ -19,8 +19,8 @@ public void uncaughtException(Thread thread, Throwable throwable) {
synchronized (this) {
// only remember the first one
if (uncaughtException == null) {
uncaughtException = throwable; // will be reported
// eventually
uncaughtException = throwable;
// will be reported eventually
} else {
doLog = true;
}
Expand Down
40 changes: 33 additions & 7 deletions hawtio-maven-plugin/src/main/java/io/hawt/maven/RunMojo.java
Expand Up @@ -16,19 +16,22 @@
public class RunMojo extends BaseMojo {

@Parameter(property = "hawtio.port", defaultValue = "8080")
private int port;
int port;

@Parameter(property = "hawtio.context", defaultValue = "hawtio")
private String context;
String context;

@Parameter(property = "hawtio.mainClass")
private String mainClass;
String mainClass;

@Parameter(property = "hawtio.arguments")
private String[] arguments;
String[] arguments;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
// use hawtio-app
extendedPluginDependencyArtifactId = "hawtio-app";

getLog().info("hawtio web console at http://localhost:" + port + "/" + context);

try {
Expand Down Expand Up @@ -84,9 +87,25 @@ protected void doExecute() throws Exception {
final Thread bootstrapThread = new Thread(threadGroup, new Runnable() {
public void run() {
try {
beforeBootstrapHawtio();

getLog().info("Starting hawtio ...");
getLog().info("*************************************");
Method hawtioMain = Thread.currentThread().getContextClassLoader().loadClass("io.hawt.app.App")
.getMethod("main", new Class[] {String[].class});
if (!hawtioMain.isAccessible()) {
getLog().debug("Setting accessibility to true in order to invoke main().");
hawtioMain.setAccessible(true);
}
String[] args = new String[]{"--port", "" + port, "--join", "false"};
hawtioMain.invoke(hawtioMain, new Object[]{args});

afterBootstrapHawtio();

beforeBootstrapMain();

getLog().info("Starting " + mainClass + "...");
getLog().info("*************************************");
Method main = Thread.currentThread().getContextClassLoader().loadClass(mainClass)
.getMethod("main", new Class[] {String[].class});
if (!main.isAccessible()) {
Expand All @@ -96,6 +115,7 @@ public void run() {
main.invoke(main, new Object[] {arguments});

afterBootstrapMain();

} catch (Exception e) { // just pass it on
// let it be printed so end users can see the exception on the console
getLog().error("*************************************");
Expand All @@ -108,8 +128,6 @@ public void run() {
}, mainClass + ".main()");

bootstrapThread.setContextClassLoader(getClassLoader());
// TODO: system properties, and restore original afterwards
// setSystemProperties();

bootstrapThread.start();
joinNonDaemonThreads(threadGroup);
Expand All @@ -122,7 +140,7 @@ public void run() {
}

if (threadGroup.getUncaughtException() != null) {
throw new MojoExecutionException(null, threadGroup.getUncaughtException());
throw new MojoExecutionException("Uncaught exception", threadGroup.getUncaughtException());
}
}

Expand All @@ -134,4 +152,12 @@ protected void afterBootstrapMain() {
// noop
}

protected void beforeBootstrapHawtio() {
// noop
}

protected void afterBootstrapHawtio() {
// noop
}

}

0 comments on commit 123c5c3

Please sign in to comment.