public void analyzeAll() throws Exception {
// Database connection
System.out.println("connecting to server");
MySQLConnection conn = new MySQLConnection();
conn.connect();
// Get the project repository details
ResultSet rs = conn.SQLSelect("SELECT * FROM projects");
while (rs.next()) {
String url = rs.getString("repos_url");
String user = rs.getString("repos_user");
if (rs.wasNull())
user = "";
String password = rs.getString("repos_password");
if (rs.wasNull())
password = "";
String name = rs.getString("name");
int idProject = rs.getInt("id");
int lastVersion = 1;
ResultSet rs2 = conn
.SQLSelect("select max(version)+1 as last_version from versions where project = "
+ idProject);
while (rs2.next()) {
lastVersion = Math.max(lastVersion, rs2.getInt("last_version"));
}
int idVersion = 1;
conn.SQLUpdate("insert into versions (project , version , creation_date) values ("
+ idProject + "," + lastVersion + " , sysdate())");
ResultSet rs3 = conn
.SQLSelect("select id from versions where version = "
+ lastVersion + " and project = " + idProject);
while (rs3.next()) {
idVersion = rs3.getInt("id");
}
System.out.println("Checking out project : " + name + " ...");
checkoutProject(url, user, password, CHECKOUT_DESTINATION_PATH
+ "/" + name);
deleteDirectory(new File(REPORTS_PATH));
File reportsDir = new File(REPORTS_PATH);
if (reportsDir.mkdir()) {
System.out.println("Reports directory created");
}
ExecuteScript javaNcssThread = new ExecuteScript(JNCSS_SCRIPT_PATH,
CHECKOUT_DESTINATION_PATH + "/" + name + "/src");
ExecuteScript pmdThread = new ExecuteScript(PMD_SCRIPT_PATH,
CHECKOUT_DESTINATION_PATH + "/" + name + "/src");
ExecuteScript clocThread = new ExecuteScript(CLOC_SCRIPT_PATH,
CHECKOUT_DESTINATION_PATH + "/" + name + "/src");
ExecuteScript findBugsThread = new ExecuteScript(
FINDBUGS_SCRIPT_PATH, CHECKOUT_DESTINATION_PATH + "/"
+ name + "/bin");
ExecuteScript coberturaThread = new ExecuteScript(
COBERTURA_SCRIPT_PATH, CHECKOUT_DESTINATION_PATH + "/"
+ name + "/bin");
System.out.println("Analyzing ...");
System.out.println("Starting JavaNCSS ...");
javaNcssThread.start();
System.out.println("Starting PMD /CPD ...");
pmdThread.start();
System.out.println("Starting CLOC ...");
clocThread.start();
System.out.println("Starting FindBugs ...");
findBugsThread.start();
javaNcssThread.join();
pmdThread.join();
clocThread.join();
findBugsThread.join();
System.out.println("JavaNCSS ended");
System.out.println("PMD /CPD ended");
System.out.println("CLOC ended");
System.out.println("FindBugs ended");
System.out.println("Starting Cobertura ...");
coberturaThread.start();
coberturaThread.join();
System.out.println("Cobertura ended");
System.out.println("Analyzing done");
GeneralParserThread generalParser = new GeneralParserThread(
XML_FILE_PATH + "/" + JNCSS_XML_FILE, XML_FILE_PATH + "/"
+ PMD_XML_FILE,
XML_FILE_PATH + "/" + CLOC_XML_FILE, CLOC_LANGUAGE,
idVersion);
CoberturaParserThread coberturaParserThread = new CoberturaParserThread(
XML_FILE_PATH + "/" + this.COBERTURA_XML_FILE, idVersion);
FindbugsParserThread findBugsParserThread = new FindbugsParserThread(
XML_FILE_PATH + "/" + this.FINDBUGS_XML_FILE, idVersion);
System.out.println("Parsing reports ...");
generalParser.start();
coberturaParserThread.start();
findBugsParserThread.start();
generalParser.join();
coberturaParserThread.join();
findBugsParserThread.join();
System.out.println("Parsing of the reports done");
System.out.println("Deleting directories ...");
File path = new File(CHECKOUT_DESTINATION_PATH);
deleteDirectory(path);
path = new File(XML_FILE_PATH);
deleteDirectory(path);
System.out.println("Directories deleted");
}
conn.disconnect();
}