📄 textuicommandline.java
字号:
/* * FindBugs - Find Bugs in Java programs * Copyright (C) 2003-2006, University of Maryland * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package edu.umd.cs.findbugs;import java.io.BufferedOutputStream;import java.io.BufferedReader;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStreamReader;import java.io.PrintStream;import java.util.Iterator;import java.util.Set;import java.util.StringTokenizer;import edu.umd.cs.findbugs.annotations.SuppressWarnings;import edu.umd.cs.findbugs.config.UserPreferences;import edu.umd.cs.findbugs.filter.FilterException;import edu.umd.cs.findbugs.util.Util;/** * Helper class to parse the command line and configure * the IFindBugsEngine object. * As a side-effect it also configures a DetectorFactoryCollection * (to enable and disable detectors as requested). */public class TextUICommandLine extends FindBugsCommandLine { /** * Handling callback for choose() method, * used to implement the -chooseVisitors and -choosePlugins options. */ private interface Chooser { /** * Choose a detector, plugin, etc. * * @param enable whether or not the item should be enabled * @param what the item */ public void choose(boolean enable, String what); } private static final int PRINTING_REPORTER = 0; private static final int SORTING_REPORTER = 1; private static final int XML_REPORTER = 2; private static final int EMACS_REPORTER = 3; private static final int HTML_REPORTER = 4; private static final int XDOCS_REPORTER = 5; private int bugReporterType = PRINTING_REPORTER; private boolean relaxedReportingMode = false; private boolean useLongBugCodes = false; private boolean xmlWithMessages = false; private boolean xmlWithAbridgedMessages = false; private String stylesheet = null; private boolean quiet = false; private ClassScreener classScreener = new ClassScreener(); private String includeFilterFile = null; private String excludeFilterFile = null; private boolean setExitCode = false; private int priorityThreshold = Detector.NORMAL_PRIORITY; private PrintStream outputStream = null; private Set<String> bugCategorySet = null; private UserPreferences userPreferences; private String trainingOutputDir; private String trainingInputDir; private String releaseName = ""; private String projectName=""; private String sourceInfoFile = null; private boolean xargs = false; private boolean scanNestedArchives = false; /** * Constructor. */ public TextUICommandLine() { addSwitch("-showPlugins", "show list of available plugins"); addSwitch("-timestampNow", "set timestamp of results to be current time"); addSwitch("-quiet", "suppress error messages"); addSwitch("-longBugCodes", "report long bug codes"); addOption("-release", "release name", "set the release name of the analyzed application"); addSwitch("-experimental", "report all warnings including experimental bug patterns"); addSwitch("-low", "report all warnings"); addSwitch("-medium", "report only medium and high priority warnings [default]"); addSwitch("-high", "report only high priority warnings"); addSwitch("-sortByClass", "sort warnings by class"); addSwitchWithOptionalExtraPart("-xml", "withMessages", "XML output (optionally with messages)"); addSwitch("-xdocs", "xdoc XML output to use with Apache Maven"); addSwitchWithOptionalExtraPart("-html", "stylesheet", "Generate HTML output (default stylesheet is default.xsl)"); addSwitch("-emacs", "Use emacs reporting format"); addSwitch("-relaxed", "Relaxed reporting mode (more false positives!)"); addSwitchWithOptionalExtraPart("-train", "outputDir", "Save training data (experimental); output dir defaults to '.'"); addSwitchWithOptionalExtraPart("-useTraining", "inputDir", "Use training data (experimental); input dir defaults to '.'"); addOption("-sourceInfo", "filename", "Specify source info file (line numbers for fields/classes)"); addOption("-projectName", "project name", "Descriptive name of project"); addOption("-outputFile", "filename", "Save output in named file"); addOption("-visitors", "v1[,v2...]", "run only named visitors"); addOption("-omitVisitors", "v1[,v2...]", "omit named visitors"); addOption("-chooseVisitors", "+v1,-v2,...", "selectively enable/disable detectors"); addOption("-choosePlugins", "+p1,-p2,...", "selectively enable/disable plugins"); addOption("-adjustPriority", "v1=(raise|lower)[,...]", "raise/lower priority of warnings for given visitor(s)"); addOption("-bugCategories", "cat1[,cat2...]", "only report bugs in given categories"); addOption("-onlyAnalyze", "classes/packages", "only analyze given classes and packages"); addOption("-exclude", "filter file", "exclude bugs matching given filter"); addOption("-include", "filter file", "include only bugs matching given filter"); addSwitchWithOptionalExtraPart("-nested", "true|false", "analyze nested jar/zip archives (default=true)"); addOption("-auxclasspath", "classpath", "set aux classpath for analysis"); addOption("-sourcepath", "source path", "set source path for analyzed classes"); addSwitch("-exitcode", "set exit code of process"); addSwitch("-xargs", "get list of classfiles/jarfiles from standard input rather than command line"); } @Override public Project getProject() { return project; } public boolean getXargs() { return xargs; } public boolean setExitCode() { return setExitCode; } public boolean quiet() { return quiet; } @SuppressWarnings("DM_EXIT") @Override protected void handleOption(String option, String optionExtraPart) { if (option.equals("-showPlugins")) { System.out.println("Available plugins:"); int count = 0; for (Iterator<Plugin> i = DetectorFactoryCollection.instance().pluginIterator(); i.hasNext(); ) { Plugin plugin = i.next(); System.out.println(" " + plugin.getPluginId() + " (default: " + (plugin.isEnabled() ? "enabled" : "disabled") + ")"); if (plugin.getShortDescription() != null) System.out.println(" Description: " + plugin.getShortDescription()); if (plugin.getProvider() != null) System.out.println(" Provider: " + plugin.getProvider()); if (plugin.getWebsite() != null) System.out.println(" Website: " + plugin.getWebsite()); ++count; } if (count == 0) { System.out.println(" No plugins are available (FindBugs installed incorrectly?)"); } System.exit(0); } else if (option.equals("-experimental")) priorityThreshold = Detector.EXP_PRIORITY; else if (option.equals("-longBugCodes")) useLongBugCodes = true; else if (option.equals("-timestampNow")) project.setTimestamp(System.currentTimeMillis()); else if (option.equals("-low")) priorityThreshold = Detector.LOW_PRIORITY; else if (option.equals("-medium")) priorityThreshold = Detector.NORMAL_PRIORITY; else if (option.equals("-high")) priorityThreshold = Detector.HIGH_PRIORITY; else if (option.equals("-sortByClass")) bugReporterType = SORTING_REPORTER; else if (option.equals("-xml")) { bugReporterType = XML_REPORTER; if (!optionExtraPart.equals("")) { if (optionExtraPart.equals("withMessages")) xmlWithMessages = true; else if (optionExtraPart.equals("withAbridgedMessages")) { xmlWithMessages = true; xmlWithAbridgedMessages = true; } else throw new IllegalArgumentException("Unknown option: -xml:" + optionExtraPart); } } else if (option.equals("-emacs")) { bugReporterType = EMACS_REPORTER; } else if (option.equals("-relaxed")) { relaxedReportingMode = true; } else if (option.equals("-train")) { trainingOutputDir = !optionExtraPart.equals("") ? optionExtraPart : "."; } else if (option.equals("-useTraining")) { trainingInputDir = !optionExtraPart.equals("") ? optionExtraPart : "."; } else if (option.equals("-html")) { bugReporterType = HTML_REPORTER; if (!optionExtraPart.equals("")) { stylesheet = optionExtraPart; } else { stylesheet = "default.xsl"; } } else if (option.equals("-xdocs")) { bugReporterType = XDOCS_REPORTER; } else if (option.equals("-quiet")) { quiet = true; } else if (option.equals("-nested")) { scanNestedArchives = optionExtraPart.equals("") || Boolean.valueOf(optionExtraPart).booleanValue(); } else if (option.equals("-exitcode")) { setExitCode = true; } else if (option.equals("-xargs")) xargs = true; else { super.handleOption(option, optionExtraPart); } } @SuppressWarnings("DM_EXIT") @Override protected void handleOptionWithArgument(String option, String argument) throws IOException { if (option.equals("-outputFile") || option.equals("-output")) { File outputFile = new File(argument); String extension = Util.getFileExtension(outputFile); if (bugReporterType == PRINTING_REPORTER && (extension.equals("xml") || extension.equals("fba"))) bugReporterType = XML_REPORTER; try { outputStream = new PrintStream(new BufferedOutputStream(new FileOutputStream(outputFile))); } catch (IOException e) { System.err.println("Couldn't open " + outputFile + " for output: " + e.toString()); System.exit(1); } } else if (option.equals("-projectName")) { this.projectName = argument; } else if (option.equals("-release")) { this.releaseName = argument;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -