/** * Reads the URL on the current VM, and streams the data to this file using the Remoting channel. * <p>This is different from resolving URL remotely. * If you instead wished to open an HTTP(S) URL on the remote side, * prefer <a href="http://javadoc.jenkins.io/plugin/apache-httpcomponents-client-4-api/io/jenkins/plugins/httpclient/RobustHTTPClient.html#copyFromRemotely-hudson.FilePath-java.net.URL-hudson.model.TaskListener-">{@code RobustHTTPClient.copyFromRemotely}</a>. * @since 1.293 */ public void copyFrom(URL url) throws IOException, InterruptedException { try (InputStream in = url.openStream()) { copyFrom(in); } }
private void placeDefaultRule(File f, InputStream src) throws IOException, InterruptedException { try { new FilePath(f).copyFrom(src); } catch (IOException e) { // we allow admins to create a read-only file here to block overwrite, // so this can fail legitimately if (!f.canWrite()) return; LOGGER.log(WARNING, "Failed to generate "+f,e); } }
@Override public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException { if (!StringUtils.isEmpty(location) && !StringUtils.isEmpty(file.getName())) { listener.getLogger().println("Copying file to "+location); FilePath ws = build.getWorkspace(); if (ws == null) { throw new IllegalStateException("The workspace should be created when setUp method is called"); } if (!ALLOW_FOLDER_TRAVERSAL_OUTSIDE_WORKSPACE && !ws.isDescendant(location)) { listener.error("Rejecting file path escaping base directory with relative path: " + location); // force the build to fail return null; } FilePath locationFilePath = ws.child(location); locationFilePath.getParent().mkdirs(); locationFilePath.copyFrom(file); locationFilePath.copyTo(new FilePath(getLocationUnderBuild(build))); } return new Environment() {}; } };
getTargetFilePath(n).copyFrom(u); if (dynamicLoad) pm.dynamicLoad(getTargetFile(n));
/** * Reads the URL on the current VM, and writes all the data to this {@link FilePath} * (this is different from resolving URL remotely.) * * @since 1.293 */ public void copyFrom(URL url) throws IOException, InterruptedException { try (InputStream in = url.openStream()) { copyFrom(in); } }
private void placeDefaultRule(File f, InputStream src) throws IOException, InterruptedException { try { new FilePath(f).copyFrom(src); } catch (IOException e) { // we allow admins to create a read-only file here to block overwrite, // so this can fail legitimately if (!f.canWrite()) return; LOGGER.log(WARNING, "Failed to generate "+f,e); } }
public String invoke(File f, VirtualChannel channel) throws IOException { File conf = new File(f, filename); FilePath urlConf = new FilePath(conf); try { urlConf.copyFrom(new ByteArrayInputStream(config.getBytes())); } catch (InterruptedException e) { throw new IOException("Failed to write configuration to " + filename, e); } return conf.getAbsolutePath(); } });
public String invoke(File f, VirtualChannel channel) throws IOException { File conf = new File(f, filename); FilePath urlConf = new FilePath(conf); try { urlConf.copyFrom(new URL(configURL)); } catch (InterruptedException e) { throw new IOException("Failed to retrieve configuration from " + configURL, e); } return conf.getAbsolutePath(); } });
protected String extractDefaultReportToWorkingDirectory(FilePath workingDirectory) throws IOException, InterruptedException { FilePath defaultConfig = workingDirectory.child(DEFAULT_CONFIG_FILE); defaultConfig.copyFrom(getClass().getResourceAsStream(DEFAULT_CONFIG_FILE)); return defaultConfig.getRemote(); }
@Override public void preOnline(Computer c, Channel channel,FilePath root, TaskListener listener) throws IOException, InterruptedException { PrintStream logger = listener.getLogger(); copyJar(logger, root, Main.class, "maven-agent"); copyJar(logger, root, Maven3Main.class, "maven3-agent"); copyJar(logger, root, Maven3Launcher.class, "maven3-interceptor"); copyJar(logger, root, AbortException.class, "maven-interceptor"); copyJar(logger, root, Maven21Interceptor.class, "maven2.1-interceptor"); copyJar(logger, root, ClassWorld.class, "plexus-classworld"); // copy classworlds 1.1 for maven2 builds root.child( "classworlds.jar" ).copyFrom(getClass().getClassLoader().getResource("classworlds.jar")); logger.println("Copied classworlds.jar"); }
@Override public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException { if (!StringUtils.isEmpty(location) && !StringUtils.isEmpty(file.getName())) { listener.getLogger().println("Copying file to "+location); FilePath locationFilePath = build.getWorkspace().child(location); locationFilePath.getParent().mkdirs(); locationFilePath.copyFrom(file); locationFilePath.copyTo(new FilePath(getLocationUnderBuild(build))); } return new Environment() {}; } };
public Map<String, String> saveDownloadedFile(InputStream is, String filePath) throws IOException { try { FilePath child = workspace.child(filePath); child.copyFrom(is); return child.act(new DownloadFileCallable(log)); } catch (InterruptedException e) { log.warn("Caught interrupted exception: " + e.getLocalizedMessage()); } finally { IOUtils.closeQuietly(is); } return null; }
@Override public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException { if (!StringUtils.isEmpty(file.getName())) { listener.getLogger().println("Copying file to "+location); FilePath locationFilePath = build.getWorkspace().child(location); locationFilePath.getParent().mkdirs(); locationFilePath.copyFrom(file); file = null; locationFilePath.copyTo(new FilePath(getLocationUnderBuild(build))); } return new Environment() {}; } };
@Override public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException { if (!StringUtils.isEmpty(file.getName())) { listener.getLogger().println("Copying file to "+location); FilePath locationFilePath = build.getWorkspace().child(location); locationFilePath.getParent().mkdirs(); locationFilePath.copyFrom(file); file = null; locationFilePath.copyTo(new FilePath(getLocationUnderBuild(build))); } return new Environment() {}; } };
private static List<PerformanceReportParser> getParserWithRelativePath(Run<?, ?> build, FilePath workspace, PrintStream logger, String glob, String percentiles) throws IOException, InterruptedException { List<PerformanceReportParser> result = getParserUsingAntPatternRelativePath(build, workspace, logger, glob, percentiles); if (result != null && !result.isEmpty()) { return result; } File report = new File(workspace.getRemote() + '/' + glob); if (!report.exists()) { // if report on remote slave FilePath localReport = new FilePath(new File(build.getRootDir(), "/temp/" + glob)); localReport.copyFrom(new FilePath(workspace, glob)); return Collections.singletonList(getParser(ParserDetector.detect(localReport.getRemote()), glob, percentiles)); } return Collections.singletonList(getParser(ParserDetector.detect(workspace.getRemote() + '/' + glob), workspace.getRemote() + '/' + glob, percentiles)); }
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { build.getWorkspace().child("junit.xml").copyFrom( getClass().getResource("junit-report-20090516.xml")); return true; } });
@Override @SuppressWarnings("null") public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { build.getWorkspace().child("junit.xml").copyFrom( getClass().getResource("/hudson/tasks/junit/junit-report-20090516.xml")); return true; } });
private FilePath copy(VirtualFile src, FilePath dst, TaskListener listener) throws IOException, InterruptedException { URL u = src.toExternalURL(); if (u != null) { new RobustHTTPClient().copyFromRemotely(dst, u, listener); } else { try (InputStream in = src.open()) { dst.copyFrom(in); } } return dst; }
@Override public boolean perform(AbstractBuild build, Launcher launcher, BuildListener buildListener) throws InterruptedException, IOException { build.getWorkspace().child(fileName).copyFrom(resourceClass.getResourceAsStream(resourceName)); return true; } });
private Object convert(String name, ParameterValue v) throws IOException, InterruptedException { if (v instanceof FileParameterValue) { FileParameterValue fv = (FileParameterValue) v; FilePath fp = new FilePath(run.getRootDir()).child(name); fp.copyFrom(fv.getFile()); return fp; } else { return v.getValue(); } }