⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 findbugstask.java

📁 一个查找java程序里bug的程序的源代码,该程序本身也是java写的,对提高java编程水平很有用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	 */	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) {		this.outputFileName = outputFileName;	}	/**	 * Set timeout in milliseconds.	 * @param timeout the timeout	 */	public void setTimeout(long timeout) {		this.timeout = timeout;	}	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 &lt;systemProperty&gt; 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 (int i = 0; i < pluginFileList.length; ++i) {				String pluginFile = pluginFileList[i];				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 ) {			throw new BuildException( "either projectfile or <class/> 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 (Iterator i = systemPropertyList.iterator(); i.hasNext(); ) {			SystemProperty systemProperty = (SystemProperty) i.next();			if (systemProperty.getName() == null || systemProperty.getValue() == null)				throw new BuildException("systemProperty elements must have name and value attributes");		}    } 	/**	 * 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 );		findbugsEngine.setTimeout( new Long( timeout ) );		if ( workHard ){			jvmargs = jvmargs + " -Dfindbugs.workHard=true";		}		if ( debug )			jvmargs = jvmargs + " -Dfindbugs.debug=true";		if ( conserveSpace )			jvmargs = jvmargs + " -Dfindbugs.conserveSpace=true";		findbugsEngine.createJvmarg().setLine( jvmargs ); 		// Add JVM arguments for system properties		for (Iterator i = systemPropertyList.iterator(); i.hasNext(); ) {			SystemProperty systemProperty = (SystemProperty) i.next();			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.FindBugs");			addArg("-pluginList");			addArg(pluginList.toString());		}				if (adjustExperimental) {			addArg("-adjustExperimental");		}		if ( sorted ) addArg("-sortByClass");		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);		}        		addArg("-exitcode");        Iterator itr = classLocations.iterator();        while ( itr.hasNext() ) {			addArg(itr.next().toString());      	} 		log("Running FindBugs...");		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 (outputFileName != null) {			log("Output saved to " + outputFileName);		}    } }// vim:ts=4

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -