]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10690 make fake-billing-plugin a core extension
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 7 Jun 2018 15:24:49 +0000 (17:24 +0200)
committerSonarTech <sonartech@sonarsource.com>
Tue, 12 Jun 2018 18:21:04 +0000 (20:21 +0200)
13 files changed:
settings.gradle
tests/build.gradle
tests/plugins/core-extension-fake-billing/build.gradle [new file with mode: 0644]
tests/plugins/core-extension-fake-billing/src/main/java/FakeBillingCoreExtension.java [new file with mode: 0644]
tests/plugins/core-extension-fake-billing/src/main/java/FakeBillingValidations.java [new file with mode: 0644]
tests/plugins/core-extension-fake-billing/src/main/resources/META-INF/services/org.sonar.core.extension.CoreExtension [new file with mode: 0644]
tests/plugins/core-extension-fake-billing/src/main/resources/org/sonar/l10n/billing.properties [new file with mode: 0644]
tests/plugins/fake-billing-plugin/build.gradle [deleted file]
tests/plugins/fake-billing-plugin/src/main/java/FakeBillingPlugin.java [deleted file]
tests/plugins/fake-billing-plugin/src/main/java/FakeBillingValidations.java [deleted file]
tests/plugins/fake-billing-plugin/src/main/resources/org/sonar/l10n/billing.properties [deleted file]
tests/src/test/java/org/sonarqube/tests/organization/BillingTest.java
tests/src/test/java/org/sonarqube/tests/organization/OrganizationSuite.java

index 10d2f7309416ecb51235ca74c734fa933ead9536..c94cf11a2d10087fc6837e1b56127b470fec71e7 100644 (file)
@@ -40,7 +40,7 @@ include 'tests:plugins:batch-plugin'
 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'
index da55a4f03cf0438dc5b9319427d8a5395aba6cee..fc5da403ddbcab650c9b85b8e10a0dc03cb4e31d 100644 (file)
@@ -19,7 +19,7 @@ def pluginsForITs = [
     ':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',
diff --git a/tests/plugins/core-extension-fake-billing/build.gradle b/tests/plugins/core-extension-fake-billing/build.gradle
new file mode 100644 (file)
index 0000000..3dc8a90
--- /dev/null
@@ -0,0 +1,4 @@
+dependencies {
+  compileOnly project(path: ':sonar-plugin-api', configuration: 'shadow')
+  compileOnly project(':server:sonar-server')
+}
diff --git a/tests/plugins/core-extension-fake-billing/src/main/java/FakeBillingCoreExtension.java b/tests/plugins/core-extension-fake-billing/src/main/java/FakeBillingCoreExtension.java
new file mode 100644 (file)
index 0000000..6ef26f7
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * 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);
+    }
+  }
+
+}
diff --git a/tests/plugins/core-extension-fake-billing/src/main/java/FakeBillingValidations.java b/tests/plugins/core-extension-fake-billing/src/main/java/FakeBillingValidations.java
new file mode 100644 (file)
index 0000000..16c178c
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * 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
+  }
+}
diff --git a/tests/plugins/core-extension-fake-billing/src/main/resources/META-INF/services/org.sonar.core.extension.CoreExtension b/tests/plugins/core-extension-fake-billing/src/main/resources/META-INF/services/org.sonar.core.extension.CoreExtension
new file mode 100644 (file)
index 0000000..f8adf89
--- /dev/null
@@ -0,0 +1 @@
+FakeBillingCoreExtension
diff --git a/tests/plugins/core-extension-fake-billing/src/main/resources/org/sonar/l10n/billing.properties b/tests/plugins/core-extension-fake-billing/src/main/resources/org/sonar/l10n/billing.properties
new file mode 100644 (file)
index 0000000..f8ac8fc
--- /dev/null
@@ -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/fake-billing-plugin/build.gradle b/tests/plugins/fake-billing-plugin/build.gradle
deleted file mode 100644 (file)
index 47f55fe..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-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'
-    )
-  }
-}
diff --git a/tests/plugins/fake-billing-plugin/src/main/java/FakeBillingPlugin.java b/tests/plugins/fake-billing-plugin/src/main/java/FakeBillingPlugin.java
deleted file mode 100644 (file)
index 97a4e80..0000000
+++ /dev/null
@@ -1,61 +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.
- */
-
-/*
- * 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;
-    }
-  }
-}
diff --git a/tests/plugins/fake-billing-plugin/src/main/java/FakeBillingValidations.java b/tests/plugins/fake-billing-plugin/src/main/java/FakeBillingValidations.java
deleted file mode 100644 (file)
index 16c178c..0000000
+++ /dev/null
@@ -1,85 +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.
- */
-
-/*
- * 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
-  }
-}
diff --git a/tests/plugins/fake-billing-plugin/src/main/resources/org/sonar/l10n/billing.properties b/tests/plugins/fake-billing-plugin/src/main/resources/org/sonar/l10n/billing.properties
deleted file mode 100644 (file)
index f8ac8fc..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-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
index 713762a7e2d0fa841c5d96770a72725739215695..a66254b5ebd4309ab54c6c319744ddbf1bcbc354 100644 (file)
@@ -25,7 +25,6 @@ import com.sonar.orchestrator.build.SonarScanner;
 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;
@@ -46,7 +45,6 @@ import static util.ItUtils.expectHttpError;
 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";
index a2b6c311e4377834a934271181756a1ebb57769a..0d2d51231e24a8d5f2cef717bbe1b97e3f4a10f1 100644 (file)
@@ -24,6 +24,7 @@ import org.junit.ClassRule;
 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;
@@ -43,12 +44,8 @@ public class OrganizationSuite {
   @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"));
 }