From 36528c1a7cfeea4aea494aaf7dc68820f5d02c19 Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Fri, 18 Jun 2021 21:02:39 -0700 Subject: [PATCH] Remove `jna-posix` (#5560) --- core/pom.xml | 5 - core/src/main/java/hudson/os/PosixAPI.java | 103 +----------------- .../main/java/hudson/os/PosixException.java | 17 +-- core/src/main/java/hudson/util/IOUtils.java | 4 +- licenseCompleter.groovy | 9 -- 5 files changed, 6 insertions(+), 132 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index cd9264102f..cec6dc0e73 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -103,11 +103,6 @@ THE SOFTWARE. org.connectbot.jbcrypt jbcrypt - - org.jruby.ext.posix - jna-posix - 1.0.3-jenkins-1 - com.github.jnr jnr-posix diff --git a/core/src/main/java/hudson/os/PosixAPI.java b/core/src/main/java/hudson/os/PosixAPI.java index 8d3a32d749..c9f40ac31b 100644 --- a/core/src/main/java/hudson/os/PosixAPI.java +++ b/core/src/main/java/hudson/os/PosixAPI.java @@ -1,10 +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; import jnr.posix.POSIXFactory; @@ -12,7 +7,6 @@ import jnr.posix.util.DefaultPOSIXHandler; /** * POSIX API wrapper. - * Formerly used the jna-posix library, but this has been superseded by jnr-posix. * @author Kohsuke Kawaguchi */ public class PosixAPI { @@ -30,106 +24,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); } @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); } }, true); } return posix; } - - /** - * @deprecated use {@link #jnr} and {@link POSIX#isNative} - */ - @Deprecated - public boolean isNative() { - return supportsNative(); - } - - /** - * @deprecated use {@link #jnr} and {@link POSIX#isNative} - */ - @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() { - @Override - public void error(org.jruby.ext.posix.POSIX.ERRORS errors, String s) { - throw new PosixException(s,errors); - } - - @Override - public void unimplementedError(String s) { - throw new UnsupportedOperationException(s); - } - - @Override - public void warn(WARNING_ID warning_id, String s, Object... objects) { - LOGGER.fine(s); - } - - @Override - public boolean isVerbose() { - return true; - } - - @Override - public File getCurrentWorkingDirectory() { - return new File(".").getAbsoluteFile(); - } - - @Override - public String[] getEnv() { - Map envs = System.getenv(); - String[] envp = new String[envs.size()]; - - int i = 0; - for (Map.Entry e : envs.entrySet()) { - envp[i++] = e.getKey()+'+'+e.getValue(); - } - return envp; - } - - @Override - public InputStream getInputStream() { - return System.in; - } - - @Override - public PrintStream getOutputStream() { - return System.out; - } - - @Override - public int getPID() { - // TODO - return 0; - } - - @Override - public PrintStream getErrorStream() { - return System.err; - } - }, true); - } - return jnaPosix; - } - - 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 03cdd50e38..c32b9a3e6b 100644 --- a/core/src/main/java/hudson/os/PosixException.java +++ b/core/src/main/java/hudson/os/PosixException.java @@ -1,28 +1,17 @@ package hudson.os; -import org.jruby.ext.posix.POSIX.ERRORS; - /** * Indicates an error during POSIX API call. * @see PosixAPI * @author Kohsuke Kawaguchi */ public class PosixException extends RuntimeException { - private final ERRORS errors; - public PosixException(String message, ERRORS errors) { + public PosixException(String message) { super(message); - this.errors = errors; } - /** @deprecated Leaks reference to deprecated jna-posix API. */ - @Deprecated - public ERRORS getErrorCode() { - return errors; - } - - @Override - public String toString() { - return super.toString()+" "+errors; + public PosixException(String message, Throwable cause) { + super(message, cause); } } diff --git a/core/src/main/java/hudson/util/IOUtils.java b/core/src/main/java/hudson/util/IOUtils.java index 140efc89d0..b51435b49c 100644 --- a/core/src/main/java/hudson/util/IOUtils.java +++ b/core/src/main/java/hudson/util/IOUtils.java @@ -141,9 +141,7 @@ public class IOUtils { return Util.permissionsToMode(Files.getPosixFilePermissions(fileToPath(f))); } } catch (IOException cause) { - PosixException e = new PosixException("Unable to get file permissions", null); - e.initCause(cause); - throw e; + throw new PosixException("Unable to get file permissions", cause); } } diff --git a/licenseCompleter.groovy b/licenseCompleter.groovy index 4dc5936c02..21c78e8f72 100644 --- a/licenseCompleter.groovy +++ b/licenseCompleter.groovy @@ -81,13 +81,4 @@ complete { match("net.jcip:jcip-annotations") { rewriteLicense([],ccby) } - - // - // Choose from multi-licensed modules - //========================================================================== - - match("*:jna-posix") { - accept("GNU Lesser General Public License Version 2.1") - } - }