activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1404116 - in /activemq/trunk/activemq-tooling/maven-activemq-plugin/src: main/java/org/apache/activemq/maven/ test/ test/java/ test/java/org/ test/java/org/apache/ test/java/org/apache/activemq/ test/java/org/apache/activemq/maven/
Date Wed, 31 Oct 2012 12:49:31 GMT
Author: tabish
Date: Wed Oct 31 12:49:30 2012
New Revision: 1404116

URL: http://svn.apache.org/viewvc?rev=1404116&view=rev
Log:
apply patch for: https://issues.apache.org/jira/browse/AMQ-4140

Added:
    activemq/trunk/activemq-tooling/maven-activemq-plugin/src/main/java/org/apache/activemq/maven/XBeanFileResolver.java
  (with props)
    activemq/trunk/activemq-tooling/maven-activemq-plugin/src/test/
    activemq/trunk/activemq-tooling/maven-activemq-plugin/src/test/java/
    activemq/trunk/activemq-tooling/maven-activemq-plugin/src/test/java/org/
    activemq/trunk/activemq-tooling/maven-activemq-plugin/src/test/java/org/apache/
    activemq/trunk/activemq-tooling/maven-activemq-plugin/src/test/java/org/apache/activemq/
    activemq/trunk/activemq-tooling/maven-activemq-plugin/src/test/java/org/apache/activemq/maven/
    activemq/trunk/activemq-tooling/maven-activemq-plugin/src/test/java/org/apache/activemq/maven/XBeanFileResolverTest.java
  (with props)
Modified:
    activemq/trunk/activemq-tooling/maven-activemq-plugin/src/main/java/org/apache/activemq/maven/BrokerMojo.java

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?rev=1404116&r1=1404115&r2=1404116&view=diff
==============================================================================
--- 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
Wed Oct 31 12:49:30 2012
@@ -82,10 +82,28 @@ public class BrokerMojo extends Abstract
      */
     private Properties systemProperties;
 
+    /**
+     * Skip execution of the ActiveMQ Broker plugin if set to true
+     * 
+     * @parameter expression="${skip}"
+     */
+    private boolean skip;
+
     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) {

Added: activemq/trunk/activemq-tooling/maven-activemq-plugin/src/main/java/org/apache/activemq/maven/XBeanFileResolver.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-tooling/maven-activemq-plugin/src/main/java/org/apache/activemq/maven/XBeanFileResolver.java?rev=1404116&view=auto
==============================================================================
--- activemq/trunk/activemq-tooling/maven-activemq-plugin/src/main/java/org/apache/activemq/maven/XBeanFileResolver.java
(added)
+++ activemq/trunk/activemq-tooling/maven-activemq-plugin/src/main/java/org/apache/activemq/maven/XBeanFileResolver.java
Wed Oct 31 12:49:30 2012
@@ -0,0 +1,85 @@
+/**
+ * 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.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+/**
+ * Helper to convert relative paths to XBean description files to URL-compliant absolute
paths.
+ * 
+ * @author Marc CARRE <carre.marc@gmail.com>
+ */
+public class XBeanFileResolver {
+    private static final String XBEAN_FILE = "xbean:file:";
+
+    private XBeanFileResolver() {
+        // Utility class, should not be instantiated.
+    }
+
+    /**
+     * Check if the provided path is an URL to a XBean file (xbean:file:<path/to/file>)
+     */
+    public static boolean isXBeanFile(final String configUri) {
+        return configUri.startsWith(XBEAN_FILE);
+    }
+
+    /**
+     * Convert provided path into a URL-style absolute path. See also:
+     * http://maven.apache.org/plugin-developers/common-bugs.html# Converting_between_URLs_and_Filesystem_Paths
+     */
+    public static String toUrlCompliantAbsolutePath(final String configUri) {
+        if (!isXBeanFile(configUri))
+            return configUri;
+
+        String filePath = extractFilePath(configUri);
+        return XBEAN_FILE + toAbsolutePath(filePath);
+    }
+
+    private static String extractFilePath(final String configUri) {
+        return configUri.substring(getIndexFilePath(configUri), configUri.length());
+    }
+
+    private static int getIndexFilePath(final String configUri) {
+        return configUri.indexOf(XBEAN_FILE) + XBEAN_FILE.length();
+    }
+
+    private static String toAbsolutePath(final String path) {
+        try {
+            final URL url = new File(path).toURI().toURL();
+            return toFilePath(url);
+        } catch (MalformedURLException e) {
+            throw new RuntimeException("Failed to resolve relative path for: " + path, e);
+        }
+    }
+
+    private static String toFilePath(final URL url) {
+        String filePath = url.getFile();
+        return underWindows() ? removePrependingSlash(filePath) : filePath;
+    }
+
+    private static String removePrependingSlash(String filePath) {
+        // Remove prepending '/' because path would be /C:/temp/file.txt, as URL would be
file:/C:/temp/file.txt
+        return filePath.substring(1, filePath.length());
+    }
+
+    private static boolean underWindows() {
+        String os = System.getProperty("os.name").toLowerCase();
+        return (os.indexOf("win") >= 0);
+    }
+}

Propchange: activemq/trunk/activemq-tooling/maven-activemq-plugin/src/main/java/org/apache/activemq/maven/XBeanFileResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/trunk/activemq-tooling/maven-activemq-plugin/src/test/java/org/apache/activemq/maven/XBeanFileResolverTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-tooling/maven-activemq-plugin/src/test/java/org/apache/activemq/maven/XBeanFileResolverTest.java?rev=1404116&view=auto
==============================================================================
--- activemq/trunk/activemq-tooling/maven-activemq-plugin/src/test/java/org/apache/activemq/maven/XBeanFileResolverTest.java
(added)
+++ activemq/trunk/activemq-tooling/maven-activemq-plugin/src/test/java/org/apache/activemq/maven/XBeanFileResolverTest.java
Wed Oct 31 12:49:30 2012
@@ -0,0 +1,52 @@
+/**
+ * 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 static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.activemq.maven.XBeanFileResolver;
+import org.junit.Test;
+
+/**
+ * Test for: Helper to convert relative paths to XBean description files to URL-compliant
absolute paths.
+ * 
+ * @author Marc CARRE <carre.marc@gmail.com>
+ */
+public class XBeanFileResolverTest {
+    private static final String XBEAN_FILE = "xbean:file:";
+
+    @Test
+    public void urlToXBeanFileShouldBeResolvedToAbsolutePath() throws IOException {
+        String currentDirectory = getCurrentDirectoryLinuxStyle();
+        String relativeXBeanFilePath = "src/main/resources/activemq.xml";
+
+        // e.g. xbean:file:C:/dev/src/active-mq/activemq-tooling/maven-activemq-plugin/src/main/resources/activemq.xml
+        String expectedUrl = XBEAN_FILE + currentDirectory + "/" + relativeXBeanFilePath;
+
+        String actualUrl = XBeanFileResolver.toUrlCompliantAbsolutePath(XBEAN_FILE + relativeXBeanFilePath);
+
+        assertEquals(expectedUrl, actualUrl);
+    }
+
+    private String getCurrentDirectoryLinuxStyle() throws IOException {
+        String currentDirectory = new File(".").getCanonicalPath();
+        return currentDirectory.replace("\\", "/");
+    }
+}

Propchange: activemq/trunk/activemq-tooling/maven-activemq-plugin/src/test/java/org/apache/activemq/maven/XBeanFileResolverTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message