Updating checkstyle plugin to show module name on failure
Change-Id: I8c3e015e1332f27315b47f60d84c151ad2e77faf
Showing
2 changed files
with
25 additions
and
11 deletions
... | @@ -111,7 +111,7 @@ def osgi_jar( | ... | @@ -111,7 +111,7 @@ def osgi_jar( |
111 | ### Checkstyle | 111 | ### Checkstyle |
112 | if srcs: | 112 | if srcs: |
113 | base = get_base_path() | 113 | base = get_base_path() |
114 | - files = base + '\n' + '\n'.join(['%s/%s' % (base, s) for s in srcs]) | 114 | + files = '%s\n%s\n' % (name, base) + '\n'.join(['%s/%s' % (base, s) for s in srcs]) |
115 | 115 | ||
116 | genrule( | 116 | genrule( |
117 | name = name + '-checkstyle-files', | 117 | name = name + '-checkstyle-files', | ... | ... |
... | @@ -33,6 +33,8 @@ import java.util.concurrent.CountDownLatch; | ... | @@ -33,6 +33,8 @@ import java.util.concurrent.CountDownLatch; |
33 | import java.util.stream.Collectors; | 33 | import java.util.stream.Collectors; |
34 | import java.util.stream.Stream; | 34 | import java.util.stream.Stream; |
35 | 35 | ||
36 | +import static com.google.common.base.Strings.isNullOrEmpty; | ||
37 | + | ||
36 | public class CheckstyleRunner { | 38 | public class CheckstyleRunner { |
37 | 39 | ||
38 | private final Configuration config; | 40 | private final Configuration config; |
... | @@ -70,16 +72,18 @@ public class CheckstyleRunner { | ... | @@ -70,16 +72,18 @@ public class CheckstyleRunner { |
70 | } | 72 | } |
71 | 73 | ||
72 | public String checkClass(String input) throws CheckstyleException, InterruptedException { | 74 | public String checkClass(String input) throws CheckstyleException, InterruptedException { |
73 | - String[] split = input.split("\n", 2); | 75 | + String[] split = input.split("\n", 3); |
74 | - if (split.length < 2 || split[1].length() == 0) { | 76 | + if (split.length < 3 || split[2].length() == 0) { |
75 | return ""; | 77 | return ""; |
76 | } | 78 | } |
77 | - String base = split[0]; | 79 | + String project = split[0]; |
78 | - String files = split[1]; | 80 | + String baseDir = split[1]; |
81 | + String files = split[2]; | ||
79 | 82 | ||
80 | // create a listener for output | 83 | // create a listener for output |
81 | StringAuditor listener = new StringAuditor(); | 84 | StringAuditor listener = new StringAuditor(); |
82 | - listener.setBase(base); | 85 | + listener.setProjectName(project); |
86 | + listener.setBaseDir(baseDir); | ||
83 | 87 | ||
84 | // create Checker object and run it | 88 | // create Checker object and run it |
85 | final Checker checker = new Checker(); | 89 | final Checker checker = new Checker(); |
... | @@ -111,10 +115,15 @@ class StringAuditor implements AuditListener { | ... | @@ -111,10 +115,15 @@ class StringAuditor implements AuditListener { |
111 | 115 | ||
112 | private CountDownLatch finishedLatch = new CountDownLatch(1); | 116 | private CountDownLatch finishedLatch = new CountDownLatch(1); |
113 | private StringBuilder output = new StringBuilder(); | 117 | private StringBuilder output = new StringBuilder(); |
114 | - private String base = ""; | 118 | + private String baseDir = ""; |
119 | + private String project = ""; | ||
120 | + | ||
121 | + public void setBaseDir(String base) { | ||
122 | + this.baseDir = base; | ||
123 | + } | ||
115 | 124 | ||
116 | - public void setBase(String base) { | 125 | + public void setProjectName(String projectName) { |
117 | - this.base = base; | 126 | + this.project = projectName; |
118 | } | 127 | } |
119 | 128 | ||
120 | public void append(String s) { | 129 | public void append(String s) { |
... | @@ -151,9 +160,14 @@ class StringAuditor implements AuditListener { | ... | @@ -151,9 +160,14 @@ class StringAuditor implements AuditListener { |
151 | switch (evt.getSeverityLevel()) { | 160 | switch (evt.getSeverityLevel()) { |
152 | case ERROR: | 161 | case ERROR: |
153 | String fileName = evt.getFileName(); | 162 | String fileName = evt.getFileName(); |
154 | - int index = fileName.indexOf(base); | 163 | + if (!isNullOrEmpty(baseDir)) { |
164 | + int index = fileName.indexOf(baseDir); | ||
155 | if (index >= 0) { | 165 | if (index >= 0) { |
156 | - fileName = fileName.substring(index + base.length() + 1); | 166 | + fileName = fileName.substring(index + baseDir.length() + 1); |
167 | + if (!isNullOrEmpty(project)) { | ||
168 | + output.append(project).append(':'); | ||
169 | + } | ||
170 | + } | ||
157 | } | 171 | } |
158 | output.append(fileName).append(':').append(evt.getLine()); | 172 | output.append(fileName).append(':').append(evt.getLine()); |
159 | if (evt.getColumn() > 0) { | 173 | if (evt.getColumn() > 0) { | ... | ... |
-
Please register or login to post a comment