hudson.model.Node.createLauncher()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(13.6k)|赞(0)|评价(0)|浏览(161)

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

Node.createLauncher介绍

[英]Returns a Launcher for executing programs on this node.

The callee must call Launcher#decorateFor(Node) before returning to complete the decoration.
[中]返回用于在此节点上执行程序的启动器。
被调用方必须在返回以完成装饰之前调用Launcher#decorefor(节点)。

代码示例

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

  1. /**
  2. * Checks if "java" is in PATH on the given node.
  3. *
  4. * <p>
  5. * If it's not, then the user must specify a configured JDK,
  6. * so this is often useful for form field validation.
  7. */
  8. public static boolean isDefaultJDKValid(Node n) {
  9. try {
  10. TaskListener listener = new StreamTaskListener(new NullStream());
  11. Launcher launcher = n.createLauncher(listener);
  12. return launcher.launch().cmds("java","-fullversion").stdout(listener).join()==0;
  13. } catch (IOException e) {
  14. return false;
  15. } catch (InterruptedException e) {
  16. return false;
  17. }
  18. }

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

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

代码示例来源:origin: org.jenkins-ci.plugins/rake

  1. private Launcher getLastBuiltLauncher(AbstractBuild build, Launcher launcher, BuildListener listener) {
  2. AbstractProject project = build.getProject();
  3. Node lastBuiltOn = project.getLastBuiltOn();
  4. Launcher lastBuiltLauncher = launcher;
  5. if (lastBuiltOn != null) {
  6. lastBuiltLauncher = lastBuiltOn.createLauncher(listener);
  7. }
  8. return lastBuiltLauncher;
  9. }

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

  1. private Launcher launcher() {
  2. return node().createLauncher(listener);
  3. }

代码示例来源:origin: org.jvnet.hudson.plugins/clearcase

  1. public String getCleartoolExe(Node node, TaskListener listener) throws IOException, InterruptedException {
  2. ClearCaseInstallation installation = this;
  3. installation = installation.forNode(node, listener);
  4. if (StringUtils.isNotBlank(installation.getHome())) {
  5. // If an installation is specified, use it
  6. return PathUtil.convertPathForOS(installation.getHome() + "/" + CLEARTOOL_EXE, node.createLauncher(listener).decorateFor(node).isUnix());
  7. } else {
  8. // Otherwise, fallback to a default case where cleartool is in PATH
  9. return CLEARTOOL_EXE_FALLBACK;
  10. }
  11. }

代码示例来源:origin: hudson/hudson-2.x

  1. public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
  2. FilePath dir = preferredLocation(tool, node);
  3. // XXX support Windows batch scripts, Unix scripts with interpreter line, etc. (see CommandInterpreter subclasses)
  4. FilePath script = dir.createTextTempFile("hudson", ".sh", command);
  5. try {
  6. String[] cmd = {"sh", "-e", script.getRemote()};
  7. int r = node.createLauncher(log).launch().cmds(cmd).stdout(log).pwd(dir).join();
  8. if (r != 0) {
  9. throw new IOException("Command returned status " + r);
  10. }
  11. } finally {
  12. script.delete();
  13. }
  14. return dir.child(toolHome);
  15. }

代码示例来源:origin: org.eclipse.hudson.main/hudson-core

  1. public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
  2. FilePath dir = preferredLocation(tool, node);
  3. // XXX support Windows batch scripts, Unix scripts with interpreter line, etc. (see CommandInterpreter subclasses)
  4. FilePath script = dir.createTextTempFile("hudson", ".sh", command);
  5. try {
  6. String[] cmd = {"sh", "-e", script.getRemote()};
  7. int r = node.createLauncher(log).launch().cmds(cmd).stdout(log).pwd(dir).join();
  8. if (r != 0) {
  9. throw new IOException("Command returned status " + r);
  10. }
  11. } finally {
  12. script.delete();
  13. }
  14. return dir.child(toolHome);
  15. }

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

  1. public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
  2. FilePath dir = preferredLocation(tool, node);
  3. // XXX support Windows batch scripts, Unix scripts with interpreter line, etc. (see CommandInterpreter subclasses)
  4. FilePath script = dir.createTextTempFile("hudson", ".sh", command);
  5. try {
  6. String[] cmd = {"sh", "-e", script.getRemote()};
  7. int r = node.createLauncher(log).launch().cmds(cmd).stdout(log).pwd(dir).join();
  8. if (r != 0) {
  9. throw new IOException("Command returned status " + r);
  10. }
  11. } finally {
  12. script.delete();
  13. }
  14. return dir.child(toolHome);
  15. }

代码示例来源:origin: org.eclipse.hudson/hudson-core

  1. public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
  2. FilePath dir = preferredLocation(tool, node);
  3. // XXX support Windows batch scripts, Unix scripts with interpreter line, etc. (see CommandInterpreter subclasses)
  4. FilePath script = dir.createTextTempFile("hudson", ".sh", command);
  5. try {
  6. String[] cmd = {"sh", "-e", script.getRemote()};
  7. int r = node.createLauncher(log).launch().cmds(cmd).stdout(log).pwd(dir).join();
  8. if (r != 0) {
  9. throw new IOException("Command returned status " + r);
  10. }
  11. } finally {
  12. script.delete();
  13. }
  14. return dir.child(toolHome);
  15. }

