@@ -100,31 +100,10 @@ public void execute(SensorContext sensorContext) {
100100 final Configuration config = sensorContext .config ();
101101 // Represent the active rules used for the analysis.
102102 final ActiveRules activeRules = sensorContext .activeRules ();
103+
103104 // run i-Code CNES execution
104105 if (config .getBoolean (ICodePluginProperties .AUTOLAUNCH_PROP_KEY ).orElse (Boolean .getBoolean (ICodePluginProperties .AUTOLAUNCH_PROP_DEFAULT ))) {
105- LOGGER .info ("i-Code CNES auto-launch enabled." );
106- final String executable = config .get (ICodePluginProperties .ICODE_PATH_KEY ).orElse (ICodePluginProperties .ICODE_PATH_DEFAULT );
107- final String [] files = sensorContext .fileSystem ().baseDir ().list ();
108- final String outputFile = config .get (ICodePluginProperties .REPORT_PATH_KEY ).orElse (ICodePluginProperties .REPORT_PATH_DEFAULT );
109- final String outputPath = Paths .get (sensorContext .fileSystem ().baseDir ().toString (),outputFile ).toString ();
110- final String outputOption = "-o" ;
111- final String command = String .join (" " , executable , String .join (" " ,files ), outputOption , outputPath );
112-
113- LOGGER .info ("Running i-Code CNES and generating results to " + outputPath );
114- try {
115- final Process icode = Runtime .getRuntime ().exec (command );
116- int success = icode .waitFor ();
117- if (0 !=success ){
118- final String message = String .format ("i-Code CNES auto-launch analysis failed with exit code %d." ,success );
119- throw new ICodeException (message );
120- }
121- LOGGER .info ("Auto-launch successfully executed i-Code CNES." );
122- } catch (InterruptedException | IOException | ICodeException e ) {
123- LOGGER .error (e .getMessage (), e );
124- sensorContext .newAnalysisError ().message (e .getMessage ()).save ();
125- }
126-
127-
106+ executeICode (sensorContext );
128107 }
129108
130109 // Report files found in file system and corresponding to SQ property.
@@ -162,6 +141,48 @@ public void execute(SensorContext sensorContext) {
162141
163142 }
164143
144+ /**
145+ * Execute i-Code through a system process.
146+ *
147+ * @param sensorContext Context of the sensor.
148+ */
149+ protected void executeICode (final SensorContext sensorContext ) {
150+ LOGGER .info ("i-Code CNES auto-launch enabled." );
151+ final Configuration config = sensorContext .config ();
152+ final String executable = config .get (ICodePluginProperties .ICODE_PATH_KEY ).orElse (ICodePluginProperties .ICODE_PATH_DEFAULT );
153+ final String [] files = sensorContext .fileSystem ().baseDir ().list ();
154+ final String outputFile = config .get (ICodePluginProperties .REPORT_PATH_KEY ).orElse (ICodePluginProperties .REPORT_PATH_DEFAULT );
155+ final String outputPath = Paths .get (sensorContext .fileSystem ().baseDir ().toString (),outputFile ).toString ();
156+ final String outputOption = "-o" ;
157+ final String command = String .join (" " , executable , String .join (" " ,files ), outputOption , outputPath );
158+
159+ LOGGER .info ("Running i-Code CNES and generating results to " + outputPath );
160+ try {
161+ int success = runICode (command );
162+ if (0 !=success ){
163+ final String message = String .format ("i-Code CNES auto-launch analysis failed with exit code %d." ,success );
164+ throw new ICodeException (message );
165+ }
166+ LOGGER .info ("Auto-launch successfully executed i-Code CNES." );
167+ } catch (InterruptedException | IOException | ICodeException e ) {
168+ LOGGER .error (e .getMessage (), e );
169+ sensorContext .newAnalysisError ().message (e .getMessage ()).save ();
170+ }
171+ }
172+
173+ /**
174+ * Run the i-Code command.
175+ *
176+ * @param command The i-Code Command to execute.
177+ * @return 0 if all was fine.
178+ * @throws IOException On possible unknown file.
179+ * @throws InterruptedException On possible process problem.
180+ */
181+ protected int runICode (final String command ) throws IOException , InterruptedException {
182+ final Process icode = Runtime .getRuntime ().exec (command );
183+ return icode .waitFor ();
184+ }
185+
165186 /**
166187 * This method save an issue into the SonarQube service.
167188 *
0 commit comments