Java Code Examples for org.sonar.api.utils.command.CommandExecutor

The following examples show how to use org.sonar.api.utils.command.CommandExecutor. These examples are extracted from open source projects. 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 Project: SonarTsPlugin   Source File: TsLintExecutorImplTest.java    License: MIT License 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    this.system = mock(System2.class);
    this.tempFolder = mock(TempFolder.class);

    this.tempOutputFile = mock(File.class);
    when(this.tempOutputFile.getAbsolutePath()).thenReturn("path/to/temp");
    when(this.tempFolder.newFile()).thenReturn(this.tempOutputFile);

    this.commandExecutor = mock(CommandExecutor.class);

    this.executorImpl = spy(new TsLintExecutorImpl(this.system, this.tempFolder));
    when(this.executorImpl.createExecutor()).thenReturn(this.commandExecutor);
    doReturn(mock(BufferedReader.class)).when(this.executorImpl).getBufferedReaderForFile(any(File.class));

    // Setup a default config, which each method will mutate as required
    this.config = new TsLintExecutorConfig();
    this.config.setPathToNode("node");
    this.config.setPathToTsLint("path/to/tslint");
    this.config.setConfigFile("path/to/config");
    this.config.setRulesDir("path/to/rules");
    this.config.setTimeoutMs(40000);
}
 
Example 2
Source Project: sonar-coldfusion   Source File: CFLintAnalyzer.java    License: Apache License 2.0 5 votes vote down vote up
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();
        }
    }

}
 
Example 3
Source Project: sonar-coldfusion   Source File: ColdfusionSensorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testBasicCFMAnalysis() {
    DefaultFileSystem fileSystem = new DefaultFileSystem(tmpFolder.getRoot());
    fileSystem.setEncoding(Charsets.UTF_8);
    fileSystem.setWorkDir(tmpFolder.getRoot().toPath());

    context.setFileSystem(fileSystem);
    context.setRuntime(SonarRuntimeImpl.forSonarQube(Version.create(7, 6), SonarQubeSide.SCANNER));

    context.settings().appendProperty("sonar.projectBaseDir", baseDir.getPath());
    addFilesToFs();

    CommandExecutor commandExecutor = CommandExecutor.create();
    String javaHome = System.getProperty("java.home");
    Assert.assertTrue(javaHome!=null && !javaHome.equals(""));

    if(OSValidator.isWindows()) {
        context.settings().appendProperty(ColdFusionPlugin.CFLINT_JAVA, javaHome + "/bin/java.exe");
    } else {
        context.settings().appendProperty(ColdFusionPlugin.CFLINT_JAVA, javaHome + "/bin/java");
    }

    ColdFusionSensor sensor = new ColdFusionSensor(context.fileSystem(), rulesProfile);
    sensor.execute(context);

    Integer nloc = 0;
    Integer comments = 0;
    Integer complexity = 0;
    for (InputFile o : context.fileSystem().inputFiles()) {
        Measure<Integer> measureNloc = context.measure(o.key(),CoreMetrics.NCLOC.key());
        Measure<Integer> measureComment = context.measure(o.key(),CoreMetrics.COMMENT_LINES.key());
        Measure<Integer> measureComplexity = context.measure(o.key(),CoreMetrics.COMPLEXITY.key());
        nloc+=measureNloc.value();
        comments+=measureComment.value();
        complexity+=measureComplexity.value();
    }
    assertThat(nloc).isEqualTo(56);
    assertThat(comments).isEqualTo(9);
    assertThat(complexity).isEqualTo(10);
}
 
Example 4
Source Project: sonar-clojure   Source File: CommandRunner.java    License: MIT License 4 votes vote down vote up
public CommandRunner(Logger log, CommandExecutor commandExecutor) {
    this.logger = log;
    this.commandExecutor = commandExecutor;
}
 
Example 5
Source Project: sonar-clojure   Source File: CommandRunner.java    License: MIT License 4 votes vote down vote up
public CommandRunner() {
    this(STATIC_LOGGER, CommandExecutor.create());
}
 
Example 6
Source Project: sonar-ruby-plugin   Source File: RubocopExecutor.java    License: MIT License 4 votes vote down vote up
protected CommandExecutor createExecutor() {
    return CommandExecutor.create();
}
 
Example 7
Source Project: SonarTsPlugin   Source File: TsLintExecutorImpl.java    License: MIT License 4 votes vote down vote up
protected CommandExecutor createExecutor() {
    return CommandExecutor.create();
}