Search in sources :

Example 1 with LogCommitInfo

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

the class AliasHandler method unifyUsernameByEmail.

/** Treat different names for the same e-mail case */
private void unifyUsernameByEmail(Map<String, List<LogCommitInfo>> usernameMap) {
    for (Entry<String, List<LogCommitInfo>> entry : usernameMap.entrySet()) {
        List<String> names = getNamesList(entry.getValue());
        String newUserName = names.get(0);
        if (names.size() > 1)
            newUserName = getNewName(names);
        for (LogCommitInfo commit : entry.getValue()) {
            commit.setUserName(newUserName);
        }
    }
}
Also used : LogCommitInfo(aserg.gtf.model.LogCommitInfo) List(java.util.List) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 2 with LogCommitInfo

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

the class AliasHandler method execute.

public Map<String, LogCommitInfo> execute(String repositoryName, Map<String, LogCommitInfo> commits) {
    Map<String, List<LogCommitInfo>> usernameMap = new HashMap<String, List<LogCommitInfo>>();
    Set<String> devNames = new HashSet<String>();
    for (LogCommitInfo commit : commits.values()) {
        String commitUsername = commit.getUserName();
        if (!usernameMap.containsKey(commitUsername))
            usernameMap.put(commitUsername, new ArrayList<LogCommitInfo>());
        usernameMap.get(commitUsername).add(commit);
    }
    unifyUsernameByEmail(usernameMap);
    Map<String, List<LogCommitInfo>> namesMap = new HashMap<String, List<LogCommitInfo>>();
    for (LogCommitInfo commit : commits.values()) {
        devNames.add(commit.getMainName());
        String commitDevName = commit.getNormMainName();
        if (!namesMap.containsKey(commitDevName))
            namesMap.put(commitDevName, new ArrayList<LogCommitInfo>());
        namesMap.get(commitDevName).add(commit);
    }
    unifyUsernameByName(namesMap);
    //printAliases(aliases);
    return commits;
}
Also used : HashMap(java.util.HashMap) LogCommitInfo(aserg.gtf.model.LogCommitInfo) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) List(java.util.List) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) HashSet(java.util.HashSet)

Example 3 with LogCommitInfo

use of aserg.gtf.model.LogCommitInfo 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 4 with LogCommitInfo

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

the class NewAliasHandler method getNamesList.

private List<String> getNamesList(Collection<LogCommitInfo> commits) {
    HashSet<String> nameSet = new HashSet<String>();
    List<String> names = new ArrayList<String>();
    for (LogCommitInfo commit : commits) {
        String simplifyedName = commit.getNormMainName().replace(" ", "");
        if (!nameSet.contains(simplifyedName)) {
            nameSet.add(simplifyedName);
            names.add(commit.getMainName());
        }
    }
    return names;
}
Also used : LogCommitInfo(aserg.gtf.model.LogCommitInfo) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) HashSet(java.util.HashSet)

Example 5 with LogCommitInfo

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

the class NewAliasHandler method setNewUsername.

private void setNewUsername(LogCommitInfo commit, String newUsername) {
    List<LogCommitInfo> listCommits = devUsernameMap.get(commit.getUserName());
    devUsernameMap.remove(commit.getUserName());
    for (LogCommitInfo commitAux : listCommits) {
        commitAux.setUserName(newUsername);
    }
    if (!devUsernameMap.containsKey(newUsername))
        devUsernameMap.put(newUsername, listCommits);
    else
        devUsernameMap.get(newUsername).addAll(listCommits);
}
Also used : LogCommitInfo(aserg.gtf.model.LogCommitInfo)

Aggregations

LogCommitInfo (aserg.gtf.model.LogCommitInfo)16 ArrayList (java.util.ArrayList)7 List (java.util.List)6 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)6 LogCommitFileInfo (aserg.gtf.model.LogCommitFileInfo)3 NewFileInfo (aserg.gtf.model.NewFileInfo)3 Repository (aserg.gtf.model.authorship.Repository)3 DOACalculator (aserg.gtf.task.DOACalculator)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 GreedyTruckFactor (aserg.gtf.truckfactor.GreedyTruckFactor)2 TFInfo (aserg.gtf.truckfactor.TFInfo)2 TruckFactor (aserg.gtf.truckfactor.TruckFactor)2 LineInfo (aserg.gtf.util.LineInfo)2 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2 Date (java.util.Date)2 Status (aserg.gtf.model.Status)1 AuthorshipInfo (aserg.gtf.model.authorship.AuthorshipInfo)1