Files
SCM-Manager/build-plugins/src/main/groovy/com/cloudogu/scm/TouchFilesTask.groovy
Sebastian Sdorra 4e1bf1d13b Update timestamps of test report if running on ci
We have to update the timestamps of our test reports on the ci server,
because Jenkins fails it the reports are older than x minutes.
2021-01-14 12:01:34 +01:00

47 lines
841 B
Groovy

package com.cloudogu.scm
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.TaskAction
import java.time.Instant
class TouchFilesTask extends DefaultTask {
@InputDirectory
File directory
@Input
String extension
@Input
long timestamp
TouchFilesTask() {
timestamp = Instant.now().toEpochMilli()
// this task should run always
outputs.upToDateWhen {
false
}
}
@TaskAction
public void execute() {
if (directory.exists()) {
touch(directory)
}
}
private void touch(File file) {
if (file.isDirectory()) {
for (File child : file.listFiles()) {
touch(child)
}
} else if (file.getName().endsWith(".${extension}")) {
file.setLastModified(timestamp)
}
}
}