From 7f8890bb51995e87f5126ecd4f2b41df7cf7effc Mon Sep 17 00:00:00 2001 From: Simon Chemouil Date: Sat, 5 Apr 2014 17:30:15 +0200 Subject: [PATCH 1/2] Made L4Z Java's JAR a valid OSGi bundle. - computing the proper Import/Export package manifest entries using bnd - replaced two calls to Class.forName with safer equivalents within OSGi --- build.xml | 22 +++++++++++++++++-- lz4.bnd | 4 ++++ src/java/net/jpountz/lz4/LZ4Factory.java | 2 +- .../net/jpountz/xxhash/XXHashFactory.java | 2 +- 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 lz4.bnd diff --git a/build.xml b/build.xml index 283366ce..ebfb2bc4 100644 --- a/build.xml +++ b/build.xml @@ -81,6 +81,14 @@ + + + + + + + @@ -270,7 +278,7 @@ + destfile="${dist}/${ivy.module}.jar"> @@ -279,6 +287,16 @@ + + + + + + + + + + - + diff --git a/lz4.bnd b/lz4.bnd new file mode 100644 index 00000000..d4f5450a --- /dev/null +++ b/lz4.bnd @@ -0,0 +1,4 @@ +Bundle-SymbolicName: lz4-java +Bundle-Name: LZ4 Java Compression +Bundle-Version: ${ivy.revision} +Export-Package: net.jpountz.* diff --git a/src/java/net/jpountz/lz4/LZ4Factory.java b/src/java/net/jpountz/lz4/LZ4Factory.java index ef0498cc..807b4659 100644 --- a/src/java/net/jpountz/lz4/LZ4Factory.java +++ b/src/java/net/jpountz/lz4/LZ4Factory.java @@ -142,7 +142,7 @@ public static LZ4Factory fastestInstance() { @SuppressWarnings("unchecked") private static T classInstance(String cls) throws NoSuchFieldException, SecurityException, ClassNotFoundException, IllegalArgumentException, IllegalAccessException { - final Class c = Class.forName(cls); + final Class c = LZ4Factory.class.getClassLoader().loadClass(cls); Field f = c.getField("INSTANCE"); return (T) f.get(null); } diff --git a/src/java/net/jpountz/xxhash/XXHashFactory.java b/src/java/net/jpountz/xxhash/XXHashFactory.java index 656b2312..0f20aac2 100644 --- a/src/java/net/jpountz/xxhash/XXHashFactory.java +++ b/src/java/net/jpountz/xxhash/XXHashFactory.java @@ -140,7 +140,7 @@ public static XXHashFactory fastestInstance() { @SuppressWarnings("unchecked") private static T classInstance(String cls) throws NoSuchFieldException, SecurityException, ClassNotFoundException, IllegalArgumentException, IllegalAccessException { - final Class c = Class.forName(cls); + final Class c = XXHashFactory.class.getClassLoader().loadClass(cls); Field f = c.getField("INSTANCE"); return (T) f.get(null); } From dc8d84a1f0bf3a7814a182ad0509fab5d4228e25 Mon Sep 17 00:00:00 2001 From: Simon Chemouil Date: Sat, 5 Apr 2014 18:15:35 +0200 Subject: [PATCH 2/2] Now exporting package versions matching the ivy revision --- build.xml | 9 +++++++++ lz4.bnd | 5 +++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/build.xml b/build.xml index ebfb2bc4..b8b75b1d 100644 --- a/build.xml +++ b/build.xml @@ -289,6 +289,15 @@ + + + diff --git a/lz4.bnd b/lz4.bnd index d4f5450a..c039cee4 100644 --- a/lz4.bnd +++ b/lz4.bnd @@ -1,4 +1,5 @@ Bundle-SymbolicName: lz4-java Bundle-Name: LZ4 Java Compression -Bundle-Version: ${ivy.revision} -Export-Package: net.jpountz.* +Bundle-Version:${ivy.revision} +Export-Package: net.jpountz.*;version:=${packages.version} +