From 295e3db9a37a2863cb8bc3659c375d99e40e0fc1 Mon Sep 17 00:00:00 2001 From: Chris Jaekl Date: Tue, 1 Sep 2015 22:27:18 +0900 Subject: [PATCH] Minor fine-tuning of findbugs command execution --- prod/cfb.properties | 3 +++ prod/net/jaekl/cfb/CFB.java | 34 ++++++++++++++++++++++++++++--- prod/net/jaekl/cfb/CfbBundle.java | 3 +++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/prod/cfb.properties b/prod/cfb.properties index a491bf0..d897971 100644 --- a/prod/cfb.properties +++ b/prod/cfb.properties @@ -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 diff --git a/prod/net/jaekl/cfb/CFB.java b/prod/net/jaekl/cfb/CFB.java index b5071d0..7dca443 100644 --- a/prod/net/jaekl/cfb/CFB.java +++ b/prod/net/jaekl/cfb/CFB.java @@ -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(); } diff --git a/prod/net/jaekl/cfb/CfbBundle.java b/prod/net/jaekl/cfb/CfbBundle.java index 0384851..a643c6e 100644 --- a/prod/net/jaekl/cfb/CfbBundle.java +++ b/prod/net/jaekl/cfb/CfbBundle.java @@ -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"; -- 2.39.2