Updated the maven-activemq-plugin

https://issues.apache.org/activemq/browse/AMQ-1223
https://issues.apache.org/activemq/browse/AMQ-1224
https://issues.apache.org/activemq/browse/AMQ-1222

Thanks for the patches and comments Tim!

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@547575 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Adrian T. Co 2007-06-15 08:28:55 +00:00
parent 78761dde4e
commit dca58fa68c
2 changed files with 113 additions and 103 deletions

View File

@ -17,12 +17,12 @@
<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">
<modelVersion>4.0.0</modelVersion>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.activemq.tooling</groupId>
<artifactId>activemq-tooling</artifactId>
<version>5.0-SNAPSHOT</version>
<parent>
<groupId>org.apache.activemq.tooling</groupId>
<artifactId>activemq-tooling</artifactId>
<version>5.0-SNAPSHOT</version>
</parent>
<artifactId>maven-activemq-plugin</artifactId>
@ -30,38 +30,27 @@
<name>ActiveMQ :: StartUp Plugin</name>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-console</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activeio-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbynet</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_1.1_spec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-j2ee-management_1.0_spec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-spring</artifactId>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -17,101 +17,122 @@ package org.apache.activemq.maven;
* limitations under the License.
*/
import org.apache.activemq.console.Main;
import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.util.Properties;
/**
* Goal which starts activemq broker.
* Goal which starts an activemq broker.
*
* @goal run
* @phase process-sources
*/
public class BrokerMojo
extends AbstractMojo {
public class BrokerMojo extends AbstractMojo {
/**
* Location of the output directory. Defaults to target.
* The maven project.
*
* @parameter expression="${project}"
* @required
* @readonly
*/
protected MavenProject project;
/**
* The broker configuration uri
*
* @parameter expression="${project.build.directory}"
* The list of currently supported URI syntaxes is described
* <a href="http://activemq.apache.org/how-do-i-embed-a-broker-inside-a-connection.html">here</a>
*
* @parameter expression="${configUri}" default-value="broker:(tcp://localhost:61616)?useJmx=false&persistent=false"
* @required
*/
private File outputDirectory;
private String configUri;
/**
* Location of activemq xml config file.
* Indicates whether to fork the broker, useful for integration tests.
*
* @parameter expression="${configFile}"
* @parameter expression="${fork}" default-value="false"
*/
private File configFile;
private boolean fork;
/**
* Broker URL.
*
* @parameter expression="${url}" default-value="broker:(tcp://localhost:61616)?useJmx=false"
* System properties to add
* @parameter expression="${systemProperties}"
*/
private String url;
private Properties systemProperties;
public void execute()
throws MojoExecutionException {
public void execute() throws MojoExecutionException {
try {
setSystemProperties();
getLog().info("Loading broker configUri: " + configUri);
File out = outputDirectory;
// Create output directory if it doesn't exist.
if (!out.exists()) {
out.mkdirs();
}
String[] args = new String[2];
if (configFile != null) {
File config;
try {
config = copy(configFile);
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage());
final BrokerService broker = BrokerFactory.createBroker(configUri);
if (fork) {
new Thread(new Runnable() {
public void run() {
try {
broker.start();
waitForShutdown(broker);
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
} else {
broker.start();
waitForShutdown(broker);
}
args[0] = "start";
args[1] = "xbean:" + (config.toURI()).toString();
} else {
args[0] = "start";
args[1] = url;
} catch (Exception e) {
throw new MojoExecutionException("Failed to start ActiveMQ Broker", e);
}
Main.main(args);
}
/**
* Copy activemq configuration file to output directory.
*
* @param source
* @return
* @throws java.io.IOException
* Wait for a shutdown invocation elsewhere
* @throws Exception
*/
public File copy(File source) throws IOException {
FileChannel in = null, out = null;
File dest = new File(outputDirectory.getAbsolutePath() + File.separator + source.getName());
protected void waitForShutdown(BrokerService broker) throws Exception {
final boolean[] shutdown = new boolean[] {false};
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
synchronized(shutdown) {
shutdown[0]=true;
shutdown.notify();
}
}
});
try {
in = new FileInputStream(source).getChannel();
out = new FileOutputStream(dest).getChannel();
long size = in.size();
MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);
out.write(buf);
} finally {
if (in != null) in.close();
if (out != null) out.close();
// Wait for any shutdown event
synchronized(shutdown) {
while( !shutdown[0] ) {
try {
shutdown.wait();
} catch (InterruptedException e) {
}
}
}
return dest;
// Stop broker
broker.stop();
}
/**
* Set system properties
*/
protected void setSystemProperties() {
// Set the default properties
System.setProperty("activemq.base", project.getBuild().getDirectory() + "/");
System.setProperty("activemq.home", project.getBuild().getDirectory() + "/");
System.setProperty("org.apache.activemq.UseDedicatedTaskRunner", "true");
System.setProperty("org.apache.activemq.default.directory.prefix", project.getBuild().getDirectory() + "/");
System.setProperty("derby.system.home", project.getBuild().getDirectory() + "/");
System.setProperty("derby.storage.fileSyncTransactionLog", "true");
// Overwrite any custom properties
System.getProperties().putAll(systemProperties);
}
}