Updated to use a Gradle 1.11 nightly
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package net.rubygrapefruit.platform.internal;
|
||||
|
||||
public class LibraryDef {
|
||||
final String name;
|
||||
final String platform;
|
||||
|
||||
public LibraryDef(String name, String platform) {
|
||||
this.name = name;
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || obj.getClass() != getClass()) {
|
||||
return false;
|
||||
}
|
||||
LibraryDef other = (LibraryDef) obj;
|
||||
return name.equals(other.name) && platform.equals(other.platform);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return name.hashCode() ^ platform.hashCode();
|
||||
}
|
||||
}
|
||||
@@ -38,9 +38,9 @@ public class NativeLibraryLoader {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
File libFile = nativeLibraryLocator.find(libraryFileName);
|
||||
File libFile = nativeLibraryLocator.find(new LibraryDef(libraryFileName, platform.getId()));
|
||||
if (libFile == null) {
|
||||
throw new NativeIntegrationUnavailableException(String.format("Native library is not available for %s.", platform));
|
||||
throw new NativeIntegrationUnavailableException(String.format("Native library '%s' is not available for %s.", libraryFileName, platform));
|
||||
}
|
||||
System.load(libFile.getCanonicalPath());
|
||||
} catch (NativeException e) {
|
||||
|
||||
@@ -30,9 +30,10 @@ public class NativeLibraryLocator {
|
||||
this.extractDir = extractDir;
|
||||
}
|
||||
|
||||
public File find(String libraryFileName) throws IOException {
|
||||
public File find(LibraryDef libraryDef) throws IOException {
|
||||
String resourceName = String.format("net/rubygrapefruit/platform/%s/%s", libraryDef.platform, libraryDef.name);
|
||||
if (extractDir != null) {
|
||||
File libFile = new File(extractDir, String.format("%s/%s", NativeLibraryFunctions.VERSION, libraryFileName));
|
||||
File libFile = new File(extractDir, String.format("%s/%s", NativeLibraryFunctions.VERSION, libraryDef.name));
|
||||
File lockFile = new File(libFile.getParentFile(), libFile.getName() + ".lock");
|
||||
lockFile.getParentFile().mkdirs();
|
||||
lockFile.createNewFile();
|
||||
@@ -44,7 +45,7 @@ public class NativeLibraryLocator {
|
||||
// Library has been extracted
|
||||
return libFile;
|
||||
}
|
||||
URL resource = getClass().getClassLoader().getResource(libraryFileName);
|
||||
URL resource = getClass().getClassLoader().getResource(resourceName);
|
||||
if (resource != null) {
|
||||
// Extract library and write marker to lock file
|
||||
libFile.getParentFile().mkdirs();
|
||||
@@ -58,20 +59,20 @@ public class NativeLibraryLocator {
|
||||
lockFileAccess.close();
|
||||
}
|
||||
} else {
|
||||
URL resource = getClass().getClassLoader().getResource(libraryFileName);
|
||||
URL resource = getClass().getClassLoader().getResource(resourceName);
|
||||
if (resource != null) {
|
||||
File libFile;
|
||||
File libDir = File.createTempFile("native-platform", "dir");
|
||||
libDir.delete();
|
||||
libDir.mkdirs();
|
||||
libFile = new File(libDir, libraryFileName);
|
||||
libFile = new File(libDir, libraryDef.name);
|
||||
libFile.deleteOnExit();
|
||||
copy(resource, libFile);
|
||||
return libFile;
|
||||
}
|
||||
}
|
||||
|
||||
File libFile = new File("build/binaries/" + libraryFileName);
|
||||
File libFile = new File(String.format("build/binaries/%s/%s", libraryDef.platform, libraryDef.name));
|
||||
if (libFile.isFile()) {
|
||||
return libFile;
|
||||
}
|
||||
|
||||
@@ -44,12 +44,14 @@ public abstract class Platform {
|
||||
platform = new Linux32Bit();
|
||||
}
|
||||
} else if (osName.contains("os x")) {
|
||||
if (arch.equals("i386") || arch.equals("x86_64") || arch.equals("amd64")) {
|
||||
platform = new OsX();
|
||||
if (arch.equals("i386")) {
|
||||
platform = new OsX32Bit();
|
||||
}
|
||||
} else if (osName.contains("sunos")) {
|
||||
platform = new Solaris();
|
||||
} else {
|
||||
else if (arch.equals("x86_64") || arch.equals("amd64")) {
|
||||
platform = new OsX64Bit();
|
||||
}
|
||||
}
|
||||
if (platform == null) {
|
||||
platform = new Unsupported();
|
||||
}
|
||||
}
|
||||
@@ -74,6 +76,8 @@ public abstract class Platform {
|
||||
throw new NativeIntegrationUnavailableException(String.format("Native integration is not available for %s.", toString()));
|
||||
}
|
||||
|
||||
public abstract String getId();
|
||||
|
||||
private static String getOperatingSystem() {
|
||||
return System.getProperty("os.name");
|
||||
}
|
||||
@@ -88,6 +92,11 @@ public abstract class Platform {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLibraryName() {
|
||||
return "native-platform.dll";
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends NativeIntegration> T get(Class<T> type, NativeLibraryLoader nativeLibraryLoader) {
|
||||
if (type.equals(Process.class)) {
|
||||
@@ -111,15 +120,15 @@ public abstract class Platform {
|
||||
|
||||
private static class Window32Bit extends Windows {
|
||||
@Override
|
||||
public String getLibraryName() {
|
||||
return "native-platform-windows-i386.dll";
|
||||
public String getId() {
|
||||
return "windows-i386";
|
||||
}
|
||||
}
|
||||
|
||||
private static class Window64Bit extends Windows {
|
||||
@Override
|
||||
public String getLibraryName() {
|
||||
return "native-platform-windows-amd64.dll";
|
||||
public String getId() {
|
||||
return "windows-amd64";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,6 +162,15 @@ public abstract class Platform {
|
||||
}
|
||||
|
||||
private abstract static class Unix extends Posix {
|
||||
@Override
|
||||
public String getLibraryName() {
|
||||
return "libnative-platform.so";
|
||||
}
|
||||
|
||||
@Override
|
||||
String getCursesLibraryName() {
|
||||
return "libnative-platform-curses.so";
|
||||
}
|
||||
}
|
||||
|
||||
private abstract static class Linux extends Unix {
|
||||
@@ -167,41 +185,19 @@ public abstract class Platform {
|
||||
|
||||
private static class Linux32Bit extends Linux {
|
||||
@Override
|
||||
public String getLibraryName() {
|
||||
return "libnative-platform-linux-i386.so";
|
||||
}
|
||||
|
||||
@Override
|
||||
String getCursesLibraryName() {
|
||||
return "libnative-platform-curses-linux-i386.so";
|
||||
public String getId() {
|
||||
return "linux-i386";
|
||||
}
|
||||
}
|
||||
|
||||
private static class Linux64Bit extends Linux {
|
||||
@Override
|
||||
public String getLibraryName() {
|
||||
return "libnative-platform-linux-amd64.so";
|
||||
}
|
||||
|
||||
@Override
|
||||
String getCursesLibraryName() {
|
||||
return "libnative-platform-curses-linux-amd64.so";
|
||||
public String getId() {
|
||||
return "linux-amd64";
|
||||
}
|
||||
}
|
||||
|
||||
private static class Solaris extends Unix {
|
||||
@Override
|
||||
public String getLibraryName() {
|
||||
return "libnative-platform-solaris.so";
|
||||
}
|
||||
|
||||
@Override
|
||||
String getCursesLibraryName() {
|
||||
return "libnative-platform-curses-solaris.so";
|
||||
}
|
||||
}
|
||||
|
||||
private static class OsX extends Posix {
|
||||
private static abstract class OsX extends Posix {
|
||||
@Override
|
||||
public <T extends NativeIntegration> T get(Class<T> type, NativeLibraryLoader nativeLibraryLoader) {
|
||||
if (type.equals(FileSystems.class)) {
|
||||
@@ -212,16 +208,34 @@ public abstract class Platform {
|
||||
|
||||
@Override
|
||||
public String getLibraryName() {
|
||||
return "libnative-platform-osx-universal.dylib";
|
||||
return "libnative-platform.dylib";
|
||||
}
|
||||
|
||||
@Override
|
||||
String getCursesLibraryName() {
|
||||
return "libnative-platform-curses-osx-universal.dylib";
|
||||
return "libnative-platform-curses.dylib";
|
||||
}
|
||||
}
|
||||
|
||||
private static class OsX32Bit extends OsX {
|
||||
@Override
|
||||
public String getId() {
|
||||
return "osx-i386";
|
||||
}
|
||||
}
|
||||
|
||||
private static class OsX64Bit extends OsX {
|
||||
@Override
|
||||
public String getId() {
|
||||
return "osx-amd64";
|
||||
}
|
||||
}
|
||||
|
||||
private static class Unsupported extends Platform {
|
||||
@Override
|
||||
public String getId() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user