Updating checkstyle plugin to show module name on failure
Change-Id: I8c3e015e1332f27315b47f60d84c151ad2e77faf
diff --git a/bucklets/onos.bucklet b/bucklets/onos.bucklet
index 7a2f1a9..9905f70 100644
--- a/bucklets/onos.bucklet
+++ b/bucklets/onos.bucklet
@@ -111,7 +111,7 @@
### Checkstyle
if srcs:
base = get_base_path()
- files = base + '\n' + '\n'.join(['%s/%s' % (base, s) for s in srcs])
+ files = '%s\n%s\n' % (name, base) + '\n'.join(['%s/%s' % (base, s) for s in srcs])
genrule(
name = name + '-checkstyle-files',
diff --git a/tools/build/conf/src/main/java/org/onosproject/checkstyle/CheckstyleRunner.java b/tools/build/conf/src/main/java/org/onosproject/checkstyle/CheckstyleRunner.java
index 1768e16..e2a89b7 100644
--- a/tools/build/conf/src/main/java/org/onosproject/checkstyle/CheckstyleRunner.java
+++ b/tools/build/conf/src/main/java/org/onosproject/checkstyle/CheckstyleRunner.java
@@ -33,6 +33,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import static com.google.common.base.Strings.isNullOrEmpty;
+
public class CheckstyleRunner {
private final Configuration config;
@@ -70,16 +72,18 @@
}
public String checkClass(String input) throws CheckstyleException, InterruptedException {
- String[] split = input.split("\n", 2);
- if (split.length < 2 || split[1].length() == 0) {
+ String[] split = input.split("\n", 3);
+ if (split.length < 3 || split[2].length() == 0) {
return "";
}
- String base = split[0];
- String files = split[1];
+ String project = split[0];
+ String baseDir = split[1];
+ String files = split[2];
// create a listener for output
StringAuditor listener = new StringAuditor();
- listener.setBase(base);
+ listener.setProjectName(project);
+ listener.setBaseDir(baseDir);
// create Checker object and run it
final Checker checker = new Checker();
@@ -111,10 +115,15 @@
private CountDownLatch finishedLatch = new CountDownLatch(1);
private StringBuilder output = new StringBuilder();
- private String base = "";
+ private String baseDir = "";
+ private String project = "";
- public void setBase(String base) {
- this.base = base;
+ public void setBaseDir(String base) {
+ this.baseDir = base;
+ }
+
+ public void setProjectName(String projectName) {
+ this.project = projectName;
}
public void append(String s) {
@@ -151,9 +160,14 @@
switch (evt.getSeverityLevel()) {
case ERROR:
String fileName = evt.getFileName();
- int index = fileName.indexOf(base);
- if (index >= 0) {
- fileName = fileName.substring(index + base.length() + 1);
+ if (!isNullOrEmpty(baseDir)) {
+ int index = fileName.indexOf(baseDir);
+ if (index >= 0) {
+ fileName = fileName.substring(index + baseDir.length() + 1);
+ if (!isNullOrEmpty(project)) {
+ output.append(project).append(':');
+ }
+ }
}
output.append(fileName).append(':').append(evt.getLine());
if (evt.getColumn() > 0) {