You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2014/01/20 20:03:42 UTC

git commit: https://issues.apache.org/jira/browse/AMQ-4509 https://issues.apache.org/jira/browse/AMQ-3452

Updated Branches:
  refs/heads/trunk f7cbe9fa1 -> a50f01127


https://issues.apache.org/jira/browse/AMQ-4509
https://issues.apache.org/jira/browse/AMQ-3452

Adds stop goal to the maven activemq plugin.  

Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/a50f0112
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/a50f0112
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/a50f0112

Branch: refs/heads/trunk
Commit: a50f01127276f45797cbe8623790aa2de818841d
Parents: f7cbe9f
Author: Timothy Bish <ta...@gmai.com>
Authored: Mon Jan 20 14:03:39 2014 -0500
Committer: Timothy Bish <ta...@gmai.com>
Committed: Mon Jan 20 14:03:39 2014 -0500

----------------------------------------------------------------------
 activemq-tooling/activemq-maven-plugin/pom.xml  |   2 +-
 .../java/org/apache/activemq/maven/Broker.java  | 120 +++++++++++++
 .../org/apache/activemq/maven/BrokerMojo.java   | 179 -------------------
 .../apache/activemq/maven/StartBrokerMojo.java  | 110 ++++++++++++
 .../apache/activemq/maven/StopBrokerMojo.java   |  47 +++++
 5 files changed, 278 insertions(+), 180 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/a50f0112/activemq-tooling/activemq-maven-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/activemq-tooling/activemq-maven-plugin/pom.xml b/activemq-tooling/activemq-maven-plugin/pom.xml
index 6f231e4..e7c3ae9 100644
--- a/activemq-tooling/activemq-maven-plugin/pom.xml
+++ b/activemq-tooling/activemq-maven-plugin/pom.xml
@@ -26,7 +26,7 @@
 
   <artifactId>activemq-maven-plugin</artifactId>
   <packaging>maven-plugin</packaging>
-  <name>ActiveMQ :: StartUp Plugin</name>
+  <name>ActiveMQ :: StartUp/Stop Plugin</name>
 
   <dependencies>
     <dependency>

http://git-wip-us.apache.org/repos/asf/activemq/blob/a50f0112/activemq-tooling/activemq-maven-plugin/src/main/java/org/apache/activemq/maven/Broker.java
----------------------------------------------------------------------
diff --git a/activemq-tooling/activemq-maven-plugin/src/main/java/org/apache/activemq/maven/Broker.java b/activemq-tooling/activemq-maven-plugin/src/main/java/org/apache/activemq/maven/Broker.java
new file mode 100644
index 0000000..14a0275
--- /dev/null
+++ b/activemq-tooling/activemq-maven-plugin/src/main/java/org/apache/activemq/maven/Broker.java
@@ -0,0 +1,120 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.maven;
+
+import java.util.Properties;
+
+import org.apache.activemq.broker.BrokerFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.maven.plugin.MojoExecutionException;
+
+public class Broker {
+
+    private static BrokerService broker;
+
+    private static boolean[] shutdown;
+
+    private static Thread shutdownThread;
+
+    public static void start(boolean fork, String configUri) throws MojoExecutionException {
+
+        if (broker != null) {
+            throw new MojoExecutionException("A local broker is already running");
+        }
+
+        try {
+            broker = BrokerFactory.createBroker(configUri);
+            if (fork) {
+                new Thread(new Runnable() {
+                    @Override
+                    public void run() {
+                        try {
+                            broker.start();
+                            waitForShutdown();
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                    }
+                }).start();
+            } else {
+                broker.start();
+                waitForShutdown();
+            }
+        } catch (Exception e) {
+            throw new MojoExecutionException("Failed to start the ActiveMQ Broker", e);
+        }
+    }
+
+    public static void stop() throws MojoExecutionException {
+
+        if (broker == null) {
+            throw new MojoExecutionException("The local broker is not running");
+        }
+
+        try {
+            broker.stop();
+            broker.waitUntilStopped();
+            broker = null;
+
+            Runtime.getRuntime().removeShutdownHook(shutdownThread);
+
+            // Terminate the shutdown hook thread
+            synchronized (shutdown) {
+                shutdown[0] = true;
+                shutdown.notify();
+            }
+        } catch (Exception e) {
+            throw new MojoExecutionException("Failed to stop the ActiveMQ Broker", e);
+        }
+    }
+
+    /**
+     * Wait for a shutdown invocation elsewhere
+     *
+     * @throws Exception
+     */
+    protected static void waitForShutdown() throws Exception {
+        shutdown = new boolean[] { false };
+
+        shutdownThread = new Thread() {
+            @Override
+            public void run() {
+                synchronized (shutdown) {
+                    shutdown[0] = true;
+                    shutdown.notify();
+                }
+            }
+        };
+
+        Runtime.getRuntime().addShutdownHook(shutdownThread);
+
+        // Wait for any shutdown event
+        synchronized (shutdown) {
+            while (!shutdown[0]) {
+                try {
+                    shutdown.wait();
+                } catch (InterruptedException e) {
+                }
+            }
+        }
+
+        // Stop broker
+        if (broker != null) {
+            broker.stop();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/activemq/blob/a50f0112/activemq-tooling/activemq-maven-plugin/src/main/java/org/apache/activemq/maven/BrokerMojo.java
----------------------------------------------------------------------
diff --git a/activemq-tooling/activemq-maven-plugin/src/main/java/org/apache/activemq/maven/BrokerMojo.java b/activemq-tooling/activemq-maven-plugin/src/main/java/org/apache/activemq/maven/BrokerMojo.java
deleted file mode 100644
index 6eabdbe..0000000
--- a/activemq-tooling/activemq-maven-plugin/src/main/java/org/apache/activemq/maven/BrokerMojo.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.activemq.maven;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.util.Properties;
-
-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;
-
-/**
- * Goal which starts an activemq broker.
- *
- * @goal run
- * @phase process-sources
- */
-public class BrokerMojo extends AbstractMojo {
-    /**
-     * The maven project.
-     *
-     * @parameter property="project" default-value="${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 property="configUri"
-     *            default-value="broker:(tcp://localhost:61616)?useJmx=false&persistent=false"
-     * @required
-     */
-    private String configUri;
-
-    /**
-     * Indicates whether to fork the broker, useful for integration tests.
-     *
-     * @parameter property="fork" default-value="false"
-     */
-    private boolean fork;
-
-    /**
-     * System properties to add
-     *
-     * @parameter property="systemProperties"
-     */
-    private Properties systemProperties;
-
-    /**
-     * Skip execution of the ActiveMQ Broker plugin if set to true
-     *
-     * @parameter property="skip"
-     */
-    private boolean skip;
-
-    @Override
-    public void execute() throws MojoExecutionException {
-        try {
-            if (skip) {
-                getLog().info("Skipped execution of ActiveMQ Broker");
-                return;
-            }
-
-            setSystemProperties();
-
-            getLog().info("Loading broker configUri: " + configUri);
-            if (XBeanFileResolver.isXBeanFile(configUri)) {
-                getLog().debug("configUri before transformation: " + configUri);
-                configUri = XBeanFileResolver.toUrlCompliantAbsolutePath(configUri);
-                getLog().debug("configUri after transformation: " + configUri);
-            }
-
-            final BrokerService broker = BrokerFactory.createBroker(configUri);
-            if (fork) {
-                new Thread(new Runnable() {
-                    @Override
-                    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);
-        }
-    }
-
-    /**
-     * 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() {
-            @Override
-            public void run() {
-                synchronized (shutdown) {
-                    shutdown[0] = true;
-                    shutdown.notify();
-                }
-            }
-        });
-
-        // Wait for any shutdown event
-        synchronized (shutdown) {
-            while (!shutdown[0]) {
-                try {
-                    shutdown.wait();
-                } catch (InterruptedException e) {
-                }
-            }
-        }
-
-        // 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);
-    }
-}

http://git-wip-us.apache.org/repos/asf/activemq/blob/a50f0112/activemq-tooling/activemq-maven-plugin/src/main/java/org/apache/activemq/maven/StartBrokerMojo.java
----------------------------------------------------------------------
diff --git a/activemq-tooling/activemq-maven-plugin/src/main/java/org/apache/activemq/maven/StartBrokerMojo.java b/activemq-tooling/activemq-maven-plugin/src/main/java/org/apache/activemq/maven/StartBrokerMojo.java
new file mode 100644
index 0000000..eef68aa
--- /dev/null
+++ b/activemq-tooling/activemq-maven-plugin/src/main/java/org/apache/activemq/maven/StartBrokerMojo.java
@@ -0,0 +1,110 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.maven;
+
+import java.util.Properties;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * Goal which starts an activemq broker.
+ *
+ * @goal run
+ * @phase process-sources
+ */
+public class StartBrokerMojo extends AbstractMojo {
+
+    /**
+     * The maven project.
+     *
+     * @parameter property="project" default-value="${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 property="configUri"
+     *            default-value="broker:(tcp://localhost:61616)?useJmx=false&persistent=false"
+     * @required
+     */
+    private String configUri;
+
+    /**
+     * Indicates whether to fork the broker, useful for integration tests.
+     *
+     * @parameter property="fork" default-value="false"
+     */
+    private boolean fork;
+
+    /**
+     * System properties to add
+     *
+     * @parameter property="systemProperties"
+     */
+    private Properties systemProperties;
+
+    /**
+     * Skip execution of the ActiveMQ Broker plugin if set to true
+     *
+     * @parameter property="skip"
+     */
+    private boolean skip;
+
+    @Override
+    public void execute() throws MojoExecutionException {
+        if (skip) {
+            getLog().info("Skipped execution of ActiveMQ Broker");
+            return;
+        }
+
+        setSystemProperties();
+
+        getLog().info("Loading broker configUri: " + configUri);
+        if (XBeanFileResolver.isXBeanFile(configUri)) {
+            getLog().debug("configUri before transformation: " + configUri);
+            configUri = XBeanFileResolver.toUrlCompliantAbsolutePath(configUri);
+            getLog().debug("configUri after transformation: " + configUri);
+        }
+
+        Broker.start(fork, configUri);
+
+        getLog().info("Started the ActiveMQ Broker");
+    }
+
+    /**
+     * 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);
+    }
+}

http://git-wip-us.apache.org/repos/asf/activemq/blob/a50f0112/activemq-tooling/activemq-maven-plugin/src/main/java/org/apache/activemq/maven/StopBrokerMojo.java
----------------------------------------------------------------------
diff --git a/activemq-tooling/activemq-maven-plugin/src/main/java/org/apache/activemq/maven/StopBrokerMojo.java b/activemq-tooling/activemq-maven-plugin/src/main/java/org/apache/activemq/maven/StopBrokerMojo.java
new file mode 100644
index 0000000..a0b15eb
--- /dev/null
+++ b/activemq-tooling/activemq-maven-plugin/src/main/java/org/apache/activemq/maven/StopBrokerMojo.java
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.maven;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * Goal which stops an activemq broker.
+ *
+ * @goal stop
+ * @phase process-sources
+ */
+public class StopBrokerMojo extends AbstractMojo {
+
+    /**
+     * Skip execution of the ActiveMQ Broker plugin if set to true
+     *
+     * @parameter property="skip"
+     */
+    private boolean skip;
+
+    public void execute() throws MojoExecutionException {
+        if (skip) {
+            getLog().info("Skipped execution of ActiveMQ Broker");
+            return;
+        }
+
+        Broker.stop();
+
+        getLog().info("Stopped the ActiveMQ Broker");
+    }
+}