Issue
I want to duplicate all files from my srcDir
which contain $$ in their name. If a file is for example:
x$$y.java
I want to create a copy of that file and name it x$y.java
.
class MyTask extends DefaultTask {
@InputDirectory File srcDir
@TaskAction
def task() {
def srcFiles = project.files(project.fileTree(dir: srcDir)).getFiles()
srcFiles.each { file ->
if (file.name.contains("\$\$")) {
// TODO copy file and rename it to the same name with one dollar sign in the middle
}
}
}
}
How can I copy and rename a file inside a custom task class?
Solution
Try:
@TaskAction
def task() {
project.copy {
from(project.fileTree(dir: srcDir).files) {
include {
it.file.name.contains('$$')
}
}
into('somewhere')
rename { name ->
name.replace('$$', '$')
}
}
}
Answered By - Opal
Answer Checked By - Clifford M. (JavaFixing Volunteer)