Minor fine-tuning of findbugs command execution
authorChris Jaekl <chris@ringo.jaekl.net>
Tue, 1 Sep 2015 13:27:18 +0000 (22:27 +0900)
committerChris Jaekl <chris@ringo.jaekl.net>
Tue, 1 Sep 2015 13:27:18 +0000 (22:27 +0900)
prod/cfb.properties
prod/net/jaekl/cfb/CFB.java
prod/net/jaekl/cfb/CfbBundle.java

index a491bf0926347b1460ef960a350f4786502d17c3..d8979712ea1a84cec92cc48fe45dcd7979c66024 100644 (file)
@@ -1 +1,4 @@
 cannot.connect.to.db=Unable to connect to database {2} on {0}:{1} as user {3}.
+cannot.exec=Got result code {1} when attempting to execute command-line:  {0}
+stderr.was=-----8<------ Error (stderr) output was: ------8<-----
+stdout.was=-----8<----- Console (stdout) output was: -----8<-----
\ No newline at end of file
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();
                }
index 0384851bbf7c17705791f4c7d144ac68c814a514..a643c6edc5a6b4f00bf728487579119d2658f303 100644 (file)
@@ -9,6 +9,9 @@ import net.jaekl.qd.QDBundleFactory;
 
 public class CfbBundle {
        public static final String CANNOT_CONNECT = "cannot.connect.to.db";
+       public static final String CANNOT_EXEC = "cannot.exec";
+       public static final String STDERR_WAS = "stderr.was";
+       public static final String STDOUT_WAS = "stdout.was";
        
        final static String BUNDLE_NAME = "cfb";