diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2023-06-26 16:05:22 -0500 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-07-18 20:03:23 +0000 |
commit | 58f87e3e1313b39df5f3669ccf5f01f5d3e97490 (patch) | |
tree | f236e39b6e7406164996d61dbc5be92ed194b45f /sonar-scanner-engine | |
parent | f2daf496660f784d97d2b6949be323ed689bca6a (diff) | |
download | sonarqube-58f87e3e1313b39df5f3669ccf5f01f5d3e97490.tar.gz sonarqube-58f87e3e1313b39df5f3669ccf5f01f5d3e97490.zip |
SONAR-19962 Upgrade Sonar Plugin API to v10.0.0.695
Diffstat (limited to 'sonar-scanner-engine')
7 files changed, 2 insertions, 250 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/platform/DefaultServer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/platform/DefaultServer.java index 64de06bc532..6b3b8c30258 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/platform/DefaultServer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/platform/DefaultServer.java @@ -72,14 +72,4 @@ public class DefaultServer extends Server { } return StringUtils.removeEnd(baseUrl, "/"); } - - @Override - public boolean isSecured() { - return false; - } - - @Override - public String getPermanentServerId() { - return getId(); - } } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/DefaultRulesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/DefaultRulesLoader.java deleted file mode 100644 index 2402fabcdbb..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/DefaultRulesLoader.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.scanner.rule; - -import java.io.IOException; -import java.io.InputStream; -import java.util.List; -import org.apache.commons.io.IOUtils; -import org.sonar.scanner.bootstrap.DefaultScannerWsClient; -import org.sonarqube.ws.Rules.ListResponse; -import org.sonarqube.ws.Rules.ListResponse.Rule; -import org.sonarqube.ws.client.GetRequest; - -public class DefaultRulesLoader implements RulesLoader { - private static final String RULES_SEARCH_URL = "/api/rules/list.protobuf"; - - private final DefaultScannerWsClient wsClient; - - public DefaultRulesLoader(DefaultScannerWsClient wsClient) { - this.wsClient = wsClient; - } - - @Override - public List<Rule> load() { - GetRequest getRequest = new GetRequest(RULES_SEARCH_URL); - ListResponse list = loadFromStream(wsClient.call(getRequest).contentStream()); - return list.getRulesList(); - } - - private static ListResponse loadFromStream(InputStream is) { - try { - return ListResponse.parseFrom(is); - } catch (IOException e) { - throw new IllegalStateException("Unable to get rules", e); - } finally { - IOUtils.closeQuietly(is); - } - } - -} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProvider.java deleted file mode 100644 index 22c6d270cc3..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProvider.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.scanner.rule; - -import java.util.List; -import org.sonar.api.batch.rule.Rules; -import org.sonar.api.batch.rule.internal.NewRule; -import org.sonar.api.batch.rule.internal.RulesBuilder; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; -import org.sonar.api.utils.log.Profiler; -import org.sonarqube.ws.Rules.ListResponse.Rule; -import org.springframework.context.annotation.Bean; - -public class RulesProvider { - private static final Logger LOG = Loggers.get(RulesProvider.class); - private static final String LOG_MSG = "Load server rules"; - - @Bean("Rules") - public Rules provide(RulesLoader ref) { - Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG); - List<Rule> loadedRules = ref.load(); - RulesBuilder builder = new RulesBuilder(); - - for (Rule r : loadedRules) { - NewRule newRule = builder.add(RuleKey.of(r.getRepository(), r.getKey())); - newRule.setName(r.getName()); - newRule.setInternalKey(r.getInternalKey()); - } - - profiler.stopInfo(); - return builder.build(); - } -} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java index 9cb9d8b509d..70f6b12ae6a 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/SpringProjectScanContainer.java @@ -21,6 +21,8 @@ package org.sonar.scanner.scan; import javax.annotation.Nullable; import javax.annotation.Priority; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.FileMetadata; import org.sonar.api.batch.fs.internal.SensorStrategy; @@ -29,8 +31,6 @@ import org.sonar.api.batch.sensor.issue.internal.DefaultNoSonarFilter; import org.sonar.api.resources.ResourceTypes; import org.sonar.api.scan.filesystem.PathResolver; import org.sonar.api.utils.MessageException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.sonar.core.config.ScannerProperties; import org.sonar.core.extension.CoreExtensionsInstaller; import org.sonar.core.language.LanguagesProvider; @@ -104,9 +104,7 @@ import org.sonar.scanner.repository.language.DefaultLanguagesRepository; import org.sonar.scanner.repository.settings.DefaultProjectSettingsLoader; import org.sonar.scanner.rule.ActiveRulesProvider; import org.sonar.scanner.rule.DefaultActiveRulesLoader; -import org.sonar.scanner.rule.DefaultRulesLoader; import org.sonar.scanner.rule.QProfileVerifier; -import org.sonar.scanner.rule.RulesProvider; import org.sonar.scanner.scan.branch.BranchConfiguration; import org.sonar.scanner.scan.branch.BranchConfigurationProvider; import org.sonar.scanner.scan.branch.BranchType; @@ -168,7 +166,6 @@ public class SpringProjectScanContainer extends SpringComponentContainer { ResourceTypes.class, ProjectReactorValidator.class, ProjectInfo.class, - new RulesProvider(), new BranchConfigurationProvider(), new ProjectBranchesProvider(), ProjectRepositoriesProvider.class, @@ -313,7 +310,6 @@ public class SpringProjectScanContainer extends SpringComponentContainer { add(SvnScmSupport.getObjects()); add(DefaultProjectSettingsLoader.class, - DefaultRulesLoader.class, DefaultActiveRulesLoader.class, DefaultQualityProfileLoader.class, DefaultProjectRepositoriesLoader.class); @@ -359,7 +355,6 @@ public class SpringProjectScanContainer extends SpringComponentContainer { getComponentByType(DeprecatedPropertiesWarningGenerator.class).execute(); - getComponentByType(ProjectFileIndexer.class).index(); // Log detected languages and their profiles after FS is indexed and languages detected diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java index 3e2880e7e41..d2cc612ad88 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java @@ -46,10 +46,8 @@ public class DefaultServerTest { assertThat(metadata.getVersion()).isEqualTo("2.2"); assertThat(metadata.getStartedAt()).isNotNull(); assertThat(metadata.getPublicRootUrl()).isEqualTo("http://foo.com"); - assertThat(metadata.getPermanentServerId()).isEqualTo("123"); assertThat(metadata.getContextPath()).isNull(); - assertThat(metadata.isSecured()).isFalse(); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/DefaultRulesLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/DefaultRulesLoaderTest.java deleted file mode 100644 index 15f63273ae7..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/DefaultRulesLoaderTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.scanner.rule; - -import com.google.common.io.ByteSource; -import com.google.common.io.Resources; -import java.io.IOException; -import java.io.InputStream; -import java.util.List; -import org.junit.Test; -import org.sonar.scanner.WsTestUtil; -import org.sonar.scanner.bootstrap.DefaultScannerWsClient; -import org.sonarqube.ws.Rules.ListResponse.Rule; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.Mockito.mock; - -public class DefaultRulesLoaderTest { - - @Test - public void testParseServerResponse() throws IOException { - DefaultScannerWsClient wsClient = mock(DefaultScannerWsClient.class); - InputStream is = Resources.asByteSource(this.getClass().getResource("DefaultRulesLoaderTest/response.protobuf")).openBufferedStream(); - WsTestUtil.mockStream(wsClient, is); - DefaultRulesLoader loader = new DefaultRulesLoader(wsClient); - List<Rule> ruleList = loader.load(); - assertThat(ruleList).hasSize(318); - } - - @Test - public void testError() throws IOException { - DefaultScannerWsClient wsClient = mock(DefaultScannerWsClient.class); - InputStream is = ByteSource.wrap("trash".getBytes()).openBufferedStream(); - WsTestUtil.mockStream(wsClient, is); - DefaultRulesLoader loader = new DefaultRulesLoader(wsClient); - - assertThatThrownBy(() -> loader.load()) - .isInstanceOf(IllegalStateException.class) - .hasMessage("Unable to get rules"); - } -} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/RulesProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/RulesProviderTest.java deleted file mode 100644 index cc9ba79bf8c..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/RulesProviderTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.scanner.rule; - -import com.google.common.collect.Lists; -import org.junit.Test; -import org.sonar.api.batch.rule.Rules; -import org.sonarqube.ws.Rules.ListResponse.Rule; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class RulesProviderTest { - @Test - public void testRuleTranslation() { - RulesLoader loader = mock(RulesLoader.class); - when(loader.load()).thenReturn(Lists.newArrayList(getTestRule())); - - RulesProvider provider = new RulesProvider(); - - Rules rules = provider.provide(loader); - - assertThat(rules.findAll()).hasSize(1); - assertRule(rules.findAll().iterator().next()); - } - - private static void assertRule(org.sonar.api.batch.rule.Rule r) { - Rule testRule = getTestRule(); - - assertThat(r.name()).isEqualTo(testRule.getName()); - assertThat(r.internalKey()).isEqualTo(testRule.getInternalKey()); - assertThat(r.key().rule()).isEqualTo(testRule.getKey()); - assertThat(r.key().repository()).isEqualTo(testRule.getRepository()); - } - - private static Rule getTestRule() { - Rule.Builder ruleBuilder = Rule.newBuilder(); - ruleBuilder.setKey("key1"); - ruleBuilder.setRepository("repo1"); - ruleBuilder.setName("name"); - ruleBuilder.setInternalKey("key1"); - return ruleBuilder.build(); - - } -} |