Search in sources :

Example 1 with LogCommitFileInfo

use of aserg.gtf.model.LogCommitFileInfo in project Truck-Factor by aserg-ufmg.

the class DOACalculator method setFileHistory.

private static boolean setFileHistory(File file, Repository repository, NewFileInfo fileInfo, Map<String, List<LogCommitFileInfo>> mapFiles) {
    List<LogCommitFileInfo> fileCommits = mapFiles.get(fileInfo.getPath());
    // Rarely, but some files do not have any commit. Should be verified each case to understand the impact. Normally is irrelevant. 
    if (fileCommits == null) {
        LOGGER.warn("No commits for " + file);
        return false;
    }
    List<LogCommitFileInfo> logFilesObjectInfo = expandCommitFileList(fileCommits, mapFiles);
    String firstAuthor = null;
    for (LogCommitFileInfo commitFile : logFilesObjectInfo) {
        //ci.name, ci.email, lcfi.oldfilename, lcfi.newfilename, lcfi.status, lcfi.id, username
        LogCommitInfo commitInfo = commitFile.getCommitInfo();
        AuthorshipInfo authorshipInfo = repository.getAuthorshipInfo(commitInfo.getAuthorName(), commitInfo.getAuthorEmail(), commitInfo.getUserName(), file);
        Status status = commitFile.getStatus();
        if (status == Status.ADDED) {
            if (firstAuthor == null) {
                //FIRST ADD
                firstAuthor = authorshipInfo.getDeveloper().getNewUserName();
                authorshipInfo.setAsFirstAuthor();
            } else if (!authorshipInfo.isFirstAuthor()) {
                //New ADD made by a different developer of the first add
                String debugStr = String.format("New add;%s;%s;%s;%s", repository.getFullName(), file.getPath(), firstAuthor, authorshipInfo.getDeveloper().getNewUserName());
                LOGGER.debug(debugStr);
                authorshipInfo.setAsSecondaryAuthor();
                authorshipInfo.addNewAddDelivery();
            } else {
                //Treat as delivery if the extra add was made by the first author 
                authorshipInfo.addNewAddDelivery();
            }
        } else if (status == Status.MODIFIED) {
            authorshipInfo.addNewDelivery();
        //file.addNewChange();					
        } else if (status == Status.RENAMED_TREATED) {
            // Considering a rename as a new delivery
            authorshipInfo.addNewDelivery();
        //file.addNewChange();		
        } else
            System.err.println("Invalid Status: " + status);
    }
    double bestDoaValue = 0;
    for (AuthorshipInfo authorshipInfo : file.getAuthorshipInfos()) {
        double authorshipDoa = authorshipInfo.getDOA();
        if (authorshipDoa > bestDoaValue) {
            bestDoaValue = authorshipDoa;
            file.setBestAuthorshipInfo(authorshipInfo);
        }
    }
    double bestDoaValueMult = 0;
    for (AuthorshipInfo authorshipInfo : file.getAuthorshipInfos()) {
        double authorshipDoaMult = authorshipInfo.getDoaMultAuthor();
        if (authorshipDoaMult > bestDoaValueMult) {
            bestDoaValueMult = authorshipDoaMult;
            file.setBestAuthorshipInfoMult(authorshipInfo);
        }
    }
    double bestDoaValueAddDeliveries = 0;
    for (AuthorshipInfo authorshipInfo : file.getAuthorshipInfos()) {
        double authorshipDoaAddDeliveries = authorshipInfo.getDoaAddDeliveries();
        if (authorshipDoaAddDeliveries > bestDoaValueAddDeliveries) {
            bestDoaValueAddDeliveries = authorshipDoaAddDeliveries;
            file.setBestAuthorshipAddDeliveries(authorshipInfo);
        }
    }
    return true;
}
Also used : RepositoryStatus(aserg.gtf.model.authorship.RepositoryStatus) Status(aserg.gtf.model.Status) AuthorshipInfo(aserg.gtf.model.authorship.AuthorshipInfo) LogCommitFileInfo(aserg.gtf.model.LogCommitFileInfo) LogCommitInfo(aserg.gtf.model.LogCommitInfo)

Example 2 with LogCommitFileInfo

use of aserg.gtf.model.LogCommitFileInfo in project Truck-Factor by aserg-ufmg.

the class DOACalculator method expandCommitFileList.

