Commits

Przemek Bruski  committed 1144944

BDEV-933 - fixed setting working directory for agent and server

  • Participants
  • Parent commits 6c0b4b4

Comments (0)

Files changed (17)

             <plugin>
                 <artifactId>maven-compiler-plugin</artifactId>
                 <configuration>
-                    <source>1.5</source>
-                    <target>1.5</target>
+                    <source>1.6</source>
+                    <target>1.6</target>
                 </configuration>
             </plugin>
         </plugins>

File src/main/java/com/sysbliss/bamboo/plugins/prepostcmd/BuildCommandRunnerException.java

 /**
- * 
+ *
  */
 package com.sysbliss.bamboo.plugins.prepostcmd;
 
 /**
  * @author jdoklovic
- * 
+ *
  */
-public class BuildCommandRunnerException extends Exception {
-    public BuildCommandRunnerException(final String message) {
-	super(message);
+public class BuildCommandRunnerException extends Exception
+{
+    public BuildCommandRunnerException(final String message)
+    {
+        super(message);
     }
 }

File src/main/java/com/sysbliss/bamboo/plugins/prepostcmd/BuildHelper.java

 
 public class BuildHelper {
 
+    private BuildHelper()
+    {
+    }
+
     public static String getBuildUrl(final String key, final int number) {
-	final StringBuffer url = new StringBuffer("/browse/");
-	url.append(EscapeChars.forURL(key));
-	url.append("-").append(number);
+        final StringBuilder url = new StringBuilder("/browse/");
+        url.append(EscapeChars.forURL(key));
+        url.append("-").append(number);
 
-	return url.toString();
-
+        return url.toString();
     }
 }

File src/main/java/com/sysbliss/bamboo/plugins/prepostcmd/RunLocation.java

     private String description;
 
     RunLocation(final String key, final String d) {
-	this.key = key;
-	this.description = d;
+        this.key = key;
+        this.description = d;
     }
 
     public String getKey() {
-	return key;
+        return key;
     }
 
     public void setKey(final String key) {
-	this.key = key;
+        this.key = key;
     }
 
     public String getDescription() {
-	return description;
+        return description;
     }
 
     public void setDescription(final String description) {
-	this.description = description;
+        this.description = description;
     }
 }

File src/main/java/com/sysbliss/bamboo/plugins/prepostcmd/action/PostBuildCommandAgentAction.java

 import com.atlassian.bamboo.process.ProcessService;
 import com.atlassian.bamboo.v2.build.BaseConfigurablePlugin;
 import com.atlassian.bamboo.v2.build.BuildContext;
+import com.atlassian.bamboo.v2.build.BuildContextHelper;
 import com.atlassian.bamboo.variable.CustomVariableContext;
 import com.atlassian.bamboo.ww2.actions.build.admin.create.BuildConfiguration;
 import com.opensymphony.xwork.ActionContext;
 import com.sysbliss.bamboo.plugins.prepostcmd.runner.PostBuildCommandRunner;
 import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
+import org.jetbrains.annotations.NotNull;
 
 import java.util.Map;
 
     private EnvironmentVariableAccessor environmentVariableAccessor;
     private ProcessService processService;
 
-    public void init(final BuildContext context) {
+    @Override
+    public void init(@NotNull final BuildContext context)
+    {
         this.buildContext = context;
     }
 
-    public BuildContext call() throws Exception {
+    @NotNull
+    @Override
+    public BuildContext call() throws Exception
+    {
         final Map<String, String> customConfiguration = buildContext.getBuildDefinition().getCustomConfiguration();
 
         if (customConfiguration == null || !"A".equals(customConfiguration.get(POST_RUNLOCATION_KEY))) {
         runner.setBuildLoggerManager(buildLoggerManager);
         runner.setCustomVariableContext(customVariableContext);
         runner.setBuildDirectoryManager(buildDirectoryManager);
+        runner.setWorkingDirectory(BuildContextHelper.getBuildWorkingDirectory(buildContext));
         runner.run();
 
         return buildContext;
     }
 
     @Override
-    protected void populateContextForEdit(final Map<String, Object> context, final BuildConfiguration buildConfiguration, final Plan plan) {
+    protected void populateContextForEdit(@NotNull final Map<String, Object> context, @NotNull final BuildConfiguration buildConfiguration, @NotNull final Plan plan) {
         if (StringUtils.isBlank(buildConfiguration.getString(POST_RUNLOCATION_KEY))) {
             ActionContext.getContext().put(POST_RUNLOCATION_KEY, RunLocation.AGENT.getKey());
         }
     }
 
     @Override
-    protected void populateContextForView(final Map<String, Object> context, final Plan plan) {
+    protected void populateContextForView(@NotNull final Map<String, Object> context, @NotNull final Plan plan) {
         final Map<String, String> config = plan.getBuildDefinition().getCustomConfiguration();
         if (config != null)
         {

File src/main/java/com/sysbliss/bamboo/plugins/prepostcmd/action/PostBuildCommandServerAction.java

 import com.atlassian.bamboo.ww2.actions.build.admin.create.BuildConfiguration;
 import com.sysbliss.bamboo.plugins.prepostcmd.runner.PostBuildCommandRunner;
 import org.apache.log4j.Logger;
+import org.jetbrains.annotations.NotNull;
 
 import java.util.Map;
 
     private EnvironmentVariableAccessor environmentVariableAccessor;
     private ProcessService processService;
 
-    public void init(final BuildContext context) {
+    @Override
+    public void init(@NotNull final BuildContext context) {
         this.buildContext = context;
     }
 
+    @NotNull
+    @Override
     public BuildContext call() throws Exception {
-        final Map customConfiguration = buildContext.getBuildDefinition().getCustomConfiguration();
+        final Map<String, String> customConfiguration = buildContext.getBuildDefinition().getCustomConfiguration();
 
         if (customConfiguration == null || !"S".equals(customConfiguration.get(POST_RUNLOCATION_KEY))) {
             log.info("post command not set to run on server, skipping");
     }
 
     @Override
-    public String getEditHtml(final BuildConfiguration buildConfiguration, final Plan plan) {
+    public String getEditHtml(@NotNull final BuildConfiguration buildConfiguration, @NotNull final Plan plan) {
         return " ";
     }
 
     @Override
-    public String getViewHtml(final Plan plan) {
+    public String getViewHtml(@NotNull final Plan plan) {
         return " ";
     }
 

File src/main/java/com/sysbliss/bamboo/plugins/prepostcmd/action/PreBuildCommandAgentAction.java

 import com.atlassian.bamboo.process.ProcessService;
 import com.atlassian.bamboo.v2.build.BaseConfigurableBuildPlugin;
 import com.atlassian.bamboo.v2.build.BuildContext;
+import com.atlassian.bamboo.v2.build.BuildContextHelper;
 import com.atlassian.bamboo.variable.CustomVariableContext;
 import com.atlassian.bamboo.ww2.actions.build.admin.create.BuildConfiguration;
 import com.opensymphony.xwork.ActionContext;
 import com.sysbliss.bamboo.plugins.prepostcmd.runner.PreBuildCommandRunner;
 import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
+import org.jetbrains.annotations.NotNull;
 
 import java.util.Map;
 
 
     private static final Logger log = Logger.getLogger(PreBuildCommandAgentAction.class);
     private static final String PRE_RUNLOCATION_KEY = "custom.sysbliss.pre.command.run.location";
-    private BuildContext buildContext;
     private CustomVariableContext customVariableContext;
     private BuildLoggerManager buildLoggerManager;
     private BuildDirectoryManager buildDirectoryManager;
     private ProcessService processService;
     private EnvironmentVariableAccessor environmentVariableAccessor;
 
+    @NotNull
     @Override
-    public void init(final BuildContext context) {
-        this.buildContext = context;
-    }
-
     public BuildContext call() throws Exception {
         // grab the custom configuration object
-        final Map customConfiguration = buildContext.getBuildDefinition().getCustomConfiguration();
+        final Map<String, String> customConfiguration = buildContext.getBuildDefinition().getCustomConfiguration();
 
         if (customConfiguration == null || !"A".equals(customConfiguration.get(PRE_RUNLOCATION_KEY))) {
             log.info("pre command not set to run on agent, skipping");
         runner.setBuildLoggerManager(buildLoggerManager);
         runner.setCustomVariableContext(customVariableContext);
         runner.setBuildDirectoryManager(buildDirectoryManager);
+        runner.setWorkingDirectory(BuildContextHelper.getBuildWorkingDirectory(buildContext));
         runner.run();
 
         return buildContext;
     }
 
     @Override
-    protected void populateContextForEdit(final Map<String, Object> context, final BuildConfiguration buildConfiguration, final Plan plan) {
+    protected void populateContextForEdit(@NotNull final Map<String, Object> context, @NotNull final BuildConfiguration buildConfiguration, @NotNull final Plan plan) {
         if (StringUtils.isBlank(buildConfiguration.getString(PRE_RUNLOCATION_KEY))) {
             ActionContext.getContext().put(PRE_RUNLOCATION_KEY, RunLocation.AGENT.getKey());
         }
     }
 
     @Override
-    protected void populateContextForView(final Map<String, Object> context, final Plan plan) {
+    protected void populateContextForView(@NotNull final Map<String, Object> context, @NotNull final Plan plan) {
         final Map<String, String> config = plan.getBuildDefinition().getCustomConfiguration();
         if (config != null)
         {

File src/main/java/com/sysbliss/bamboo/plugins/prepostcmd/action/PreBuildCommandServerAction.java

 import com.atlassian.bamboo.ww2.actions.build.admin.create.BuildConfiguration;
 import com.sysbliss.bamboo.plugins.prepostcmd.runner.PreBuildCommandRunner;
 import org.apache.log4j.Logger;
+import org.jetbrains.annotations.NotNull;
 
 import java.util.Map;
 
 
     private static final Logger log = Logger.getLogger(PreBuildCommandServerAction.class);
     private static final String PRE_RUNLOCATION_KEY = "custom.sysbliss.pre.command.run.location";
-    private BuildContext buildContext;
     private CustomVariableContext customVariableContext;
     private BuildLoggerManager buildLoggerManager;
     private BuildDirectoryManager buildDirectoryManager;
     private ProcessService processService;
     private EnvironmentVariableAccessor environmentVariableAccessor;
 
+    @NotNull
     @Override
-    public void init(final BuildContext context) {
-        this.buildContext = context;
-    }
-
     public BuildContext call() throws Exception {
         // grab the custom configuration object
-        final Map customConfiguration = buildContext.getBuildDefinition().getCustomConfiguration();
+        final Map<String, String> customConfiguration = buildContext.getBuildDefinition().getCustomConfiguration();
 
         if (customConfiguration == null || !"S".equals(customConfiguration.get(PRE_RUNLOCATION_KEY))) {
             log.info("pre command not set to run on server, skipping");
     }
 
     @Override
-    public String getEditHtml(final BuildConfiguration buildConfiguration, final Plan plan) {
+    public String getEditHtml(@NotNull final BuildConfiguration buildConfiguration, @NotNull final Plan plan) {
         return " ";
     }
 
     @Override
-    public String getViewHtml(final Plan plan) {
+    public String getViewHtml(@NotNull final Plan plan) {
         return " ";
     }
 

File src/main/java/com/sysbliss/bamboo/plugins/prepostcmd/runner/AbstractCommandRunner.java

 import com.atlassian.bamboo.builder.BuildState;
 import com.atlassian.bamboo.process.EnvironmentVariableAccessor;
 import com.atlassian.bamboo.process.ProcessService;
-import com.atlassian.bamboo.utils.SystemProperty;
 import com.atlassian.bamboo.v2.build.BuildContext;
 import com.atlassian.bamboo.v2.build.BuildContextHelper;
 import com.atlassian.bamboo.variable.CustomVariableContext;
 import com.sysbliss.bamboo.plugins.prepostcmd.BuildCommandRunnerException;
 import com.sysbliss.bamboo.plugins.prepostcmd.BuildHelper;
 import org.apache.commons.lang.StringUtils;
-import org.apache.log4j.Logger;
+import org.apache.commons.lang.SystemUtils;
+import org.jetbrains.annotations.Nullable;
 
 import java.io.File;
 import java.util.ArrayList;
  */
 public abstract class AbstractCommandRunner implements CommandRunner
 {
-
     protected CustomVariableContext customVariableContext;
     protected BuildLoggerManager buildLoggerManager;
     protected BuildDirectoryManager buildDirectoryManager;
     private final ProcessService processService;
     private Map<String, String> customConfiguration = null;
     private Map<String, String> rawBuildData = null;
+    private File workingDirectory;
 
 
     protected AbstractCommandRunner(final BuildContext bc, final EnvironmentVariableAccessor environmentVariableAccessor, final ProcessService processService)
         this.rawBuildData = buildContext.getBuildResult().getCustomBuildData();
     }
 
+    @Nullable
     protected String getEnvironmentVariable(Map<String, String> customConfiguration, String variableName)
     {
         String env = customConfiguration.get(variableName);
         if (StringUtils.isBlank(env))
         {
             final Map<String, String> environment = environmentVariableAccessor.getEnvironment();
-            if (environment == null || environment.isEmpty())
+            if (environment.isEmpty())
             {
                 return null;
             }
         return env;
     }
 
+    public void setWorkingDirectory(@Nullable File workingDirectory)
+    {
+        this.workingDirectory = workingDirectory;
+    }
+
     public static class RunContext
     {
         public String command = "";
     /**
      * {@inheritDoc}
      */
+    @Override
     public final void run() throws Exception
     {
         setCommonBuildData();
         execute();
     }
 
+    @Override
     public final void execute() throws Exception
     {
         final RunContext runContext = getRunContext();
             runContext.command = customVariableContext.substituteString(runContext.command, buildContext, buildLoggerManager.getBuildLogger(buildContext.getPlanResultKey()));
             runContext.envVars = customVariableContext.substituteString(runContext.envVars, buildContext, buildLoggerManager.getBuildLogger(buildContext.getPlanResultKey()));
 
-            execCommand(runContext);
+            execCommand(runContext, workingDirectory);
         }
     }
 
-    private void execCommand(final RunContext rc) throws Exception
+    private void execCommand(final RunContext rc, @Nullable File workingDirectoryOrNull) throws Exception
     {
+        final File workingDirectory = workingDirectoryOrNull != null ? workingDirectoryOrNull : SystemUtils.getJavaIoTmpDir();
         final Map<String, String> customEnv = getCustomEnvironmentAsMap(rc.envVars);
-        final String workingDirectory = rawBuildData.get("projectBaseDir");
 
         if (rc.runInThread)
         {
         }
     }
     
-    public abstract Logger getLogger();
-
-    public abstract RunContext getRunContext();
-
-    public abstract String getLogPrefix();
-
     public void setBuildLoggerManager(final BuildLoggerManager buildLoggerManager)
     {
         this.buildLoggerManager = buildLoggerManager;

File src/main/java/com/sysbliss/bamboo/plugins/prepostcmd/runner/ExternalTaskCompatibilityContext.java

 
 import java.io.File;
 
-/**
- * Created by IntelliJ IDEA. User: mwent Date: 10/6/11 Time: 10:54 AM To change this template use File | Settings | File
- * Templates.
- */
-    public class ExternalTaskCompatibilityContext implements TaskContext
+
+public class ExternalTaskCompatibilityContext implements TaskContext
+{
+    private final BuildLogger buildLogger;
+    private final File workingDirectory;
+    private final BuildContext buildContext;
+
+    public ExternalTaskCompatibilityContext(BuildLogger buildLogger, BuildContext buildContext, File workingDirectory)
     {
-        private final BuildLogger buildLogger;
-        private final File workingDirectory;
-        private final BuildContext buildContext;
+        this.buildContext = buildContext;
+        this.buildLogger = buildLogger;
+        this.workingDirectory = workingDirectory;
+    }
 
-        public ExternalTaskCompatibilityContext(BuildLogger buildLogger, BuildContext buildContext, File workingDirectory)
-        {
-            this.buildContext = buildContext;
-            this.buildLogger = buildLogger;
-            this.workingDirectory = workingDirectory;
-        }
+    @NotNull
+    @Override
+    public BuildContext getBuildContext()
+    {
+        return buildContext;
+    }
 
-        @NotNull
-        @Override
-        public BuildContext getBuildContext()
-        {
-            return buildContext;
-        }
+    @NotNull
+    @Override
+    public BuildLogger getBuildLogger()
+    {
+        return buildLogger;
+    }
 
-        @NotNull
-        @Override
-        public BuildLogger getBuildLogger()
-        {
-            return buildLogger;
-        }
+    @NotNull
+    @Override
+    public File getRootDirectory()
+    {
+        return workingDirectory;
+    }
 
-        @NotNull
-        @Override
-        public File getRootDirectory()
-        {
-            return workingDirectory;
-        }
+    @NotNull
+    @Override
+    public File getWorkingDirectory()
+    {
+        return workingDirectory;
+    }
 
-        @NotNull
-        @Override
-        public File getWorkingDirectory()
-        {
-            return workingDirectory;
-        }
+    @NotNull
+    @Override
+    public ConfigurationMap getConfigurationMap()
+    {
+        return new ConfigurationMapImpl();
+    }
 
-        @NotNull
-        @Override
-        public ConfigurationMap getConfigurationMap()
-        {
-            return new ConfigurationMapImpl();
-        }
+    @Override
+    public long getId()
+    {
+        return 0;
+    }
 
-        @Override
-        public long getId()
-        {
-            return 0;
-        }
+    @NotNull
+    @Override
+    public String getPluginKey()
+    {
+        return "";
+    }
 
-        @NotNull
-        @Override
-        public String getPluginKey()
-        {
-            return "";
-        }
+    @Override
+    public String getUserDescription()
+    {
+        return "";
+    }
 
-        @Override
-        public String getUserDescription()
-        {
-            return "";
-        }
-
-        @Override
-        public boolean isFinalising()
-        {
-            return false;
-        }
-    }
+    @Override
+    public boolean isFinalising()
+    {
+        return false;
+    }
+}

File src/main/java/com/sysbliss/bamboo/plugins/prepostcmd/runner/PostBuildCommandRunner.java

                     log.error("Error getting Environment Variables...", e);
                 }
 
-                context.runInThread = new Boolean(customConfiguration.get(SUCCESS_THREAD_KEY)).booleanValue();
-                context.failBuild = new Boolean(customConfiguration.get(SUCCESS_FAILBUILD_KEY)).booleanValue();
+                context.runInThread = Boolean.parseBoolean(customConfiguration.get(SUCCESS_THREAD_KEY));
+                context.failBuild = Boolean.parseBoolean(customConfiguration.get(SUCCESS_FAILBUILD_KEY));
                 if (context.runInThread)
                 {
                     context.failBuild = false;
                     log.error("Error getting Environment Variables...", e);
                 }
 
-                context.runInThread = new Boolean(customConfiguration.get(FAILED_THREAD_KEY)).booleanValue();
+                context.runInThread = Boolean.parseBoolean(customConfiguration.get(FAILED_THREAD_KEY));
                 context.failBuild = false;
             }
         }
     private BuildState getBuildState()
     {
         BuildState buildState = buildContext.getBuildResult().getBuildState();
-        if (buildState == null || buildState.equals(BuildState.UNKNOWN))
+        if (buildState.equals(BuildState.UNKNOWN))
         {
 
             if (0 < buildContext.getBuildResult().getBuildReturnCode())

File src/main/java/com/sysbliss/bamboo/plugins/prepostcmd/runner/PreBuildCommandRunner.java

                 log.error("Error getting Environment Variables...", e);
             }
 
-            context.runInThread = new Boolean(customConfiguration.get(PRE_THREAD_KEY)).booleanValue();
-            context.failBuild = new Boolean(customConfiguration.get(PRE_FAILBUILD_KEY)).booleanValue();
+            context.runInThread = Boolean.parseBoolean(customConfiguration.get(PRE_THREAD_KEY));
+            context.failBuild = Boolean.parseBoolean(customConfiguration.get(PRE_FAILBUILD_KEY));
             if (context.runInThread)
             {
                 context.failBuild = false;

File src/main/java/com/sysbliss/bamboo/plugins/prepostcmd/runner/ProcessRunner.java

 import com.atlassian.bamboo.process.ProcessService;
 import com.atlassian.bamboo.task.TaskContext;
 import com.atlassian.bamboo.v2.build.BuildContext;
-import com.atlassian.bamboo.v2.build.BuildContextHelper;
 import com.atlassian.utils.process.ExternalProcess;
 import org.apache.log4j.Logger;
 
  */
 public class ProcessRunner
 {
-
     public static final String LOG_PREFIX = "[BuildCommandRunner] ";
 
-    public static int run(final ProcessService processService, final BuildContext buildContext, final String cmd, final String workingDirectory, final Map<String, String> customEnv, final Logger log, final BuildLogger blog)
+    private ProcessRunner()
+    {
+    }
+
+    public static int run(final ProcessService processService, final BuildContext buildContext, final String cmd, final File workingDirectory, final Map<String, String> customEnv, final Logger log, final BuildLogger blog)
     {
         int exitVal = -1;
         log.info("running command: " + cmd);
         if (log.isDebugEnabled())
         {
             log.debug("Environment Variables: ");
-            for (String key : customEnv.keySet())
+            for (Map.Entry<String, String> stringStringEntry : customEnv.entrySet())
             {
-                log.debug(key + ": " + customEnv.get(key));
+                log.debug(stringStringEntry.getKey() + ": " + stringStringEntry.getValue());
             }
         }
 
         try
         {
-            TaskContext taskContext = new ExternalTaskCompatibilityContext(blog, buildContext, new File(workingDirectory));
+            TaskContext taskContext = new ExternalTaskCompatibilityContext(blog, buildContext, workingDirectory);
             ExternalProcess externalProcess = processService.executeProcess(taskContext, new ExternalProcessBuilder()
                     .commandFromString(cmd)
                     .env(customEnv)
-                    .workingDirectory(new File(workingDirectory)));
+                    .workingDirectory(taskContext.getWorkingDirectory()));
 
             if (externalProcess.getHandler().isComplete())
             {

File src/test/java/com/sysbliss/bamboo/plugins/test/CommandRunnerTestBase.java

 import com.atlassian.bamboo.build.BuildDefinition;
 import com.atlassian.bamboo.build.BuildLoggerManager;
 import com.atlassian.bamboo.build.logger.BuildLogger;
+import com.atlassian.bamboo.builder.BuildState;
 import com.atlassian.bamboo.configuration.AdministrationConfiguration;
 import com.atlassian.bamboo.configuration.AdministrationConfigurationManager;
 import com.atlassian.bamboo.plan.PlanKeys;
 import java.util.LinkedList;
 import java.util.Map;
 
-import static org.easymock.EasyMock.*;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
 
 /**
  * @author jdoklovic
         pluginAccessor = createMock(PluginAccessor.class);
 
         // define common expectations
-        expect(buildLoggerManager.getBuildLogger(FULL_BUILD_KEY)).andReturn(buildLogger).anyTimes();
         expect(buildLoggerManager.getBuildLogger(planResultKey)).andReturn(buildLogger).anyTimes();
         expect(buildContext.getBuildDefinition()).andReturn(buildDefinition).anyTimes();
         expect(buildContext.getBuildResult()).andReturn(buildResult).anyTimes();
         conf.put(PreBuildCommandRunner.PRE_THREAD_KEY, null);
 
         final Map<String, String> data = buildContext.getBuildResult().getCustomBuildData();
-        if (null != data)
-        {
-            data.put(PostRunnerTestBase.EXIT_CODE_KEY, "");
-            data.put(PreRunnerTestBase.EXIT_CODE_KEY, "");
-        }
+        data.put(PostRunnerTestBase.EXIT_CODE_KEY, "");
+        data.put(PreRunnerTestBase.EXIT_CODE_KEY, "");
 
-        buildResult.setBuildState(null);
+        buildResult.setBuildState(BuildState.UNKNOWN);
 
     }
 
     {
         INSTANCE;
 
+        @Override
         public String apply(@Nullable Map.Entry<String, String> input)
         {
             return String.format("%s", Preconditions.checkNotNull(input).getValue());

File src/test/java/com/sysbliss/bamboo/plugins/test/pre/AsyncPreRunnerTest.java

 /**
- * 
+ *
  */
 package com.sysbliss.bamboo.plugins.test.pre;
 
-import java.util.Map;
-
+import com.atlassian.bamboo.builder.BuildState;
+import com.sysbliss.bamboo.plugins.prepostcmd.runner.PreBuildCommandRunner;
 import org.testng.annotations.Test;
 
-import com.sysbliss.bamboo.plugins.prepostcmd.runner.PreBuildCommandRunner;
+import java.util.Map;
 
 /**
  * @author jdoklovic
- * 
+ *
  *         Note: We're forcing the order of these tests since they are async methods
  */
 public class AsyncPreRunnerTest extends AsyncPreTestBase {
     @Test
     public void runAsyncBadCommand() throws Exception {
-	cleanCustomConfiguration();
-	// configure the plugin
-	final Map<String, String> config = buildContext.getBuildDefinition().getCustomConfiguration();
-	config.put(PreBuildCommandRunner.CMD_KEY, NOT_FOUND_COMMAND);
-	config.put(PreBuildCommandRunner.PRE_FAILBUILD_KEY, "false");
-	config.put(PreBuildCommandRunner.PRE_THREAD_KEY, "true");
-	buildResult.setBuildState(null);
+        cleanCustomConfiguration();
+        // configure the plugin
+        final Map<String, String> config = buildContext.getBuildDefinition().getCustomConfiguration();
+        config.put(PreBuildCommandRunner.CMD_KEY, NOT_FOUND_COMMAND);
+        config.put(PreBuildCommandRunner.PRE_FAILBUILD_KEY, "false");
+        config.put(PreBuildCommandRunner.PRE_THREAD_KEY, "true");
+        buildResult.setBuildState(BuildState.UNKNOWN);
 
-	runner.run();
+        runner.run();
 
     }
 
     @Test(dependsOnMethods = { "runAsyncBadCommand" }, timeOut = 10000)
     public void checkAsyncBadCommand() throws InterruptedException {
-	waitForExitCode();
+        waitForExitCode();
 
-	final int exitcode = Integer.parseInt(buildContext.getBuildResult().getCustomBuildData().get(EXIT_CODE_KEY));
-	assert 0 != exitcode : "expected exitcode to be -1 but was " + exitcode;
+        final int exitcode = Integer.parseInt(buildContext.getBuildResult().getCustomBuildData().get(EXIT_CODE_KEY));
+        assert 0 != exitcode : "expected exitcode to be -1 but was " + exitcode;
     }
 
     @Test(dependsOnMethods = { "checkAsyncBadCommand" })
     public void runAsyncExit1Command() throws Exception {
-	cleanCustomConfiguration();
-	// configure the plugin
-	final Map<String, String> config = buildContext.getBuildDefinition().getCustomConfiguration();
-	config.put(PreBuildCommandRunner.CMD_KEY, currentLocation + EXIT_1_COMMAND);
-	config.put(PreBuildCommandRunner.PRE_FAILBUILD_KEY, "false");
-	config.put(PreBuildCommandRunner.PRE_THREAD_KEY, "true");
-	buildResult.setBuildState(null);
+        cleanCustomConfiguration();
+        // configure the plugin
+        final Map<String, String> config = buildContext.getBuildDefinition().getCustomConfiguration();
+        config.put(PreBuildCommandRunner.CMD_KEY, currentLocation + EXIT_1_COMMAND);
+        config.put(PreBuildCommandRunner.PRE_FAILBUILD_KEY, "false");
+        config.put(PreBuildCommandRunner.PRE_THREAD_KEY, "true");
+        buildResult.setBuildState(BuildState.UNKNOWN);
 
-	runner.run();
+        runner.run();
     }
 
     @Test(dependsOnMethods = { "runAsyncExit1Command" }, timeOut = 10000)
     public void checkAsyncExit1Command() throws InterruptedException {
-	waitForExitCode();
+        waitForExitCode();
 
-	final int exitcode = Integer.parseInt(buildContext.getBuildResult().getCustomBuildData().get(EXIT_CODE_KEY));
-	assert 0 != exitcode : "expected exitcode to not be 0 but was " + exitcode;
+        final int exitcode = Integer.parseInt(buildContext.getBuildResult().getCustomBuildData().get(EXIT_CODE_KEY));
+        assert 0 != exitcode : "expected exitcode to not be 0 but was " + exitcode;
     }
 
     @Test(dependsOnMethods = { "checkAsyncExit1Command" })
     public void runAsyncExit0Command() throws Exception {
-	cleanCustomConfiguration();
-	// configure the plugin
-	final Map<String, String> config = buildContext.getBuildDefinition().getCustomConfiguration();
-	config.put(PreBuildCommandRunner.CMD_KEY, currentLocation + EXIT_0_COMMAND);
-	config.put(PreBuildCommandRunner.PRE_FAILBUILD_KEY, "false");
-	config.put(PreBuildCommandRunner.PRE_THREAD_KEY, "true");
-	buildResult.setBuildState(null);
+        cleanCustomConfiguration();
+        // configure the plugin
+        final Map<String, String> config = buildContext.getBuildDefinition().getCustomConfiguration();
+        config.put(PreBuildCommandRunner.CMD_KEY, currentLocation + EXIT_0_COMMAND);
+        config.put(PreBuildCommandRunner.PRE_FAILBUILD_KEY, "false");
+        config.put(PreBuildCommandRunner.PRE_THREAD_KEY, "true");
+        buildResult.setBuildState(BuildState.UNKNOWN);
 
-	runner.run();
+        runner.run();
     }
 
     @Test(dependsOnMethods = { "runAsyncExit0Command" }, timeOut = 10000)
     public void checkAsyncExit0Command() throws InterruptedException {
-	waitForExitCode();
+        waitForExitCode();
 
-	final int exitcode = Integer.parseInt(buildContext.getBuildResult().getCustomBuildData().get(EXIT_CODE_KEY));
-	assert 0 == exitcode : "expected exitcode to be 0 but was " + exitcode;
+        final int exitcode = Integer.parseInt(buildContext.getBuildResult().getCustomBuildData().get(EXIT_CODE_KEY));
+        assert 0 == exitcode : "expected exitcode to be 0 but was " + exitcode;
     }
 }

File src/test/java/com/sysbliss/bamboo/plugins/test/pre/PreRunContextTest.java

  */
 package com.sysbliss.bamboo.plugins.test.pre;
 
-import java.util.Map;
-
+import com.atlassian.bamboo.builder.BuildState;
+import com.sysbliss.bamboo.plugins.prepostcmd.runner.AbstractCommandRunner.RunContext;
+import com.sysbliss.bamboo.plugins.prepostcmd.runner.PreBuildCommandRunner;
 import org.apache.commons.lang.StringUtils;
 import org.testng.annotations.Test;
 
-import com.sysbliss.bamboo.plugins.prepostcmd.runner.PreBuildCommandRunner;
-import com.sysbliss.bamboo.plugins.prepostcmd.runner.AbstractCommandRunner.RunContext;
+import java.util.Map;
 
 /**
  * @author jdoklovic
 	cleanCustomConfiguration();
 	final Map<String, String> config = buildContext.getBuildDefinition().getCustomConfiguration();
 	config.put(PreBuildCommandRunner.CMD_KEY, EXIT_0_COMMAND);
-	buildResult.setBuildState(null);
+	buildResult.setBuildState(BuildState.UNKNOWN);
 
 	final RunContext rc = runner.getRunContext();
 	assert StringUtils.isNotBlank(rc.command);
 	final Map<String, String> config = buildContext.getBuildDefinition().getCustomConfiguration();
 	config.put(PreBuildCommandRunner.CMD_KEY, EXIT_0_COMMAND);
 	config.put(PreBuildCommandRunner.PRE_THREAD_KEY, "true");
-	buildResult.setBuildState(null);
+	buildResult.setBuildState(BuildState.UNKNOWN);
 
 	final RunContext rc = runner.getRunContext();
 
 	final Map<String, String> config = buildContext.getBuildDefinition().getCustomConfiguration();
 	config.put(PreBuildCommandRunner.CMD_KEY, EXIT_0_COMMAND);
 	config.put(PreBuildCommandRunner.PRE_FAILBUILD_KEY, "false");
-	buildResult.setBuildState(null);
+	buildResult.setBuildState(BuildState.UNKNOWN);
 
 	final RunContext rc = runner.getRunContext();
 

File src/test/java/com/sysbliss/bamboo/plugins/test/pre/PreRunnerTest.java

  */
 package com.sysbliss.bamboo.plugins.test.pre;
 
+import com.atlassian.bamboo.builder.BuildState;
 import com.sysbliss.bamboo.plugins.prepostcmd.BuildCommandRunnerException;
 import com.sysbliss.bamboo.plugins.prepostcmd.runner.PreBuildCommandRunner;
 import org.testng.annotations.Test;
         final Map<String, String> config = buildContext.getBuildDefinition().getCustomConfiguration();
         config.put(PreBuildCommandRunner.CMD_KEY, NOT_FOUND_COMMAND);
         config.put(PreBuildCommandRunner.PRE_FAILBUILD_KEY, "false");
-        buildResult.setBuildState(null);
+        buildResult.setBuildState(BuildState.UNKNOWN);
 
         runner.run();
 
         final Map<String, String> config = buildContext.getBuildDefinition().getCustomConfiguration();
         config.put(PreBuildCommandRunner.CMD_KEY, NOT_FOUND_COMMAND);
         config.put(PreBuildCommandRunner.PRE_FAILBUILD_KEY, "true");
-        buildResult.setBuildState(null);
+        buildResult.setBuildState(BuildState.UNKNOWN);
 
         runner.run();
     }
         final Map<String, String> config = buildContext.getBuildDefinition().getCustomConfiguration();
         config.put(PreBuildCommandRunner.CMD_KEY, currentLocation + EXIT_1_COMMAND);
         config.put(PreBuildCommandRunner.PRE_FAILBUILD_KEY, "false");
-        buildResult.setBuildState(null);
+        buildResult.setBuildState(BuildState.UNKNOWN);
 
         runner.run();
 
         final Map<String, String> config = buildContext.getBuildDefinition().getCustomConfiguration();
         config.put(PreBuildCommandRunner.CMD_KEY, currentLocation + EXIT_1_COMMAND);
         config.put(PreBuildCommandRunner.PRE_FAILBUILD_KEY, "false");
-        buildResult.setBuildState(null);
+        buildResult.setBuildState(BuildState.UNKNOWN);
 
         runner.run();
 
         final Map<String, String> config = buildContext.getBuildDefinition().getCustomConfiguration();
         config.put(PreBuildCommandRunner.CMD_KEY, currentLocation + EXIT_0_COMMAND);
         config.put(PreBuildCommandRunner.PRE_FAILBUILD_KEY, "false");
-        buildResult.setBuildState(null);
+        buildResult.setBuildState(BuildState.UNKNOWN);
 
         runner.run();