4 import java.io.FileInputStream;
5 import java.io.IOException;
6 import java.io.PrintWriter;
7 import java.util.ArrayList;
8 import java.util.Arrays;
10 import java.util.Properties;
12 import org.apache.commons.cli.CommandLine;
13 import org.apache.commons.cli.GnuParser;
14 import org.apache.commons.cli.Options;
15 import org.apache.commons.cli.ParseException;
18 private static final String FINDBUGS_HOME = "FindBugsHome";
19 private static final String MAIL_FROM = "mail.from";
20 private static final String MAIL_SMTP_HOST = "mail.smtp.host";
21 private static final String NOTIFY = "notify";
23 File m_configProperties;
25 String m_dbName; // db name
26 File m_fbp; // FindBugsProject file
27 File m_fbDir; // Directory where FindBugs is installed
28 String m_host; // db host
29 int m_port; // db port
30 String m_user; // db user
31 String m_pass; // db password
32 String m_buildNum; // build number (version)
33 boolean m_removeSchema; // purge DB schema
34 File m_output; // File to which we should write our output (report)
37 String m_mailSmtpHost;
38 List<String> m_notify;
51 m_removeSchema = false;
54 m_mailFrom = "findbugs@localhost";
55 m_mailSmtpHost = "localhost";
56 m_notify = new ArrayList<String>();
58 m_options = createOptions();
61 public String getMailFrom() { return m_mailFrom; }
62 public String getMailSmtpHost() { return m_mailSmtpHost; }
63 public ArrayList<String> getNotify() { return new ArrayList<String>(m_notify); }
65 public void readFile(File configProperties) throws IOException
67 Properties props = new Properties();
68 FileInputStream fis = null;
71 fis = new FileInputStream(configProperties);
80 if (props.containsKey(FINDBUGS_HOME)) {
81 m_fbDir = new File(props.getProperty(FINDBUGS_HOME));
83 if (props.containsKey(MAIL_FROM)) {
84 m_mailFrom = props.getProperty(MAIL_FROM);
86 if (props.containsKey(MAIL_SMTP_HOST)) {
87 m_mailSmtpHost = props.getProperty(MAIL_SMTP_HOST);
89 if (props.containsKey(NOTIFY)) {
90 String[] addresses = props.getProperty(NOTIFY).split(",");
91 m_notify = Arrays.asList(addresses);
95 public Options createOptions() {
96 Options opt = new Options();
98 opt.addOption("c", "config", true, "Properties configuration file");
99 opt.addOption("d", "dbname", true, "DB name");
100 opt.addOption(null, "drop-tables", false, "Remove database schema (drop all data)");
101 opt.addOption("f", "fbp", true, "FindBugsProject file");
102 opt.addOption("h", "host", true, "DB hostname");
103 opt.addOption("n", "number", true, "Build number (version)");
104 opt.addOption("o", "outfile", true, "Output report filename");
105 opt.addOption("p", "pass", true, "DB password");
106 opt.addOption("t", "port", true, "DB port");
107 opt.addOption("u", "user", true, "DB username");
112 public void parseArgs(PrintWriter pw, String[] args) throws ParseException
114 assert(null != m_options);
116 CommandLine line = new GnuParser().parse(m_options, args);
117 if (line.hasOption("c")) {
118 m_configProperties = new File(line.getOptionValue("c"));
120 if (line.hasOption("d")) {
121 m_dbName = line.getOptionValue("d");
123 if (line.hasOption("f")) {
124 m_fbp = new File(line.getOptionValue("f"));
126 if (line.hasOption("h")) {
127 m_host = line.getOptionValue("h");
129 if (line.hasOption("n")) {
130 m_buildNum = line.getOptionValue("n");
132 if (line.hasOption("o")) {
133 m_output = new File(line.getOptionValue("o"));
135 if (line.hasOption("p")) {
136 m_pass = line.getOptionValue("p");
138 m_removeSchema = line.hasOption("drop-tables");
139 if (line.hasOption("t")) {
140 m_port = Integer.parseInt(line.getOptionValue("t"));
142 if (line.hasOption("u")) {
143 m_user = line.getOptionValue("u");