From c6772d62c5f3a66e5bee7178e08a5e040b1ee997 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Wed, 25 Feb 2009 20:18:34 +0000 Subject: [PATCH] fixed a test case so that it works on Unix git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@15759 71c3de6d-444a-0410-be80-ed276b4c234a --- .../java/hudson/util/jna/GNUCLibrary.java | 5 +++- .../org/jvnet/hudson/test/HudsonTestCase.java | 10 +++++--- .../tools/ToolLocationNodePropertyTest.java | 24 ++++++++----------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/hudson/util/jna/GNUCLibrary.java b/core/src/main/java/hudson/util/jna/GNUCLibrary.java index 56e08a5631..cb8630be4d 100644 --- a/core/src/main/java/hudson/util/jna/GNUCLibrary.java +++ b/core/src/main/java/hudson/util/jna/GNUCLibrary.java @@ -30,6 +30,8 @@ import com.sun.jna.Native; import com.sun.jna.ptr.IntByReference; import org.jvnet.libpam.impl.CLibrary.passwd; +import java.io.File; + /** * GNU C library. * @@ -64,7 +66,8 @@ public interface GNUCLibrary extends Library { static final int FD_CLOEXEC = 1; int chown(String fileName, int uid, int gid); - + int chmod(String fileName, int i); + // this is listed in http://developer.apple.com/DOCUMENTATION/Darwin/Reference/ManPages/man3/sysctlbyname.3.html // but not in http://www.gnu.org/software/libc/manual/html_node/System-Parameters.html#index-sysctl-3493 diff --git a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java index 610c32a483..d390c24aca 100644 --- a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java +++ b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java @@ -48,14 +48,13 @@ import hudson.model.Node.Mode; import hudson.slaves.CommandLauncher; import hudson.slaves.DumbSlave; import hudson.slaves.RetentionStrategy; -import hudson.tasks.BuildStep; import hudson.tasks.Mailer; import hudson.tasks.Maven; import hudson.tasks.Ant; -import hudson.tasks.Publisher; import hudson.tasks.Maven.MavenInstallation; import hudson.util.ProcessTreeKiller; import hudson.util.StreamTaskListener; +import hudson.util.jna.GNUCLibrary; import java.io.BufferedReader; import java.io.File; @@ -73,7 +72,6 @@ import java.util.Enumeration; import java.util.Iterator; import java.util.List; import java.util.Locale; -import java.util.Map; import java.util.jar.Manifest; import java.util.logging.Filter; import java.util.logging.Level; @@ -316,6 +314,9 @@ public abstract class HudsonTestCase extends TestCase { } File mvnHome = createTmpDir(); mvn.unzip(new FilePath(mvnHome)); + // TODO: switch to tar that preserves file permissions more easily + if(!Hudson.isWindows()) + GNUCLibrary.LIBC.chmod(new File(mvnHome,"maven-2.0.7/bin/mvn").getPath(),0755); MavenInstallation mavenInstallation = new MavenInstallation("default", new File(mvnHome,"maven-2.0.7").getAbsolutePath()); @@ -336,6 +337,9 @@ public abstract class HudsonTestCase extends TestCase { } File antHome = createTmpDir(); ant.unzip(new FilePath(antHome)); + // TODO: switch to tar that preserves file permissions more easily + if(!Hudson.isWindows()) + GNUCLibrary.LIBC.chmod(new File(antHome,"apache-ant-1.7.1/bin/ant").getPath(),0755); Ant.AntInstallation antInstallation = new Ant.AntInstallation("default", new File(antHome,"apache-ant-1.7.1").getAbsolutePath()); diff --git a/test/src/test/java/hudson/tools/ToolLocationNodePropertyTest.java b/test/src/test/java/hudson/tools/ToolLocationNodePropertyTest.java index 0ba2881944..f671f0532d 100644 --- a/test/src/test/java/hudson/tools/ToolLocationNodePropertyTest.java +++ b/test/src/test/java/hudson/tools/ToolLocationNodePropertyTest.java @@ -25,32 +25,21 @@ package hudson.tools; import hudson.model.*; -import hudson.slaves.EnvironmentVariablesNodeProperty.Entry; import hudson.slaves.DumbSlave; -import hudson.slaves.EnvironmentVariablesNodeProperty; -import hudson.slaves.NodeProperty; import hudson.tasks.Maven; import hudson.tasks.BatchFile; import hudson.tasks.Ant; +import hudson.tasks.Shell; import hudson.tasks.Ant.AntInstallation; import hudson.tasks.Maven.MavenInstallation; -import hudson.tasks.Maven.MavenInstallation.DescriptorImpl; -import hudson.maven.MavenBuilder; import hudson.EnvVars; import java.io.IOException; -import java.util.Collections; -import java.util.Map; -import java.util.Arrays; -import java.util.HashMap; import junit.framework.Assert; -import org.jvnet.hudson.test.CaptureEnvironmentBuilder; import org.jvnet.hudson.test.HudsonTestCase; import org.jvnet.hudson.test.SingleFileSCM; -import org.jvnet.hudson.test.HudsonTestCase.WebClient; -import org.codehaus.groovy.tools.shell.Command; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlPage; @@ -112,7 +101,7 @@ public class ToolLocationNodePropertyTest extends HudsonTestCase { Hudson.getInstance().getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(new MavenInstallation("maven", "THIS IS WRONG")); project.getBuildersList().add(new Maven("--version", "maven")); - project.getBuildersList().add(new BatchFile("set")); + configureDumpEnvBuilder(); Build build = project.scheduleBuild2(0).get(); assertBuildStatus(Result.FAILURE, build); @@ -125,6 +114,13 @@ public class ToolLocationNodePropertyTest extends HudsonTestCase { assertBuildStatus(Result.SUCCESS, build); } + private void configureDumpEnvBuilder() throws IOException { + if(Hudson.isWindows()) + project.getBuildersList().add(new BatchFile("set")); + else + project.getBuildersList().add(new Shell("export")); + } + public void testAnt() throws Exception { Ant.AntInstallation ant = configureDefaultAnt(); String antPath = ant.getHome(); @@ -132,7 +128,7 @@ public class ToolLocationNodePropertyTest extends HudsonTestCase { project.setScm(new SingleFileSCM("build.xml", "")); project.getBuildersList().add(new Ant("-version", "ant", null,null,null)); - project.getBuildersList().add(new BatchFile("set")); + configureDumpEnvBuilder(); Build build = project.scheduleBuild2(0).get(); assertBuildStatus(Result.FAILURE, build);