Search in sources :

Example 1 with SearchWsRequest

use of org.sonarqube.ws.client.qualityprofile.SearchWsRequest in project sonarlint-core by SonarSource.

the class ConnectedModeTest method analysisTemplateRule.

@Test
public void analysisTemplateRule() throws Exception {
    // WS quality profile is not available before 5.2 so let's skip this test
    assumeTrue(ORCHESTRATOR.getServer().version().isGreaterThanOrEquals("5.2"));
    SearchWsRequest searchReq = new SearchWsRequest();
    searchReq.setQualityProfile("SonarLint IT Java");
    searchReq.setProjectKey(PROJECT_KEY_JAVA);
    searchReq.setDefaults(false);
    SearchWsResponse search = adminWsClient.qualityProfiles().search(searchReq);
    QualityProfile qp = null;
    for (QualityProfile q : search.getProfilesList()) {
        if (q.getName().equals("SonarLint IT Java")) {
            qp = q;
        }
    }
    assertThat(qp).isNotNull();
    WsRequest request = new PostRequest("/api/rules/create").setParam("custom_key", "myrule").setParam("name", "myrule").setParam("markdown_description", "my_rule_description").setParam("params", "methodName=echo;className=foo.Foo;argumentTypes=int").setParam("template_key", "squid:S2253").setParam("severity", "MAJOR");
    WsResponse response = adminWsClient.wsConnector().call(request);
    assertTrue(response.isSuccessful());
    request = new PostRequest("/api/qualityprofiles/activate_rule").setParam("profile_key", qp.getKey()).setParam("rule_key", "squid:myrule");
    response = adminWsClient.wsConnector().call(request);
    assertTrue(response.isSuccessful());
    try {
        updateGlobal();
        updateModule(PROJECT_KEY_JAVA);
        SaveIssueListener issueListener = new SaveIssueListener();
        engine.analyze(createAnalysisConfiguration(PROJECT_KEY_JAVA, PROJECT_KEY_JAVA, "src/main/java/foo/Foo.java", "sonar.java.binaries", new File("projects/sample-java/target/classes").getAbsolutePath()), issueListener, null, null);
        assertThat(issueListener.getIssues()).hasSize(3);
        assertThat(engine.getRuleDetails("squid:myrule").getHtmlDescription()).contains("my_rule_description");
    } finally {
        request = new PostRequest("/api/rules/delete").setParam("key", "squid:myrule");
        response = adminWsClient.wsConnector().call(request);
        assertTrue(response.isSuccessful());
    }
}
Also used : PostRequest(org.sonarqube.ws.client.PostRequest) RemoveGroupWsRequest(org.sonarqube.ws.client.permission.RemoveGroupWsRequest) SearchWsRequest(org.sonarqube.ws.client.qualityprofile.SearchWsRequest) WsRequest(org.sonarqube.ws.client.WsRequest) SearchWsRequest(org.sonarqube.ws.client.qualityprofile.SearchWsRequest) SearchWsResponse(org.sonarqube.ws.QualityProfiles.SearchWsResponse) WsResponse(org.sonarqube.ws.client.WsResponse) QualityProfile(org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile) SearchWsResponse(org.sonarqube.ws.QualityProfiles.SearchWsResponse) File(java.io.File) Test(org.junit.Test)

Example 2 with SearchWsRequest

use of org.sonarqube.ws.client.qualityprofile.SearchWsRequest in project sonarlint-core by SonarSource.

the class ConnectedModeTest method checkForUpdate.

