提交 ff71ab75 编写于 作者: A Andrew Kiellor

Migrated some usages of GNUCLibrary to the jnr PosixAPI, fixed 'mvn...

Migrated some usages of GNUCLibrary to the jnr PosixAPI, fixed 'mvn -Plight-test install' on ubuntu with OpenJDK.
上级 8deb42bf
......@@ -27,6 +27,7 @@ package hudson;
import hudson.Launcher.LocalLauncher;
import hudson.Launcher.RemoteLauncher;
import hudson.os.PosixAPI;
import jenkins.model.Jenkins;
import hudson.model.TaskListener;
import hudson.model.AbstractProject;
......@@ -1432,32 +1433,12 @@ public final class FilePath implements Serializable {
}
/**
* Run chmod via libc if we can, otherwise fall back to Ant.
* Run chmod via jnr-posix
*/
private static void _chmod(File f, int mask) throws IOException {
if (Functions.isWindows()) return; // noop
try {
if(LIBC.chmod(f.getAbsolutePath(),mask)!=0) {
throw new IOException("Failed to chmod "+f+" : "+LIBC.strerror(Native.getLastError()));
}
} catch(NoClassDefFoundError e) { // cf. https://groups.google.com/group/hudson-dev/browse_thread/thread/6d16c3e8ea0dbc9?hl=fr
_chmodAnt(f, mask);
} catch(UnsatisfiedLinkError e2) { // HUDSON-8155: use Ant's chmod task on non-GNU C systems
_chmodAnt(f, mask);
}
}
private static void _chmodAnt(File f, int mask) {
if (!CHMOD_WARNED) { // only warn this once to avoid flooding the log
CHMOD_WARNED = true;
LOGGER.warning("GNU C Library not available: Using Ant's chmod task instead.");
}
Chmod chmodTask = new Chmod();
chmodTask.setProject(new Project());
chmodTask.setFile(f);
chmodTask.setPerm(Integer.toOctalString(mask));
chmodTask.execute();
PosixAPI.jnr().chmod(f.getAbsolutePath(),mask);
}
private static boolean CHMOD_WARNED = false;
......
......@@ -57,6 +57,7 @@ import hudson.model.*;
import hudson.model.Executor;
import hudson.model.Node.Mode;
import hudson.model.Queue.Executable;
import hudson.os.PosixAPI;
import hudson.remoting.Which;
import hudson.security.ACL;
import hudson.security.AbstractPasswordBasedSecurityRealm;
......@@ -82,7 +83,6 @@ import hudson.tools.ToolProperty;
import hudson.util.PersistedList;
import hudson.util.ReflectionUtils;
import hudson.util.StreamTaskListener;
import hudson.util.jna.GNUCLibrary;
import java.beans.PropertyDescriptor;
import java.io.BufferedReader;
......@@ -587,8 +587,9 @@ public abstract class HudsonTestCase extends TestCase implements RootAction {
mvn.copyFrom(HudsonTestCase.class.getClassLoader().getResource(mavenVersion + "-bin.zip"));
mvn.unzip(new FilePath(buildDirectory));
// TODO: switch to tar that preserves file permissions more easily
if(!Functions.isWindows())
GNUCLibrary.LIBC.chmod(new File(mvnHome, "bin/mvn").getPath(),0755);
if(!Functions.isWindows()) {
PosixAPI.jnr().chmod(new File(mvnHome, "bin/mvn").getPath(), 0755);
}
MavenInstallation mavenInstallation = new MavenInstallation("default",
mvnHome.getAbsolutePath(), NO_PROPERTIES);
......@@ -611,8 +612,9 @@ public abstract class HudsonTestCase extends TestCase implements RootAction {
File antHome = createTmpDir();
ant.unzip(new FilePath(antHome));
// TODO: switch to tar that preserves file permissions more easily
if(!Functions.isWindows())
GNUCLibrary.LIBC.chmod(new File(antHome,"apache-ant-1.8.1/bin/ant").getPath(),0755);
if(!Functions.isWindows()) {
PosixAPI.jnr().chmod(new File(antHome,"apache-ant-1.8.1/bin/ant").getPath(),0755);
}
antInstallation = new AntInstallation("default", new File(antHome,"apache-ant-1.8.1").getAbsolutePath(),NO_PROPERTIES);
}
......@@ -1976,8 +1978,8 @@ public abstract class HudsonTestCase extends TestCase implements RootAction {
if (!Functions.isWindows()) {
try {
GNUCLibrary.LIBC.unsetenv("MAVEN_OPTS");
GNUCLibrary.LIBC.unsetenv("MAVEN_DEBUG_OPTS");
PosixAPI.jnr().unsetenv("MAVEN_OPTS");
PosixAPI.jnr().unsetenv("MAVEN_DEBUG_OPTS");
} catch (Exception e) {
LOGGER.log(Level.WARNING,"Failed to cancel out MAVEN_OPTS",e);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册