Author: anierbeck
Date: Sun Jan 16 17:46:57 2011
New Revision: 1059620
URL: http://svn.apache.org/viewvc?rev=1059620&view=rev
Log:
[KARAF-394] - Ability to use features-maven-plugin:add-features-to-repo without
specifying features, patch provided by Sergey Zhemzhitsky
Modified:
karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/AddFeaturesToRepoMojo.java
Modified:
karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/AddFeaturesToRepoMojo.java
URL:
http://svn.apache.org/viewvc/karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/AddFeaturesToRepoMojo.java?rev=1059620&r1=1059619&r2=1059620&view=diff
==============================================================================
---
karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/AddFeaturesToRepoMojo.java
(original)
+++
karaf/trunk/tooling/features-maven-plugin/src/main/java/org/apache/karaf/tooling/features/AddFeaturesToRepoMojo.java
Sun Jan 16 17:46:57 2011
@@ -26,6 +26,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
@@ -38,6 +39,9 @@ import javax.xml.parsers.DocumentBuilder
import javax.xml.parsers.ParserConfigurationException;
import org.apache.maven.artifact.Artifact;
+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.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.plugin.MojoExecutionException;
@@ -136,6 +140,9 @@ public class AddFeaturesToRepoMojo exten
bundles.addAll(featuresMap.get(feature).getConfigFiles());
}
}
+
+ // bundles with explicitely specified remote repos. key -> bundle,
value -> remote repo
+ Map<String, ArtifactRepository> explicitRepoBundles = new
HashMap<String, ArtifactRepository>();
getLog().info("Base repo: " + localRepo.getUrl());
for (String bundle : bundles) {
@@ -171,46 +178,30 @@ public class AddFeaturesToRepoMojo exten
if (index3 > 0) {
bundle = bundle.substring(0, index3);
}
+ if (index1 > 0 || index2 > 0 || endIndex > 0 || index3 > 0)
+ getLog().debug("Bundle URL truncated: "+bundle);
- String[] parts = bundle.substring("mvn:".length()).split("/");
- String groupId = parts[0];
- String artifactId = parts[1];
- String version = null;
- String classifier = null;
- String type = "jar";
- if (parts.length > 2) {
- version = parts[2];
- if (parts.length > 3) {
- type = parts[3];
- if (parts.length > 4) {
- classifier = parts[4];
- }
- }
- }
- String dir = groupId.replace('.', '/') + "/" + artifactId +
"/" + version + "/";
- String name = artifactId + "-" + version + (classifier != null
? "-" + classifier : "") + "." + type;
+ String bundleDescriptor = bundle.substring("mvn:".length());
+ //check if the bundle descriptor contains also remote
repository information.
+ if(bundleDescriptor.startsWith("http://")) {
+ final int repoDelimIntex =
bundleDescriptor.indexOf('!');
+ String repoUrl = bundleDescriptor.substring(0,
repoDelimIntex);
+
+ ArtifactRepository repo = new DefaultArtifactRepository(
+ repoUrl,
+ repoUrl,
+ new DefaultRepositoryLayout());
+ bundleDescriptor =
bundleDescriptor.substring(repoDelimIntex + 1);
- Artifact artifact;
- try {
- artifact = factory.createArtifactWithClassifier(groupId,
artifactId, version, type, classifier);
- getLog().info("Copying bundle: " + bundle);
- resolver.resolve(artifact, remoteRepos, localRepo);
- copy(new FileInputStream(artifact.getFile()),
- repository,
- name,
- dir,
- new byte[8192]);
- } catch (ArtifactResolutionException e) {
- if (failOnArtifactResolutionError) {
- throw new MojoFailureException("Can't resolve bundle "
+ bundle, e);
- }
- getLog().error("Can't resolve bundle " + bundle, e);
- } catch (ArtifactNotFoundException e) {
- if (failOnArtifactResolutionError) {
- throw new MojoFailureException("Can't resolve bundle "
+ bundle, e);
- }
- getLog().error("Can't resolve bundle " + bundle, e);
+ explicitRepoBundles.put(bundleDescriptor, repo);
+ continue;
}
+ //bundle URL without repository information are resolved now
+ resolveBundle(bundle, remoteRepos);
+ }
+ // resolving all bundles with explicitly specified remote
repository
+ for(Map.Entry<String, ArtifactRepository> explicitBundle :
explicitRepoBundles.entrySet()) {
+ resolveBundle(explicitBundle.getKey(),
Collections.singletonList(explicitBundle.getValue()));
}
if (copyFileBasedDescriptors != null) {
for (CopyFileBasedDescriptor fileBasedDescritpor :
copyFileBasedDescriptors) {
@@ -229,6 +220,48 @@ public class AddFeaturesToRepoMojo exten
throw new MojoExecutionException("Error populating repository", e);
}
}
+
+ // resolves the bundle in question
+ private void resolveBundle(String bundle, List<ArtifactRepository>
remoteRepos) throws IOException, MojoFailureException {
+ String[] parts = bundle.split("/");
+ String groupId = parts[0];
+ String artifactId = parts[1];
+ String version = null;
+ String classifier = null;
+ String type = "jar";
+ if (parts.length > 2) {
+ version = parts[2];
+ if (parts.length > 3) {
+ type = parts[3];
+ if (parts.length > 4) {
+ classifier = parts[4];
+ }
+ }
+ }
+ String dir = groupId.replace('.', '/') + "/" + artifactId + "/" +
version + "/";
+ String name = artifactId + "-" + version + (classifier != null ? "-" +
classifier : "") + "." + type;
+
+ Artifact artifact = factory.createArtifactWithClassifier(groupId,
artifactId, version, type, classifier);
+ try {
+ getLog().info("Copying bundle: " + bundle);
+ resolver.resolve(artifact, remoteRepos, localRepo);
+ copy(new FileInputStream(artifact.getFile()),
+ repository,
+ name,
+ dir,
+ new byte[8192]);
+ } catch (ArtifactResolutionException e) {
+ if (failOnArtifactResolutionError) {
+ throw new MojoFailureException("Can't resolve bundle "
+ bundle, e);
+ }
+ getLog().error("Can't resolve bundle " + bundle, e);
+ } catch (ArtifactNotFoundException e) {
+ if (failOnArtifactResolutionError) {
+ throw new MojoFailureException("Can't resolve bundle "
+ bundle, e);
+ }
+ getLog().error("Can't resolve bundle " + bundle, e);
+ }
+ }
private void addFeatures(List<String> features, Set<String>
featuresBundles, Set<String> transitiveFeatures, Map<String, Feature>
featuresMap) {
for (String feature : features) {