First pass for windows support.

This commit is contained in:
Adam Murdoch
2012-08-04 12:32:15 +10:00
parent dadf93caf8
commit e5537494b0
11 changed files with 689 additions and 617 deletions

View File

@@ -1,61 +1,81 @@
package net.rubygrapefruit.platform.internal;
public abstract class Platform {
private static Platform platform;
public static Platform current() {
synchronized (Platform.class) {
if (platform == null) {
String osName = System.getProperty("os.name").toLowerCase();
if (osName.contains("windows")) {
platform = new Windows();
} else if (osName.contains("linux")) {
platform = new Linux();
} else if (osName.contains("os x")) {
platform = new OsX();
} else {
platform = new Unsupported();
}
}
return platform;
}
}
public boolean isSupported() {
return true;
}
public abstract String getLibraryName();
private static class Windows extends Platform {
@Override
public String getLibraryName() {
return "native-platform.dll";
}
}
private static class Linux extends Platform {
@Override
public String getLibraryName() {
return "libnative-platform.so";
}
}
private static class OsX extends Platform {
@Override
public String getLibraryName() {
return "libnative-platform.dylib";
}
}
private static class Unsupported extends Platform {
@Override
public boolean isSupported() {
return false;
}
public String getLibraryName() {
throw new UnsupportedOperationException();
}
}
}
package net.rubygrapefruit.platform.internal;
public abstract class Platform {
private static Platform platform;
public static Platform current() {
synchronized (Platform.class) {
if (platform == null) {
String osName = System.getProperty("os.name").toLowerCase();
if (osName.contains("windows")) {
platform = new Windows();
} else if (osName.contains("linux")) {
platform = new Linux();
} else if (osName.contains("os x")) {
platform = new OsX();
} else {
platform = new Unsupported();
}
}
return platform;
}
}
public boolean isSupported() {
return true;
}
public boolean isPosix() {
return false;
}
public boolean isWindows() {
return false;
}
public abstract String getLibraryName();
private static class Windows extends Platform {
@Override
public boolean isWindows() {
return true;
}
@Override
public String getLibraryName() {
return "native-platform.dll";
}
}
private static abstract class Posix extends Platform {
@Override
public boolean isPosix() {
return true;
}
}
private static class Linux extends Posix {
@Override
public String getLibraryName() {
return "libnative-platform.so";
}
}
private static class OsX extends Posix {
@Override
public String getLibraryName() {
return "libnative-platform.dylib";
}
}
private static class Unsupported extends Platform {
@Override
public boolean isSupported() {
return false;
}
public String getLibraryName() {
throw new UnsupportedOperationException();
}
}
}