ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hi...@apache.org
Subject svn commit: r1587110 - in /ant/ivy/core/trunk: doc/ src/java/org/apache/ivy/core/pack/ src/java/org/apache/ivy/osgi/core/ src/java/org/apache/ivy/osgi/repo/ src/java/org/apache/ivy/util/ test/java/org/apache/ivy/osgi/p2/
Date Sun, 13 Apr 2014 22:14:03 GMT
Author: hibou
Date: Sun Apr 13 22:14:03 2014
New Revision: 1587110

URL: http://svn.apache.org/r1587110
Log:
Add support for packed jar within an OSGi bundle

Added:
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/pack/OsgiBundlePacking.java   (with props)
Modified:
    ant/ivy/core/trunk/doc/concept.html
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/pack/Pack200Packing.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/pack/PackingRegistry.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/pack/ZipPacking.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/core/BundleInfoAdapter.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/core/ManifestParser.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/AbstractOSGiResolver.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/util/FileUtil.java
    ant/ivy/core/trunk/test/java/org/apache/ivy/osgi/p2/P2DescriptorTest.java

Modified: ant/ivy/core/trunk/doc/concept.html
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/doc/concept.html?rev=1587110&r1=1587109&r2=1587110&view=diff
==============================================================================
--- ant/ivy/core/trunk/doc/concept.html (original)
+++ ant/ivy/core/trunk/doc/concept.html Sun Apr 13 22:14:03 2014
@@ -289,6 +289,7 @@ A <i>packaged</i> artifact needs to be d
 <ul>
     <li><tt>zip</tt>, <tt>jar</tt> or <tt>war</tt>:
the artifact will be uncompressed as a folder</li>
     <li><tt>pack200</tt>: the artifact will be unpacked to a file via the
<a href="http://docs.oracle.com/javase/7/docs/technotes/tools/share/pack200.html">pack200</a>
algorithm</li>
+    <li><tt>bundle</tt>: the OSGi artifact will be uncompressed as a folder,
and every embedded jar file entry which is packed via the the <a href="http://docs.oracle.com/javase/7/docs/technotes/tools/share/pack200.html">pack200</a>
algorithm will be unpacked</li>
 </ul>
 
 So, if in an <tt>ivy.xml</tt>, there would be declared a such artifact:

Added: ant/ivy/core/trunk/src/java/org/apache/ivy/core/pack/OsgiBundlePacking.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/pack/OsgiBundlePacking.java?rev=1587110&view=auto
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/pack/OsgiBundlePacking.java (added)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/pack/OsgiBundlePacking.java Sun Apr 13
22:14:03 2014
@@ -0,0 +1,48 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.ivy.core.pack;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.ivy.util.FileUtil;
+
+/**
+ * Packaging which handle OSGi bundles with inner packed jar
+ */
+public class OsgiBundlePacking extends ZipPacking {
+
+    private static final String[] NAMES = {"bundle"};
+
+    @Override
+    public String[] getNames() {
+        return NAMES;
+    }
+
+    @Override
+    protected void writeFile(InputStream zip, File f) throws FileNotFoundException, IOException
{
+        // XXX maybe we should only unpack file listed by the 'Bundle-ClassPath' MANIFEST
header ?
+        if (f.getName().endsWith(".jar.pack.gz")) {
+            zip = FileUtil.unwrapPack200(zip);
+            f = new File(f.getParentFile(), f.getName().substring(0, f.getName().length()
- 8));
+        }
+        super.writeFile(zip, f);
+    }
+}

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/core/pack/OsgiBundlePacking.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/core/pack/OsgiBundlePacking.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/core/pack/OsgiBundlePacking.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/pack/Pack200Packing.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/pack/Pack200Packing.java?rev=1587110&r1=1587109&r2=1587110&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/pack/Pack200Packing.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/pack/Pack200Packing.java Sun Apr 13 22:14:03
2014
@@ -17,15 +17,10 @@
  */
 package org.apache.ivy.core.pack;
 
