Skip to content

Commit

Permalink
Added another decorator.
Browse files Browse the repository at this point in the history
This allows us to pass in a proper Launcher that handles all the environment variables without asking individual user to fill in a proper environment variables
  • Loading branch information
kohsuke committed Oct 24, 2012
1 parent ba23c8b commit f5cebdc
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions core/src/main/java/hudson/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -690,6 +691,52 @@ private boolean[] prefix(boolean[] args) {
};
}

/**
* Returns a decorated {@link Launcher} that automatically adds the specified environment
* variables.
*
* Those that are specified in {@link ProcStarter#envs(String...)} will take precedence over
* what's specified here.
*

This comment has been minimized.

Copy link
@jglick

jglick Oct 24, 2012

Member

Is this not now 1.489?

* @since 1.488
*/
public final Launcher decorateByEnv(EnvVars _env) {
final EnvVars env = new EnvVars(_env);
final Launcher outer = this;
return new Launcher(outer) {
@Override
public Proc launch(ProcStarter starter) throws IOException {
EnvVars e = new EnvVars(env);
if (starter.envs!=null) {
for (int i=0; i<starter.envs.length; i+=2)

This comment has been minimized.

Copy link
@jglick
e.put(starter.envs[i],starter.envs[i+1]);
}

String[] r = new String[e.size()*2];
int idx=0;
for (Entry<String, String> i : e.entrySet()) {
r[idx++] = i.getKey();
r[idx++] = i.getValue();
}

starter.envs = r;
return outer.launch(starter);
}

@Override
public Channel launchChannel(String[] cmd, OutputStream out, FilePath workDir, Map<String, String> envVars) throws IOException, InterruptedException {
EnvVars e = new EnvVars(env);
e.putAll(envVars);
return outer.launchChannel(cmd,out,workDir,e);
}

@Override
public void kill(Map<String, String> modelEnvVars) throws IOException, InterruptedException {
outer.kill(modelEnvVars);
}
};
}

/**
* {@link Launcher} that launches process locally.
*/
Expand Down

0 comments on commit f5cebdc

Please sign in to comment.