Search in sources :

Example 1 with ConnectedSonarLintEngineImpl

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

the class ConnectedModeTest method start.

@Before
public void start() {
    FileUtils.deleteQuietly(sonarUserHome.toFile());
    Map<String, String> globalProps = new HashMap<>();
    globalProps.put("sonar.global.label", "It works");
    logs = new ArrayList<>();
    engine = new ConnectedSonarLintEngineImpl(ConnectedGlobalConfiguration.builder().setServerId("orchestrator").setSonarLintUserHome(sonarUserHome).setLogOutput((msg, level) -> logs.add(msg)).setExtraProperties(globalProps).build());
    assertThat(engine.getGlobalStorageStatus()).isNull();
    assertThat(engine.getState()).isEqualTo(State.NEVER_UPDATED);
    // This profile is altered in a test
    ORCHESTRATOR.getServer().restoreProfile(FileLocation.ofClasspath("/java-sonarlint.xml"));
}
Also used : HashMap(java.util.HashMap) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) Before(org.junit.Before)

Example 2 with ConnectedSonarLintEngineImpl

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

the class ConnectedModeRequirementsTest method start.

@Before
public void start() {
    FileUtils.deleteQuietly(sonarUserHome.toFile());
    engine = new ConnectedSonarLintEngineImpl(ConnectedGlobalConfiguration.builder().setServerId("orchestrator").setSonarLintUserHome(sonarUserHome).setLogOutput((msg, level) -> System.out.println(msg)).build());
    assertThat(engine.getGlobalStorageStatus()).isNull();
    assertThat(engine.getState()).isEqualTo(State.NEVER_UPDATED);
}
Also used : ValidationResult(org.sonarsource.sonarlint.core.client.api.connected.ValidationResult) BeforeClass(org.junit.BeforeClass) UserParameters(org.sonar.wsclient.user.UserParameters) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) WsHelperImpl(org.sonarsource.sonarlint.core.WsHelperImpl) ConnectedGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration) UpdateResult(org.sonarsource.sonarlint.core.client.api.connected.UpdateResult) Rule(org.junit.Rule) After(org.junit.After) ClassRule(org.junit.ClassRule) Path(java.nio.file.Path) ExpectedException(org.junit.rules.ExpectedException) State(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine.State) LoadedAnalyzer(org.sonarsource.sonarlint.core.client.api.connected.LoadedAnalyzer) TemporaryFolder(org.junit.rules.TemporaryFolder) ConnectedSonarLintEngine(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine) Orchestrator(com.sonar.orchestrator.Orchestrator) Before(org.junit.Before) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) Before(org.junit.Before)

Example 3 with ConnectedSonarLintEngineImpl

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

the class ConnectedEmptyStorageMediumTest method prepare.

@BeforeClass
public static void prepare() throws Exception {
    Path slHome = temp.newFolder().toPath();
    ConnectedGlobalConfiguration config = ConnectedGlobalConfiguration.builder().setServerId("localhost").setSonarLintUserHome(slHome).setLogOutput((msg, level) -> {
    }).build();
    sonarlint = new ConnectedSonarLintEngineImpl(config);
    baseDir = temp.newFolder();
}
Also used : Path(java.nio.file.Path) AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) ImmutableMap(com.google.common.collect.ImmutableMap) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) Test(org.junit.Test) GlobalUpdateRequiredException(org.sonarsource.sonarlint.core.client.api.exceptions.GlobalUpdateRequiredException) ConnectedAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) ConnectedGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration) File(java.io.File) IssueListener(org.sonarsource.sonarlint.core.client.api.common.analysis.IssueListener) Assertions.fail(org.assertj.core.api.Assertions.fail) ClassRule(org.junit.ClassRule) Path(java.nio.file.Path) Collections(java.util.Collections) State(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine.State) TemporaryFolder(org.junit.rules.TemporaryFolder) ConnectedSonarLintEngine(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine) Mockito.mock(org.mockito.Mockito.mock) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) ConnectedGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration) BeforeClass(org.junit.BeforeClass)

Example 4 with ConnectedSonarLintEngineImpl

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

the class ConnectedFileExclusionsMediumTest method prepare.

@BeforeClass
public static void prepare() throws Exception {
    Path slHome = temp.newFolder().toPath();
    /*
     * This storage contains one server id "local" and two modules: "test-project" (with an empty QP) and "test-project-2" (with default QP)
     */
    Path storage = Paths.get(ConnectedFileExclusionsMediumTest.class.getResource("/sample-storage").toURI());
    Path tmpStorage = slHome.resolve("storage");
    FileUtils.copyDirectory(storage.toFile(), tmpStorage.toFile());
    PluginReferences.Builder builder = PluginReferences.newBuilder();
    ProtobufUtil.writeToFile(builder.build(), tmpStorage.resolve("local").resolve("global").resolve(StoragePaths.PLUGIN_REFERENCES_PB));
    writeModuleStatus(tmpStorage, MODULE_KEY, VersionUtils.getLibraryVersion());
    writeStatus(tmpStorage, VersionUtils.getLibraryVersion());
    ConnectedGlobalConfiguration config = ConnectedGlobalConfiguration.builder().setServerId("local").setSonarLintUserHome(slHome).setStorageRoot(tmpStorage).setLogOutput(createNoOpLogOutput()).build();
    sonarlint = new ConnectedSonarLintEngineImpl(config);
    baseDir = temp.newFolder();
}
Also used : Path(java.nio.file.Path) PluginReferences(org.sonarsource.sonarlint.core.proto.Sonarlint.PluginReferences) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) ConnectedGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration) BeforeClass(org.junit.BeforeClass)

