Search in sources :

Example 1 with NewFileInfoDAO

use of aserg.gtf.dao.NewFileInfoDAO in project Truck-Factor by aserg-ufmg.

the class LinguistExtractor method extractAndPersist.

public void extractAndPersist() throws IOException {
    NewFileInfoDAO fiDAO = new NewFileInfoDAO();
    fiDAO.setAllAsNotLinguist();
    List<NewFileInfo> files = execute();
    try {
        Map<String, List<String>> languageMap = new HashMap<String, List<String>>();
        System.out.format("%s (%s): Extracting file language information...", repositoryName, new Date());
        BufferedReader br = new BufferedReader(new FileReader(repositoryPath + fileName));
        String sCurrentLine;
        String[] values;
        while ((sCurrentLine = br.readLine()) != null) {
            values = sCurrentLine.split(";");
            String language = values[0];
            if (language.contains("\'"))
                language = language.replace("'", "''");
            String path = values[1];
            List<String> paths;
            if (languageMap.containsKey(language))
                paths = languageMap.get(language);
            else {
                paths = new ArrayList<String>();
                languageMap.put(language, paths);
            }
            paths.add(path);
            files.add(new NewFileInfo(repositoryName, path, language));
        }
        br.close();
        for (Entry<String, List<String>> entry : languageMap.entrySet()) {
            fiDAO.updateLanguageFileInfo(repositoryName, entry.getKey(), entry.getValue());
        }
    } catch (Exception e) {
        System.err.println("Erro no projeto " + repositoryName);
        System.err.println(e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) NewFileInfoDAO(aserg.gtf.dao.NewFileInfoDAO) Date(java.util.Date) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) List(java.util.List) FileReader(java.io.FileReader) NewFileInfo(aserg.gtf.model.NewFileInfo)

Aggregations

NewFileInfoDAO (aserg.gtf.dao.NewFileInfoDAO)1 NewFileInfo (aserg.gtf.model.NewFileInfo)1 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1