include 'tests:plugins:blue-green-plugin-v1'
include 'tests:plugins:blue-green-plugin-v2'
include 'tests:plugins:extension-lifecycle-plugin'
-include 'tests:plugins:fake-billing-plugin'
+include 'tests:plugins:core-extension-fake-billing'
include 'tests:plugins:core-extension-it-tests'
include 'tests:plugins:foo-plugin-v1'
include 'tests:plugins:foo-plugin-v2'
':tests:plugins:blue-green-plugin-v1',
':tests:plugins:blue-green-plugin-v2',
':tests:plugins:extension-lifecycle-plugin',
- ':tests:plugins:fake-billing-plugin',
+ ':tests:plugins:core-extension-fake-billing',
':tests:plugins:core-extension-it-tests',
':tests:plugins:foo-plugin-v1',
':tests:plugins:foo-plugin-v2',
--- /dev/null
+dependencies {
+ compileOnly project(path: ':sonar-plugin-api', configuration: 'shadow')
+ compileOnly project(':server:sonar-server')
+}
--- /dev/null
+/*
+ * 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.
+ */
+
+/*
+ * 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.SonarQubeSide;
+import org.sonar.core.extension.CoreExtension;
+
+import static org.sonar.api.SonarQubeSide.COMPUTE_ENGINE;
+import static org.sonar.api.SonarQubeSide.SERVER;
+
+public class FakeBillingCoreExtension implements CoreExtension {
+ @Override
+ public String getName() {
+ return "fake-billing";
+ }
+
+ @Override
+ public void load(Context context) {
+ SonarQubeSide sonarQubeSide = context.getRuntime().getSonarQubeSide();
+ // Nothing should be loaded when the plugin is running within by the scanner
+ if (sonarQubeSide == SERVER || sonarQubeSide == COMPUTE_ENGINE) {
+ context.addExtension(FakeBillingValidations.class);
+ }
+ }
+
+}
--- /dev/null
+/*
+ * 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.
+ */
+
+/*
+ * 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.Settings;
+import org.sonar.server.organization.BillingValidationsExtension;
+
+import static java.lang.String.format;
+
+public class FakeBillingValidations implements BillingValidationsExtension {
+
+ private static final String PREVENT_PROJECT_ANALYSIS_SETTING = "sonar.billing.preventProjectAnalysis";
+ private static final String PREVENT_UPDATING_PROJECTS_VISIBILITY_TO_PRIVATE_SETTING = "sonar.billing.preventUpdatingProjectsVisibilityToPrivate";
+
+ private final Settings settings;
+
+ public FakeBillingValidations(Settings settings) {
+ this.settings = settings;
+ }
+
+ @Override
+ public void checkOnProjectAnalysis(Organization organization) {
+ boolean preventProjectAnalysis = settings.getBoolean(PREVENT_PROJECT_ANALYSIS_SETTING);
+ if (preventProjectAnalysis) {
+ throw new BillingValidationsException(format("Organization %s cannot perform analysis", organization.getKey()));
+ }
+ }
+
+ @Override
+ public void checkCanUpdateProjectVisibility(Organization organization, boolean updateToPrivate) {
+ boolean preventUpdatingProjectsToPrivate = settings.getBoolean(PREVENT_UPDATING_PROJECTS_VISIBILITY_TO_PRIVATE_SETTING);
+ if (preventUpdatingProjectsToPrivate) {
+ throw new BillingValidationsException(format("Organization %s cannot use private project", organization.getKey()));
+ }
+ }
+
+ @Override
+ public boolean canUpdateProjectVisibilityToPrivate(Organization organization) {
+ if (!settings.hasKey(PREVENT_UPDATING_PROJECTS_VISIBILITY_TO_PRIVATE_SETTING)) {
+ return true;
+ }
+ return !settings.getBoolean(PREVENT_UPDATING_PROJECTS_VISIBILITY_TO_PRIVATE_SETTING);
+ }
+
+ @Override
+ public void onDelete(Organization organization) {
+ // do nothing
+ }
+}
--- /dev/null
+FakeBillingCoreExtension
--- /dev/null
+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
+++ /dev/null
-dependencies {
- compileOnly project(path: ':sonar-plugin-api', configuration: 'shadow')
- compileOnly project(':server:sonar-server')
-}
-
-jar {
- manifest {
- attributes(
- 'Plugin-Key': 'billing',
- 'Plugin-Version': version,
- 'Plugin-Class': 'FakeBillingPlugin',
- 'Plugin-ChildFirstClassLoader': 'false',
- 'Sonar-Version': version,
- 'SonarLint-Supported': 'false',
- 'Plugin-Name': 'Plugins :: Fake Billing Plugin',
- 'Plugin-License': 'GNU LGPL 3'
- )
- }
-}
+++ /dev/null
-/*
- * 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.
- */
-
-/*
- * 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 FakeBillingPlugin 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(FakeBillingValidations.class);
- }
- }
-
- private static boolean isRunningInSQ() {
- try {
- Class.forName("org.sonar.server.plugins.privileged.CoreExtensionBridge");
- return true;
- } catch (ClassNotFoundException e) {
- return false;
- }
- }
-}
+++ /dev/null
-/*
- * 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.
- */
-
-/*
- * 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.Settings;
-import org.sonar.server.organization.BillingValidationsExtension;
-
-import static java.lang.String.format;
-
-public class FakeBillingValidations implements BillingValidationsExtension {
-
- private static final String PREVENT_PROJECT_ANALYSIS_SETTING = "sonar.billing.preventProjectAnalysis";
- private static final String PREVENT_UPDATING_PROJECTS_VISIBILITY_TO_PRIVATE_SETTING = "sonar.billing.preventUpdatingProjectsVisibilityToPrivate";
-
- private final Settings settings;
-
- public FakeBillingValidations(Settings settings) {
- this.settings = settings;
- }
-
- @Override
- public void checkOnProjectAnalysis(Organization organization) {
- boolean preventProjectAnalysis = settings.getBoolean(PREVENT_PROJECT_ANALYSIS_SETTING);
- if (preventProjectAnalysis) {
- throw new BillingValidationsException(format("Organization %s cannot perform analysis", organization.getKey()));
- }
- }
-
- @Override
- public void checkCanUpdateProjectVisibility(Organization organization, boolean updateToPrivate) {
- boolean preventUpdatingProjectsToPrivate = settings.getBoolean(PREVENT_UPDATING_PROJECTS_VISIBILITY_TO_PRIVATE_SETTING);
- if (preventUpdatingProjectsToPrivate) {
- throw new BillingValidationsException(format("Organization %s cannot use private project", organization.getKey()));
- }
- }
-
- @Override
- public boolean canUpdateProjectVisibilityToPrivate(Organization organization) {
- if (!settings.hasKey(PREVENT_UPDATING_PROJECTS_VISIBILITY_TO_PRIVATE_SETTING)) {
- return true;
- }
- return !settings.getBoolean(PREVENT_UPDATING_PROJECTS_VISIBILITY_TO_PRIVATE_SETTING);
- }
-
- @Override
- public void onDelete(Organization organization) {
- // do nothing
- }
-}
+++ /dev/null
-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
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
-import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.qa.util.Tester;
import static util.ItUtils.newProjectKey;
import static util.ItUtils.projectDir;
-@Ignore("FIXME IT disabled because it relies on a privileged plugin (fake-billing-plugin)")
public class BillingTest {
private static final String PROPERTY_PREVENT_ANALYSIS = "sonar.billing.preventProjectAnalysis";
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
+import static util.ItUtils.installCoreExtension;
import static util.ItUtils.newOrchestratorBuilder;
import static util.ItUtils.pluginArtifact;
import static util.ItUtils.xooPlugin;
@ClassRule
public static final Orchestrator ORCHESTRATOR = newOrchestratorBuilder(
builder -> builder
-
.addPlugin(xooPlugin())
- .addPlugin(pluginArtifact("fake-billing-plugin"))
.addPlugin(pluginArtifact("ui-extensions-plugin"))
-
- .setServerProperty("sonar.sonarcloud.enabled", "true")
-
- );
+ .setServerProperty("sonar.sonarcloud.enabled", "true"),
+ server -> installCoreExtension(server, "core-extension-fake-billing"));
}