Skip to content

Commit

Permalink
Check if author config file exists instead of detecting it via an exc…
Browse files Browse the repository at this point in the history
…eption
  • Loading branch information
germainelee02 committed Jun 18, 2023
1 parent 3878389 commit 7ef745a
Showing 1 changed file with 23 additions and 20 deletions.
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 @@ public List<RepoConfiguration> getRepoConfigurations()
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

0 comments on commit 7ef745a

Please sign in to comment.