-
Notifications
You must be signed in to change notification settings - Fork 9
/
groovylint.groovy
103 lines (93 loc) · 3.46 KB
/
groovylint.groovy
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* Copyright (c) 2019 Ableton AG, Berlin. All rights reserved.
*
* Use of this source code is governed by a MIT-style
* license that can be found in the LICENSE file.
*/
/**
* Check a set of files with the {@code groovylint} Docker image.
* @param args Map of arguments, which may include:
* <ul>
* <li>
* {@code includesPattern}: A comma-separated list of Ant-style file patterns
* to check. <strong>(required)</strong>.
* </li>
* <li>
* {@code extraArgs}: Extra arguments to pass to CodeNarc. Callers will have to
* escape these arguments if necessary.
* </li>
* <li>
* {@code groovylintImage}: If specified, use this Docker image handle to run
* {@code groovylint}. If {@code null}, then this function will try to fetch
* {@code groovylint} from Docker hub using the same version number
* corresponding to this library.
* </li>
* </ul>
*/
void check(Map args = [:]) {
assert args.includesPattern
String includesPattern = args.includesPattern
String extraArgs = args.extraArgs ?: ''
Object image = args.groovylintImage
if (!image) {
String version = env['library.groovylint.version']
if (!version) {
error 'Could not find groovylint version in environment'
}
image = docker.image("abletonag/groovylint:${version}")
image.pull()
}
echo "Using groovylint Docker image: ${image.id}"
image.inside {
sh "python3 /opt/run_codenarc.py -- -includes=${includesPattern} ${extraArgs}"
}
}
/**
* Check a set of files with the {@code groovylint} Docker image.
* @param includesPattern A comma-separated list of Ant-style file patterns to check.
* @param groovylintImage If specified, use this Docker image handle to run
* {@code groovylint}. If {@code null}, then this function will try to fetch
* {@code groovylint} from Docker hub using the same version number corresponding
* to this library. (default: {@code null})
* @param extraArgs Extra arguments to pass to CodeNarc. Callers will have to escape these
* arguments if necessary.
* @deprecated Use check(Map) instead.
*/
void check(String includesPattern, Object groovylintImage = null, String extraArgs = '') {
check(
extraArgs: extraArgs,
includesPattern: includesPattern,
groovylintImage: groovylintImage,
)
}
/**
* Check a single file with the {@code groovylint} Docker image.
* @param args Map of arguments, which may include:
* <ul>
* <li>
* {@code path}: Path to the single file to lint <strong>(required)</strong>.
* </li>
* <li>
* {@code groovylintImage}: If specified, use this Docker image handle to run
* {@code groovylint}. If {@code null}, then this function will try to fetch
* {@code groovylint} from Docker hub using the same version number
* corresponding to this library.
* </li>
* </ul>
*/
void checkSingleFile(Map args = [:]) {
assert args.path
Object image = args.groovylintImage
if (!image) {
String version = env['library.groovylint.version']
if (!version) {
error 'Could not find groovylint version in environment'
}
image = docker.image("abletonag/groovylint:${version}")
image.pull()
}
echo "Using groovylint Docker image: ${image.id}"
image.inside {
sh "python3 /opt/run_codenarc.py --single-file ${args.path}"
}
}