Author: jbonofre
Date: Mon Jan 17 10:25:13 2011
New Revision: 1059848
URL: http://svn.apache.org/viewvc?rev=1059848&view=rev
Log:
[KARAF-391] Revert the commited patch as we can have NPE during
features-to-repo goal. We need to review the patch.
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=1059848&r1=1059847&r2=1059848&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
Mon Jan 17 10:25:13 2011
@@ -26,7 +26,6 @@ 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;
@@ -39,9 +38,6 @@ 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;
@@ -140,9 +136,6 @@ 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) {
@@ -178,30 +171,42 @@ 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 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);
+ 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;
- explicitRepoBundles.put(bundleDescriptor, repo);
- continue;
+ 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);
}
- //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) {
@@ -220,48 +225,6 @@ 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) {