提交 f5cebdc8 编写于 作者: K Kohsuke Kawaguchi

Added another decorator.

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
上级 ba23c8b5
......@@ -51,6 +51,7 @@ import java.util.Arrays;
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;
......@@ -690,6 +691,52 @@ public abstract class Launcher {
};
}
/**
* 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.
*
* @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)
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.
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册