📄 findbugstask.java
字号:
String[] elementList = src.list(); for (String anElementList : elementList) { if (!anElementList.equals("")) { nonEmpty = true; break; } } if (nonEmpty) { if (auxAnalyzepath == null) { auxAnalyzepath = src; } else { auxAnalyzepath.append(src); } } } /** * Path to use for auxAnalyzepath. */ public Path createAuxAnalyzepath() { if (auxAnalyzepath == null) { auxAnalyzepath = new Path(getProject()); } return auxAnalyzepath.createPath(); } /** * Adds a reference to a sourcepath defined elsewhere. */ public void setAuxAnalyzepathRef(Reference r) { createAuxAnalyzepath().setRefid(r); } /** * the sourcepath to use. */ public void setSourcePath(Path src) { if (sourcePath == null) { sourcePath = src; } else { sourcePath.append(src); } } /** * Path to use for sourcepath. */ public Path createSourcePath() { if (sourcePath == null) { sourcePath = new Path(getProject()); } return sourcePath.createPath(); } /** * Adds a reference to a source path defined elsewhere. */ public void setSourcePathRef(Reference r) { createSourcePath().setRefid(r); } /** * Add a class location */ public ClassLocation createClass() { ClassLocation cl = new ClassLocation(); classLocations.add( cl ); return cl; } /** * Set name of output file. */ public void setOutputFile(String outputFileName) { if (outputFileName != null && outputFileName.length() > 0) this.outputFileName = outputFileName; } /** * Set the packages or classes to analyze */ public void setOnlyAnalyze(String filter) { this.onlyAnalyze = filter; } /** * Set timeout in milliseconds. * @param timeout the timeout */ public void setTimeout(long timeout) { this.timeout = timeout; } @Override public void execute() throws BuildException { checkParameters(); try { execFindbugs(); } catch (BuildException e) { if (errorProperty != null) { getProject().setProperty(errorProperty, "true"); } if (failOnError) { throw e; } } } /** * the classpath to use. */ public void setClasspath(Path src) { if (classpath == null) { classpath = src; } else { classpath.append(src); } } /** * Path to use for classpath. */ public Path createClasspath() { if (classpath == null) { classpath = new Path(getProject()); } return classpath.createPath(); } /** * Adds a reference to a classpath defined elsewhere. */ public void setClasspathRef(Reference r) { createClasspath().setRefid(r); } /** * the plugin list to use. */ public void setPluginList(Path src) { if (pluginList == null) { pluginList = src; } else { pluginList.append(src); } } /** * Path to use for plugin list. */ public Path createPluginList() { if (pluginList == null) { pluginList = new Path(getProject()); } return pluginList.createPath(); } /** * Adds a reference to a plugin list defined elsewhere. */ public void setPluginListRef(Reference r) { createPluginList().setRefid(r); } /** * Create a SystemProperty (to handle <systemProperty> elements). */ public SystemProperty createSystemProperty() { SystemProperty systemProperty = new SystemProperty(); systemPropertyList.add(systemProperty); return systemProperty; } /** * Check that all required attributes have been set * * @since Ant 1.5 */ private void checkParameters() { if ( homeDir == null && (classpath == null || pluginList == null) ) { throw new BuildException( "either home attribute or " + "classpath and pluginList attributes " + " must be defined for task <" + getTaskName() + "/>", getLocation() ); } if (pluginList != null) { // Make sure that all plugins are actually Jar files. String[] pluginFileList = pluginList.list(); for (String pluginFile : pluginFileList) { if (!pluginFile.endsWith(".jar")) { throw new BuildException("plugin file " + pluginFile + " is not a Jar file " + "in task <" + getTaskName() + "/>", getLocation()); } } } if ( projectFile == null && classLocations.size() == 0 && auxAnalyzepath == null) { throw new BuildException( "either projectfile, <class/> or <auxAnalyzepath/> child " + "elements must be defined for task <" + getTaskName() + "/>", getLocation() ); } if ( outputFormat != null && !( outputFormat.trim().equalsIgnoreCase("xml" ) || outputFormat.trim().equalsIgnoreCase("xml:withMessages" ) || outputFormat.trim().equalsIgnoreCase("html" ) || outputFormat.trim().equalsIgnoreCase("text" ) || outputFormat.trim().equalsIgnoreCase("xdocs" ) || outputFormat.trim().equalsIgnoreCase("emacs") ) ) { throw new BuildException( "output attribute must be either " + "'text', 'xml', 'html', 'xdocs' or 'emacs' for task <" + getTaskName() + "/>", getLocation() ); } if ( reportLevel != null && !( reportLevel.trim().equalsIgnoreCase("experimental" ) || reportLevel.trim().equalsIgnoreCase("low" ) || reportLevel.trim().equalsIgnoreCase("medium" ) || reportLevel.trim().equalsIgnoreCase("high" ) ) ) { throw new BuildException( "reportlevel attribute must be either " + "'experimental' or 'low' or 'medium' or 'high' for task <" + getTaskName() + "/>", getLocation() ); } if ( excludeFile != null && includeFile != null ) { throw new BuildException("only one of excludeFile and includeFile " + " attributes may be used in task <" + getTaskName() + "/>", getLocation()); } for (SystemProperty aSystemPropertyList : systemPropertyList) { SystemProperty systemProperty = (SystemProperty) aSystemPropertyList; if (systemProperty.getName() == null || systemProperty.getValue() == null) throw new BuildException("systemProperty elements must have name and value attributes"); } if (effort != null && !effort.equals("min") && !effort.equals("default") && !effort.equals("max")) { throw new BuildException("effort attribute must be one of 'min', 'default', or 'max'"); } } /** * Add an argument to the JVM used to execute FindBugs. * @param arg the argument */ private void addArg(String arg) { findbugsEngine.createArg().setValue(arg); } /** * Create a new JVM to do the work. * * @since Ant 1.5 */ private void execFindbugs() throws BuildException { findbugsEngine = (Java) getProject().createTask("java"); findbugsEngine.setTaskName( getTaskName() ); findbugsEngine.setFork( true ); if (jvm.length()>0) findbugsEngine.setJvm( jvm ); findbugsEngine.setTimeout( timeout ); if ( debug ) jvmargs = jvmargs + " -Dfindbugs.debug=true"; findbugsEngine.createJvmarg().setLine( jvmargs ); // Add JVM arguments for system properties for (SystemProperty aSystemPropertyList : systemPropertyList) { SystemProperty systemProperty = (SystemProperty) aSystemPropertyList; String jvmArg = "-D" + systemProperty.getName() + "=" + systemProperty.getValue(); findbugsEngine.createJvmarg().setValue(jvmArg); } if (homeDir != null) { // Use findbugs.home to locate findbugs.jar and the standard // plugins. This is the usual means of initialization. findbugsEngine.setJar( new File( homeDir + File.separator + "lib" + File.separator + FINDBUGS_JAR ) ); addArg("-home"); addArg(homeDir.getPath()); } else { // Use an explicitly specified classpath and list of plugin Jars // to initialize. This is useful for other tools which may have // FindBugs installed using a non-standard directory layout. findbugsEngine.setClasspath(classpath); findbugsEngine.setClassname("edu.umd.cs.findbugs.FindBugs2"); addArg("-pluginList"); addArg(pluginList.toString()); } if (projectName != null) { addArg("-projectName"); addArg(projectName); } if (adjustExperimental) { addArg("-adjustExperimental"); } if ( conserveSpace ) { addArg("-conserveSpace"); } if ( workHard ){ addArg("-workHard"); } if ( effort != null ) { addArg("-effort:" + effort); } if ( sorted ) addArg("-sortByClass"); if ( timestampNow ) addArg("-timestampNow"); if ( outputFormat != null && !outputFormat.trim().equalsIgnoreCase("text") ) { outputFormat = outputFormat.trim(); String outputArg = "-"; int colon = outputFormat.indexOf(':'); if (colon >= 0) { outputArg += outputFormat.substring(0, colon).toLowerCase(); outputArg += ":"; outputArg += outputFormat.substring(colon + 1); } else { outputArg += outputFormat.toLowerCase(); if (stylesheet != null) { outputArg += ":"; outputArg += stylesheet.trim(); } } addArg(outputArg); } if ( quietErrors ) addArg("-quiet"); if ( reportLevel != null ) addArg("-" + reportLevel.trim().toLowerCase()); if ( projectFile != null ) { addArg("-project"); addArg(projectFile.getPath()); } if ( excludeFile != null ) { addArg("-exclude"); addArg(excludeFile.getPath()); } if ( includeFile != null) { addArg("-include"); addArg(includeFile.getPath()); } if ( visitors != null) { addArg("-visitors"); addArg(visitors); } if ( omitVisitors != null ) { addArg("-omitVisitors"); addArg(omitVisitors); } if ( auxClasspath != null ) { addArg("-auxclasspath"); addArg(auxClasspath.toString()); } if ( sourcePath != null) { addArg("-sourcepath"); addArg(sourcePath.toString()); } if ( outputFileName != null ) { addArg("-outputFile"); addArg(outputFileName); } if ( relaxed ) { addArg("-relaxed"); } if ( onlyAnalyze != null ) { addArg("-onlyAnalyze"); addArg(onlyAnalyze); } addArg("-exitcode"); for (ClassLocation classLocation : classLocations) { addArg(classLocation.toString()); } if (auxAnalyzepath != null) { String[] result = auxAnalyzepath.toString().split(java.io.File.pathSeparator); for (int x=0; x<result.length; x++) { addArg(result[x]); } } log("Running FindBugs..."); if (debug) { log(findbugsEngine.getCommandLine().describeCommand()); } int rc = findbugsEngine.executeJava(); if ((rc & ExitCodes.ERROR_FLAG) != 0) { throw new BuildException("Execution of findbugs failed."); } if ((rc & ExitCodes.MISSING_CLASS_FLAG) != 0) { log("Classes needed for analysis were missing"); } if (warningsProperty != null && (rc & ExitCodes.BUGS_FOUND_FLAG) != 0) { getProject().setProperty(warningsProperty, "true"); } if (outputFileName != null) { log("Output saved to " + outputFileName); } } }// vim:ts=4
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -