Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gboissinot committed Sep 27, 2011
1 parent 1a2b745 commit 1adeec1
Showing 1 changed file with 36 additions and 36 deletions.
Expand Up @@ -49,35 +49,38 @@ public Environment setUpEnvironment(AbstractBuild build, Launcher launcher, Buil
variables.putAll(getBuildVariables(build));
}

//Build a properties object with all information
final Map<String, String> envMap = getEnvVarsFromInfoObject(info, variables, launcher, listener);
variables.putAll(envMap);

// Retrieve triggered cause
if (info.isPopulateTriggerCause()) {
Map<String, String> triggerVariable = new BuildCauseRetriever().getTriggeredCause(build);
variables.putAll(triggerVariable);
}
final FilePath rootPath = getNodeRootPath();
if (rootPath != null) {

//Resolves vars each other
EnvVars.resolve(variables);
//Build a properties object with all information
final Map<String, String> envMap = getEnvVarsFromProperties(rootPath, info, variables, launcher, listener);
variables.putAll(envMap);

//Remove unset variables
final Map<String, String> resultVariables = new EnvInjectEnvVarsUnset(logger).removeUnsetVars(variables);
// Retrieve triggered cause
if (info.isPopulateTriggerCause()) {
Map<String, String> triggerVariable = new BuildCauseRetriever().getTriggeredCause(build);
variables.putAll(triggerVariable);
}

//Add a display action
FilePath rootPath = getNodeRootPath();
if (rootPath != null) {
//Resolves vars each other
EnvVars.resolve(variables);

//Remove unset variables
final Map<String, String> resultVariables = new EnvInjectEnvVarsUnset(logger).removeUnsetVars(variables);

//Add an action
new EnvInjectActionSetter(rootPath).addEnvVarsToEnvInjectBuildAction(build, resultVariables);
}

return new Environment() {
//Execute script
executeScript(rootPath, info, resultVariables, launcher, listener);

@Override
public void buildEnvVars(Map<String, String> env) {
env.putAll(resultVariables);
}
};
return new Environment() {
@Override
public void buildEnvVars(Map<String, String> env) {
env.putAll(resultVariables);
}
};
}

} catch (EnvInjectException envEx) {
logger.error("SEVERE ERROR occurs: " + envEx.getMessage());
Expand All @@ -88,29 +91,26 @@ public void buildEnvVars(Map<String, String> env) {
}
}


return new Environment() {
};
}

private Map<String, String> getEnvVarsFromInfoObject(final EnvInjectJobPropertyInfo info, final Map<String, String> currentEnvVars, final Launcher launcher, BuildListener listener) throws Throwable {

private Map<String, String> getEnvVarsFromProperties(FilePath rootPath, final EnvInjectJobPropertyInfo info, final Map<String, String> currentEnvVars, final Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
final Map<String, String> resultMap = new LinkedHashMap<String, String>();

EnvInjectLogger logger = new EnvInjectLogger(listener);
FilePath rootPath = getNodeRootPath();
if (rootPath != null) {

//Get env vars from properties
resultMap.putAll(rootPath.act(new PropertiesVariablesRetriever(info, currentEnvVars, logger)));

//Execute script info
EnvInjectScriptExecutorService scriptExecutorService = new EnvInjectScriptExecutorService(info, currentEnvVars, rootPath, launcher, logger);
scriptExecutorService.executeScriptFromInfoObject();
}

//Get env vars from properties
resultMap.putAll(rootPath.act(new PropertiesVariablesRetriever(info, currentEnvVars, logger)));
return resultMap;
}

private static void executeScript(FilePath rootPath, final EnvInjectJobPropertyInfo info, final Map<String, String> currentEnvVars, final Launcher launcher, BuildListener listener) throws EnvInjectException {
EnvInjectLogger logger = new EnvInjectLogger(listener);
EnvInjectScriptExecutorService scriptExecutorService = new EnvInjectScriptExecutorService(info, currentEnvVars, rootPath, launcher, logger);
scriptExecutorService.executeScriptFromInfoObject();
}

private Node getNode() {
Computer computer = Computer.currentComputer();
return computer.getNode();
Expand Down

0 comments on commit 1adeec1

Please sign in to comment.