Removed unused code, move to new package and fix loading of libraries from build directory
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -3,4 +3,5 @@
|
||||
.settings
|
||||
.gradle
|
||||
.maven
|
||||
build
|
||||
build
|
||||
/bin/
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'maven'
|
||||
|
||||
group = 'net.rubygrapefruit'
|
||||
archivesBaseName = 'platform'
|
||||
group = 'com.github.boukefalos'
|
||||
archivesBaseName = 'jlibloader'
|
||||
version = '0.1'
|
||||
|
||||
uploadArchives {
|
||||
|
||||
@@ -14,18 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.rubygrapefruit.platform;
|
||||
package com.github.boukefalos.jlibloader;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.rubygrapefruit.platform.internal.NativeLibraryLoader;
|
||||
import net.rubygrapefruit.platform.internal.NativeLibraryLocator;
|
||||
import net.rubygrapefruit.platform.internal.Platform;
|
||||
import com.github.boukefalos.jlibloader.internal.NativeLibraryLoader;
|
||||
import com.github.boukefalos.jlibloader.internal.NativeLibraryLocator;
|
||||
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 {
|
||||
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 NativeException On failure to load the native library.
|
||||
*/
|
||||
@ThreadSafe
|
||||
static public void init(File extractDir) throws NativeLibraryUnavailableException, NativeException {
|
||||
synchronized (Native.class) {
|
||||
if (loader == null) {
|
||||
@@ -14,10 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.rubygrapefruit.platform;
|
||||
package com.github.boukefalos.jlibloader;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* 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.
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.rubygrapefruit.platform.internal;
|
||||
package com.github.boukefalos.jlibloader.internal;
|
||||
|
||||
public class LibraryDef {
|
||||
final String group;
|
||||
@@ -14,15 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.rubygrapefruit.platform.internal;
|
||||
|
||||
import net.rubygrapefruit.platform.NativeException;
|
||||
import net.rubygrapefruit.platform.NativeLibraryUnavailableException;
|
||||
package com.github.boukefalos.jlibloader.internal;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.github.boukefalos.jlibloader.NativeException;
|
||||
import com.github.boukefalos.jlibloader.NativeLibraryUnavailableException;
|
||||
|
||||
public class NativeLibraryLoader {
|
||||
private final Set<String> loaded = new HashSet<String>();
|
||||
private final Platform platform;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.rubygrapefruit.platform.internal;
|
||||
package com.github.boukefalos.jlibloader.internal;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -24,7 +24,7 @@ import java.io.OutputStream;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.net.URL;
|
||||
|
||||
import net.rubygrapefruit.platform.NativeException;
|
||||
import com.github.boukefalos.jlibloader.NativeException;
|
||||
|
||||
public class NativeLibraryLocator {
|
||||
private final File extractDir;
|
||||
@@ -83,7 +83,10 @@ public class NativeLibraryLocator {
|
||||
if (libFile.isFile()) {
|
||||
return libFile;
|
||||
}
|
||||
|
||||
libFile = new File(String.format("build/binaries/mainSharedLibrary/%s/%s", libraryDef.platform.replace("-", "_"), libraryDef.name));
|
||||
if (libFile.isFile()) {
|
||||
return libFile;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
358
src/main/java/net/rubygrapefruit/platform/internal/Platform.java → src/main/java/com/github/boukefalos/jlibloader/internal/Platform.java
Executable file → Normal file
358
src/main/java/net/rubygrapefruit/platform/internal/Platform.java → src/main/java/com/github/boukefalos/jlibloader/internal/Platform.java
Executable file → Normal file
@@ -1,180 +1,180 @@
|
||||
/*
|
||||
* 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.internal;
|
||||
|
||||
import net.rubygrapefruit.platform.NativeLibraryUnavailableException;
|
||||
|
||||
public abstract class Platform {
|
||||
private static Platform platform;
|
||||
|
||||
public static Platform current() {
|
||||
synchronized (Platform.class) {
|
||||
if (platform == null) {
|
||||
String osName = getOperatingSystem().toLowerCase();
|
||||
String arch = getArchitecture();
|
||||
if (osName.contains("windows")) {
|
||||
if (arch.equals("x86")) {
|
||||
platform = new Window32Bit();
|
||||
}
|
||||
else if (arch.equals("amd64")) {
|
||||
platform = new Window64Bit();
|
||||
}
|
||||
} else if (osName.contains("linux")) {
|
||||
if (arch.equals("amd64") || arch.equals("x86_64")) {
|
||||
platform = new Linux64Bit();
|
||||
}
|
||||
else if (arch.equals("i386") || arch.equals("x86")) {
|
||||
platform = new Linux32Bit();
|
||||
}
|
||||
} else if (osName.contains("os x") || osName.contains("darwin")) {
|
||||
if (arch.equals("i386")) {
|
||||
platform = new OsX32Bit();
|
||||
}
|
||||
else if (arch.equals("x86_64") || arch.equals("amd64") || arch.equals("universal")) {
|
||||
platform = new OsX64Bit();
|
||||
}
|
||||
}
|
||||
else if (osName.contains("freebsd")) {
|
||||
if (arch.equals("amd64")) {
|
||||
platform = new FreeBSD64Bit();
|
||||
}
|
||||
else if (arch.equals("i386") || arch.equals("x86")) {
|
||||
platform = new FreeBSD32Bit();
|
||||
}
|
||||
}
|
||||
if (platform == null) {
|
||||
platform = new Unsupported();
|
||||
}
|
||||
}
|
||||
return platform;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isWindows() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s %s", getOperatingSystem(), getArchitecture());
|
||||
}
|
||||
|
||||
public String getLibraryName(String name) {
|
||||
throw new NativeLibraryUnavailableException(String.format("Native library is not available for %s.", toString()));
|
||||
}
|
||||
|
||||
public abstract String getId();
|
||||
|
||||
private static String getOperatingSystem() {
|
||||
return System.getProperty("os.name");
|
||||
}
|
||||
|
||||
private static String getArchitecture() {
|
||||
return System.getProperty("os.arch");
|
||||
}
|
||||
|
||||
private abstract static class Windows extends Platform {
|
||||
@Override
|
||||
public boolean isWindows() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLibraryName(String name) {
|
||||
return String.format("%s.dll", name);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Window32Bit extends Windows {
|
||||
@Override
|
||||
public String getId() {
|
||||
return "windows-i386";
|
||||
}
|
||||
}
|
||||
|
||||
private static class Window64Bit extends Windows {
|
||||
@Override
|
||||
public String getId() {
|
||||
return "windows-amd64";
|
||||
}
|
||||
}
|
||||
|
||||
private static abstract class Posix extends Platform {}
|
||||
|
||||
private abstract static class Unix extends Posix {
|
||||
@Override
|
||||
public String getLibraryName(String name) {
|
||||
return String.format("lib%s.so", name);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Linux32Bit extends Unix {
|
||||
@Override
|
||||
public String getId() {
|
||||
return "linux-i386";
|
||||
}
|
||||
}
|
||||
|
||||
private static class Linux64Bit extends Unix {
|
||||
@Override
|
||||
public String getId() {
|
||||
return "linux-amd64";
|
||||
}
|
||||
}
|
||||
|
||||
private static class FreeBSD32Bit extends Unix {
|
||||
@Override
|
||||
public String getId() {
|
||||
return "freebsd-i386";
|
||||
}
|
||||
}
|
||||
|
||||
private static class FreeBSD64Bit extends Unix {
|
||||
@Override
|
||||
public String getId() {
|
||||
return "freebsd-amd64";
|
||||
}
|
||||
}
|
||||
|
||||
private static abstract class OsX extends Posix {
|
||||
@Override
|
||||
public String getLibraryName(String name) {
|
||||
return String.format("lib%s.dylib", name);
|
||||
}
|
||||
}
|
||||
|
||||
private static class OsX32Bit extends OsX {
|
||||
@Override
|
||||
public String getId() {
|
||||
return "osx-i386";
|
||||
}
|
||||
}
|
||||
|
||||
private static class OsX64Bit extends OsX {
|
||||
@Override
|
||||
public String getId() {
|
||||
return "osx-amd64";
|
||||
}
|
||||
}
|
||||
|
||||
private static class Unsupported extends Platform {
|
||||
@Override
|
||||
public String getId() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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 com.github.boukefalos.jlibloader.internal;
|
||||
|
||||
import com.github.boukefalos.jlibloader.NativeLibraryUnavailableException;
|
||||
|
||||
public abstract class Platform {
|
||||
private static Platform platform;
|
||||
|
||||
public static Platform current() {
|
||||
synchronized (Platform.class) {
|
||||
if (platform == null) {
|
||||
String osName = getOperatingSystem().toLowerCase();
|
||||
String arch = getArchitecture();
|
||||
if (osName.contains("windows")) {
|
||||
if (arch.equals("x86")) {
|
||||
platform = new Window32Bit();
|
||||
}
|
||||
else if (arch.equals("amd64")) {
|
||||
platform = new Window64Bit();
|
||||
}
|
||||
} else if (osName.contains("linux")) {
|
||||
if (arch.equals("amd64") || arch.equals("x86_64")) {
|
||||
platform = new Linux64Bit();
|
||||
}
|
||||
else if (arch.equals("i386") || arch.equals("x86")) {
|
||||
platform = new Linux32Bit();
|
||||
}
|
||||
} else if (osName.contains("os x") || osName.contains("darwin")) {
|
||||
if (arch.equals("i386")) {
|
||||
platform = new OsX32Bit();
|
||||
}
|
||||
else if (arch.equals("x86_64") || arch.equals("amd64") || arch.equals("universal")) {
|
||||
platform = new OsX64Bit();
|
||||
}
|
||||
}
|
||||
else if (osName.contains("freebsd")) {
|
||||
if (arch.equals("amd64")) {
|
||||
platform = new FreeBSD64Bit();
|
||||
}
|
||||
else if (arch.equals("i386") || arch.equals("x86")) {
|
||||
platform = new FreeBSD32Bit();
|
||||
}
|
||||
}
|
||||
if (platform == null) {
|
||||
platform = new Unsupported();
|
||||
}
|
||||
}
|
||||
return platform;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isWindows() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s %s", getOperatingSystem(), getArchitecture());
|
||||
}
|
||||
|
||||
public String getLibraryName(String name) {
|
||||
throw new NativeLibraryUnavailableException(String.format("Native library is not available for %s.", toString()));
|
||||
}
|
||||
|
||||
public abstract String getId();
|
||||
|
||||
private static String getOperatingSystem() {
|
||||
return System.getProperty("os.name");
|
||||
}
|
||||
|
||||
private static String getArchitecture() {
|
||||
return System.getProperty("os.arch");
|
||||
}
|
||||
|
||||
private abstract static class Windows extends Platform {
|
||||
@Override
|
||||
public boolean isWindows() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLibraryName(String name) {
|
||||
return String.format("%s.dll", name);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Window32Bit extends Windows {
|
||||
@Override
|
||||
public String getId() {
|
||||
return "windows-i386";
|
||||
}
|
||||
}
|
||||
|
||||
private static class Window64Bit extends Windows {
|
||||
@Override
|
||||
public String getId() {
|
||||
return "windows-amd64";
|
||||
}
|
||||
}
|
||||
|
||||
private static abstract class Posix extends Platform {}
|
||||
|
||||
private abstract static class Unix extends Posix {
|
||||
@Override
|
||||
public String getLibraryName(String name) {
|
||||
return String.format("lib%s.so", name);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Linux32Bit extends Unix {
|
||||
@Override
|
||||
public String getId() {
|
||||
return "linux-i386";
|
||||
}
|
||||
}
|
||||
|
||||
private static class Linux64Bit extends Unix {
|
||||
@Override
|
||||
public String getId() {
|
||||
return "linux-amd64";
|
||||
}
|
||||
}
|
||||
|
||||
private static class FreeBSD32Bit extends Unix {
|
||||
@Override
|
||||
public String getId() {
|
||||
return "freebsd-i386";
|
||||
}
|
||||
}
|
||||
|
||||
private static class FreeBSD64Bit extends Unix {
|
||||
@Override
|
||||
public String getId() {
|
||||
return "freebsd-amd64";
|
||||
}
|
||||
}
|
||||
|
||||
private static abstract class OsX extends Posix {
|
||||
@Override
|
||||
public String getLibraryName(String name) {
|
||||
return String.format("lib%s.dylib", name);
|
||||
}
|
||||
}
|
||||
|
||||
private static class OsX32Bit extends OsX {
|
||||
@Override
|
||||
public String getId() {
|
||||
return "osx-i386";
|
||||
}
|
||||
}
|
||||
|
||||
private static class OsX64Bit extends OsX {
|
||||
@Override
|
||||
public String getId() {
|
||||
return "osx-amd64";
|
||||
}
|
||||
}
|
||||
|
||||
private static class Unsupported extends Platform {
|
||||
@Override
|
||||
public String getId() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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 {
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user