Some renames and javadoc.

This commit is contained in:
Adam Murdoch
2012-09-01 10:02:02 +10:00
parent ee7f527b41
commit 3e4dc956ed
11 changed files with 74 additions and 43 deletions

View File

@@ -9,14 +9,13 @@ These APIs support Java 5 and later. Some of these APIs overlap with APIs availa
### Generic
* Get and set UNIX file mode.
* Get PID of current process.
* Get kernel name and version.
* Get machine architecture.
### Terminal and console
These bindings work for both the UNIX terminal and Windows console:
These bindings work for both the UNIX terminal and the Windows console:
* Determine if stdout/stderr are attached to a terminal.
* Query the terminal size.
@@ -27,6 +26,7 @@ These bindings work for both the UNIX terminal and Windows console:
### File systems
* Get and set UNIX file mode.
* List the available file systems on the machine
* Query file system mount point.
* Query file system type.
@@ -37,7 +37,7 @@ These bindings work for both the UNIX terminal and Windows console:
Currently ported to OS X, Linux, Solaris and Windows. Tested on:
* OS X 10.7.4, 10.8 (i386 and x86_64)
* OS X 10.7.4, 10.8 (x86_64)
* Ubunutu 12.04 (amd64)
* Solaris 11 (x86)
* Windows 7 (amd64)
@@ -47,16 +47,18 @@ Currently ported to OS X, Linux, Solaris and Windows. Tested on:
Include `native-platform.jar` and `native-platform-jni.jar` in your classpath.
import net.rubygrapefruit.platform.Native;
import net.rubygrapefruit.platform.TerminalAccess;
import static net.rubygrapefruit.platform.TerminalAccess.Output.*;
import net.rubygrapefruit.platform.Terminals;
import net.rubygrapefruit.platform.Terminal;
import static net.rubygrapefruit.platform.Terminals.Output.*;
TerminalAccess terminalAccess = Native.get(TerminalAccess.class);
Terminals terminals = Native.get(Terminals.class);
// check if terminal
terminalAccess.isTerminal(Stdout);
terminals.isTerminal(Stdout);
// use terminal
terminalAccess.getTerminal(Stdout).bold();
Terminal stdout = terminals.getTerminal(Stdout);
stdout.bold();
System.out.println("bold text");
@@ -91,18 +93,30 @@ in `build/distributions/native-platform.zip`.
You can run `$INSTALL_DIR/bin/native-platform` to run the test application.
## Testing
* Test on IBM JVM.
* Test on Java 5, 6, 7.
* Test on Windows 7, Windows XP
## TODO
### Fixes
* Build 32 bit and 64 bit libraries.
* Windows: build 32 bit and 64 bit libraries.
* Windows: flush System.out or System.err on attribute change.
* Solaris: fix unicode file name handling.
* Windows: fail for unsupported architecture.
* Linux: fail for unsupported architecture.
* Linux: detect remote filesystems.
* Solaris: fix unicode file name handling.
* Solaris: fail for unsupported architecture.
* Solaris: build 32 bit and 64 bit libraries.
* Freebsd: finish port.
* Freebsd: fail for unsupported architecture.
* Freebsd: build 32 bit and 64 bit libraries.
### Improvements
* Handle multiple platforms in self-extracting jar.
* Support for cygwin terminal
* Use TERM=xtermc instead of TERM=xterm on Solaris.
* Add diagnostics for terminal.
@@ -110,14 +124,13 @@ You can run `$INSTALL_DIR/bin/native-platform` to run the test application.
* Version each native interface separately.
* String names for errno values.
* Split into multiple projects.
* Test on IBM JVM.
* Convert to c.
* Thread safety.
* Improve error message when unsupported capability is used.
* 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
* Handle string encoding for file system details.
* Handle string encoding for system info.
### Ideas

View File

