You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by ld...@apache.org on 2011/03/21 12:28:10 UTC

svn commit: r1083735 - in /karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features: CustomBundleURLStreamHandlerFactory.java FeatureURLHandler.java ValidateFeaturesMojo.java WarURLHandler.java

Author: ldywicki
Date: Mon Mar 21 11:28:10 2011
New Revision: 1083735

URL: http://svn.apache.org/viewvc?rev=1083735&view=rev
Log:
[KARAF-528] Fix WAR url prefix handling in Maven plugin

Added:
    karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/WarURLHandler.java
Modified:
    karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/CustomBundleURLStreamHandlerFactory.java
    karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/FeatureURLHandler.java
    karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/ValidateFeaturesMojo.java

Modified: karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/CustomBundleURLStreamHandlerFactory.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/CustomBundleURLStreamHandlerFactory.java?rev=1083735&r1=1083734&r2=1083735&view=diff
==============================================================================
--- karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/CustomBundleURLStreamHandlerFactory.java (original)
+++ karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/CustomBundleURLStreamHandlerFactory.java Mon Mar 21 11:28:10 2011
@@ -27,8 +27,9 @@ public class CustomBundleURLStreamHandle
     private static final String FEATURE_URI_PREFIX = "feature";
     private static final String SPRING_URI_PREFIX = "spring";
     private static final String BLUEPRINT_URI_PREFIX = "blueprint";
-	
-	public URLStreamHandler createURLStreamHandler(String protocol) {
+    private static final String WAR_URI_PREFIX = "war";
+
+    public URLStreamHandler createURLStreamHandler(String protocol) {
 		if (protocol.equals(MVN_URI_PREFIX)) {
 			return new org.ops4j.pax.url.mvn.Handler();
 		} else if (protocol.equals(WRAP_URI_PREFIX)){
@@ -39,6 +40,8 @@ public class CustomBundleURLStreamHandle
 			return new SpringURLHandler();
 		} else if (protocol.equals(BLUEPRINT_URI_PREFIX)){
 			return new BlueprintURLHandler();
+        } else if (protocol.equals(WAR_URI_PREFIX)) {
+            return new WarURLHandler();
 		} else {
 			return null;
 		}

Modified: karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/FeatureURLHandler.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/FeatureURLHandler.java?rev=1083735&r1=1083734&r2=1083735&view=diff
==============================================================================
--- karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/FeatureURLHandler.java (original)
+++ karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/FeatureURLHandler.java Mon Mar 21 11:28:10 2011
@@ -56,7 +56,7 @@ public class FeatureURLHandler extends U
         }
         featureXmlURL = new URL(url.getPath());
 
-        logger.debug("Blueprint xml URL is: [" + featureXmlURL + "]");
+        logger.debug("Feature xml URL is: [" + featureXmlURL + "]");
         return new Connection(url);
     }
 
@@ -82,8 +82,8 @@ public class FeatureURLHandler extends U
                 os.close();
                 return new ByteArrayInputStream(os.toByteArray());
             } catch (Exception e) {
-                logger.error("Error opening blueprint xml url", e);
-                throw (IOException) new IOException("Error opening blueprint xml url").initCause(e);
+                logger.error("Error opening feature xml url", e);
+                throw (IOException) new IOException("Error opening features xml url").initCause(e);
             }
         }
     }

Modified: karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/ValidateFeaturesMojo.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/ValidateFeaturesMojo.java?rev=1083735&r1=1083734&r2=1083735&view=diff
==============================================================================
--- karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/ValidateFeaturesMojo.java (original)
+++ karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/ValidateFeaturesMojo.java Mon Mar 21 11:28:10 2011
@@ -157,7 +157,6 @@ public class ValidateFeaturesMojo extend
             analyze(repository);
             validate(repository);
         } catch (Exception e) {
-            e.printStackTrace();
             throw new MojoExecutionException(String.format("Unable to validate %s: %s", file.getAbsolutePath(), e.getMessage()), e);
         }
 
@@ -454,8 +453,9 @@ public class ValidateFeaturesMojo extend
             try {
                 is = new BufferedInputStream(new URL(bundle).openStream());
             } catch (Exception e){
-                e.printStackTrace();
+                getLog().warn("Error while opening artifact", e);
             }
+
             try {
                 is.mark(256 * 1024);
                 JarInputStream jar = new JarInputStream(is);
@@ -466,7 +466,9 @@ public class ValidateFeaturesMojo extend
                 
                 return m;
             } finally {
-                is.close();
+                if (is != null) { // just in case when we did not open bundle
+                    is.close();
+                }
             }
         } else {
             Artifact mvnArtifact = (Artifact) artifact;

Added: karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/WarURLHandler.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/WarURLHandler.java?rev=1083735&view=auto
==============================================================================
--- karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/WarURLHandler.java (added)
+++ karaf/branches/karaf-2.2.x/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/WarURLHandler.java Mon Mar 21 11:28:10 2011
@@ -0,0 +1,66 @@
+/**
+ *
+ * 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.karaf.tooling.features;
+
+import org.apache.karaf.deployer.blueprint.BlueprintTransformer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+
+/**
+ * Simple workaround for "WAR" prefix.
+ */
+public class WarURLHandler extends URLStreamHandler {
+
+	private final Logger logger = LoggerFactory.getLogger(WarURLHandler.class);
+
+	private static String SYNTAX = "war: war-uri";
+
+	private URL warURL;
+
+    /**
+     * Open the connection for the given URL.
+     *
+     * @param url the url from which to open a connection.
+     * @return a connection on the specified URL.
+     * @throws java.io.IOException if an error occurs or if the URL is malformed.
+     */
+    @Override
+	public URLConnection openConnection(URL url) throws IOException {
+		if (url.getPath() == null || url.getPath().trim().length() == 0) {
+			throw new MalformedURLException ("Path can not be null or empty. Syntax: " + SYNTAX );
+		}
+
+        // We don't resolve any specific data here, just forward it to another URL Stream Handler
+		warURL = new URL(url.getPath());
+		return warURL.openConnection();
+	}
+
+	public URL getWarURL() {
+		return warURL;
+	}
+
+}