提交 7e8bf72e 编写于 作者: K Kohsuke Kawaguchi

[JENKINS-15466] remember the cause of the initialization failure given that JVM doesn't remember.

上级 35eadbcf
package hudson.util.jna;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
/**
* {@link InvocationHandler} that reports the same exception over and over again when methods are invoked
* on the interface.
*
* This is convenient to remember why the initialization of the real JNA proxy failed.
*
* @author Kohsuke Kawaguchi
* @since 1.487
*/
public class InitializationErrorInvocationHandler implements InvocationHandler {
private final Throwable cause;
private InitializationErrorInvocationHandler(Throwable cause) {
this.cause = cause;
}
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (method.getDeclaringClass()==Object.class)
return method.invoke(this,args);
throw new UnsupportedOperationException("Failed to link the library: ", cause);
}
public static <T> T create(Class<T> type, Throwable cause) {
return type.cast(Proxy.newProxyInstance(type.getClassLoader(), new Class[]{type}, new InitializationErrorInvocationHandler(cause)));
}
}
......@@ -24,7 +24,10 @@
package hudson.util.jna;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.WString;
......@@ -59,6 +62,18 @@ public class Kernel32Utils {
}
public static boolean isJunctionOrSymlink(File file) throws IOException {
return (file.exists() && (Kernel32.INSTANCE.FILE_ATTRIBUTE_REPARSE_POINT & getWin32FileAttributes(file)) != 0);
return (file.exists() && (Kernel32.FILE_ATTRIBUTE_REPARSE_POINT & getWin32FileAttributes(file)) != 0);
}
/*package*/ static Kernel32 load() {
try {
return (Kernel32) Native.loadLibrary("kernel32", Kernel32.class);
} catch (Throwable e) {
LOGGER.log(Level.SEVERE, "Failed to load Kernel32", e);
return InitializationErrorInvocationHandler.create(Kernel32.class,e);
}
}
private static final Logger LOGGER = Logger.getLogger(Kernel32Utils.class.getName());
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册