/** Expand commitsfile list by adding renames history 
	 *  Only used when renames are not treated using git facilities */
private static List<LogCommitFileInfo> expandCommitFileList(List<LogCommitFileInfo> logCommitFiles, Map<String, List<LogCommitFileInfo>> mapFiles) {
    Map<String, LogCommitFileInfo> map = new HashMap<String, LogCommitFileInfo>();
    for (LogCommitFileInfo commitFile : logCommitFiles) map.put(commitFile.getTempId().toString(), commitFile);
    while (hasRenamed(map.values())) {
        List<LogCommitFileInfo> tempCommitFiles = new ArrayList<LogCommitFileInfo>(map.values());
        for (LogCommitFileInfo commitFile : tempCommitFiles) {
            Status status = commitFile.getStatus();
            if (status == Status.RENAMED) {
                List<LogCommitFileInfo> newList = mapFiles.get(commitFile.getOldFileName());
                // Some renamed files do not have any commit, even in GitHub.
                if (newList == null) {
                    LOGGER.warn("ERROR in RENAME: No commits for old filename: " + commitFile.getOldFileName());
                } else {
                    for (LogCommitFileInfo newCommitFile : newList) {
                        if (!map.containsKey(newCommitFile.getTempId().toString()))
                            map.put(newCommitFile.getTempId().toString(), newCommitFile);
                    }
                }
                commitFile.setStatus(Status.RENAMED_TREATED);
            }
        }
    }
    return new ArrayList<LogCommitFileInfo>(map.values());
}
Also used : RepositoryStatus(aserg.gtf.model.authorship.RepositoryStatus) Status(aserg.gtf.model.Status) HashMap(java.util.HashMap) LogCommitFileInfo(aserg.gtf.model.LogCommitFileInfo) ArrayList(java.util.ArrayList)

Example 3 with LogCommitFileInfo

use of aserg.gtf.model.LogCommitFileInfo in project Truck-Factor by aserg-ufmg.

the class GitLogExtractor method insertFiles.

private void insertFiles(String projectName, Map<String, LogCommitInfo> mapCommit) throws IOException {
    LOGGER.info(projectName + ": Extracting logCommitFiles...");
    BufferedReader br = new BufferedReader(new FileReader(repositoryPath + "commitfileinfo.log"));
    String sCurrentLine;
    String[] values;
    while ((sCurrentLine = br.readLine()) != null) {
        values = sCurrentLine.split(";");
        String sha = values[0];
        LogCommitInfo commit = mapCommit.get(sha);
        commit.addCommitFile(new LogCommitFileInfo(commit, values[1], values[2], values[3]));
    }
    br.close();
}
Also used : LogCommitFileInfo(aserg.gtf.model.LogCommitFileInfo) LogCommitInfo(aserg.gtf.model.LogCommitInfo) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Example 4 with LogCommitFileInfo

use of aserg.gtf.model.LogCommitFileInfo in project Truck-Factor by aserg-ufmg.

the class DOACalculator method getCommitFilesMap.

private static Map<String, List<LogCommitFileInfo>> getCommitFilesMap(Collection<LogCommitInfo> commits) {
    Map<String, List<LogCommitFileInfo>> map = new HashMap<String, List<LogCommitFileInfo>>();
    for (LogCommitInfo commitInfo : commits) {
        if (commitInfo.getLogCommitFiles() != null) {
            for (LogCommitFileInfo commitFile : commitInfo.getLogCommitFiles()) {
                String fileName = commitFile.getNewFileName();
                if (!map.containsKey(fileName))
                    map.put(fileName, new ArrayList<LogCommitFileInfo>());
                map.get(fileName).add(commitFile);
            }
        }
    }
    return map;
}
Also used : HashMap(java.util.HashMap) LogCommitFileInfo(aserg.gtf.model.LogCommitFileInfo) LogCommitInfo(aserg.gtf.model.LogCommitInfo) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

LogCommitFileInfo (aserg.gtf.model.LogCommitFileInfo)4 LogCommitInfo (aserg.gtf.model.LogCommitInfo)3 Status (aserg.gtf.model.Status)2 RepositoryStatus (aserg.gtf.model.authorship.RepositoryStatus)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 AuthorshipInfo (aserg.gtf.model.authorship.AuthorshipInfo)1 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 List (java.util.List)1