activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r547575 - in /activemq/trunk/activemq-tooling/maven-activemq-plugin: pom.xml src/main/java/org/apache/activemq/maven/BrokerMojo.java
Date Fri, 15 Jun 2007 08:28:56 GMT
Author: aco
Date: Fri Jun 15 01:28:55 2007
New Revision: 547575

URL: http://svn.apache.org/viewvc?view=rev&rev=547575
Log:
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!

Modified:
    activemq/trunk/activemq-tooling/maven-activemq-plugin/pom.xml
    activemq/trunk/activemq-tooling/maven-activemq-plugin/src/main/java/org/apache/activemq/maven/BrokerMojo.java

Modified: activemq/trunk/activemq-tooling/maven-activemq-plugin/pom.xml
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-tooling/maven-activemq-plugin/pom.xml?view=diff&rev=547575&r1=547574&r2=547575
==============================================================================
--- activemq/trunk/activemq-tooling/maven-activemq-plugin/pom.xml (original)
+++ activemq/trunk/activemq-tooling/maven-activemq-plugin/pom.xml Fri Jun 15 01:28:55 2007
@@ -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>

Modified: activemq/trunk/activemq-tooling/maven-activemq-plugin/src/main/java/org/apache/activemq/maven/BrokerMojo.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-tooling/maven-activemq-plugin/src/main/java/org/apache/activemq/maven/BrokerMojo.java?view=diff&rev=547575&r1=547574&r2=547575
==============================================================================
--- activemq/trunk/activemq-tooling/maven-activemq-plugin/src/main/java/org/apache/activemq/maven/BrokerMojo.java
(original)
+++ activemq/trunk/activemq-tooling/maven-activemq-plugin/src/main/java/org/apache/activemq/maven/BrokerMojo.java
Fri Jun 15 01:28:55 2007
@@ -17,101 +17,122 @@
  * 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
+     *
+     * 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="${project.build.directory}"
+     * @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;
-
-    public void execute()
-            throws MojoExecutionException {
+    private Properties systemProperties;
 
-        File out = outputDirectory;
+    public void execute() throws MojoExecutionException {
+        try {
+            setSystemProperties();
+            getLog().info("Loading broker configUri: " + configUri);
 
-        // Create output directory if it doesn't exist.
-        if (!out.exists()) {
-            out.mkdirs();
+            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);
+            }
+        } catch (Exception e) {
+            throw new MojoExecutionException("Failed to start ActiveMQ Broker", e);
         }
+    }
 
-        String[] args = new String[2];
-        if (configFile != null) {
-            File config;
-            try {
-                config = copy(configFile);
-            } catch (IOException e) {
-                throw new MojoExecutionException(e.getMessage());
+    /**
+     * Wait for a shutdown invocation elsewhere
+     * @throws Exception
+     */
+    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();
+                }
             }
+        });
 
-            args[0] = "start";
-            args[1] = "xbean:" + (config.toURI()).toString();
-        } else {
-            args[0] = "start";
-            args[1] = url;
+        // Wait for any shutdown event
+        synchronized(shutdown) {
+            while( !shutdown[0] ) {
+                try {
+                    shutdown.wait();
+                } catch (InterruptedException e) {
+                }
+            }
         }
 
-        Main.main(args);
+        // Stop broker
+        broker.stop();
     }
 
     /**
-     * Copy activemq configuration file to output directory.
-     *
-     * @param source
-     * @return
-     * @throws java.io.IOException
+     * Set system properties
      */
-    public File copy(File source) throws IOException {
-        FileChannel in = null, out = null;
-        File dest = new File(outputDirectory.getAbsolutePath() + File.separator + source.getName());
-
-        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();
-        }
+    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");
 
-        return dest;
+        // Overwrite any custom properties
+        System.getProperties().putAll(systemProperties);
     }
 }



Mime
View raw message