Search in sources :

Example 1 with InputFile

use of org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.InputFile in project sonarlint-core by SonarSource.

the class StandaloneDaemonTest method createAnalysisConfig.

private AnalysisReq createAnalysisConfig(String projectName) throws IOException {
    Path projectPath = clientTools.deployProject(projectName);
    List<Path> sourceFiles = clientTools.collectAllFiles(projectPath.resolve("src"));
    Builder builder = AnalysisReq.newBuilder();
    for (Path p : sourceFiles) {
        InputFile file = InputFile.newBuilder().setCharset(StandardCharsets.UTF_8.name()).setPath(p.toAbsolutePath().toString()).setIsTest(false).build();
        builder.addFile(file);
    }
    return builder.setBaseDir(projectPath.toAbsolutePath().toString()).setWorkDir(temp.newFolder().getAbsolutePath()).putAllProperties(Collections.singletonMap("key", "value")).build();
}
Also used : Path(java.nio.file.Path) Builder(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.AnalysisReq.Builder) ManagedChannelBuilder(io.grpc.ManagedChannelBuilder) InputFile(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.InputFile)

Example 2 with InputFile

use of org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.InputFile in project sonarlint-core by SonarSource.

the class StandaloneSonarLintImpl method analyze.

@Override
public void analyze(AnalysisReq requestConfig, StreamObserver<Issue> response) {
    if (engine == null) {
        response.onError(new IllegalStateException("Not registered"));
        return;
    }
    try {
        List<ClientInputFile> files = new LinkedList<>();
        List<InputFile> requestFiles = requestConfig.getFileList();
        Path baseDir = Paths.get(requestConfig.getBaseDir());
        for (InputFile f : requestFiles) {
            files.add(new DefaultClientInputFile(baseDir, Paths.get(f.getPath()), f.getIsTest(), Charset.forName(f.getCharset()), f.getUserObject(), trimToNull(f.getLanguage())));
        }
        StandaloneAnalysisConfiguration config = new StandaloneAnalysisConfiguration(baseDir, Paths.get(requestConfig.getWorkDir()), files, requestConfig.getPropertiesMap());
        logOutput.log("Analysis configuration:\n" + config.toString(), Level.DEBUG);
        engine.analyze(config, new ProxyIssueListener(response), logOutput, null);
        response.onCompleted();
    } catch (Exception e) {
        LOGGER.error("Error analyzing", e);
        response.onError(e);
    }
}
Also used : Path(java.nio.file.Path) DefaultClientInputFile(org.sonarlint.daemon.model.DefaultClientInputFile) ProxyIssueListener(org.sonarlint.daemon.model.ProxyIssueListener) StandaloneAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration) DefaultClientInputFile(org.sonarlint.daemon.model.DefaultClientInputFile) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) LinkedList(java.util.LinkedList) DefaultClientInputFile(org.sonarlint.daemon.model.DefaultClientInputFile) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) InputFile(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.InputFile)

Example 3 with InputFile

use of org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.InputFile in project sonarlint-core by SonarSource.

the class ConnectedSonarLintImpl method analyze.

@Override
public void analyze(ConnectedAnalysisReq requestConfig, StreamObserver<org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Issue> response) {
    try {
        List<ClientInputFile> files = new LinkedList<>();
        List<InputFile> requestFiles = requestConfig.getFileList();
        Path baseDir = Paths.get(requestConfig.getBaseDir());
        for (InputFile f : requestFiles) {
            files.add(new DefaultClientInputFile(baseDir, Paths.get(f.getPath()), f.getIsTest(), Charset.forName(f.getCharset()), f.getUserObject(), trimToNull(f.getLanguage())));
        }
        ConnectedAnalysisConfiguration config = new ConnectedAnalysisConfiguration(requestConfig.getModuleKey(), baseDir, Paths.get(requestConfig.getWorkDir()), files, requestConfig.getPropertiesMap());
        engine.analyze(config, new ProxyIssueListener(response), logOutput, null);
        response.onCompleted();
    } catch (Exception e) {
        LOGGER.error("Error analyzing", e);
        response.onError(e);
    }
}
Also used : Path(java.nio.file.Path) DefaultClientInputFile(org.sonarlint.daemon.model.DefaultClientInputFile) ConnectedAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration) ProxyIssueListener(org.sonarlint.daemon.model.ProxyIssueListener) DefaultClientInputFile(org.sonarlint.daemon.model.DefaultClientInputFile) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) LinkedList(java.util.LinkedList) DefaultClientInputFile(org.sonarlint.daemon.model.DefaultClientInputFile) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) InputFile(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.InputFile)

Example 4 with InputFile

use of org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.InputFile in project sonarlint-core by SonarSource.

the class ConnectedDaemonTest method createAnalysisConfig.

private ConnectedAnalysisReq createAnalysisConfig(String projectName) throws IOException {
    Path projectPath = clientTools.deployProject(projectName);
    List<Path> sourceFiles = clientTools.collectAllFiles(projectPath);
    Builder builder = ConnectedAnalysisReq.newBuilder();
    for (Path p : sourceFiles) {
        InputFile file = InputFile.newBuilder().setCharset(StandardCharsets.UTF_8.name()).setPath(p.toAbsolutePath().toString()).setIsTest(false).build();
        builder.addFile(file);
    }
    return builder.setBaseDir(projectPath.toAbsolutePath().toString()).setWorkDir(temp.newFolder().getAbsolutePath()).setModuleKey(PROJECT_KEY_JAVA).putAllProperties(Collections.singletonMap("sonar.java.binaries", new File("projects/sample-java/target/classes").getAbsolutePath())).build();
}
Also used : Path(java.nio.file.Path) ManagedChannelBuilder(io.grpc.ManagedChannelBuilder) Builder(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.ConnectedAnalysisReq.Builder) InputFile(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.InputFile) File(java.io.File) InputFile(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.InputFile)

Aggregations

Path (java.nio.file.Path)4 InputFile (org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.InputFile)4 ManagedChannelBuilder (io.grpc.ManagedChannelBuilder)2 LinkedList (java.util.LinkedList)2 DefaultClientInputFile (org.sonarlint.daemon.model.DefaultClientInputFile)2 ProxyIssueListener (org.sonarlint.daemon.model.ProxyIssueListener)2 ClientInputFile (org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)2 File (java.io.File)1 ConnectedAnalysisConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration)1 StandaloneAnalysisConfiguration (org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration)1 Builder (org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.AnalysisReq.Builder)1 Builder (org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.ConnectedAnalysisReq.Builder)1