hudson.Launcher类的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(164)

本文整理了Java中hudson.Launcher类的一些代码示例,展示了Launcher类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Launcher类的具体详情如下:
包路径:hudson.Launcher
类名称:Launcher

Launcher介绍

[英]Starts a process.

This hides the difference between running programs locally vs remotely.

'env' parameter

To allow important environment variables to be copied over to the remote machine, the 'env' parameter shouldn't contain default inherited environment variables (which often contains machine-specific information, like PATH, TIMEZONE, etc.)

Launcher is responsible for inheriting environment variables.
[中]开始一个过程。
这隐藏了本地运行程序与远程运行程序之间的差异。
“env”参数
要允许将重要的环境变量复制到远程计算机,“env”参数不应包含默认继承的环境变量(通常包含特定于计算机的信息,如路径、时区等)
Launcher负责继承环境变量。

代码示例

代码示例来源:origin: jenkinsci/jenkins

@Override
public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
  FilePath dir = preferredLocation(tool, node);
  // TODO support Unix scripts with interpreter line (see Shell.buildCommandLine)
  FilePath script = dir.createTextTempFile("hudson", getCommandFileExtension(), command);
  try {
    String cmd[] = getCommandCall(script);
    int r = node.createLauncher(log).launch().cmds(cmd).stdout(log).pwd(dir).join();
    if (r != 0) {
      throw new IOException("Command returned status " + r);
    }
  } finally {
    script.delete();
  }
  return dir.child(getToolHome());
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Gets the executable path of this maven on the given target system.
 */
public String getExecutable(Launcher launcher) throws IOException, InterruptedException {
  return launcher.getChannel().call(new GetExecutable());
}
private class GetExecutable extends MasterToSlaveCallable<String, IOException> {

代码示例来源:origin: jenkinsci/jenkins

@Override
public boolean isUnix() {
  return outer.isUnix();
}

代码示例来源:origin: jenkinsci/docker-slaves-plugin

@Override
public boolean checkImageExists(TaskListener listener, String image) throws IOException, InterruptedException {
  ArgumentListBuilder args = new ArgumentListBuilder()
      .add("inspect")
      .add("-f", "'{{.Id}}'")
      .add(image);
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  Launcher launcher = new Launcher.LocalLauncher(listener);
  return launchDockerCLI(launcher, args)
      .stdout(out).stderr(launcher.getListener().getLogger()).join() == 0;
}

代码示例来源:origin: jenkinsci/nodejs-plugin

@Override
  public String invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
    Charset charset = Charset.defaultCharset();
    FilePath basePath = new FilePath(f);
    Launcher launcher = basePath.createLauncher(new StreamTaskListener(new NullOutputStream(), charset));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Proc starter = launcher.launch().cmdAsSingleString("uname -m").stdout(baos).start();
    int exitCode = starter.join();
    if (exitCode != 0) {
      throw new IOException("Fail to execute 'uname -m' because: " + baos.toString(charset.name()));
    }
    return new String(baos.toByteArray(), charset).trim();
  }
};

代码示例来源:origin: org.jvnet.hudson.main/maven3-plugin

