From 2769cf82ccae57ee3716aecc9bd694be1f115d92 Mon Sep 17 00:00:00 2001 From: Chris Jaekl Date: Sun, 13 Dec 2015 18:17:11 +0900 Subject: [PATCH] Add the concept of "Project Name" to the RUNS table in the database. This permits multiple projects to share one database, keeping delta comparisons distinct between them. --- jenkins_invoke.sh | 2 +- prod/net/jaekl/cfb/CFB.java | 8 +++++++- prod/net/jaekl/cfb/analyze/Analysis.java | 5 ++++- prod/net/jaekl/cfb/analyze/Analyzer.java | 5 +++-- prod/net/jaekl/cfb/db/CfbSchema.java | 3 ++- prod/net/jaekl/cfb/store/DbStore.java | 17 +++++++++++------ test/net/jaekl/cfb/analyze/AnalysisTest.java | 2 +- 7 files changed, 29 insertions(+), 13 deletions(-) diff --git a/jenkins_invoke.sh b/jenkins_invoke.sh index 935c361..804b8f4 100755 --- a/jenkins_invoke.sh +++ b/jenkins_invoke.sh @@ -28,4 +28,4 @@ EOF #cat cfb.fbp cd ${SCRIPT_DIR} -bash -x ./go.sh -c ${SCRIPT_DIR}/config.properties -d cfb -u cfb -p cfb -f cfb.fbp -n jenkins_${JOB_NAME}_${BUILD_NUMBER} -o ${OUT_FILE} +bash -x ./go.sh -c ${SCRIPT_DIR}/config.properties -d cfb -u cfb -p cfb -f cfb.fbp -j ${JOB_NAME} -n jenkins_${JOB_NAME}_${BUILD_NUMBER} -o ${OUT_FILE} diff --git a/prod/net/jaekl/cfb/CFB.java b/prod/net/jaekl/cfb/CFB.java index c088ca8..c02aa54 100644 --- a/prod/net/jaekl/cfb/CFB.java +++ b/prod/net/jaekl/cfb/CFB.java @@ -55,6 +55,7 @@ public class CFB { int m_port; // db port String m_user; // db user String m_pass; // db password + String m_projName; // project (module) name String m_buildNum; // build number (version) boolean m_removeSchema; // purge DB schema File m_output; // File to which we should write our output (report) @@ -74,6 +75,7 @@ public class CFB { m_port = 5432; m_pass = ""; m_user = "user"; + m_projName = null; m_buildNum = null; m_removeSchema = false; m_output = null; @@ -87,6 +89,7 @@ public class CFB { opt.addOption(null, "drop-tables", false, "Remove database schema (drop all data)"); opt.addOption("f", "fbp", true, "FindBugsProject file"); opt.addOption("h", "host", true, "DB hostname"); + opt.addOption("j", "project", true, "proJect name"); opt.addOption("n", "number", true, "Build number (version)"); opt.addOption("o", "outfile", true, "Output report filename"); opt.addOption("p", "pass", true, "DB password"); @@ -113,6 +116,9 @@ public class CFB { if (line.hasOption("h")) { m_host = line.getOptionValue("h"); } + if (line.hasOption("j")) { + m_projName = line.getOptionValue("j"); + } if (line.hasOption("n")) { m_buildNum = line.getOptionValue("n"); } @@ -206,7 +212,7 @@ public class CFB { } Analyzer analyzer = new Analyzer(messageMap); - Analysis analysis = analyzer.analyze(pw, workDir, m_fbp, m_buildNum); + Analysis analysis = analyzer.analyze(pw, workDir, m_fbp, m_projName, m_buildNum); if (null == analysis) { pw.println(trans(CfbBundle.ANALYSIS_FAILED)); return; diff --git a/prod/net/jaekl/cfb/analyze/Analysis.java b/prod/net/jaekl/cfb/analyze/Analysis.java index 70bad86..81f4b89 100644 --- a/prod/net/jaekl/cfb/analyze/Analysis.java +++ b/prod/net/jaekl/cfb/analyze/Analysis.java @@ -19,13 +19,15 @@ import org.xml.sax.helpers.XMLReaderFactory; public class Analysis { long m_id; BugCollection m_bugCollection; + String m_projectName; String m_buildNumber; long m_start; // Date.getTime() when analysis was started long m_end; - public Analysis(String buildNumber) { + public Analysis(String projectName, String buildNumber) { m_id = (-1); m_bugCollection = null; + m_projectName = projectName; m_buildNumber = buildNumber; m_start = new Date().getTime(); m_end = 0; @@ -33,6 +35,7 @@ public class Analysis { public BugCollection getBugCollection() { return m_bugCollection; } public long getId() { return m_id; } + public String getProjectName() { return m_projectName; } public String getBuildNumber() { return m_buildNumber; } public Date getStart() { return new Date(m_start); } public Date getEnd() { return (0 == m_end ? null : new Date(m_end)); } // the end time (when FindBugs was done analyzing) diff --git a/prod/net/jaekl/cfb/analyze/Analyzer.java b/prod/net/jaekl/cfb/analyze/Analyzer.java index a7903ee..d1aa115 100644 --- a/prod/net/jaekl/cfb/analyze/Analyzer.java +++ b/prod/net/jaekl/cfb/analyze/Analyzer.java @@ -24,9 +24,10 @@ public class Analyzer { m_msgMap = msgMap; } - public Analysis analyze(PrintWriter pw, File workDir, File fbp, String buildNumber) throws IOException, XmlParseException, SAXException + public Analysis analyze(PrintWriter pw, File workDir, File fbp, String projName, String buildNumber) + throws IOException, XmlParseException, SAXException { - Analysis result = new Analysis(buildNumber); + Analysis result = new Analysis(projName, buildNumber); File fbOutput = outputWorkFile(workDir, fbp); diff --git a/prod/net/jaekl/cfb/db/CfbSchema.java b/prod/net/jaekl/cfb/db/CfbSchema.java index 230133b..84f858d 100644 --- a/prod/net/jaekl/cfb/db/CfbSchema.java +++ b/prod/net/jaekl/cfb/db/CfbSchema.java @@ -37,6 +37,7 @@ public class CfbSchema extends Schema { public static final Column METHODNAME = new Column("METHODNAME", VARCHAR, 256, NULL); public static final Column METHODROLE = new Column("METHODROLE", VARCHAR, 80, NULL); public static final Column NAME = new Column("NAME", VARCHAR, 256, NOT_NULL); + public static final Column PROJNAME = new Column("PROJNAME", VARCHAR, 80, NOT_NULL); public static final Column RUNID = new Column("RUNID", INTEGER, -1, NOT_NULL); public static final Column SECONDLOCID = new Column("SECONDLOCID", INTEGER, -1, NULL); public static final Column STARTLINE = new Column("STARTLINE", INTEGER, -1, NULL); @@ -52,7 +53,7 @@ public class CfbSchema extends Schema { private static final Column[] CATEGORIES_COLS = { CATEGORYID, CATEGORY }; private static final Column[] FOUND_COLS = { FOUNDID, RUNID, BUGID, CATEGORYID, FIRSTLOCID, SECONDLOCID, THIRDLOCID, VARID_FK }; private static final Column[] LOCATIONS_COLS = { LOCID, CLASSNAME, METHODNAME, METHODROLE, STARTLINE, ENDLINE }; - private static final Column[] RUNS_COLS = { RUNID, VERSION, STARTTIME, ENDTIME }; + private static final Column[] RUNS_COLS = { RUNID, PROJNAME, VERSION, STARTTIME, ENDTIME }; private static final Column[] VARIABLES_COLS = { VARID_PK, NAME, VARROLE }; public static final Table BUGS = new Table("BUGS", BUGS_COLS); diff --git a/prod/net/jaekl/cfb/store/DbStore.java b/prod/net/jaekl/cfb/store/DbStore.java index 6c20979..3860ca5 100644 --- a/prod/net/jaekl/cfb/store/DbStore.java +++ b/prod/net/jaekl/cfb/store/DbStore.java @@ -54,6 +54,7 @@ public class DbStore { Object[][] values = { { Long.valueOf(runId), + analysis.getProjectName(), analysis.getBuildNumber(), analysis.getStart(), analysis.getEnd() @@ -287,7 +288,10 @@ public class DbStore { { Column[] columns = { CfbSchema.RUNID }; Table[] tables = { CfbSchema.RUNS }; - Condition[] conditions = { new Condition( CfbSchema.STARTTIME, analysis.getStart(), Operation.LESS_THAN ) }; + Condition[] conditions = { + new Condition( CfbSchema.PROJNAME, analysis.getProjectName(), Operation.EQUAL ), + new Condition( CfbSchema.STARTTIME, analysis.getStart(), Operation.LESS_THAN ) + }; Sort[] sorts = { new Sort( CfbSchema.STARTTIME, Sort.Direction.DESCENDING ) }; int limit = 1; @@ -300,7 +304,7 @@ public class DbStore { Analysis getAnalysis(Long analysisId) throws SQLException, TypeMismatchException { - Column[] columns = { CfbSchema.VERSION, CfbSchema.STARTTIME, CfbSchema.ENDTIME }; + Column[] columns = { CfbSchema.PROJNAME, CfbSchema.VERSION, CfbSchema.STARTTIME, CfbSchema.ENDTIME }; Table[] tables = { CfbSchema.RUNS }; Condition[] conditions = { new Condition( CfbSchema.RUNID, analysisId, Operation.EQUAL ) }; @@ -311,11 +315,12 @@ public class DbStore { Row row = rows.get(0); - String version = row.getString(0); - java.util.Date start= row.getDate(1); - java.util.Date end = row.getDate(2); + String projName = row.getString(0); + String version = row.getString(1); + java.util.Date start= row.getDate(2); + java.util.Date end = row.getDate(3); - Analysis prior = new Analysis(version); + Analysis prior = new Analysis(projName, version); prior.setId(analysisId.longValue()); prior.setStart(start); prior.setEnd(end); diff --git a/test/net/jaekl/cfb/analyze/AnalysisTest.java b/test/net/jaekl/cfb/analyze/AnalysisTest.java index 5b48927..e874412 100644 --- a/test/net/jaekl/cfb/analyze/AnalysisTest.java +++ b/test/net/jaekl/cfb/analyze/AnalysisTest.java @@ -61,7 +61,7 @@ public class AnalysisTest { try ( ByteArrayInputStream bais = new ByteArrayInputStream(SAMPLE1_XML.getBytes(utf8))) { InputSource inputSource = new InputSource(bais); - Analysis analysis = new Analysis(null); + Analysis analysis = new Analysis(null, null); analysis.parse(inputSource); assertNotNull(analysis); -- 2.39.2