You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2015/03/04 09:42:11 UTC
karaf git commit: [KARAF-3528] When updating bundles,
use the Bundle-UpdateLocation header Fix problems with some jar files.
Repository: karaf
Updated Branches:
refs/heads/master e1db56f6c -> 087259696
[KARAF-3528] When updating bundles, use the Bundle-UpdateLocation header
Fix problems with some jar files.
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/08725969
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/08725969
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/08725969
Branch: refs/heads/master
Commit: 0872596960b5539fa8d5f8596106e7f13a437deb
Parents: e1db56f
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Wed Mar 4 09:41:41 2015 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Wed Mar 4 09:41:41 2015 +0100
----------------------------------------------------------------------
util/pom.xml | 7 ++++
.../apache/karaf/util/bundles/BundleUtils.java | 29 +++++++++++-----
.../org/apache/karaf/util/BundleUtilsTest.java | 35 ++++++++++++++++++++
3 files changed, 62 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/08725969/util/pom.xml
----------------------------------------------------------------------
diff --git a/util/pom.xml b/util/pom.xml
index 741a89d..97bcc5e 100644
--- a/util/pom.xml
+++ b/util/pom.xml
@@ -56,6 +56,13 @@
<groupId>org.apache.karaf.jaas</groupId>
<artifactId>org.apache.karaf.jaas.boot</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>javax.mail</groupId>
+ <artifactId>mail</artifactId>
+ <version>1.4.7</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<properties>
http://git-wip-us.apache.org/repos/asf/karaf/blob/08725969/util/src/main/java/org/apache/karaf/util/bundles/BundleUtils.java
----------------------------------------------------------------------
diff --git a/util/src/main/java/org/apache/karaf/util/bundles/BundleUtils.java b/util/src/main/java/org/apache/karaf/util/bundles/BundleUtils.java
index 4b44b65..94c70c3 100644
--- a/util/src/main/java/org/apache/karaf/util/bundles/BundleUtils.java
+++ b/util/src/main/java/org/apache/karaf/util/bundles/BundleUtils.java
@@ -16,12 +16,15 @@
*/
package org.apache.karaf.util.bundles;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
+import java.util.zip.CRC32;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
@@ -33,7 +36,7 @@ public class BundleUtils {
public static File fixBundleWithUpdateLocation(InputStream is, String uri) throws IOException {
File file = File.createTempFile("update-", ".jar");
try (ZipInputStream zis = new ZipInputStream(is);
- ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(file))) {
+ ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(file))) {
byte[] buf = new byte[8192];
zos.setLevel(0);
@@ -42,19 +45,27 @@ public class BundleUtils {
if (entry == null) {
break;
}
- zos.putNextEntry(entry);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ int n;
+ while (-1 != (n = zis.read(buf))) {
+ baos.write(buf, 0, n);
+ }
if (entry.getName().equals(JarFile.MANIFEST_NAME)) {
- Manifest man = new Manifest(zis);
+ Manifest man = new Manifest(new ByteArrayInputStream(baos.toByteArray()));
if (man.getMainAttributes().getValue(Constants.BUNDLE_UPDATELOCATION) == null) {
man.getMainAttributes().putValue(Constants.BUNDLE_UPDATELOCATION, uri);
}
- man.write(zos);
- } else {
- int n;
- while (-1 != (n = zis.read(buf))) {
- zos.write(buf, 0, n);
- }
+ baos.reset();
+ man.write(baos);
}
+ byte[] data = baos.toByteArray();
+ CRC32 crc = new CRC32();
+ crc.update(data);
+ entry = new ZipEntry(entry.getName());
+ entry.setSize(data.length);
+ entry.setCrc(crc.getValue());
+ zos.putNextEntry(entry);
+ zos.write(data);
zis.closeEntry();
zos.closeEntry();
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/08725969/util/src/test/java/org/apache/karaf/util/BundleUtilsTest.java
----------------------------------------------------------------------
diff --git a/util/src/test/java/org/apache/karaf/util/BundleUtilsTest.java b/util/src/test/java/org/apache/karaf/util/BundleUtilsTest.java
new file mode 100644
index 0000000..39f45f5
--- /dev/null
+++ b/util/src/test/java/org/apache/karaf/util/BundleUtilsTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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.karaf.util;
+
+import org.apache.karaf.util.bundles.BundleUtils;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.net.URL;
+
+public class BundleUtilsTest {
+
+ @Test
+ public void testJavaxMail() throws Exception {
+ String url = getClass().getClassLoader().getResource("com/sun/mail/util/ASCIIUtility.class").toString();
+ url = url.substring("jar:file:".length(), url.indexOf("!/"));
+ File file = new File(url);
+ BundleUtils.fixBundleWithUpdateLocation(new FileInputStream(file), "mvn:javax.mail/mail/1.4.7");
+ }
+}