ONOS-4572 Adding checkstyle for Java tests in Buck
Change-Id: I3099046ba9db4ff59a9c4d0aa6bd0a73edc367d2
Showing
1 changed file
with
42 additions
and
26 deletions
... | @@ -18,6 +18,39 @@ def _get_name(): | ... | @@ -18,6 +18,39 @@ def _get_name(): |
18 | base_path = get_base_path() | 18 | base_path = get_base_path() |
19 | return ONOS_ARTIFACT_BASE + base_path.replace('/', '-') #TODO Unix-separator | 19 | return ONOS_ARTIFACT_BASE + base_path.replace('/', '-') #TODO Unix-separator |
20 | 20 | ||
21 | +def checkstyle( | ||
22 | + name, | ||
23 | + srcs = None, | ||
24 | + jar_target = None, | ||
25 | + ): | ||
26 | + | ||
27 | + if srcs and jar_target: | ||
28 | + base = get_base_path() | ||
29 | + files = '%s\n%s\n' % (name, base) + '\n'.join(['%s/%s' % (base, s) for s in srcs]) | ||
30 | + | ||
31 | + genrule( | ||
32 | + name = name + '-checkstyle-files', | ||
33 | + bash = "echo '%s' > $OUT" % files, | ||
34 | + srcs = srcs, | ||
35 | + out = 'checkstyle-files.txt', | ||
36 | + ) | ||
37 | + | ||
38 | + sh_test( | ||
39 | + name = name + '-checkstyle', | ||
40 | + test = '//tools/build/conf:start-checkstyle', | ||
41 | + deps = [ jar_target ], | ||
42 | + args = [ | ||
43 | + '$(location //tools/build/conf:checkstyle-jar)', | ||
44 | + '$(location :' + name + '-checkstyle-files)', | ||
45 | + '$(location //tools/build/conf:checkstyle-xml)', | ||
46 | + '$(location //tools/build/conf:suppressions-xml)', | ||
47 | + ], | ||
48 | + test_rule_timeout_ms = 20000, | ||
49 | + labels = [ 'checkstyle' ], | ||
50 | + ) | ||
51 | + else: | ||
52 | + print 'Not generating checkstyle rule for %s because there are no sources.' % name | ||
53 | + | ||
21 | def osgi_jar( | 54 | def osgi_jar( |
22 | name = None, | 55 | name = None, |
23 | srcs = None, | 56 | srcs = None, |
... | @@ -109,34 +142,11 @@ def osgi_jar( | ... | @@ -109,34 +142,11 @@ def osgi_jar( |
109 | ) | 142 | ) |
110 | 143 | ||
111 | ### Checkstyle | 144 | ### Checkstyle |
112 | - if srcs: | 145 | + checkstyle( |
113 | - base = get_base_path() | ||
114 | - files = '%s\n%s\n' % (name, base) + '\n'.join(['%s/%s' % (base, s) for s in srcs]) | ||
115 | - | ||
116 | - genrule( | ||
117 | name = name + '-checkstyle-files', | 146 | name = name + '-checkstyle-files', |
118 | - bash = "echo '%s' > $OUT" % files, | ||
119 | srcs = srcs, | 147 | srcs = srcs, |
120 | - out = 'checkstyle-files.txt', | 148 | + jar_target = ':'+ bare_jar_name, |
121 | - ) | 149 | + ) |
122 | - | ||
123 | - sh_test( | ||
124 | - name = name + '-checkstyle', | ||
125 | - test = '//tools/build/conf:start-checkstyle', | ||
126 | - deps = [ | ||
127 | - ':'+ bare_jar_name, | ||
128 | - ], | ||
129 | - args = [ | ||
130 | - '$(location //tools/build/conf:checkstyle-jar)', | ||
131 | - '$(location :' + name + '-checkstyle-files)', | ||
132 | - '$(location //tools/build/conf:checkstyle-xml)', | ||
133 | - '$(location //tools/build/conf:suppressions-xml)', | ||
134 | - ], | ||
135 | - test_rule_timeout_ms = 20000, | ||
136 | - labels = [ 'checkstyle' ], | ||
137 | - ) | ||
138 | - else: | ||
139 | - print 'Not generating checkstyle rule for %s because there are no sources.' % name | ||
140 | 150 | ||
141 | # TODO add project config for intellij | 151 | # TODO add project config for intellij |
142 | # project_config( | 152 | # project_config( |
... | @@ -211,4 +221,10 @@ def osgi_jar_with_tests( | ... | @@ -211,4 +221,10 @@ def osgi_jar_with_tests( |
211 | visibility = visibility | 221 | visibility = visibility |
212 | ) | 222 | ) |
213 | 223 | ||
224 | + checkstyle( | ||
225 | + name = name + '-tests', | ||
226 | + srcs = test_srcs, | ||
227 | + jar_target = ':' + name + '-tests', | ||
228 | + ) | ||
229 | + | ||
214 | #FIXME need to run checkstyle on test sources | 230 | #FIXME need to run checkstyle on test sources | ... | ... |
-
Please register or login to post a comment