X-Git-Url: http://jaekl.net/gitweb/?a=blobdiff_plain;f=prod%2Fnet%2Fjaekl%2Fcfb%2Fanalyze%2FMessageMap.java;h=635e79df21c86b2e546e3ddf36869c2b0a426467;hb=e6448f6cf67e5a5409f24b531c2443b3bed53b52;hp=ac5288faf7e673b48fbf9f6c51fb4264f8f7a057;hpb=3c10b6100c6035a65ce37dea846b027135289f67;p=cfb.git diff --git a/prod/net/jaekl/cfb/analyze/MessageMap.java b/prod/net/jaekl/cfb/analyze/MessageMap.java index ac5288f..635e79d 100644 --- a/prod/net/jaekl/cfb/analyze/MessageMap.java +++ b/prod/net/jaekl/cfb/analyze/MessageMap.java @@ -4,8 +4,20 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.List; import java.util.Locale; +import net.jaekl.cfb.db.CfbSchema; +import net.jaekl.cfb.db.Column; +import net.jaekl.cfb.db.Condition; +import net.jaekl.cfb.db.Row; +import net.jaekl.cfb.db.Table; +import net.jaekl.cfb.db.TypeMismatchException; +import net.jaekl.cfb.db.driver.DbDriver; +import net.jaekl.cfb.xml.messages.BugCategory; +import net.jaekl.cfb.xml.messages.BugPattern; import net.jaekl.cfb.xml.messages.MessageCollection; import net.jaekl.qd.xml.ParseErrorHandler; import net.jaekl.qd.xml.ParseHandler; @@ -30,26 +42,81 @@ public class MessageMap { public MessageCollection getColl() { return m_msgColl; } public File getFindBugsDir() { return m_findBugsDir; } - public void load(File findBugsDir, Locale locale) throws FileNotFoundException, IOException, SAXException + // Load the list of primary keys (sequence numbers) from the database + public void loadIds(Connection con, DbDriver driver) throws SQLException, TypeMismatchException + { + loadCategoryIds(con, driver); + loadBugPatternIds(con, driver); + + } + + void loadCategoryIds(Connection con, DbDriver driver) throws SQLException, TypeMismatchException + { + Column[] columns = { CfbSchema.CATEGORYID, + CfbSchema.CATEGORY }; + Table[] tables = { CfbSchema.CATEGORIES }; + Condition[] conditions = { }; + List rows = driver.select(con, columns, tables, conditions); + + for (Row row : rows) { + Long catId = row.getLong(0); + String catName = row.getString(1); + + BugCategory cat = getColl().getCategory(catName); + if (null == cat) { + throw new SQLException("Database result (" + catId + ", \"" + catName + "\") not found in messages.xml. " + + "Perhaps your database and findbugs versions are out of sync?"); + } + + cat.setId(catId); + } + } + + void loadBugPatternIds(Connection con, DbDriver driver) throws SQLException, TypeMismatchException + { + Column[] columns = { CfbSchema.BUGID, CfbSchema.TYPE }; + Table[] tables = { CfbSchema.BUGS }; + Condition[] conditions = { }; + List rows = driver.select(con, columns, tables, conditions); + + for (Row row: rows) { + Long bugId = row.getLong(0); + String type = row.getString(1); + + BugPattern bug = getColl().getPattern(type); + if (null == bug) { + throw new SQLException("Database result (" + bugId + ", \"" + type + "\") not found in messages.xml. " + + "Perhaps your database and findbugs versions are out of sync?"); + } + + bug.setId(bugId); + } + } + + // Load the list of bug patterns and categories from the FindBugs messages.xml file. + public void load(File findBugsDir, Locale locale) throws FBMsgFileNotFoundException, IOException, SAXException { m_findBugsDir = findBugsDir; String langName = locale.getLanguage(); - File msgXml = new File(findBugsDir.getAbsolutePath() + File.separator + MESSAGES + "_" + langName + "." + XML); + String basePath = findBugsDir.getAbsolutePath() + File.separator + "etc" + File.separator; + + File msgXml = new File(basePath + MESSAGES + "_" + langName + "." + XML); if (! msgXml.canRead()) { - msgXml = new File(findBugsDir.getAbsolutePath() + File.separator + MESSAGES + "." + XML); + msgXml = new File(basePath + MESSAGES + "." + XML); } if (! msgXml.canRead()) { - throw new FileNotFoundException(msgXml.getAbsolutePath()); + throw new FBMsgFileNotFoundException(msgXml.getAbsolutePath()); } parse(new InputSource(new FileInputStream(msgXml))); } - void parse(InputSource xml) throws FileNotFoundException, IOException, SAXException + // Parse the FindBugs messages.xml file + public void parse(InputSource xml) throws FileNotFoundException, IOException, SAXException { m_msgColl = new MessageCollection();