@@ -72,19 +72,19 @@ public void execute(SensorContext context) {
7272 final String [] args = new String [] { externalTool , "-source" , sourceDir , "-out" ,
7373 tempResultsFile .getAbsolutePath (), "/include:all" };
7474
75- final Process process = new ProcessBuilder (args ).start ();
75+ final Process process = new ProcessBuilder (args ).inheritIO (). start ();
7676 LOGGER .debug ("Running SQLCodeGuard with {}" , Arrays .toString (args ));
7777
7878 final int result = process .waitFor ();
79- if (result != 0 || !tempResultsFile .exists () || tempResultsFile .length () == 0 ) {
80- LOGGER .warn ("Was not able to run SQLCodeGuard with {}" , Arrays .toString (args ));
79+ if (!tempResultsFile .exists () || tempResultsFile .length () == 0 ) {
80+ LOGGER .warn ("SQLCodeGuard returned with '{}'. Arguments were: {}" , result , Arrays .toString (args ));
8181 return ;
8282 }
83- try (BOMInputStream stream = new BOMInputStream (new FileInputStream (tempResultsFile ))) {
83+ try (final BOMInputStream stream = new BOMInputStream (new FileInputStream (tempResultsFile ))) {
8484
8585 final CodeGuardIssues issues = read (stream );
8686
87- for (org .sonar .plugins .sql .models .cgissues .CodeGuardIssues .File f : issues .getFile ()) {
87+ for (final org .sonar .plugins .sql .models .cgissues .CodeGuardIssues .File f : issues .getFile ()) {
8888
8989 final List <InputFile > files = find (context , f .getFullname ());
9090 if (files .isEmpty ()) {
@@ -94,10 +94,10 @@ public void execute(SensorContext context) {
9494 final InputFile file = files .get (0 );
9595 for (final Issue is : f .getIssue ()) {
9696 try {
97- NewExternalIssue newExternalIssue = context .newExternalIssue ().ruleId (is .getCode ())
97+ final NewExternalIssue newExternalIssue = context .newExternalIssue ().ruleId (is .getCode ())
9898 .engineId (repositoryName ).type (RuleType .CODE_SMELL );
99- NewIssueLocation location = newExternalIssue .newLocation ().on (file ). message ( is . getText () )
100- .at (file .selectLine (is .getLine ()));
99+ final NewIssueLocation location = newExternalIssue .newLocation ().on (file )
100+ .message ( is . getText ()). at (file .selectLine (is .getLine ()));
101101 newExternalIssue .at (location ).severity (extractSeverity (is .getSeverity ())).save ();
102102 } catch (Throwable e ) {
103103 LOGGER .warn ("Unexpected error adding issue on file " + f .getFullname (), e );
@@ -113,16 +113,24 @@ public void execute(SensorContext context) {
113113
114114 }
115115
116- private final Severity extractSeverity (String severity ) {
117- String val = "MAJOR" ;
118-
119- if (severity != null ) {
120- val = severity .toUpperCase ();
116+ private final Severity extractSeverity (final String severityValue ) {
117+ String severity = "MAJOR" ;
118+ if (severityValue != null ) {
119+ severity = severityValue .toUpperCase ();
120+ }
121+ if ("ERROR" .equalsIgnoreCase (severity )) {
122+ return Severity .CRITICAL ;
123+ }
124+ if ("WARNING" .equalsIgnoreCase (severity )) {
125+ return Severity .MAJOR ;
121126 }
122- if ("WARNING" .equalsIgnoreCase (val )) {
123- val = "MAJOR" ;
127+ try {
128+ return Severity .valueOf (severity );
129+ } catch (Exception e ) {
130+
124131 }
125- return Severity .valueOf (val );
132+ return Severity .MAJOR ;
133+
126134 }
127135
128136}
0 commit comments