Skip to content

Commit

Permalink
Treat dot files and folders as internal
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsromero committed Jul 26, 2021
1 parent 3ca4640 commit 7d28c66
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class AsciidoctorFileScanner {
public static String[] INTERNAL_FOLDERS_AND_FILES_PATTERNS = {
"**/_*.*",
"**/_*",
"**/.*",
"**/_*/**/*.*",
};

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ private List<File> 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;
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/test/java/org/asciidoctor/maven/AsciidoctorMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<File> sanitizedExpected = Arrays.stream(expected)
.filter(file -> !file.getName().startsWith("_"))
.filter(file -> {
char firstChar = file.getName().charAt(0);
return firstChar != '_' && firstChar != '.';
})
.collect(Collectors.toList());

List<String> expectedNames = sanitizedExpected.stream().map(File::getName).collect(Collectors.toList());
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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?
Original file line number Diff line number Diff line change
@@ -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?

0 comments on commit 7d28c66

Please sign in to comment.