Skip to content

Commit

Permalink
fix (CollectIncludes): ignore certain directories (#1086)
Browse files Browse the repository at this point in the history
* exclude directories from file traversal
* update changelog.adoc
* remove bracket from code line in web
  • Loading branch information
PacoVK committed Mar 16, 2023
1 parent c34f2da commit 8061694
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Config.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ collectIncludes.with {
// separatorChar = "_" // define the allowed separators after prefix. default: "-_"

// cleanOutputFolder = true // should the output folder be emptied before generation? default: false

// excludeDirectories = [] // define additional directories that should not be traversed.
}
//end::collectIncludesConfig[]

Expand Down
1 change: 1 addition & 0 deletions changelog.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project tries to adhere to https://semver.org/spec/v2.0.0.html[Semantic
* add environment variable `DTC_CONFIG_FILE` in `dtcw` and `dtcw.ps1` to specify a configuration file other than than `docToolchainConfig.groovy` in the project root folder.
* `collectIncludes`
** changed regexp to start with `^[A-Za-z]` as file name to allow lowercase filenames as well.
** certain directories are excluded from traversal. Define `excludeDirectories` in order to skip additional directories.

== 2.2.1 - 2023-03-05

Expand Down
15 changes: 13 additions & 2 deletions scripts/collectIncludes.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//tag::collectIncludes[]
import static groovy.io.FileType.*
import static groovy.io.FileVisitResult.*
import java.security.MessageDigest

task collectIncludes(
Expand All @@ -17,7 +18,10 @@ task collectIncludes(
}
doLast {
//let's search the whole project for files, not only the docs folder
//could be a problem with node projects :-)
//exclude typical system folders
final defaultExcludedDirectories = [
'.svn', '.git', '.idea', 'node_modules', '.gradle', 'build', '.github'
]

//running as subproject? set scandir to main project
String scanDir_save = scanDir
Expand Down Expand Up @@ -51,14 +55,21 @@ task collectIncludes(
String minPrefixLength = config.collectIncludes.minPrefixLength?:"3"
String maxPrefixLength = config.collectIncludes.maxPrefixLength?:""
String separatorChar = config.collectIncludes.separatorChar?:"-_"
def extraExcludeDirectories = config.collectIncludes.excludeDirectories?:[]

def excludedDirectories = defaultExcludedDirectories + extraExcludeDirectories

String prefixRegEx = "[A-Za-z]{" + minPrefixLength + "," + maxPrefixLength + "}"
String separatorCharRegEx = "[" + separatorChar + "]"
String fileFilterRegEx = "^" + prefixRegEx + separatorCharRegEx + ".*[.](" + fileFilter + ")\$"

logger.info "considering files with this pattern: " + fileFilterRegEx

sourceFolder.traverse(type: FILES) { file ->
sourceFolder.traverse(
type: FILES,
preDir : { if (it.name in excludedDirectories) return SKIP_SUBTREE },
excludeNameFilter: excludedDirectories
) { file ->
if (file.name ==~ fileFilterRegEx) {
String typeRegEx = "^(" + prefixRegEx + ")" + separatorCharRegEx + ".*\$"
def type = file.name.replaceAll(typeRegEx,'\$1').toUpperCase()
Expand Down
3 changes: 3 additions & 0 deletions template_config/Config.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,9 @@ collectIncludes.with {
separatorChar = "_" // define the allowed separators after prefix. default: "-_"

cleanOutputFolder = true // should the output folder be emptied before generation? default: false

excludeDirectories = [] // define additional directories that should not be traversed.

}
//end::collectIncludesConfig[]

Expand Down

0 comments on commit 8061694

Please sign in to comment.