From 9ff7a96c6afd5b8837da8ee1ba44b263670ae391 Mon Sep 17 00:00:00 2001 From: jonasongg <120372506+jonasongg@users.noreply.github.com> Date: Sat, 17 Feb 2024 02:43:22 +0800 Subject: [PATCH 1/2] [#2111] Fix failing zoomFeature cypress test (#2114) Fix nondeterministically failing zoomFeature cypress test The "range changes in chartview should reflect in zoom" test in chartView_zoomFeature.cy.js fails because as time passes, the coordinates in the ramp that correspond to the desired zoom area change. Let's add an "until" filter to the relevant cypress tests to stop this from happening --- .../tests/chartView/chartView_zoomFeature.cy.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/frontend/cypress/tests/chartView/chartView_zoomFeature.cy.js b/frontend/cypress/tests/chartView/chartView_zoomFeature.cy.js index ac8599ef95..4bb5e03a0b 100644 --- a/frontend/cypress/tests/chartView/chartView_zoomFeature.cy.js +++ b/frontend/cypress/tests/chartView/chartView_zoomFeature.cy.js @@ -251,6 +251,9 @@ describe('range changes in chartview should reflect in zoom', () => { cy.get('div.mui-textfield.search_box > input:visible') .should('be.visible') .type('jamessspanggg'); + cy.get('input[name="until"]:visible') + .type('2023-12-31'); + cy.get('body').type(zoomKey, { release: false }) .get('#summary-charts .summary-chart__ramp .ramp') .first() @@ -277,6 +280,9 @@ describe('range changes in chartview should reflect in zoom', () => { cy.get('div.mui-textfield.search_box > input:visible') .should('be.visible') .type('jamessspanggg'); + cy.get('input[name="until"]:visible') + .type('2023-12-31'); + cy.get('body').type(zoomKey, { release: false }) .get('#summary-charts .summary-chart__ramp .ramp') .first() @@ -303,6 +309,9 @@ describe('range changes in chartview should reflect in zoom', () => { cy.get('div.mui-textfield.search_box > input:visible') .should('be.visible') .type('jamessspanggg'); + cy.get('input[name="until"]:visible') + .type('2023-12-31'); + cy.get('body').type(zoomKey, { release: false }) .get('#summary-charts .summary-chart__ramp .ramp') .first() @@ -329,6 +338,8 @@ describe('range changes in chartview should reflect in zoom', () => { cy.get('div.mui-textfield.search_box > input:visible') .should('be.visible') .type('jamessspanggg'); + cy.get('input[name="until"]:visible') + .type('2023-12-31'); cy.get('body').type(zoomKey, { release: false }) .get('#summary-charts .summary-chart__ramp .ramp') From d2018d246e74fa04ae70d2f1f0f16c9e8e29e187 Mon Sep 17 00:00:00 2001 From: George Tay Date: Sat, 17 Feb 2024 02:58:45 +0800 Subject: [PATCH 2/2] [#2076] Refactor RepoConfiguration to simplify constructor complexity (#2078) Refactor RepoConfiguration to simplify constructor complexity. Currently, the constructors for the `RepoConfiguration` class is very complex, involving up to 18 parameters at once, and is not easily extensible. With the proposed changes, the constructor now follows the Builder pattern, by using a nested class `Builder` that helps to compose config parameters in a way that is much more modular and comprehensible, enhancing code quality and reducing confusion among developers. However, it must be noted that `Builder` objects are not reusable as of now, and that more combinations of arguments are permitted due to the removal of constructors for `RepoBuilder`, which previously helped to ensure the correctness of parameter combinations. Let's refactor `RepoConfiguration` to simplify the complexity of the constructor and increase modularity of the code. --- .../reposense/model/CliRunConfiguration.java | 6 +- .../reposense/model/RepoConfiguration.java | 482 +++++++++++++++--- .../parser/ConfigurationBuildException.java | 8 + .../reposense/parser/RepoConfigCsvParser.java | 24 +- .../java/reposense/LocalRepoSystemTest.java | 16 +- .../java/reposense/git/GitBranchTest.java | 6 +- .../model/RepoConfigurationTest.java | 297 +++++++++-- .../parser/RepoConfigParserTest.java | 28 +- .../StandaloneConfigJsonParserTest.java | 9 +- .../java/reposense/report/RepoClonerTest.java | 9 +- .../reposense/template/GitTestTemplate.java | 7 +- 11 files changed, 734 insertions(+), 158 deletions(-) create mode 100644 src/main/java/reposense/parser/ConfigurationBuildException.java diff --git a/src/main/java/reposense/model/CliRunConfiguration.java b/src/main/java/reposense/model/CliRunConfiguration.java index 7be82b5616..8d7e19c7e0 100644 --- a/src/main/java/reposense/model/CliRunConfiguration.java +++ b/src/main/java/reposense/model/CliRunConfiguration.java @@ -31,7 +31,11 @@ public List getRepoConfigurations() throws ParseException { List configs = new ArrayList<>(); for (String locationString : cliArguments.getLocations()) { try { - configs.add(new RepoConfiguration(new RepoLocation(locationString))); + configs.add( + new RepoConfiguration.Builder() + .location(new RepoLocation(locationString)) + .build() + ); } catch (InvalidLocationException ile) { logger.log(Level.WARNING, ile.getMessage(), ile); } diff --git a/src/main/java/reposense/model/RepoConfiguration.java b/src/main/java/reposense/model/RepoConfiguration.java index 3db17466ce..8466cfb52b 100644 --- a/src/main/java/reposense/model/RepoConfiguration.java +++ b/src/main/java/reposense/model/RepoConfiguration.java @@ -7,11 +7,13 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.logging.Logger; import java.util.stream.Collectors; import reposense.git.GitBranch; import reposense.git.exception.GitBranchException; +import reposense.parser.ConfigurationBuildException; import reposense.system.LogsManager; import reposense.util.FileUtil; @@ -25,96 +27,422 @@ public class RepoConfiguration { private static final Logger logger = LogsManager.getLogger(RepoConfiguration.class); private RepoLocation location; - private String branch; + private String branch = DEFAULT_BRANCH; private String displayName; private String outputFolderName; - private final transient String extraOutputFolderName; + private transient String extraOutputFolderName = DEFAULT_EXTRA_OUTPUT_FOLDER_NAME; private transient ZoneId zoneId; private transient LocalDateTime sinceDate; private transient LocalDateTime untilDate; private transient String repoFolderName; - private transient FileTypeManager fileTypeManager; + private transient FileTypeManager fileTypeManager = new FileTypeManager(Collections.emptyList()); private transient List ignoreGlobList = new ArrayList<>(); private transient List ignoredAuthorsList = new ArrayList<>(); private transient AuthorConfiguration authorConfig; - private transient boolean isStandaloneConfigIgnored; - private transient boolean isFileSizeLimitIgnored; - private transient List ignoreCommitList; + private transient boolean isStandaloneConfigIgnored = false; + private transient boolean isFileSizeLimitIgnored = false; + private transient List ignoreCommitList = Collections.emptyList(); private transient boolean isLastModifiedDateIncluded; - private transient boolean isShallowCloningPerformed; - private transient boolean isFindingPreviousAuthorsPerformed; - private transient boolean isFormatsOverriding; + private transient boolean isShallowCloningPerformed = false; + private transient boolean isFindingPreviousAuthorsPerformed = false; + private transient boolean isFormatsOverriding = false; private transient boolean isIgnoreGlobListOverriding; - private transient boolean isIgnoreCommitListOverriding; + private transient boolean isIgnoreCommitListOverriding = false; private transient boolean isIgnoredAuthorsListOverriding; - private transient long fileSizeLimit; - private transient boolean isFileSizeLimitOverriding; - private transient boolean isIgnoredFileAnalysisSkipped; - - public RepoConfiguration(RepoLocation location) { - this(location, DEFAULT_BRANCH); - } - - public RepoConfiguration(RepoLocation location, String branch) { - this(location, branch, DEFAULT_EXTRA_OUTPUT_FOLDER_NAME); - } - - public RepoConfiguration(RepoLocation location, String branch, String extraOutputFolderName) { - this(location, branch, Collections.emptyList(), Collections.emptyList(), - RepoConfiguration.DEFAULT_FILE_SIZE_LIMIT, false, false, Collections.emptyList(), false, false, false, - false, false, false, false, Collections.emptyList(), false, extraOutputFolderName); - } - - public RepoConfiguration(RepoLocation location, String branch, List formats, List ignoreGlobList, - long fileSizeLimit, boolean isStandaloneConfigIgnored, boolean isFileSizeLimitIgnored, - List ignoreCommitList, boolean isFormatsOverriding, boolean isIgnoreGlobListOverriding, - boolean isIgnoreCommitListOverriding, boolean isFileSizeLimitOverriding, boolean isShallowCloningPerformed, - boolean isFindingPreviousAuthorsPerformed, boolean isIgnoredFileAnalysisSkipped, - List ignoredAuthorsList, boolean isIgnoredAuthorsListOverriding) { - this(location, branch, formats, ignoreGlobList, fileSizeLimit, isStandaloneConfigIgnored, - isFileSizeLimitIgnored, ignoreCommitList, isFormatsOverriding, isIgnoreGlobListOverriding, - isIgnoreCommitListOverriding, isFileSizeLimitOverriding, isShallowCloningPerformed, - isFindingPreviousAuthorsPerformed, isIgnoredFileAnalysisSkipped, ignoredAuthorsList, - isIgnoredAuthorsListOverriding, DEFAULT_EXTRA_OUTPUT_FOLDER_NAME); - } - - public RepoConfiguration(RepoLocation location, String branch, List formats, List ignoreGlobList, - long fileSizeLimit, boolean isStandaloneConfigIgnored, boolean isFileSizeLimitIgnored, - List ignoreCommitList, boolean isFormatsOverriding, boolean isIgnoreGlobListOverriding, - boolean isIgnoreCommitListOverriding, boolean isFileSizeLimitOverriding, boolean isShallowCloningPerformed, - boolean isFindingPreviousAuthorsPerformed, boolean isIgnoredFileAnalysisSkipped, - List ignoredAuthorsList, boolean isIgnoredAuthorsListOverriding, String extraOutputFolderName) { - this.authorConfig = new AuthorConfiguration(location, branch); - this.location = location; - this.branch = location.isEmpty() ? DEFAULT_BRANCH : branch; - this.ignoreGlobList = ignoreGlobList; - this.fileSizeLimit = fileSizeLimit; - this.isStandaloneConfigIgnored = isStandaloneConfigIgnored; - this.isFileSizeLimitIgnored = isFileSizeLimitIgnored; - this.fileTypeManager = new FileTypeManager(formats); - this.ignoreCommitList = ignoreCommitList; - this.isFormatsOverriding = isFormatsOverriding; - this.isIgnoreGlobListOverriding = isIgnoreGlobListOverriding; - this.isIgnoreCommitListOverriding = isIgnoreCommitListOverriding; - this.isFileSizeLimitOverriding = isFileSizeLimitOverriding; - this.isShallowCloningPerformed = isShallowCloningPerformed; - this.isFindingPreviousAuthorsPerformed = isFindingPreviousAuthorsPerformed; - this.isIgnoredFileAnalysisSkipped = isIgnoredFileAnalysisSkipped; - this.ignoredAuthorsList = ignoredAuthorsList; - this.isIgnoredAuthorsListOverriding = isIgnoredAuthorsListOverriding; - this.extraOutputFolderName = extraOutputFolderName; - - String organization = location.getOrganization(); - String repoName = location.getRepoName(); - displayName = repoName + "[" + branch + "]"; - outputFolderName = repoName + "_" + branch; - repoFolderName = repoName; - - if (!organization.isEmpty()) { - repoFolderName = organization + "_" + repoFolderName; - displayName = organization + "/" + displayName; - outputFolderName = organization + "_" + outputFolderName; + private transient long fileSizeLimit = DEFAULT_FILE_SIZE_LIMIT; + private transient boolean isFileSizeLimitOverriding = false; + private transient boolean isIgnoredFileAnalysisSkipped = false; + + /** + * Constructs an empty instance of {@code RepoConfiguration}, which is used by the {@code Builder} + * to construct new {@code RepoConfiguration} instances. + */ + private RepoConfiguration() {} + + /** + * Builds the necessary configurations for RepoConfiguration. + * Obeys the Builder pattern as described in {@link CliArguments}. + */ + public static class Builder { + private String displayName; + private String outputFolderName; + private String repoFolderName; + private RepoConfiguration repoConfiguration; + + /** + * Returns an empty instance of the RepoConfiguration Builder. + */ + public Builder() { + this.repoConfiguration = new RepoConfiguration(); + } + + /** + * Processes the author configuration of the repository. + */ + private void processAuthor() { + this.repoConfiguration.authorConfig = new AuthorConfiguration( + this.repoConfiguration.location, + this.repoConfiguration.branch); + } + + /** + * Processes the branch of the repository. + */ + private void processBranch() { + this.repoConfiguration.branch = this.repoConfiguration.location.isEmpty() + ? DEFAULT_BRANCH + : this.repoConfiguration.branch; + } + + /** + * Processes the relevant names of the repository configs. + */ + private void processNames() { + String repoName = this.repoConfiguration.location.getRepoName(); + String org = this.repoConfiguration.location.getOrganization(); + + String defaultDisplayName = repoName + "[" + this.repoConfiguration.branch + "]"; + String defaultOutputFolderName = repoName + "_" + this.repoConfiguration.branch; + String defaultRepoFolderName = repoName; + + if (!org.isEmpty()) { + defaultDisplayName = org + "/" + defaultDisplayName; + defaultRepoFolderName = org + "_" + defaultRepoFolderName; + defaultOutputFolderName = org + "_" + defaultOutputFolderName; + } + + this.repoConfiguration.displayName = Optional.ofNullable(this.displayName) + .orElse(defaultDisplayName); + this.repoConfiguration.outputFolderName = Optional.ofNullable(this.outputFolderName) + .orElse(defaultOutputFolderName); + this.repoConfiguration.repoFolderName = Optional.ofNullable(this.repoFolderName) + .orElse(defaultRepoFolderName); + } + + /** + * Updates the {@code location} for {@code RepoConfiguration}. + * + * @param location A repository location. + * @return This builder object + */ + public Builder location(RepoLocation location) { + this.repoConfiguration.location = location; + return this; + } + + /** + * Updates the {@code branch} for {@code RepoConfiguration}. + * + * @param branch Branch of the repository of interest. + * @return This builder object. + */ + public Builder branch(String branch) { + this.repoConfiguration.branch = branch; + return this; + } + + /** + * Updates the {@code displayName} for {@code RepoConfiguration}. + * + * @param displayName Display name of the repository. + * @return This builder object. + */ + public Builder displayName(String displayName) { + this.displayName = displayName; + this.repoConfiguration.displayName = displayName; + return this; + } + + /** + * Updates the {@code outputFolderName} for {@code RepoConfiguration}. + * + * @param outputFolderName Output folder name of the repository. + * @return This builder object. + */ + public Builder outputFolderName(String outputFolderName) { + this.outputFolderName = outputFolderName; + this.repoConfiguration.outputFolderName = outputFolderName; + return this; + } + + /** + * Updates the {@code extraOutputFolderName} for {@code RepoConfiguration}. + * + * @param extraOutputFolderName Extra output folder name of the repository. + * @return This builder object. + */ + public Builder extraOutputFolderName(String extraOutputFolderName) { + this.repoConfiguration.extraOutputFolderName = extraOutputFolderName; + return this; + } + + /** + * Updates the {@code zoneId} for {@code RepoConfiguration}. + * + * @param zoneId Time-zone of the repository. + * @return This builder object. + */ + public Builder zoneId(ZoneId zoneId) { + this.repoConfiguration.zoneId = zoneId; + return this; + } + + /** + * Updates the {@code sinceDate} for {@code RepoConfiguration}. + * + * @param sinceDate Starting date of analysis. + * @return This builder object. + */ + public Builder sinceDate(LocalDateTime sinceDate) { + this.repoConfiguration.sinceDate = sinceDate; + return this; + } + + /** + * Updates the {@code untilDate} for {@code RepoConfiguration}. + * + * @param untilDate Ending date of analysis. + * @return This builder object. + */ + public Builder untilDate(LocalDateTime untilDate) { + this.repoConfiguration.untilDate = untilDate; + return this; + } + + /** + * Updates the {@code repoFolderName} for {@code RepoConfiguration}. + * + * @param repoFolderName Folder name of the repository. + * @return This builder object. + */ + public Builder repoFolderName(String repoFolderName) { + this.repoFolderName = repoFolderName; + this.repoConfiguration.repoFolderName = repoFolderName; + return this; + } + + /** + * Updates the {@code fileTypeManager} for {@code RepoConfiguration}. + * + * @param fileTypes List of file types and groupings permitted. + * @return This builder object. + */ + public Builder fileTypeManager(List fileTypes) { + this.repoConfiguration.fileTypeManager = new FileTypeManager(fileTypes); + return this; + } + + /** + * Updates the {@code ignoreGlobList} for {@code RepoConfiguration}. + * + * @param ignoredGlobList List of glob patterns to ignore. + * @return This builder object. + */ + public Builder ignoreGlobList(List ignoredGlobList) { + this.repoConfiguration.ignoreGlobList = ignoredGlobList; + return this; + } + + /** + * Updates the {@code ignoredAuthorsList} for {@code RepoConfiguration}. + * + * @param ignoredAuthorsList List of authors to ignore. + * @return This builder object. + */ + public Builder ignoredAuthorsList(List ignoredAuthorsList) { + this.repoConfiguration.ignoredAuthorsList = ignoredAuthorsList; + return this; + } + + /** + * Updates the {@code authorConfig} for {@code RepoConfiguration}. + * + * @param authorConfig Author configuration information of the repository. + * @return This builder object. + */ + public Builder authorConfig(AuthorConfiguration authorConfig) { + this.repoConfiguration.authorConfig = authorConfig; + return this; + } + + /** + * Updates the {@code isStandaloneConfigIgnored} for {@code RepoConfiguration}. + * + * @param isStandaloneConfigIgnored Checks if standalone config is ignored. + * @return This builder object. + */ + public Builder isStandaloneConfigIgnored(boolean isStandaloneConfigIgnored) { + this.repoConfiguration.isStandaloneConfigIgnored = isStandaloneConfigIgnored; + return this; + } + + /** + * Updates the {@code isFileSizeLimitIgnored} for {@code RepoConfiguration}. + * + * @param isFileSizeLimitIgnored Checks if file size limit is ignored. + * @return This builder object. + */ + public Builder isFileSizeLimitIgnored(boolean isFileSizeLimitIgnored) { + this.repoConfiguration.isFileSizeLimitIgnored = isFileSizeLimitIgnored; + return this; + } + + /** + * Updates the {@code ignoreCommitList} for {@code RepoConfiguration}. + * + * @param ignoreCommitList List of commits to ignore. + * @return This builder object. + */ + public Builder ignoreCommitList(List ignoreCommitList) { + this.repoConfiguration.ignoreCommitList = ignoreCommitList; + return this; + } + + /** + * Updates the {@code isLastModifiedDateIncluded} for {@code RepoConfiguration}. + * + * @param isLastModifiedDateIncluded Checks if last modified date is included. + * @return This builder object. + */ + public Builder isLastModifiedDateIncluded(boolean isLastModifiedDateIncluded) { + this.repoConfiguration.isLastModifiedDateIncluded = isLastModifiedDateIncluded; + return this; + } + + /** + * Updates the {@code isShallowCloningPerformed} for {@code RepoConfiguration}. + * + * @param isShallowCloningPerformed Checks if shallow cloning is performed. + * @return This builder object. + */ + public Builder isShallowCloningPerformed(boolean isShallowCloningPerformed) { + this.repoConfiguration.isShallowCloningPerformed = isShallowCloningPerformed; + return this; + } + + /** + * Updates the {@code isFindingPreviousAuthorsPerformed} for {@code RepoConfiguration}. + * + * @param isFindingPreviousAuthorsPerformed Checks if finding previous authors is performed. + * @return This builder object. + */ + public Builder isFindingPreviousAuthorsPerformed(boolean isFindingPreviousAuthorsPerformed) { + this.repoConfiguration.isFindingPreviousAuthorsPerformed = isFindingPreviousAuthorsPerformed; + return this; + } + + /** + * Updates the {@code isFormatsOverriding} for {@code RepoConfiguration}. + * + * @param isFormatsOverriding Checks if file formats are overridden. + * @return This builder object. + */ + public Builder isFormatsOverriding(boolean isFormatsOverriding) { + this.repoConfiguration.isFormatsOverriding = isFormatsOverriding; + return this; + } + + /** + * Updates the {@code isIgnoreGlobListOverriding} for {@code RepoConfiguration}. + * + * @param isIgnoreGlobListOverriding Checks if the list of ignored glob is overridden. + * @return This builder object. + */ + public Builder isIgnoreGlobListOverriding(boolean isIgnoreGlobListOverriding) { + this.repoConfiguration.isIgnoreGlobListOverriding = isIgnoreGlobListOverriding; + return this; + } + + /** + * Updates the {@code isIgnoreCommitListOverriding} for {@code RepoConfiguration}. + * + * @param isIgnoreCommitListOverriding Checks if the list of ignored commits is overridden. + * @return This builder object. + */ + public Builder isIgnoreCommitListOverriding(boolean isIgnoreCommitListOverriding) { + this.repoConfiguration.isIgnoreCommitListOverriding = isIgnoreCommitListOverriding; + return this; + } + + /** + * Updates the {@code isFileSizeLimitOverriding} for {@code RepoConfiguration}. + * + * @param isIgnoredAuthorsListOverriding Checks if the list of ignored authors is overridden. + * @return This builder object. + */ + public Builder isIgnoredAuthorsListOverriding(boolean isIgnoredAuthorsListOverriding) { + this.repoConfiguration.isIgnoredAuthorsListOverriding = isIgnoredAuthorsListOverriding; + return this; + } + + /** + * Updates the {@code fileSizeLimit} for {@code RepoConfiguration}. + * + * @param fileSizeLimit File size limit of the repository. + * @return This builder object. + */ + public Builder fileSizeLimit(long fileSizeLimit) { + this.repoConfiguration.fileSizeLimit = fileSizeLimit; + return this; + } + + /** + * Updates the {@code isFileSizeLimitOverriding} for {@code RepoConfiguration}. + * + * @param isFileSizeLimitOverriding Checks if the file size limit is overridden. + * @return This builder object. + */ + public Builder isFileSizeLimitOverriding(boolean isFileSizeLimitOverriding) { + this.repoConfiguration.isFileSizeLimitOverriding = isFileSizeLimitOverriding; + return this; + } + + /** + * Updates the {@code isIgnoredFileAnalysisSkipped} for {@code RepoConfiguration}. + * + * @param isIgnoredFileAnalysisSkipped Checks if the analysis of ignored files is skipped. + * @return This builder object. + */ + public Builder isIgnoredFileAnalysisSkipped(boolean isIgnoredFileAnalysisSkipped) { + this.repoConfiguration.isIgnoredFileAnalysisSkipped = isIgnoredFileAnalysisSkipped; + return this; + } + + /** + * Builds the {@code RepoConfiguration} object with the necessary configurations. + * + * @return {@code RepoConfiguration}. + * @throws ConfigurationBuildException if there was an issue building the {@code RepoConfiguration} + * object. + */ + public RepoConfiguration build() { + if (!validate()) { + throw new ConfigurationBuildException(); + } + + this.processAuthor(); + this.processBranch(); + this.processNames(); + + // save a reference to the current built object + RepoConfiguration toReturn = this.repoConfiguration; + + // reset the internal reference to avoid aliasing + this.repoConfiguration = new RepoConfiguration(); + + // return the reference to the built RepoConfiguration object + return toReturn; + } + + /** + * Checks if the current {@code RepoConfiguration} object contains all the necessary parameters + * needed to build successfully. + * + * @return true if the {@code RepoConfiguration} object contains all the necessary parameters else false + */ + private boolean validate() { + return Optional.ofNullable(this.repoConfiguration.location).isPresent(); } } diff --git a/src/main/java/reposense/parser/ConfigurationBuildException.java b/src/main/java/reposense/parser/ConfigurationBuildException.java new file mode 100644 index 0000000000..fd1f43fea8 --- /dev/null +++ b/src/main/java/reposense/parser/ConfigurationBuildException.java @@ -0,0 +1,8 @@ +package reposense.parser; + +/** + * Signals that there was an issue building a Configuration (missing parameters, etc.). + */ +public class ConfigurationBuildException extends RuntimeException { + +} diff --git a/src/main/java/reposense/parser/RepoConfigCsvParser.java b/src/main/java/reposense/parser/RepoConfigCsvParser.java index fd045e3c07..e504669191 100644 --- a/src/main/java/reposense/parser/RepoConfigCsvParser.java +++ b/src/main/java/reposense/parser/RepoConfigCsvParser.java @@ -172,11 +172,25 @@ private void addConfig(List results, RepoLocation location, S boolean isIgnoredFileAnalysisSkipped, boolean isFileSizeLimitOverriding, long fileSizeLimit, boolean isStandaloneConfigIgnored, boolean isShallowCloningPerformed, boolean isFindingPreviousAuthorsPerformed) { - RepoConfiguration config = new RepoConfiguration(location, branch, formats, ignoreGlobList, fileSizeLimit, - isStandaloneConfigIgnored, isFileSizeLimitIgnored, ignoreCommitList, isFormatsOverriding, - isIgnoreGlobListOverriding, isIgnoreCommitListOverriding, isFileSizeLimitOverriding, - isShallowCloningPerformed, isFindingPreviousAuthorsPerformed, isIgnoredFileAnalysisSkipped, - ignoredAuthorsList, isIgnoredAuthorsListOverriding); + RepoConfiguration config = new RepoConfiguration.Builder() + .location(location) + .branch(branch) + .fileTypeManager(formats) + .ignoreGlobList(ignoreGlobList) + .fileSizeLimit(fileSizeLimit) + .isStandaloneConfigIgnored(isStandaloneConfigIgnored) + .isFileSizeLimitIgnored(isFileSizeLimitIgnored) + .ignoreCommitList(ignoreCommitList) + .isFormatsOverriding(isFormatsOverriding) + .isIgnoreGlobListOverriding(isIgnoreGlobListOverriding) + .isIgnoreCommitListOverriding(isIgnoreCommitListOverriding) + .isFileSizeLimitOverriding(isFileSizeLimitOverriding) + .isShallowCloningPerformed(isShallowCloningPerformed) + .isFindingPreviousAuthorsPerformed(isFindingPreviousAuthorsPerformed) + .isIgnoredFileAnalysisSkipped(isIgnoredFileAnalysisSkipped) + .ignoredAuthorsList(ignoredAuthorsList) + .isIgnoredAuthorsListOverriding(isIgnoredAuthorsListOverriding) + .build(); if (results.contains(config)) { logger.warning("Ignoring duplicated repository " + location + " " + branch); diff --git a/src/systemtest/java/reposense/LocalRepoSystemTest.java b/src/systemtest/java/reposense/LocalRepoSystemTest.java index 663a119fbd..c51a9f06d9 100644 --- a/src/systemtest/java/reposense/LocalRepoSystemTest.java +++ b/src/systemtest/java/reposense/LocalRepoSystemTest.java @@ -39,10 +39,18 @@ public class LocalRepoSystemTest { @BeforeAll public static void setupLocalRepos() throws Exception { - TestRepoCloner.clone(new RepoConfiguration(new RepoLocation("https://github.com/reposense/testrepo-Alpha")), - Paths.get("."), LOCAL_DIRECTORY_ONE); - TestRepoCloner.clone(new RepoConfiguration(new RepoLocation("https://github.com/reposense/testrepo-Alpha")), - Paths.get("."), LOCAL_DIRECTORY_TWO); + TestRepoCloner.clone( + new RepoConfiguration.Builder() + .location(new RepoLocation("https://github.com/reposense/testrepo-Alpha")) + .build(), + Paths.get("."), LOCAL_DIRECTORY_ONE + ); + TestRepoCloner.clone( + new RepoConfiguration.Builder() + .location(new RepoLocation("https://github.com/reposense/testrepo-Alpha")) + .build(), + Paths.get("."), LOCAL_DIRECTORY_TWO + ); } @BeforeEach diff --git a/src/test/java/reposense/git/GitBranchTest.java b/src/test/java/reposense/git/GitBranchTest.java index 04ed4a07d8..308bbc156c 100644 --- a/src/test/java/reposense/git/GitBranchTest.java +++ b/src/test/java/reposense/git/GitBranchTest.java @@ -31,8 +31,10 @@ public void getCurrentBranch_masterBranch_success() throws Exception { @Test public void getCurrentBranch_uncommonDefaultBranch_success() throws Exception { - RepoConfiguration uncommonDefaultConfig = new RepoConfiguration( - new RepoLocation(TEST_REPO_UNCOMMON_DEFAULT_GIT_LOCATION), RepoConfiguration.DEFAULT_BRANCH); + RepoConfiguration uncommonDefaultConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_UNCOMMON_DEFAULT_GIT_LOCATION)) + .branch(RepoConfiguration.DEFAULT_BRANCH) + .build(); uncommonDefaultConfig.setFormats(FileTypeTest.DEFAULT_TEST_FORMATS); TestRepoCloner.cloneAndBranch(uncommonDefaultConfig); String currentBranch = GitBranch.getCurrentBranch(uncommonDefaultConfig.getRepoRoot()); diff --git a/src/test/java/reposense/model/RepoConfigurationTest.java b/src/test/java/reposense/model/RepoConfigurationTest.java index 0fcefbe7ff..60b2892660 100644 --- a/src/test/java/reposense/model/RepoConfigurationTest.java +++ b/src/test/java/reposense/model/RepoConfigurationTest.java @@ -5,6 +5,8 @@ import java.lang.reflect.Method; import java.nio.file.Path; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -16,6 +18,7 @@ import reposense.parser.ArgsParser; import reposense.parser.AuthorConfigCsvParser; +import reposense.parser.ConfigurationBuildException; import reposense.parser.GroupConfigCsvParser; import reposense.parser.RepoConfigCsvParser; import reposense.report.ReportGenerator; @@ -110,7 +113,10 @@ public static void setUp() throws Exception { expectedAuthors.add(THIRD_AUTHOR); expectedAuthors.add(FOURTH_AUTHOR); - repoDeltaStandaloneConfig = new RepoConfiguration(new RepoLocation(TEST_REPO_DELTA), "master"); + repoDeltaStandaloneConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_DELTA)) + .branch("master") + .build(); repoDeltaStandaloneConfig.setAuthorList(expectedAuthors); repoDeltaStandaloneConfig.addAuthorNamesToAuthorMapEntry(FIRST_AUTHOR, FIRST_AUTHOR_ALIASES); repoDeltaStandaloneConfig.addAuthorNamesToAuthorMapEntry(FOURTH_AUTHOR, FOURTH_AUTHOR_ALIASES); @@ -130,7 +136,10 @@ public static void setUp() throws Exception { @Test public void repoConfig_usesStandaloneConfig_success() throws Exception { - RepoConfiguration actualConfig = new RepoConfiguration(new RepoLocation(TEST_REPO_DELTA), "master"); + RepoConfiguration actualConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_DELTA)) + .branch("master") + .build(); TestRepoCloner.cloneAndBranch(actualConfig); reportGenerator.updateRepoConfig(actualConfig); @@ -144,7 +153,10 @@ public void repoConfig_ignoresStandaloneConfig_success() throws Exception { author.setIgnoreGlobList(REPO_LEVEL_GLOB_LIST); expectedAuthors.add(author); - RepoConfiguration expectedConfig = new RepoConfiguration(new RepoLocation(TEST_REPO_DELTA), "master"); + RepoConfiguration expectedConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_DELTA)) + .branch("master") + .build(); expectedConfig.setAuthorList(expectedAuthors); expectedConfig.addAuthorNamesToAuthorMapEntry(author, FIRST_AUTHOR_ALIASES); expectedConfig.setAuthorDisplayName(author, "Ahm"); @@ -174,7 +186,10 @@ public void repoConfig_ignoresStandaloneConfig_success() throws Exception { @Test public void repoConfig_ignoresStandaloneConfigInCli_success() throws Exception { - RepoConfiguration expectedConfig = new RepoConfiguration(new RepoLocation(TEST_REPO_DELTA), "master"); + RepoConfiguration expectedConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_DELTA)) + .branch("master") + .build(); expectedConfig.setFormats(FileType.convertFormatStringsToFileTypes(CLI_FORMATS)); expectedConfig.setStandaloneConfigIgnored(true); @@ -201,12 +216,16 @@ public void repoConfig_ignoresStandaloneConfigInCli_success() throws Exception { @Test public void repoConfig_ignoreStandaloneConfigInCli_overrideCsv() throws Exception { - RepoConfiguration repoBetaExpectedConfig = new RepoConfiguration( - new RepoLocation(TEST_REPO_BETA), "master"); + RepoConfiguration repoBetaExpectedConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_BETA)) + .branch("master") + .build(); repoBetaExpectedConfig.setFormats(FileType.convertFormatStringsToFileTypes(CLI_FORMATS)); repoBetaExpectedConfig.setStandaloneConfigIgnored(true); - RepoConfiguration repoDeltaExpectedConfig = new RepoConfiguration( - new RepoLocation(TEST_REPO_DELTA), "master"); + RepoConfiguration repoDeltaExpectedConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_DELTA)) + .branch("master") + .build(); repoDeltaExpectedConfig.setStandaloneConfigIgnored(true); String input = new InputBuilder().addConfig(IGNORE_STANDALONE_FLAG_OVERRIDE_CSV_TEST) @@ -230,7 +249,10 @@ public void repoConfig_ignoreStandaloneConfigInCli_overrideCsv() throws Exceptio @Test public void repoConfig_ignoreFileSizeLimit_success() throws Exception { - RepoConfiguration expectedConfig = new RepoConfiguration(new RepoLocation(TEST_REPO_DELTA), "master"); + RepoConfiguration expectedConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_DELTA)) + .branch("master") + .build(); expectedConfig.setIgnoreGlobList(REPO_LEVEL_GLOB_LIST); expectedConfig.setFormats(CONFIG_FORMATS); expectedConfig.setStandaloneConfigIgnored(true); @@ -255,13 +277,17 @@ public void repoConfig_ignoreFileSizeLimit_success() throws Exception { @Test public void repoConfig_ignoreFileSizeLimitInCli_overrideCsv() throws Exception { - RepoConfiguration repoBetaExpectedConfig = new RepoConfiguration( - new RepoLocation(TEST_REPO_BETA), "master"); + RepoConfiguration repoBetaExpectedConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_BETA)) + .branch("master") + .build(); repoBetaExpectedConfig.setFormats(FileType.convertFormatStringsToFileTypes(CLI_FORMATS)); repoBetaExpectedConfig.setStandaloneConfigIgnored(true); repoBetaExpectedConfig.setFileSizeLimitIgnored(true); - RepoConfiguration repoDeltaExpectedConfig = new RepoConfiguration( - new RepoLocation(TEST_REPO_DELTA), "master"); + RepoConfiguration repoDeltaExpectedConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_DELTA)) + .branch("master") + .build(); repoDeltaExpectedConfig.setStandaloneConfigIgnored(true); repoDeltaExpectedConfig.setFileSizeLimitIgnored(true); @@ -287,8 +313,10 @@ public void repoConfig_ignoreFileSizeLimitInCli_overrideCsv() throws Exception { @Test public void repoConfig_withoutIgnoreStandaloneConfigInCli_useCsv() throws Exception { - RepoConfiguration repoBetaExpectedConfig = new RepoConfiguration( - new RepoLocation(TEST_REPO_BETA), "master"); + RepoConfiguration repoBetaExpectedConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_BETA)) + .branch("master") + .build(); repoBetaExpectedConfig.setFormats(FileType.convertFormatStringsToFileTypes(CLI_FORMATS)); repoBetaExpectedConfig.setStandaloneConfigIgnored(true); @@ -329,7 +357,10 @@ public void repoConfig_wrongKeywordUseStandaloneConfig_success() throws Exceptio @Test public void repoConfig_shallowCloning_success() throws Exception { - RepoConfiguration expectedConfig = new RepoConfiguration(new RepoLocation(TEST_REPO_DELTA), "master"); + RepoConfiguration expectedConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_DELTA)) + .branch("master") + .build(); expectedConfig.setIgnoreGlobList(REPO_LEVEL_GLOB_LIST); expectedConfig.setFormats(CONFIG_FORMATS); expectedConfig.setStandaloneConfigIgnored(true); @@ -354,7 +385,10 @@ public void repoConfig_shallowCloning_success() throws Exception { @Test public void repoConfig_shallowCloningInCli_success() throws Exception { - RepoConfiguration expectedConfig = new RepoConfiguration(new RepoLocation(TEST_REPO_DELTA), "master"); + RepoConfiguration expectedConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_DELTA)) + .branch("master") + .build(); expectedConfig.setFormats(FileType.convertFormatStringsToFileTypes(CLI_FORMATS)); expectedConfig.setStandaloneConfigIgnored(true); expectedConfig.setIsShallowCloningPerformed(true); @@ -382,13 +416,17 @@ public void repoConfig_shallowCloningInCli_success() throws Exception { @Test public void repoConfig_shallowCloningInCli_overrideCsv() throws Exception { - RepoConfiguration repoBetaExpectedConfig = new RepoConfiguration( - new RepoLocation(TEST_REPO_BETA), "master"); + RepoConfiguration repoBetaExpectedConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_BETA)) + .branch("master") + .build(); repoBetaExpectedConfig.setFormats(FileType.convertFormatStringsToFileTypes(CLI_FORMATS)); repoBetaExpectedConfig.setStandaloneConfigIgnored(true); repoBetaExpectedConfig.setIsShallowCloningPerformed(true); - RepoConfiguration repoDeltaExpectedConfig = new RepoConfiguration( - new RepoLocation(TEST_REPO_DELTA), "master"); + RepoConfiguration repoDeltaExpectedConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_DELTA)) + .branch("master") + .build(); repoDeltaExpectedConfig.setStandaloneConfigIgnored(true); repoDeltaExpectedConfig.setIsShallowCloningPerformed(true); @@ -414,13 +452,17 @@ public void repoConfig_shallowCloningInCli_overrideCsv() throws Exception { @Test public void repoConfig_withoutShallowCloningInInCli_useCsv() throws Exception { - RepoConfiguration repoBetaExpectedConfig = new RepoConfiguration( - new RepoLocation(TEST_REPO_BETA), "master"); + RepoConfiguration repoBetaExpectedConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_BETA)) + .branch("master") + .build(); repoBetaExpectedConfig.setFormats(FileType.convertFormatStringsToFileTypes(CLI_FORMATS)); repoBetaExpectedConfig.setStandaloneConfigIgnored(true); repoBetaExpectedConfig.setIsShallowCloningPerformed(true); - RepoConfiguration repoDeltaExpectedConfig = new RepoConfiguration( - new RepoLocation(TEST_REPO_DELTA), "master"); + RepoConfiguration repoDeltaExpectedConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_DELTA)) + .branch("master") + .build(); repoDeltaExpectedConfig.setStandaloneConfigIgnored(true); String input = new InputBuilder().addConfig(SHALLOW_CLONING_FLAG_OVERRIDE_TEST_CONFIG_FILES).build(); @@ -443,7 +485,10 @@ public void repoConfig_withoutShallowCloningInInCli_useCsv() throws Exception { @Test public void repoConfig_findPreviousAuthors_success() throws Exception { - RepoConfiguration expectedConfig = new RepoConfiguration(new RepoLocation(TEST_REPO_DELTA), "master"); + RepoConfiguration expectedConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_DELTA)) + .branch("master") + .build(); expectedConfig.setIgnoreGlobList(REPO_LEVEL_GLOB_LIST); expectedConfig.setFormats(CONFIG_FORMATS); expectedConfig.setStandaloneConfigIgnored(true); @@ -468,7 +513,10 @@ public void repoConfig_findPreviousAuthors_success() throws Exception { @Test public void repoConfig_findPreviousAuthorsInCli_success() throws Exception { - RepoConfiguration expectedConfig = new RepoConfiguration(new RepoLocation(TEST_REPO_DELTA), "master"); + RepoConfiguration expectedConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_DELTA)) + .branch("master") + .build(); expectedConfig.setFormats(FileType.convertFormatStringsToFileTypes(CLI_FORMATS)); expectedConfig.setStandaloneConfigIgnored(true); expectedConfig.setIsFindingPreviousAuthorsPerformed(true); @@ -496,13 +544,17 @@ public void repoConfig_findPreviousAuthorsInCli_success() throws Exception { @Test public void repoConfig_findPreviousAuthorsInCli_overrideCsv() throws Exception { - RepoConfiguration repoBetaExpectedConfig = new RepoConfiguration( - new RepoLocation(TEST_REPO_BETA), "master"); + RepoConfiguration repoBetaExpectedConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_BETA)) + .branch("master") + .build(); repoBetaExpectedConfig.setFormats(FileType.convertFormatStringsToFileTypes(CLI_FORMATS)); repoBetaExpectedConfig.setStandaloneConfigIgnored(true); repoBetaExpectedConfig.setIsFindingPreviousAuthorsPerformed(true); - RepoConfiguration repoDeltaExpectedConfig = new RepoConfiguration( - new RepoLocation(TEST_REPO_DELTA), "master"); + RepoConfiguration repoDeltaExpectedConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_DELTA)) + .branch("master") + .build(); repoDeltaExpectedConfig.setStandaloneConfigIgnored(true); repoDeltaExpectedConfig.setIsFindingPreviousAuthorsPerformed(true); @@ -528,13 +580,17 @@ public void repoConfig_findPreviousAuthorsInCli_overrideCsv() throws Exception { @Test public void repoConfig_withoutFindPreviousAuthorsInCli_useCsv() throws Exception { - RepoConfiguration repoBetaExpectedConfig = new RepoConfiguration( - new RepoLocation(TEST_REPO_BETA), "master"); + RepoConfiguration repoBetaExpectedConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_BETA)) + .branch("master") + .build(); repoBetaExpectedConfig.setFormats(FileType.convertFormatStringsToFileTypes(CLI_FORMATS)); repoBetaExpectedConfig.setStandaloneConfigIgnored(true); repoBetaExpectedConfig.setIsFindingPreviousAuthorsPerformed(true); - RepoConfiguration repoDeltaExpectedConfig = new RepoConfiguration( - new RepoLocation(TEST_REPO_DELTA), "master"); + RepoConfiguration repoDeltaExpectedConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_DELTA)) + .branch("master") + .build(); repoDeltaExpectedConfig.setStandaloneConfigIgnored(true); String input = new InputBuilder().addConfig(FIND_PREVIOUS_AUTHORS_FLAG_OVERRIDE_TEST_CONFIG_FILES).build(); @@ -558,12 +614,16 @@ public void repoConfig_withoutFindPreviousAuthorsInCli_useCsv() throws Exception @Test public void repoConfig_userEnvironmentCannotRunFindPreviousAuthors_setFindPreviousAuthorsToFalseInAllRepoConfigs() throws Exception { - RepoConfiguration repoBetaExpectedConfig = new RepoConfiguration( - new RepoLocation(TEST_REPO_BETA), "master"); + RepoConfiguration repoBetaExpectedConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_BETA)) + .branch("master") + .build(); repoBetaExpectedConfig.setFormats(FileType.convertFormatStringsToFileTypes(CLI_FORMATS)); repoBetaExpectedConfig.setStandaloneConfigIgnored(true); - RepoConfiguration repoDeltaExpectedConfig = new RepoConfiguration( - new RepoLocation(TEST_REPO_DELTA), "master"); + RepoConfiguration repoDeltaExpectedConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_DELTA)) + .branch("master") + .build(); repoDeltaExpectedConfig.setStandaloneConfigIgnored(true); String input = new InputBuilder().addConfig(FIND_PREVIOUS_AUTHORS_FLAG_OVERRIDE_TEST_CONFIG_FILES).build(); @@ -651,9 +711,16 @@ public void repoConfig_withoutFormatsAndCliFormats_useAllFormats() throws Except @Test public void repoConfig_emptyLocationDifferentBranch_equal() throws Exception { - RepoConfiguration emptyLocationEmptyBranchRepoConfig = new RepoConfiguration(new RepoLocation(""), ""); - RepoConfiguration emptyLocationDefaultBranchRepoConfig = new RepoConfiguration(new RepoLocation("")); - RepoConfiguration emptyLocationWithBranchRepoConfig = new RepoConfiguration(new RepoLocation(""), "master"); + RepoConfiguration emptyLocationEmptyBranchRepoConfig = new RepoConfiguration.Builder() + .location(new RepoLocation("")) + .branch("") + .build(); + RepoConfiguration emptyLocationDefaultBranchRepoConfig = new RepoConfiguration.Builder() + .location(new RepoLocation("")).build(); + RepoConfiguration emptyLocationWithBranchRepoConfig = new RepoConfiguration.Builder() + .location(new RepoLocation("")) + .branch("master") + .build(); Assertions.assertEquals(emptyLocationDefaultBranchRepoConfig, emptyLocationEmptyBranchRepoConfig); Assertions.assertEquals(emptyLocationWithBranchRepoConfig, emptyLocationEmptyBranchRepoConfig); @@ -662,19 +729,37 @@ public void repoConfig_emptyLocationDifferentBranch_equal() throws Exception { @Test public void repoConfig_sameLocationDifferentBranch_notEqual() throws Exception { RepoConfiguration validLocationValidBranchRepoConfig = - new RepoConfiguration(new RepoLocation(TEST_REPO_DELTA), "master"); + new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_DELTA)) + .branch("master") + .build(); RepoConfiguration validLocationDefaultBranchRepoConfig = - new RepoConfiguration(new RepoLocation(TEST_REPO_DELTA)); + new RepoConfiguration.Builder().location(new RepoLocation(TEST_REPO_DELTA)).build(); Assertions.assertNotEquals(validLocationDefaultBranchRepoConfig, validLocationValidBranchRepoConfig); } @Test public void repoConfig_overrideStandaloneConfig_success() throws Exception { - RepoConfiguration expectedConfig = new RepoConfiguration(new RepoLocation(TEST_REPO_DELTA), "master", - Collections.emptyList(), Collections.emptyList(), RepoConfiguration.DEFAULT_FILE_SIZE_LIMIT, false, - false, Collections.emptyList(), true, true, true, false, false, false, false, - Arrays.asList("lithiumlkid"), true); + RepoConfiguration expectedConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_DELTA)) + .branch("master") + .fileTypeManager(Collections.emptyList()) + .ignoreGlobList(Collections.emptyList()) + .fileSizeLimit(RepoConfiguration.DEFAULT_FILE_SIZE_LIMIT) + .isStandaloneConfigIgnored(false) + .isFileSizeLimitIgnored(false) + .ignoreCommitList(Collections.emptyList()) + .isFormatsOverriding(true) + .isIgnoreGlobListOverriding(true) + .isIgnoreCommitListOverriding(true) + .isFileSizeLimitOverriding(false) + .isShallowCloningPerformed(false) + .isFindingPreviousAuthorsPerformed(false) + .isIgnoredFileAnalysisSkipped(false) + .ignoredAuthorsList(Arrays.asList("lithiumlkid")) + .isIgnoredAuthorsListOverriding(true) + .build(); List expectedAuthorList = new ArrayList<>(); Author[] authors = new Author[]{FIRST_AUTHOR, SECOND_AUTHOR, THIRD_AUTHOR, FOURTH_AUTHOR}; @@ -711,8 +796,10 @@ public void repoConfig_overrideStandaloneConfig_success() throws Exception { @Test public void repoConfig_minimalStandaloneConfig_fieldsAssignedDefaultValues() throws Exception { - RepoConfiguration expectedConfig = new RepoConfiguration(new RepoLocation(TEST_REPO_MINIMAL_STANDALONE_CONFIG), - "master"); + RepoConfiguration expectedConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_MINIMAL_STANDALONE_CONFIG)) + .branch("master") + .build(); Author firstAuthor = new Author("bluein-green"); Author secondAuthor = new Author("jylee-git"); @@ -723,8 +810,10 @@ public void repoConfig_minimalStandaloneConfig_fieldsAssignedDefaultValues() thr expectedConfig.setFormats(Collections.emptyList()); expectedConfig.setIgnoreCommitList(Collections.emptyList()); - RepoConfiguration actualConfig = new RepoConfiguration(new RepoLocation(TEST_REPO_MINIMAL_STANDALONE_CONFIG), - "master"); + RepoConfiguration actualConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_MINIMAL_STANDALONE_CONFIG)) + .branch("master") + .build(); TestRepoCloner.cloneAndBranch(actualConfig); reportGenerator.updateRepoConfig(actualConfig); @@ -738,7 +827,10 @@ public void repoConfig_removeIgnoredAuthors_success() throws Exception { author.setIgnoreGlobList(REPO_LEVEL_GLOB_LIST); expectedAuthors.add(author); - RepoConfiguration expectedConfig = new RepoConfiguration(new RepoLocation(TEST_REPO_DELTA), "master"); + RepoConfiguration expectedConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_DELTA)) + .branch("master") + .build(); expectedConfig.setAuthorList(expectedAuthors); expectedConfig.addAuthorNamesToAuthorMapEntry(author, FIRST_AUTHOR_ALIASES); expectedConfig.setAuthorDisplayName(author, "Ahm"); @@ -769,4 +861,103 @@ public void repoConfig_removeIgnoredAuthors_success() throws Exception { TestUtil.compareRepoConfig(expectedConfig, actualConfig); } + + @Test + public void repoBuilder_displayName_success() throws Exception { + RepoConfiguration actualConfig = new RepoConfiguration.Builder() + .displayName("CS3281") + .location(new RepoLocation(TEST_REPO_MINIMAL_STANDALONE_CONFIG)) + .branch("master") + .build(); + + Assertions.assertEquals(actualConfig.getDisplayName(), "CS3281"); + } + + @Test + public void repoBuilder_outputFolderName_success() throws Exception { + RepoConfiguration actualConfig = new RepoConfiguration.Builder() + .outputFolderName("CS3281 Folder") + .location(new RepoLocation(TEST_REPO_MINIMAL_STANDALONE_CONFIG)) + .branch("master") + .build(); + + Assertions.assertEquals(actualConfig.getOutputFolderName(), "CS3281 Folder"); + } + + @Test + public void repoBuilder_repoFolderName_success() throws Exception { + RepoConfiguration actualConfig = new RepoConfiguration.Builder() + .repoFolderName("CS3281 Folder") + .location(new RepoLocation(TEST_REPO_MINIMAL_STANDALONE_CONFIG)) + .branch("master") + .build(); + + Assertions.assertEquals(actualConfig.getRepoFolderName(), "CS3281 Folder"); + } + + @Test + public void repoBuilder_zoneID_success() throws Exception { + RepoConfiguration actualConfig = new RepoConfiguration.Builder() + .zoneId(ZoneId.systemDefault()) + .location(new RepoLocation(TEST_REPO_MINIMAL_STANDALONE_CONFIG)) + .branch("master") + .build(); + + Assertions.assertEquals(actualConfig.getZoneId(), ZoneId.systemDefault()); + } + + @Test + public void repoBuilder_sinceDate_success() throws Exception { + RepoConfiguration actualConfig = new RepoConfiguration.Builder() + .sinceDate(LocalDateTime.of(2024, 1, 1, 12, 0, 0)) + .location(new RepoLocation(TEST_REPO_MINIMAL_STANDALONE_CONFIG)) + .branch("master") + .build(); + + Assertions.assertEquals(actualConfig.getSinceDate(), + LocalDateTime.of(2024, 1, 1, 12, 0, 0)); + } + + @Test + public void repoBuilder_untilDate_success() throws Exception { + RepoConfiguration actualConfig = new RepoConfiguration.Builder() + .untilDate(LocalDateTime.of(2024, 1, 1, 12, 0, 0)) + .location(new RepoLocation(TEST_REPO_MINIMAL_STANDALONE_CONFIG)) + .branch("master") + .build(); + + Assertions.assertEquals(actualConfig.getUntilDate(), + LocalDateTime.of(2024, 1, 1, 12, 0, 0)); + } + + @Test + public void repoBuilder_authorConfig_success() throws Exception { + RepoLocation loc = new RepoLocation(TEST_REPO_MINIMAL_STANDALONE_CONFIG); + String branch = "master"; + + RepoConfiguration actualConfig = new RepoConfiguration.Builder() + .authorConfig(new AuthorConfiguration(loc, branch)) + .location(loc) + .branch(branch) + .build(); + + Assertions.assertEquals(actualConfig.getAuthorConfig(), + new AuthorConfiguration(loc, branch)); + } + + @Test + public void repoBuilder_isLastModifiedDateIncluded_success() throws Exception { + RepoConfiguration actualConfig = new RepoConfiguration.Builder() + .isLastModifiedDateIncluded(true) + .location(new RepoLocation(TEST_REPO_MINIMAL_STANDALONE_CONFIG)) + .branch("master") + .build(); + + Assertions.assertTrue(actualConfig.isLastModifiedDateIncluded()); + } + + @Test + public void repoBuilder_buildWithInvalid_failure() { + Assertions.assertThrows(ConfigurationBuildException.class, () -> new RepoConfiguration.Builder().build()); + } } diff --git a/src/test/java/reposense/parser/RepoConfigParserTest.java b/src/test/java/reposense/parser/RepoConfigParserTest.java index 02d3feb01a..f2491188c2 100644 --- a/src/test/java/reposense/parser/RepoConfigParserTest.java +++ b/src/test/java/reposense/parser/RepoConfigParserTest.java @@ -127,16 +127,20 @@ public void merge_twoRepoConfigs_success() throws Exception { expectedAuthors.add(FIRST_AUTHOR); expectedAuthors.add(SECOND_AUTHOR); - RepoConfiguration firstRepo = new RepoConfiguration(new RepoLocation(TEST_REPO_BETA_LOCATION), - TEST_REPO_BETA_MASTER_BRANCH); + RepoConfiguration firstRepo = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_BETA_LOCATION)) + .branch(TEST_REPO_BETA_MASTER_BRANCH) + .build(); firstRepo.setAuthorList(expectedAuthors); firstRepo.setAuthorDisplayName(FIRST_AUTHOR, "Nbr"); firstRepo.setAuthorDisplayName(SECOND_AUTHOR, "Zac"); firstRepo.addAuthorNamesToAuthorMapEntry(SECOND_AUTHOR, Arrays.asList("Zachary Tang")); firstRepo.setIgnoreGlobList(REPO_LEVEL_GLOB_LIST); - RepoConfiguration secondRepo = new RepoConfiguration(new RepoLocation(TEST_REPO_BETA_LOCATION), - TEST_REPO_BETA_ADD_CONFIG_JSON_BRANCH); + RepoConfiguration secondRepo = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_BETA_LOCATION)) + .branch(TEST_REPO_BETA_ADD_CONFIG_JSON_BRANCH) + .build(); secondRepo.setAuthorList(Arrays.asList(SECOND_AUTHOR)); secondRepo.setAuthorDisplayName(SECOND_AUTHOR, "Zac"); secondRepo.addAuthorNamesToAuthorMapEntry(SECOND_AUTHOR, Arrays.asList("Zachary Tang")); @@ -170,7 +174,10 @@ public void merge_emptyLocation_success() throws Exception { expectedDeltaAuthors.add(FIRST_AUTHOR); RepoConfiguration expectedBetaConfig = - new RepoConfiguration(new RepoLocation(TEST_REPO_BETA_LOCATION), TEST_REPO_BETA_MASTER_BRANCH); + new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_BETA_LOCATION)) + .branch(TEST_REPO_BETA_MASTER_BRANCH) + .build(); expectedBetaConfig.setAuthorList(expectedBetaAuthors); expectedBetaConfig.setAuthorDisplayName(FIRST_AUTHOR, "Nbr"); expectedBetaConfig.setAuthorDisplayName(SECOND_AUTHOR, "Zac"); @@ -179,7 +186,10 @@ public void merge_emptyLocation_success() throws Exception { expectedBetaConfig.setIsShallowCloningPerformed(true); RepoConfiguration expectedDeltaConfig = - new RepoConfiguration(new RepoLocation(TEST_REPO_DELTA_LOCATION), TEST_REPO_DELTA_BRANCH); + new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_DELTA_LOCATION)) + .branch(TEST_REPO_DELTA_BRANCH) + .build(); expectedDeltaConfig.setAuthorList(expectedDeltaAuthors); expectedDeltaConfig.setAuthorDisplayName(FIRST_AUTHOR, "Nbr"); expectedDeltaConfig.setStandaloneConfigIgnored(true); @@ -207,8 +217,10 @@ public void merge_emptyLocation_success() throws Exception { @Test public void repoConfig_defaultBranch_success() throws Exception { - RepoConfiguration expectedConfig = new RepoConfiguration(new RepoLocation(TEST_REPO_BETA_LOCATION), - RepoConfiguration.DEFAULT_BRANCH); + RepoConfiguration expectedConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_BETA_LOCATION)) + .branch(RepoConfiguration.DEFAULT_BRANCH) + .build(); String input = new InputBuilder().addConfig(TEST_EMPTY_BRANCH_CONFIG_FOLDER).build(); CliArguments cliArguments = ArgsParser.parse(translateCommandline(input)); diff --git a/src/test/java/reposense/parser/StandaloneConfigJsonParserTest.java b/src/test/java/reposense/parser/StandaloneConfigJsonParserTest.java index 2dadab322b..e56d4ef2d0 100644 --- a/src/test/java/reposense/parser/StandaloneConfigJsonParserTest.java +++ b/src/test/java/reposense/parser/StandaloneConfigJsonParserTest.java @@ -56,12 +56,14 @@ public static void setUp() throws Exception { author.setAuthorAliases(Arrays.asList("Yong Hao TENG")); author.setIgnoreGlobList(Arrays.asList("**.css", "**.html", "**.jade", "**.js")); - expectedGithubIdOnlyRepoconfig = new RepoConfiguration(new RepoLocation(TEST_DUMMY_LOCATION)); + expectedGithubIdOnlyRepoconfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_DUMMY_LOCATION)).build(); expectedGithubIdOnlyRepoconfig.setFormats(FileTypeTest.NO_SPECIFIED_FORMATS); expectedGithubIdOnlyRepoconfig.setAuthorList(Arrays.asList(new Author("yong24s"))); expectedGithubIdOnlyRepoconfig.addAuthorEmailsToAuthorMapEntry(author, author.getEmails()); - expectedFullRepoConfig = new RepoConfiguration(new RepoLocation(TEST_DUMMY_LOCATION)); + expectedFullRepoConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_DUMMY_LOCATION)).build(); expectedFullRepoConfig.setFormats(FileType.convertFormatStringsToFileTypes( Arrays.asList("gradle", "jade", "java", "js", "md", "scss", "yml"))); expectedFullRepoConfig.setIgnoreCommitList(Arrays.asList(new CommitHash( @@ -110,7 +112,8 @@ public void standaloneConfig_malformedJsonFile_throwsJsonSyntaxException() { private void assertSameConfig(RepoConfiguration expectedRepoConfig, StandaloneConfig actualStandaloneConfig) throws Exception { - RepoConfiguration actualRepoConfig = new RepoConfiguration(new RepoLocation(TEST_DUMMY_LOCATION)); + RepoConfiguration actualRepoConfig = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_DUMMY_LOCATION)).build(); actualRepoConfig.update(actualStandaloneConfig); TestUtil.compareRepoConfig(expectedRepoConfig, actualRepoConfig); } diff --git a/src/test/java/reposense/report/RepoClonerTest.java b/src/test/java/reposense/report/RepoClonerTest.java index 8f384fd5e9..18604700e3 100644 --- a/src/test/java/reposense/report/RepoClonerTest.java +++ b/src/test/java/reposense/report/RepoClonerTest.java @@ -22,7 +22,8 @@ public class RepoClonerTest { @Test public void repoCloner_emptyRepo_failsGracefully() throws Exception { RepoConfiguration emptyRepositoryRepoConfig = - new RepoConfiguration(new RepoLocation(TEST_REPO_EMPTY_GIT_LOCATION)); + new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_EMPTY_GIT_LOCATION)).build(); RepoCloner repoCloner = new RepoCloner(); repoCloner.cloneBare(emptyRepositoryRepoConfig); @@ -34,11 +35,13 @@ public void repoCloner_emptyRepo_failsGracefully() throws Exception { @Test public void repoCloner_validRepoLocationWithRelativePathingAndSpaces_success() throws Exception { // Clones a test repository into the test directory for testing of relative pathing - RepoConfiguration tempRemoteConfiguration = new RepoConfiguration(new RepoLocation(TEST_REPO_GIT_LOCATION)); + RepoConfiguration tempRemoteConfiguration = new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_GIT_LOCATION)).build(); TestRepoCloner.cloneBare(tempRemoteConfiguration, Paths.get("."), REPOCLONE_LOCAL_TEST_PATH.toString()); RepoConfiguration repoWithRelativePathingAndSpacesAndEndingBackslash = - new RepoConfiguration(new RepoLocation(REPOCLONE_LOCAL_TEST_PATH.toString())); + new RepoConfiguration.Builder() + .location(new RepoLocation(REPOCLONE_LOCAL_TEST_PATH.toString())).build(); RepoCloner repoCloner = new RepoCloner(); repoCloner.cloneBare(repoWithRelativePathingAndSpacesAndEndingBackslash); Assertions.assertTrue(Files.exists(REPOCLONE_LOCAL_TEST_PATH)); diff --git a/src/test/java/reposense/template/GitTestTemplate.java b/src/test/java/reposense/template/GitTestTemplate.java index 452d9c6317..1b9b853588 100644 --- a/src/test/java/reposense/template/GitTestTemplate.java +++ b/src/test/java/reposense/template/GitTestTemplate.java @@ -138,8 +138,11 @@ public void after() { } private static RepoConfiguration newRepoConfiguration() throws Exception { - return new RepoConfiguration(new RepoLocation(TEST_REPO_GIT_LOCATION), "master", - EXTRA_OUTPUT_FOLDER_NAME_SUPPLIER.get()); + return new RepoConfiguration.Builder() + .location(new RepoLocation(TEST_REPO_GIT_LOCATION)) + .branch("master") + .extraOutputFolderName(EXTRA_OUTPUT_FOLDER_NAME_SUPPLIER.get()) + .build(); } /**