1616
1717public class ClippyJsonReportReader {
1818 private final JSONParser jsonParser = new JSONParser ();
19- private final Consumer <Issue > consumer ;
19+ private final Consumer <ClippyIssue > consumer ;
2020 private static final Logger LOG = Loggers .get (ClippyJsonReportReader .class );
2121
22- public static class Issue {
22+ public static class ClippyIssue {
2323 @ Nullable
2424 String filePath ;
2525 @ Nullable
@@ -38,11 +38,11 @@ public static class Issue {
3838 String severity ;
3939 }
4040
41- private ClippyJsonReportReader (Consumer <Issue > consumer ) {
41+ private ClippyJsonReportReader (Consumer <ClippyIssue > consumer ) {
4242 this .consumer = consumer ;
4343 }
4444
45- static void read (InputStream in , Consumer <Issue > consumer ) throws IOException , ParseException {
45+ static void read (InputStream in , Consumer <ClippyIssue > consumer ) throws IOException , ParseException {
4646 new ClippyJsonReportReader (consumer ).read (in );
4747 }
4848
@@ -55,33 +55,33 @@ private void read(InputStream in) throws IOException, ParseException {
5555 }
5656
5757 private void onResult (JSONObject result ) {
58- Issue issue = new Issue ();
58+ ClippyIssue clippyIssue = new ClippyIssue ();
5959
6060 JSONObject message = (JSONObject ) result .get ("message" );
6161 if (message == null ) return ;
6262 JSONObject code = (JSONObject ) message .get ("code" );
6363 if (code == null ) return ;
64- issue .ruleKey = (String ) code .get ("code" );
64+ clippyIssue .ruleKey = (String ) code .get ("code" );
6565
66- LOG .debug ("Clippy rule found : " + issue .ruleKey );
66+ LOG .debug ("Clippy rule found : " + clippyIssue .ruleKey );
6767
6868
6969 JSONArray spans = (JSONArray ) message .get ("spans" );
70- if ((spans == null )|| spans .size ()== 0 ) return ;
70+ if ((spans == null ) || spans .size () == 0 ) return ;
7171 JSONObject span = (JSONObject ) spans .get (0 );
72- issue .filePath = (String ) span .get ("file_name" );
72+ clippyIssue .filePath = (String ) span .get ("file_name" );
7373
7474
75- issue .message = (String ) message .get ("message" );
75+ clippyIssue .message = (String ) message .get ("message" );
7676
77- issue .lineNumberStart = toInteger (span .get ("line_start" )) ;
78- issue .lineNumberEnd = toInteger (span .get ("line_end" ));
79- issue .colNumberStart = toInteger (span .get ("column_start" ));
80- issue .colNumberEnd = toInteger (span .get ("column_end" )) ;
77+ clippyIssue .lineNumberStart = toInteger (span .get ("line_start" ));
78+ clippyIssue .lineNumberEnd = toInteger (span .get ("line_end" ));
79+ clippyIssue .colNumberStart = toInteger (span .get ("column_start" ));
80+ clippyIssue .colNumberEnd = toInteger (span .get ("column_end" ));
8181
82- issue .severity = (String ) message .get ("level" );
82+ clippyIssue .severity = (String ) message .get ("level" );
8383
84- consumer .accept (issue );
84+ consumer .accept (clippyIssue );
8585 }
8686
8787 private static Integer toInteger (Object value ) {
@@ -91,15 +91,15 @@ private static Integer toInteger(Object value) {
9191 return null ;
9292 }
9393
94- public static InputStream toJSON (File rawReport ) throws IOException {
95- String BEGIN = "{\" results\" : [" ;
96- String END = "]}" ;
94+ public static InputStream toJSON (File rawReport ) throws IOException {
95+ String BEGIN = "{\" results\" : [" ;
96+ String END = "]}" ;
9797
9898 if (rawReport == null ) {
9999 throw new FileNotFoundException ();
100100 }
101101
102- StringBuffer sb = new StringBuffer (BEGIN );
102+ StringBuffer sb = new StringBuffer (BEGIN );
103103
104104 //read text report line by line
105105 String reportPath = rawReport .getAbsolutePath ();
@@ -108,22 +108,17 @@ public static InputStream toJSON(File rawReport) throws IOException{
108108 reader = new BufferedReader (new FileReader (
109109 reportPath ));
110110 String line = reader .readLine ();
111- String separator = "" ;
111+ String separator = "" ;
112112 while (line != null ) {
113-
114- // read next line
115-
116113 //a valid Clippy result needs to be a valid json String
117- if (line .startsWith ("{" ) && line .endsWith ("}" )){
114+ if (line .startsWith ("{" ) && line .endsWith ("}" )) {
118115 sb .append (separator ).append (line );
119- separator = "," ;
116+ separator = "," ;
120117 }
121118 line = reader .readLine ();
122119 }
123120 reader .close ();
124-
125- sb .append (END );
126-
121+ sb .append (END );
127122 InputStream in = new ByteArrayInputStream (sb .toString ().getBytes ());
128123 return in ;
129124 }
0 commit comments