Add the concept of "Project Name" to the RUNS table in the database.
[cfb.git] / prod / net / jaekl / cfb / analyze / Analysis.java
1 package net.jaekl.cfb.analyze;
2
3 // Copyright (C) 2015 Christian Jaekl
4
5 import java.io.FileNotFoundException;
6 import java.io.IOException;
7 import java.io.PrintWriter;
8 import java.util.Date;
9
10 import net.jaekl.cfb.xml.BugCollection;
11 import net.jaekl.qd.xml.ParseErrorHandler;
12 import net.jaekl.qd.xml.ParseHandler;
13
14 import org.xml.sax.InputSource;
15 import org.xml.sax.SAXException;
16 import org.xml.sax.XMLReader;
17 import org.xml.sax.helpers.XMLReaderFactory;
18
19 public class Analysis {
20         long m_id;
21         BugCollection m_bugCollection;
22         String m_projectName;
23         String m_buildNumber;
24         long m_start;   // Date.getTime() when analysis was started
25         long m_end;
26         
27         public Analysis(String projectName, String buildNumber) {
28                 m_id = (-1);
29                 m_bugCollection = null;
30                 m_projectName = projectName;
31                 m_buildNumber = buildNumber;
32                 m_start = new Date().getTime();
33                 m_end = 0;
34         }
35         
36         public BugCollection getBugCollection() { return m_bugCollection; }
37         public long getId() { return m_id; }
38         public String getProjectName() { return m_projectName; }
39         public String getBuildNumber() { return m_buildNumber; }
40         public Date getStart() { return new Date(m_start); }
41         public Date getEnd() { return (0 == m_end ? null : new Date(m_end)); }  // the end time (when FindBugs was done analyzing)
42
43         public void setBugCollection(BugCollection bugs) { m_bugCollection = bugs; }
44         public void setId(long id) { m_id = id; }
45         public void setStart(Date start) { m_start = start.getTime(); }
46         public void setEnd(Date date) { m_end = date.getTime(); }
47         
48         public void parse(InputSource xml) throws FileNotFoundException, IOException, SAXException 
49         {
50                 m_bugCollection = new BugCollection();
51                 
52             XMLReader reader = XMLReaderFactory.createXMLReader();
53             ParseHandler ph = new ParseHandler(m_bugCollection);
54             ParseErrorHandler peh = new ParseErrorHandler();
55             reader.setContentHandler(ph);
56             reader.setErrorHandler(peh);
57             reader.parse(xml);
58         }
59         
60         
61         public void dump(PrintWriter pw)
62         {
63                 if (null != m_bugCollection) {
64                         m_bugCollection.dump(pw, 2);
65                 }
66         }
67 }