代码示例来源:origin: org.jvnet.hudson.plugins/clearcase

  1. @Override
  2. public boolean processWorkspaceBeforeDeletion(AbstractProject<?, ?> project, FilePath workspace, Node node) throws IOException, InterruptedException {
  3. if (node == null) {
  4. // HUDSON-7663 : deleting a job that has never run
  5. return true;
  6. }
  7. StreamTaskListener listener = StreamTaskListener.fromStdout();
  8. Launcher launcher = node.createLauncher(listener);
  9. ClearTool ct = createClearTool(null, createClearToolLauncher(listener, project.getSomeWorkspace().getParent().getParent(), launcher));
  10. try {
  11. if (isUseDynamicView() && !isCreateDynView()) {
  12. return true;
  13. }
  14. AbstractBuild<?, ?> latestBuildOnNode = null;
  15. for(AbstractBuild<?, ?> build : project.getBuilds()) {
  16. if (node.equals(build.getBuiltOn())) {
  17. latestBuildOnNode = build;
  18. break;
  19. }
  20. }
  21. if (latestBuildOnNode == null) {
  22. latestBuildOnNode = project.getLastBuild();
  23. }
  24. BuildVariableResolver buildVariableResolver = new BuildVariableResolver(latestBuildOnNode);
  25. ct.rmviewtag(generateNormalizedViewName(buildVariableResolver));
  26. } catch (Exception e) {
  27. Logger.getLogger(AbstractClearCaseScm.class.getName()).log(Level.WARNING, "Failed to remove ClearCase view", e);
  28. }
  29. return true;
  30. }

代码示例来源:origin: org.eclipse.hudson.main/hudson-core

  1. /**
  2. * Checks if "java" is in PATH on the given node.
  3. *
  4. * <p>
  5. * If it's not, then the user must specify a configured JDK,
  6. * so this is often useful for form field validation.
  7. */
  8. public static boolean isDefaultJDKValid(Node n) {
  9. try {
  10. TaskListener listener = new StreamTaskListener(new NullStream());
  11. Launcher launcher = n.createLauncher(listener);
  12. return launcher.launch().cmds("java","-fullversion").stdout(listener).join()==0;
  13. } catch (IOException e) {
  14. return false;
  15. } catch (InterruptedException e) {
  16. return false;
  17. }
  18. }

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

  1. /**
  2. * Checks if "java" is in PATH on the given node.
  3. *
  4. * <p>
  5. * If it's not, then the user must specify a configured JDK,
  6. * so this is often useful for form field validation.
  7. */
  8. public static boolean isDefaultJDKValid(Node n) {
  9. try {
  10. TaskListener listener = new StreamTaskListener(new NullStream());
  11. Launcher launcher = n.createLauncher(listener);
  12. return launcher.launch().cmds("java","-fullversion").stdout(listener).join()==0;
  13. } catch (IOException e) {
  14. return false;
  15. } catch (InterruptedException e) {
  16. return false;
  17. }
  18. }

代码示例来源:origin: org.eclipse.hudson/hudson-core

  1. /**
  2. * Checks if "java" is in PATH on the given node.
  3. *
  4. * <p> If it's not, then the user must specify a configured JDK, so this is
  5. * often useful for form field validation.
  6. */
  7. public static boolean isDefaultJDKValid(Node n) {
  8. try {
  9. TaskListener listener = new StreamTaskListener(new NullStream());
  10. Launcher launcher = n.createLauncher(listener);
  11. return launcher.launch().cmds("java", "-fullversion").stdout(listener).join() == 0;
  12. } catch (IOException e) {
  13. return false;
  14. } catch (InterruptedException e) {
  15. return false;
  16. }
  17. }

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

  1. /**
  2. * Checks if "java" is in PATH on the given node.
  3. *
  4. * <p>
  5. * If it's not, then the user must specify a configured JDK,
  6. * so this is often useful for form field validation.
  7. */
  8. public static boolean isDefaultJDKValid(Node n) {
  9. try {
  10. TaskListener listener = new StreamTaskListener(new NullStream());
  11. Launcher launcher = n.createLauncher(listener);
  12. return launcher.launch().cmds("java","-fullversion").stdout(listener).join()==0;
  13. } catch (IOException e) {
  14. return false;
  15. } catch (InterruptedException e) {
  16. return false;
  17. }
  18. }

代码示例来源:origin: hudson/hudson-2.x

  1. /**
  2. * Checks if "java" is in PATH on the given node.
  3. *
  4. * <p>
  5. * If it's not, then the user must specify a configured JDK,
  6. * so this is often useful for form field validation.
  7. */
  8. public static boolean isDefaultJDKValid(Node n) {
  9. try {
  10. TaskListener listener = new StreamTaskListener(new NullStream());
  11. Launcher launcher = n.createLauncher(listener);
  12. return launcher.launch().cmds("java","-fullversion").stdout(listener).join()==0;
  13. } catch (IOException e) {
  14. return false;
  15. } catch (InterruptedException e) {
  16. return false;
  17. }
  18. }

