4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.io.PrintWriter;
7 import java.util.ArrayList;
8 import java.util.Arrays;
10 import java.util.Properties;
12 import net.jaekl.qd.util.FileIO;
14 import org.apache.commons.cli.CommandLine;
15 import org.apache.commons.cli.GnuParser;
16 import org.apache.commons.cli.Options;
17 import org.apache.commons.cli.ParseException;
20 private static final String FINDBUGS_HOME = "FindBugsHome";
21 private static final String MAIL_FROM = "mail.from";
22 private static final String MAIL_SMTP_HOST = "mail.smtp.host";
23 private static final String NOTIFY = "notify";
25 File m_configProperties;
27 String m_dbName; // db name
28 File m_fbp; // FindBugsProject file
29 File m_fbDir; // Directory where FindBugs is installed
30 String m_host; // db host
31 int m_port; // db port
32 String m_user; // db user
33 String m_pass; // db password
34 String m_buildNum; // build number (version)
35 boolean m_removeSchema; // purge DB schema
36 File m_output; // File to which we should write our output (report)
39 String m_mailSmtpHost;
40 List<String> m_notify;
53 m_removeSchema = false;
56 m_mailFrom = "findbugs@localhost";
57 m_mailSmtpHost = "localhost";
58 m_notify = new ArrayList<String>();
60 m_options = createOptions();
63 public String getMailFrom() { return m_mailFrom; }
64 public String getMailSmtpHost() { return m_mailSmtpHost; }
65 public ArrayList<String> getNotify() { return new ArrayList<String>(m_notify); }
67 public void readFile(File configProperties) throws IOException
69 Properties props = new Properties();
70 InputStream is = null;
73 is = FileIO.getInst().openInput(configProperties);
82 if (props.containsKey(FINDBUGS_HOME)) {
83 m_fbDir = new File(props.getProperty(FINDBUGS_HOME));
85 if (props.containsKey(MAIL_FROM)) {
86 m_mailFrom = props.getProperty(MAIL_FROM);
88 if (props.containsKey(MAIL_SMTP_HOST)) {
89 m_mailSmtpHost = props.getProperty(MAIL_SMTP_HOST);
91 if (props.containsKey(NOTIFY)) {
92 String[] addresses = props.getProperty(NOTIFY).split(",");
93 m_notify = Arrays.asList(addresses);
97 public Options createOptions() {
98 Options opt = new Options();
100 opt.addOption("c", "config", true, "Properties configuration file");
101 opt.addOption("d", "dbname", true, "DB name");
102 opt.addOption(null, "drop-tables", false, "Remove database schema (drop all data)");
103 opt.addOption("f", "fbp", true, "FindBugsProject file");
104 opt.addOption("h", "host", true, "DB hostname");
105 opt.addOption("n", "number", true, "Build number (version)");
106 opt.addOption("o", "outfile", true, "Output report filename");
107 opt.addOption("p", "pass", true, "DB password");
108 opt.addOption("t", "port", true, "DB port");
109 opt.addOption("u", "user", true, "DB username");
114 public void parseArgs(PrintWriter pw, String[] args) throws ParseException
116 assert(null != m_options);
118 CommandLine line = new GnuParser().parse(m_options, args);
119 if (line.hasOption("c")) {
120 m_configProperties = new File(line.getOptionValue("c"));
122 if (line.hasOption("d")) {
123 m_dbName = line.getOptionValue("d");
125 if (line.hasOption("f")) {
126 m_fbp = new File(line.getOptionValue("f"));
128 if (line.hasOption("h")) {
129 m_host = line.getOptionValue("h");
131 if (line.hasOption("n")) {
132 m_buildNum = line.getOptionValue("n");
134 if (line.hasOption("o")) {
135 m_output = new File(line.getOptionValue("o"));
137 if (line.hasOption("p")) {
138 m_pass = line.getOptionValue("p");
140 m_removeSchema = line.hasOption("drop-tables");
141 if (line.hasOption("t")) {
142 m_port = Integer.parseInt(line.getOptionValue("t"));
144 if (line.hasOption("u")) {
145 m_user = line.getOptionValue("u");