forked from henkelmax/mod-gradle-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtaskutils.gradle
More file actions
73 lines (67 loc) · 2.25 KB
/
taskutils.gradle
File metadata and controls
73 lines (67 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def runCommand(String commandName, boolean ignoreExitCode, String... commands) {
def osName = System.getProperty("os.name")
if (!osName.toLowerCase().contains("windows")) {
throw new RuntimeException('This task only works on Windows')
}
def args = []
args.add('cmd')
args.add('/c')
args.addAll(commands)
printGreen("Executing '{}'", commandName)
def result = exec {
commandLine args
ignoreExitValue ignoreExitCode
}
if (result.exitValue == 0) {
printGreen("Successfully executed '{}'", commandName)
} else if (ignoreExitCode) {
logger.error("Task '{}' failed with exit code {} - Ignoring", commandName, result.exitValue)
}
return result
}
def runGradleTasks(List<String> mandatoryTasks, List<String> optionalTasks) {
def errored = false
def results = []
for (String task : mandatoryTasks) {
if (errored) {
results.add([task, null])
continue
}
def result = runGradleTask(task, true)
if (result.exitValue != 0) {
errored = true
}
results.add([task, result])
}
for (String task : optionalTasks) {
if (errored) {
results.add([task, null])
continue
}
def result = runGradleTask(task, true)
results.add([task, result])
}
logger.lifecycle('')
printGreen('Execution results:')
results.forEach {
def result = it[1]
printGreen('{} -> {}', it[0], result == null ? 'SKIPPED' : (result.exitValue == 0 ? 'SUCCESS' : 'FAILURE'))
}
}
def runGradleTask(String taskName, boolean ignoreExitCode) {
return runCommand(taskName, ignoreExitCode, 'gradlew', taskName)
}
def printGreen(String template, Object... args) {
def green = '\u001B[32m'
def reset = '\u001B[0m'
logger.lifecycle("${green}${template}${reset}", args)
}
ext.runGradleTasks = { List<String> mandatoryTasks, List<String> optionalTasks ->
runGradleTasks(mandatoryTasks, optionalTasks)
}
ext.runGradleTask = { String taskName, boolean ignoreExitCode ->
runGradleTask(taskName, ignoreExitCode)
}
ext.runCommand = { String commandName, boolean ignoreExitCode, String... commands ->
runCommand(commandName, ignoreExitCode, commands)
}