Implemented SystemInfo for windows.
This commit is contained in:
@@ -38,8 +38,8 @@ libraries {
|
||||
args("-lcurses", "-arch", "x86_64", "-arch", "i386", "-o", outputFile)
|
||||
}
|
||||
} else if (org.gradle.internal.os.OperatingSystem.current().windows) {
|
||||
main.spec {
|
||||
baseName = 'native-platform-win32'
|
||||
i386.spec {
|
||||
baseName = 'native-platform-windows-i386'
|
||||
includes(["${org.gradle.internal.jvm.Jvm.current().javaHome}/include"])
|
||||
includes(["${org.gradle.internal.jvm.Jvm.current().javaHome}/include/win32"])
|
||||
args("/DWIN32")
|
||||
|
||||
@@ -128,7 +128,7 @@ You can run `$INSTALL_DIR/bin/native-platform` to run the test application.
|
||||
* Cache class, method and field lookups (in particular for String conversions).
|
||||
* Determine C charset once at startup
|
||||
* Change readLink() implementation so that it does not need to NULL terminate the encoded content
|
||||
* Implement java_to_char_str()
|
||||
* Don't use NewStringUTF() anywhere
|
||||
* Use iconv() to convert from C char string to UTF-16 when converting from C char string to Java String.
|
||||
* Support for cygwin terminal
|
||||
* Use TERM=xtermc instead of TERM=xterm on Solaris.
|
||||
@@ -141,8 +141,6 @@ You can run `$INSTALL_DIR/bin/native-platform` to run the test application.
|
||||
* Make native library extraction multi-process safe.
|
||||
* Initial release.
|
||||
* Use fully decomposed form for unicode file names on hfs+ filesystems.
|
||||
* Handle string encoding for file system details.
|
||||
* Handle string encoding for system info.
|
||||
|
||||
### Ideas
|
||||
|
||||
|
||||
@@ -12,7 +12,33 @@ void mark_failed_with_errno(JNIEnv *env, const char* message, jobject result) {
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_net_rubygrapefruit_platform_internal_jni_NativeLibraryFunctions_getPlatform(JNIEnv *env, jclass target) {
|
||||
Java_net_rubygrapefruit_platform_internal_jni_NativeLibraryFunctions_getSystemInfo(JNIEnv *env, jclass target, jobject info, jobject result) {
|
||||
jclass infoClass = env->GetObjectClass(info);
|
||||
|
||||
OSVERSIONINFOEX versionInfo;
|
||||
versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
|
||||
if (GetVersionEx((OSVERSIONINFO*)&versionInfo) == 0) {
|
||||
mark_failed_with_errno(env, "could not get version info", result);
|
||||
return;
|
||||
}
|
||||
|
||||
SYSTEM_INFO systemInfo;
|
||||
GetNativeSystemInfo(&systemInfo);
|
||||
jstring arch = NULL;
|
||||
if (systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) {
|
||||
arch = env->NewStringUTF("amd64");
|
||||
} else if (systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL) {
|
||||
arch = env->NewStringUTF("x86");
|
||||
} else if (systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64) {
|
||||
arch = env->NewStringUTF("ia64");
|
||||
} else {
|
||||
arch = env->NewStringUTF("unknown");
|
||||
}
|
||||
|
||||
jmethodID method = env->GetMethodID(infoClass, "windows", "(IIIZLjava/lang/String;)V");
|
||||
env->CallVoidMethod(info, method, versionInfo.dwMajorVersion, versionInfo.dwMinorVersion,
|
||||
versionInfo.dwBuildNumber, versionInfo.wProductType == VER_NT_WORKSTATION,
|
||||
arch);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
32
src/main/java/net/rubygrapefruit/platform/internal/MutableSystemInfo.java
Normal file → Executable file
32
src/main/java/net/rubygrapefruit/platform/internal/MutableSystemInfo.java
Normal file → Executable file
@@ -18,4 +18,36 @@ public class MutableSystemInfo implements SystemInfo {
|
||||
public String getMachineArchitecture() {
|
||||
return machineArchitecture;
|
||||
}
|
||||
|
||||
void windows(int major, int minor, int build, boolean workstation, String arch) {
|
||||
osName = toWindowsVersionName(major, minor, workstation);
|
||||
osVersion = String.format("%s.%s (build %s)", major, minor, build);
|
||||
machineArchitecture = arch;
|
||||
}
|
||||
|
||||
private String toWindowsVersionName(int major, int minor, boolean workstation) {
|
||||
switch (major) {
|
||||
case 5:
|
||||
switch (minor) {
|
||||
case 0:
|
||||
return "Windows 2000";
|
||||
case 1:
|
||||
return "Windows XP";
|
||||
case 2:
|
||||
return "Windows Server 2003";
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
switch (minor) {
|
||||
case 0:
|
||||
return workstation ? "Windows Vista" : "Windows Server 2008";
|
||||
case 1:
|
||||
return workstation ? "Windows 7" : "Windows Server 2008 R2";
|
||||
case 2:
|
||||
return workstation ? "Windows 8" : "Windows Server 2012";
|
||||
}
|
||||
break;
|
||||
}
|
||||
return "Windows (unknown version)";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,11 @@ public abstract class Platform {
|
||||
|
||||
@Override
|
||||
public String getLibraryName() {
|
||||
return "native-platform-win32.dll";
|
||||
if (getArchitecture().equals("x86")) {
|
||||
return "native-platform-windows-i386.dll";
|
||||
}
|
||||
throw new NativeIntegrationUnavailableException(String.format(
|
||||
"Native integration is not available for this architecture (%s) on Windows.", getArchitecture()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,6 +61,9 @@ public abstract class Platform {
|
||||
if (type.equals(Terminals.class)) {
|
||||
return type.cast(new WindowsTerminals());
|
||||
}
|
||||
if (type.equals(SystemInfo.class)) {
|
||||
return type.cast(new DefaultSystemInfo());
|
||||
}
|
||||
return super.get(type);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user