From ca183f7f3f45e1ae2338f3a5c37d44fc0e295111 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Fri, 22 Jun 2018 16:03:36 +0200 Subject: SONAR-10138 Remove support for API < 5.6 --- .../sonar/core/component/ComponentKeysTest.java | 9 --- .../sonar/core/issue/DefaultIssueBuilderTest.java | 78 --------------------- .../org/sonar/core/platform/PluginLoaderTest.java | 50 +------------ sonar-core/src/test/projects/base-plugin/pom.xml | 2 +- .../src/org/sonar/plugins/base/BasePlugin.java | 8 +-- .../target/base-plugin-0.1-SNAPSHOT.jar | Bin 3421 -> 3476 bytes .../src/test/projects/dependent-plugin/pom.xml | 2 +- .../sonar/plugins/dependent/DependentPlugin.java | 8 +-- .../target/dependent-plugin-0.1-SNAPSHOT.jar | Bin 3077 -> 3137 bytes 9 files changed, 11 insertions(+), 146 deletions(-) delete mode 100644 sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueBuilderTest.java (limited to 'sonar-core/src/test') diff --git a/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java b/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java index 43533c48dbb..3d7c0d6f193 100644 --- a/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java +++ b/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java @@ -26,10 +26,7 @@ import static org.mockito.Mockito.when; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.resources.Directory; -import org.sonar.api.resources.Project; public class ComponentKeysTest { @Rule @@ -37,12 +34,6 @@ public class ComponentKeysTest { @Test public void create_effective_key() { - Project project = new Project(ProjectDefinition.create().setKey("my_project")); - assertThat(ComponentKeys.createEffectiveKey("my_project", project)).isEqualTo("my_project"); - - Directory dir = Directory.create("src/org/foo"); - assertThat(ComponentKeys.createEffectiveKey("my_project", dir)).isEqualTo("my_project:src/org/foo"); - InputFile file = mock(InputFile.class); when(file.relativePath()).thenReturn("foo/Bar.php"); assertThat(ComponentKeys.createEffectiveKey("my_project", file)).isEqualTo("my_project:foo/Bar.php"); diff --git a/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueBuilderTest.java b/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueBuilderTest.java deleted file mode 100644 index 8c214f89873..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueBuilderTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 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.core.issue; - -import org.junit.Test; -import org.sonar.api.issue.Issue; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.rule.Severity; - -import static org.assertj.core.api.Assertions.assertThat; - -public class DefaultIssueBuilderTest { - - @Test - public void build_new_issue() { - String componentKey = "org.apache.struts:struts-core:Action.java"; - String projectKey = "org.apache.struts"; - DefaultIssue issue = (DefaultIssue) new DefaultIssueBuilder() - .componentKey(componentKey) - .projectKey(projectKey) - .message("the message") - .line(123) - .effortToFix(10000.0) - .ruleKey(RuleKey.of("squid", "NullDereference")) - .fromExternalRuleEngine(false) - .severity(Severity.CRITICAL) - .attribute("JIRA", "FOO-123") - .attribute("YOUTRACK", "YT-123") - .build(); - - assertThat(issue).isNotNull(); - assertThat(issue.key()).isNotNull(); - assertThat(issue.effortToFix()).isEqualTo(10000.0); - assertThat(issue.componentKey()).isEqualTo(componentKey); - assertThat(issue.projectKey()).isEqualTo(projectKey); - assertThat(issue.message()).isEqualTo("the message"); - assertThat(issue.line()).isEqualTo(123); - assertThat(issue.ruleKey().repository()).isEqualTo("squid"); - assertThat(issue.ruleKey().rule()).isEqualTo("NullDereference"); - assertThat(issue.isFromExternalRuleEngine()).isFalse(); - assertThat(issue.severity()).isEqualTo(Severity.CRITICAL); - assertThat(issue.assignee()).isNull(); - assertThat(issue.isNew()).isTrue(); - assertThat(issue.resolution()).isNull(); - assertThat(issue.status()).isEqualTo(Issue.STATUS_OPEN); - assertThat(issue.attribute("JIRA")).isEqualTo("FOO-123"); - assertThat(issue.attribute("YOUTRACK")).isEqualTo("YT-123"); - assertThat(issue.attributes()).hasSize(2); - } - - @Test - public void not_set_default_severity() { - DefaultIssue issue = (DefaultIssue) new DefaultIssueBuilder() - .componentKey("Action.java") - .projectKey("org.apache.struts") - .ruleKey(RuleKey.of("squid", "NullDereference")) - .build(); - - assertThat(issue.severity()).isNull(); - } -} diff --git a/sonar-core/src/test/java/org/sonar/core/platform/PluginLoaderTest.java b/sonar-core/src/test/java/org/sonar/core/platform/PluginLoaderTest.java index 432296e40fc..76a1268f933 100644 --- a/sonar-core/src/test/java/org/sonar/core/platform/PluginLoaderTest.java +++ b/sonar-core/src/test/java/org/sonar/core/platform/PluginLoaderTest.java @@ -24,19 +24,14 @@ import java.io.File; import java.io.IOException; import java.util.Collection; import java.util.Collections; -import java.util.List; -import java.util.Map; import org.assertj.core.data.MapEntry; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import org.sonar.api.Plugin; -import org.sonar.api.SonarPlugin; import org.sonar.updatecenter.common.Version; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; -import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; public class PluginLoaderTest { @@ -47,29 +42,6 @@ public class PluginLoaderTest { private PluginClassloaderFactory classloaderFactory = mock(PluginClassloaderFactory.class); private PluginLoader loader = new PluginLoader(new FakePluginExploder(), classloaderFactory); - @Test - public void instantiate_plugin_entry_point() { - PluginClassLoaderDef def = new PluginClassLoaderDef("fake"); - def.addMainClass("fake", FakePlugin.class.getName()); - - Map instances = loader.instantiatePluginClasses(ImmutableMap.of(def, getClass().getClassLoader())); - assertThat(instances).containsOnlyKeys("fake"); - assertThat(instances.get("fake")).isInstanceOf(FakePlugin.class); - } - - @Test - public void plugin_entry_point_must_be_no_arg_public() { - PluginClassLoaderDef def = new PluginClassLoaderDef("fake"); - def.addMainClass("fake", IncorrectPlugin.class.getName()); - - try { - loader.instantiatePluginClasses(ImmutableMap.of(def, getClass().getClassLoader())); - fail(); - } catch (IllegalStateException e) { - assertThat(e).hasMessage("Fail to instantiate class [org.sonar.core.platform.PluginLoaderTest$IncorrectPlugin] of plugin [fake]"); - } - } - @Test public void define_classloader() throws Exception { File jarFile = temp.newFile(); @@ -172,27 +144,7 @@ public class PluginLoaderTest { private static class FakePluginExploder extends PluginJarExploder { @Override public ExplodedPlugin explode(PluginInfo info) { - return new ExplodedPlugin(info.getKey(), info.getNonNullJarFile(), Collections.emptyList()); - } - } - - public static class FakePlugin extends SonarPlugin { - @Override - public List getExtensions() { - return Collections.emptyList(); - } - } - - /** - * No public empty-param constructor - */ - public static class IncorrectPlugin extends SonarPlugin { - public IncorrectPlugin(String s) { - } - - @Override - public List getExtensions() { - return Collections.emptyList(); + return new ExplodedPlugin(info.getKey(), info.getNonNullJarFile(), Collections.emptyList()); } } } diff --git a/sonar-core/src/test/projects/base-plugin/pom.xml b/sonar-core/src/test/projects/base-plugin/pom.xml index 484d5b78dea..95c772b15c4 100644 --- a/sonar-core/src/test/projects/base-plugin/pom.xml +++ b/sonar-core/src/test/projects/base-plugin/pom.xml @@ -13,7 +13,7 @@ org.sonarsource.sonarqube sonar-plugin-api - 5.2-SNAPSHOT + 7.2-SNAPSHOT provided diff --git a/sonar-core/src/test/projects/base-plugin/src/org/sonar/plugins/base/BasePlugin.java b/sonar-core/src/test/projects/base-plugin/src/org/sonar/plugins/base/BasePlugin.java index 6afa10ce96c..d6619367f09 100644 --- a/sonar-core/src/test/projects/base-plugin/src/org/sonar/plugins/base/BasePlugin.java +++ b/sonar-core/src/test/projects/base-plugin/src/org/sonar/plugins/base/BasePlugin.java @@ -2,11 +2,11 @@ package org.sonar.plugins.base; import java.util.Collections; import java.util.List; -import org.sonar.api.SonarPlugin; +import org.sonar.api.Plugin; -public class BasePlugin extends SonarPlugin { +public class BasePlugin implements Plugin { + + public void define(Plugin.Context context) { - public List getExtensions() { - return Collections.emptyList(); } } diff --git a/sonar-core/src/test/projects/base-plugin/target/base-plugin-0.1-SNAPSHOT.jar b/sonar-core/src/test/projects/base-plugin/target/base-plugin-0.1-SNAPSHOT.jar index c2bdb08c95c..87f9e2899cd 100644 Binary files a/sonar-core/src/test/projects/base-plugin/target/base-plugin-0.1-SNAPSHOT.jar and b/sonar-core/src/test/projects/base-plugin/target/base-plugin-0.1-SNAPSHOT.jar differ diff --git a/sonar-core/src/test/projects/dependent-plugin/pom.xml b/sonar-core/src/test/projects/dependent-plugin/pom.xml index dcb4754e3fc..9bd5580863d 100644 --- a/sonar-core/src/test/projects/dependent-plugin/pom.xml +++ b/sonar-core/src/test/projects/dependent-plugin/pom.xml @@ -13,7 +13,7 @@ org.sonarsource.sonarqube sonar-plugin-api - 5.2-SNAPSHOT + 7.2-SNAPSHOT provided diff --git a/sonar-core/src/test/projects/dependent-plugin/src/org/sonar/plugins/dependent/DependentPlugin.java b/sonar-core/src/test/projects/dependent-plugin/src/org/sonar/plugins/dependent/DependentPlugin.java index 2b7783ae4fe..907a09ee83f 100644 --- a/sonar-core/src/test/projects/dependent-plugin/src/org/sonar/plugins/dependent/DependentPlugin.java +++ b/sonar-core/src/test/projects/dependent-plugin/src/org/sonar/plugins/dependent/DependentPlugin.java @@ -2,17 +2,17 @@ package org.sonar.plugins.dependent; import java.util.Collections; import java.util.List; -import org.sonar.api.SonarPlugin; +import org.sonar.api.Plugin; import org.sonar.plugins.base.api.BaseApi; -public class DependentPlugin extends SonarPlugin { +public class DependentPlugin implements Plugin { public DependentPlugin() { // uses a class that is exported by base-plugin new BaseApi().doNothing(); } - public List getExtensions() { - return Collections.emptyList(); + public void define(Plugin.Context context) { + } } diff --git a/sonar-core/src/test/projects/dependent-plugin/target/dependent-plugin-0.1-SNAPSHOT.jar b/sonar-core/src/test/projects/dependent-plugin/target/dependent-plugin-0.1-SNAPSHOT.jar index b828a8c6386..81b8475944e 100644 Binary files a/sonar-core/src/test/projects/dependent-plugin/target/dependent-plugin-0.1-SNAPSHOT.jar and b/sonar-core/src/test/projects/dependent-plugin/target/dependent-plugin-0.1-SNAPSHOT.jar differ -- cgit v1.2.3