Replaced SystemInfo.getMachineArchitecture() with getArchitecture() and getArchitectureName().

This commit is contained in:
Adam Murdoch
2013-12-10 14:28:48 +11:00
parent f677815cab
commit 81e0adbbcd
5 changed files with 31 additions and 9 deletions

View File

@@ -21,6 +21,8 @@ package net.rubygrapefruit.platform;
*/
@ThreadSafe
public interface SystemInfo extends NativeIntegration {
enum Architecture { i386, amd64 }
/**
* Returns the name of the kernel for the current operating system.
*/
@@ -33,9 +35,15 @@ public interface SystemInfo extends NativeIntegration {
@ThreadSafe
String getKernelVersion();
/**
* Returns the machine architecture name, as reported by the operating system.
*/
@ThreadSafe
String getArchitectureName();
/**
* Returns the machine architecture, as reported by the operating system.
*/
@ThreadSafe
String getMachineArchitecture();
Architecture getArchitecture();
}

View File

@@ -32,18 +32,19 @@ public class DefaultSystemInfo implements SystemInfo {
}
}
@Override
public String getKernelName() {
return systemInfo.getKernelName();
}
@Override
public String getKernelVersion() {
return systemInfo.getKernelVersion();
}
@Override
public String getMachineArchitecture() {
return systemInfo.getMachineArchitecture();
public String getArchitectureName() {
return systemInfo.getArchitectureName();
}
public Architecture getArchitecture() {
return systemInfo.getArchitecture();
}
}

View File

@@ -16,6 +16,7 @@
package net.rubygrapefruit.platform.internal;
import net.rubygrapefruit.platform.NativeException;
import net.rubygrapefruit.platform.SystemInfo;
public class MutableSystemInfo implements SystemInfo {
@@ -32,10 +33,21 @@ public class MutableSystemInfo implements SystemInfo {
return osVersion;
}
public String getMachineArchitecture() {
public String getArchitectureName() {
return machineArchitecture;
}
public Architecture getArchitecture() {
if (machineArchitecture.equals("amd64") || machineArchitecture.equals("x86_64")) {
return Architecture.amd64;
}
if (machineArchitecture.equals("i386") || machineArchitecture.equals("x86")) {
return Architecture.i386;
}
throw new NativeException(String.format("Cannot determine architecture from kernel architecture name '%s'.",
machineArchitecture));
}
// Called from native code
void windows(int major, int minor, int build, boolean workstation, String arch) {
osName = toWindowsVersionName(major, minor, workstation);

View File

@@ -33,6 +33,7 @@ class SystemInfoTest extends Specification {
expect:
systemInfo.kernelName
systemInfo.kernelVersion
systemInfo.machineArchitecture
systemInfo.architectureName
systemInfo.architecture
}
}

View File

@@ -50,7 +50,7 @@ public class Main {
System.out.println("* Encoding: " + System.getProperty("file.encoding"));
SystemInfo systemInfo = Native.get(SystemInfo.class);
System.out.println("* Kernel: " + systemInfo.getKernelName() + ' ' + systemInfo.getKernelVersion() + ' ' + systemInfo.getMachineArchitecture());
System.out.println("* Kernel: " + systemInfo.getKernelName() + ' ' + systemInfo.getKernelVersion() + ' ' + systemInfo.getArchitectureName() + " (" + systemInfo.getArchitecture() + ")");
Process process = Native.get(Process.class);
System.out.println("* PID: " + process.getProcessId());