@@ -71,12 +71,7 @@ public void build(String outputFile) throws IOException {
7171 }
7272
7373 private void buildIntroductionAndConfiguration () throws IOException {
74- JSONObject data = null ;
75- try {
76- data = client .fetchDataFromURL ("/api/navigation/component?component=" , project );
77- } catch (IOException | InterruptedException e ) {
78- System .err .println ("Error at doing the HTTP petition: " + e .getMessage ());
79- }
74+ JSONObject data = client .fetchDataFromURL ("/api/navigation/component?component=" , project );
8075
8176 String name = data .getString ("name" );
8277
@@ -111,13 +106,8 @@ private void buildSynthesisSection() throws IOException {
111106 pdf .tittle3Font ();
112107 pdf .addLine ("ANALYSIS STATUS" );
113108
114- JSONObject data = null ;
115- try {
116- data = client .fetchDataFromURL ("/api/measures/component?metricKeys=reliability_rating,software_quality_maintainability_rating,security_rating,security_review_rating&component=" , project );
117- data = data .getJSONObject ("component" );
118- } catch (IOException | InterruptedException e ) {
119- System .err .println ("Error at doing the HTTP petition: " + e .getMessage ());
120- }
109+ JSONObject data = client .fetchDataFromURL ("/api/measures/component?metricKeys=reliability_rating,software_quality_maintainability_rating,security_rating,security_review_rating&component=" , project );
110+ data = data .getJSONObject ("component" );
121111
122112 String [] headers = {"Reliability" , "Security" , "Security Review" , "Maintainability" };
123113 List <String []> rows = new ArrayList <>();
@@ -133,12 +123,8 @@ private void buildSynthesisSection() throws IOException {
133123 pdf .tittle3Font ();
134124 pdf .addLine ("QUALITY GATE STATUS" );
135125
136- try {
137- data = client .fetchDataFromURL ("/api/qualitygates/project_status?projectKey=" , project );
138- data = data .getJSONObject ("projectStatus" );
139- } catch (IOException | InterruptedException e ) {
140- System .err .println ("Error at doing the HTTP petition: " + e .getMessage ());
141- }
126+ data = client .fetchDataFromURL ("/api/qualitygates/project_status?projectKey=" , project );
127+ data = data .getJSONObject ("projectStatus" );
142128
143129 pdf .bodyFont ();
144130 pdf .addLine ("| Quality Gate Status | " + data .getString ("status" ) + " |" );
@@ -147,12 +133,8 @@ private void buildSynthesisSection() throws IOException {
147133 pdf .tittle3Font ();
148134 pdf .addLine ("METRICS" );
149135
150- try {
151- data = client .fetchDataFromURL ("/api/measures/component?metricKeys=duplicated_lines_density,comment_lines_density,ncloc,complexity,cognitive_complexity,coverage&component=" , project );
152- data = data .getJSONObject ("component" );
153- } catch (IOException | InterruptedException e ) {
154- System .err .println ("Error at doing the HTTP petition: " + e .getMessage ());
155- }
136+ data = client .fetchDataFromURL ("/api/measures/component?metricKeys=duplicated_lines_density,comment_lines_density,ncloc,complexity,cognitive_complexity,coverage&component=" , project );
137+ data = data .getJSONObject ("component" );
156138
157139 headers = new String []{"Coverage" , "Duplications" , "Comment Density" , "Lines of Code" , "Cyclomatic Complexity" , "Cognitive Complexity" };
158140 rows = new ArrayList <>();
@@ -187,12 +169,8 @@ private void buildSynthesisSection() throws IOException {
187169 pdf .tittle3Font ();
188170 pdf .addLine ("TESTS" );
189171
190- try {
191- data = client .fetchDataFromURL ("/api/measures/component?metricKeys=tests,test_success_density,skipped_tests,test_errors,test_failures&component=" , project );
192- data = data .getJSONObject ("component" );
193- } catch (IOException | InterruptedException e ) {
194- System .err .println ("Error at doing the HTTP petition: " + e .getMessage ());
195- }
172+ data = client .fetchDataFromURL ("/api/measures/component?metricKeys=tests,test_success_density,skipped_tests,test_errors,test_failures&component=" , project );
173+ data = data .getJSONObject ("component" );
196174
197175 headers = new String []{"Total" , "Success Rate" , "Skipped" , "Errors" , "Failures" };
198176 rows = new ArrayList <>();
@@ -226,12 +204,8 @@ private void buildSynthesisSection() throws IOException {
226204 pdf .tittle3Font ();
227205 pdf .addLine ("DETAILED TECHNICAL DEBTS" );
228206
229- try {
230- data = client .fetchDataFromURL ("/api/measures/component?metricKeys=reliability_remediation_effort,security_remediation_effort,sqale_index&component=" , project );
231- data = data .getJSONObject ("component" );
232- } catch (IOException | InterruptedException e ) {
233- System .err .println ("Error at doing the HTTP petition: " + e .getMessage ());
234- }
207+ data = client .fetchDataFromURL ("/api/measures/component?metricKeys=reliability_remediation_effort,security_remediation_effort,sqale_index&component=" , project );
208+ data = data .getJSONObject ("component" );
235209
236210 headers = new String []{"Reliability" , "Security" , "Maintainability" , "Total" };
237211 rows = new ArrayList <>();
@@ -266,12 +240,8 @@ private void buildSynthesisSection() throws IOException {
266240 pdf .tittle3Font ();
267241 pdf .addLine ("LINES PER LANGUAGE" );
268242
269- try {
270- data = client .fetchDataFromURL ("/api/measures/component?metricKeys=ncloc_language_distribution&component=" , project );
271- data = data .getJSONObject ("component" );
272- } catch (IOException | InterruptedException e ) {
273- System .err .println ("Error at doing the HTTP petition: " + e .getMessage ());
274- }
243+ data = client .fetchDataFromURL ("/api/measures/component?metricKeys=ncloc_language_distribution&component=" , project );
244+ data = data .getJSONObject ("component" );
275245
276246 headers = new String []{"Language" , "Number of Lines" , "Total Percent" };
277247 rows = new ArrayList <>();
@@ -295,14 +265,8 @@ private void buildSecurityHotspotsSection() throws IOException {
295265 pdf .tittle3Font ();
296266 pdf .addLine ("SECURITY HOTSPOTS COUNT BY CATEGORY AND PRIORITY" );
297267
298- JSONObject data = null ;
299- JSONArray dataArray = null ;
300- try {
301- data = client .fetchDataFromURL ("/api/security_reports/show?standard=sonarsourceSecurity&project=" , project );
302- dataArray = data .getJSONArray ("categories" );
303- } catch (IOException | InterruptedException e ) {
304- System .err .println ("Error at doing the HTTP petition: " + e .getMessage ());
305- }
268+ JSONObject data = client .fetchDataFromURL ("/api/security_reports/show?standard=sonarsourceSecurity&project=" , project );
269+ JSONArray dataArray = data .getJSONArray ("categories" );
306270
307271 String [] headers = {"Categories" , "Security" , "Security Hotspots" };
308272 List <String []> rows = new ArrayList <>();
@@ -326,26 +290,22 @@ private void buildSecurityHotspotsSection() throws IOException {
326290 pdf .tittle3Font ();
327291 pdf .addLine ("SECURITY HOTSPOT LIST" );
328292
329- try {
330- int pageIndex = 1 ;
331- int total = Integer .MAX_VALUE ;
332- dataArray = new JSONArray ();
333- while ((pageIndex - 1 ) * 500 < total ) {
334- data = client .fetchDataFromURL (
335- String .format ("/api/hotspots/search?status=TO_REVIEW&ps=500&pageIndex=%d&project=" , pageIndex ),
336- project
337- );
338- JSONArray currentPage = data .getJSONArray ("hotspots" );
339- for (int i = 0 ; i < currentPage .length (); i ++) {
340- dataArray .put (currentPage .getJSONObject (i ));
341- }
342- if (data .has ("paging" )) {
343- total = data .getJSONObject ("paging" ).getInt ("total" );
344- }
345- pageIndex ++;
293+ int pageIndex = 1 ;
294+ int total = Integer .MAX_VALUE ;
295+ dataArray = new JSONArray ();
296+ while ((pageIndex - 1 ) * 500 < total ) {
297+ data = client .fetchDataFromURL (
298+ String .format ("/api/hotspots/search?status=TO_REVIEW&ps=500&pageIndex=%d&project=" , pageIndex ),
299+ project
300+ );
301+ JSONArray currentPage = data .getJSONArray ("hotspots" );
302+ for (int i = 0 ; i < currentPage .length (); i ++) {
303+ dataArray .put (currentPage .getJSONObject (i ));
346304 }
347- } catch (IOException | InterruptedException e ) {
348- System .err .println ("Error at doing the HTTP petition: " + e .getMessage ());
305+ if (data .has ("paging" )) {
306+ total = data .getJSONObject ("paging" ).getInt ("total" );
307+ }
308+ pageIndex ++;
349309 }
350310
351311 JSONArray hotspotArray = new JSONArray (groupHotspotsByRule (dataArray ).values ());
@@ -372,12 +332,7 @@ private void buildIssuesSection() throws IOException {
372332
373333 String [][] typeLabels = {{"BUG" , "Bug" }, {"VULNERABILITY" , "Vulnerability" }, {"CODE_SMELL" , "Code Smell" }};
374334 for (String [] typeLabel : typeLabels ) {
375- JSONObject data = null ;
376- try {
377- data = client .fetchDataFromURL ("/api/issues/search?types=" + typeLabel [0 ] + "&facets=severities&componentKeys=" , project );
378- } catch (IOException | InterruptedException e ) {
379- System .err .println ("Error at doing the HTTP petition: " + e .getMessage ());
380- }
335+ JSONObject data = client .fetchDataFromURL ("/api/issues/search?types=" + typeLabel [0 ] + "&facets=severities&componentKeys=" , project );
381336 JSONArray facetValues = data .getJSONArray ("facets" ).getJSONObject (0 ).getJSONArray ("values" );
382337 rows .add (new String []{
383338 typeLabel [1 ],
@@ -395,25 +350,21 @@ private void buildIssuesSection() throws IOException {
395350 pdf .addLine ("ISSUES LIST" );
396351
397352 JSONArray dataArray = new JSONArray ();
398- try {
399- int pageIndex = 1 ;
400- int total = Integer .MAX_VALUE ;
401- while ((pageIndex - 1 ) * 500 < total ) {
402- JSONObject data = client .fetchDataFromURL (
403- String .format ("/api/issues/search?issueStatuses=OPEN&ps=500&pageIndex=%d&componentKeys=" , pageIndex ),
404- project
405- );
406- JSONArray currentPage = data .getJSONArray ("issues" );
407- for (int i = 0 ; i < currentPage .length (); i ++) {
408- dataArray .put (currentPage .getJSONObject (i ));
409- }
410- if (data .has ("paging" )) {
411- total = data .getJSONObject ("paging" ).getInt ("total" );
412- }
413- pageIndex ++;
353+ int pageIndex = 1 ;
354+ int total = Integer .MAX_VALUE ;
355+ while ((pageIndex - 1 ) * 500 < total ) {
356+ JSONObject data = client .fetchDataFromURL (
357+ String .format ("/api/issues/search?issueStatuses=OPEN&ps=500&pageIndex=%d&componentKeys=" , pageIndex ),
358+ project
359+ );
360+ JSONArray currentPage = data .getJSONArray ("issues" );
361+ for (int i = 0 ; i < currentPage .length (); i ++) {
362+ dataArray .put (currentPage .getJSONObject (i ));
363+ }
364+ if (data .has ("paging" )) {
365+ total = data .getJSONObject ("paging" ).getInt ("total" );
414366 }
415- } catch (IOException | InterruptedException e ) {
416- System .err .println ("Error at doing the HTTP petition: " + e .getMessage ());
367+ pageIndex ++;
417368 }
418369
419370 JSONArray issuesArray = new JSONArray (groupIssuesByRule (dataArray ).values ());
0 commit comments