1 18 19 package org.apache.tools.ant.taskdefs.optional.dotnet; 20 21 import org.apache.tools.ant.taskdefs.MatchingTask; 22 import org.apache.tools.ant.taskdefs.condition.Os; 23 import org.apache.tools.ant.types.FileSet; 24 import org.apache.tools.ant.Project; 25 import org.apache.tools.ant.DirectoryScanner; 26 27 import java.io.File ; 28 import java.util.Vector ; 29 import java.util.Hashtable ; 30 import java.util.Enumeration ; 31 32 36 public class DotnetBaseMatchingTask extends MatchingTask { 37 41 protected File outputFile; 42 45 protected Vector filesets = new Vector (); 46 47 50 protected File srcDir; 51 52 57 protected static final boolean isWindows = Os.isFamily("windows"); 59 60 63 67 public File getSrcDir() { 68 return this.srcDir; 69 } 70 71 76 public void setSrcDir(File srcDirName) { 77 this.srcDir = srcDirName; 78 } 79 80 85 public void setDestFile(File file) { 86 outputFile = file; 87 } 88 89 93 public void addSrc(FileSet src) { 94 filesets.add(src); 95 } 96 97 101 public File getDestFile() { 102 return outputFile; 103 } 104 105 112 protected int buildFileList(NetCommand command, Hashtable filesToBuild, long outputTimestamp) { 113 int filesOutOfDate = 0; 114 boolean scanImplicitFileset 115 = getSrcDir() != null || filesets.size() == 0; 116 if (scanImplicitFileset) { 117 if (getSrcDir() == null) { 120 setSrcDir(getProject().resolveFile(".")); 122 } 123 log("working from source directory " + getSrcDir(), 124 Project.MSG_VERBOSE); 125 DirectoryScanner scanner = getDirectoryScanner(getSrcDir()); 127 filesOutOfDate = command.scanOneFileset(scanner, 128 filesToBuild, outputTimestamp); 129 } 130 for (int i = 0; i < filesets.size(); i++) { 132 FileSet fs = (FileSet) filesets.elementAt(i); 133 filesOutOfDate += command.scanOneFileset( 134 fs.getDirectoryScanner(getProject()), 135 filesToBuild, 136 outputTimestamp); 137 } 138 139 return filesOutOfDate; 140 } 141 142 147 protected void addFilesToCommand(Hashtable filesToBuild, NetCommand command) { 148 int count = filesToBuild.size(); 149 log("compiling " + count + " file" + ((count == 1) ? "" : "s"), 150 Project.MSG_VERBOSE); 151 Enumeration files = filesToBuild.elements(); 152 while (files.hasMoreElements()) { 153 File file = (File ) files.nextElement(); 154 command.addArgument(file.toString()); 155 } 156 } 157 158 162 protected long getOutputFileTimestamp() { 163 long outputTimestamp; 164 if (getDestFile() != null && getDestFile().exists()) { 165 outputTimestamp = getDestFile().lastModified(); 166 } else { 167 outputTimestamp = 0; 168 } 169 return outputTimestamp; 170 } 171 172 177 protected void addFilesAndExecute(NetCommand command, boolean ignoreTimestamps) { 178 long outputTimestamp = getOutputFileTimestamp(); 179 Hashtable filesToBuild = new Hashtable (); 180 int filesOutOfDate = buildFileList(command, filesToBuild, outputTimestamp); 181 182 if (filesOutOfDate > 0) { 184 addFilesToCommand(filesToBuild, command); 186 command.runCommand(); 187 } else { 188 log("output file is up to date", Project.MSG_VERBOSE); 189 } 190 } 191 192 193 194 } 195 | Popular Tags |