From dc3144cba269380b55d015a57b03e4e466bd091d Mon Sep 17 00:00:00 2001 From: Sébastien Lesaint Date: Wed, 5 Jul 2017 14:30:14 +0200 Subject: SONAR-9507 add IT --- tests/plugins/fake-governance-plugin/pom.xml | 44 ++++++++++++++++++++++ .../src/main/java/FakeGovernancePlugin.java | 42 +++++++++++++++++++++ .../src/main/java/FakeWorkerCountProviderImpl.java | 40 ++++++++++++++++++++ .../resources/org/sonar/l10n/billing.properties | 2 + tests/plugins/pom.xml | 1 + 5 files changed, 129 insertions(+) create mode 100644 tests/plugins/fake-governance-plugin/pom.xml create mode 100644 tests/plugins/fake-governance-plugin/src/main/java/FakeGovernancePlugin.java create mode 100644 tests/plugins/fake-governance-plugin/src/main/java/FakeWorkerCountProviderImpl.java create mode 100644 tests/plugins/fake-governance-plugin/src/main/resources/org/sonar/l10n/billing.properties (limited to 'tests/plugins') diff --git a/tests/plugins/fake-governance-plugin/pom.xml b/tests/plugins/fake-governance-plugin/pom.xml new file mode 100644 index 00000000000..7f81da99349 --- /dev/null +++ b/tests/plugins/fake-governance-plugin/pom.xml @@ -0,0 +1,44 @@ + + + 4.0.0 + + + org.sonarsource.sonarqube.tests + plugins + 6.5-SNAPSHOT + + + fake-governance-plugin + sonar-plugin + Plugins :: Fake Governance Plugin + + + + org.sonarsource.sonarqube + sonar-plugin-api + ${project.version} + provided + + + org.sonarsource.sonarqube + sonar-server + ${project.version} + provided + + + + + + + org.sonarsource.sonar-packaging-maven-plugin + sonar-packaging-maven-plugin + 1.15 + true + + FakeGovernancePlugin + governance + + + + + diff --git a/tests/plugins/fake-governance-plugin/src/main/java/FakeGovernancePlugin.java b/tests/plugins/fake-governance-plugin/src/main/java/FakeGovernancePlugin.java new file mode 100644 index 00000000000..2d9c47cc854 --- /dev/null +++ b/tests/plugins/fake-governance-plugin/src/main/java/FakeGovernancePlugin.java @@ -0,0 +1,42 @@ + +/* + * SonarQube + * Copyright (C) 2009-2017 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. + */ + +import org.sonar.api.Plugin; + +public class FakeGovernancePlugin implements Plugin { + + @Override + public void define(Context context) { + // Nothing should be loaded when the plugin is running within by the scanner + if (isRunningInSQ()) { + context.addExtension(FakeWorkerCountProviderImpl.class); + } + } + + private static boolean isRunningInSQ() { + try { + Class.forName("org.sonar.plugin.PrivilegedPluginBridge"); + return true; + } catch (ClassNotFoundException e) { + return false; + } + } +} diff --git a/tests/plugins/fake-governance-plugin/src/main/java/FakeWorkerCountProviderImpl.java b/tests/plugins/fake-governance-plugin/src/main/java/FakeWorkerCountProviderImpl.java new file mode 100644 index 00000000000..ad737c42eb0 --- /dev/null +++ b/tests/plugins/fake-governance-plugin/src/main/java/FakeWorkerCountProviderImpl.java @@ -0,0 +1,40 @@ + +/* + * SonarQube + * Copyright (C) 2009-2017 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. + */ + +import org.sonar.api.config.Configuration; +import org.sonar.ce.configuration.WorkerCountProvider; + +public class FakeWorkerCountProviderImpl implements WorkerCountProvider { + + private static final String PROPERTY_WORKER_COUNT = "fakeGovernance.workerCount"; + + private final Configuration configuration; + + public FakeWorkerCountProviderImpl(Configuration configuration) { + this.configuration = configuration; + } + + @Override + public int get() { + return configuration.get(PROPERTY_WORKER_COUNT).map(Integer::valueOf).orElse(1); + } + +} diff --git a/tests/plugins/fake-governance-plugin/src/main/resources/org/sonar/l10n/billing.properties b/tests/plugins/fake-governance-plugin/src/main/resources/org/sonar/l10n/billing.properties new file mode 100644 index 00000000000..f8ac8fcaef5 --- /dev/null +++ b/tests/plugins/fake-governance-plugin/src/main/resources/org/sonar/l10n/billing.properties @@ -0,0 +1,2 @@ +billing.upgrade_box.header=The fake billing plugin is installed +billing.upgrade_box.text=It shows how to change the wording and hide the "Upgrade" button. \ No newline at end of file diff --git a/tests/plugins/pom.xml b/tests/plugins/pom.xml index 52aa4a5d611..b5f3af0d112 100644 --- a/tests/plugins/pom.xml +++ b/tests/plugins/pom.xml @@ -41,6 +41,7 @@ batch-plugin extension-lifecycle-plugin fake-billing-plugin + fake-governance-plugin foo-plugin-v1 foo-plugin-v2 global-property-change-plugin -- cgit v1.2.3