From 67552c880a133135db919b2c5086a70b89d2a472 Mon Sep 17 00:00:00 2001 From: Jago de Vreede Date: Fri, 9 Feb 2024 13:54:59 +0100 Subject: [PATCH] feat: excludeFiles are now regex implements #62 --- README.md | 2 +- .../semver/check/core/Configuration.java | 18 ++++++++++++++---- .../semver/check/core/SemVerChecker.java | 14 ++------------ 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 48fc16b..f3aed22 100644 --- a/README.md +++ b/README.md @@ -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. | diff --git a/semver-check-core/src/main/java/io/github/jagodevreede/semver/check/core/Configuration.java b/semver-check-core/src/main/java/io/github/jagodevreede/semver/check/core/Configuration.java index 817afcc..2d5e348 100644 --- a/semver-check-core/src/main/java/io/github/jagodevreede/semver/check/core/Configuration.java +++ b/semver-check-core/src/main/java/io/github/jagodevreede/semver/check/core/Configuration.java @@ -12,13 +12,13 @@ public class Configuration { private final List includePackages; private final List excludePackages; - private final List excludeFiles; + private final List excludeFiles; private final List runtimeClasspathElements; public Configuration(List includePackages, List excludePackages, List excludeFiles, List 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; } @@ -30,7 +30,7 @@ public List getExcludePackages() { return excludePackages; } - public List getExcludeFiles() { + public List getExcludeFiles() { return excludeFiles; } @@ -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; + } } diff --git a/semver-check-core/src/main/java/io/github/jagodevreede/semver/check/core/SemVerChecker.java b/semver-check-core/src/main/java/io/github/jagodevreede/semver/check/core/SemVerChecker.java index 9a8c1cf..1e8e99b 100644 --- a/semver-check-core/src/main/java/io/github/jagodevreede/semver/check/core/SemVerChecker.java +++ b/semver-check-core/src/main/java/io/github/jagodevreede/semver/check/core/SemVerChecker.java @@ -139,7 +139,7 @@ private SemVerType determineFileDifferences() throws IOException { Map filesInNewJar = getFilesNotClassedInJar(newJar); for (Map.Entry fileInOriginal : filesInOriginalJar.entrySet()) { - if (isFileExcluded(fileInOriginal.getKey())) { + if (configuration.isFileExcluded(fileInOriginal.getKey())) { continue; } JarEntry fileInNewJar = filesInNewJar.get(fileInOriginal.getKey()); @@ -154,7 +154,7 @@ private SemVerType determineFileDifferences() throws IOException { } for (Map.Entry fileInNewJar : filesInNewJar.entrySet()) { - if (isFileExcluded(fileInNewJar.getKey())) { + if (configuration.isFileExcluded(fileInNewJar.getKey())) { continue; } JarEntry fileInOriginal = filesInOriginalJar.get(fileInNewJar.getKey()); @@ -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 {