-import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.jar.JarOutputStream;
-import java.util.jar.Pack200;
-import java.util.jar.Pack200.Unpacker;
-import java.util.zip.GZIPInputStream;
+
+import org.apache.ivy.util.FileUtil;
 
 public class Pack200Packing extends StreamPacking {
 
@@ -54,25 +49,7 @@ public class Pack200Packing extends Stre
 
     @Override
     public InputStream unpack(InputStream packed) throws IOException {
-        BufferedInputStream buffered = new BufferedInputStream(packed);
-        buffered.mark(4);
-        byte[] magic = new byte[4];
-        buffered.read(magic, 0, 4);
-        buffered.reset();
-
-        InputStream in = buffered;
-
-        if (magic[0] == (byte) 0x1F && magic[1] == (byte) 0x8B && magic[2]
== (byte) 0x08) {
-            // this is a gziped pack200
-            in = new GZIPInputStream(in);
-        }
-
-        Unpacker unpacker = Pack200.newUnpacker();
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        JarOutputStream jar = new JarOutputStream(baos);
-        unpacker.unpack(in, jar);
-        jar.close();
-        return new ByteArrayInputStream(baos.toByteArray());
+        return FileUtil.unwrapPack200(packed);
     }
 
 }

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/pack/PackingRegistry.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/pack/PackingRegistry.java?rev=1587110&r1=1587109&r2=1587110&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/pack/PackingRegistry.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/pack/PackingRegistry.java Sun Apr 13 22:14:03
2014
@@ -28,6 +28,7 @@ public class PackingRegistry {
         // register defaults
         register(new ZipPacking());
         register(new Pack200Packing());
+        register(new OsgiBundlePacking());
     }
 
     public void register(ArchivePacking packing) {

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/pack/ZipPacking.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/pack/ZipPacking.java?rev=1587110&r1=1587109&r2=1587110&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/pack/ZipPacking.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/pack/ZipPacking.java Sun Apr 13 22:14:03
2014
@@ -18,6 +18,7 @@
 package org.apache.ivy.core.pack;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -66,16 +67,7 @@ public class ZipPacking extends ArchiveP
                 if (entry.isDirectory()) {
                     f.mkdirs();
                 } else {
-                    FileOutputStream out = new FileOutputStream(f);
-                    try {
-                        FileUtil.copy(zip, out, null, false);
-                    } finally {
-                        try {
-                            out.close();
-                        } catch (IOException e) {
-                            // ignore
-                        }
-                    }
+                    writeFile(zip, f);
                 }
 
                 f.setLastModified(entry.getTime());
@@ -91,4 +83,17 @@ public class ZipPacking extends ArchiveP
         }
     }
 
