Add ability to execute FindBugs
authorChris Jaekl <chris@ringo.jaekl.net>
Sat, 29 Aug 2015 13:54:42 +0000 (22:54 +0900)
committerChris Jaekl <chris@ringo.jaekl.net>
Sat, 29 Aug 2015 13:54:42 +0000 (22:54 +0900)
go.sh
prod/net/jaekl/cfb/CFB.java
prod/net/jaekl/cfb/db/Schema.java
prod/net/jaekl/cfb/db/driver/PostgresqlDriver.java

diff --git a/go.sh b/go.sh
index b546f3c3f56adfc70c0346e3c59f90c31880dea8..a1b104b0acf6bd4c8856255d73e010e3b8b2293b 100755 (executable)
--- a/go.sh
+++ b/go.sh
@@ -1,7 +1,7 @@
 #!/bin/bash
 CFB_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 echo Compiling...
-find "${CFB_ROOT}/prod" -name "*.java" | xargs javac -classpath ${CFB_ROOT}/prod:${CLASSPATH} -Xlint:deprecation
+find "${CFB_ROOT}/prod" -name "*.java" | xargs javac -g -classpath ${CFB_ROOT}/prod:${CLASSPATH} -Xlint:deprecation
 cp -r ${CFB_ROOT}/prod/* ${CFB_ROOT}/bin/
 find "${CFB_ROOT}/prod" -name '*.class' -exec rm {} \;
 echo Launching...
index 4d30011284f4d33e02a57a950c6e30cb74ebbcea..b5071d0cb18fd4efc77d4f2f6f300c8306c3325f 100644 (file)
@@ -1,11 +1,15 @@
 package net.jaekl.cfb;
 
+import java.io.File;
+import java.io.IOException;
 import java.io.PrintWriter;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.text.MessageFormat;
 import java.util.Locale;
 
+import net.jaekl.cfb.analyze.Analysis;
+import net.jaekl.cfb.analyze.Analyzer;
 import net.jaekl.cfb.db.CfbSchema;
 import net.jaekl.cfb.db.driver.DbDriver;
 import net.jaekl.cfb.db.driver.PostgresqlDriver;
@@ -24,6 +28,7 @@ public class CFB {
        
        // Command-line parameters
        String m_dbName; // db name
+       File m_fbp;             // FindBugsProject file
        String m_host;  // db host
        int m_port;             // db port
        String m_user;  // db user
@@ -36,6 +41,7 @@ public class CFB {
                m_bundle = CfbBundle.getInst(m_locale);
                
                m_dbName = "CFB";
+               m_fbp  = null;
                m_host = "localhost";
                m_port = 5432;
                m_pass = "";
@@ -46,10 +52,11 @@ public class CFB {
                Options opt = new Options();
                
                opt.addOption("d", "dbname", true, "DB name");
-               opt.addOption("h", "host", true, "DB hostname");
-               opt.addOption("p", "pass", true, "DB password");
-               opt.addOption("t", "port", true, "DB port");
-               opt.addOption("u", "user", true, "DB username");
+               opt.addOption("f", "fbp",    true, "FindBugsProject file");
+               opt.addOption("h", "host",   true, "DB hostname");
+               opt.addOption("p", "pass",   true, "DB password");
+               opt.addOption("t", "port",   true, "DB port");
+               opt.addOption("u", "user",   true, "DB username");
                
                return opt;
        }
@@ -62,6 +69,9 @@ public class CFB {
                        if (line.hasOption("d")) {
                                m_dbName = line.getOptionValue("d");
                        }
+                       if (line.hasOption("f")) {
+                               m_fbp = new File(line.getOptionValue("f"));
+                       }
                        if (line.hasOption("h")) {
                                m_host = line.getOptionValue("h");
                        }
@@ -92,20 +102,26 @@ public class CFB {
                return m_bundle.get(key);
        }
        
-       void doMain(PrintWriter pw, String[] args) throws SQLException {
+       void doMain(PrintWriter pw, String[] args) throws SQLException, IOException {
                if ( ! parseArgs(pw, args) ) {
                        return;
                }
                
                try (Connection con = m_driver.connect(m_host, m_port, m_dbName, m_user, m_pass)) {
-                       if (null == con) {
-                               String cannotConnectFormat = trans(CfbBundle.CANNOT_CONNECT);
-                               String cannotConnect = MessageFormat.format(cannotConnectFormat, m_host, m_port, m_dbName, m_user);
-                               pw.println(cannotConnect);
-                               return;
-                       }
                        m_schema.ensureDbInitialized(con);                      
                }
+               catch (SQLException exc) {
+                       String cannotConnectFormat = trans(CfbBundle.CANNOT_CONNECT);
+                       String cannotConnect = MessageFormat.format(cannotConnectFormat, m_host, ""+m_port, m_dbName, m_user);
+                       exc.printStackTrace(pw);
+                       pw.println(cannotConnect);
+                       return;
+               }
+               
+               File findBugsDir = new File(".");
+               File workDir = new File(".");
+               Analyzer analyzer = new Analyzer(findBugsDir);
+               Analysis analysis = analyzer.analyze(workDir, m_fbp);
        }
        
        public static void main(String[] args) {
@@ -113,7 +129,7 @@ public class CFB {
                
                try (PrintWriter pw = new PrintWriter(System.out)){
                        cfb.doMain(pw, args);
-               } catch (SQLException exc) {
+               } catch (SQLException | IOException exc) {
                        exc.printStackTrace();
                }
        }
index eef7b8ea15aad2e8272ccfb4d50afbb3850f7262..176526d9b649aaadcedd1c4f24a979b9e9eb7e00 100644 (file)
@@ -23,15 +23,16 @@ public class Schema {
        
        public boolean ensureDbInitialized(Connection con) throws SQLException {
                assert(null != con);
-               boolean result = true;
                
                if (allTablesPresent(con)) {
                        return true;
                }
                
-               result = createAllTables(con);
+               if (!createAllTables(con)) {
+                       return false;
+               }
                
-               return result;
+               return true;
        }
        
        boolean allTablesPresent(Connection con) throws SQLException 
@@ -56,6 +57,7 @@ public class Schema {
                }
                
                // We could be more thorough here, and check that the expected columns are in place.
+               // Also, eventually, some sort of DB schema versioning will be needed.
                
                return true;            
        }
index ec90ab8e9622c8498bb0fc4a745bf3dd739b57fc..55994b33b0d6f690f31d57bfa668aa9c55afdaee 100644 (file)
@@ -30,8 +30,7 @@ public class PostgresqlDriver extends DbDriver {
        }
 
        @Override
-       public ResultSet selectColumnsFromWhere(Column[] columns, Table[] tables,
-                       String where) {
+       public ResultSet selectColumnsFromWhere(Column[] columns, Table[] tables, String where) {
                // TODO Auto-generated method stub
                return null;
        }