You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by cs...@apache.org on 2012/05/16 16:13:31 UTC

svn commit: r1339179 - in /karaf/trunk/main/src: main/java/org/apache/karaf/main/util/SimpleMavenResolver.java test/java/org/apache/karaf/main/util/SimpleMavenResolverTest.java

Author: cschneider
Date: Wed May 16 14:13:30 2012
New Revision: 1339179

URL: http://svn.apache.org/viewvc?rev=1339179&view=rev
Log:
KARAF-1296 Bugfix. Allow extension and qualifier at the same time and add test

Added:
    karaf/trunk/main/src/test/java/org/apache/karaf/main/util/SimpleMavenResolverTest.java
Modified:
    karaf/trunk/main/src/main/java/org/apache/karaf/main/util/SimpleMavenResolver.java

Modified: karaf/trunk/main/src/main/java/org/apache/karaf/main/util/SimpleMavenResolver.java
URL: http://svn.apache.org/viewvc/karaf/trunk/main/src/main/java/org/apache/karaf/main/util/SimpleMavenResolver.java?rev=1339179&r1=1339178&r2=1339179&view=diff
==============================================================================
--- karaf/trunk/main/src/main/java/org/apache/karaf/main/util/SimpleMavenResolver.java (original)
+++ karaf/trunk/main/src/main/java/org/apache/karaf/main/util/SimpleMavenResolver.java Wed May 16 14:13:30 2012
@@ -81,36 +81,30 @@ public class SimpleMavenResolver impleme
      * @param name input artifact info
      * @return path as supplied or a default maven repo path
      */
-    private static String fromMaven(URI name) {
+    static String fromMaven(URI name) {
         Matcher m = mvnPattern.matcher(name.toString());
         if (!m.matches()) {
             return name.toString();
         }
-        StringBuilder b = new StringBuilder();
-        b.append(m.group(1));
-        for (int i = 0; i < b.length(); i++) {
-            if (b.charAt(i) == '.') {
-                b.setCharAt(i, '/');
-            }
-        }
-        b.append("/");//groupId
+        StringBuilder path = new StringBuilder();
+        path.append(m.group(1).replace(".", "/"));
+        path.append("/");//groupId
         String artifactId = m.group(2);
         String version = m.group(3);
         String extension = m.group(5);
         String classifier = m.group(7);
-        b.append(artifactId).append("/");//artifactId
-        b.append(version).append("/");//version
-        b.append(artifactId).append("-").append(version);
+        path.append(artifactId).append("/");//artifactId
+        path.append(version).append("/");//version
+        path.append(artifactId).append("-").append(version);
         if (present(classifier)) {
-            b.append("-").append(classifier);
+            path.append("-").append(classifier);
+        }
+        if (present(extension)) {
+            path.append(".").append(extension);
         } else {
-            if (present(extension)) {
-                b.append(".").append(extension);
-            } else {
-                b.append(".jar");
-            }
+            path.append(".jar");
         }
-        return b.toString();
+        return path.toString();
     }
 
     private static boolean present(String part) {

Added: karaf/trunk/main/src/test/java/org/apache/karaf/main/util/SimpleMavenResolverTest.java
URL: http://svn.apache.org/viewvc/karaf/trunk/main/src/test/java/org/apache/karaf/main/util/SimpleMavenResolverTest.java?rev=1339179&view=auto
==============================================================================
--- karaf/trunk/main/src/test/java/org/apache/karaf/main/util/SimpleMavenResolverTest.java (added)
+++ karaf/trunk/main/src/test/java/org/apache/karaf/main/util/SimpleMavenResolverTest.java Wed May 16 14:13:30 2012
@@ -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.karaf.main.util;
+
+import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Collections;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+public class SimpleMavenResolverTest {
+    private static final String ARTIFACT_COORDS = "mvn:org.apache.karaf.features/framework/1.0.0/xml/features";
+
+    @Test
+    public void mavenToPath() throws URISyntaxException {
+        String resolvedPath = SimpleMavenResolver.fromMaven(new URI(ARTIFACT_COORDS));
+        Assert.assertEquals("org/apache/karaf/features/framework/1.0.0/framework-1.0.0-features.xml", resolvedPath);
+    }
+    
+    @Test
+    public void testResolve() throws URISyntaxException {
+        File basedir = new File(getClass().getClassLoader().getResource("foo").getPath()).getParentFile();
+        File home = new File(basedir, "test-karaf-home");
+        File system = new File(home, "system");
+        SimpleMavenResolver resolver = new SimpleMavenResolver(Collections.singletonList(system));
+        resolver.resolve(new URI(ARTIFACT_COORDS)); // Will throw exception if the artifact can not be resolved
+    }
+}