Minor fine-tuning of findbugs command execution
[cfb.git] / prod / net / jaekl / cfb / CFB.java
index b5071d0cb18fd4efc77d4f2f6f300c8306c3325f..7dca443fa6b62aa65428b997bb9f4ad4b65a0871 100644 (file)
@@ -29,6 +29,7 @@ public class CFB {
        // Command-line parameters
        String m_dbName; // db name
        File m_fbp;             // FindBugsProject file
+       File m_fbDir;   // Directory where FindBugs is installed
        String m_host;  // db host
        int m_port;             // db port
        String m_user;  // db user
@@ -41,7 +42,8 @@ public class CFB {
                m_bundle = CfbBundle.getInst(m_locale);
                
                m_dbName = "CFB";
-               m_fbp  = null;
+               m_fbp    = null;
+               m_fbDir  = null;
                m_host = "localhost";
                m_port = 5432;
                m_pass = "";
@@ -102,7 +104,29 @@ public class CFB {
                return m_bundle.get(key);
        }
        
+       String getenv(String varName) {
+               // This is a separate function so that we can override it at unit test time
+               return System.getenv(varName);
+       }
+       
+       String getProperty(String propName) {
+               // This is a separate function so that we can override it at unit test time
+               return System.getProperty(propName);
+       }
+       
+       void initArgs() {
+               String findBugsDir = getenv("FINDBUGS_HOME");
+               if (null != findBugsDir) {
+                       m_fbDir = new File(findBugsDir);
+               }
+               findBugsDir = getProperty("findbugs.home");
+               if (null != findBugsDir) {
+                       m_fbDir = new File(findBugsDir);
+               }
+       }
+       
        void doMain(PrintWriter pw, String[] args) throws SQLException, IOException {
+               initArgs();     // read environment and system properties
                if ( ! parseArgs(pw, args) ) {
                        return;
                }
@@ -118,10 +142,13 @@ public class CFB {
                        return;
                }
                
-               File findBugsDir = new File(".");
+               File findBugsDir = (null != m_fbDir) ? m_fbDir : new File(".");
                File workDir = new File(".");
                Analyzer analyzer = new Analyzer(findBugsDir);
-               Analysis analysis = analyzer.analyze(workDir, m_fbp);
+               Analysis analysis = analyzer.analyze(pw, workDir, m_fbp);
+               if (null != analysis) {
+                       // TODO
+               }
        }
        
        public static void main(String[] args) {
@@ -129,6 +156,7 @@ public class CFB {
                
                try (PrintWriter pw = new PrintWriter(System.out)){
                        cfb.doMain(pw, args);
+                       pw.flush();
                } catch (SQLException | IOException exc) {
                        exc.printStackTrace();
                }