Search in sources :

Example 1 with StandaloneSonarLintEngineImpl

use of org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl in project sonarlint-core by SonarSource.

the class Main method main.

public static void main(String[] args) throws MalformedURLException {
    String version = args[0];
    List<Path> pluginPaths = new ArrayList<>();
    for (int i = 1; i < args.length; i++) {
        pluginPaths.add(Paths.get(args[i]));
    }
    StandaloneGlobalConfiguration.Builder builder = StandaloneGlobalConfiguration.builder().setLogOutput(new LogOutput() {

        @Override
        public void log(String formattedMessage, Level level) {
        // Ignore
        }
    });
    for (Path path : pluginPaths) {
        builder.addPlugin(path.toUri().toURL());
    }
    StandaloneSonarLintEngineImpl client = new StandaloneSonarLintEngineImpl(builder.build());
    client.start();
    Table<String, String, RuleDetails> rulesByKeyAndLanguage = TreeBasedTable.create();
    for (String ruleKeyStr : ((StandaloneGlobalContainer) client.getGlobalContainer()).getActiveRuleKeys()) {
        RuleDetails ruleDetails = client.getRuleDetails(ruleKeyStr);
        RuleKey ruleKey = RuleKey.parse(ruleKeyStr);
        rulesByKeyAndLanguage.put(ruleKey.rule(), ruleDetails.getLanguage(), ruleDetails);
    }
    try {
        System.out.print("{");
        System.out.print("\"version\": \"");
        System.out.print(version);
        System.out.print("\",");
        System.out.print("\"rules\": [");
        boolean first = true;
        for (String ruleKey : rulesByKeyAndLanguage.rowKeySet()) {
            if (!first) {
                System.out.print(",");
            }
            first = false;
            System.out.print("{");
            System.out.print("\"key\": \"");
            System.out.print(ruleKey);
            System.out.print("\",");
            System.out.print("\"title\": \"");
            System.out.print(escapeJson(rulesByKeyAndLanguage.row(ruleKey).values().iterator().next().getName()));
            System.out.print("\",");
            Set<String> mergedTags = new HashSet<>();
            for (RuleDetails rule : rulesByKeyAndLanguage.row(ruleKey).values()) {
                mergedTags.addAll(Arrays.asList(rule.getTags()));
            }
            writeTags(mergedTags);
            System.out.print(",");
            System.out.print("\"implementations\": [");
            boolean firstLang = true;
            for (Map.Entry<String, RuleDetails> detailPerLanguage : rulesByKeyAndLanguage.row(ruleKey).entrySet()) {
                if (!firstLang) {
                    System.out.print(",");
                }
                firstLang = false;
                RuleDetails ruleDetails = detailPerLanguage.getValue();
                System.out.print("{");
                System.out.print("\"key\": \"");
                System.out.print(ruleDetails.getKey());
                System.out.print("\",");
                System.out.print("\"language\": \"");
                System.out.print(languageLabel(detailPerLanguage.getKey()));
                System.out.print("\",");
                System.out.print("\"title\": \"");
                System.out.print(escapeJson(ruleDetails.getName()));
                System.out.print("\",");
                System.out.print("\"description\": \"");
                System.out.print(escapeJson(ruleDetails.getHtmlDescription()));
                System.out.print("\",");
                System.out.print("\"severity\": \"");
                System.out.print(StringUtils.capitalize(ruleDetails.getSeverity().toLowerCase()));
                System.out.print("\",");
                String[] tags = ruleDetails.getTags();
                writeTags(Arrays.asList(tags));
                System.out.print("}");
            }
            System.out.print("]");
            System.out.print("}");
        }
        System.out.print("]");
        System.out.print("}");
    } finally {
        client.stop();
    }
}
Also used : Path(java.nio.file.Path) RuleKey(org.sonar.api.rule.RuleKey) ArrayList(java.util.ArrayList) StandaloneGlobalContainer(org.sonarsource.sonarlint.core.container.standalone.StandaloneGlobalContainer) LogOutput(org.sonarsource.sonarlint.core.client.api.common.LogOutput) StandaloneSonarLintEngineImpl(org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl) StandaloneGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneGlobalConfiguration) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) RuleDetails(org.sonarsource.sonarlint.core.client.api.common.RuleDetails) HashSet(java.util.HashSet)

Example 2 with StandaloneSonarLintEngineImpl

use of org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl in project sonarlint-core by SonarSource.

the class StandaloneSonarLintImpl method start.

private void start() {
    Builder builder = StandaloneGlobalConfiguration.builder();
    for (URL pluginPath : analyzers) {
        builder.addPlugin(pluginPath);
    }
    builder.setLogOutput(logOutput);
    builder.setSonarLintUserHome(Utils.getStandaloneHome());
    engine = new StandaloneSonarLintEngineImpl(builder.build());
}
Also used : Builder(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneGlobalConfiguration.Builder) URL(java.net.URL) StandaloneSonarLintEngineImpl(org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl)

