Initialer Commit
commit
2ea5215d7f
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
|
@ -0,0 +1,4 @@
|
|||
.DS_Store
|
||||
bin/*
|
||||
|
||||
/bin
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>org.hwo.platform</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,11 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
|
@ -0,0 +1,53 @@
|
|||
package org.hwo.platform;
|
||||
|
||||
public class Platform {
|
||||
|
||||
public enum OsType { UNKNOWN, LINUX, OSX, WINDOWS};
|
||||
public enum Bitness { B32, B64 };
|
||||
|
||||
public static OsType getOperatingSystem()
|
||||
{
|
||||
if (System.getProperty("os.name").equals("Mac OS X"))
|
||||
return OsType.OSX;
|
||||
if (System.getProperty("os.name").equals("Linux"))
|
||||
return OsType.LINUX;
|
||||
if (System.getProperty("os.name").startsWith("Windows"))
|
||||
return OsType.WINDOWS;
|
||||
|
||||
return OsType.UNKNOWN;
|
||||
}
|
||||
|
||||
public static Bitness getBitness(){
|
||||
String arch = System.getProperty("os.arch");
|
||||
if (arch == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (arch.equals("x86")){
|
||||
return Bitness.B32;
|
||||
} else if (arch.equals("i386")){
|
||||
return Bitness.B32;
|
||||
} else if (arch.equals("xmd64")){
|
||||
return Bitness.B64;
|
||||
} else if (arch.equals("amd64")){
|
||||
return Bitness.B64;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String PlatformName(){
|
||||
OsType ost = getOperatingSystem();
|
||||
Bitness bit = getBitness();
|
||||
|
||||
return String.format("%s%s",
|
||||
(ost == OsType.LINUX) ? "linux" :
|
||||
(ost == OsType.OSX) ? "osx" :
|
||||
(ost == OsType.WINDOWS) ? "mswin" :
|
||||
"unknown",
|
||||
(bit == Bitness.B32) ? "32" :
|
||||
(bit == Bitness.B64) ? "64" :
|
||||
"XX"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package org.hwo.platform;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.hwo.platform.natives.NativeLoader;
|
||||
|
||||
public class Ressource {
|
||||
|
||||
public static boolean extract(Class<?> clazz,String resource,String filename){
|
||||
return extract(
|
||||
clazz.getResourceAsStream(resource),
|
||||
filename
|
||||
);
|
||||
}
|
||||
|
||||
public static boolean extract(String resource,String filename){
|
||||
return extract(
|
||||
NativeLoader.class.getResourceAsStream(resource),
|
||||
filename
|
||||
);
|
||||
}
|
||||
|
||||
private static boolean extract(InputStream in,String filename){
|
||||
try {
|
||||
FileOutputStream fos = new FileOutputStream(filename);
|
||||
byte[] buffer = new byte[in.available()];
|
||||
in.read(buffer);
|
||||
fos.write(buffer);
|
||||
fos.close();
|
||||
|
||||
return true;
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
package org.hwo.platform.natives;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputStream.GetField;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import javax.management.RuntimeErrorException;
|
||||
|
||||
import org.hwo.platform.Platform;
|
||||
import org.hwo.platform.Platform.Bitness;
|
||||
import org.hwo.platform.Platform.OsType;
|
||||
import org.hwo.platform.Ressource;
|
||||
|
||||
public class NativeLoader {
|
||||
private static boolean patchedLinux = false;
|
||||
|
||||
public static String nativeLibraryName(String libName){
|
||||
switch (Platform.getOperatingSystem())
|
||||
{
|
||||
case LINUX:
|
||||
return String.format("lib%s.so",libName);
|
||||
case OSX:
|
||||
return String.format("lib%s.dylib",libName);
|
||||
case WINDOWS:
|
||||
return String.format("%s.dll",libName);
|
||||
default:
|
||||
throw new RuntimeException("Betriebssystem nicht unterstützt!");
|
||||
}
|
||||
}
|
||||
|
||||
public static String nativeResourceName(String libName){
|
||||
return String.format("/native/%s/%s", Platform.PlatformName(), nativeLibraryName(libName));
|
||||
}
|
||||
|
||||
/*
|
||||
* loadLibrary()
|
||||
*
|
||||
* Versuche native Bibliothek zu laden
|
||||
*
|
||||
* 1. System.loadLibrary(...)
|
||||
* 2. System.load(...)
|
||||
* 3. /native/...
|
||||
* 4. CLASSPATH:/native/...
|
||||
*
|
||||
*/
|
||||
public static void loadLibrary(String libName)
|
||||
{
|
||||
try
|
||||
{
|
||||
System.loadLibrary(libName);
|
||||
System.err.println(String.format("NativeLoader.loadLibrary(): System.loadLibrary('%s') erfolgreich",libName));
|
||||
return;
|
||||
} catch (UnsatisfiedLinkError e)
|
||||
{
|
||||
System.err.println(String.format("NativeLoader.loadLibrary(): System.loadLibrary('%s') erfolglos",libName));
|
||||
};
|
||||
|
||||
String libFileName = new File("").getAbsolutePath() + File.separator + nativeLibraryName(libName);
|
||||
try
|
||||
{
|
||||
System.load(libFileName);
|
||||
System.err.println(String.format("NativeLoader.loadLibrary(): System.load('%s') erfolgreich",libFileName));
|
||||
return;
|
||||
} catch (UnsatisfiedLinkError e)
|
||||
{
|
||||
System.err.println(String.format("NativeLoader.loadLibrary(): System.load('%s') erfolglos",libFileName));
|
||||
};
|
||||
|
||||
String nativeResourceName = nativeResourceName(libName);
|
||||
try
|
||||
{
|
||||
System.load(nativeResourceName);
|
||||
System.err.println(String.format("NativeLoader.loadLibrary(): System.load('%s') erfolgreich",nativeResourceName));
|
||||
return;
|
||||
} catch (UnsatisfiedLinkError e)
|
||||
{
|
||||
System.err.println(String.format("NativeLoader.loadLibrary(): System.load('%s') erfolglos",nativeResourceName));
|
||||
};
|
||||
|
||||
File tempLibFile;
|
||||
try {
|
||||
tempLibFile = File.createTempFile("extract-", nativeLibraryName(libName));
|
||||
} catch (IOException ioe){
|
||||
System.err.println(String.format("NativeLoader.loadLibrary(): File.createTempFile('extract-','%s') erfolglos",nativeLibraryName(libName)));
|
||||
throw new RuntimeException(ioe);
|
||||
}
|
||||
|
||||
try {
|
||||
Ressource.extract(nativeResourceName, tempLibFile.getAbsolutePath());
|
||||
System.load(tempLibFile.getAbsolutePath());
|
||||
System.err.println(String.format("NativeLoader.loadLibrary(): System.load('%s') erfolgreich",tempLibFile.getAbsolutePath()));
|
||||
return;
|
||||
} catch (UnsatisfiedLinkError e)
|
||||
{
|
||||
System.err.println(String.format("NativeLoader.loadLibrary(): System.load('%s') erfolglos",tempLibFile.getAbsolutePath()));
|
||||
} catch (Exception e){
|
||||
System.err.println(String.format("NativeLoader.loadLibrary(): Resource.extract('%s','%s') erfolglos",nativeResourceName,tempLibFile.getAbsolutePath()));
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
/* Suchpfad um aktuelles Arbeitsberzeichnis erweitern */
|
||||
System.setProperty("java.library.path",String.format(".:%s",System.getProperty("java.library.path")));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue