Skip to content

Commit

Permalink
Fix optional files in bare archetypes. (#1250)
Browse files Browse the repository at this point in the history
- Expand the name of the removed optional files so that tokenized template file names are properly removed
 - Delete empty directories
 - Inline all the closures (to make it prettier !)
  • Loading branch information
romain-grecourt authored Jan 23, 2020
1 parent 7b8c716 commit 0d0f38c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,27 @@ def optionalFiles = [
]

// remove optional files that should not be included
def processOptionalFiles(prop, fnames) {
optionalFiles.each{ prop, fnames ->
if (request.getProperties().get(prop).matches("n|no|false")) {
fnames.each{ fname -> new File(fname).delete() }
fnames.each{ fname ->
request.getProperties().each { entry ->
fname = fname.replaceAll("__${entry.key}__","${entry.value}")
}
new File(fname).delete()
}
}
}
optionalFiles.each{ key, value -> processOptionalFiles(key, value) }

// rename .vm files
def renameVmFile(file) {
rootDir.traverse(type: groovy.io.FileType.FILES, maxDepth: -1) { file ->
if (file.path.endsWith(".vm")) {
file.renameTo file.path.substring(0, file.path.length() - 3)
}
}
rootDir.traverse(type: groovy.io.FileType.FILES, maxDepth: -1) { file -> renameVmFile(file) }

// delete empty dirs
rootDir.traverse(type: groovy.io.FileType.DIRECTORIES, maxDepth: -1, postDir: { dir ->
if (dir.list().length == 0) {
dir.delete()
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,27 @@ def optionalFiles = [
]

// remove optional files that should not be included
def processOptionalFiles(prop, fnames) {
optionalFiles.each{ prop, fnames ->
if (request.getProperties().get(prop).matches("n|no|false")) {
fnames.each{ fname -> new File(fname).delete() }
fnames.each{ fname ->
request.getProperties().each { entry ->
fname = fname.replaceAll("__${entry.key}__","${entry.value}")
}
new File(fname).delete()
}
}
}
optionalFiles.each{ key, value -> processOptionalFiles(key, value) }

// rename .vm files
def renameVmFile(file) {
rootDir.traverse(type: groovy.io.FileType.FILES, maxDepth: -1) { file ->
if (file.path.endsWith(".vm")) {
file.renameTo file.path.substring(0, file.path.length() - 3)
}
}
rootDir.traverse(type: groovy.io.FileType.FILES, maxDepth: -1) { file -> renameVmFile(file) }

// delete empty dirs
rootDir.traverse(type: groovy.io.FileType.DIRECTORIES, maxDepth: -1, postDir: { dir ->
if (dir.list().length == 0) {
dir.delete()
}
})

0 comments on commit 0d0f38c

Please sign in to comment.