Add the concept of "Project Name" to the RUNS table in the database.
[cfb.git] / prod / net / jaekl / cfb / CFB.java
index 33a1ca04b23312d3e19b05efbc8e8b5cfc2f1546..c02aa546aa0f7efe1bd29b36f81703127e3e6497 100644 (file)
@@ -9,7 +9,9 @@ package net.jaekl.cfb;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
+import java.nio.charset.Charset;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.text.MessageFormat;
@@ -53,6 +55,7 @@ public class CFB {
        int m_port;             // db port
        String m_user;  // db user
        String m_pass;  // db password
+       String m_projName; // project (module) name
        String m_buildNum; // build number (version)
        boolean m_removeSchema; // purge DB schema
        File m_output;  // File to which we should write our output (report)
@@ -72,6 +75,7 @@ public class CFB {
                m_port = 5432;
                m_pass = "";
                m_user = "user";
+               m_projName = null;
                m_buildNum = null;
                m_removeSchema = false;
                m_output = null;
@@ -85,6 +89,7 @@ public class CFB {
                opt.addOption(null, "drop-tables", false, "Remove database schema (drop all data)");
                opt.addOption("f",  "fbp",         true,  "FindBugsProject file");
                opt.addOption("h",  "host",        true,  "DB hostname");
+               opt.addOption("j",  "project",     true,  "proJect name");
                opt.addOption("n",  "number",      true,  "Build number (version)");
                opt.addOption("o",  "outfile",     true,  "Output report filename");
                opt.addOption("p",  "pass",        true,  "DB password");
@@ -111,6 +116,9 @@ public class CFB {
                        if (line.hasOption("h")) {
                                m_host = line.getOptionValue("h");
                        }
+                       if (line.hasOption("j")) {
+                               m_projName = line.getOptionValue("j");
+                       }
                        if (line.hasOption("n")) {
                                m_buildNum = line.getOptionValue("n");
                        }
@@ -204,7 +212,7 @@ public class CFB {
                }
                
                Analyzer analyzer = new Analyzer(messageMap);
-               Analysis analysis = analyzer.analyze(pw, workDir, m_fbp, m_buildNum);
+               Analysis analysis = analyzer.analyze(pw, workDir, m_fbp, m_projName, m_buildNum);
                if (null == analysis) {
                        pw.println(trans(CfbBundle.ANALYSIS_FAILED));
                        return;
@@ -218,7 +226,9 @@ public class CFB {
                        Delta delta = new Delta(prior, analysis);
 
                        HtmlReport report = new HtmlReport(m_bundle, messageMap.getColl(), delta);
-                       report.write(m_output);
+                       if (null != m_output) {
+                               report.write(m_output);
+                       }
                        
                        Notifier notifier = new Notifier(m_bundle, m_config);
                        notifier.sendEmailIfNeeded(pw, report);
@@ -244,7 +254,7 @@ public class CFB {
        public static void main(String[] args) {
                CFB cfb = new CFB(Locale.getDefault());
                
-               try (PrintWriter pw = new PrintWriter(System.out)){
+               try (PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out, Charset.defaultCharset()))) {
                        cfb.doMain(pw, args);
                        pw.flush();
                } catch (SQLException | IOException | XmlParseException | SAXException | TypeMismatchException exc) {