+    protected void writeFile(InputStream zip, File f) throws FileNotFoundException, IOException
{
+        FileOutputStream out = new FileOutputStream(f);
+        try {
+            FileUtil.copy(zip, out, null, false);
+        } finally {
+            try {
+                out.close();
+            } catch (IOException e) {
+                // ignore
+            }
+        }
+    }
+
 }

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/core/BundleInfoAdapter.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/core/BundleInfoAdapter.java?rev=1587110&r1=1587109&r2=1587110&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/core/BundleInfoAdapter.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/core/BundleInfoAdapter.java Sun Apr 13
22:14:03 2014
@@ -115,8 +115,8 @@ public class BundleInfoAdapter {
                 String type = "jar";
                 String ext = "jar";
                 String packaging = null;
-                if (bundle.hasInnerClasspath()) {
-                    packaging = "zip";
+                if (bundle.hasInnerClasspath() && !bundleArtifact.isSource()) {
+                    packaging = "bundle";
                 }
                 if ("packed".equals(bundleArtifact.getFormat())) {
                     ext = "jar.pack.gz";

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/core/ManifestParser.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/core/ManifestParser.java?rev=1587110&r1=1587109&r2=1587110&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/core/ManifestParser.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/core/ManifestParser.java Sun Apr 13 22:14:03
2014
@@ -204,6 +204,7 @@ public class ManifestParser {
         if (bundleClasspath != null) {
             ManifestHeaderValue bundleClasspathValue = new ManifestHeaderValue(bundleClasspath);
             bundleInfo.setClasspath(bundleClasspathValue.getValues());
+            bundleInfo.setHasInnerClasspath(true);
         }
 
         return bundleInfo;

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/AbstractOSGiResolver.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/AbstractOSGiResolver.java?rev=1587110&r1=1587109&r2=1587110&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/AbstractOSGiResolver.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/osgi/repo/AbstractOSGiResolver.java Sun Apr
13 22:14:03 2014
@@ -234,6 +234,9 @@ public abstract class AbstractOSGiResolv
     public ResolvedResource findResource(ResolvedResource[] rress, ResourceMDParser rmdparser,
             ModuleRevisionId mrid, Date date) {
         ResolvedResource found = super.findResource(rress, rmdparser, mrid, date);
+        if (found == null) {
+            return null;
+        }
 
         String osgiType = mrid.getOrganisation();
         // for non bundle requirement : log the selected bundle

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/util/FileUtil.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/util/FileUtil.java?rev=1587110&r1=1587109&r2=1587110&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/util/FileUtil.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/util/FileUtil.java Sun Apr 13 22:14:03 2014
@@ -17,7 +17,10 @@
  */
 package org.apache.ivy.util;
 
+import java.io.BufferedInputStream;
 import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -36,7 +39,12 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Stack;
 import java.util.StringTokenizer;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Pack200;
+import java.util.jar.Pack200.Unpacker;
 import java.util.regex.Pattern;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.ZipInputStream;
 
 import org.apache.ivy.util.url.URLHandlerRegistry;
 
@@ -637,4 +645,87 @@ public final class FileUtil {
         return l;
     }
 
+    public static InputStream unwrapPack200(InputStream packed) throws IOException {
+        BufferedInputStream buffered = new BufferedInputStream(packed);
+        buffered.mark(4);
+        byte[] magic = new byte[4];
+        buffered.read(magic, 0, 4);
+        buffered.reset();
+
+        InputStream in = buffered;
+
+        if (magic[0] == (byte) 0x1F && magic[1] == (byte) 0x8B && magic[2]
== (byte) 0x08) {
+            // this is a gziped pack200
+            in = new GZIPInputStream(in);
+        }
+
+        Unpacker unpacker = Pack200.newUnpacker();
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        JarOutputStream jar = new JarOutputStream(baos);
+        unpacker.unpack(new UncloseInputStream(in), jar);
+        jar.close();
+        return new ByteArrayInputStream(baos.toByteArray());
+    }
+
+    /**
+     * Wrap an input stream and do not close the stream on call to close(). Used to avoid
closing a
+     * {@link ZipInputStream} used with {@link Unpacker#unpack(File, JarOutputStream)}
+     */
+    private static final class UncloseInputStream extends InputStream {
+
+        private InputStream wrapped;
+
+        public UncloseInputStream(InputStream wrapped) {
+            this.wrapped = wrapped;
+        }
+
+        public void close() throws IOException {
+            // do not close
+        }
+
+        public int read() throws IOException {
+            return wrapped.read();
+        }
+
+        public int hashCode() {
+            return wrapped.hashCode();
+        }
+
+        public int read(byte[] b) throws IOException {
+            return wrapped.read(b);
+        }
+
+        public boolean equals(Object obj) {
+            return wrapped.equals(obj);
+        }
+
+        public int read(byte[] b, int off, int len) throws IOException {
+            return wrapped.read(b, off, len);
+        }
+
+        public long skip(long n) throws IOException {
+            return wrapped.skip(n);
+        }
+
+        public String toString() {
+            return wrapped.toString();
+        }
+
+        public int available() throws IOException {
+            return wrapped.available();
+        }
+
+        public void mark(int readlimit) {
+            wrapped.mark(readlimit);
+        }
+
+        public void reset() throws IOException {
+            wrapped.reset();
+        }
+
+        public boolean markSupported() {
+            return wrapped.markSupported();
+        }
+
+    }
 }

Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/osgi/p2/P2DescriptorTest.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/osgi/p2/P2DescriptorTest.java?rev=1587110&r1=1587109&r2=1587110&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/osgi/p2/P2DescriptorTest.java (original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/osgi/p2/P2DescriptorTest.java Sun Apr 13 22:14:03
2014
@@ -195,7 +195,12 @@ public class P2DescriptorTest extends Te
 
             assertEquals(artifact, ar.getArtifact());
             assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
-            assertNotNull(ar.getUnpackedLocalFile());
+            // only the binary get unpacked
+            if (ar.getArtifact().getType().equals("source")) {
+                assertNull(ar.getUnpackedLocalFile());
+            } else {
+                assertNotNull(ar.getUnpackedLocalFile());
+            }
         }
     }
 



Mime
View raw message