Package parsers

Source Code of parsers.GeneralParser

package parsers;

import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;

import database.MySQLConnection;

/**
*
* A dummy parser which is used to aggregate data retrieved from some actual
* parsers
*
*/
public class GeneralParser {

  private JavaNcssParser jncssParser;
  private PmdParser pmdParser;
  private ClocParser clocParser;

  private String jncssPath;
  private String pmdPath;
  private String clocPath;

  public GeneralParser(String jncssPath, String pmdPath, String clocPath,
      String clocLanguage) {
    this.jncssPath = jncssPath;
    this.pmdPath = pmdPath;
    this.clocPath = clocPath;

    jncssParser = new JavaNcssParser();
    pmdParser = new PmdParser();
    clocParser = new ClocParser(clocLanguage);
  }

  public void parseResults() throws InterruptedException {

    Thread jncssParsingThread = new Thread() {
      public void run() {

        try {
          System.out.println("General Parser : parsing JavaNCSS ("
              + jncssPath + ")");

          jncssParser.readResults(jncssPath);

        } catch (ParserConfigurationException e) {
          e.printStackTrace();
        } catch (SAXException e) {
          e.printStackTrace();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    };

    Thread pmdParsingThread = new Thread() {
      public void run() {

        try {
          pmdParser.readResults(pmdPath);
        } catch (ParserConfigurationException e) {
          e.printStackTrace();
        } catch (SAXException e) {
          e.printStackTrace();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    };

    Thread clocParsingThread = new Thread() {
      public void run() {

        try {
          clocParser.readResults(clocPath);
        } catch (ParserConfigurationException e) {
          e.printStackTrace();
        } catch (SAXException e) {
          e.printStackTrace();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    };

    // Launch parsing threads
    jncssParsingThread.start();
    pmdParsingThread.start();
    clocParsingThread.start();

    // Wait for parsing threads
    jncssParsingThread.join();
    pmdParsingThread.join();
    clocParsingThread.join();
  }

  public void saveResults(int idVersion) throws Exception {

    MySQLConnection conn = new MySQLConnection();
    conn.connect();

    int numLinesOfCode = this.clocParser.getNumLinesOfCode();
    int numFiles = this.clocParser.getNumFiles();
    int numComments = this.clocParser.getNumComments();
    int numPackages = this.jncssParser.getNumPackages();
    int numClasses = this.jncssParser.getNumClasses();
    int numFunctions = this.jncssParser.getNumFunctions();
    int numCodeDuplications = this.pmdParser.getNumCodeDuplications();

    conn.SQLUpdate("insert into general_stats (version , nloc , nfunc , ncl , npkg , ncom , ndupl , nfile) values ("
        + idVersion
        + ","
        + (numLinesOfCode == -1 ? "NULL" : numLinesOfCode)
        + ","
        + (numFunctions == -1 ? "NULL" : numFunctions)
        + ","
        + (numClasses == -1 ? "NULL" : numClasses)
        + ","
        + (numPackages == -1 ? "NULL" : numPackages)
        + ","
        + (numComments == -1 ? "NULL" : numComments)
        + ","
        + (numCodeDuplications == -1 ? "NULL" : numCodeDuplications)
        + "," + (numFiles == -1 ? "NULL" : numFiles) + ")");

    conn.disconnect();
  }
}
TOP

Related Classes of parsers.GeneralParser

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.