ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hi...@apache.org
Subject [31/50] [abbrv] ant-ivy git commit: IVY-1448 Use the descriptor URL to construct an URI, in OSGiManifestParser, instead of using the descriptor resource's name
Date Thu, 25 May 2017 13:49:17 GMT
IVY-1448 Use the descriptor URL to construct an URI, in OSGiManifestParser, instead of using
the descriptor resource's name


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

Branch: refs/heads/xooki2asciidoc
Commit: b308d598b603056e3ff7e8d53e099b677d4e8d38
Parents: 7a8d27f
Author: Jaikiran Pai <jaikiran.pai@gmail.com>
Authored: Thu May 18 12:57:01 2017 +0530
Committer: Jaikiran Pai <jaikiran.pai@gmail.com>
Committed: Thu May 18 12:57:01 2017 +0530

----------------------------------------------------------------------
 .../ivy/osgi/core/OSGiManifestParser.java       | 18 +++++++++++----
 .../parser/xml/XmlModuleDescriptorParser.java   |  2 +-
 .../ivy/osgi/core/OSGiManifestParserTest.java   | 23 ++++++++++++++++++++
 .../osgi/module1/META-INF/MANIFEST.MF           |  3 +++
 4 files changed, 41 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/b308d598/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 66cced1..e331161 100644
--- a/src/java/org/apache/ivy/osgi/core/OSGiManifestParser.java
+++ b/src/java/org/apache/ivy/osgi/core/OSGiManifestParser.java
@@ -62,14 +62,24 @@ public class OSGiManifestParser implements ModuleDescriptorParser {
 
     public ModuleDescriptor parseDescriptor(ParserSettings ivySettings, URL descriptorURL,
             Resource res, boolean validate) throws ParseException, IOException {
-        Manifest m = new Manifest(res.openStream());
-        BundleInfo bundleInfo = ManifestParser.parseManifest(m);
+        final InputStream resourceStream = res.openStream();
+        final Manifest manifest;
         try {
-            bundleInfo.addArtifact(new BundleArtifact(false, new URI(res.getName()), null));
+            manifest = new Manifest(resourceStream);
+        } finally {
+            try {
+                resourceStream.close();
+            } catch (Exception e) {
+                // ignore
+            }
+        }
+        BundleInfo bundleInfo = ManifestParser.parseManifest(manifest);
+        try {
+            bundleInfo.addArtifact(new BundleArtifact(false, descriptorURL.toURI(), null));
         } catch (URISyntaxException e) {
             throw new RuntimeException("Unsupported repository, resources names are not uris",
e);
         }
-        return BundleInfoAdapter.toModuleDescriptor(this, null, bundleInfo, m, profileProvider);
+        return BundleInfoAdapter.toModuleDescriptor(this, null, bundleInfo, manifest, profileProvider);
     }
 
     public void toIvyFile(InputStream is, Resource res, File destFile, ModuleDescriptor md)

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/b308d598/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 5e2a073..1a247bb 100644
--- a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java
+++ b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java
@@ -699,7 +699,7 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser
{
             FileResource res = new FileResource(null, file);
             ModuleDescriptorParser parser = ModuleDescriptorParserRegistry.getInstance().getParser(
                 res);
-            return parser.parseDescriptor(getSettings(), file.toURL(), res, isValidate());
+            return parser.parseDescriptor(getSettings(), file.toURI().toURL(), res, isValidate());
         }
 
         /**

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/b308d598/test/java/org/apache/ivy/osgi/core/OSGiManifestParserTest.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/osgi/core/OSGiManifestParserTest.java b/test/java/org/apache/ivy/osgi/core/OSGiManifestParserTest.java
index 7b37ba4..e0ad9c8 100644
--- a/test/java/org/apache/ivy/osgi/core/OSGiManifestParserTest.java
+++ b/test/java/org/apache/ivy/osgi/core/OSGiManifestParserTest.java
@@ -18,12 +18,16 @@
 package org.apache.ivy.osgi.core;
 
 import java.io.File;
+import java.net.URL;
 import java.util.Arrays;
 
 import org.apache.ivy.core.module.descriptor.Configuration;
 import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
 import org.apache.ivy.core.settings.IvySettings;
 import org.apache.ivy.plugins.parser.AbstractModuleDescriptorParserTester;
+import org.apache.ivy.plugins.parser.ParserSettings;
+import org.apache.ivy.plugins.repository.Resource;
+import org.apache.ivy.plugins.repository.file.FileResource;
 import org.apache.ivy.util.DefaultMessageLogger;
 import org.apache.ivy.util.Message;
 
@@ -58,4 +62,23 @@ public class OSGiManifestParserTest extends AbstractModuleDescriptorParserTester
         assertNotNull(md.getDependencies());
         assertEquals(0, md.getDependencies().length);
     }
+
+    /**
+     * Tests that the {@link OSGiManifestParser#parseDescriptor(ParserSettings, URL, Resource,
boolean)} works fine for descriptors
+     * that are backed by {@link FileResource}
+     *
+     * @throws Exception
+     */
+    public void testFileResource() throws Exception {
+        final File manifestFile = new File("test/repositories/osgi/module1/META-INF/MANIFEST.MF");
+        assertTrue("Manifest file is either missing or not a file at " + manifestFile.getAbsolutePath(),
manifestFile.isFile());
+
+        final Resource manifestFileResource = new FileResource(null, manifestFile);
+        final ModuleDescriptor md = OSGiManifestParser.getInstance().parseDescriptor(settings,
manifestFile.toURI().toURL(), manifestFileResource, true);
+
+        assertNotNull("Module descriptor created through a OSGi parser was null", md);
+        assertEquals("Unexpected organization name in module descriptor created through a
OSGi parser", "bundle", md.getModuleRevisionId().getOrganisation());
+        assertEquals("Unexpected module name in module descriptor created through a OSGi
parser", "module1", md.getModuleRevisionId().getName());
+        assertEquals("Unexpected version in module descriptor created through a OSGi parser",
"1.2.3", md.getModuleRevisionId().getRevision());
+    }
 }

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/b308d598/test/repositories/osgi/module1/META-INF/MANIFEST.MF
----------------------------------------------------------------------
diff --git a/test/repositories/osgi/module1/META-INF/MANIFEST.MF b/test/repositories/osgi/module1/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..c2c8bfd
--- /dev/null
+++ b/test/repositories/osgi/module1/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Bundle-SymbolicName: module1
+Bundle-Version: 1.2.3
+


Mime
View raw message