You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by hi...@apache.org on 2014/10/28 22:37:09 UTC

[06/35] git commit: When parsing an OSGi MANIFEST, add its entries in the extra infos of the module descriptor

When parsing an OSGi MANIFEST, add its entries in the extra infos of the module descriptor


git-svn-id: https://svn.apache.org/repos/asf/ant/ivy/core/trunk@1592238 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/ant-ivy/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant-ivy/commit/ff2f32b9
Tree: http://git-wip-us.apache.org/repos/asf/ant-ivy/tree/ff2f32b9
Diff: http://git-wip-us.apache.org/repos/asf/ant-ivy/diff/ff2f32b9

Branch: refs/heads/2.4.x
Commit: ff2f32b914a5486e4f4870c6bc6fae14a85fb086
Parents: a6a5e30
Author: Nicolas Lalevee <hi...@apache.org>
Authored: Sat May 3 16:22:05 2014 +0000
Committer: Nicolas Lalevee <hi...@apache.org>
Committed: Sat May 3 16:22:05 2014 +0000

----------------------------------------------------------------------
 .../org/apache/ivy/ant/ConvertManifestTask.java |  2 +-
 .../apache/ivy/osgi/core/BundleInfoAdapter.java | 20 +++++++++++++++-----
 .../ivy/osgi/core/OSGiManifestParser.java       |  2 +-
 .../parser/xml/XmlModuleDescriptorParser.java   |  2 ++
 .../apache/ivy/osgi/obr/OBRResolverTest.java    | 15 ++++++++-------
 5 files changed, 27 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/ff2f32b9/src/java/org/apache/ivy/ant/ConvertManifestTask.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/ant/ConvertManifestTask.java b/src/java/org/apache/ivy/ant/ConvertManifestTask.java
index ad91093..ab470d7 100644
--- a/src/java/org/apache/ivy/ant/ConvertManifestTask.java
+++ b/src/java/org/apache/ivy/ant/ConvertManifestTask.java
@@ -84,7 +84,7 @@ public class ConvertManifestTask extends IvyTask {
             throw new BuildException("Incorrect manifest file '" + manifest + "'", e);
         }
         ModuleDescriptor md = BundleInfoAdapter.toModuleDescriptor(
-            OSGiManifestParser.getInstance(), null, bundleInfo, profileProvider);
+            OSGiManifestParser.getInstance(), null, bundleInfo, m, profileProvider);
 
         try {
             XmlModuleDescriptorWriter.write(md, ivyFile);

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/ff2f32b9/src/java/org/apache/ivy/osgi/core/BundleInfoAdapter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/osgi/core/BundleInfoAdapter.java b/src/java/org/apache/ivy/osgi/core/BundleInfoAdapter.java
index 29e3341..27a24c0 100644
--- a/src/java/org/apache/ivy/osgi/core/BundleInfoAdapter.java
+++ b/src/java/org/apache/ivy/osgi/core/BundleInfoAdapter.java
@@ -27,7 +27,9 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
+import java.util.jar.Manifest;
 
 import org.apache.ivy.Ivy;
 import org.apache.ivy.core.module.descriptor.Artifact;
@@ -68,19 +70,21 @@ public class BundleInfoAdapter {
 
     public static final String EXTRA_INFO_EXPORT_PREFIX = "_osgi_export_";
 
+    public static DefaultModuleDescriptor toModuleDescriptor(ModuleDescriptorParser parser,
+            URI baseUri, BundleInfo bundle, ExecutionEnvironmentProfileProvider profileProvider) {
+        return toModuleDescriptor(parser, baseUri, bundle, null, profileProvider);
+    }
+
     /**
      * 
      * @param baseUri
      *            uri to help build the absolute url if the bundle info has a relative uri.
-     * @param bundle
-     * @param profileProvider
-     * @param parser
      * @return
      * @throws ProfileNotFoundException
      */
     public static DefaultModuleDescriptor toModuleDescriptor(ModuleDescriptorParser parser,
-            URI baseUri, BundleInfo bundle, ExecutionEnvironmentProfileProvider profileProvider)
-            throws ProfileNotFoundException {
+            URI baseUri, BundleInfo bundle, Manifest manifest,
+            ExecutionEnvironmentProfileProvider profileProvider) throws ProfileNotFoundException {
         DefaultModuleDescriptor md = new DefaultModuleDescriptor(parser, null);
         md.addExtraAttributeNamespace("o", Ivy.getIvyHomeURL() + "osgi");
         ModuleRevisionId mrid = asMrid(BundleInfo.BUNDLE_TYPE, bundle.getSymbolicName(),
@@ -160,6 +164,12 @@ public class BundleInfoAdapter {
             }
         }
 
+        if (manifest != null) {
+            for (Entry<Object, Object> entries : manifest.getMainAttributes().entrySet()) {
+                md.addExtraInfo(entries.getKey().toString(), entries.getValue().toString());
+            }
+        }
+
         return md;
     }
 

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/ff2f32b9/src/java/org/apache/ivy/osgi/core/OSGiManifestParser.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/osgi/core/OSGiManifestParser.java b/src/java/org/apache/ivy/osgi/core/OSGiManifestParser.java
index fb3d1a3..66cced1 100644
--- a/src/java/org/apache/ivy/osgi/core/OSGiManifestParser.java
+++ b/src/java/org/apache/ivy/osgi/core/OSGiManifestParser.java
@@ -69,7 +69,7 @@ public class OSGiManifestParser implements ModuleDescriptorParser {
         } catch (URISyntaxException e) {
             throw new RuntimeException("Unsupported repository, resources names are not uris", e);
         }
-        return BundleInfoAdapter.toModuleDescriptor(this, null, bundleInfo, profileProvider);
+        return BundleInfoAdapter.toModuleDescriptor(this, null, bundleInfo, m, profileProvider);
     }
 
     public void toIvyFile(InputStream is, Resource res, File destFile, ModuleDescriptor md)

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/ff2f32b9/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java
index 35f93e3..800b963 100644
--- a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java
+++ b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java
@@ -561,6 +561,8 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser {
                 Namespace parentNamespace = ((DefaultModuleDescriptor) parent).getNamespace();
                 descriptor.setNamespace(parentNamespace);
             }
+
+            descriptor.getExtraInfo().putAll(parent.getExtraInfo());
         }
 
         private static String mergeRevisionValue(String inherited, String override) {

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/ff2f32b9/test/java/org/apache/ivy/osgi/obr/OBRResolverTest.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/osgi/obr/OBRResolverTest.java b/test/java/org/apache/ivy/osgi/obr/OBRResolverTest.java
index 4b42917..0a97e8a 100644
--- a/test/java/org/apache/ivy/osgi/obr/OBRResolverTest.java
+++ b/test/java/org/apache/ivy/osgi/obr/OBRResolverTest.java
@@ -25,6 +25,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.jar.JarInputStream;
+import java.util.jar.Manifest;
 
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
@@ -294,9 +295,9 @@ public class OBRResolverTest extends TestCase {
 
     private void genericTestResolve(String jarName, String conf, ModuleRevisionId[] expectedMrids,
             ModuleRevisionId[] expected2Mrids) throws Exception {
-        JarInputStream in = new JarInputStream(new FileInputStream("test/test-repo/bundlerepo/"
-                + jarName));
-        BundleInfo bundleInfo = ManifestParser.parseManifest(in.getManifest());
+        Manifest manifest = new JarInputStream(new FileInputStream("test/test-repo/bundlerepo/"
+                + jarName)).getManifest();
+        BundleInfo bundleInfo = ManifestParser.parseManifest(manifest);
         bundleInfo.addArtifact(new BundleArtifact(false, new File("test/test-repo/bundlerepo/"
                 + jarName).toURI(), null));
         DefaultModuleDescriptor md = BundleInfoAdapter.toModuleDescriptor(
@@ -326,13 +327,13 @@ public class OBRResolverTest extends TestCase {
     }
 
     private void genericTestFailingResolve(String jarName, String conf) throws Exception {
-        JarInputStream in = new JarInputStream(new FileInputStream("test/test-repo/bundlerepo/"
-                + jarName));
-        BundleInfo bundleInfo = ManifestParser.parseManifest(in.getManifest());
+        Manifest manifest = new JarInputStream(new FileInputStream("test/test-repo/bundlerepo/"
+                + jarName)).getManifest();
+        BundleInfo bundleInfo = ManifestParser.parseManifest(manifest);
         bundleInfo.addArtifact(new BundleArtifact(false, new File("test/test-repo/bundlerepo/"
                 + jarName).toURI(), null));
         DefaultModuleDescriptor md = BundleInfoAdapter.toModuleDescriptor(
-            OSGiManifestParser.getInstance(), null, bundleInfo, profileProvider);
+            OSGiManifestParser.getInstance(), null, bundleInfo, manifest, profileProvider);
         ResolveReport resolveReport = ivy.resolve(md,
             new ResolveOptions().setConfs(new String[] {conf}).setOutputReport(false));
         assertTrue(resolveReport.hasError());