From 29056df74b476196a98db9b0492a3d19fe48ce5b Mon Sep 17 00:00:00 2001
From: Michal Srb <msrb@redhat.com>
Date: Fri, 18 Oct 2013 10:05:23 +0200
Subject: [PATCH] Drop jna-posix compatibility
---
core/src/main/java/hudson/os/PosixAPI.java | 78 ++----------------------
core/src/main/java/hudson/os/PosixException.java | 8 +--
2 files changed, 10 insertions(+), 76 deletions(-)
diff --git a/core/src/main/java/hudson/os/PosixAPI.java b/core/src/main/java/hudson/os/PosixAPI.java
index 2e69069..e3aa344 100644
--- a/core/src/main/java/hudson/os/PosixAPI.java
+++ b/core/src/main/java/hudson/os/PosixAPI.java
@@ -1,9 +1,5 @@
package hudson.os;
-import java.io.File;
-import java.io.InputStream;
-import java.io.PrintStream;
-import java.util.Map;
import java.util.logging.Logger;
import jnr.constants.platform.Errno;
import jnr.posix.POSIX;
@@ -29,17 +25,13 @@ public class PosixAPI {
if (posix == null) {
posix = POSIXFactory.getPOSIX(new DefaultPOSIXHandler() {
@Override public void error(Errno error, String extraData) {
- throw new PosixException("native error " + error.description() + " " + extraData, convert(error));
+ throw new PosixException("native error "
+ + error.description() + " " + extraData, error);
}
@Override public void error(Errno error, String methodName, String extraData) {
- throw new PosixException("native error calling " + methodName + ": " + error.description() + " " + extraData, convert(error));
- }
- private org.jruby.ext.posix.POSIX.ERRORS convert(Errno error) {
- try {
- return org.jruby.ext.posix.POSIX.ERRORS.valueOf(error.name());
- } catch (IllegalArgumentException x) {
- return org.jruby.ext.posix.POSIX.ERRORS.EIO; // PosixException.message has real error anyway
- }
+ throw new PosixException("native error calling "
+ + methodName + ": " + error.description() + " "
+ + extraData, error);
}
}, true);
}
@@ -59,65 +51,7 @@ public class PosixAPI {
*/
@Deprecated
public static boolean supportsNative() {
- return !(jnaPosix instanceof org.jruby.ext.posix.JavaPOSIX);
- }
-
- private static org.jruby.ext.posix.POSIX jnaPosix;
- /** @deprecated Use {@link #jnr} instead. */
- @Deprecated
- public static synchronized org.jruby.ext.posix.POSIX get() {
- if (jnaPosix == null) {
- jnaPosix = org.jruby.ext.posix.POSIXFactory.getPOSIX(new org.jruby.ext.posix.POSIXHandler() {
- public void error(org.jruby.ext.posix.POSIX.ERRORS errors, String s) {
- throw new PosixException(s,errors);
- }
-
- public void unimplementedError(String s) {
- throw new UnsupportedOperationException(s);
- }
-
- public void warn(WARNING_ID warning_id, String s, Object... objects) {
- LOGGER.fine(s);
- }
-
- public boolean isVerbose() {
- return true;
- }
-
- public File getCurrentWorkingDirectory() {
- return new File(".").getAbsoluteFile();
- }
-
- public String[] getEnv() {
- Map<String,String> envs = System.getenv();
- String[] envp = new String[envs.size()];
-
- int i = 0;
- for (Map.Entry<String,String> e : envs.entrySet()) {
- envp[i++] = e.getKey()+'+'+e.getValue();
- }
- return envp;
- }
-
- public InputStream getInputStream() {
- return System.in;
- }
-
- public PrintStream getOutputStream() {
- return System.out;
- }
-
- public int getPID() {
- // TODO
- return 0;
- }
-
- public PrintStream getErrorStream() {
- return System.err;
- }
- }, true);
- }
- return jnaPosix;
+ return posix.isNative();
}
private static final Logger LOGGER = Logger.getLogger(PosixAPI.class.getName());
diff --git a/core/src/main/java/hudson/os/PosixException.java b/core/src/main/java/hudson/os/PosixException.java
index 03cdd50..116d420 100644
--- a/core/src/main/java/hudson/os/PosixException.java
+++ b/core/src/main/java/hudson/os/PosixException.java
@@ -1,6 +1,6 @@
package hudson.os;
-import org.jruby.ext.posix.POSIX.ERRORS;
+import jnr.constants.platform.Errno;
/**
* Indicates an error during POSIX API call.
@@ -8,16 +8,16 @@ import org.jruby.ext.posix.POSIX.ERRORS;
* @author Kohsuke Kawaguchi
*/
public class PosixException extends RuntimeException {
- private final ERRORS errors;
+ private final Errno errors;
- public PosixException(String message, ERRORS errors) {
+ public PosixException(String message, Errno errors) {
super(message);
this.errors = errors;
}
/** @deprecated Leaks reference to deprecated jna-posix API. */
@Deprecated
- public ERRORS getErrorCode() {
+ public Errno getErrorCode() {
return errors;
}
--
1.8.3.1