diff options
author | Jakob Odersky <jodersky@gmail.com> | 2015-12-06 17:03:08 -0800 |
---|---|---|
committer | Jakob Odersky <jodersky@gmail.com> | 2015-12-06 17:09:40 -0800 |
commit | e2505d1d9e2e49554057a8cd5fb71b0ac0e3ba63 (patch) | |
tree | f4fec79ba707aa9b2dec903d54a164f357961f19 /jni-library/src | |
parent | 3e90312b3f2d912bf27e91b454a6ef21a81a2fc5 (diff) | |
download | sbt-jni-e2505d1d9e2e49554057a8cd5fb71b0ac0e3ba63.tar.gz sbt-jni-e2505d1d9e2e49554057a8cd5fb71b0ac0e3ba63.tar.bz2 sbt-jni-e2505d1d9e2e49554057a8cd5fb71b0ac0e3ba63.zip |
Use separate project for native libraries
Diffstat (limited to 'jni-library/src')
-rw-r--r-- | jni-library/src/main/scala/ch/jodersky/jni/NativeLoader.scala | 19 | ||||
-rw-r--r-- | jni-library/src/main/scala/ch/jodersky/jni/Platform.scala | 6 |
2 files changed, 15 insertions, 10 deletions
diff --git a/jni-library/src/main/scala/ch/jodersky/jni/NativeLoader.scala b/jni-library/src/main/scala/ch/jodersky/jni/NativeLoader.scala index 46d4b2d..261e52b 100644 --- a/jni-library/src/main/scala/ch/jodersky/jni/NativeLoader.scala +++ b/jni-library/src/main/scala/ch/jodersky/jni/NativeLoader.scala @@ -1,11 +1,10 @@ package ch.jodersky.jni import java.io.{File, FileOutputStream, InputStream, OutputStream} -import scala.io.Source /** - * Provides enhanced native library loading functionality. - */ + * Provides enhanced native library loading functionality. + */ object NativeLoader { /** Name of the shared library file that is contained in a jar. */ @@ -13,7 +12,7 @@ object NativeLoader { final val BufferSize = 4096 - /** Extract a resource from this class loader to a temporary file. */ + /** Extracts a resource from this class loader to a temporary file. */ private def extract(path: String): Option[File] = { var in: Option[InputStream] = None var out: Option[OutputStream] = None @@ -45,12 +44,16 @@ object NativeLoader { msg ) + /** + * Gets the absolute, full path of a resource on the classpath, given a libraryPath + * and platform. + */ def fullLibraryPath(libraryPath: String, platform: Platform) = { - libraryPath + "/native/" + platform.id + "/" + LibraryName + libraryPath + "/native/" + platform.id + "/" + LibraryName } private def loadFromJar(libraryPath: String): Unit = { - val platform = Platform.current.getOrElse{ + val platform = Platform.current.getOrElse { loadError("Cannot determine current platform.") } @@ -63,10 +66,10 @@ object NativeLoader { } /** - * Load a native library from the available library path or fall back + * Loads a native library from the available library path or fall back * to extracting and loading a native library from available resources. */ - def load(library: String, libraryPath: String): Unit = try { + def load(libraryPath: String, library: String): Unit = try { System.loadLibrary(library) } catch { case ex: UnsatisfiedLinkError => loadFromJar(libraryPath) diff --git a/jni-library/src/main/scala/ch/jodersky/jni/Platform.scala b/jni-library/src/main/scala/ch/jodersky/jni/Platform.scala index db1662d..cff9e95 100644 --- a/jni-library/src/main/scala/ch/jodersky/jni/Platform.scala +++ b/jni-library/src/main/scala/ch/jodersky/jni/Platform.scala @@ -20,15 +20,16 @@ case class Platform private (arch: String, kernel: String) { object Platform { + /** The unknown platform. */ final val Unknown = Platform("unknown", "unknown") - /** Create a platform with spaces stripped and case normalized. */ + /** Creates a platform with spaces stripped and case normalized. */ def normalized(arch: String, kernel: String): Platform = { def normalize(str: String) = str.toLowerCase.filter(!_.isWhitespace) Platform(normalize(arch), normalize(kernel)) } - /** Run 'uname' to determine current platform. Returns None if uname does not exist. */ + /** Runs 'uname' to determine current platform. Returns None if uname does not exist. */ def uname: Option[Platform] = { val lineOpt = try { Some(Process("uname -sm").lines.head) @@ -45,6 +46,7 @@ object Platform { } } + /** Determines platform the current JVM is running on. */ def current = uname } |