|
17 | 17 |
|
18 | 18 | import com.fortify.cli.common.cli.cmd.AbstractRunnableCommand; |
19 | 19 | import com.fortify.cli.common.cli.util.FcliCommandExecutorFactory; |
| 20 | +import com.fortify.cli.common.exception.FcliCommandExecutionException; |
20 | 21 | import com.fortify.cli.common.exception.FcliSimpleException; |
21 | 22 | import com.fortify.cli.common.util.JreHelper; |
22 | 23 | import com.fortify.cli.common.util.OutputHelper; |
@@ -142,9 +143,13 @@ private RegistrationResult tryRegisterTool(ToolSetupSpec spec, String version) { |
142 | 143 | String installDir = extractInstallDirFromJsonOutput(result.getOut()); |
143 | 144 | return new RegistrationResult(true, installDir != null ? installDir : "PATH"); |
144 | 145 | } |
145 | | - } catch (Exception e) { |
| 146 | + } catch (FcliCommandExecutionException e) { |
146 | 147 | // Registration failed, but don't throw - just log progress |
147 | 148 | System.out.println("Tool " + toolName + " not found in PATH, will proceed with installation"); |
| 149 | + // Do not show stderr for expected registration failures |
| 150 | + } catch (Exception e) { |
| 151 | + // Other exceptions |
| 152 | + System.out.println("Tool " + toolName + " not found in PATH, will proceed with installation"); |
148 | 153 | } |
149 | 154 | return new RegistrationResult(false, null); |
150 | 155 | } |
@@ -186,16 +191,24 @@ private InstallResult installTool(ToolSetupSpec spec, String version) { |
186 | 191 | } |
187 | 192 | } |
188 | 193 |
|
189 | | - var result = executeFcliCommand(cmd); |
190 | | - if (result.getExitCode() != 0) { |
191 | | - throw new FcliSimpleException("Failed to install " + toolName); |
| 194 | + try { |
| 195 | + var result = executeFcliCommand(cmd); |
| 196 | + |
| 197 | + // Extract action and install directory from JSON output |
| 198 | + String action = extractActionFromJsonOutput(result.getOut()); |
| 199 | + String installDir = extractInstallDirFromJsonOutput(result.getOut()); |
| 200 | + |
| 201 | + return new InstallResult(action != null ? action : "installed", installDir != null ? installDir : "installed"); |
| 202 | + } catch (FcliCommandExecutionException e) { |
| 203 | + // Show user-friendly error message |
| 204 | + System.err.println("Installation for " + toolName + " failed:"); |
| 205 | + if (e.getResult().getErr() != null && !e.getResult().getErr().isEmpty()) { |
| 206 | + System.err.println(e.getResult().getErr()); |
| 207 | + } else if (e.getResult().getOut() != null && !e.getResult().getOut().isEmpty()) { |
| 208 | + System.err.println(e.getResult().getOut()); |
| 209 | + } |
| 210 | + throw new FcliSimpleException("Installation of " + toolName + " failed"); |
192 | 211 | } |
193 | | - |
194 | | - // Extract action and install directory from JSON output |
195 | | - String action = extractActionFromJsonOutput(result.getOut()); |
196 | | - String installDir = extractInstallDirFromJsonOutput(result.getOut()); |
197 | | - |
198 | | - return new InstallResult(action != null ? action : "installed", installDir != null ? installDir : "installed"); |
199 | 212 | } |
200 | 213 |
|
201 | 214 | private String extractInstallDirFromJsonOutput(String output) { |
@@ -325,7 +338,7 @@ private OutputHelper.Result executeFcliCommand(String cmd) { |
325 | 338 | var executor = FcliCommandExecutorFactory.builder() |
326 | 339 | .cmd(cmd) |
327 | 340 | .stdoutOutputType(OutputType.collect) // Collect stdout to get the JSON output |
328 | | - .stderrOutputType(OutputType.suppress) // Suppress stderr to avoid showing exceptions |
| 341 | + .stderrOutputType(OutputType.collect) // Collect stderr to show on failure |
329 | 342 | .build() |
330 | 343 | .create(); |
331 | 344 | return executor.execute(); |
|
0 commit comments