/** * Performs a necessary variable/environment/context expansion. * * @param node * Node that this tool is used in. * @param envs * Set of environment variables to expand any references. * @param listener * Any lengthy operation (such as auto-installation) will report its progress here. * @return * {@link ToolInstallation} object that is fully specialized. * @see NodeSpecific * @see EnvironmentSpecific * @since 1.460 */ public ToolInstallation translate(@Nonnull Node node, EnvVars envs, TaskListener listener) throws IOException, InterruptedException { ToolInstallation t = this; if (t instanceof NodeSpecific) { NodeSpecific n = (NodeSpecific) t; t = (ToolInstallation)n.forNode(node,listener); } if (t instanceof EnvironmentSpecific) { EnvironmentSpecific e = (EnvironmentSpecific) t; t = (ToolInstallation)e.forEnvironment(envs); } return t; }
public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException { FilePath expected = preferredLocation(tool, node); Installable inst = getInstallable(); if(inst==null) { log.getLogger().println("Invalid tool ID "+id); return expected; } if (inst instanceof NodeSpecific) { inst = (Installable) ((NodeSpecific) inst).forNode(node, log); } if(isUpToDate(expected,inst)) return expected; if(expected.installIfNecessaryFrom(new URL(inst.url), log, "Unpacking " + inst.url + " to " + expected + " on " + node.getDisplayName())) { expected.child(".timestamp").delete(); // we don't use the timestamp FilePath base = findPullUpDirectory(expected); if(base!=null && base!=expected) base.moveAllChildrenTo(expected); // leave a record for the next up-to-date check expected.child(".installedFrom").write(inst.url,"UTF-8"); expected.act(new ZipExtractionInstaller.ChmodRecAPlusX()); } return expected; }
/** * Performs a necessary variable/environment/context expansion. * * @param node * Node that this tool is used in. * @param envs * Set of environment variables to expand any references. * @param listener * Any lengthy operation (such as auto-installation) will report its progress here. * @return * {@link ToolInstallation} object that is fully specialized. * @see NodeSpecific * @see EnvironmentSpecific * @since 1.460 */ public ToolInstallation translate(@Nonnull Node node, EnvVars envs, TaskListener listener) throws IOException, InterruptedException { ToolInstallation t = this; if (t instanceof NodeSpecific) { NodeSpecific n = (NodeSpecific) t; t = (ToolInstallation)n.forNode(node,listener); } if (t instanceof EnvironmentSpecific) { EnvironmentSpecific e = (EnvironmentSpecific) t; t = (ToolInstallation)e.forEnvironment(envs); } return t; }
@CheckForNull public static <T extends ToolInstallation & EnvironmentSpecific<T> & NodeSpecific<T>> T getBuildTool(@Nullable T tool, EnvVars env, TaskListener listener, FilePath workspace) throws IOException, InterruptedException { Computer computer = workspace.toComputer(); if (computer == null) { return null; } Node node = computer.getNode(); if (tool == null || node == null) { return null; } T t = tool.forNode(node, listener); t = t.forEnvironment(env); return t; }
@Override protected List<String> run() throws Exception { String toolVersion = step.getToolVersion(); String toolId = step.getToolId(); for (ToolDescriptor<?> desc : ToolInstallation.all()) { if (toolId != null && !desc.getId().equals(toolId)) { continue; } for (ToolInstallation tool : desc.getInstallations()) { if (tool.getName().equals(toolVersion)) { if (tool instanceof NodeSpecific) { tool = (ToolInstallation) ((NodeSpecific<?>) tool).forNode(node, listener); } if (tool instanceof EnvironmentSpecific) { tool = (ToolInstallation) ((EnvironmentSpecific<?>) tool).forEnvironment(env); } List<String> toolEnvList = new ArrayList<>(); EnvVars toolEnv = new EnvVars(); tool.buildEnvVars(toolEnv); for (Map.Entry<String,String> entry: toolEnv.entrySet()) { toolEnvList.add(entry.getKey() + "=" + entry.getValue()); } return toolEnvList; } } } throw new AbortException("No tool of type " + toolId + " named " + toolVersion + " found"); }
public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException { FilePath expected = preferredLocation(tool, node); Installable inst = getInstallable(); if(inst==null) { log.getLogger().println("Invalid tool ID "+id); return expected; } if (inst instanceof NodeSpecific) { inst = (Installable) ((NodeSpecific) inst).forNode(node, log); } if(isUpToDate(expected,inst)) return expected; if(expected.installIfNecessaryFrom(new URL(inst.url), log, "Unpacking " + inst.url + " to " + expected + " on " + node.getDisplayName())) { expected.child(".timestamp").delete(); // we don't use the timestamp FilePath base = findPullUpDirectory(expected); if(base!=null && base!=expected) base.moveAllChildrenTo(expected); // leave a record for the next up-to-date check expected.child(".installedFrom").write(inst.url,"UTF-8"); expected.act(new ZipExtractionInstaller.ChmodRecAPlusX()); } return expected; }
/** * Performs an installation. */ private int install(ToolInstallation t, BuildIDs id, AbstractProject p) throws IOException, InterruptedException { Run b = p.getBuildByNumber(Integer.parseInt(id.number)); if (b==null) throw new AbortException("No such build: "+id.number); Executor exec = b.getExecutor(); if (exec==null) throw new AbortException(b.getFullDisplayName()+" is not building"); Node node = exec.getOwner().getNode(); if (t instanceof NodeSpecific) { NodeSpecific n = (NodeSpecific) t; t = (ToolInstallation)n.forNode(node,new StreamTaskListener(stderr)); } if (t instanceof EnvironmentSpecific) { EnvironmentSpecific e = (EnvironmentSpecific) t; t = (ToolInstallation)e.forEnvironment(EnvVars.getRemote(channel)); } stdout.println(t.getHome()); return 0; }
/** * Performs an installation. */ private int install(ToolInstallation t, BuildIDs id, AbstractProject p) throws IOException, InterruptedException { Run b = p.getBuildByNumber(Integer.parseInt(id.number)); if (b==null) throw new AbortException("No such build: "+id.number); Executor exec = b.getExecutor(); if (exec==null) throw new AbortException(b.getFullDisplayName()+" is not building"); Node node = exec.getOwner().getNode(); if (t instanceof NodeSpecific) { NodeSpecific n = (NodeSpecific) t; t = (ToolInstallation)n.forNode(node,new StreamTaskListener(stderr)); } if (t instanceof EnvironmentSpecific) { EnvironmentSpecific e = (EnvironmentSpecific) t; t = (ToolInstallation)e.forEnvironment(EnvVars.getRemote(channel)); } stdout.println(t.getHome()); return 0; }
/** * Performs an installation. */ private int install(ToolInstallation t, BuildIDs id, AbstractProject p) throws IOException, InterruptedException { Run b = p.getBuildByNumber(Integer.parseInt(id.number)); if (b==null) throw new AbortException("No such build: "+id.number); Executor exec = b.getExecutor(); if (exec==null) throw new AbortException(b.getFullDisplayName()+" is not building"); Node node = exec.getOwner().getNode(); if (t instanceof NodeSpecific) { NodeSpecific n = (NodeSpecific) t; t = (ToolInstallation)n.forNode(node,new StreamTaskListener(stderr)); } if (t instanceof EnvironmentSpecific) { EnvironmentSpecific e = (EnvironmentSpecific) t; t = (ToolInstallation)e.forEnvironment(EnvVars.getRemote(channel)); } stdout.println(t.getHome()); return 0; }
/** * Performs an installation. */ private int install(ToolInstallation t, BuildIDs id, AbstractProject p) throws IOException, InterruptedException { Run b = p.getBuildByNumber(Integer.parseInt(id.number)); if (b == null) { throw new AbortException("No such build: " + id.number); } Executor exec = b.getExecutor(); if (exec == null) { throw new AbortException(b.getFullDisplayName() + " is not building"); } Node node = exec.getOwner().getNode(); if (t instanceof NodeSpecific) { NodeSpecific n = (NodeSpecific) t; t = (ToolInstallation) n.forNode(node, new StreamTaskListener(stderr)); } if (t instanceof EnvironmentSpecific) { EnvironmentSpecific e = (EnvironmentSpecific) t; t = (ToolInstallation) e.forEnvironment(EnvVars.getRemote(channel)); } stdout.println(t.getHome()); return 0; }
@Override protected String run() throws Exception { String name = step.getName(); String type = step.getType(); for (ToolDescriptor<?> desc : ToolInstallation.all()) { if (type != null && !desc.getId().equals(type) && !SymbolLookup.getSymbolValue(desc).contains(type)) { continue; } for (ToolInstallation tool : desc.getInstallations()) { if (tool.getName().equals(name)) { if (tool instanceof NodeSpecific) { tool = (ToolInstallation) ((NodeSpecific<?>) tool).forNode(getContext().get(Node.class), getContext().get(TaskListener.class)); } if (tool instanceof EnvironmentSpecific) { tool = (ToolInstallation) ((EnvironmentSpecific<?>) tool).forEnvironment(getContext().get(EnvVars.class)); } return tool.getHome(); } } } throw new AbortException("No " + (type != null ? type : "tool") + " named " + name + " found"); }
/** * Get the ZAP_HOME setup by Custom Tools Plugin or already present on the build's machine. * * @param build * @param listener * of type BuildListener: the display log listener during the Jenkins job execution. * @return of type String: the installed tool location, without zap.bat or zap.sh at the end. * @throws InterruptedException * @throws IOException * @see <a href= "https://groups.google.com/forum/#!topic/jenkinsci-dev/RludxaYjtDk"> https://groups.google.com/forum/#!topic/jenkinsci-dev/RludxaYjtDk </a> */ private String retrieveZapHomeWithToolInstall(AbstractBuild<?, ?> build, BuildListener listener) throws IOException, InterruptedException { EnvVars env = null; Node node = null; String installPath = null; if (autoInstall) { env = build.getEnvironment(listener); node = build.getBuiltOn(); for (ToolDescriptor<?> desc : ToolInstallation.all()) for (ToolInstallation tool : desc.getInstallations()) if (tool.getName().equals(this.toolUsed)) { if (tool instanceof NodeSpecific) tool = (ToolInstallation) ((NodeSpecific<?>) tool).forNode(node, listener); if (tool instanceof EnvironmentSpecific) tool = (ToolInstallation) ((EnvironmentSpecific<?>) tool).forEnvironment(env); installPath = tool.getHome(); return installPath; } } else installPath = build.getEnvironment(listener).get(this.zapHome); return installPath; }