import org.sonar.api.utils.System2;
import org.sonar.api.utils.UriReader;
import org.sonar.api.utils.Version;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.ce.CeConfigurationModule;
import org.sonar.ce.CeDistributedInformationImpl;
import org.sonar.ce.CeHttpModule;
import org.sonar.ce.user.CeUserSession;
import org.sonar.core.component.DefaultResourceTypes;
import org.sonar.core.config.CorePropertyDefinitions;
+import org.sonar.core.extension.CoreExtensionRepositoryImpl;
+import org.sonar.core.extension.CoreExtensionsInstaller;
+import org.sonar.core.extension.CoreExtensionsLoader;
import org.sonar.core.i18n.RuleI18nManager;
import org.sonar.core.platform.ComponentContainer;
+import org.sonar.core.platform.EditionProvider;
import org.sonar.core.platform.Module;
+import org.sonar.core.platform.PlatformEditionProvider;
import org.sonar.core.platform.PluginClassloaderFactory;
import org.sonar.core.platform.PluginLoader;
import org.sonar.core.timemachine.Periods;
import org.sonar.server.es.EsModule;
import org.sonar.server.es.ProjectIndexersImpl;
import org.sonar.server.event.NewAlerts;
-import org.sonar.core.extension.CoreExtensionRepositoryImpl;
-import org.sonar.core.extension.CoreExtensionsInstaller;
-import org.sonar.core.extension.CoreExtensionsLoader;
import org.sonar.server.favorite.FavoriteUpdater;
import org.sonar.server.issue.IssueFieldsSetter;
import org.sonar.server.issue.index.IssueIndex;
CoreExtensionsInstaller coreExtensionsInstaller = this.level4.getComponentByType(CECoreExtensionsInstaller.class);
coreExtensionsInstaller.install(this.level4, t -> true);
this.level4.startComponents();
+ PlatformEditionProvider editionProvider = this.level4.getComponentByType(PlatformEditionProvider.class);
+ Loggers.get(ComputeEngineContainerImpl.class)
+ .info("Running {} edition", editionProvider.get().map(EditionProvider.Edition::getLabel).orElse(""));
startupTasks();
// System
ServerLogging.class,
+ // SonarSource editions
+ PlatformEditionProvider.class,
+
// privileged plugins
CECoreExtensionsInstaller.class,
PrivilegedPluginsBootstraper.class,
assertThat(picoContainer.getComponentAdapters())
.hasSize(
CONTAINER_ITSELF
- + 84 // level 4
+ + 85 // level 4
+ 21 // content of QualityGateModule
+ 6 // content of CeConfigurationModule
+ 4 // content of CeQueueModule
import org.sonar.core.component.DefaultResourceTypes;
import org.sonar.core.extension.CoreExtensionsInstaller;
import org.sonar.core.platform.ComponentContainer;
+import org.sonar.core.platform.PlatformEditionProvider;
import org.sonar.core.timemachine.Periods;
import org.sonar.server.authentication.AuthenticationModule;
import org.sonar.server.authentication.LogOAuthWarning;
CeModule.class,
CeWsModule.class,
+ // SonarSource editions
+ PlatformEditionProvider.class,
+
InternalPropertiesImpl.class,
ProjectConfigurationFactory.class,
*/
package org.sonar.server.platform.platformlevel;
+import org.sonar.api.utils.log.Loggers;
+import org.sonar.core.platform.EditionProvider;
+import org.sonar.core.platform.PlatformEditionProvider;
import org.sonar.server.app.ProcessCommandWrapper;
import org.sonar.server.es.IndexerStartupTask;
import org.sonar.server.organization.DefaultOrganizationEnforcer;
get(ServerLifecycleNotifier.class).notifyStart();
get(ProcessCommandWrapper.class).notifyOperational();
get(WebServerRuleFinder.class).stopCaching();
+ Loggers.get(PlatformLevelStartup.class)
+ .info("Running {} Edition", get(PlatformEditionProvider.class).get().map(EditionProvider.Edition::getLabel).orElse(""));
}
});
--- /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.
+ */
+package org.sonar.core.platform;
+
+import java.util.Optional;
+import org.sonar.api.ce.ComputeEngineSide;
+import org.sonar.api.server.ServerSide;
+
+@ServerSide
+@ComputeEngineSide
+public interface EditionProvider {
+ enum Edition {
+ COMMUNITY("Community"),
+ DEVELOPER("Developer"),
+ ENTERPRISE("Enterprise"),
+ DATA_CENTER("Data Center");
+
+ private final String label;
+
+ Edition(String label) {
+ this.label = label;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+ }
+
+ Optional<Edition> get();
+}
--- /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.
+ */
+package org.sonar.core.platform;
+
+import java.util.Optional;
+
+import static com.google.common.base.Preconditions.checkState;
+import static org.sonar.core.platform.EditionProvider.Edition.COMMUNITY;
+
+public class PlatformEditionProvider implements EditionProvider {
+ private static final EditionProvider[] NO_OTHER_PROVIDERS = new EditionProvider[0];
+ private final EditionProvider[] otherEditionProviders;
+
+ public PlatformEditionProvider() {
+ this(NO_OTHER_PROVIDERS);
+ }
+
+ public PlatformEditionProvider(EditionProvider[] otherEditionProviders) {
+ this.otherEditionProviders = otherEditionProviders;
+ }
+
+ @Override
+ public Optional<Edition> get() {
+ checkState(otherEditionProviders.length <= 1, "There can't be more than 1 other EditionProvider");
+ if (otherEditionProviders.length == 1) {
+ return otherEditionProviders[0].get();
+ }
+ return Optional.of(COMMUNITY);
+ }
+}
--- /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.
+ */
+package org.sonar.core.platform;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static java.util.Optional.of;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.core.platform.EditionProvider.Edition.COMMUNITY;
+import static org.sonar.core.platform.EditionProvider.Edition.DATA_CENTER;
+import static org.sonar.core.platform.EditionProvider.Edition.DEVELOPER;
+
+public class PlatformEditionProviderTest {
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Test
+ public void returns_COMMUNITY_when_there_is_no_other_EditionProvider() {
+ ComponentContainer container = new ComponentContainer();
+ ComponentContainer child = new ComponentContainer(container);
+ child.add(PlatformEditionProvider.class);
+
+ assertThat(container.getComponentByType(PlatformEditionProvider.class)).isNull();
+ PlatformEditionProvider platformEditionProvider = child.getComponentByType(PlatformEditionProvider.class);
+ assertThat(platformEditionProvider.get()).contains(COMMUNITY);
+ }
+
+ @Test
+ public void returns_edition_from_other_EditionProvider_in_any_container() {
+ ComponentContainer container = new ComponentContainer();
+ container.add((EditionProvider) () -> of(DATA_CENTER));
+ ComponentContainer child = new ComponentContainer(container);
+ child.add(PlatformEditionProvider.class);
+
+ assertThat(container.getComponentByType(PlatformEditionProvider.class)).isNull();
+ PlatformEditionProvider platformEditionProvider = child.getComponentByType(PlatformEditionProvider.class);
+ assertThat(platformEditionProvider.get()).contains(DATA_CENTER);
+ }
+
+ @Test
+ public void get_fails_with_ISE_if_there_is_more_than_one_other_EditionProvider_in_any_container() {
+ ComponentContainer container = new ComponentContainer();
+ container.add((EditionProvider) () -> of(DATA_CENTER));
+ ComponentContainer child = new ComponentContainer(container);
+ child.add((EditionProvider) () -> of(DEVELOPER));
+ child.add(PlatformEditionProvider.class);
+
+ assertThat(container.getComponentByType(PlatformEditionProvider.class)).isNull();
+ PlatformEditionProvider platformEditionProvider = child.getComponentByType(PlatformEditionProvider.class);
+
+ expectedException.expect(IllegalStateException.class);
+ expectedException.expectMessage("There can't be more than 1 other EditionProvider");
+
+ platformEditionProvider.get();
+ }
+}