1 18 package org.apache.tools.ant.taskdefs; 19 20 import java.io.File ; 21 import org.apache.tools.ant.BuildException; 22 import org.apache.tools.ant.Task; 23 import org.apache.tools.ant.util.FileUtils; 24 25 41 42 public class TempFile extends Task { 43 44 private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); 45 46 49 private String property; 50 51 54 private File destDir = null; 55 56 59 private String prefix; 60 61 64 private String suffix = ""; 65 66 67 private boolean deleteOnExit; 68 69 75 public void setProperty(String property) { 76 this.property = property; 77 } 78 79 80 86 public void setDestDir(File destDir) { 87 this.destDir = destDir; 88 } 89 90 91 96 public void setPrefix(String prefix) { 97 this.prefix = prefix; 98 } 99 100 101 106 public void setSuffix(String suffix) { 107 this.suffix = suffix; 108 } 109 110 115 public void setDeleteOnExit(boolean deleteOnExit) { 116 this.deleteOnExit = deleteOnExit; 117 } 118 119 123 public boolean isDeleteOnExit() { 124 return deleteOnExit; 125 } 126 127 132 public void execute() throws BuildException { 133 if (property == null || property.length() == 0) { 134 throw new BuildException("no property specified"); 135 } 136 if (destDir == null) { 137 destDir = getProject().resolveFile("."); 138 } 139 File tfile = FILE_UTILS.createTempFile( 140 prefix, suffix, destDir, deleteOnExit); 141 142 getProject().setNewProperty(property, tfile.toString()); 143 } 144 } 145 | Popular Tags |