Java Code Examples for org.sonar.api.utils.command.Command#create()
The following examples show how to use
org.sonar.api.utils.command.Command#create() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommandRunner.java From sonar-clojure with MIT License | 6 votes |
CommandStreamConsumer run(String command, CommandStreamConsumer stdout, CommandStreamConsumer stderr, Long timeOut, String... arguments) { Command cmd = Command.create(command); Arrays.stream(arguments).filter(Objects::nonNull).forEach(cmd::addArgument); int returnCode = commandExecutor.execute(cmd, stdout, stderr, fromSecondsToMilliseconds(timeOut)); logger.debug("command: " + cmd.getArguments()); logger.debug("stdout: " + String.join(DELIMITER, stdout.getData())); logger.debug("stderr: " + String.join(DELIMITER, stderr.getData())); if (SUCCESS_RETURN_CODE != returnCode) { //TODO A return code different than 0 doesn't mean error for some of the plugins we use. logger.warn("Command: " + cmd.getArguments() + " returned a non-zero code." + " Please make sure plugin is working" + " isolated before running sonar-scanner"); } return stdout; }
Example 2
Source File: CFLintAnalyzer.java From sonar-coldfusion with Apache License 2.0 | 5 votes |
public void analyze(File configFile) throws IOException, XMLStreamException { File executableJar = null; try { Command command = Command.create(settings.get(ColdFusionPlugin.CFLINT_JAVA).orElseThrow( IllegalStateException::new )); addCflintJavaOpts(command); executableJar = extractCflintJar(); command.addArgument("-jar") .addArgument(executableJar.getPath()) .addArgument("-xml") .addArgument("-folder") .addArgument(settings.get("sonar.projectBaseDir").orElseThrow( IllegalStateException::new )) .addArgument("-xmlfile") .addArgument(fs.workDir() + File.separator + "cflint-result.xml") .addArgument("-configfile") .addArgument(configFile.getPath()); CommandExecutor executor = CommandExecutor.create(); int exitCode = executor.execute(command, new LogInfoStreamConsumer(), new LogErrorStreamConsumer(), Integer.MAX_VALUE); if (exitCode != 0) { throw new IllegalStateException("The CFLint analyzer failed with exit code: " + exitCode); } } finally { //cleanup if(executableJar!= null && executableJar.exists()) { executableJar.deleteOnExit(); } } }