Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyBlaise99 committed Mar 3, 2024
1 parent 41900e9 commit e57b81d
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 43 deletions.
26 changes: 6 additions & 20 deletions src/main/java/reposense/authorship/FileInfoAnalyzer.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package reposense.authorship;

import static reposense.parser.ArgsParser.DEFAULT_ORIGINALITY_THRESHOLD;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -77,19 +75,6 @@ public FileResult analyzeTextFile(RepoConfiguration config, FileInfo fileInfo, b
return generateTextFileResult(fileInfo);
}

/**
* Overloading method for test cases.
* <br>
* Analyzes the lines of the file, given in the {@code fileInfo}, that has changed in the time period provided
* by {@code config}, without further analyzing the authorship of each line in the commit.
* Does not further analyze the authorship of each line in the commit.
* Returns null if the file is missing from the local system, or none of the
* {@link Author} specified in {@code config} contributed to the file in {@code fileInfo}.
*/
public FileResult analyzeTextFile(RepoConfiguration config, FileInfo fileInfo) {
return analyzeTextFile(config, fileInfo, false, DEFAULT_ORIGINALITY_THRESHOLD);
}

/**
* Analyzes the binary file, given in the {@code fileInfo}, that has changed in the time period provided
* by {@code config}.
Expand Down Expand Up @@ -185,7 +170,8 @@ private void aggregateBlameAuthorModifiedAndDateInfo(RepoConfiguration config, F
config.getZoneId());
Author author = config.getAuthor(authorName, authorEmail);

if (!fileInfo.isFileLineTracked(lineCount / 5) || author.isIgnoringFile(filePath)
int lineNumber = lineCount / 5;
if (!fileInfo.isFileLineTracked(lineNumber) || author.isIgnoringFile(filePath)
|| CommitHash.isInsideCommitList(commitHash, config.getIgnoreCommitList())
|| commitDate.isBefore(sinceDate) || commitDate.isAfter(untilDate)) {
author = Author.UNKNOWN_AUTHOR;
Expand All @@ -197,15 +183,15 @@ private void aggregateBlameAuthorModifiedAndDateInfo(RepoConfiguration config, F
MESSAGE_SHALLOW_CLONING_LAST_MODIFIED_DATE_CONFLICT, config.getRepoName()));
}

fileInfo.setLineLastModifiedDate(lineCount / 5, commitDate);
fileInfo.setLineLastModifiedDate(lineNumber, commitDate);
}
fileInfo.setLineAuthor(lineCount / 5, author);
fileInfo.setLineAuthor(lineNumber, author);

if (shouldAnalyzeAuthorship && !author.equals(Author.UNKNOWN_AUTHOR)) {
String lineContent = fileInfo.getLine(lineCount / 5 + 1).getContent();
String lineContent = fileInfo.getLine(lineNumber + 1).getContent();
boolean isFullCredit = AuthorshipAnalyzer.analyzeAuthorship(config, fileInfo.getPath(), lineContent,
commitHash, author, originalityThreshold);
fileInfo.setIsFullCredit(lineCount / 5, isFullCredit);
fileInfo.setIsFullCredit(lineNumber, isFullCredit);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/reposense/model/CliArguments.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public class CliArguments {
private boolean isFindingPreviousAuthorsPerformed;
private boolean isAuthorshipAnalyzed;
private double originalityThreshold;

private boolean isTestMode = ArgsParser.DEFAULT_IS_TEST_MODE;
private boolean isFreshClonePerformed = ArgsParser.DEFAULT_SHOULD_FRESH_CLONE;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/reposense/report/ReportGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ private AnalyzeJobOutput analyzeRepos(String outputPath, List<RepoConfiguration>
CloneJobOutput cloneJobOutput, boolean shouldAnalyzeAuthorship, double originalityThreshold) {
RepoLocation location = cloneJobOutput.getLocation();
boolean cloneSuccessful = cloneJobOutput.isCloneSuccessful();

List<Path> generatedFiles = new ArrayList<>();
List<AnalysisErrorInfo> analysisErrors = new ArrayList<>();
RepoCloner repoCloner = new RepoCloner();
Expand Down
44 changes: 25 additions & 19 deletions src/test/java/reposense/authorship/FileAnalyzerTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package reposense.authorship;

import static reposense.parser.ArgsParser.DEFAULT_ORIGINALITY_THRESHOLD;

import java.time.LocalDateTime;
import java.time.Month;
import java.util.Arrays;
Expand Down Expand Up @@ -160,13 +162,13 @@ public void analyzeTextFile_blameTestFileIgnoreFakeAuthorCommitFullHash_success(
config.setUntilDate(BLAME_TEST_UNTIL_DATE);
FileInfo fileInfoFull = fileInfoExtractor.generateFileInfo(config, "blameTest.java");
config.setIgnoreCommitList(Collections.singletonList(FAKE_AUTHOR_BLAME_TEST_FILE_COMMIT_08022018));
fileInfoAnalyzer.analyzeTextFile(config, fileInfoFull);
analyzeTextFile(config, fileInfoFull);

FileInfo fileInfoShort = fileInfoExtractor.generateFileInfo(config, "blameTest.java");
config.setIgnoreCommitList(
Collections.singletonList(
new CommitHash(FAKE_AUTHOR_BLAME_TEST_FILE_COMMIT_08022018_STRING.substring(0, 8))));
fileInfoAnalyzer.analyzeTextFile(config, fileInfoShort);
analyzeTextFile(config, fileInfoShort);

Assertions.assertEquals(fileInfoFull, fileInfoShort);

Expand All @@ -190,14 +192,14 @@ public void analyzeFile_blameWithPreviousAuthorsIgnoreFirstCommitThatChangedLine

config.setIgnoreCommitList(Collections.singletonList(MAIN_AUTHOR_BLAME_TEST_FILE_COMMIT_06022018));
createTestIgnoreRevsFile(config.getIgnoreCommitList());
fileInfoAnalyzer.analyzeTextFile(config, fileInfoFull);
analyzeTextFile(config, fileInfoFull);
removeTestIgnoreRevsFile();

FileInfo fileInfoShort = fileInfoExtractor.generateFileInfo(config, "blameTest.java");
config.setIgnoreCommitList(Collections.singletonList(
new CommitHash(MAIN_AUTHOR_BLAME_TEST_FILE_COMMIT_06022018_STRING.substring(0, 8))));
new CommitHash(MAIN_AUTHOR_BLAME_TEST_FILE_COMMIT_06022018_STRING.substring(0, 8))));
config.setIgnoreCommitList(createTestIgnoreRevsFile(config.getIgnoreCommitList()));
fileInfoAnalyzer.analyzeTextFile(config, fileInfoShort);
analyzeTextFile(config, fileInfoShort);
removeTestIgnoreRevsFile();

Assertions.assertEquals(fileInfoFull, fileInfoShort);
Expand All @@ -217,13 +219,13 @@ public void analyzeTextFile_blameTestFileIgnoreAllCommit_success() {
FileInfo fileInfoFull = fileInfoExtractor.generateFileInfo(config, "blameTest.java");
config.setIgnoreCommitList(Arrays.asList(FAKE_AUTHOR_BLAME_TEST_FILE_COMMIT_08022018,
MAIN_AUTHOR_BLAME_TEST_FILE_COMMIT_06022018));
fileInfoAnalyzer.analyzeTextFile(config, fileInfoFull);
analyzeTextFile(config, fileInfoFull);

FileInfo fileInfoShort = fileInfoExtractor.generateFileInfo(config, "blameTest.java");
config.setIgnoreCommitList(CommitHash.convertStringsToCommits(
Arrays.asList(FAKE_AUTHOR_BLAME_TEST_FILE_COMMIT_08022018_STRING.substring(0, 8),
MAIN_AUTHOR_BLAME_TEST_FILE_COMMIT_06022018_STRING.substring(0, 8))));
fileInfoAnalyzer.analyzeTextFile(config, fileInfoShort);
analyzeTextFile(config, fileInfoShort);

Assertions.assertEquals(fileInfoFull, fileInfoShort);
fileInfoFull.getLines().forEach(lineInfo ->
Expand All @@ -242,7 +244,7 @@ public void analyzeFile_blameWithPreviousAuthorTestFileIgnoreAllCommit_success()
config.setIgnoreCommitList(Arrays.asList(FAKE_AUTHOR_BLAME_TEST_FILE_COMMIT_08022018,
MAIN_AUTHOR_BLAME_TEST_FILE_COMMIT_06022018, AUTHOR_TO_IGNORE_BLAME_TEST_FILE_COMMIT_07082021));
createTestIgnoreRevsFile(config.getIgnoreCommitList());
fileInfoAnalyzer.analyzeTextFile(config, fileInfoFull);
analyzeTextFile(config, fileInfoFull);
removeTestIgnoreRevsFile();

FileInfo fileInfoShort = fileInfoExtractor.generateFileInfo(config, "blameTest.java");
Expand All @@ -251,7 +253,7 @@ public void analyzeFile_blameWithPreviousAuthorTestFileIgnoreAllCommit_success()
MAIN_AUTHOR_BLAME_TEST_FILE_COMMIT_06022018_STRING.substring(0, 8),
AUTHOR_TO_IGNORE_BLAME_TEST_FILE_COMMIT_07082021_STRING.substring(0, 8))));
createTestIgnoreRevsFile(config.getIgnoreCommitList());
fileInfoAnalyzer.analyzeTextFile(config, fileInfoShort);
analyzeTextFile(config, fileInfoShort);
removeTestIgnoreRevsFile();

Assertions.assertEquals(fileInfoFull, fileInfoShort);
Expand All @@ -265,14 +267,14 @@ public void analyzeTextFile_blameTestFileIgnoreRangedCommit_success() {
config.setUntilDate(BLAME_TEST_UNTIL_DATE);
FileInfo fileInfoFull = fileInfoExtractor.generateFileInfo(config, "blameTest.java");
config.setIgnoreCommitList(FAKE_AUTHOR_BLAME_RANGED_COMMIT_LIST_09022018);
fileInfoAnalyzer.analyzeTextFile(config, fileInfoFull);
analyzeTextFile(config, fileInfoFull);

FileInfo fileInfoRanged = fileInfoExtractor.generateFileInfo(config, "blameTest.java");
String rangedCommit = FAKE_AUTHOR_BLAME_RANGED_COMMIT_ONE_06022018_STRING + ".."
+ FAKE_AUTHOR_BLAME_RANGED_COMMIT_FOUR_08022018_STRING;
config.setIgnoreCommitList(CommitHash.getHashes(config.getRepoRoot(), config.getBranch(),
new CommitHash(rangedCommit)).collect(Collectors.toList()));
fileInfoAnalyzer.analyzeTextFile(config, fileInfoRanged);
analyzeTextFile(config, fileInfoRanged);

Assertions.assertEquals(fileInfoFull, fileInfoRanged);
fileInfoFull.getLines().forEach(lineInfo ->
Expand All @@ -285,14 +287,14 @@ public void analyzeTextFile_blameTestFileIgnoreRangedCommitShort_success() {
config.setUntilDate(BLAME_TEST_UNTIL_DATE);
FileInfo fileInfoFull = fileInfoExtractor.generateFileInfo(config, "blameTest.java");
config.setIgnoreCommitList(FAKE_AUTHOR_BLAME_RANGED_COMMIT_LIST_09022018);
fileInfoAnalyzer.analyzeTextFile(config, fileInfoFull);
analyzeTextFile(config, fileInfoFull);

FileInfo fileInfoRangedShort = fileInfoExtractor.generateFileInfo(config, "blameTest.java");
String rangedCommitShort = FAKE_AUTHOR_BLAME_RANGED_COMMIT_ONE_06022018_STRING.substring(0, 8) + ".."
+ FAKE_AUTHOR_BLAME_RANGED_COMMIT_FOUR_08022018_STRING.substring(0, 8);
config.setIgnoreCommitList(CommitHash.getHashes(config.getRepoRoot(), config.getBranch(),
new CommitHash(rangedCommitShort)).collect(Collectors.toList()));
fileInfoAnalyzer.analyzeTextFile(config, fileInfoRangedShort);
analyzeTextFile(config, fileInfoRangedShort);

Assertions.assertEquals(fileInfoFull, fileInfoRangedShort);
fileInfoFull.getLines().forEach(lineInfo ->
Expand All @@ -309,7 +311,7 @@ public void analyzeTextFile_emailWithAdditionOperator_success() {
config.setAuthorList(Collections.singletonList(author));

FileInfo fileInfo = fileInfoExtractor.generateFileInfo(config, "pr_617.java");
fileInfoAnalyzer.analyzeTextFile(config, fileInfo);
analyzeTextFile(config, fileInfo);

Assertions.assertEquals(1, fileInfo.getLines().size());
fileInfo.getLines().forEach(lineInfo -> Assertions.assertEquals(author, lineInfo.getAuthor()));
Expand All @@ -326,7 +328,7 @@ public void analyzeTextFile_shouldIncludeLastModifiedDateInLines_success() {
config.setAuthorList(Collections.singletonList(author));

FileInfo fileInfo = fileInfoExtractor.generateFileInfo(config, "includeLastModifiedDateInLinesTest.java");
fileInfoAnalyzer.analyzeTextFile(config, fileInfo);
analyzeTextFile(config, fileInfo);

Assertions.assertEquals(4, fileInfo.getLines().size());
fileInfo.getLines().forEach(lineInfo ->
Expand All @@ -341,7 +343,7 @@ public void analyzeTextFile_fileExceedingFileSizeLimit_success() {
GitCheckout.checkoutBranch(config.getRepoRoot(), config.getBranch());

FileInfo fileInfo = fileInfoExtractor.generateFileInfo(config, "largeFile.json");
fileInfoAnalyzer.analyzeTextFile(config, fileInfo);
analyzeTextFile(config, fileInfo);

Assertions.assertEquals(46902, fileInfo.getLines().size());
Assertions.assertEquals(fileInfo.getFileSize() > config.getFileSizeLimit(), fileInfo.exceedsFileLimit());
Expand All @@ -355,7 +357,7 @@ public void analyzeBinaryFile_shouldSetLinesToBeEmpty_success() {
GitCheckout.checkoutBranch(config.getRepoRoot(), config.getBranch());
List<FileInfo> binaryFileInfos = fileInfoExtractor.extractBinaryFileInfos(config);

for (FileInfo binaryFileInfo: binaryFileInfos) {
for (FileInfo binaryFileInfo : binaryFileInfos) {
fileInfoAnalyzer.analyzeBinaryFile(config, binaryFileInfo);
Assertions.assertEquals(0, binaryFileInfo.getLines().size());
}
Expand All @@ -371,7 +373,7 @@ public void analyzeBinaryFile_nonExistingFilePath_success() {
List<FileInfo> binaryFileInfos = Arrays.asList(new FileInfo("/nonExistingJpgPicture.jpg"),
new FileInfo("/nonExistingPngPicture.png"));

for (FileInfo binaryFileInfo: binaryFileInfos) {
for (FileInfo binaryFileInfo : binaryFileInfos) {
Assertions.assertNull(fileInfoAnalyzer.analyzeBinaryFile(config, binaryFileInfo));
}
}
Expand All @@ -390,7 +392,11 @@ public void analyzeFile_filesWithEmptyEmailCommit_success() {
FileInfo textFileInfo = fileInfos.get(0);
FileInfo binaryFileInfo = new FileInfo("empty-email-commit-binary-file.png");

Assertions.assertNotNull(fileInfoAnalyzer.analyzeTextFile(config, textFileInfo));
Assertions.assertNotNull(analyzeTextFile(config, textFileInfo));
Assertions.assertNotNull(fileInfoAnalyzer.analyzeBinaryFile(config, binaryFileInfo));
}

private FileResult analyzeTextFile(RepoConfiguration config, FileInfo fileInfo) {
return fileInfoAnalyzer.analyzeTextFile(config, fileInfo, false, DEFAULT_ORIGINALITY_THRESHOLD);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package reposense.authorship;

import static reposense.parser.ArgsParser.DEFAULT_ORIGINALITY_THRESHOLD;

import java.time.LocalDateTime;
import java.time.Month;
import java.util.ArrayList;
Expand Down Expand Up @@ -49,10 +51,10 @@ public void aggregateFileResult_clearFileLines_success() {

List<FileResult> fileResults = textFileInfos.stream()
.filter(f -> !f.getPath().equals("annotationTest.java"))
.map(fileInfo -> fileInfoAnalyzer.analyzeTextFile(config, fileInfo))
.map(fileInfo -> fileInfoAnalyzer.analyzeTextFile(config, fileInfo, false,
DEFAULT_ORIGINALITY_THRESHOLD))
.filter(Objects::nonNull)
.collect(Collectors.toList());
//

FileResultAggregator fileResultAggregator = new FileResultAggregator();
fileResultAggregator.aggregateFileResult(fileResults, config.getAuthorList(), config.getAllFileTypes());
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/reposense/template/GitTestTemplate.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package reposense.template;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static reposense.parser.ArgsParser.DEFAULT_ORIGINALITY_THRESHOLD;

import java.io.File;
import java.time.ZoneId;
Expand Down Expand Up @@ -195,7 +196,7 @@ public void assertFileAnalysisCorrectness(FileResult fileResult, List<Author> ex

public FileResult getFileResult(String relativePath) {
FileInfo fileInfo = fileInfoExtractor.generateFileInfo(configs.get(), relativePath);
return fileInfoAnalyzer.analyzeTextFile(configs.get(), fileInfo);
return fileInfoAnalyzer.analyzeTextFile(configs.get(), fileInfo, false, DEFAULT_ORIGINALITY_THRESHOLD);
}

/**
Expand Down

0 comments on commit e57b81d

Please sign in to comment.