diff --git a/core/src/main/java/hudson/FilePath.java b/core/src/main/java/hudson/FilePath.java index 564bb2763d..5b5569036d 100644 --- a/core/src/main/java/hudson/FilePath.java +++ b/core/src/main/java/hudson/FilePath.java @@ -25,6 +25,7 @@ import org.apache.tools.tar.TarOutputStream; import org.apache.tools.zip.ZipOutputStream; import org.apache.tools.zip.ZipEntry; import org.apache.commons.io.IOUtils; +import org.apache.commons.fileupload.FileItem; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -326,6 +327,30 @@ public final class FilePath implements Serializable { }); } + /** + * Place the data from {@link FileItem} into the file location specified by this {@link FilePath} object. + */ + public void copyFrom(FileItem file) throws IOException, InterruptedException { + if(channel==null) { + try { + file.write(new File(remote)); + } catch (IOException e) { + throw e; + } catch (Exception e) { + throw new IOException2(e); + } + } else { + InputStream i = file.getInputStream(); + OutputStream o = write(); + try { + IOUtils.copy(i,o); + } finally { + o.close(); + i.close(); + } + } + } + /** * Code that gets executed on the machine where the {@link FilePath} is local. * Used to act on {@link FilePath}. diff --git a/core/src/main/java/hudson/FileSystemProvisioner.java b/core/src/main/java/hudson/FileSystemProvisioner.java index b8dfdc72cb..8991a20a41 100644 --- a/core/src/main/java/hudson/FileSystemProvisioner.java +++ b/core/src/main/java/hudson/FileSystemProvisioner.java @@ -7,6 +7,7 @@ import hudson.model.Computer; import hudson.model.Describable; import hudson.model.Job; import hudson.model.TaskListener; +import hudson.model.listeners.RunListener; import hudson.util.DescriptorList; import java.io.BufferedOutputStream; @@ -63,7 +64,8 @@ import java.io.OutputStream; * the retention policy. * * Can't the 2nd step happen automatically, when someone else depends on - * the workspace snapshot of the upstream? + * the workspace snapshot of the upstream? Yes, by using {@link RunListener}. + * So this becomes like a special SCM type. * * To support promoted builds, we need an abstraction for permalinks. * This is also needed for other UI. @@ -127,12 +129,18 @@ public abstract class FileSystemProvisioner implements ExtensionPoint, Describab */ public static final DescriptorList LIST = new DescriptorList(); + /** + * Default implementation. + */ + public static final FileSystemProvisioner DEFAULT = new Default(); /** * Default implementation that doesn't rely on any file system specific capability, * and thus can be used anywhere that Hudson runs. */ public static final class Default extends FileSystemProvisioner { + private Default() {} + public void prepareWorkspace(AbstractBuild build, FilePath ws, TaskListener listener) throws IOException, InterruptedException { ws.mkdirs(); } diff --git a/core/src/main/java/hudson/FileSystemProvisionerDescriptor.java b/core/src/main/java/hudson/FileSystemProvisionerDescriptor.java index f23926d479..04f71f32e3 100644 --- a/core/src/main/java/hudson/FileSystemProvisionerDescriptor.java +++ b/core/src/main/java/hudson/FileSystemProvisionerDescriptor.java @@ -31,7 +31,7 @@ public abstract class FileSystemProvisionerDescriptor extends Descriptor * This method is called to do this, after Hudson determines that the workspace should be deleted * to reclaim disk space. The implementation of this method is expected to sniff the contents of - * the workspace, and if it looks like the one created by {@link FileSystemProvisioner#prepareWorkspace(AbstractBuild, TaskListener)}, + * the workspace, and if it looks like the one created by {@link FileSystemProvisioner#prepareWorkspace(AbstractBuild, FilePath, TaskListener)}, * perform the necessary deletion operation, and return true. * *