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 DB_HOST = "db.host";
21 private static final String DB_NAME = "db.name";
22 private static final String DB_PASS = "db.pass";
23 private static final String DB_PORT = "db.port";
24 private static final String DB_USER = "db.user";
25 private static final String FINDBUGS_HOME = "FindBugsHome";
26 private static final String MAIL_FROM = "mail.from";
27 private static final String MAIL_SMTP_HOST = "mail.smtp.host";
28 private static final String NOTIFY = "notify";
30 File m_configProperties;
32 String m_dbName; // db name
33 File m_fbp; // FindBugsProject file
34 File m_fbDir; // Directory where FindBugs is installed
35 String m_host; // db host
36 int m_port; // db port
37 String m_user; // db user
38 String m_pass; // db password
39 String m_buildNum; // build number (version)
40 boolean m_removeSchema; // purge DB schema
41 File m_output; // File to which we should write our output (report)
44 String m_mailSmtpHost;
45 List<String> m_notify;
58 m_removeSchema = false;
61 m_mailFrom = "findbugs@localhost";
62 m_mailSmtpHost = "localhost";
63 m_notify = new ArrayList<String>();
65 m_options = createOptions();
68 public String getMailFrom() { return m_mailFrom; }
69 public String getMailSmtpHost() { return m_mailSmtpHost; }
70 public ArrayList<String> getNotify() { return new ArrayList<String>(m_notify); }
72 public String getDbHost() { return m_host; }
73 public int getDbPort() { return m_port; }
74 public String getDbName() { return m_dbName; }
75 public String getDbUser() { return m_user; }
76 public String getDbPass() { return m_pass; }
78 public void setDbHost(String value) { m_host = value; }
79 public void setDbPort(int value) { m_port = value; }
80 public void setDbName(String value) { m_dbName = value; }
81 public void setDbUser(String value) { m_user = value; }
82 public void setDbPass(String value) { m_pass = value; }
84 public void readFile(File configProperties) throws IOException
86 Properties props = new Properties();
87 InputStream is = null;
90 is = FileIO.getInst().openInput(configProperties);
99 if (props.containsKey(DB_HOST)) {
100 m_host = props.getProperty(DB_HOST);
102 if (props.containsKey(DB_NAME)) {
103 m_dbName = props.getProperty(DB_NAME);
105 if (props.containsKey(DB_PASS)) {
106 m_pass = props.getProperty(DB_PASS);
108 if (props.containsKey(DB_PORT)) {
109 m_port = Integer.parseInt(props.getProperty(DB_PORT));
111 if (props.containsKey(DB_USER)) {
112 m_user = props.getProperty(DB_USER);
114 if (props.containsKey(FINDBUGS_HOME)) {
115 m_fbDir = new File(props.getProperty(FINDBUGS_HOME));
117 if (props.containsKey(MAIL_FROM)) {
118 m_mailFrom = props.getProperty(MAIL_FROM);
120 if (props.containsKey(MAIL_SMTP_HOST)) {
121 m_mailSmtpHost = props.getProperty(MAIL_SMTP_HOST);
123 if (props.containsKey(NOTIFY)) {
124 String[] addresses = props.getProperty(NOTIFY).split(",");
125 m_notify = Arrays.asList(addresses);
129 public Options createOptions() {
130 Options opt = new Options();
132 opt.addOption("c", "config", true, "Properties configuration file");
133 opt.addOption("d", "dbname", true, "DB name");
134 opt.addOption(null, "drop-tables", false, "Remove database schema (drop all data)");
135 opt.addOption("f", "fbp", true, "FindBugsProject file");
136 opt.addOption("h", "host", true, "DB hostname");
137 opt.addOption("n", "number", true, "Build number (version)");
138 opt.addOption("o", "outfile", true, "Output report filename");
139 opt.addOption("p", "pass", true, "DB password");
140 opt.addOption("t", "port", true, "DB port");
141 opt.addOption("u", "user", true, "DB username");
146 public void parseArgs(PrintWriter pw, String[] args) throws ParseException
148 assert(null != m_options);
150 CommandLine line = new GnuParser().parse(m_options, args);
151 if (line.hasOption("c")) {
152 m_configProperties = new File(line.getOptionValue("c"));
154 if (line.hasOption("d")) {
155 m_dbName = line.getOptionValue("d");
157 if (line.hasOption("f")) {
158 m_fbp = new File(line.getOptionValue("f"));
160 if (line.hasOption("h")) {
161 m_host = line.getOptionValue("h");
163 if (line.hasOption("n")) {
164 m_buildNum = line.getOptionValue("n");
166 if (line.hasOption("o")) {
167 m_output = new File(line.getOptionValue("o"));
169 if (line.hasOption("p")) {
170 m_pass = line.getOptionValue("p");
172 m_removeSchema = line.hasOption("drop-tables");
173 if (line.hasOption("t")) {
174 m_port = Integer.parseInt(line.getOptionValue("t"));
176 if (line.hasOption("u")) {
177 m_user = line.getOptionValue("u");