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;
}
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());
}
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();
}
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;
}
Aggregations