-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avoids docInfo files from being copied in refresh mojo
- Loading branch information
1 parent
460e1b9
commit 9605dc0
Showing
9 changed files
with
281 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/org/asciidoctor/maven/refresh/ResourcesPatternBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
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.apache.commons.lang3.StringUtils.isBlank; | ||
import static org.asciidoctor.maven.io.AsciidoctorFileScanner.ASCIIDOC_FILE_EXTENSIONS_REG_EXP; | ||
|
||
/** | ||
* Builds regular expression to include all valid resources to be copied for `auto-refresh` mojo. | ||
* | ||
* @author abelsromero | ||
*/ | ||
public class ResourcesPatternBuilder { | ||
|
||
private final String sourceDocumentName; | ||
private final List<String> sourceDocumentExtensions; | ||
|
||
public ResourcesPatternBuilder(final String sourceDocumentName, final List<String> sourceDocumentExtensions) { | ||
this.sourceDocumentName = sourceDocumentName; | ||
this.sourceDocumentExtensions = sourceDocumentExtensions; | ||
} | ||
|
||
public String build() { | ||
final StringJoiner filePattern = new StringJoiner("|") | ||
.add(ASCIIDOC_FILE_EXTENSIONS_REG_EXP); | ||
if (!sourceDocumentExtensions.isEmpty()) | ||
filePattern.add(String.join("|", sourceDocumentExtensions)); | ||
|
||
final String specialFiles = Arrays.stream(AsciidoctorFileScanner.IGNORED_FILE_NAMES) | ||
.map(pattern -> pattern.replaceAll("\\*", ".*")) | ||
.map(pattern -> pattern.replaceAll("\\.", "\\\\.")) | ||
.collect(Collectors.joining("|")); | ||
|
||
return new StringBuilder() | ||
.append("^") | ||
.append("(?!(" + specialFiles + (isBlank(sourceDocumentName) ? "" : "|" + sourceDocumentName) + "))") | ||
.append("[^_.].*\\.(?!(") | ||
.append(filePattern.toString()) | ||
.append(")).*$") | ||
.toString(); | ||
} | ||
|
||
} |
Oops, something went wrong.