Search in sources :

Example 1 with LogOutput

use of org.sonarsource.sonarlint.core.client.api.common.LogOutput in project sonarlint-core by SonarSource.

the class LogCallbackAppender method append.

@Override
protected void append(ILoggingEvent event) {
    LogOutput target = tlTtarget.get();
    if (target == null) {
        defaultAppender.doAppend(event);
        return;
    }
    String msg;
    if (event.getThrowableProxy() == null) {
        msg = event.getFormattedMessage();
    } else {
        ExtendedThrowableProxyConverter throwableConverter = new ExtendedThrowableProxyConverter();
        throwableConverter.start();
        msg = event.getFormattedMessage() + "\n" + throwableConverter.convert(event);
        throwableConverter.stop();
    }
    handleErrors(event);
    target.log(msg, translate(event.getLevel()));
}
Also used : ExtendedThrowableProxyConverter(ch.qos.logback.classic.pattern.ExtendedThrowableProxyConverter) LogOutput(org.sonarsource.sonarlint.core.client.api.common.LogOutput)

Example 2 with LogOutput

use of org.sonarsource.sonarlint.core.client.api.common.LogOutput 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 3 with LogOutput

use of org.sonarsource.sonarlint.core.client.api.common.LogOutput in project sonarlint-core by SonarSource.

the class StandaloneNoPluginMediumTest method prepare.

@Before
public void prepare() throws IOException {
    LogOutput logOutput = (msg, level) -> logs.put(level, msg);
    sonarlint = new StandaloneSonarLintEngineImpl(StandaloneGlobalConfiguration.builder().setLogOutput(logOutput).build());
    baseDir = temp.newFolder();
}
Also used : LinkedListMultimap(com.google.common.collect.LinkedListMultimap) Arrays(java.util.Arrays) ImmutableMap(com.google.common.collect.ImmutableMap) TestUtils(org.sonarsource.sonarlint.core.TestUtils) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) Multimap(com.google.common.collect.Multimap) Level(org.sonarsource.sonarlint.core.client.api.common.LogOutput.Level) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) File(java.io.File) StandaloneSonarLintEngineImpl(org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl) StandaloneAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration) Rule(org.junit.Rule) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults) StandaloneGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneGlobalConfiguration) After(org.junit.After) TemporaryFolder(org.junit.rules.TemporaryFolder) LogOutput(org.sonarsource.sonarlint.core.client.api.common.LogOutput) StandaloneSonarLintEngine(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneSonarLintEngine) Before(org.junit.Before) LogOutput(org.sonarsource.sonarlint.core.client.api.common.LogOutput) StandaloneSonarLintEngineImpl(org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl) Before(org.junit.Before)

Aggregations

LogOutput (org.sonarsource.sonarlint.core.client.api.common.LogOutput)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 StandaloneSonarLintEngineImpl (org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl)2 StandaloneGlobalConfiguration (org.sonarsource.sonarlint.core.client.api.standalone.StandaloneGlobalConfiguration)2 ExtendedThrowableProxyConverter (ch.qos.logback.classic.pattern.ExtendedThrowableProxyConverter)1 LinkedListMultimap (com.google.common.collect.LinkedListMultimap)1 Multimap (com.google.common.collect.Multimap)1 File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 FileUtils (org.apache.commons.io.FileUtils)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 After (org.junit.After)1 Before (org.junit.Before)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1