Skip to content

Commit

Permalink
Remove unused class AsciidoctorFileScanner (asciidoctor#600)
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsromero authored Aug 28, 2022
1 parent 489de4c commit b6c6db6
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
import java.util.*;

import static org.asciidoctor.maven.commons.StringUtils.isBlank;
import static org.asciidoctor.maven.io.AsciidoctorFileScanner.ASCIIDOC_NON_INTERNAL_REG_EXP;
import static org.asciidoctor.maven.process.SourceDocumentFinder.CUSTOM_FILE_EXTENSIONS_PATTERN_PREFIX;
import static org.asciidoctor.maven.process.SourceDocumentFinder.CUSTOM_FILE_EXTENSIONS_PATTERN_SUFFIX;
import static org.asciidoctor.maven.process.SourceDocumentFinder.*;

@Mojo(name = "auto-refresh")
public class AsciidoctorRefreshMojo extends AsciidoctorMojo {
Expand Down Expand Up @@ -156,7 +154,7 @@ private IOFileFilter buildSourcesFileFilter() {
return FileFilterUtils.or(FileFilterUtils.directoryFileFilter(), new RegexFileFilter(stringJoiner.toString()));
}

return FileFilterUtils.or(FileFilterUtils.directoryFileFilter(), new RegexFileFilter(ASCIIDOC_NON_INTERNAL_REG_EXP));
return FileFilterUtils.or(FileFilterUtils.directoryFileFilter(), new RegexFileFilter(STANDARD_FILE_EXTENSIONS_PATTERN));
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.apache.commons.io.FileUtils;
import org.asciidoctor.maven.AsciidoctorMojo;
import org.asciidoctor.maven.io.AsciidoctorFileScanner;
import org.asciidoctor.maven.model.Resource;
import org.codehaus.plexus.util.DirectoryScanner;

Expand All @@ -25,6 +24,32 @@
*/
public class CopyResourcesProcessor implements ResourcesProcessor {

// docinfo snippets should not be copied
public static String[] IGNORED_FILE_NAMES = {
"docinfo.html",
"docinfo-header.html",
"docinfo-footer.html",
"*-docinfo.html",
"*-docinfo-header.html",
"*-docinfo-footer.html",
"docinfo.xml",
"docinfo-header.xml",
"docinfo-footer.xml",
"*-docinfo.xml",
"*-docinfo-header.xml",
"*-docinfo-footer.xml"
};

private static String[] DEFAULT_ASCIIDOC_EXTENSIONS = {"**/*.adoc", "**/*.ad", "**/*.asc", "**/*.asciidoc"};

// Files and directories beginning with underscore are ignored
private static String[] INTERNAL_FOLDERS_AND_FILES_PATTERNS = {
"**/_*.*",
"**/_*",
"**/.*",
"**/_*/**/*.*",
};

/*
* (non-Javadoc)
*
Expand Down Expand Up @@ -64,13 +89,14 @@ private List<Resource> prepareResources(File sourceDirectory, AsciidoctorMojo co
for (Resource resource : resources) {

List<String> excludes = new ArrayList<>();
for (String value : AsciidoctorFileScanner.INTERNAL_FOLDERS_AND_FILES_PATTERNS) {
for (String value : INTERNAL_FOLDERS_AND_FILES_PATTERNS) {
excludes.add(value);
}
for (String value : AsciidoctorFileScanner.IGNORED_FILE_NAMES) {
for (String value : IGNORED_FILE_NAMES) {
excludes.add("**/" + value);
}
for (String value : AsciidoctorFileScanner.DEFAULT_ASCIIDOC_EXTENSIONS) {

for (String value : DEFAULT_ASCIIDOC_EXTENSIONS) {
excludes.add(value);
}
// exclude filename extensions if defined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,23 @@
*/
public class SourceDocumentFinder {

/** Pattern for matching standard file extensions. */
private static final String STANDARD_FILE_EXTENSIONS_PATTERN = "^[^_.].*\\.a((sc(iidoc)?)|d(oc)?)$";
// copied from org.asciidoctor.AsciiDocDirectoryWalker.ASCIIDOC_REG_EXP_EXTENSION
// should probably be configured in AsciidoctorMojo through @Parameter 'extension'
public static final String ASCIIDOC_FILE_EXTENSIONS_REG_EXP = "a((sc(iidoc)?)|d(oc)?)";

/** Prefix for matching custom file extensions. */
/**
* Pattern for matching standard file extensions.
*/
public static final String STANDARD_FILE_EXTENSIONS_PATTERN = "^[^_.].*\\." + ASCIIDOC_FILE_EXTENSIONS_REG_EXP + "$";

/**
* Prefix for matching custom file extensions.
*/
public static final String CUSTOM_FILE_EXTENSIONS_PATTERN_PREFIX = "^[^_.].*\\.(";

/** Suffix for matching custom file extensions. */
/**
* Suffix for matching custom file extensions.
*/
public static final String CUSTOM_FILE_EXTENSIONS_PATTERN_SUFFIX = ")$";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package org.asciidoctor.maven.refresh;

import org.asciidoctor.maven.io.AsciidoctorFileScanner;

import java.util.Arrays;
import java.util.List;
import java.util.StringJoiner;
import java.util.stream.Collectors;

import static org.asciidoctor.maven.commons.StringUtils.isBlank;
import static org.asciidoctor.maven.io.AsciidoctorFileScanner.ASCIIDOC_FILE_EXTENSIONS_REG_EXP;
import static org.asciidoctor.maven.process.CopyResourcesProcessor.IGNORED_FILE_NAMES;
import static org.asciidoctor.maven.process.SourceDocumentFinder.ASCIIDOC_FILE_EXTENSIONS_REG_EXP;

/**
* Builds regular expression to include all valid resources, as well as exclude invalid ones
Expand All @@ -32,7 +31,7 @@ public String build() {
if (!sourceDocumentExtensions.isEmpty())
filePattern.add(String.join("|", sourceDocumentExtensions));

final String specialFiles = Arrays.stream(AsciidoctorFileScanner.IGNORED_FILE_NAMES)
final String specialFiles = Arrays.stream(IGNORED_FILE_NAMES)
.map(pattern -> pattern.replaceAll("\\*", ".*"))
.map(pattern -> pattern.replaceAll("\\.", "\\\\."))
.collect(Collectors.joining("|"));
Expand All @@ -41,7 +40,7 @@ public String build() {
.append("^")
.append("(?!(" + specialFiles + (isBlank(sourceDocumentName) ? "" : "|" + sourceDocumentName) + "))")
.append("[^_.].*\\.(?!(")
.append(filePattern.toString())
.append(filePattern)
.append(")).*$")
.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.apache.commons.io.IOUtils;
import org.apache.maven.plugin.logging.SystemStreamLog;
import org.apache.maven.project.MavenProject;
import org.asciidoctor.maven.io.AsciidoctorFileScanner;
import org.asciidoctor.maven.log.LogHandler;
import org.asciidoctor.maven.model.Resource;
import org.assertj.core.api.Assertions;
Expand All @@ -18,6 +17,7 @@
import java.util.stream.Collectors;

import static java.util.Collections.singletonList;
import static org.asciidoctor.maven.process.SourceDocumentFinder.STANDARD_FILE_EXTENSIONS_PATTERN;
import static org.codehaus.plexus.util.ReflectionUtils.setVariableValueInObject;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -177,11 +177,8 @@ public static void assertEqualsStructure(File[] expected, File[] actual) {

File[] htmls = actualFile.listFiles(f -> f.getName().endsWith("html"));
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("_") && !f.getName().startsWith(".");
});
Assertions.assertThat(htmls).hasSize(asciidocs.length);
File[] asciiDocs = expectedFile.listFiles(f -> f.getName().matches(STANDARD_FILE_EXTENSIONS_PATTERN));
Assertions.assertThat(htmls).hasSize(asciiDocs.length);
}
File[] actualChildren = actualFile.listFiles(File::isDirectory);
assertEqualsStructure(expectedChildren, actualChildren);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import java.util.List;
import java.util.UUID;

import static org.asciidoctor.maven.io.AsciidoctorFileScanner.IGNORED_FILE_NAMES;
import static org.asciidoctor.maven.io.TestFilesHelper.createFileWithContent;
import static org.asciidoctor.maven.process.CopyResourcesProcessor.IGNORED_FILE_NAMES;
import static org.assertj.core.api.Assertions.assertThat;

public class CopyResourcesProcessorTest {
Expand Down

0 comments on commit b6c6db6

Please sign in to comment.