Author: bdelacretaz
Date: Mon Dec 21 15:25:28 2015
New Revision: 1721192
URL: http://svn.apache.org/viewvc?rev=1721192&view=rev
Log:
SLING-5379 - remove java 7 requirement, does not seem worth it just for
try-with-resources
Modified:
sling/trunk/bundles/commons/osgi/pom.xml
sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/BundleUtil.java
sling/trunk/bundles/commons/osgi/src/test/java/org/apache/sling/commons/osgi/BundleUtilTest.java
Modified: sling/trunk/bundles/commons/osgi/pom.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/commons/osgi/pom.xml?rev=1721192&r1=1721191&r2=1721192&view=diff
==============================================================================
--- sling/trunk/bundles/commons/osgi/pom.xml (original)
+++ sling/trunk/bundles/commons/osgi/pom.xml Mon Dec 21 15:25:28 2015
@@ -41,7 +41,6 @@
</scm>
<properties>
- <sling.java.version>7</sling.java.version>
<test.jars.folder>${project.build.directory}/testjars</test.jars.folder>
</properties>
Modified:
sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/BundleUtil.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/BundleUtil.java?rev=1721192&r1=1721191&r2=1721192&view=diff
==============================================================================
---
sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/BundleUtil.java
(original)
+++
sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/BundleUtil.java
Mon Dec 21 15:25:28 2015
@@ -48,7 +48,9 @@ public class BundleUtil {
* @throws IOException If something goes wrong reading or writing.
*/
public static File renameBSN(File bundleFile, String newBSN, File tempDir)
throws IOException {
- try (JarInputStream jis = new JarInputStream(new
FileInputStream(bundleFile))) {
+ JarInputStream jis = null;
+ try {
+ jis = new JarInputStream(new FileInputStream(bundleFile));
Manifest inputMF = jis.getManifest();
Attributes inputAttrs = inputMF.getMainAttributes();
@@ -64,7 +66,9 @@ public class BundleUtil {
outputAttrs.putValue("Bundle-SymbolicName", newBSN);
outputAttrs.putValue("X-Original-Bundle-SymbolicName", orgBSN);
- try (JarOutputStream jos = new JarOutputStream(new
FileOutputStream(newBundle), newMF)) {
+ JarOutputStream jos = null;
+ try {
+ jos = new JarOutputStream(new FileOutputStream(newBundle),
newMF);
JarEntry je = null;
while ((je = jis.getNextJarEntry()) != null) {
try {
@@ -76,9 +80,16 @@ public class BundleUtil {
jis.closeEntry();;
}
}
+ } finally {
+ if(jos != null) {
+ jos.close();
+ }
}
-
return newBundle;
+ } finally {
+ if(jis != null) {
+ jis.close();
+ }
}
}
Modified:
sling/trunk/bundles/commons/osgi/src/test/java/org/apache/sling/commons/osgi/BundleUtilTest.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/commons/osgi/src/test/java/org/apache/sling/commons/osgi/BundleUtilTest.java?rev=1721192&r1=1721191&r2=1721192&view=diff
==============================================================================
---
sling/trunk/bundles/commons/osgi/src/test/java/org/apache/sling/commons/osgi/BundleUtilTest.java
(original)
+++
sling/trunk/bundles/commons/osgi/src/test/java/org/apache/sling/commons/osgi/BundleUtilTest.java
Mon Dec 21 15:25:28 2015
@@ -18,7 +18,12 @@
*/
package org.apache.sling.commons.osgi;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -32,11 +37,15 @@ import java.util.jar.Manifest;
import org.junit.Test;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
public class BundleUtilTest {
+
+ private static void closeQuietly(Closeable c) {
+ try {
+ c.close();
+ } catch(IOException ignore) {
+ }
+ }
+
@Test
public void testBSNRenaming() throws IOException {
File tempDir = new File(System.getProperty("java.io.tmpdir"));
@@ -49,8 +58,11 @@ public class BundleUtilTest {
try {
compareJarContents(originalFile, generatedFile);
- try (JarFile jfOrg = new JarFile(originalFile);
- JarFile jfNew = new JarFile(generatedFile)) {
+ JarFile jfOrg = null;
+ JarFile jfNew = null;
+ try {
+ jfOrg = new JarFile(originalFile);
+ jfNew = new JarFile(generatedFile);
Manifest mfOrg = jfOrg.getManifest();
Manifest mfNew = jfNew.getManifest();
@@ -69,6 +81,9 @@ public class BundleUtilTest {
assertEquals("Different keys: " + key, orgVal,
newVal);
}
}
+ } finally {
+ closeQuietly(jfOrg);
+ closeQuietly(jfNew);
}
} finally {
@@ -77,8 +92,11 @@ public class BundleUtilTest {
}
private static void compareJarContents(File orgJar, File actualJar) throws
IOException {
- try (JarInputStream jis1 = new JarInputStream(new
FileInputStream(orgJar));
- JarInputStream jis2 = new JarInputStream(new
FileInputStream(actualJar))) {
+ JarInputStream jis1 = null;
+ JarInputStream jis2 = null;
+ try {
+ jis1 = new JarInputStream(new FileInputStream(orgJar));
+ jis2 = new JarInputStream(new FileInputStream(actualJar));
JarEntry je1 = null;
while ((je1 = jis1.getNextJarEntry()) != null) {
if (je1.isDirectory())
@@ -103,6 +121,9 @@ public class BundleUtilTest {
jis2.closeEntry();
}
}
+ } finally {
+ closeQuietly(jis1);
+ closeQuietly(jis2);
}
}