Example 5 with ConnectedSonarLintEngineImpl

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

the class ConnectedIssueMediumTest method prepare.

@BeforeClass
public static void prepare() throws Exception {
    Path slHome = temp.newFolder().toPath();
    Path pluginCache = slHome.resolve("plugins");
    /*
     * This storage contains one server id "local" and two modules: "test-project" (with an empty QP) and "test-project-2" (with default QP)
     */
    Path storage = Paths.get(ConnectedIssueMediumTest.class.getResource("/sample-storage").toURI());
    Path tmpStorage = slHome.resolve("storage");
    FileUtils.copyDirectory(storage.toFile(), tmpStorage.toFile());
    Files.move(tmpStorage.resolve("local"), tmpStorage.resolve(StoragePaths.encodeForFs(SERVER_ID)));
    PluginCache cache = PluginCache.create(pluginCache);
    PluginReferences.Builder builder = PluginReferences.newBuilder();
    builder.addReference(PluginReference.newBuilder().setFilename(PluginLocator.SONAR_JAVASCRIPT_PLUGIN_JAR).setHash(PluginLocator.SONAR_JAVASCRIPT_PLUGIN_JAR_HASH).setKey("javascript").build());
    cache.get(PluginLocator.SONAR_JAVASCRIPT_PLUGIN_JAR, PluginLocator.SONAR_JAVASCRIPT_PLUGIN_JAR_HASH, new Copier() {

        @Override
        public void copy(String filename, Path toFile) throws IOException {
            FileUtils.copyURLToFile(PluginLocator.getJavaScriptPluginUrl(), toFile.toFile());
        }
    });
    builder.addReference(PluginReference.newBuilder().setFilename(PluginLocator.SONAR_JAVA_PLUGIN_JAR).setHash(PluginLocator.SONAR_JAVA_PLUGIN_JAR_HASH).setKey("java").build());
    cache.get(PluginLocator.SONAR_JAVA_PLUGIN_JAR, PluginLocator.SONAR_JAVA_PLUGIN_JAR_HASH, new Copier() {

        @Override
        public void copy(String filename, Path toFile) throws IOException {
            FileUtils.copyURLToFile(PluginLocator.getJavaPluginUrl(), toFile.toFile());
        }
    });
    ProtobufUtil.writeToFile(builder.build(), tmpStorage.resolve(StoragePaths.encodeForFs(SERVER_ID)).resolve("global").resolve(StoragePaths.PLUGIN_REFERENCES_PB));
    // update versions in test storage and create an empty stale module storage
    writeModuleStatus(tmpStorage, "test-project", StoragePaths.STORAGE_VERSION);
    writeModuleStatus(tmpStorage, JAVA_MODULE_KEY, StoragePaths.STORAGE_VERSION);
    writeModuleStatus(tmpStorage, "stale_module", "0");
    writeStatus(tmpStorage, VersionUtils.getLibraryVersion());
    ConnectedGlobalConfiguration config = ConnectedGlobalConfiguration.builder().setServerId(SERVER_ID).setSonarLintUserHome(slHome).setStorageRoot(tmpStorage).setLogOutput(createNoOpLogOutput()).build();
    sonarlint = new ConnectedSonarLintEngineImpl(config);
    baseDir = temp.newFolder();
}
Also used : Path(java.nio.file.Path) PluginReferences(org.sonarsource.sonarlint.core.proto.Sonarlint.PluginReferences) Copier(org.sonarsource.sonarlint.core.plugin.cache.PluginCache.Copier) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) PluginCache(org.sonarsource.sonarlint.core.plugin.cache.PluginCache) IOException(java.io.IOException) ConnectedGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration) BeforeClass(org.junit.BeforeClass)

Aggregations

ConnectedSonarLintEngineImpl (org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl)11 Path (java.nio.file.Path)8 BeforeClass (org.junit.BeforeClass)8 ConnectedGlobalConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration)8 Test (org.junit.Test)5 ConnectedSonarLintEngine (org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine)5 IOException (java.io.IOException)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Before (org.junit.Before)4 ClassRule (org.junit.ClassRule)4 TemporaryFolder (org.junit.rules.TemporaryFolder)4 PluginReferences (org.sonarsource.sonarlint.core.proto.Sonarlint.PluginReferences)4 Orchestrator (com.sonar.orchestrator.Orchestrator)3 FileUtils (org.apache.commons.io.FileUtils)3 After (org.junit.After)3 Rule (org.junit.Rule)3 ExpectedException (org.junit.rules.ExpectedException)3 UserParameters (org.sonar.wsclient.user.UserParameters)3 ServerConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration)3 PluginCache (org.sonarsource.sonarlint.core.plugin.cache.PluginCache)3