Skip to content

Commit

Permalink
feat: excludeFiles are now regex
Browse files Browse the repository at this point in the history
implements #62
  • Loading branch information
jagodevreede committed Feb 9, 2024
1 parent 3b5f621 commit 67552c8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ The following configuration options are available:
| overwriteOutputFile | `true` | If set to `false` then the output file will not be overwritten. |
| includePackages | | Only uses packages in the list and ignores any others, can be a comma separated list or a list of includePackage. Values are a regex pattern (See [example project](semver-check-maven-plugin-example) for example) |
| excludePackages | | Ignores packages can be a comma separated list or a list of excludePackage. Values are a regex pattern (See [example project](semver-check-maven-plugin-example) for example) |
| excludeFiles | | Ignores files in that starts with given here. Can be a comma separated list or a list of excludeFile (See [example project](semver-check-maven-plugin-example) for example) |
| excludeFiles | | Ignores files in match the regex with given here. Can be a comma separated list or a list of excludeFile (See [example project](semver-check-maven-plugin-example) for example) |
| failOnIncorrectVersion | `false` | If set to `true` then if the semver mismatches the build will fail. |
| allowHigherVersions | `true` | Only has effect when `failOnIncorrectVersion` is set. If allowHigherVersions set to `false` it will also break if it detected a is lower then expected version. |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public class Configuration {

private final List<Pattern> includePackages;
private final List<Pattern> excludePackages;
private final List<String> excludeFiles;
private final List<Pattern> excludeFiles;
private final List<String> runtimeClasspathElements;

public Configuration(List<String> includePackages, List<String> excludePackages, List<String> excludeFiles, List<String> runtimeClasspathElements) {
this.includePackages = includePackages.stream().map(Pattern::compile).collect(Collectors.toList());
this.excludePackages = excludePackages.stream().map(Pattern::compile).collect(Collectors.toList());;
this.excludeFiles = excludeFiles;
this.excludePackages = excludePackages.stream().map(Pattern::compile).collect(Collectors.toList());
this.excludeFiles = excludeFiles.stream().map(Pattern::compile).collect(Collectors.toList());
this.runtimeClasspathElements = runtimeClasspathElements;
}

Expand All @@ -30,7 +30,7 @@ public List<Pattern> getExcludePackages() {
return excludePackages;
}

public List<String> getExcludeFiles() {
public List<Pattern> getExcludeFiles() {
return excludeFiles;
}

Expand All @@ -56,4 +56,14 @@ public boolean isExcluded(ClassInformation aClass) {
}
return false;
}

public boolean isFileExcluded(String fileName) {
for (Pattern excludeFile : getExcludeFiles()) {
if (excludeFile.matcher(fileName).matches()) {
log.debug("File {} is skipped as it is excluded from the check as it in excluded files {}", fileName, excludeFile);
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private SemVerType determineFileDifferences() throws IOException {
Map<String, JarEntry> filesInNewJar = getFilesNotClassedInJar(newJar);

for (Map.Entry<String, JarEntry> fileInOriginal : filesInOriginalJar.entrySet()) {
if (isFileExcluded(fileInOriginal.getKey())) {
if (configuration.isFileExcluded(fileInOriginal.getKey())) {
continue;
}
JarEntry fileInNewJar = filesInNewJar.get(fileInOriginal.getKey());
Expand All @@ -154,7 +154,7 @@ private SemVerType determineFileDifferences() throws IOException {
}

for (Map.Entry<String, JarEntry> fileInNewJar : filesInNewJar.entrySet()) {
if (isFileExcluded(fileInNewJar.getKey())) {
if (configuration.isFileExcluded(fileInNewJar.getKey())) {
continue;
}
JarEntry fileInOriginal = filesInOriginalJar.get(fileInNewJar.getKey());
Expand All @@ -166,16 +166,6 @@ private SemVerType determineFileDifferences() throws IOException {
return NONE;
}

private boolean isFileExcluded(String key) {
for (String excludeFile : configuration.getExcludeFiles()) {
if (key.startsWith(excludeFile)) {
log.debug("File {} is skipped as it is excluded from the check as it in excluded files {}", key, excludeFile);
return true;
}
}
return false;
}

private SemVerType determineClassDifference(ClassInformation originalClass, ClassInformation classInNewJar) {
SemVerType classResult = NONE;
try {
Expand Down

0 comments on commit 67552c8

Please sign in to comment.