1 18 19 package org.apache.tools.ant.taskdefs.optional.ccm; 20 21 22 import java.io.File ; 23 import java.util.Vector ; 24 import org.apache.tools.ant.BuildException; 25 import org.apache.tools.ant.DirectoryScanner; 26 import org.apache.tools.ant.Project; 27 import org.apache.tools.ant.taskdefs.Execute; 28 import org.apache.tools.ant.types.Commandline; 29 import org.apache.tools.ant.types.FileSet; 30 31 32 36 public class CCMCheck extends Continuus { 37 38 private File file = null; 39 private String comment = null; 40 private String task = null; 41 42 44 protected Vector filesets = new Vector (); 45 46 48 49 public CCMCheck() { 50 super(); 51 } 52 53 57 public File getFile() { 58 return file; 59 } 60 61 65 public void setFile(File v) { 66 log("working file " + v, Project.MSG_VERBOSE); 67 this.file = v; 68 } 69 70 74 public String getComment() { 75 return comment; 76 } 77 78 82 public void setComment(String v) { 83 this.comment = v; 84 } 85 86 87 91 public String getTask() { 92 return task; 93 } 94 95 100 public void setTask(String v) { 101 this.task = v; 102 } 103 104 105 109 public void addFileset(FileSet set) { 110 filesets.addElement(set); 111 } 112 113 114 122 public void execute() throws BuildException { 123 124 if (file == null && filesets.size() == 0) { 125 throw new BuildException( 126 "Specify at least one source - a file or a fileset."); 127 } 128 129 if (file != null && file.exists() && file.isDirectory()) { 130 throw new BuildException("CCMCheck cannot be generated for directories"); 131 } 132 133 if (file != null && filesets.size() > 0) { 134 throw new BuildException("Choose between file and fileset !"); 135 } 136 137 if (getFile() != null) { 138 doit(); 139 return; 140 } 141 142 int sizeofFileSet = filesets.size(); 143 for (int i = 0; i < sizeofFileSet; i++) { 144 FileSet fs = (FileSet) filesets.elementAt(i); 145 DirectoryScanner ds = fs.getDirectoryScanner(getProject()); 146 String [] srcFiles = ds.getIncludedFiles(); 147 for (int j = 0; j < srcFiles.length; j++) { 148 File src = new File (fs.getDir(getProject()), srcFiles[j]); 149 setFile(src); 150 doit(); 151 } 152 } 153 } 154 155 158 private void doit() { 159 Commandline commandLine = new Commandline(); 160 161 165 commandLine.setExecutable(getCcmCommand()); 166 commandLine.createArgument().setValue(getCcmAction()); 167 168 checkOptions(commandLine); 169 170 int result = run(commandLine); 171 if (Execute.isFailure(result)) { 172 String msg = "Failed executing: " + commandLine.toString(); 173 throw new BuildException(msg, getLocation()); 174 } 175 } 176 177 178 181 private void checkOptions(Commandline cmd) { 182 if (getComment() != null) { 183 cmd.createArgument().setValue(FLAG_COMMENT); 184 cmd.createArgument().setValue(getComment()); 185 } 186 187 if (getTask() != null) { 188 cmd.createArgument().setValue(FLAG_TASK); 189 cmd.createArgument().setValue(getTask()); 190 } 191 192 if (getFile() != null) { 193 cmd.createArgument().setValue(file.getAbsolutePath()); 194 } 195 } 196 197 200 public static final String FLAG_COMMENT = "/comment"; 201 202 205 public static final String FLAG_TASK = "/task"; 206 } 207 208 | Popular Tags |