Clean up error handling to make things slightly friendlier on an initial install.
[cfb.git] / prod / net / jaekl / cfb / CFB.java
index 35a08c3b178491f92e1d2c456b53a5900e64db6c..c6c995d41cf70e66d9ecdb54329fca321b18cd3c 100644 (file)
@@ -21,6 +21,7 @@ import java.util.Locale.Category;
 import net.jaekl.cfb.analyze.Analysis;
 import net.jaekl.cfb.analyze.Analyzer;
 import net.jaekl.cfb.analyze.Delta;
+import net.jaekl.cfb.analyze.FBMsgFileNotFoundException;
 import net.jaekl.cfb.analyze.HtmlReport;
 import net.jaekl.cfb.analyze.MessageMap;
 import net.jaekl.cfb.analyze.Notifier;
@@ -30,6 +31,7 @@ import net.jaekl.cfb.db.driver.DbDriver;
 import net.jaekl.cfb.db.driver.PostgresqlDriver;
 import net.jaekl.cfb.store.DbStore;
 import net.jaekl.cfb.store.StoreException;
+import net.jaekl.cfb.util.Env;
 import net.jaekl.qd.xml.XmlParseException;
 
 import org.apache.commons.cli.CommandLine;
@@ -40,6 +42,8 @@ import org.apache.commons.cli.ParseException;
 import org.xml.sax.SAXException;
 
 public class CFB {
+       public static final String FINDBUGS_HOME = "FINDBUGS_HOME";     // name of the FINDBUGS_HOME environment variable
+       
        DbDriver m_driver;
        CfbSchema m_schema;
        volatile static CfbBundle m_bundle = null;      
@@ -151,8 +155,8 @@ public class CFB {
                help.printHelp(pw, 80, getClass().getName(), "", opt, 0, 0, "", true);
        }
        
-       String trans(String key) {
-               return getBundle(m_locale).get(key);
+       String trans(String key, Object... params) {
+               return getBundle(m_locale).get(key, params);
        }
        
        String getenv(String varName) {
@@ -196,7 +200,13 @@ public class CFB {
                File findBugsDir = getFindBugsDir();
                File workDir = new File(".");
                MessageMap messageMap = new MessageMap();
-               messageMap.load(findBugsDir, Locale.getDefault(Category.DISPLAY));
+               try {
+                       messageMap.load(findBugsDir, Locale.getDefault(Category.DISPLAY));
+               }
+               catch (FBMsgFileNotFoundException exc) {
+                       reportException(pw, exc);
+                       return;
+               }
                
                if (!ensureDbInitialized(pw, messageMap)) {
                        return;
@@ -270,6 +280,21 @@ public class CFB {
                        reportUnableToConnect(pw, exc);
                }
        }
+       
+       void reportException(PrintWriter pw, FBMsgFileNotFoundException exc) {
+               exc.printStackTrace(pw);
+               
+               pw.println(trans(CfbBundle.CANNOT_LOAD_FBMSG_FILE, exc.getFilename()));
+               
+               String fbHome = Env.get(FINDBUGS_HOME);
+               if (null == fbHome) {
+                       pw.println(trans(CfbBundle.FINDBUGS_HOME_IS_NOT_SET, FINDBUGS_HOME));
+               }
+               else {
+                       pw.println(trans(CfbBundle.FINDBUGS_HOME_IS_SET_TO, FINDBUGS_HOME, fbHome));
+               }
+
+       }
 
        private void reportUnableToConnect(PrintWriter pw, SQLException exc) {
                String cannotConnectFormat = trans(CfbBundle.CANNOT_CONNECT);