@@ -18,13 +18,13 @@ public class Main {
System.out.println(" * " + fileSystem.getMountPoint() + ' ' + fileSystem.getFileSystemType() + ' ' + fileSystem.getDeviceName() + (fileSystem.isRemote() ? " remote" : " local"));
}
TerminalAccess terminalAccess = Native.get(TerminalAccess.class);
boolean stdoutIsTerminal = terminalAccess.isTerminal(TerminalAccess.Output.Stdout);
boolean stderrIsTerminal = terminalAccess.isTerminal(TerminalAccess.Output.Stderr);
Terminals terminals = Native.get(Terminals.class);
boolean stdoutIsTerminal = terminals.isTerminal(Terminals.Output.Stdout);
boolean stderrIsTerminal = terminals.isTerminal(Terminals.Output.Stderr);
System.out.println("* stdout: " + (stdoutIsTerminal ? "terminal" : "not a terminal"));
System.out.println("* stderr: " + (stderrIsTerminal ? "terminal" : "not a terminal"));
if (stdoutIsTerminal) {
Terminal terminal = terminalAccess.getTerminal(TerminalAccess.Output.Stdout);
Terminal terminal = terminals.getTerminal(Terminals.Output.Stdout);
TerminalSize terminalSize = terminal.getTerminalSize();
System.out.println("* terminal size: " + terminalSize.getCols() + " cols x " + terminalSize.getRows() + " rows");
System.out.println("* text attributes: " + (terminal.supportsTextAttributes() ? "yes" : "no"));

View File

@@ -1,7 +1,7 @@
package net.rubygrapefruit.platform;
/**
* Functions to query and modify a process' meta-data
* Functions to query and modify a process' state.
*
* Supported on Linux, OS X, Windows.
*/

View File

@@ -1,9 +1,27 @@
package net.rubygrapefruit.platform;
/**
* Provides access to some system information.
*/
public interface SystemInfo extends NativeIntegration {
String getKernelName();
/**
* Returns the name of the kernel for the current operating system.
*
* @throws NativeException on failure.
*/
String getKernelName() throws NativeException;
String getKernelVersion();
/**
* Returns the version of the kernel for the current operating system.
*
* @throws NativeException on failure.
*/
String getKernelVersion() throws NativeException;
String getMachineArchitecture();
/**
* Returns the machine architecture, as reported by the operating system.
*
* @throws NativeException on failure.
*/
String getMachineArchitecture() throws NativeException;
}

View File

@@ -5,7 +5,7 @@ package net.rubygrapefruit.platform;
*
* Supported on Linux, OS X, Windows.
*/
public interface TerminalAccess extends NativeIntegration {
public interface Terminals extends NativeIntegration {
enum Output {Stdout, Stderr}
/**

View File

@@ -58,8 +58,8 @@ public abstract class Platform {
if (type.equals(net.rubygrapefruit.platform.Process.class)) {
return type.cast(new DefaultProcess());
}
if (type.equals(TerminalAccess.class)) {
return type.cast(new WindowsTerminalAccess());
if (type.equals(Terminals.class)) {
return type.cast(new WindowsTerminals());
}
return super.get(type);
}
@@ -74,8 +74,8 @@ public abstract class Platform {
if (type.equals(Process.class)) {
return type.cast(new DefaultProcess());
}
if (type.equals(TerminalAccess.class)) {
return type.cast(new TerminfoTerminalAccess());
if (type.equals(Terminals.class)) {
return type.cast(new TerminfoTerminals());
}
if (type.equals(SystemInfo.class)) {
MutableSystemInfo systemInfo = new MutableSystemInfo();

View File

@@ -2,7 +2,7 @@ package net.rubygrapefruit.platform.internal;
import net.rubygrapefruit.platform.NativeException;
import net.rubygrapefruit.platform.Terminal;
import net.rubygrapefruit.platform.TerminalAccess;
import net.rubygrapefruit.platform.Terminals;
import net.rubygrapefruit.platform.TerminalSize;
import net.rubygrapefruit.platform.internal.jni.PosixTerminalFunctions;
import net.rubygrapefruit.platform.internal.jni.TerminfoFunctions;
@@ -10,14 +10,14 @@ import net.rubygrapefruit.platform.internal.jni.TerminfoFunctions;
import java.io.PrintStream;
public class TerminfoTerminal extends AbstractTerminal {
private final TerminalAccess.Output output;
private final Terminals.Output output;
private final PrintStream stream;
private final TerminalCapabilities capabilities = new TerminalCapabilities();
private Color foreground;
public TerminfoTerminal(TerminalAccess.Output output) {
public TerminfoTerminal(Terminals.Output output) {
this.output = output;
stream = output == TerminalAccess.Output.Stdout ? System.out : System.err;
stream = output == Terminals.Output.Stdout ? System.out : System.err;
}
@Override

View File

@@ -1,10 +1,10 @@
package net.rubygrapefruit.platform.internal;
import net.rubygrapefruit.platform.Terminal;
import net.rubygrapefruit.platform.TerminalAccess;
import net.rubygrapefruit.platform.Terminals;
import net.rubygrapefruit.platform.internal.jni.PosixTerminalFunctions;
public class TerminfoTerminalAccess implements TerminalAccess {
public class TerminfoTerminals implements Terminals {
private static Output currentlyOpen;
private static TerminfoTerminal current;

View File

@@ -2,14 +2,14 @@ package net.rubygrapefruit.platform.internal;
import net.rubygrapefruit.platform.NativeException;
import net.rubygrapefruit.platform.Terminal;
import net.rubygrapefruit.platform.TerminalAccess;
import net.rubygrapefruit.platform.Terminals;
import net.rubygrapefruit.platform.TerminalSize;
import net.rubygrapefruit.platform.internal.jni.WindowsConsoleFunctions;
public class WindowsTerminal extends AbstractTerminal {
private final TerminalAccess.Output output;
private final Terminals.Output output;
public WindowsTerminal(TerminalAccess.Output output) {
public WindowsTerminal(Terminals.Output output) {
this.output = output;
}

View File

@@ -2,10 +2,10 @@ package net.rubygrapefruit.platform.internal;
import net.rubygrapefruit.platform.NativeException;
import net.rubygrapefruit.platform.Terminal;
import net.rubygrapefruit.platform.TerminalAccess;
import net.rubygrapefruit.platform.Terminals;
import net.rubygrapefruit.platform.internal.jni.WindowsConsoleFunctions;
public class WindowsTerminalAccess implements TerminalAccess {
public class WindowsTerminals implements Terminals {
private static Output currentlyOpen;
private static WindowsTerminal current;

View File

@@ -8,18 +8,18 @@ import spock.lang.IgnoreIf
class TerminalTest extends Specification {
@Rule TemporaryFolder tmpDir
final TerminalAccess terminal = Native.get(TerminalAccess.class)
final Terminals terminal = Native.get(Terminals.class)
def "can check if attached to terminal"() {
expect:
!terminal.isTerminal(TerminalAccess.Output.Stdout);
!terminal.isTerminal(TerminalAccess.Output.Stderr);
!terminal.isTerminal(Terminals.Output.Stdout);
!terminal.isTerminal(Terminals.Output.Stderr);
}
@IgnoreIf({Platform.current().windows})
def "cannot access posix terminal from a test"() {
when:
terminal.getTerminal(TerminalAccess.Output.Stdout)
terminal.getTerminal(Terminals.Output.Stdout)
then:
NativeException e = thrown()
@@ -29,7 +29,7 @@ class TerminalTest extends Specification {
@IgnoreIf({!Platform.current().windows})
def "cannot access windows console from a test"() {
when:
terminal.getTerminal(TerminalAccess.Output.Stdout)
terminal.getTerminal(Terminals.Output.Stdout)
then:
NativeException e = thrown()