From e350a38760c93e373562d6a3e906df5904250146 Mon Sep 17 00:00:00 2001 From: Nicolas Lalevee Date: Tue, 21 Aug 2012 14:19:22 +0000 Subject: [PATCH] Add support for bundle with inner classpath git-svn-id: https://svn.apache.org/repos/asf/ant/ivy/core/trunk@1375562 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/ivy/osgi/core/BundleInfo.java | 13 +++++++++++++ .../apache/ivy/osgi/core/BundleInfoAdapter.java | 16 ++++++++++++---- .../org/apache/ivy/osgi/p2/P2MetadataParser.java | 14 +++++++++++++- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/java/org/apache/ivy/osgi/core/BundleInfo.java b/src/java/org/apache/ivy/osgi/core/BundleInfo.java index 3bc4bd01..6bbb2a82 100644 --- a/src/java/org/apache/ivy/osgi/core/BundleInfo.java +++ b/src/java/org/apache/ivy/osgi/core/BundleInfo.java @@ -74,6 +74,8 @@ public class BundleInfo { private URI sourceURI; + private boolean hasInnerClasspath; + public BundleInfo(String name, Version version) { this.symbolicName = name; this.version = version; @@ -225,6 +227,14 @@ public class BundleInfo { return versionTarget; } + public void setHasInnerClasspath(boolean hasInnerClasspath) { + this.hasInnerClasspath = hasInnerClasspath; + } + + public boolean hasInnerClasspath() { + return hasInnerClasspath; + } + public int hashCode() { final int prime = 31; int result = 1; @@ -312,6 +322,9 @@ public class BundleInfo { } else if (!sourceURI.equals(other.sourceURI)) { return false; } + if (hasInnerClasspath != other.hasInnerClasspath) { + return false; + } return true; } diff --git a/src/java/org/apache/ivy/osgi/core/BundleInfoAdapter.java b/src/java/org/apache/ivy/osgi/core/BundleInfoAdapter.java index 54a02124..6648386f 100644 --- a/src/java/org/apache/ivy/osgi/core/BundleInfoAdapter.java +++ b/src/java/org/apache/ivy/osgi/core/BundleInfoAdapter.java @@ -23,9 +23,11 @@ import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; import org.apache.ivy.Ivy; @@ -111,14 +113,16 @@ public class BundleInfoAdapter { requirementAsDependency(md, bundle, exportedPkgNames); + String compression = bundle.hasInnerClasspath() ? "zip" : null; URI uri = bundle.getUri(); if (uri != null) { - DefaultArtifact artifact = buildArtifact(mrid, baseUri, uri, "jar"); + DefaultArtifact artifact = buildArtifact(mrid, baseUri, uri, "jar", compression); md.addArtifact(CONF_NAME_DEFAULT, artifact); } URI sourceURI = bundle.getSourceURI(); if (sourceURI != null) { - DefaultArtifact artifact = buildArtifact(mrid, baseUri, sourceURI, "source"); + DefaultArtifact artifact = buildArtifact(mrid, baseUri, sourceURI, "source", + compression); md.addArtifact(CONF_NAME_DEFAULT, artifact); } @@ -151,7 +155,7 @@ public class BundleInfoAdapter { return md; } - public static DefaultArtifact buildArtifact(ModuleRevisionId mrid, URI baseUri, URI uri, String type) { + public static DefaultArtifact buildArtifact(ModuleRevisionId mrid, URI baseUri, URI uri, String type, String compression) { DefaultArtifact artifact; if ("ivy".equals(uri.getScheme())) { artifact = decodeIvyURI(uri); @@ -159,9 +163,13 @@ public class BundleInfoAdapter { if (!uri.isAbsolute()) { uri = baseUri.resolve(uri); } + Map extraAtt = new HashMap(); + if (compression != null) { + extraAtt.put("compression", compression); + } try { artifact = new DefaultArtifact(mrid, null, mrid.getName(), type, "jar", new URL( - uri.toString()), null); + uri.toString()), extraAtt); } catch (MalformedURLException e) { throw new RuntimeException("Unable to make the uri into the url", e); } diff --git a/src/java/org/apache/ivy/osgi/p2/P2MetadataParser.java b/src/java/org/apache/ivy/osgi/p2/P2MetadataParser.java index 0e916228..1266c355 100644 --- a/src/java/org/apache/ivy/osgi/p2/P2MetadataParser.java +++ b/src/java/org/apache/ivy/osgi/p2/P2MetadataParser.java @@ -295,6 +295,9 @@ public class P2MetadataParser implements XMLInputParser { // }); addChild(new TouchpointDataHandler(), new ChildElementHandler() { public void childHanlded(DelegetingHandler child) throws SAXParseException { + if (((TouchpointDataHandler) child).zipped) { + bundleInfo.setHasInnerClasspath(true); + } if (!bundleInfo.isSource()) { // we only care about parsing the manifest if it is a source return; @@ -685,11 +688,14 @@ public class P2MetadataParser implements XMLInputParser { String manifest; + boolean zipped; + public TouchpointDataHandler() { super(TOUCHPOINTDATA); addChild(new InstructionsHandler(), new ChildElementHandler() { public void childHanlded(DelegetingHandler child) { manifest = ((InstructionsHandler) child).manifest; + zipped = ((InstructionsHandler) child).zipped; } }); } @@ -708,12 +714,18 @@ public class P2MetadataParser implements XMLInputParser { String manifest; + boolean zipped; + public InstructionsHandler() { super(INSTRUCTIONS); addChild(new InstructionHandler(), new ChildElementHandler() { public void childHanlded(DelegetingHandler child) { - if (((InstructionHandler) child).key.equals("manifest")) { + String key = ((InstructionHandler) child).key; + if ("manifest".equals(key)) { manifest = ((InstructionHandler) child).getBufferedChars(); + } else if ("zipped".equals(key)) { + zipped = Boolean.valueOf( + ((InstructionHandler) child).getBufferedChars().trim()).booleanValue(); } } });