You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by dj...@apache.org on 2011/01/28 20:35:15 UTC
svn commit: r1064828 - in /karaf/trunk/tooling/features-maven-plugin/src:
main/java/org/apache/karaf/tooling/features/
test/java/org/apache/karaf/tooling/features/
Author: djencks
Date: Fri Jan 28 19:35:15 2011
New Revision: 1064828
URL: http://svn.apache.org/viewvc?rev=1064828&view=rev
Log:
KARAF-424 integrate remote repo mvn url support better
Added:
karaf/trunk/tooling/features-maven-plugin/src/test/java/org/apache/karaf/tooling/features/BundleToArtifactTest.java (with props)
Modified:
karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/ArchiveKarMojo.java
karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/MojoSupport.java
Modified: karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/ArchiveKarMojo.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/ArchiveKarMojo.java?rev=1064828&r1=1064827&r2=1064828&view=diff
==============================================================================
--- karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/ArchiveKarMojo.java (original)
+++ karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/ArchiveKarMojo.java Fri Jan 28 19:35:15 2011
@@ -34,13 +34,10 @@ import org.apache.maven.archiver.MavenAr
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
-import org.apache.maven.artifact.versioning.ArtifactVersion;
-import org.apache.maven.model.License;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.codehaus.plexus.archiver.jar.JarArchiver;
-import org.osgi.framework.Constants;
/**
* assembles a kar archive from a features.xml file
@@ -143,7 +140,7 @@ public class ArchiveKarMojo extends Mojo
for (Feature feature : features.getFeature()) {
for (Bundle bundle : feature.getBundle()) {
if (bundle.isDependency() == null || !bundle.isDependency()) {
- bundles.add(bundleToArtifact(bundle.getValue()));
+ bundles.add(bundleToArtifact(bundle.getValue(), false));
}
}
}
Modified: karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/MojoSupport.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/MojoSupport.java?rev=1064828&r1=1064827&r2=1064828&view=diff
==============================================================================
--- karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/MojoSupport.java (original)
+++ karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/MojoSupport.java Fri Jan 28 19:35:15 2011
@@ -34,6 +34,8 @@ import org.apache.maven.artifact.Artifac
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.DefaultArtifactRepository;
+import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.artifact.resolver.ArtifactCollector;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
@@ -90,7 +92,7 @@ public abstract class MojoSupport extend
/**
* @parameter default-value="${project.remoteArtifactRepositories}"
*/
- protected List remoteRepos;
+ protected List<ArtifactRepository> remoteRepos;
/**
* @component
@@ -351,28 +353,27 @@ public abstract class MojoSupport extend
}
}
- protected Artifact bundleToArtifact(String bundle) throws MojoExecutionException {
+ protected Artifact bundleToArtifact(String bundle, boolean skipNonMavenProtocols) throws MojoExecutionException {
bundle = bundle.replace("\r\n", "").replace("\n", "").replace(" ", "");
final int index = bundle.indexOf("mvn:");
if (index < 0) {
-// if (skipNonMavenProtocols) {
-// continue;
-// }
+ if (skipNonMavenProtocols) {
+ return null;
+ }
throw new MojoExecutionException("Bundle url is not a maven url: " + bundle);
- }
- else {
- bundle = bundle.substring(index);
+ } else {
+ bundle = bundle.substring(index + "mvn:".length());
}
// Truncate the URL when a '#', a '?' or a '$' is encountered
final int index1 = bundle.indexOf('?');
final int index2 = bundle.indexOf('#');
int endIndex = -1;
if (index1 > 0) {
- if (index2 > 0) {
- endIndex = Math.min(index1, index2);
- } else {
- endIndex = index1;
- }
+ if (index2 > 0) {
+ endIndex = Math.min(index1, index2);
+ } else {
+ endIndex = index1;
+ }
} else if (index2 > 0) {
endIndex = index2;
}
@@ -384,7 +385,20 @@ public abstract class MojoSupport extend
bundle = bundle.substring(0, index3);
}
- String[] parts = bundle.substring("mvn:".length()).split("/");
+ //check if the bundle descriptor contains also remote repository information.
+ ArtifactRepository repo = null;
+ if (bundle.startsWith("http://")) {
+ final int repoDelimIntex = bundle.indexOf('!');
+ String repoUrl = bundle.substring(0, repoDelimIntex);
+
+ repo = new DefaultArtifactRepository(
+ repoUrl,
+ repoUrl,
+ new DefaultRepositoryLayout());
+ bundle = bundle.substring(repoDelimIntex + 1);
+
+ }
+ String[] parts = bundle.split("/");
String groupId = parts[0];
String artifactId = parts[1];
String version = null;
@@ -400,6 +414,7 @@ public abstract class MojoSupport extend
}
}
Artifact artifact = factory.createArtifactWithClassifier(groupId, artifactId, version, type, classifier);
+ artifact.setRepository(repo);
return artifact;
}
}
Added: karaf/trunk/tooling/features-maven-plugin/src/test/java/org/apache/karaf/tooling/features/BundleToArtifactTest.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/features-maven-plugin/src/test/java/org/apache/karaf/tooling/features/BundleToArtifactTest.java?rev=1064828&view=auto
==============================================================================
--- karaf/trunk/tooling/features-maven-plugin/src/test/java/org/apache/karaf/tooling/features/BundleToArtifactTest.java (added)
+++ karaf/trunk/tooling/features-maven-plugin/src/test/java/org/apache/karaf/tooling/features/BundleToArtifactTest.java Fri Jan 28 19:35:15 2011
@@ -0,0 +1,88 @@
+/*
+ * 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 java.lang.reflect.Field;
+import java.util.HashMap;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.DefaultArtifactFactory;
+import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
+import org.apache.maven.artifact.handler.manager.DefaultArtifactHandlerManager;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.junit.Test;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class BundleToArtifactTest extends MojoSupport {
+
+ public BundleToArtifactTest() throws NoSuchFieldException, IllegalAccessException {
+ factory = new DefaultArtifactFactory();
+ ArtifactHandlerManager artifactHandlerManager = new DefaultArtifactHandlerManager();
+ Field f = factory.getClass().getDeclaredField("artifactHandlerManager");
+ f.setAccessible(true);
+ f.set(factory, artifactHandlerManager);
+ f.setAccessible(false);
+
+ f = artifactHandlerManager.getClass().getDeclaredField("artifactHandlers");
+ f.setAccessible(true);
+ f.set(artifactHandlerManager, new HashMap());
+ f.setAccessible(false);
+ }
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ }
+
+ @Test
+ public void testSimpleURL() throws Exception {
+ Artifact artifact = bundleToArtifact("mvn:org.foo/bar/1.0/kar", false);
+ assert artifact.getGroupId().equals("org.foo");
+ assert artifact.getArtifactId().equals("bar");
+ assert artifact.getBaseVersion().equals("1.0");
+ assert artifact.getType().equals("kar");
+ assert artifact.getRepository() == null;
+ assert artifact.getClassifier() == null;
+ }
+
+ @Test
+ public void testURLWithClassifier() throws Exception {
+ Artifact artifact = bundleToArtifact("mvn:org.foo/bar/1.0/kar/type", false);
+ assert artifact.getGroupId().equals("org.foo");
+ assert artifact.getArtifactId().equals("bar");
+ assert artifact.getBaseVersion().equals("1.0");
+ assert artifact.getType().equals("kar");
+ assert artifact.getRepository() == null;
+ assert artifact.getClassifier().equals("type");
+ }
+
+ @Test
+ public void testRemoteRepoURL() throws Exception {
+ Artifact artifact = bundleToArtifact("mvn:http://baz.com!org.foo/bar/1.0/kar", false);
+ assert artifact.getGroupId().equals("org.foo");
+ assert artifact.getArtifactId().equals("bar");
+ assert artifact.getBaseVersion().equals("1.0");
+ assert artifact.getType().equals("kar");
+ assert artifact.getRepository().getUrl().equals("http://baz.com");
+ assert artifact.getClassifier() == null;
+ }
+}
Propchange: karaf/trunk/tooling/features-maven-plugin/src/test/java/org/apache/karaf/tooling/features/BundleToArtifactTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: karaf/trunk/tooling/features-maven-plugin/src/test/java/org/apache/karaf/tooling/features/BundleToArtifactTest.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: karaf/trunk/tooling/features-maven-plugin/src/test/java/org/apache/karaf/tooling/features/BundleToArtifactTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain