commit
b83b6a76e2
56
pom.xml
56
pom.xml
|
@ -82,7 +82,6 @@
|
|||
</testResource>
|
||||
</testResources>
|
||||
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
@ -171,9 +170,10 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<version>2.3.4</version>
|
||||
<version>2.3.7</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<manifestLocation>META-INF</manifestLocation>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${pproject.name}</Bundle-Name>
|
||||
|
@ -181,8 +181,56 @@
|
|||
<Bundle-Activator>org.xerial.snappy.SnappyBundleActivator</Bundle-Activator>
|
||||
<Export-Package>org.xerial.snappy</Export-Package>
|
||||
<Import-Package>org.osgi.framework;version="[1.5,2)"</Import-Package>
|
||||
<Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
|
||||
<Bundle-NativeCode>
|
||||
org/xerial/snappy/native/Windows/amd64/snappyjava.dll;selection-filter="(&(osgi.arch=x86_64)(osgi.os=win32))",
|
||||
org/xerial/snappy/native/Windows/x86/snappyjava.dll;selection-filter="(&(osgi.arch=x86)(osgi.os=win32))",
|
||||
org/xerial/snappy/native/Mac/i386/libsnappyjava.jnilib;selection-filter="(&(osgi.arch=x86)(osgi.os=macosx))",
|
||||
org/xerial/snappy/native/Mac/x86_64/libsnappyjava.jnilib;selection-filter="(&(osgi.arch=x86_64)(osgi.os=macosx))",
|
||||
org/xerial/snappy/native/Linux/amd64/libsnappyjava.so;selection-filter="(&(osgi.arch=x86_64)(osgi.os=linux))",
|
||||
org/xerial/snappy/native/Linux/i386/libsnappyjava.so;selection-filter="(&(osgi.arch=x86)(osgi.os=linux))",
|
||||
org/xerial/snappy/native/Linux/arm/libsnappyjava.so;selection-filter="(&(osgi.arch=arm)(osgi.os=linux))"
|
||||
</Bundle-NativeCode>
|
||||
<!-- TODO: unsure about ARMHF -->
|
||||
</instructions>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>bundle-manifest</id>
|
||||
<phase>process-classes</phase>
|
||||
<goals>
|
||||
<goal>manifest</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<index>true</index>
|
||||
<manifestFile>META-INF/MANIFEST.MF</manifestFile>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>2.4.1</version>
|
||||
<configuration>
|
||||
<followSymLinks>false</followSymLinks>
|
||||
<filesets>
|
||||
<fileset>
|
||||
<directory>META-INF</directory>
|
||||
<includes>
|
||||
<include>MANIFEST.MF</include>
|
||||
</includes>
|
||||
</fileset>
|
||||
</filesets>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
|
@ -205,6 +253,7 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
|
||||
<extensions>
|
||||
|
@ -254,7 +303,6 @@
|
|||
</profile>
|
||||
</profiles>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
|
@ -285,5 +333,7 @@
|
|||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
//--------------------------------------
|
||||
package org.xerial.snappy;
|
||||
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleActivator;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
|
@ -35,12 +38,23 @@ import org.osgi.framework.BundleContext;
|
|||
*/
|
||||
public class SnappyBundleActivator implements BundleActivator
|
||||
{
|
||||
public void start(BundleContext context) throws Exception {
|
||||
/**
|
||||
* Name of the Snappy native library
|
||||
*/
|
||||
public static final String LIBRARY_NAME = "snappyjava";
|
||||
|
||||
/**
|
||||
* Make a call to {@link System#loadLibrary(String)} to load the native library which assumes
|
||||
* that the library is available on the path based on this {@link Bundle}'s {@link Manifest}.
|
||||
*/
|
||||
public void start(BundleContext context) throws Exception
|
||||
{
|
||||
System.loadLibrary(System.mapLibraryName(LIBRARY_NAME));
|
||||
SnappyLoader.setApi(new SnappyNative());
|
||||
}
|
||||
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
|
||||
public void stop(BundleContext context) throws Exception
|
||||
{
|
||||
SnappyLoader.setApi(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,7 +24,13 @@
|
|||
//--------------------------------------
|
||||
package org.xerial.snappy;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
|
@ -87,8 +93,18 @@ public class SnappyLoader
|
|||
public static final String KEY_SNAPPY_USE_SYSTEMLIB = "org.xerial.snappy.use.systemlib";
|
||||
public static final String KEY_SNAPPY_DISABLE_BUNDLED_LIBS = "org.xerial.snappy.disable.bundled.libs"; // Depreciated, but preserved for backward compatibility
|
||||
|
||||
private static boolean isLoaded = false;
|
||||
private static Object api = null;
|
||||
private static volatile boolean isLoaded = false;
|
||||
private static volatile Object api = null;
|
||||
|
||||
/**
|
||||
* Set the api instance.
|
||||
*
|
||||
* @param nativeCode
|
||||
*/
|
||||
static synchronized void setApi(Object nativeCode)
|
||||
{
|
||||
api = nativeCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* load system properties when configuration file of the name
|
||||
|
@ -200,8 +216,8 @@ public class SnappyLoader
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
static synchronized Object load() {
|
||||
|
||||
static synchronized Object load()
|
||||
{
|
||||
if (api != null)
|
||||
return api;
|
||||
|
||||
|
@ -216,7 +232,7 @@ public class SnappyLoader
|
|||
isLoaded = true;
|
||||
// Look up SnappyNative, injected to the root classloder, using reflection in order to avoid the initialization of SnappyNative class in this context class loader.
|
||||
Object nativeCode = Class.forName("org.xerial.snappy.SnappyNative").newInstance();
|
||||
api = nativeCode;
|
||||
setApi(nativeCode);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
Loading…
Reference in New Issue