Skip to content

Commit

Permalink
Improving of method validateFilename + calling it from different places
Browse files Browse the repository at this point in the history
  • Loading branch information
vtelensky committed Aug 4, 2017
1 parent 335bc71 commit 3144f30
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ private Map<String, List<File>> groupBoxFilesByVersion(File boxDir) {

private boolean validateFilename(File boxFile) {
String filename = boxFile.getName();
List<String> parsedFilename = Arrays.asList(filename.split("_"));
if (parsedFilename.size() != 3) {
File parentDir = boxFile.getParentFile();

if (!filename.matches(parentDir.getName() + "_(\\d+)_(\\w+)\\.box")) {
LOG.warn("box file [{}] has wrong name. must be in format ${name}_${version}_${provider}.box", filename);
return false;
}
Expand Down Expand Up @@ -135,7 +136,7 @@ private BoxProvider createBoxProviderFromFile(File file) {
}

private boolean containsValidBoxFile(File file) {
File[] files = file.listFiles((dir, name) -> name.matches(dir.getName() + "_(\\d+)_(\\w+)\\.box"));
File[] files = file.listFiles(this::validateFilename);
return files.length > 0;
}
}

0 comments on commit 3144f30

Please sign in to comment.