| 1 19 20 package edu.umd.cs.findbugs.anttask; 21 22 23 import edu.umd.cs.findbugs.ExitCodes; 24 import java.io.File ; 25 import org.apache.tools.ant.BuildException; 26 import org.apache.tools.ant.Task; 27 import org.apache.tools.ant.taskdefs.Ant.Reference; 28 import org.apache.tools.ant.taskdefs.Java; 29 import org.apache.tools.ant.types.Path; 30 31 77 public class FindBugsViewerTask extends Task { 78 79 private static final String FINDBUGSGUI_JAR = "findbugsGUI.jar"; 80 private static final long DEFAULT_TIMEOUT = -1; 82 private boolean debug = false; 84 private File projectFile = null; 85 private File loadbugs = null; 86 private long timeout = DEFAULT_TIMEOUT; 87 private String jvmargs = ""; 88 private String look = "native"; 89 private File homeDir = null; 90 private Path classpath = null; 91 private Path pluginList = null; 92 93 private Java findbugsEngine = null; 94 95 96 public FindBugsViewerTask() { 97 } 98 99 104 public void setLoadbugs(File loadbugs) { 105 this.loadbugs = loadbugs; 106 } 107 108 111 public void setProjectFile(File projectFile) { 112 this.projectFile = projectFile; 113 } 114 115 118 public void setDebug(boolean flag) { 119 this.debug = flag; 120 } 121 122 125 public void setJvmargs(String args) { 126 this.jvmargs = args; 127 } 128 129 132 public void setLook(String look) { 133 this.look = look; 134 } 135 136 137 140 public void setHome(File homeDir) { 141 this.homeDir = homeDir; 142 } 143 144 145 148 public Path createClasspath() { 149 if (classpath == null) { 150 classpath = new Path(getProject()); 151 } 152 return classpath.createPath(); 153 } 154 155 158 public void setClasspathRef(Reference r) { 159 createClasspath().setRefid(r); 160 } 161 162 163 166 public void setPluginList(Path src) { 167 if (pluginList == null) { 168 pluginList = src; 169 } 170 else { 171 pluginList.append(src); 172 } 173 } 174 175 178 public Path createPluginList() { 179 if (pluginList == null) { 180 pluginList = new Path(getProject()); 181 } 182 return pluginList.createPath(); 183 } 184 185 188 public void setPluginListRef(Reference r) { 189 createPluginList().setRefid(r); 190 } 191 192 197 public void setTimeout(long timeout) { 198 this.timeout = timeout; 199 } 200 201 205 private void addArg(String arg) { 206 findbugsEngine.createArg().setValue(arg); 207 } 208 209 @Override  210 public void execute() throws BuildException { 211 findbugsEngine = (Java)getProject().createTask("java"); 212 213 findbugsEngine.setTaskName(getTaskName()); 214 findbugsEngine.setFork(true); 215 216 if (timeout > 0) { 217 findbugsEngine.setTimeout(timeout); 218 } 219 220 221 if (debug) { 222 jvmargs = jvmargs + " -Dfindbugs.debug=true"; 223 } 224 findbugsEngine.createJvmarg().setLine(jvmargs); 225 226 if (homeDir != null) { 227 230 findbugsEngine.setJar( new File ( homeDir + File.separator + "lib" + 231 File.separator + FINDBUGSGUI_JAR ) ); 232 233 addArg("-home"); 234 addArg(homeDir.getPath()); 235 } 236 else { 237 241 findbugsEngine.setClasspath(classpath); 242 findbugsEngine.setClassname("edu.umd.cs.findbugs.FindBugsFrame"); 243 244 addArg("-pluginList"); 245 addArg(pluginList.toString()); 246 } 247 248 if (projectFile != null) { 249 addArg("-project"); 250 addArg(projectFile.getPath()); 251 } 252 253 if (loadbugs != null) { 254 addArg("-loadbugs"); 255 addArg(loadbugs.getPath()); 256 } 257 258 if (look != null) { 259 addArg("-look:" + look); 260 } 263 264 265 267 log("Launching FindBugs Viewer..."); 268 269 int rc = findbugsEngine.executeJava(); 270 271 if ((rc & ExitCodes.ERROR_FLAG) != 0) { 272 throw new BuildException("Execution of findbugs failed."); 273 } 274 if ((rc & ExitCodes.MISSING_CLASS_FLAG) != 0) { 275 log("Classes needed for analysis were missing"); 276 } 277 } 278 279 } 280 | Popular Tags |