@Test
public void checkForUpdate() throws Exception {
    updateGlobal();
    updateModule(PROJECT_KEY_JAVA);
    ServerConfiguration serverConfig = getServerConfig(true);
    StorageUpdateCheckResult result = engine.checkIfGlobalStorageNeedUpdate(serverConfig, null);
    assertThat(result.needUpdate()).isFalse();
    // restarting server should not lead to notify an update
    ORCHESTRATOR.restartServer();
    result = engine.checkIfGlobalStorageNeedUpdate(serverConfig, null);
    assertThat(result.needUpdate()).isFalse();
    // Change a global setting that is not in the whitelist
    setSettings(null, "sonar.foo", "bar");
    result = engine.checkIfGlobalStorageNeedUpdate(serverConfig, null);
    assertThat(result.needUpdate()).isFalse();
    // Change a global setting that *is* in the whitelist
    setSettingsMultiValue(null, "sonar.inclusions", "**/*");
    // Activate a new rule
    SearchWsResponse response = newAdminWsClient(ORCHESTRATOR).qualityProfiles().search(new SearchWsRequest().setLanguage("java"));
    String profileKey = response.getProfilesList().stream().filter(p -> p.getName().equals("SonarLint IT Java")).findFirst().get().getKey();
    ORCHESTRATOR.getServer().adminWsClient().post("api/qualityprofiles/activate_rule", "profile_key", profileKey, "rule_key", "squid:S1228");
    result = engine.checkIfGlobalStorageNeedUpdate(serverConfig, null);
    assertThat(result.needUpdate()).isTrue();
    assertThat(result.changelog()).containsOnly("Global settings updated", "Quality profile 'SonarLint IT Java' for language 'Java' updated");
    result = engine.checkIfModuleStorageNeedUpdate(serverConfig, PROJECT_KEY_JAVA, null);
    assertThat(result.needUpdate()).isFalse();
    // Change a project setting that is not in the whitelist
    setSettings(PROJECT_KEY_JAVA, "sonar.foo", "biz");
    result = engine.checkIfModuleStorageNeedUpdate(serverConfig, PROJECT_KEY_JAVA, null);
    assertThat(result.needUpdate()).isFalse();
    // Change a project setting that *is* in the whitelist
    setSettingsMultiValue(PROJECT_KEY_JAVA, "sonar.exclusions", "**/*.foo");
    result = engine.checkIfModuleStorageNeedUpdate(serverConfig, PROJECT_KEY_JAVA, null);
    assertThat(result.needUpdate()).isTrue();
    assertThat(result.changelog()).containsOnly("Project settings updated");
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) PermissionParameters(org.sonar.wsclient.permissions.PermissionParameters) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) OrchestratorBuilder(com.sonar.orchestrator.OrchestratorBuilder) UnsupportedServerException(org.sonarsource.sonarlint.core.client.api.exceptions.UnsupportedServerException) InetAddress(java.net.InetAddress) WsClient(org.sonarqube.ws.client.WsClient) MovedContextHandler(org.eclipse.jetty.server.handler.MovedContextHandler) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) Map(java.util.Map) After(org.junit.After) ClassRule(org.junit.ClassRule) Path(java.nio.file.Path) Server(org.eclipse.jetty.server.Server) ConnectedSonarLintEngine(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine) StorageUpdateCheckResult(org.sonarsource.sonarlint.core.client.api.connected.StorageUpdateCheckResult) AfterClass(org.junit.AfterClass) RemoveGroupWsRequest(org.sonarqube.ws.client.permission.RemoveGroupWsRequest) NetworkUtils(com.sonar.orchestrator.util.NetworkUtils) FileLocation(com.sonar.orchestrator.locator.FileLocation) WsClientFactories(org.sonarqube.ws.client.WsClientFactories) SearchWsResponse(org.sonarqube.ws.QualityProfiles.SearchWsResponse) StandardCharsets(java.nio.charset.StandardCharsets) Configuration(com.sonar.orchestrator.config.Configuration) List(java.util.List) ExternalResource(org.junit.rules.ExternalResource) Assertions.fail(org.assertj.core.api.Assertions.fail) Assume.assumeTrue(org.junit.Assume.assumeTrue) SearchWsRequest(org.sonarqube.ws.client.qualityprofile.SearchWsRequest) Orchestrator(com.sonar.orchestrator.Orchestrator) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) QualityProfile(org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile) BeforeClass(org.junit.BeforeClass) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) HashMap(java.util.HashMap) PropertyDeleteQuery(org.sonar.wsclient.services.PropertyDeleteQuery) ConnectedGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration) ArrayList(java.util.ArrayList) HttpConnector(org.sonarqube.ws.client.HttpConnector) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) WsHelper(org.sonarsource.sonarlint.core.client.api.connected.WsHelper) ExpectedException(org.junit.rules.ExpectedException) State(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine.State) Nullable(javax.annotation.Nullable) Before(org.junit.Before) PropertyCreateQuery(org.sonar.wsclient.services.PropertyCreateQuery) MavenBuild(com.sonar.orchestrator.build.MavenBuild) Files(java.nio.file.Files) UserParameters(org.sonar.wsclient.user.UserParameters) PostRequest(org.sonarqube.ws.client.PostRequest) Assertions.tuple(org.assertj.core.api.Assertions.tuple) WsResponse(org.sonarqube.ws.client.WsResponse) SetRequest(org.sonarqube.ws.client.setting.SetRequest) Assert.assertTrue(org.junit.Assert.assertTrue) 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) File(java.io.File) ServerConnector(org.eclipse.jetty.server.ServerConnector) Rule(org.junit.Rule) Paths(java.nio.file.Paths) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults) WsRequest(org.sonarqube.ws.client.WsRequest) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) StorageUpdateCheckResult(org.sonarsource.sonarlint.core.client.api.connected.StorageUpdateCheckResult) ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) SearchWsRequest(org.sonarqube.ws.client.qualityprofile.SearchWsRequest) SearchWsResponse(org.sonarqube.ws.QualityProfiles.SearchWsResponse) Test(org.junit.Test)

Aggregations

File (java.io.File)2 Test (org.junit.Test)2 SearchWsResponse (org.sonarqube.ws.QualityProfiles.SearchWsResponse)2 QualityProfile (org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile)2 PostRequest (org.sonarqube.ws.client.PostRequest)2 WsRequest (org.sonarqube.ws.client.WsRequest)2 WsResponse (org.sonarqube.ws.client.WsResponse)2 RemoveGroupWsRequest (org.sonarqube.ws.client.permission.RemoveGroupWsRequest)2 SearchWsRequest (org.sonarqube.ws.client.qualityprofile.SearchWsRequest)2 Orchestrator (com.sonar.orchestrator.Orchestrator)1 OrchestratorBuilder (com.sonar.orchestrator.OrchestratorBuilder)1 MavenBuild (com.sonar.orchestrator.build.MavenBuild)1 Configuration (com.sonar.orchestrator.config.Configuration)1 FileLocation (com.sonar.orchestrator.locator.FileLocation)1 NetworkUtils (com.sonar.orchestrator.util.NetworkUtils)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1