代码示例来源:origin: org.eclipse.hudson.main/hudson-core

  1. public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
  2. FilePath expectedLocation = preferredLocation(tool, node);
  3. PrintStream out = log.getLogger();
  4. try {
  5. if(!acceptLicense) {
  6. out.println(Messages.JDKInstaller_UnableToInstallUntilLicenseAccepted());
  7. return expectedLocation;
  8. }
  9. // already installed?
  10. FilePath marker = expectedLocation.child(".installedByHudson");
  11. if (marker.exists() && marker.readToString().equals(id)) {
  12. return expectedLocation;
  13. }
  14. expectedLocation.deleteRecursive();
  15. expectedLocation.mkdirs();
  16. Platform p = Platform.of(node);
  17. URL url = locate(log, p, CPU.of(node));
  18. out.println("Downloading "+url);
  19. FilePath file = expectedLocation.child(p.bundleFileName);
  20. file.copyFrom(url);
  21. // JDK6u13 on Windows doesn't like path representation like "/tmp/foo", so make it a strict platform native format by doing 'absolutize'
  22. install(node.createLauncher(log), p, new FilePathFileSystem(node), log, expectedLocation.absolutize().getRemote(), file.getRemote());
  23. // successfully installed
  24. file.delete();
  25. marker.write(id, null);
  26. } catch (DetectionFailedException e) {
  27. out.println("JDK installation skipped: "+e.getMessage());
  28. }
  29. return expectedLocation;
  30. }

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

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

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

  1. public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
  2. FilePath expectedLocation = preferredLocation(tool, node);
  3. PrintStream out = log.getLogger();
  4. try {
  5. if(!acceptLicense) {
  6. out.println(Messages.JDKInstaller_UnableToInstallUntilLicenseAccepted());
  7. return expectedLocation;
  8. }
  9. // already installed?
  10. FilePath marker = expectedLocation.child(".installedByHudson");
  11. if (marker.exists() && marker.readToString().equals(id)) {
  12. return expectedLocation;
  13. }
  14. expectedLocation.deleteRecursive();
  15. expectedLocation.mkdirs();
  16. Platform p = Platform.of(node);
  17. URL url = locate(log, p, CPU.of(node));
  18. out.println("Downloading "+url);
  19. FilePath file = expectedLocation.child(p.bundleFileName);
  20. file.copyFrom(url);
  21. // JDK6u13 on Windows doesn't like path representation like "/tmp/foo", so make it a strict platform native format by doing 'absolutize'
  22. install(node.createLauncher(log), p, new FilePathFileSystem(node), log, expectedLocation.absolutize().getRemote(), file.getRemote());
  23. // successfully installed
  24. file.delete();
  25. marker.write(id, null);
  26. } catch (DetectionFailedException e) {
  27. out.println("JDK installation skipped: "+e.getMessage());
  28. }
  29. return expectedLocation;
  30. }

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

  1. install(node.createLauncher(log), p, new FilePathFileSystem(node), log, expectedLocation.absolutize().getRemote(), file.getRemote());

代码示例来源:origin: org.jenkins-ci.plugins.workflow/workflow-cps-global-lib

  1. static void doRetrieve(String name, boolean changelog, @Nonnull SCM scm, FilePath target, Run<?, ?> run, TaskListener listener) throws Exception {
  2. // Adapted from CpsScmFlowDefinition:
  3. SCMStep delegate = new GenericSCMStep(scm);
  4. delegate.setPoll(false); // TODO we have no API for determining if a given SCMHead is branch-like or tag-like; would we want to turn on polling if the former?
  5. delegate.setChangelog(changelog);
  6. FilePath dir;
  7. Node node = Jenkins.getActiveInstance();
  8. if (run.getParent() instanceof TopLevelItem) {
  9. FilePath baseWorkspace = node.getWorkspaceFor((TopLevelItem) run.getParent());
  10. if (baseWorkspace == null) {
  11. throw new IOException(node.getDisplayName() + " may be offline");
  12. }
  13. dir = baseWorkspace.withSuffix(getFilePathSuffix() + "libs").child(name);
  14. } else { // should not happen, but just in case:
  15. throw new AbortException("Cannot check out in non-top-level build");
  16. }
  17. Computer computer = node.toComputer();
  18. if (computer == null) {
  19. throw new IOException(node.getDisplayName() + " may be offline");
  20. }
  21. try (WorkspaceList.Lease lease = computer.getWorkspaceList().allocate(dir)) {
  22. delegate.checkout(run, lease.path, listener, node.createLauncher(listener));
  23. // Cannot add WorkspaceActionImpl to private CpsFlowExecution.flowStartNodeActions; do we care?
  24. // Copy sources with relevant files from the checkout:
  25. lease.path.copyRecursiveTo("src/**/*.groovy,vars/*.groovy,vars/*.txt,resources/", null, target);
  26. }
  27. }

相关文章