Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1881] Check if author config file exists instead of detecting it via an exception #2007

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions src/main/java/reposense/model/ConfigRunConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package reposense.model;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -40,27 +41,29 @@
List<AuthorConfiguration> authorConfigs;
List<GroupConfiguration> groupConfigs;

try {
authorConfigs = new AuthorConfigCsvParser(cliArguments.getAuthorConfigFilePath()).parse();
RepoConfiguration.merge(repoConfigs, authorConfigs);
RepoConfiguration.setHasAuthorConfigFileToRepoConfigs(repoConfigs, true);
} catch (FileNotFoundException fnfe) {
// FileNotFoundException thrown as author-config.csv is not found.
// Ignore exception as the file is optional.
} catch (IOException | InvalidCsvException e) {
// for all IO and invalid csv exceptions, log the error and continue
logger.log(Level.WARNING, e.getMessage(), e);
Path authorConfigFilePath = cliArguments.getAuthorConfigFilePath();
Path groupConfigFilePath = cliArguments.getGroupConfigFilePath();


if (authorConfigFilePath != null && Files.exists(authorConfigFilePath)) {
try {
authorConfigs = new AuthorConfigCsvParser(cliArguments.getAuthorConfigFilePath()).parse();
RepoConfiguration.merge(repoConfigs, authorConfigs);
RepoConfiguration.setHasAuthorConfigFileToRepoConfigs(repoConfigs, true);
} catch (IOException | InvalidCsvException e) {
// for all IO and invalid csv exceptions, log the error and continue
logger.log(Level.WARNING, e.getMessage(), e);
}
}

try {
groupConfigs = new GroupConfigCsvParser(cliArguments.getGroupConfigFilePath()).parse();
RepoConfiguration.setGroupConfigsToRepos(repoConfigs, groupConfigs);
} catch (FileNotFoundException fnfe) {
// FileNotFoundException thrown as groups-config.csv is not found.
// Ignore exception as the file is optional.
} catch (IOException | InvalidCsvException e) {
// for all other IO and invalid csv exceptions, log the error and continue
logger.log(Level.WARNING, e.getMessage(), e);
if (groupConfigFilePath != null && Files.exists(groupConfigFilePath)) {
try {
groupConfigs = new GroupConfigCsvParser(cliArguments.getGroupConfigFilePath()).parse();
RepoConfiguration.setGroupConfigsToRepos(repoConfigs, groupConfigs);
} catch (IOException | InvalidCsvException e) {

Check warning on line 63 in src/main/java/reposense/model/ConfigRunConfiguration.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/reposense/model/ConfigRunConfiguration.java#L63

Added line #L63 was not covered by tests
// for all IO and invalid csv exceptions, log the error and continue
logger.log(Level.WARNING, e.getMessage(), e);

Check warning on line 65 in src/main/java/reposense/model/ConfigRunConfiguration.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/reposense/model/ConfigRunConfiguration.java#L65

Added line #L65 was not covered by tests
}
}

return repoConfigs;
Expand Down
Loading