From 4568135dfd1ea6c8396ff3880655e127e3605288 Mon Sep 17 00:00:00 2001 From: Jason Irwin Date: Fri, 24 Nov 2023 15:38:54 +0000 Subject: [PATCH 01/13] Reverting MENFORCER-364 as the change was only partially implemented and did not adequately deal with mixed filesystems. --- .../rules/files/RequireFilesExist.java | 26 +------------------ .../rules/files/TestRequireFilesExist.java | 9 ------- 2 files changed, 1 insertion(+), 34 deletions(-) diff --git a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/files/RequireFilesExist.java b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/files/RequireFilesExist.java index 9318dbca6..0f25c1002 100644 --- a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/files/RequireFilesExist.java +++ b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/files/RequireFilesExist.java @@ -31,35 +31,11 @@ public final class RequireFilesExist extends AbstractRequireFiles { @Override boolean checkFile(File file) { // if we get here and the handle is null, treat it as a success - return file == null ? true : file.exists() && osIndependentNameMatch(file, true); + return file == null ? true : file.exists(); } @Override String getErrorMsg() { return "Some required files are missing:" + System.lineSeparator(); } - - /** - * OSes like Windows are case insensitive, so this method will compare the file path with the actual path. A simple - * {@link File#exists()} is not enough for such OS. - * - * @param file the file to verify - * @param defaultValue value to return in case an IO exception occurs, should never happen as the file already - * exists - * @return - */ - private boolean osIndependentNameMatch(File file, boolean defaultValue) { - try { - File absFile; - if (!file.isAbsolute()) { - absFile = new File(new File(".").getCanonicalFile(), file.getPath()); - } else { - absFile = file; - } - - return absFile.toURI().equals(absFile.getCanonicalFile().toURI()); - } catch (IOException e) { - return defaultValue; - } - } } diff --git a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesExist.java b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesExist.java index 33c726154..fc9192b8f 100644 --- a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesExist.java +++ b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesExist.java @@ -49,15 +49,6 @@ void testFileExists() throws Exception { rule.execute(); } - @Test - void testFileOsIndependentExists() { - rule.setFilesList(Collections.singletonList(new File("POM.xml"))); - - EnforcerRuleException e = assertThrows(EnforcerRuleException.class, () -> rule.execute()); - - assertNotNull(e.getMessage()); - } - @Test void testEmptyFile() { rule.setFilesList(Collections.singletonList(null)); From c7ca86196bc086c5d5d01b4b92c71b1b737a9c20 Mon Sep 17 00:00:00 2001 From: Jason Irwin Date: Fri, 24 Nov 2023 15:46:28 +0000 Subject: [PATCH 02/13] Tidy-up from spotless. No functional changes. --- .../org/apache/maven/enforcer/rules/files/RequireFilesExist.java | 1 - 1 file changed, 1 deletion(-) diff --git a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/files/RequireFilesExist.java b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/files/RequireFilesExist.java index 0f25c1002..bdaecf880 100644 --- a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/files/RequireFilesExist.java +++ b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/files/RequireFilesExist.java @@ -21,7 +21,6 @@ import javax.inject.Named; import java.io.File; -import java.io.IOException; /** * The Class RequireFilesExist. From 81b80278ca92e83bde2ed4b7b3902b0bc0b06713 Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Fri, 24 Nov 2023 19:57:33 +0100 Subject: [PATCH 03/13] Extend IT with example from issue --- .../src/it/projects/require-files-exist/pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/maven-enforcer-plugin/src/it/projects/require-files-exist/pom.xml b/maven-enforcer-plugin/src/it/projects/require-files-exist/pom.xml index ce4612ced..9c81f1690 100644 --- a/maven-enforcer-plugin/src/it/projects/require-files-exist/pom.xml +++ b/maven-enforcer-plugin/src/it/projects/require-files-exist/pom.xml @@ -46,6 +46,8 @@ under the License. pom.xml + ../require-files-exist/pom.xml + ${project.basedir}/../require-files-exist/pom.xml From 0b456640812d55f0266a7b5d4981cd8bb021a8b1 Mon Sep 17 00:00:00 2001 From: roadSurfer <38717523+roadSurfer@users.noreply.github.com> Date: Mon, 27 Nov 2023 10:41:42 +0000 Subject: [PATCH 04/13] Updated documentation with statement on filesystem case-sensitivity --- .../src/site/apt/requireFilesDontExist.apt.vm | 19 ++++++++------- .../src/site/apt/requireFilesExist.apt.vm | 19 ++++++++------- .../src/site/apt/requireFilesSize.apt.vm | 23 +++++++++++-------- 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/enforcer-rules/src/site/apt/requireFilesDontExist.apt.vm b/enforcer-rules/src/site/apt/requireFilesDontExist.apt.vm index 53b8ca686..89c52f7ee 100644 --- a/enforcer-rules/src/site/apt/requireFilesDontExist.apt.vm +++ b/enforcer-rules/src/site/apt/requireFilesDontExist.apt.vm @@ -13,8 +13,8 @@ ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations -~~ under the License. - +~~ under the License. + ------ Require Files Dont Exist ------ @@ -27,22 +27,25 @@ Require Files Don't Exist This rule checks that the specified list of files do not exist. + The filesystem(s) will dictate the case-sensitive rules when checking files. If you require checks that your + filesystem(s) do not support (e.g. a case-sensitive check on a case-insensitive filesystem) then you should consider + adding your own custom plugin that meets your specific needs. The following parameters are supported by this rule: - + * <> - an optional message to the user if the rule fails. - + * <> - A list of files to check. - + * <> - If null files should be allowed. If allowed, they will be treated as if they do not exist. Default is false. * <> - Allows that one of files can make the rule pass, instead of all the files. Default is false. - + [] - + Sample Plugin Configuration: - + +---+ [...] diff --git a/enforcer-rules/src/site/apt/requireFilesExist.apt.vm b/enforcer-rules/src/site/apt/requireFilesExist.apt.vm index 5a65f9ee2..9d67a4f44 100644 --- a/enforcer-rules/src/site/apt/requireFilesExist.apt.vm +++ b/enforcer-rules/src/site/apt/requireFilesExist.apt.vm @@ -13,8 +13,8 @@ ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations -~~ under the License. - +~~ under the License. + ------ Require Files Exist ------ @@ -27,22 +27,25 @@ Require Files Exist This rule checks that the specified list of files exist. + The filesystem(s) will dictate the case-sensitive rules when checking files. If you require checks that your + filesystem(s) do not support (e.g. a case-sensitive check on a case-insensitive filesystem) then you should consider + adding your own custom plugin that meets your specific needs. The following parameters are supported by this rule: - + * <> - an optional message to the user if the rule fails. - + * <> - A list of files to check. - + * <> - If null files should be allowed. If allowed, they will be treated as if they do exist. Default is false. * <> - Allows that one of files can make the rule pass, instead of all the files. Default is false. - + [] - + Sample Plugin Configuration: - + +---+ [...] diff --git a/enforcer-rules/src/site/apt/requireFilesSize.apt.vm b/enforcer-rules/src/site/apt/requireFilesSize.apt.vm index ed4fa0d8e..b8b30ad79 100644 --- a/enforcer-rules/src/site/apt/requireFilesSize.apt.vm +++ b/enforcer-rules/src/site/apt/requireFilesSize.apt.vm @@ -13,8 +13,8 @@ ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations -~~ under the License. - +~~ under the License. + ------ Require File Size ------ @@ -27,26 +27,29 @@ Require File Size This rule checks that the specified list of files exist and are within the specified size range. + The filesystem(s) will dictate the case-sensitive rules when checking files. If you require checks that your + filesystem(s) do not support (e.g. a case-sensitive check on a case-insensitive filesystem) then you should consider + adding your own custom plugin that meets your specific needs. The following parameters are supported by this rule: - + * <> - an optional message to the user if the rule fails. - + * <> - A list of files to check. If this list is empty, the main project artifact will be checked. - + * <> - maximum size in bytes for this file. - + * <> - minimum size in bytes for this file. - + * <> - If null files should be allowed. If allowed, they will be treated as if they do exist. Default is false. * <> - Allows that one of files can make the rule pass, instead of all the files. Default is false. - + [] - + Sample Plugin Configuration: - + +---+ [...] From 326ff7fa0da07a7cefe0d90757fb64a3821bb5b2 Mon Sep 17 00:00:00 2001 From: roadSurfer <38717523+roadSurfer@users.noreply.github.com> Date: Mon, 27 Nov 2023 10:42:29 +0000 Subject: [PATCH 05/13] Added explicit testing of symbolic links --- .../files/TestRequireFilesDontExist.java | 51 ++++++++++++++++--- .../rules/files/TestRequireFilesExist.java | 36 +++++++++++++ .../rules/files/TestRequireFilesSize.java | 45 ++++++++++++++++ 3 files changed, 126 insertions(+), 6 deletions(-) diff --git a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java index 93a1a0e39..0c4c21a4e 100644 --- a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java +++ b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java @@ -20,6 +20,9 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Arrays; import java.util.Collections; @@ -27,10 +30,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.*; /** * Test the "require files don't exist" rule. @@ -107,15 +107,54 @@ void testEmptyFileListAllowNull() { @Test void testFileDoesNotExist() throws EnforcerRuleException, IOException { File f = File.createTempFile("junit", null, temporaryFolder); + rule.setFilesList(Collections.singletonList(f)); + + EnforcerRuleException e = assertThrows(EnforcerRuleException.class, rule::execute); + assertNotNull(e.getMessage()); + f.delete(); assertFalse(f.exists()); - rule.setFilesList(Collections.singletonList(f)); - rule.execute(); } + @Test + void testSymbolicLinkDoesNotExist() throws Exception { + File canonicalFile = File.createTempFile("canonical_", null, temporaryFolder); + File linkFile = Files.createSymbolicLink(Paths.get(temporaryFolder.getAbsolutePath(), "symbolic.link"), + Paths.get(canonicalFile.getAbsolutePath())).toFile(); + + try { + rule.setFilesList(Collections.singletonList(linkFile)); + EnforcerRuleException e = assertThrows(EnforcerRuleException.class, rule::execute); + assertNotNull(e.getMessage()); + + linkFile.delete(); + rule.execute(); + } finally { + if (linkFile.exists()) { + linkFile.delete(); + } + canonicalFile.delete(); + } + } + + @Test + void testSymbolicLinkTargetDoesNotExist() throws Exception { + File canonicalFile = File.createTempFile("canonical_", null, temporaryFolder); + File linkFile = Files.createSymbolicLink(Paths.get(temporaryFolder.getAbsolutePath(), "symbolic.link"), + Paths.get(canonicalFile.getAbsolutePath())).toFile(); + canonicalFile.delete(); + rule.setFilesList(Collections.singletonList(linkFile)); + + try { + rule.execute(); + } finally { + linkFile.delete(); + } + } + @Test void testFileDoesNotExistSatisfyAny() throws EnforcerRuleException, IOException { File f = File.createTempFile("junit", null, temporaryFolder); diff --git a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesExist.java b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesExist.java index fc9192b8f..279b48a34 100644 --- a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesExist.java +++ b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesExist.java @@ -20,6 +20,9 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Arrays; import java.util.Collections; @@ -49,6 +52,39 @@ void testFileExists() throws Exception { rule.execute(); } + @Test + void testSymbolicLinkExists() throws Exception { + File canonicalFile = File.createTempFile("canonical_", null, temporaryFolder); + File linkFile = Files.createSymbolicLink(Paths.get(temporaryFolder.getAbsolutePath(), "symbolic.link"), + Paths.get(canonicalFile.getAbsolutePath())).toFile(); + rule.setFilesList(Collections.singletonList(linkFile)); + + try { + rule.execute(); + } finally { + linkFile.delete(); + canonicalFile.delete(); + } + } + + @Test + void testSymbolicLinkTargetDoesNotExist() throws Exception { + File canonicalFile = File.createTempFile("canonical_", null, temporaryFolder); + File linkFile = Files.createSymbolicLink(Paths.get(temporaryFolder.getAbsolutePath(), "symbolic.link"), + Paths.get(canonicalFile.getAbsolutePath())).toFile(); + canonicalFile.delete(); + rule.setFilesList(Collections.singletonList(linkFile)); + + try { + rule.execute(); + fail("Should get an exception"); + } catch (Exception e) { + assertNotNull(e.getMessage()); + } finally { + linkFile.delete(); + } + } + @Test void testEmptyFile() { rule.setFilesList(Collections.singletonList(null)); diff --git a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesSize.java b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesSize.java index f0a7a042b..cd4048f25 100644 --- a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesSize.java +++ b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesSize.java @@ -22,6 +22,9 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Arrays; import java.util.Collections; @@ -180,6 +183,48 @@ void testRequireFilesSizeSatisfyAny() throws EnforcerRuleException, IOException rule.execute(); } + @Test + void testSymbolicLinkTooSmall() throws Exception { + File canonicalFile = File.createTempFile("canonical_", null, temporaryFolder); + File linkFile = Files.createSymbolicLink(Paths.get(temporaryFolder.getAbsolutePath(), "symbolic.link"), + Paths.get(canonicalFile.getAbsolutePath())).toFile(); + + rule.setFilesList(Arrays.asList(linkFile)); + rule.setMinsize(10); + try { + rule.execute(); + fail("Should get exception"); + } catch (EnforcerRuleException e) { + assertNotNull(e.getMessage()); + } finally { + linkFile.delete(); + canonicalFile.delete(); + } + } + + @Test + void testSymbolicLinkTooBig() throws Exception { + File canonicalFile = File.createTempFile("canonical_", null, temporaryFolder); + try (BufferedWriter out = new BufferedWriter(new FileWriter(canonicalFile))) { + out.write("123456789101112131415"); + } + assertTrue(canonicalFile.length() > 10); + File linkFile = Files.createSymbolicLink(Paths.get(temporaryFolder.getAbsolutePath(), "symbolic.link"), + Paths.get(canonicalFile.getAbsolutePath())).toFile(); + + rule.setFilesList(Arrays.asList(linkFile)); + rule.setMaxsize(10); + try { + rule.execute(); + fail("Should get exception"); + } catch (EnforcerRuleException e) { + assertNotNull(e.getMessage()); + } finally { + linkFile.delete(); + canonicalFile.delete(); + } + } + /** * Test id. */ From b82306decaf2a061a27b86a321f9beeaed7619cf Mon Sep 17 00:00:00 2001 From: roadSurfer <38717523+roadSurfer@users.noreply.github.com> Date: Mon, 27 Nov 2023 16:42:40 +0000 Subject: [PATCH 06/13] Maven Spotless fixes, no functional changes --- .../rules/files/TestRequireFilesDontExist.java | 13 ++++++++----- .../enforcer/rules/files/TestRequireFilesExist.java | 13 ++++++++----- .../enforcer/rules/files/TestRequireFilesSize.java | 13 ++++++++----- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java index 0c4c21a4e..e15639398 100644 --- a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java +++ b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java @@ -21,7 +21,6 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; import java.util.Collections; @@ -122,8 +121,10 @@ void testFileDoesNotExist() throws EnforcerRuleException, IOException { @Test void testSymbolicLinkDoesNotExist() throws Exception { File canonicalFile = File.createTempFile("canonical_", null, temporaryFolder); - File linkFile = Files.createSymbolicLink(Paths.get(temporaryFolder.getAbsolutePath(), "symbolic.link"), - Paths.get(canonicalFile.getAbsolutePath())).toFile(); + File linkFile = Files.createSymbolicLink( + Paths.get(temporaryFolder.getAbsolutePath(), "symbolic.link"), + Paths.get(canonicalFile.getAbsolutePath())) + .toFile(); try { rule.setFilesList(Collections.singletonList(linkFile)); @@ -143,8 +144,10 @@ void testSymbolicLinkDoesNotExist() throws Exception { @Test void testSymbolicLinkTargetDoesNotExist() throws Exception { File canonicalFile = File.createTempFile("canonical_", null, temporaryFolder); - File linkFile = Files.createSymbolicLink(Paths.get(temporaryFolder.getAbsolutePath(), "symbolic.link"), - Paths.get(canonicalFile.getAbsolutePath())).toFile(); + File linkFile = Files.createSymbolicLink( + Paths.get(temporaryFolder.getAbsolutePath(), "symbolic.link"), + Paths.get(canonicalFile.getAbsolutePath())) + .toFile(); canonicalFile.delete(); rule.setFilesList(Collections.singletonList(linkFile)); diff --git a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesExist.java b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesExist.java index 279b48a34..c69fe6a36 100644 --- a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesExist.java +++ b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesExist.java @@ -21,7 +21,6 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; import java.util.Collections; @@ -55,8 +54,10 @@ void testFileExists() throws Exception { @Test void testSymbolicLinkExists() throws Exception { File canonicalFile = File.createTempFile("canonical_", null, temporaryFolder); - File linkFile = Files.createSymbolicLink(Paths.get(temporaryFolder.getAbsolutePath(), "symbolic.link"), - Paths.get(canonicalFile.getAbsolutePath())).toFile(); + File linkFile = Files.createSymbolicLink( + Paths.get(temporaryFolder.getAbsolutePath(), "symbolic.link"), + Paths.get(canonicalFile.getAbsolutePath())) + .toFile(); rule.setFilesList(Collections.singletonList(linkFile)); try { @@ -70,8 +71,10 @@ void testSymbolicLinkExists() throws Exception { @Test void testSymbolicLinkTargetDoesNotExist() throws Exception { File canonicalFile = File.createTempFile("canonical_", null, temporaryFolder); - File linkFile = Files.createSymbolicLink(Paths.get(temporaryFolder.getAbsolutePath(), "symbolic.link"), - Paths.get(canonicalFile.getAbsolutePath())).toFile(); + File linkFile = Files.createSymbolicLink( + Paths.get(temporaryFolder.getAbsolutePath(), "symbolic.link"), + Paths.get(canonicalFile.getAbsolutePath())) + .toFile(); canonicalFile.delete(); rule.setFilesList(Collections.singletonList(linkFile)); diff --git a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesSize.java b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesSize.java index cd4048f25..d53c36a9c 100644 --- a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesSize.java +++ b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesSize.java @@ -23,7 +23,6 @@ import java.io.FileWriter; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; import java.util.Collections; @@ -186,8 +185,10 @@ void testRequireFilesSizeSatisfyAny() throws EnforcerRuleException, IOException @Test void testSymbolicLinkTooSmall() throws Exception { File canonicalFile = File.createTempFile("canonical_", null, temporaryFolder); - File linkFile = Files.createSymbolicLink(Paths.get(temporaryFolder.getAbsolutePath(), "symbolic.link"), - Paths.get(canonicalFile.getAbsolutePath())).toFile(); + File linkFile = Files.createSymbolicLink( + Paths.get(temporaryFolder.getAbsolutePath(), "symbolic.link"), + Paths.get(canonicalFile.getAbsolutePath())) + .toFile(); rule.setFilesList(Arrays.asList(linkFile)); rule.setMinsize(10); @@ -209,8 +210,10 @@ void testSymbolicLinkTooBig() throws Exception { out.write("123456789101112131415"); } assertTrue(canonicalFile.length() > 10); - File linkFile = Files.createSymbolicLink(Paths.get(temporaryFolder.getAbsolutePath(), "symbolic.link"), - Paths.get(canonicalFile.getAbsolutePath())).toFile(); + File linkFile = Files.createSymbolicLink( + Paths.get(temporaryFolder.getAbsolutePath(), "symbolic.link"), + Paths.get(canonicalFile.getAbsolutePath())) + .toFile(); rule.setFilesList(Arrays.asList(linkFile)); rule.setMaxsize(10); From 01570d47cabafb0c7978ee0be41b2bb80f6eae05 Mon Sep 17 00:00:00 2001 From: roadSurfer <38717523+roadSurfer@users.noreply.github.com> Date: Mon, 27 Nov 2023 16:43:17 +0000 Subject: [PATCH 07/13] Fixed spurious whitespace changes --- .../src/site/apt/requireFilesDontExist.apt.vm | 20 ++++++++-------- .../src/site/apt/requireFilesExist.apt.vm | 20 ++++++++-------- .../src/site/apt/requireFilesSize.apt.vm | 24 +++++++++---------- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/enforcer-rules/src/site/apt/requireFilesDontExist.apt.vm b/enforcer-rules/src/site/apt/requireFilesDontExist.apt.vm index 89c52f7ee..ba7a53c24 100644 --- a/enforcer-rules/src/site/apt/requireFilesDontExist.apt.vm +++ b/enforcer-rules/src/site/apt/requireFilesDontExist.apt.vm @@ -13,8 +13,8 @@ ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations -~~ under the License. - +~~ under the License. + ------ Require Files Dont Exist ------ @@ -26,26 +26,26 @@ Require Files Don't Exist This rule checks that the specified list of files do not exist. - - The filesystem(s) will dictate the case-sensitive rules when checking files. If you require checks that your + + The mounted filesystem(s) will dictate the case-sensitive rules when checking files. If you require checks that your filesystem(s) do not support (e.g. a case-sensitive check on a case-insensitive filesystem) then you should consider adding your own custom plugin that meets your specific needs. The following parameters are supported by this rule: - + * <> - an optional message to the user if the rule fails. - + * <> - A list of files to check. - + * <> - If null files should be allowed. If allowed, they will be treated as if they do not exist. Default is false. * <> - Allows that one of files can make the rule pass, instead of all the files. Default is false. - + [] - + Sample Plugin Configuration: - + +---+ [...] diff --git a/enforcer-rules/src/site/apt/requireFilesExist.apt.vm b/enforcer-rules/src/site/apt/requireFilesExist.apt.vm index 9d67a4f44..06e8a0cc8 100644 --- a/enforcer-rules/src/site/apt/requireFilesExist.apt.vm +++ b/enforcer-rules/src/site/apt/requireFilesExist.apt.vm @@ -13,8 +13,8 @@ ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations -~~ under the License. - +~~ under the License. + ------ Require Files Exist ------ @@ -26,26 +26,26 @@ Require Files Exist This rule checks that the specified list of files exist. - - The filesystem(s) will dictate the case-sensitive rules when checking files. If you require checks that your + + The mounted filesystem(s) will dictate the case-sensitive rules when checking files. If you require checks that your filesystem(s) do not support (e.g. a case-sensitive check on a case-insensitive filesystem) then you should consider adding your own custom plugin that meets your specific needs. The following parameters are supported by this rule: - + * <> - an optional message to the user if the rule fails. - + * <> - A list of files to check. - + * <> - If null files should be allowed. If allowed, they will be treated as if they do exist. Default is false. * <> - Allows that one of files can make the rule pass, instead of all the files. Default is false. - + [] - + Sample Plugin Configuration: - + +---+ [...] diff --git a/enforcer-rules/src/site/apt/requireFilesSize.apt.vm b/enforcer-rules/src/site/apt/requireFilesSize.apt.vm index b8b30ad79..e2ba7f89f 100644 --- a/enforcer-rules/src/site/apt/requireFilesSize.apt.vm +++ b/enforcer-rules/src/site/apt/requireFilesSize.apt.vm @@ -13,8 +13,8 @@ ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations -~~ under the License. - +~~ under the License. + ------ Require File Size ------ @@ -26,30 +26,30 @@ Require File Size This rule checks that the specified list of files exist and are within the specified size range. - - The filesystem(s) will dictate the case-sensitive rules when checking files. If you require checks that your + + The mounted filesystem(s) will dictate the case-sensitive rules when checking files. If you require checks that your filesystem(s) do not support (e.g. a case-sensitive check on a case-insensitive filesystem) then you should consider adding your own custom plugin that meets your specific needs. The following parameters are supported by this rule: - + * <> - an optional message to the user if the rule fails. - + * <> - A list of files to check. If this list is empty, the main project artifact will be checked. - + * <> - maximum size in bytes for this file. - + * <> - minimum size in bytes for this file. - + * <> - If null files should be allowed. If allowed, they will be treated as if they do exist. Default is false. * <> - Allows that one of files can make the rule pass, instead of all the files. Default is false. - + [] - + Sample Plugin Configuration: - + +---+ [...] From 11dbb9550fea6782d830af74fd36fa6771fe2db3 Mon Sep 17 00:00:00 2001 From: roadSurfer <38717523+roadSurfer@users.noreply.github.com> Date: Thu, 9 Jan 2025 10:21:26 +0000 Subject: [PATCH 08/13] Language changes as requested --- enforcer-rules/src/site/apt/requireFilesDontExist.apt.vm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/enforcer-rules/src/site/apt/requireFilesDontExist.apt.vm b/enforcer-rules/src/site/apt/requireFilesDontExist.apt.vm index ba7a53c24..06e414249 100644 --- a/enforcer-rules/src/site/apt/requireFilesDontExist.apt.vm +++ b/enforcer-rules/src/site/apt/requireFilesDontExist.apt.vm @@ -27,9 +27,9 @@ Require Files Don't Exist This rule checks that the specified list of files do not exist. - The mounted filesystem(s) will dictate the case-sensitive rules when checking files. If you require checks that your - filesystem(s) do not support (e.g. a case-sensitive check on a case-insensitive filesystem) then you should consider - adding your own custom plugin that meets your specific needs. + The mounted filesystem(s) will dictate the case-sensitivity rules when checking files. If checks are required that + filesystem(s) do not support (e.g. a case-sensitive check on a case-insensitive filesystem) consider adding a custom + plugin that meets the specific needs. The following parameters are supported by this rule: From e0d8be0b98c4be90d86e31c58e1883dcd4bed7eb Mon Sep 17 00:00:00 2001 From: roadSurfer <38717523+roadSurfer@users.noreply.github.com> Date: Thu, 9 Jan 2025 10:22:31 +0000 Subject: [PATCH 09/13] Code changes per PR comments --- .../rules/files/TestRequireFilesDontExist.java | 17 ++++++++++++++++- .../rules/files/TestRequireFilesExist.java | 6 +++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java index e15639398..bf683371b 100644 --- a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java +++ b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java @@ -29,7 +29,11 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * Test the "require files don't exist" rule. @@ -108,6 +112,7 @@ void testFileDoesNotExist() throws EnforcerRuleException, IOException { File f = File.createTempFile("junit", null, temporaryFolder); rule.setFilesList(Collections.singletonList(f)); + // Check the file is detected as being present EnforcerRuleException e = assertThrows(EnforcerRuleException.class, rule::execute); assertNotNull(e.getMessage()); @@ -115,6 +120,7 @@ void testFileDoesNotExist() throws EnforcerRuleException, IOException { assertFalse(f.exists()); + // Rule should now pass as the file was deleted rule.execute(); } @@ -128,10 +134,13 @@ void testSymbolicLinkDoesNotExist() throws Exception { try { rule.setFilesList(Collections.singletonList(linkFile)); + // Check the link is detected as being present EnforcerRuleException e = assertThrows(EnforcerRuleException.class, rule::execute); assertNotNull(e.getMessage()); linkFile.delete(); + + // Rule should now pass as the link was deleted rule.execute(); } finally { if (linkFile.exists()) { @@ -148,10 +157,16 @@ void testSymbolicLinkTargetDoesNotExist() throws Exception { Paths.get(temporaryFolder.getAbsolutePath(), "symbolic.link"), Paths.get(canonicalFile.getAbsolutePath())) .toFile(); + + // Check the target is detected as being present + EnforcerRuleException e = assertThrows(EnforcerRuleException.class, rule::execute); + assertNotNull(e.getMessage()); + canonicalFile.delete(); rule.setFilesList(Collections.singletonList(linkFile)); try { + // Rule should now pass as the target was deleted rule.execute(); } finally { linkFile.delete(); diff --git a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesExist.java b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesExist.java index c69fe6a36..5e8c2dcb1 100644 --- a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesExist.java +++ b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesExist.java @@ -29,7 +29,11 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * Test the "require files exist" rule. From 14449e160ffb3155dfcf6e53ae3772406efbe9ec Mon Sep 17 00:00:00 2001 From: roadSurfer <38717523+roadSurfer@users.noreply.github.com> Date: Fri, 10 Jan 2025 09:54:58 +0000 Subject: [PATCH 10/13] Further updates per PR comments --- .../rules/files/RequireFilesExist.java | 2 +- .../src/site/apt/requireFilesExist.apt.vm | 20 ++++++------- .../src/site/apt/requireFilesSize.apt.vm | 24 +++++++-------- .../files/TestRequireFilesDontExist.java | 29 ++++++------------- .../rules/files/TestRequireFilesExist.java | 12 ++------ .../rules/files/TestRequireFilesSize.java | 6 ---- 6 files changed, 35 insertions(+), 58 deletions(-) diff --git a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/files/RequireFilesExist.java b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/files/RequireFilesExist.java index bdaecf880..31c109e41 100644 --- a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/files/RequireFilesExist.java +++ b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/files/RequireFilesExist.java @@ -30,7 +30,7 @@ public final class RequireFilesExist extends AbstractRequireFiles { @Override boolean checkFile(File file) { // if we get here and the handle is null, treat it as a success - return file == null ? true : file.exists(); + return file == null || file.exists(); } @Override diff --git a/enforcer-rules/src/site/apt/requireFilesExist.apt.vm b/enforcer-rules/src/site/apt/requireFilesExist.apt.vm index 06e8a0cc8..e0f97c43d 100644 --- a/enforcer-rules/src/site/apt/requireFilesExist.apt.vm +++ b/enforcer-rules/src/site/apt/requireFilesExist.apt.vm @@ -13,8 +13,8 @@ ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations -~~ under the License. - +~~ under the License. + ------ Require Files Exist ------ @@ -26,26 +26,26 @@ Require Files Exist This rule checks that the specified list of files exist. - - The mounted filesystem(s) will dictate the case-sensitive rules when checking files. If you require checks that your + + The mounted filesystem(s) will dictate the case-sensitivity rules when checking files. If you require checks that your filesystem(s) do not support (e.g. a case-sensitive check on a case-insensitive filesystem) then you should consider adding your own custom plugin that meets your specific needs. The following parameters are supported by this rule: - + * <> - an optional message to the user if the rule fails. - + * <> - A list of files to check. - + * <> - If null files should be allowed. If allowed, they will be treated as if they do exist. Default is false. * <> - Allows that one of files can make the rule pass, instead of all the files. Default is false. - + [] - + Sample Plugin Configuration: - + +---+ [...] diff --git a/enforcer-rules/src/site/apt/requireFilesSize.apt.vm b/enforcer-rules/src/site/apt/requireFilesSize.apt.vm index e2ba7f89f..dd2cd1017 100644 --- a/enforcer-rules/src/site/apt/requireFilesSize.apt.vm +++ b/enforcer-rules/src/site/apt/requireFilesSize.apt.vm @@ -13,8 +13,8 @@ ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations -~~ under the License. - +~~ under the License. + ------ Require File Size ------ @@ -26,30 +26,30 @@ Require File Size This rule checks that the specified list of files exist and are within the specified size range. - - The mounted filesystem(s) will dictate the case-sensitive rules when checking files. If you require checks that your + + The mounted filesystem(s) will dictate the case-sensitivity rules when checking files. If you require checks that your filesystem(s) do not support (e.g. a case-sensitive check on a case-insensitive filesystem) then you should consider adding your own custom plugin that meets your specific needs. The following parameters are supported by this rule: - + * <> - an optional message to the user if the rule fails. - + * <> - A list of files to check. If this list is empty, the main project artifact will be checked. - + * <> - maximum size in bytes for this file. - + * <> - minimum size in bytes for this file. - + * <> - If null files should be allowed. If allowed, they will be treated as if they do exist. Default is false. * <> - Allows that one of files can make the rule pass, instead of all the files. Default is false. - + [] - + Sample Plugin Configuration: - + +---+ [...] diff --git a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java index bf683371b..552c81e05 100644 --- a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java +++ b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java @@ -132,22 +132,15 @@ void testSymbolicLinkDoesNotExist() throws Exception { Paths.get(canonicalFile.getAbsolutePath())) .toFile(); - try { - rule.setFilesList(Collections.singletonList(linkFile)); - // Check the link is detected as being present - EnforcerRuleException e = assertThrows(EnforcerRuleException.class, rule::execute); - assertNotNull(e.getMessage()); + rule.setFilesList(Collections.singletonList(linkFile)); + // Check the link is detected as being present + EnforcerRuleException e = assertThrows(EnforcerRuleException.class, rule::execute); + assertNotNull(e.getMessage()); - linkFile.delete(); + linkFile.delete(); - // Rule should now pass as the link was deleted - rule.execute(); - } finally { - if (linkFile.exists()) { - linkFile.delete(); - } - canonicalFile.delete(); - } + // Rule should now pass as the link was deleted + rule.execute(); } @Test @@ -165,12 +158,8 @@ void testSymbolicLinkTargetDoesNotExist() throws Exception { canonicalFile.delete(); rule.setFilesList(Collections.singletonList(linkFile)); - try { - // Rule should now pass as the target was deleted - rule.execute(); - } finally { - linkFile.delete(); - } + // Rule should now pass as the target was deleted + rule.execute(); } @Test diff --git a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesExist.java b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesExist.java index 5e8c2dcb1..04769ea33 100644 --- a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesExist.java +++ b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesExist.java @@ -62,14 +62,10 @@ void testSymbolicLinkExists() throws Exception { Paths.get(temporaryFolder.getAbsolutePath(), "symbolic.link"), Paths.get(canonicalFile.getAbsolutePath())) .toFile(); + rule.setFilesList(Collections.singletonList(linkFile)); - try { - rule.execute(); - } finally { - linkFile.delete(); - canonicalFile.delete(); - } + rule.execute(); } @Test @@ -84,11 +80,9 @@ void testSymbolicLinkTargetDoesNotExist() throws Exception { try { rule.execute(); - fail("Should get an exception"); + fail("Should have received an exception"); } catch (Exception e) { assertNotNull(e.getMessage()); - } finally { - linkFile.delete(); } } diff --git a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesSize.java b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesSize.java index d53c36a9c..e6377095e 100644 --- a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesSize.java +++ b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesSize.java @@ -197,9 +197,6 @@ void testSymbolicLinkTooSmall() throws Exception { fail("Should get exception"); } catch (EnforcerRuleException e) { assertNotNull(e.getMessage()); - } finally { - linkFile.delete(); - canonicalFile.delete(); } } @@ -222,9 +219,6 @@ void testSymbolicLinkTooBig() throws Exception { fail("Should get exception"); } catch (EnforcerRuleException e) { assertNotNull(e.getMessage()); - } finally { - linkFile.delete(); - canonicalFile.delete(); } } From 61211d907b136765ff324ec1a1a85f79e8d54a01 Mon Sep 17 00:00:00 2001 From: roadSurfer <38717523+roadSurfer@users.noreply.github.com> Date: Fri, 31 Jan 2025 15:22:59 +0000 Subject: [PATCH 11/13] Further updates per PR comments --- .../rules/files/TestRequireFilesDontExist.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java index 552c81e05..c1f44bc68 100644 --- a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java +++ b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java @@ -34,6 +34,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assumptions.assumeFalse; /** * Test the "require files don't exist" rule. @@ -108,13 +109,13 @@ void testEmptyFileListAllowNull() { } @Test - void testFileDoesNotExist() throws EnforcerRuleException, IOException { + void testDeletedFileDetected() throws EnforcerRuleException, IOException { File f = File.createTempFile("junit", null, temporaryFolder); rule.setFilesList(Collections.singletonList(f)); // Check the file is detected as being present EnforcerRuleException e = assertThrows(EnforcerRuleException.class, rule::execute); - assertNotNull(e.getMessage()); + assumeFalse(e.getMessage() == null); f.delete(); @@ -125,7 +126,7 @@ void testFileDoesNotExist() throws EnforcerRuleException, IOException { } @Test - void testSymbolicLinkDoesNotExist() throws Exception { + void testSymbolicLinkDeletedDetected() throws Exception { File canonicalFile = File.createTempFile("canonical_", null, temporaryFolder); File linkFile = Files.createSymbolicLink( Paths.get(temporaryFolder.getAbsolutePath(), "symbolic.link"), @@ -135,16 +136,16 @@ void testSymbolicLinkDoesNotExist() throws Exception { rule.setFilesList(Collections.singletonList(linkFile)); // Check the link is detected as being present EnforcerRuleException e = assertThrows(EnforcerRuleException.class, rule::execute); - assertNotNull(e.getMessage()); + assumeFalse(e.getMessage() == null); linkFile.delete(); - // Rule should now pass as the link was deleted + // Rule should now pass as the target was deleted rule.execute(); } @Test - void testSymbolicLinkTargetDoesNotExist() throws Exception { + void testSymbolicLinkTargetDeletedDetected() throws Exception { File canonicalFile = File.createTempFile("canonical_", null, temporaryFolder); File linkFile = Files.createSymbolicLink( Paths.get(temporaryFolder.getAbsolutePath(), "symbolic.link"), @@ -153,7 +154,7 @@ void testSymbolicLinkTargetDoesNotExist() throws Exception { // Check the target is detected as being present EnforcerRuleException e = assertThrows(EnforcerRuleException.class, rule::execute); - assertNotNull(e.getMessage()); + assumeFalse(e.getMessage() == null); canonicalFile.delete(); rule.setFilesList(Collections.singletonList(linkFile)); @@ -163,7 +164,7 @@ void testSymbolicLinkTargetDoesNotExist() throws Exception { } @Test - void testFileDoesNotExistSatisfyAny() throws EnforcerRuleException, IOException { + void testDeletedFileDetectedSatisfyAny() throws EnforcerRuleException, IOException { File f = File.createTempFile("junit", null, temporaryFolder); f.delete(); From 4c62cb696ed131127c2f7c3110912fda4502eb10 Mon Sep 17 00:00:00 2001 From: roadSurfer <38717523+roadSurfer@users.noreply.github.com> Date: Mon, 3 Feb 2025 16:49:54 +0000 Subject: [PATCH 12/13] Further updates per PR comments --- .../src/site/apt/requireFilesDontExist.apt.vm | 24 +++++++++---------- .../src/site/apt/requireFilesExist.apt.vm | 6 ++--- .../files/TestRequireFilesDontExist.java | 6 ++--- .../rules/files/TestRequireFilesExist.java | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/enforcer-rules/src/site/apt/requireFilesDontExist.apt.vm b/enforcer-rules/src/site/apt/requireFilesDontExist.apt.vm index 06e414249..d63d2cee5 100644 --- a/enforcer-rules/src/site/apt/requireFilesDontExist.apt.vm +++ b/enforcer-rules/src/site/apt/requireFilesDontExist.apt.vm @@ -13,8 +13,8 @@ ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations -~~ under the License. - +~~ under the License. + ------ Require Files Dont Exist ------ @@ -25,27 +25,27 @@ Require Files Don't Exist - This rule checks that the specified list of files do not exist. - - The mounted filesystem(s) will dictate the case-sensitivity rules when checking files. If checks are required that - filesystem(s) do not support (e.g. a case-sensitive check on a case-insensitive filesystem) consider adding a custom + This rule checks that the specified files do not exist. + + The filesystem will dictate the case-sensitivity rules when checking files. If checks are required that + filesystem do not support (e.g. a case-sensitive check on a case-insensitive filesystem) consider adding a custom plugin that meets the specific needs. The following parameters are supported by this rule: - + * <> - an optional message to the user if the rule fails. - + * <> - A list of files to check. - + * <> - If null files should be allowed. If allowed, they will be treated as if they do not exist. Default is false. * <> - Allows that one of files can make the rule pass, instead of all the files. Default is false. - + [] - + Sample Plugin Configuration: - + +---+ [...] diff --git a/enforcer-rules/src/site/apt/requireFilesExist.apt.vm b/enforcer-rules/src/site/apt/requireFilesExist.apt.vm index e0f97c43d..177c37a3c 100644 --- a/enforcer-rules/src/site/apt/requireFilesExist.apt.vm +++ b/enforcer-rules/src/site/apt/requireFilesExist.apt.vm @@ -25,10 +25,10 @@ Require Files Exist - This rule checks that the specified list of files exist. + This rule checks that the specified files exist. - The mounted filesystem(s) will dictate the case-sensitivity rules when checking files. If you require checks that your - filesystem(s) do not support (e.g. a case-sensitive check on a case-insensitive filesystem) then you should consider + The filesystem will dictate the case-sensitivity rules when checking files. If you require checks that your + filesystem do not support (e.g. a case-sensitive check on a case-insensitive filesystem) then you should consider adding your own custom plugin that meets your specific needs. The following parameters are supported by this rule: diff --git a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java index c1f44bc68..d6890240e 100644 --- a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java +++ b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java @@ -115,11 +115,11 @@ void testDeletedFileDetected() throws EnforcerRuleException, IOException { // Check the file is detected as being present EnforcerRuleException e = assertThrows(EnforcerRuleException.class, rule::execute); - assumeFalse(e.getMessage() == null); + assertNotNull(e.getMessage()); f.delete(); - assertFalse(f.exists()); + assumeFalse(f.exists()); // Rule should now pass as the file was deleted rule.execute(); @@ -136,7 +136,7 @@ void testSymbolicLinkDeletedDetected() throws Exception { rule.setFilesList(Collections.singletonList(linkFile)); // Check the link is detected as being present EnforcerRuleException e = assertThrows(EnforcerRuleException.class, rule::execute); - assumeFalse(e.getMessage() == null); + assertNotNull(e.getMessage()); linkFile.delete(); diff --git a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesExist.java b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesExist.java index 04769ea33..9e346566c 100644 --- a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesExist.java +++ b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesExist.java @@ -81,7 +81,7 @@ void testSymbolicLinkTargetDoesNotExist() throws Exception { try { rule.execute(); fail("Should have received an exception"); - } catch (Exception e) { + } catch (EnforcerRuleException e) { assertNotNull(e.getMessage()); } } From 86dc7ee170da44926e6ee40d9e22f9eafeb005c5 Mon Sep 17 00:00:00 2001 From: roadSurfer <38717523+roadSurfer@users.noreply.github.com> Date: Mon, 3 Feb 2025 17:10:09 +0000 Subject: [PATCH 13/13] Further updates per PR comments --- .../maven/enforcer/rules/files/TestRequireFilesDontExist.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java index d6890240e..bc31981c5 100644 --- a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java +++ b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/files/TestRequireFilesDontExist.java @@ -154,7 +154,7 @@ void testSymbolicLinkTargetDeletedDetected() throws Exception { // Check the target is detected as being present EnforcerRuleException e = assertThrows(EnforcerRuleException.class, rule::execute); - assumeFalse(e.getMessage() == null); + assertNotNull(e.getMessage()); canonicalFile.delete(); rule.setFilesList(Collections.singletonList(linkFile));