Example 3 with StandaloneSonarLintEngineImpl

use of org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl in project sonarlint-core by SonarSource.

the class LogMediumTest method prepare.

@Before
public void prepare() throws IOException {
    logs = Multimaps.synchronizedListMultimap(LinkedListMultimap.create());
    config = StandaloneGlobalConfiguration.builder().addPlugin(PluginLocator.getJavaScriptPluginUrl()).setLogOutput(createLogOutput(logs)).build();
    sonarlint = new StandaloneSonarLintEngineImpl(config);
    baseDir = temp.newFolder();
}
Also used : StandaloneSonarLintEngineImpl(org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl) Before(org.junit.Before)

Example 4 with StandaloneSonarLintEngineImpl

use of org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl in project sonar-java by SonarSource.

the class SonarLintTest method prepare.

@BeforeClass
public static void prepare() throws Exception {
    StandaloneGlobalConfiguration config = StandaloneGlobalConfiguration.builder().addPlugin(JavaTestSuite.JAVA_PLUGIN_LOCATION.getFile().toURI().toURL()).setSonarLintUserHome(temp.newFolder().toPath()).setLogOutput((formattedMessage, level) -> {
    /* Don't pollute logs*/
    }).build();
    sonarlintEngine = new StandaloneSonarLintEngineImpl(config);
    baseDir = temp.newFolder();
}
Also used : BeforeClass(org.junit.BeforeClass) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) StandaloneSonarLintEngineImpl(org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl) ArrayList(java.util.ArrayList) Charset(java.nio.charset.Charset) Files(com.google.common.io.Files) StandaloneGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneGlobalConfiguration) ClassRule(org.junit.ClassRule) Path(java.nio.file.Path) StandaloneSonarLintEngine(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneSonarLintEngine) AfterClass(org.junit.AfterClass) ImmutableMap(com.google.common.collect.ImmutableMap) Assertions.tuple(org.assertj.core.api.Assertions.tuple) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) FileInputStream(java.io.FileInputStream) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) StandaloneAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration) List(java.util.List) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults) Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) InputStream(java.io.InputStream) StandaloneGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneGlobalConfiguration) StandaloneSonarLintEngineImpl(org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl) BeforeClass(org.junit.BeforeClass)

Example 5 with StandaloneSonarLintEngineImpl

use of org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl in project sonarlint-intellij by SonarSource.

the class StandaloneTest method prepare.

@BeforeClass
public static void prepare() throws Exception {
    StandaloneGlobalConfiguration config = StandaloneGlobalConfiguration.builder().addPlugins(getPlugins(PLUGINS_FOLDER).toArray(new URL[0])).setSonarLintUserHome(temp.newFolder("sonarlint").toPath()).setLogOutput((msg, level) -> System.out.println("[" + level + "]: " + msg)).build();
    sonarlintEngine = new StandaloneSonarLintEngineImpl(config);
    baseDir = temp.newFolder();
}
Also used : BeforeClass(org.junit.BeforeClass) MalformedURLException(java.net.MalformedURLException) Files(java.nio.file.Files) Assertions.tuple(org.assertj.core.api.Assertions.tuple) URL(java.net.URL) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IOException(java.io.IOException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) StandaloneSonarLintEngineImpl(org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl) ArrayList(java.util.ArrayList) StandaloneAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration) List(java.util.List) Paths(java.nio.file.Paths) StandaloneGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneGlobalConfiguration) Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) ClassRule(org.junit.ClassRule) Path(java.nio.file.Path) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) StandaloneSonarLintEngine(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneSonarLintEngine) StandaloneGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneGlobalConfiguration) StandaloneSonarLintEngineImpl(org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl) BeforeClass(org.junit.BeforeClass)

Aggregations

StandaloneSonarLintEngineImpl (org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl)11 StandaloneGlobalConfiguration (org.sonarsource.sonarlint.core.client.api.standalone.StandaloneGlobalConfiguration)8 IOException (java.io.IOException)6 Path (java.nio.file.Path)6 File (java.io.File)5 BeforeClass (org.junit.BeforeClass)5 ClientInputFile (org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)5 URL (java.net.URL)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Test (org.junit.Test)4 TemporaryFolder (org.junit.rules.TemporaryFolder)4 StandaloneAnalysisConfiguration (org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration)4 StandaloneSonarLintEngine (org.sonarsource.sonarlint.core.client.api.standalone.StandaloneSonarLintEngine)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 StandardCharsets (java.nio.charset.StandardCharsets)3 Collections (java.util.Collections)3 List (java.util.List)3 FileUtils (org.apache.commons.io.FileUtils)3