private String getMavenVersionFromConsole() throws Exception {
  ArgumentListBuilder args = new ArgumentListBuilder();
  args.add(getExecutable());
  args.add("--version");
  env.put(M2_HOME, getHome().getRemote());
  env.put(MAVEN_SKIP_RC, TRUE);
  ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  Proc process = launcher.launch()
    .cmds(args)
    .envs(env)
    .pwd(build.getWorkspace())
    .stdout(buffer)
    .start();
  String output = new String(buffer.toByteArray());
  if (muxlog.isTraceEnabled()) {
    muxlog.trace("Process output:\n{}", output);

代码示例来源:origin: jenkinsci/docker-custom-build-environment-plugin

public boolean pullImage(String image) throws IOException, InterruptedException {
  ArgumentListBuilder args = dockerCommand()
    .add("pull", image);
  OutputStream out = verbose ? listener.getLogger() : new ByteArrayOutputStream();
  OutputStream err = verbose ? listener.getLogger() : new ByteArrayOutputStream();
  int status = launcher.launch()
      .envs(getEnvVars())
      .cmds(args)
      .stdout(out).stderr(err).join();
  return status == 0;
}

代码示例来源:origin: jenkinsci/docker-custom-build-environment-plugin

public String buildImage(FilePath workspace, String dockerfile, boolean forcePull, boolean noCache) throws IOException, InterruptedException {
    .add("build");
    args.add("--pull");
    args.add("--no-cache");
  args.add("--file", dockerfile)
    .add(workspace.getRemote());
  args.add("--label", "jenkins-project=" + this.build.getProject().getName());
  args.add("--label", "jenkins-build-number=" + this.build.getNumber());
  OutputStream logOutputStream = listener.getLogger();
  OutputStream err = listener.getLogger();
  ByteArrayOutputStream resultOutputStream = new ByteArrayOutputStream();
  TeeOutputStream teeOutputStream = new TeeOutputStream(logOutputStream, resultOutputStream);
  int status = launcher.launch()
      .envs(getEnvVars())
      .cmds(args)
      .stdout(teeOutputStream).stderr(err).join();
  if (status != 0) {
    throw new RuntimeException("Failed to build docker image from project Dockerfile");
  Matcher matcher = pattern.matcher(resultOutputStream.toString("UTF-8"));
  if (!matcher.find())

代码示例来源:origin: jenkinsci/jenkins

.replaceAll("[\t\r\n]+"," ");
ArgumentListBuilder args = new ArgumentListBuilder();
MavenInstallation mi = getMaven();
if(mi==null) {
  String execName = build.getWorkspace().act(new DecideDefaultMavenCommand(normalizedTarget));
  args.add(execName);
} else {
  mi = mi.forNode(Computer.currentComputer().getNode(), listener);
    return false;
  args.add(exec);
  args.add("-Dmaven.repo.local=" + build.getWorkspace().child(".repository"));
args.addTokenized(normalizedTarget);
wrapUpArguments(args,normalizedTarget,build,launcher,listener);
if (!launcher.isUnix()) {
  args = args.toWindowsCommand();
  int r = launcher.launch().cmds(args).envs(env).stdout(mca).pwd(build.getModuleRoot()).join();
  if (0 != r) {
    return false;

代码示例来源:origin: jenkinsci/coverity-plugin

private void addCommand(String cmd, String home){
  String command = cmd;
  if (!StringUtils.isEmpty(home)){
    command = new FilePath(launcher.getChannel(), home).child("bin").child(command).getRemote();
  }
  commandLine.add(command);
}

代码示例来源:origin: jenkinsci/artifactory-plugin

public static void exeConan(ArgumentListBuilder args, FilePath pwd, Launcher launcher, TaskListener listener, Run build, EnvVars env) {
  boolean failed;
  try {
    if (!pwd.exists()) {
      pwd.mkdirs();
    if (launcher.isUnix()) {
      boolean hasMaskedArguments = args.hasMaskedArguments();
      StringBuilder sb = new StringBuilder();
      for (String arg : args.toList()) {
        sb.append(escapeUnixArgument(arg)).append(" ");
      args.clear();
      args.add("sh", "-c");
      if (hasMaskedArguments) {
      args = args.toWindowsCommand();
    int exitValue = launcher.launch().cmds(args).envs(env).stdout(listener).pwd(pwd).join();
    failed = (exitValue != 0);
  } catch (Exception e) {
    listener.error("Couldn't execute the conan client executable. " + e.getMessage());
    build.setResult(Result.FAILURE);
    throw new Run.RunnerAbortedException();

代码示例来源:origin: jenkinsci/comments-remover-plugin

private void runCommentsRemoverProcess(FilePath workspace, Launcher launcher, TaskListener listener, File
    removerScriptDir, File outputDirPath) throws IOException, InterruptedException {
  String pythonPath = getDescriptor().getPythonPath();
  String pipPath = getDescriptor().getPipPath();
  String pipExecutable = StringUtils.isEmpty(pythonPath) ? "pip" : pipPath;
  String[] pipCommand = new String[]{pipExecutable, "install", "-r", removerScriptDir + File.separator + "requirements.txt", "-q"};
  listener.getLogger().println("Installing pip requirements [" + StringUtils.join(pipCommand, " ") + "]...");
  runProcess(launcher.launch().cmds(pipCommand).readStdout().start(), listener);
  String pythonExecutable = StringUtils.isEmpty(pythonPath) ? "python" : pythonPath;
  String[] commentsRemoverCommand = new String[]{pythonExecutable, removerScriptDir + File.separator + COMMENTS_REMOVER_ENTRY_FILE,
      workspace.getRemote() + File.separator + filename, language, outputDirPath.getAbsolutePath()};
  listener.getLogger().println("Executing script [" + StringUtils.join(commentsRemoverCommand, " ") + "]...");
  runProcess(launcher.launch().cmds(commentsRemoverCommand).readStdout().start(), listener);
}

代码示例来源:origin: jenkinsci/artifactory-plugin

@Override
protected Boolean run() throws Exception {
  pomFile = new FilePath(ws, step.getPomFile()).getRemote();
  failOnSnapshot = step.isFailOnSnapshot();
  dryRun = step.isDryRun();
  this.version = step.getVersion();
  this.versionPerModule = step.getVersionPerModule();
  Boolean call = launcher.getChannel().call(new MasterToSlaveCallable<Boolean, IOException>() {
    public Boolean call() throws IOException {
      return transformPoms();
    }
  });
  return call;
}

代码示例来源:origin: jenkinsci/artifactory-plugin

@Override
protected BuildInfo run() throws Exception {
  BuildInfo buildInfo = Utils.prepareBuildinfo(build, step.getBuildInfo());
  FilePath conanHomeDirectory = new FilePath(launcher.getChannel(), step.getConanHome());
  persistBuildProperties(buildInfo, conanHomeDirectory);
  EnvVars extendedEnv = new EnvVars(env);
  extendedEnv.put(Utils.CONAN_USER_HOME, step.getConanHome());
  execConanCommand(extendedEnv);
  FilePath logFilePath = execConanCollectBuildInfo(extendedEnv);
  Build regularBuildInfo = Utils.getGeneratedBuildInfo(build, listener, launcher, logFilePath.getRemote());
  buildInfo.append(regularBuildInfo);
  return buildInfo;
}

代码示例来源:origin: jenkinsci/docker-commons-plugin

@Override
public KeyMaterial materialize() throws IOException, InterruptedException {
  FilePath dockerConfig = createSecretsDirectory();
  try {
    // TODO on Docker 17.07+ use --password-stdin
    EnvVars envWithConfig = new EnvVars(env);
    envWithConfig.put("DOCKER_CONFIG", dockerConfig.getRemote());
    if (launcher.launch().cmds(new ArgumentListBuilder(dockerExecutable, "login", "-u", username, "-p").add(password, true).add(endpoint)).envs(envWithConfig).stdout(listener).join() != 0) {
      throw new AbortException("docker login failed");
    }
  } catch (IOException | InterruptedException x) {
    try {
      dockerConfig.deleteRecursive();
    } catch (Exception x2) {
      x.addSuppressed(x2);
    }
    throw x;
  }
  return new RegistryKeyMaterial(dockerConfig, new EnvVars("DOCKER_CONFIG", dockerConfig.getRemote()));
}

代码示例来源:origin: jenkinsci/maven-plugin

@Override
protected String getMavenAgentClassPath(MavenInstallation mvn, FilePath slaveRoot, BuildListener listener) throws IOException, InterruptedException {
  String classWorldsJar = getLauncher().getChannel().call(new GetClassWorldsJar(mvn.getHome(),listener));
  String path = classPathEntry(slaveRoot, Maven33Main.class, "maven33-agent", listener) +
    (getLauncher().isUnix()?":":";")+classWorldsJar;
  // TODO this configurable??
  path += (getLauncher().isUnix()?":":";")+mvn.getHomeDir().getPath()+"/conf/logging";
  return path;
}

代码示例来源:origin: jenkinsci/shiningpanda-plugin

throws InterruptedException, IOException {
ArgumentListBuilder args = new ArgumentListBuilder("ln", "-s", target.getRemote(), link.getRemote());
  return 0 == launcher.launch().cmds(args).stdout(listener).join();
} catch (IOException e) {
  e.printStackTrace(listener.fatalError(Messages.CommandInterpreter_CommandFailed()));

代码示例来源:origin: jenkinsci/jenkins

/**
 * Starts the new process as configured.
 */
public Proc start() throws IOException {
  return launch(this);
}

代码示例来源:origin: ingenieux/awseb-deployment-plugin

public boolean perform() throws Exception {
    FilePath rootFileObject = new FilePath(this.workspace, config.getRootObject());

    final DeployerContext
        deployerContext = new DeployerContext(config, rootFileObject, listener);

    final VirtualChannel channel = launcher.getChannel();

    if (null == channel)
      throw new IllegalStateException("Null Channel (?)");

    final Future<Boolean>
        booleanFuture =
        channel.callAsync(new SlaveDeployerCallable(deployerContext));

    return booleanFuture.get();
  }
}

代码示例来源:origin: org.jvnet.hudson.main/maven3-plugin

public FilePath getHome() {
  if (home == null) {
    home = new FilePath(launcher.getChannel(), installation.getHome());
  }
  return home;
}

相关文章