Revert "Remove JNR (#5979)" (#6299)

This reverts commit 899d9fb584.
This commit is contained in:
Basil Crow authored and GitHub committed 2022-02-21 23:00:19 -08:00
1 parent 899d9fb584
commit dbb6e2a76f
6 files changed
+70

No files matched your search

@@ -0,0 +1,37 @@
package hudson.os;
import jnr.constants.platform.Errno;
import jnr.posix.POSIX;
import jnr.posix.POSIXFactory;
import jnr.posix.util.DefaultPOSIXHandler;
/**
* POSIX API wrapper.
* @author Kohsuke Kawaguchi
*/
public class PosixAPI {
private static POSIX posix;
/**
* Load the JNR implementation of the POSIX APIs for the current platform.
* Runtime exceptions will be of type {@link PosixException}.
* {@link IllegalStateException} will be thrown for methods not implemented on this platform.
* @return some implementation (even on Windows or unsupported Unix)
* @since 1.518
*/
public static synchronized POSIX jnr() {
if (posix == null) {
posix = POSIXFactory.getPOSIX(new DefaultPOSIXHandler() {
@Override public void error(Errno error, String extraData) {
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);
}
}, true);
}
return posix;
}
}
@@ -2,6 +2,7 @@ package hudson.os;
/**
* Indicates an error during POSIX API call.
* @see PosixAPI
* @author Kohsuke Kawaguchi
*/
public class PosixException extends RuntimeException {
@@ -33,6 +33,8 @@ import com.sun.jna.Pointer;
import com.sun.jna.StringArray;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.NativeLongByReference;
import hudson.os.PosixAPI;
import jnr.posix.POSIX;
/**
* GNU C library.
@@ -40,6 +42,7 @@ import com.sun.jna.ptr.NativeLongByReference;
* <p>
* Not available on all platforms (such as Linux/PPC, IBM mainframe, etc.), so the caller should recover gracefully
* in case of {@link LinkageError}. See JENKINS-4820.
* <p>Consider deprecating all methods present also in {@link POSIX} (as obtained by {@link PosixAPI#jnr}).
* @author Kohsuke Kawaguchi
*/
public interface GNUCLibrary extends Library {