From 1577da4d5488b4f6f093ef0657c04415326b9bd3 Mon Sep 17 00:00:00 2001 From: Chris Jaekl Date: Sat, 29 Aug 2015 22:54:42 +0900 Subject: [PATCH] Add ability to execute FindBugs --- go.sh | 2 +- prod/net/jaekl/cfb/CFB.java | 40 +++++++++++++------ prod/net/jaekl/cfb/db/Schema.java | 8 ++-- .../jaekl/cfb/db/driver/PostgresqlDriver.java | 3 +- 4 files changed, 35 insertions(+), 18 deletions(-) diff --git a/go.sh b/go.sh index b546f3c..a1b104b 100755 --- 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... diff --git a/prod/net/jaekl/cfb/CFB.java b/prod/net/jaekl/cfb/CFB.java index 4d30011..b5071d0 100644 --- a/prod/net/jaekl/cfb/CFB.java +++ b/prod/net/jaekl/cfb/CFB.java @@ -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(); } } diff --git a/prod/net/jaekl/cfb/db/Schema.java b/prod/net/jaekl/cfb/db/Schema.java index eef7b8e..176526d 100644 --- a/prod/net/jaekl/cfb/db/Schema.java +++ b/prod/net/jaekl/cfb/db/Schema.java @@ -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; } diff --git a/prod/net/jaekl/cfb/db/driver/PostgresqlDriver.java b/prod/net/jaekl/cfb/db/driver/PostgresqlDriver.java index ec90ab8..55994b3 100644 --- a/prod/net/jaekl/cfb/db/driver/PostgresqlDriver.java +++ b/prod/net/jaekl/cfb/db/driver/PostgresqlDriver.java @@ -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; } -- 2.39.2