/** * Returns a {@link FilePath} by adding the given suffix to this path name. */ public FilePath withSuffix(String suffix) { return new FilePath(channel,remote+suffix); }
@Override public FilePath createPath(String absolutePath) { return new FilePath((VirtualChannel)null,absolutePath); }
/** * The same as {@link FilePath#FilePath(FilePath,String)} but more OO. * @param relOrAbsolute a relative or absolute path * @return a file on the same channel */ public @Nonnull FilePath child(String relOrAbsolute) { return new FilePath(this,relOrAbsolute); }
@Override public FilePath[] invoke(File f, VirtualChannel channel) throws IOException { String[] files = glob(reading(f), includes, excludes, defaultExcludes); FilePath[] r = new FilePath[files.length]; for( int i=0; i<r.length; i++ ) r[i] = new FilePath(new File(f,files[i])); return r; } }
@Override public FilePath call() throws IOException { return new FilePath(new File(System.getProperty("user.home"))); } }
@Override public List<FilePath> invoke(File f, VirtualChannel channel) throws IOException { File[] children = reading(f).listFiles(filter); if (children == null) { return Collections.emptyList(); } ArrayList<FilePath> r = new ArrayList<FilePath>(children.length); for (File child : children) r.add(new FilePath(child)); return r; } }
/** * Gets the parent file. * @return parent FilePath or null if there is no parent */ public FilePath getParent() { int i = remote.length() - 2; for (; i >= 0; i--) { char ch = remote.charAt(i); if(ch=='\\' || ch=='/') break; } return i >= 0 ? new FilePath( channel, remote.substring(0,i+1) ) : null; }
public FilePath call() throws IOException { File home = new File(System.getProperty("user.home")); File hudsonHome = new File(home, ".hudson"); if (hudsonHome.exists()) { return new FilePath(new File(hudsonHome, "cli-credentials")); } return new FilePath(new File(home, ".jenkins/cli-credentials")); } }
@Override public FilePath call() throws IOException { final File hprof = File.createTempFile("hudson-heapdump", "hprof"); hprof.delete(); try { MBeanServer server = ManagementFactory.getPlatformMBeanServer(); server.invoke(new ObjectName("com.sun.management:type=HotSpotDiagnostic"), "dumpHeap", new Object[]{hprof.getAbsolutePath(), true}, new String[]{String.class.getName(), boolean.class.getName()}); return new FilePath(hprof); } catch (JMException e) { throw new IOException(e); } }
/** * Gets the {@link FilePath} on this node. */ public @CheckForNull FilePath createPath(String absolutePath) { VirtualChannel ch = getChannel(); if(ch==null) return null; // offline return new FilePath(ch,absolutePath); }
/** * Sets the current directory for the new JVM. * This overloaded version only makes sense when you are launching JVM locally. */ public JVMBuilder pwd(File pwd) { return pwd(new FilePath(pwd)); }
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); } }
private static FilePath getTargetFilePath(String name) { return new FilePath(getTargetFile(name)); }
@Override public @Nonnull FilePath getRootPath() { return new FilePath(getRootDir()); }
public ProcStarter pwd(@Nonnull File workDir) { return pwd(new FilePath(workDir)); }
public void restoreTo(AbstractBuild<?,?> owner, FilePath dst, TaskListener listener) throws IOException, InterruptedException { File zip = new File(owner.getRootDir(),"workspace.zip"); if (zip.exists()) {// we used to keep it in zip new FilePath(zip).unzip(dst); } else {// but since 1.456 we do tgz File tgz = new File(owner.getRootDir(),"workspace.tgz"); new FilePath(tgz).untar(dst, TarCompression.GZIP); } } }
@Override public void archive(FilePath workspace, Launcher launcher, BuildListener listener, final Map<String,String> artifacts) throws IOException, InterruptedException { File dir = getArtifactsDir(); String description = "transfer of " + artifacts.size() + " files"; // TODO improve when just one file workspace.copyRecursiveTo(new FilePath.ExplicitlySpecifiedDirScanner(artifacts), new FilePath(dir), description); }
/** * Absolutizes this {@link FilePath} and returns the new one. */ public FilePath absolutize() throws IOException, InterruptedException { return new FilePath(channel, act(new Absolutize())); } private static class Absolutize extends SecureFileCallable<String> {
public FilePath getWorkspaceFor(TopLevelItem item) { for (WorkspaceLocator l : WorkspaceLocator.all()) { FilePath workspace = l.locate(item, this); if (workspace != null) { return workspace; } } return new FilePath(expandVariablesForDirectory(workspaceDir, item)); }