Removed unused code, move to new package and fix loading of libraries from build directory

This commit is contained in:
2014-11-23 20:32:02 +00:00
parent 441cbedf0c
commit 15d864c4c4
24 changed files with 203 additions and 894 deletions

3
.gitignore vendored
View File

@@ -3,4 +3,5 @@
.settings .settings
.gradle .gradle
.maven .maven
build build
/bin/

View File

@@ -1,8 +1,8 @@
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'maven' apply plugin: 'maven'
group = 'net.rubygrapefruit' group = 'com.github.boukefalos'
archivesBaseName = 'platform' archivesBaseName = 'jlibloader'
version = '0.1' version = '0.1'
uploadArchives { uploadArchives {

View File

@@ -14,18 +14,14 @@
* limitations under the License. * limitations under the License.
*/ */
package net.rubygrapefruit.platform; package com.github.boukefalos.jlibloader;
import java.io.File; import java.io.File;
import net.rubygrapefruit.platform.internal.NativeLibraryLoader; import com.github.boukefalos.jlibloader.internal.NativeLibraryLoader;
import net.rubygrapefruit.platform.internal.NativeLibraryLocator; import com.github.boukefalos.jlibloader.internal.NativeLibraryLocator;
import net.rubygrapefruit.platform.internal.Platform; import com.github.boukefalos.jlibloader.internal.Platform;
/**
* Provides access to the native integrations. Use {@link #get(Class)} to load a particular integration.
*/
@ThreadSafe
public class Native { public class Native {
private static NativeLibraryLoader loader; private static NativeLibraryLoader loader;
@@ -41,7 +37,6 @@ public class Native {
* @throws NativeLibraryUnavailableException When the native library is not available on the current machine. * @throws NativeLibraryUnavailableException When the native library is not available on the current machine.
* @throws NativeException On failure to load the native library. * @throws NativeException On failure to load the native library.
*/ */
@ThreadSafe
static public void init(File extractDir) throws NativeLibraryUnavailableException, NativeException { static public void init(File extractDir) throws NativeLibraryUnavailableException, NativeException {
synchronized (Native.class) { synchronized (Native.class) {
if (loader == null) { if (loader == null) {

View File

@@ -14,10 +14,12 @@
* limitations under the License. * limitations under the License.
*/ */
package net.rubygrapefruit.platform; package com.github.boukefalos.jlibloader;
public class NativeException extends RuntimeException { public class NativeException extends RuntimeException {
public NativeException(String message, Throwable throwable) { private static final long serialVersionUID = 1L;
public NativeException(String message, Throwable throwable) {
super(message, throwable); super(message, throwable);
} }

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package net.rubygrapefruit.platform; package com.github.boukefalos.jlibloader;
/** /**
* Thrown when a given integration is not available for the current machine. * Thrown when a given integration is not available for the current machine.

View File

@@ -1,4 +1,4 @@
package net.rubygrapefruit.platform.internal; package com.github.boukefalos.jlibloader.internal;
public class LibraryDef { public class LibraryDef {
final String group; final String group;

View File

@@ -14,15 +14,15 @@
* limitations under the License. * limitations under the License.
*/ */
package net.rubygrapefruit.platform.internal; package com.github.boukefalos.jlibloader.internal;
import net.rubygrapefruit.platform.NativeException;
import net.rubygrapefruit.platform.NativeLibraryUnavailableException;
import java.io.File; import java.io.File;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import com.github.boukefalos.jlibloader.NativeException;
import com.github.boukefalos.jlibloader.NativeLibraryUnavailableException;
public class NativeLibraryLoader { public class NativeLibraryLoader {
private final Set<String> loaded = new HashSet<String>(); private final Set<String> loaded = new HashSet<String>();
private final Platform platform; private final Platform platform;

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package net.rubygrapefruit.platform.internal; package com.github.boukefalos.jlibloader.internal;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@@ -24,7 +24,7 @@ import java.io.OutputStream;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.net.URL; import java.net.URL;
import net.rubygrapefruit.platform.NativeException; import com.github.boukefalos.jlibloader.NativeException;
public class NativeLibraryLocator { public class NativeLibraryLocator {
private final File extractDir; private final File extractDir;
@@ -83,7 +83,10 @@ public class NativeLibraryLocator {
if (libFile.isFile()) { if (libFile.isFile()) {
return libFile; return libFile;
} }
libFile = new File(String.format("build/binaries/mainSharedLibrary/%s/%s", libraryDef.platform.replace("-", "_"), libraryDef.name));
if (libFile.isFile()) {
return libFile;
}
return null; return null;
} }

View File

@@ -1,180 +1,180 @@
/* /*
* Copyright 2012 Adam Murdoch * Copyright 2012 Adam Murdoch
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package net.rubygrapefruit.platform.internal; package com.github.boukefalos.jlibloader.internal;
import net.rubygrapefruit.platform.NativeLibraryUnavailableException; import com.github.boukefalos.jlibloader.NativeLibraryUnavailableException;
public abstract class Platform { public abstract class Platform {
private static Platform platform; private static Platform platform;
public static Platform current() { public static Platform current() {
synchronized (Platform.class) { synchronized (Platform.class) {
if (platform == null) { if (platform == null) {
String osName = getOperatingSystem().toLowerCase(); String osName = getOperatingSystem().toLowerCase();
String arch = getArchitecture(); String arch = getArchitecture();
if (osName.contains("windows")) { if (osName.contains("windows")) {
if (arch.equals("x86")) { if (arch.equals("x86")) {
platform = new Window32Bit(); platform = new Window32Bit();
} }
else if (arch.equals("amd64")) { else if (arch.equals("amd64")) {
platform = new Window64Bit(); platform = new Window64Bit();
} }
} else if (osName.contains("linux")) { } else if (osName.contains("linux")) {
if (arch.equals("amd64") || arch.equals("x86_64")) { if (arch.equals("amd64") || arch.equals("x86_64")) {
platform = new Linux64Bit(); platform = new Linux64Bit();
} }
else if (arch.equals("i386") || arch.equals("x86")) { else if (arch.equals("i386") || arch.equals("x86")) {
platform = new Linux32Bit(); platform = new Linux32Bit();
} }
} else if (osName.contains("os x") || osName.contains("darwin")) { } else if (osName.contains("os x") || osName.contains("darwin")) {
if (arch.equals("i386")) { if (arch.equals("i386")) {
platform = new OsX32Bit(); platform = new OsX32Bit();
} }
else if (arch.equals("x86_64") || arch.equals("amd64") || arch.equals("universal")) { else if (arch.equals("x86_64") || arch.equals("amd64") || arch.equals("universal")) {
platform = new OsX64Bit(); platform = new OsX64Bit();
} }
} }
else if (osName.contains("freebsd")) { else if (osName.contains("freebsd")) {
if (arch.equals("amd64")) { if (arch.equals("amd64")) {
platform = new FreeBSD64Bit(); platform = new FreeBSD64Bit();
} }
else if (arch.equals("i386") || arch.equals("x86")) { else if (arch.equals("i386") || arch.equals("x86")) {
platform = new FreeBSD32Bit(); platform = new FreeBSD32Bit();
} }
} }
if (platform == null) { if (platform == null) {
platform = new Unsupported(); platform = new Unsupported();
} }
} }
return platform; return platform;
} }
} }
public boolean isWindows() { public boolean isWindows() {
return false; return false;
} }
@Override @Override
public String toString() { public String toString() {
return String.format("%s %s", getOperatingSystem(), getArchitecture()); return String.format("%s %s", getOperatingSystem(), getArchitecture());
} }
public String getLibraryName(String name) { public String getLibraryName(String name) {
throw new NativeLibraryUnavailableException(String.format("Native library is not available for %s.", toString())); throw new NativeLibraryUnavailableException(String.format("Native library is not available for %s.", toString()));
} }
public abstract String getId(); public abstract String getId();
private static String getOperatingSystem() { private static String getOperatingSystem() {
return System.getProperty("os.name"); return System.getProperty("os.name");
} }
private static String getArchitecture() { private static String getArchitecture() {
return System.getProperty("os.arch"); return System.getProperty("os.arch");
} }
private abstract static class Windows extends Platform { private abstract static class Windows extends Platform {
@Override @Override
public boolean isWindows() { public boolean isWindows() {
return true; return true;
} }
@Override @Override
public String getLibraryName(String name) { public String getLibraryName(String name) {
return String.format("%s.dll", name); return String.format("%s.dll", name);
} }
} }
private static class Window32Bit extends Windows { private static class Window32Bit extends Windows {
@Override @Override
public String getId() { public String getId() {
return "windows-i386"; return "windows-i386";
} }
} }
private static class Window64Bit extends Windows { private static class Window64Bit extends Windows {
@Override @Override
public String getId() { public String getId() {
return "windows-amd64"; return "windows-amd64";
} }
} }
private static abstract class Posix extends Platform {} private static abstract class Posix extends Platform {}
private abstract static class Unix extends Posix { private abstract static class Unix extends Posix {
@Override @Override
public String getLibraryName(String name) { public String getLibraryName(String name) {
return String.format("lib%s.so", name); return String.format("lib%s.so", name);
} }
} }
private static class Linux32Bit extends Unix { private static class Linux32Bit extends Unix {
@Override @Override
public String getId() { public String getId() {
return "linux-i386"; return "linux-i386";
} }
} }
private static class Linux64Bit extends Unix { private static class Linux64Bit extends Unix {
@Override @Override
public String getId() { public String getId() {
return "linux-amd64"; return "linux-amd64";
} }
} }
private static class FreeBSD32Bit extends Unix { private static class FreeBSD32Bit extends Unix {
@Override @Override
public String getId() { public String getId() {
return "freebsd-i386"; return "freebsd-i386";
} }
} }
private static class FreeBSD64Bit extends Unix { private static class FreeBSD64Bit extends Unix {
@Override @Override
public String getId() { public String getId() {
return "freebsd-amd64"; return "freebsd-amd64";
} }
} }
private static abstract class OsX extends Posix { private static abstract class OsX extends Posix {
@Override @Override
public String getLibraryName(String name) { public String getLibraryName(String name) {
return String.format("lib%s.dylib", name); return String.format("lib%s.dylib", name);
} }
} }
private static class OsX32Bit extends OsX { private static class OsX32Bit extends OsX {
@Override @Override
public String getId() { public String getId() {
return "osx-i386"; return "osx-i386";
} }
} }
private static class OsX64Bit extends OsX { private static class OsX64Bit extends OsX {
@Override @Override
public String getId() { public String getId() {
return "osx-amd64"; return "osx-amd64";
} }
} }
private static class Unsupported extends Platform { private static class Unsupported extends Platform {
@Override @Override
public String getId() { public String getId() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
} }
} }

View File

@@ -1,61 +0,0 @@
/*
* Copyright 2012 Adam Murdoch
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.rubygrapefruit.platform;
import java.io.File;
/**
* Information about a file system. This is a snapshot view and does not change.
*/
@ThreadSafe
public interface FileSystem {
/**
* Returns the root directory of this file system.
*/
@ThreadSafe
File getMountPoint();
/**
* Returns the operating system specific name for the type of this file system.
*/
@ThreadSafe
String getFileSystemType();
/**
* Returns true if this file system is a remote file system, or false if local.
*/
@ThreadSafe
boolean isRemote();
/**
* Returns true if this file system is performance case sensitive searches.
*/
@ThreadSafe
boolean isCaseSensitive();
/**
* Returns true if this file system preserves file name case.
*/
@ThreadSafe
boolean isCasePreserving();
/**
* Returns the operating system specific name for this file system.
*/
@ThreadSafe
String getDeviceName();
}

View File

@@ -1,34 +0,0 @@
/*
* Copyright 2012 Adam Murdoch
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.rubygrapefruit.platform;
import java.util.List;
/**
* Provides access to the file systems of the current machine.
*/
@ThreadSafe
public interface FileSystems extends NativeIntegration {
/**
* Returns the set of all file systems for the current machine.
*
* @return The set of file systems. Never returns null.
* @throws NativeException On failure.
*/
@ThreadSafe
List<FileSystem> getFileSystems() throws NativeException;
}

View File

@@ -1,10 +0,0 @@
package net.rubygrapefruit.platform;
/**
* Thrown when attempting to query an unknown registry key or value.
*/
public class MissingRegistryEntryException extends NativeException {
public MissingRegistryEntryException(String message) {
super(message);
}
}

View File

@@ -1,23 +0,0 @@
/*
* Copyright 2012 Adam Murdoch
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.rubygrapefruit.platform;
/**
* A marker interface that represents a native integration.
*/
public interface NativeIntegration {
}

View File

@@ -1,35 +0,0 @@
/*
* Copyright 2012 Adam Murdoch
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.rubygrapefruit.platform;
/**
* Provides some information about a file. This is a snapshot and does not change.
*/
@ThreadSafe
public interface PosixFile {
enum Type {File, Directory, Symlink, Other, Missing}
/**
* Returns the type of this file.
*/
Type getType();
/**
* Returns the mode of this file.
*/
int getMode();
}

View File

@@ -1,65 +0,0 @@
/*
* Copyright 2012 Adam Murdoch
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.rubygrapefruit.platform;
import java.io.File;
/**
* Functions to query and modify a file's POSIX meta-data.
*/
@ThreadSafe
public interface PosixFiles extends NativeIntegration {
/**
* Sets the mode for the given file.
*
* @throws NativeException On failure.
*/
@ThreadSafe
void setMode(File path, int perms) throws NativeException;
/**
* Gets the mode for the given file.
*
* @throws NativeException On failure.
*/
@ThreadSafe
int getMode(File path) throws NativeException;
/**
* Creates a symbolic link with given contents.
*
* @throws NativeException On failure.
*/
@ThreadSafe
void symlink(File link, String contents) throws NativeException;
/**
* Reads the contents of a symbolic link.
*
* @throws NativeException On failure.
*/
@ThreadSafe
String readLink(File link) throws NativeException;
/**
* Returns basic information about the given file.
*
* @throws NativeException On failure.
*/
@ThreadSafe
PosixFile stat(File path) throws NativeException;
}

View File

@@ -1,70 +0,0 @@
/*
* Copyright 2012 Adam Murdoch
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.rubygrapefruit.platform;
import java.io.File;
/**
* Functions to query and modify a process' state.
*/
@ThreadSafe
public interface Process extends NativeIntegration {
/**
* Returns the process identifier.
*
* @throws NativeException On failure.
*/
@ThreadSafe
int getProcessId() throws NativeException;
/**
* Returns the process' current working directory.
*
* @throws NativeException On failure.
*/
@ThreadSafe
File getWorkingDirectory() throws NativeException;
/**
* Sets the process' working directory.
*
* @throws NativeException On failure.
*/
@ThreadSafe
void setWorkingDirectory(File directory) throws NativeException;
/**
* Get the value of an environment variable.
*
* @return The value or null if no such environment variable. Also returns null for an environment variable whose
* value is an empty string.
* @throws NativeException On failure.
*/
@ThreadSafe
String getEnvironmentVariable(String name) throws NativeException;
/**
* Sets the value of an environment variable.
*
* @param value the new value. Use null or an empty string to remove the environment variable. Note that on some
* platforms it is not possible to remove the environment variable safely. On such platforms, the value is set to an
* empty string instead.
* @throws NativeException On failure.
*/
@ThreadSafe
void setEnvironmentVariable(String name, String value) throws NativeException;
}

View File

@@ -1,36 +0,0 @@
/*
* Copyright 2012 Adam Murdoch
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.rubygrapefruit.platform;
import java.lang.Process;
/**
* Used to start processes, taking care of some platform-specific issues when launching processes concurrently or
* launching processes that will run in the background.
*/
@ThreadSafe
public interface ProcessLauncher extends NativeIntegration {
/**
* Starts a process from the given settings.
*
* @param processBuilder The process settings.
* @return the process
* @throws NativeException On failure to start the process.
*/
@ThreadSafe
Process start(ProcessBuilder processBuilder) throws NativeException;
}

View File

@@ -1,49 +0,0 @@
/*
* Copyright 2012 Adam Murdoch
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.rubygrapefruit.platform;
/**
* Provides access to some system information. This is a snapshot view and does not change.
*/
@ThreadSafe
public interface SystemInfo extends NativeIntegration {
enum Architecture { i386, amd64 }
/**
* Returns the name of the kernel for the current operating system.
*/
@ThreadSafe
String getKernelName();
/**
* Returns the version of the kernel for the current operating system.
*/
@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
Architecture getArchitecture();
}

View File

@@ -1,143 +0,0 @@
/*
* Copyright 2012 Adam Murdoch
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.rubygrapefruit.platform;
/**
* Allows the terminal/console to be manipulated.
*
* <p>On UNIX based platforms, this provides access to the terminal. On Windows platforms, this provides access to the
* console.
* </p>
*/
@ThreadSafe
public interface Terminal {
/**
* Basic colors supported by a terminal.
*/
enum Color {
// Don't change the order of these. They are in ANSI order
Black, Red, Green, Yellow, Blue, Magenta, Cyan, White
}
/**
* Returns true if this terminal supports setting text attributes, such as bold.
*/
@ThreadSafe
boolean supportsTextAttributes();
/**
* Returns true if this terminal supports setting output colors.
*/
@ThreadSafe
boolean supportsColor();
/**
* Returns true if this terminal supports moving the cursor.
*/
@ThreadSafe
boolean supportsCursorMotion();
/**
* Returns the size of the terminal. Supported by all terminals.
*
* @return The current terminal size. Never returns null.
* @throws NativeException On failure.
*/
@ThreadSafe
TerminalSize getTerminalSize() throws NativeException;
/**
* Sets the terminal foreground color, if supported. Does nothing if this terminal does not support setting the
* foreground color.
*
* @throws NativeException On failure.
*/
@ThreadSafe
Terminal foreground(Color color) throws NativeException;
/**
* Switches the terminal to bold mode, if supported. Does nothing if this terminal does not support bold mode.
*
* @throws NativeException On failure.
*/
@ThreadSafe
Terminal bold() throws NativeException;
/**
* Switches the terminal to normal mode. Supported by all terminals.
*
* @throws NativeException On failure.
*/
@ThreadSafe
Terminal normal() throws NativeException;
/**
* Switches the terminal to normal mode and restores default colors. Supported by all terminals.
*
* @throws NativeException On failure.
*/
@ThreadSafe
Terminal reset() throws NativeException;
/**
* Moves the cursor the given number of characters to the left.
*
* @throws NativeException On failure, or if this terminal does not support cursor motion.
*/
@ThreadSafe
Terminal cursorLeft(int count) throws NativeException;
/**
* Moves the cursor the given number of characters to the right.
*
* @throws NativeException On failure, or if this terminal does not support cursor motion.
*/
@ThreadSafe
Terminal cursorRight(int count) throws NativeException;
/**
* Moves the cursor the given number of characters up.
*
* @throws NativeException On failure, or if this terminal does not support cursor motion.
*/
@ThreadSafe
Terminal cursorUp(int count) throws NativeException;
/**
* Moves the cursor the given number of characters down.
*
* @throws NativeException On failure, or if this terminal does not support cursor motion.
*/
@ThreadSafe
Terminal cursorDown(int count) throws NativeException;
/**
* Moves the cursor to the start of the current line.
*
* @throws NativeException On failure, or if this terminal does not support cursor motion.
*/
@ThreadSafe
Terminal cursorStartOfLine() throws NativeException;
/**
* Clears characters from the cursor position to the end of the current line.
*
* @throws NativeException On failure, or if this terminal does not support clearing.
*/
@ThreadSafe
Terminal clearToEndOfLine() throws NativeException;
}

View File

@@ -1,35 +0,0 @@
/*
* Copyright 2012 Adam Murdoch
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.rubygrapefruit.platform;
/**
* The size of a terminal. This is a snapshot view and does not change.
*/
@ThreadSafe
public interface TerminalSize {
/**
* Returns the number of character columns in the terminal.
*/
@ThreadSafe
public int getCols();
/**
* Returns the number of character rows in the terminal.
*/
@ThreadSafe
public int getRows();
}

View File

@@ -1,49 +0,0 @@
/*
* Copyright 2012 Adam Murdoch
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.rubygrapefruit.platform;
/**
* Provides access to the terminal/console.
*
* <p>On UNIX based platforms, this provides access to the terminal. On Windows platforms, this provides access to the
* console.
* </p>
*/
@ThreadSafe
public interface Terminals extends NativeIntegration {
/**
* System outputs.
*/
enum Output {Stdout, Stderr}
/**
* Returns true if the given output is attached to a terminal.
*
* @throws NativeException On failure.
*/
@ThreadSafe
boolean isTerminal(Output output) throws NativeException;
/**
* Returns the terminal attached to the given output.
*
* @return The terminal. Never returns null.
* @throws NativeException When the output is not attached to a terminal.
*/
@ThreadSafe
Terminal getTerminal(Output output) throws NativeException;
}

View File

@@ -1,27 +0,0 @@
/*
* Copyright 2012 Adam Murdoch
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.rubygrapefruit.platform;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
/**
* Indicates that the given class or method is thread safe.
*/
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface ThreadSafe {
}

View File

@@ -1,35 +0,0 @@
package net.rubygrapefruit.platform;
import java.util.List;
@ThreadSafe
public interface WindowsRegistry extends NativeIntegration {
public enum Key {
HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER
}
/**
* Returns a registry key value as a String.
*
* @throws NativeException On failure.
* @throws MissingRegistryEntryException When the requested key or value does not exist.
*/
String getStringValue(Key key, String subkey, String value) throws NativeException;
/**
* Lists the subkeys of a registry key.
*
* @throws NativeException On failure.
* @throws MissingRegistryEntryException When the requested key does not exist.
*/
List<String> getSubkeys(Key key, String subkey) throws NativeException;
/**
* Lists the value names of a registry key.
*
* @throws NativeException On failure.
* @throws MissingRegistryEntryException When the requested key does not exist.
*/
List<String> getValueNames(Key key, String subkey) throws NativeException;
}

View File

@@ -1,20 +0,0 @@
/*
* Copyright 2012 Adam Murdoch
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* The native integrations. Use {@link net.rubygrapefruit.platform.Native#get(Class)} to access a native integration.
*/
package net.rubygrapefruit.platform;