1 19 package edu.umd.cs.findbugs; 20 21 import java.io.File ; 22 import java.io.IOException ; 23 import java.net.URL ; 24 import java.util.ArrayList ; 25 import java.util.StringTokenizer ; 26 27 import edu.umd.cs.findbugs.config.AnalysisFeatureSetting; 28 import edu.umd.cs.findbugs.config.CommandLine; 29 30 36 public abstract class FindBugsCommandLine extends CommandLine { 37 38 41 protected AnalysisFeatureSetting[] settingList = FindBugs.DEFAULT_EFFORT; 42 43 46 protected Project project = new Project(); 47 48 52 public FindBugsCommandLine() { 53 addOption("-project", "project", "analyze given project"); 54 addOption("-home", "home directory", "specify FindBugs home directory"); 55 addOption("-pluginList", "jar1[" + File.pathSeparator + "jar2...]", 56 "specify list of plugin Jar files to load"); 57 addSwitchWithOptionalExtraPart("-effort", "min|default|max", "set analysis effort level"); 58 addSwitch("-adjustExperimental", "lower priority of experimental Bug Patterns"); 59 addSwitch("-workHard", "ensure analysis effort is at least 'default'"); 60 addSwitch("-conserveSpace", "same as -effort:min (for backward compatibility)"); 61 } 62 63 public AnalysisFeatureSetting[] getSettingList() { 64 return settingList; 65 } 66 67 public Project getProject() { 68 return project; 69 } 70 71 @Override 73 protected void handleOption(String option, String optionExtraPart) { 74 if (option.equals("-effort")) { 75 if (optionExtraPart.equals("min")) { 76 settingList = FindBugs.MIN_EFFORT; 77 } else if (optionExtraPart.equals("less")) { 78 settingList = FindBugs.LESS_EFFORT; 79 } else if (optionExtraPart.equals("default")) { 80 settingList = FindBugs.DEFAULT_EFFORT; 81 } else if (optionExtraPart.equals("more")) { 82 settingList = FindBugs.MORE_EFFORT; 83 } else if (optionExtraPart.equals("max")) { 84 settingList = FindBugs.MAX_EFFORT; 85 } else { 86 throw new IllegalArgumentException ("-effort:<value> must be one of min,default,more,max"); 87 } 88 } else if (option.equals("-workHard")) { 89 if (settingList != FindBugs.MAX_EFFORT) 90 settingList = FindBugs.MORE_EFFORT; 91 92 } else if (option.equals("-conserveSpace")) { 93 settingList = FindBugs.MIN_EFFORT; 94 } else if (option.equals("-adjustExperimental")) { 95 BugInstance.setAdjustExperimental(true); 96 } else { 97 throw new IllegalStateException (); 98 } 99 } 100 101 @Override 102 protected void handleOptionWithArgument(String option, String argument) throws IOException { 103 if (option.equals("-home")) { 104 FindBugs.setHome(argument); 105 } else if (option.equals("-pluginList")) { 106 String pluginListStr = argument; 107 ArrayList <URL > pluginList = new ArrayList <URL >(); 108 StringTokenizer tok = new StringTokenizer (pluginListStr, File.pathSeparator); 109 while (tok.hasMoreTokens()) { 110 pluginList.add(new File (tok.nextToken()).toURL()); 111 } 112 113 DetectorFactoryCollection.rawInstance().setPluginList(pluginList.toArray(new URL [pluginList.size()])); 114 } else if (option.equals("-project")) { 115 String projectFile = argument; 116 117 projectFile = new File (projectFile).getAbsolutePath(); 119 120 try { 121 project = new Project(); 122 project.read(projectFile); 123 } catch (IOException e) { 124 System.err.println("Error opening " + projectFile); 125 e.printStackTrace(System.err); 126 throw e; 127 } 128 } else { 129 throw new IllegalStateException (); 130 } 131 } 132 } 133 | Popular Tags |