From 35b13ffca357f014c6d65b74a9b3cac2582f5efb Mon Sep 17 00:00:00 2001 From: Abel Salgado Romero Date: Sat, 31 Jul 2021 20:45:42 +0200 Subject: [PATCH] Treat dot files and folders as internal (#550) --- CHANGELOG.adoc | 3 ++- .../org/asciidoctor/maven/io/AsciidoctorFileScanner.java | 4 +++- .../asciidoctor/maven/process/SourceDocumentFinder.java | 3 ++- .../java/org/asciidoctor/maven/AsciidoctorMojoTest.java | 8 +++++--- .../maven/process/SourceDocumentFinderTest.java | 4 ++-- .../.these_sources_are_not_processed/ignored.adoc | 8 ++++++++ .../level-1-1/.internal-dot-partial.adoc | 8 ++++++++ 7 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 src/test/resources/src/asciidoctor/relative-path-treatment/.these_sources_are_not_processed/ignored.adoc create mode 100644 src/test/resources/src/asciidoctor/relative-path-treatment/level-1-1/.internal-dot-partial.adoc diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 6fee3145..33b840fe 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -21,7 +21,8 @@ Documentation:: Bug Fixes:: - * Fix excluding sources when enclosing parent path starts with _ (#544) + * Fix excluding sources when enclosing parent path starts with _ (#546) + * Treat dot files and folders same as internal #5505) == v2.2.0 (2021-07-18) diff --git a/src/main/java/org/asciidoctor/maven/io/AsciidoctorFileScanner.java b/src/main/java/org/asciidoctor/maven/io/AsciidoctorFileScanner.java index ee68a205..8ed43770 100644 --- a/src/main/java/org/asciidoctor/maven/io/AsciidoctorFileScanner.java +++ b/src/main/java/org/asciidoctor/maven/io/AsciidoctorFileScanner.java @@ -24,6 +24,7 @@ public class AsciidoctorFileScanner { public static String[] INTERNAL_FOLDERS_AND_FILES_PATTERNS = { "**/_*.*", "**/_*", + "**/.*", "**/_*/**/*.*", }; @@ -40,7 +41,8 @@ public class AsciidoctorFileScanner { "docinfo-footer.xml", "*-docinfo.xml", "*-docinfo-header.xml", - "*-docinfo-footer.xml"}; + "*-docinfo-footer.xml" + }; private final BuildContext buildContext; diff --git a/src/main/java/org/asciidoctor/maven/process/SourceDocumentFinder.java b/src/main/java/org/asciidoctor/maven/process/SourceDocumentFinder.java index 144c00de..c746fdb5 100644 --- a/src/main/java/org/asciidoctor/maven/process/SourceDocumentFinder.java +++ b/src/main/java/org/asciidoctor/maven/process/SourceDocumentFinder.java @@ -59,7 +59,8 @@ private List find(Path sourceDirectory, Pattern sourceDocumentPattern) { .filter(path -> sourceDocumentPattern.matcher(path.getFileName().toString()).matches()) .filter(path -> { for (Path part : sourceDirectory.relativize(path)) { - if (part.toString().startsWith("_")) { + char firstCharacter = part.toString().charAt(0); + if (firstCharacter == '_' || firstCharacter == '.') { return false; } } diff --git a/src/test/java/org/asciidoctor/maven/AsciidoctorMojoTest.java b/src/test/java/org/asciidoctor/maven/AsciidoctorMojoTest.java index 117b30b2..d4162dc5 100644 --- a/src/test/java/org/asciidoctor/maven/AsciidoctorMojoTest.java +++ b/src/test/java/org/asciidoctor/maven/AsciidoctorMojoTest.java @@ -667,9 +667,11 @@ public void should_not_copy_custom_source_documents_when_custom_extensions_are_s */ private void assertEqualsStructure(File[] expected, File[] actual) { - List sanitizedExpected = Arrays.stream(expected) - .filter(file -> !file.getName().startsWith("_")) + .filter(file -> { + char firstChar = file.getName().charAt(0); + return firstChar != '_' && firstChar != '.'; + }) .collect(Collectors.toList()); List expectedNames = sanitizedExpected.stream().map(File::getName).collect(Collectors.toList()); @@ -691,7 +693,7 @@ private void assertEqualsStructure(File[] expected, File[] actual) { if (htmls.length > 0) { File[] asciidocs = expectedFile.listFiles(f -> { String asciidocFilePattern = ".*\\." + AsciidoctorFileScanner.ASCIIDOC_FILE_EXTENSIONS_REG_EXP + "$"; - return f.getName().matches(asciidocFilePattern) && !f.getName().startsWith("_"); + return f.getName().matches(asciidocFilePattern) && !f.getName().startsWith("_") && !f.getName().startsWith("."); }); Assertions.assertThat(htmls).hasSize(asciidocs.length); } diff --git a/src/test/java/org/asciidoctor/maven/process/SourceDocumentFinderTest.java b/src/test/java/org/asciidoctor/maven/process/SourceDocumentFinderTest.java index 95d53705..33d76d8f 100644 --- a/src/test/java/org/asciidoctor/maven/process/SourceDocumentFinderTest.java +++ b/src/test/java/org/asciidoctor/maven/process/SourceDocumentFinderTest.java @@ -105,7 +105,7 @@ public void should_exclude_hidden_sources() { // then assertThat(files) .hasSize(6) - .allMatch(file -> !file.getName().startsWith("_")); + .allMatch(file -> !file.getName().startsWith("_") || !file.getName().startsWith(".")); } @Test @@ -144,7 +144,7 @@ private boolean isContainedInInternalDirectory(File file) { int cursor = 0; do { cursor = path.indexOf(File.separator, cursor + 1); - if (path.charAt(cursor + 1) == '_') + if (path.charAt(cursor + 1) == '_' || path.charAt(cursor + 1) == '.') return true; } while (cursor != -1); return false; diff --git a/src/test/resources/src/asciidoctor/relative-path-treatment/.these_sources_are_not_processed/ignored.adoc b/src/test/resources/src/asciidoctor/relative-path-treatment/.these_sources_are_not_processed/ignored.adoc new file mode 100644 index 00000000..6f5a9436 --- /dev/null +++ b/src/test/resources/src/asciidoctor/relative-path-treatment/.these_sources_are_not_processed/ignored.adoc @@ -0,0 +1,8 @@ +:toc: left +:icons: + +== Summary +This document won't get converted by default because it is inside a hidden folder. + +Hidden folders begin with underscore `.`. + +TIP: How cool is this? diff --git a/src/test/resources/src/asciidoctor/relative-path-treatment/level-1-1/.internal-dot-partial.adoc b/src/test/resources/src/asciidoctor/relative-path-treatment/level-1-1/.internal-dot-partial.adoc new file mode 100644 index 00000000..f0b409bd --- /dev/null +++ b/src/test/resources/src/asciidoctor/relative-path-treatment/level-1-1/.internal-dot-partial.adoc @@ -0,0 +1,8 @@ +:toc: left +:icons: + +== Summary +This document won't get converted by default because it considered "internal". + +That is, is prefixed with a dot `.`. + +TIP: How cool is this?