]> jaekl.net Git - cfb.git/commitdiff
Add the concept of "Project Name" to the RUNS table in the database.
authorChris Jaekl <cejaekl@yahoo.com>
Sun, 13 Dec 2015 09:17:11 +0000 (18:17 +0900)
committerChris Jaekl <cejaekl@yahoo.com>
Sun, 13 Dec 2015 09:17:11 +0000 (18:17 +0900)
This permits multiple projects to share one database, keeping delta comparisons distinct between them.

jenkins_invoke.sh
prod/net/jaekl/cfb/CFB.java
prod/net/jaekl/cfb/analyze/Analysis.java
prod/net/jaekl/cfb/analyze/Analyzer.java
prod/net/jaekl/cfb/db/CfbSchema.java
prod/net/jaekl/cfb/store/DbStore.java
test/net/jaekl/cfb/analyze/AnalysisTest.java

index 935c361a1b8c0b8326c190d70105b8fc98c148dd..804b8f4b23f2a252d9b7db69958b450ee8d85677 100755 (executable)
@@ -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}
index c088ca8d818aa3fa6574302e54129b275f51eb84..c02aa546aa0f7efe1bd29b36f81703127e3e6497 100644 (file)
@@ -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;
index 70bad863e00d6b858a625a7019cffa5b40de781d..81f4b89bad189a0722e89a2c28d3ebdd99d9636f 100644 (file)
@@ -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)
index a7903ee3d3ef48c1f7173037b6ecd08e9fb8900c..d1aa115e9d6ab3418c1f20979ad3fa446d7737b8 100644 (file)
@@ -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);
                
index 230133b1a8326f6f9c65b67420a8536bba907cfb..84f858db4db6572ab20b2b84246b9537962f68eb 100644 (file)
@@ -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);
index 6c2097925f3d78a3c14fb91e6325643d66578be1..3860ca5637e5c2fd31f93bec95b1d59900dec6d5 100644 (file)
@@ -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);
index 5b48927e8f9cf5ef99dd2839608e5752f55330ea..e874412281d6b2ca2189290600f9de5ae121d2f3 100644 (file)
@@ -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);