--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 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.server.platform;
+
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.measure.SumNclocDbQuery;
+
+public class StatisticsSupport {
+
+ private final DbClient dbClient;
+
+ public StatisticsSupport(DbClient dbClient) {
+ this.dbClient = dbClient;
+ }
+
+ public long getLinesOfCode(){
+ try (DbSession dbSession = dbClient.openSession(false)) {
+ SumNclocDbQuery query = SumNclocDbQuery.builder()
+ .setOnlyPrivateProjects(false)
+ .build();
+ return dbClient.liveMeasureDao().sumNclocOfBiggestBranch(dbSession, query);
+ }
+ }
+}
import org.sonar.server.platform.monitoring.PluginsSection;
import org.sonar.server.platform.monitoring.SettingsSection;
import org.sonar.server.platform.monitoring.StandaloneSystemSection;
-import org.sonar.server.platform.monitoring.StatisticsSystemSection;
import org.sonar.server.platform.monitoring.cluster.AppNodesInfoLoaderImpl;
import org.sonar.server.platform.monitoring.cluster.CeQueueGlobalSection;
import org.sonar.server.platform.monitoring.cluster.EsClusterStateSection;
AlmConfigurationSection.class,
ServerPushSection.class,
BundledSection.class,
- StatisticsSystemSection.class
-
+ StatisticsSupport.class
);
if (standalone) {
add(
import org.sonar.server.log.ServerLogging;
import org.sonar.server.platform.DockerSupport;
import org.sonar.server.platform.OfficialDistribution;
+import org.sonar.server.platform.StatisticsSupport;
import org.sonar.server.user.SecurityRealmFactory;
import static org.sonar.api.CoreProperties.CORE_FORCE_AUTHENTICATION_DEFAULT_VALUE;
+import static org.sonar.api.measures.CoreMetrics.NCLOC;
import static org.sonar.process.ProcessProperties.Property.PATH_DATA;
import static org.sonar.process.ProcessProperties.Property.PATH_HOME;
import static org.sonar.process.ProcessProperties.Property.PATH_TEMP;
private final ServerLogging serverLogging;
private final OfficialDistribution officialDistribution;
private final DockerSupport dockerSupport;
+ private final StatisticsSupport statisticsSupport;
private final SonarRuntime sonarRuntime;
public StandaloneSystemSection(Configuration config, SecurityRealmFactory securityRealmFactory,
IdentityProviderRepository identityProviderRepository, Server server, ServerLogging serverLogging,
- OfficialDistribution officialDistribution, DockerSupport dockerSupport, SonarRuntime sonarRuntime) {
+ OfficialDistribution officialDistribution, DockerSupport dockerSupport, StatisticsSupport statisticsSupport, SonarRuntime sonarRuntime) {
this.config = config;
this.securityRealmFactory = securityRealmFactory;
this.identityProviderRepository = identityProviderRepository;
this.serverLogging = serverLogging;
this.officialDistribution = officialDistribution;
this.dockerSupport = dockerSupport;
+ this.statisticsSupport = statisticsSupport;
this.sonarRuntime = sonarRuntime;
}
setAttribute(protobuf, "Server ID", server.getId());
setAttribute(protobuf, "Version", getVersion());
setAttribute(protobuf, "Edition", sonarRuntime.getEdition().getLabel());
+ setAttribute(protobuf, NCLOC.getName(), statisticsSupport.getLinesOfCode());
setAttribute(protobuf, "Docker", dockerSupport.isRunningInDocker());
setAttribute(protobuf, "External User Authentication", getExternalUserAuthentication());
addIfNotEmpty(protobuf, "Accepted external identity providers", getEnabledIdentityProviders());
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2022 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.server.platform.monitoring;
-
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
-import org.sonar.db.measure.SumNclocDbQuery;
-import org.sonar.process.systeminfo.SystemInfoSection;
-import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
-
-import static org.sonar.process.systeminfo.SystemInfoUtils.setAttribute;
-
-public class StatisticsSystemSection implements SystemInfoSection {
-
- private final DbClient dbClient;
-
- public StatisticsSystemSection(DbClient dbClient) {
- this.dbClient = dbClient;
- }
-
- @Override
- public ProtobufSystemInfo.Section toProtobuf() {
- ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder();
-
- protobuf.setName("Statistics");
- setAttribute(protobuf, "loc", getLoc());
-
- return protobuf.build();
- }
-
- private long getLoc(){
- try (DbSession dbSession = dbClient.openSession(false)) {
- SumNclocDbQuery query = SumNclocDbQuery.builder()
- .setOnlyPrivateProjects(false)
- .build();
- return dbClient.liveMeasureDao().sumNclocOfBiggestBranch(dbSession, query);
- }
- }
-
-}
import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
import org.sonar.server.authentication.IdentityProviderRepository;
import org.sonar.server.platform.DockerSupport;
+import org.sonar.server.platform.StatisticsSupport;
import org.sonar.server.user.SecurityRealmFactory;
import static org.sonar.api.CoreProperties.CORE_FORCE_AUTHENTICATION_DEFAULT_VALUE;
+import static org.sonar.api.measures.CoreMetrics.NCLOC;
import static org.sonar.process.systeminfo.SystemInfoUtils.setAttribute;
@ServerSide
private final SecurityRealmFactory securityRealmFactory;
private final IdentityProviderRepository identityProviderRepository;
private final DockerSupport dockerSupport;
+ private final StatisticsSupport statisticsSupport;
private final SonarRuntime sonarRuntime;
public GlobalSystemSection(Configuration config, Server server, SecurityRealmFactory securityRealmFactory,
- IdentityProviderRepository identityProviderRepository, DockerSupport dockerSupport, SonarRuntime sonarRuntime) {
+ IdentityProviderRepository identityProviderRepository, DockerSupport dockerSupport, StatisticsSupport statisticsSupport, SonarRuntime sonarRuntime) {
this.config = config;
this.server = server;
this.securityRealmFactory = securityRealmFactory;
this.identityProviderRepository = identityProviderRepository;
this.dockerSupport = dockerSupport;
+ this.statisticsSupport = statisticsSupport;
this.sonarRuntime = sonarRuntime;
}
setAttribute(protobuf, "Server ID", server.getId());
setAttribute(protobuf, "Edition", sonarRuntime.getEdition().getLabel());
+ setAttribute(protobuf, NCLOC.getName() ,statisticsSupport.getLinesOfCode());
setAttribute(protobuf, "Docker", dockerSupport.isRunningInDocker());
setAttribute(protobuf, "High Availability", true);
setAttribute(protobuf, "External User Authentication", getExternalUserAuthentication());
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 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.server.platform;
+
+import org.junit.Test;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.measure.SumNclocDbQuery;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class StatisticsSupportTest {
+
+ private final DbClient dbClient = mock(DbClient.class, RETURNS_DEEP_STUBS);
+ private final StatisticsSupport statisticsSupport = new StatisticsSupport(dbClient);
+
+ @Test
+ public void should_return_metric_from_liveMeasureDao() {
+ when(dbClient.liveMeasureDao().sumNclocOfBiggestBranch(any(DbSession.class), any(SumNclocDbQuery.class))).thenReturn(1800999L);
+
+ long linesOfCode = statisticsSupport.getLinesOfCode();
+
+ assertThat(linesOfCode).isEqualTo(1800999L);
+ }
+
+}
\ No newline at end of file
import org.sonar.server.log.ServerLogging;
import org.sonar.server.platform.DockerSupport;
import org.sonar.server.platform.OfficialDistribution;
+import org.sonar.server.platform.StatisticsSupport;
import org.sonar.server.user.SecurityRealmFactory;
import static org.assertj.core.api.Assertions.assertThat;
private SecurityRealmFactory securityRealmFactory = mock(SecurityRealmFactory.class);
private OfficialDistribution officialDistribution = mock(OfficialDistribution.class);
private DockerSupport dockerSupport = mock(DockerSupport.class);
+ private StatisticsSupport statisticsSupport = mock(StatisticsSupport.class);
private SonarRuntime sonarRuntime = mock(SonarRuntime.class);
private StandaloneSystemSection underTest = new StandaloneSystemSection(settings.asConfig(), securityRealmFactory, identityProviderRepository, server,
- serverLogging, officialDistribution, dockerSupport, sonarRuntime);
+ serverLogging, officialDistribution, dockerSupport, statisticsSupport, sonarRuntime);
@Before
public void setUp() {
assertThatAttributeIs(protobuf, "Force authentication", false);
}
+ @Test
+ public void return_Lines_of_Codes_from_StatisticsSupport(){
+ when(statisticsSupport.getLinesOfCode()).thenReturn(17752L);
+ ProtobufSystemInfo.Section protobuf = underTest.toProtobuf();
+ assertThatAttributeIs(protobuf,"Lines of Code", 17752L);
+ }
+
@Test
@UseDataProvider("trueOrFalse")
public void return_docker_flag_from_DockerSupport(boolean flag) {
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2022 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.server.platform.monitoring;
-
-import org.junit.Test;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
-import org.sonar.db.measure.SumNclocDbQuery;
-import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.sonar.process.systeminfo.SystemInfoUtils.attribute;
-
-
-public class StatisticsSystemSectionTest {
-
- private DbClient dbClient = mock(DbClient.class, RETURNS_DEEP_STUBS);
-
- private final StatisticsSystemSection statisticsSystemSection = new StatisticsSystemSection(dbClient);
-
- @Test
- public void shouldWriteProtobuf() {
-
- when(dbClient.liveMeasureDao().sumNclocOfBiggestBranch(any(DbSession.class), any(SumNclocDbQuery.class))).thenReturn(1800999L);
-
- ProtobufSystemInfo.Section protobuf = statisticsSystemSection.toProtobuf();
- long value = attribute(protobuf, "loc").getLongValue();
-
- assertThat(value).isEqualTo(1800999L);
-
- }
-
-
-}
\ No newline at end of file
import org.sonar.server.authentication.IdentityProviderRepositoryRule;
import org.sonar.server.authentication.TestIdentityProvider;
import org.sonar.server.platform.DockerSupport;
+import org.sonar.server.platform.StatisticsSupport;
import org.sonar.server.user.SecurityRealmFactory;
import static org.assertj.core.api.Assertions.assertThat;
private SecurityRealmFactory securityRealmFactory = mock(SecurityRealmFactory.class);
private DockerSupport dockerSupport = mock(DockerSupport.class);
+ private StatisticsSupport statisticsSupport = mock(StatisticsSupport.class);
private SonarRuntime sonarRuntime = mock(SonarRuntime.class);
+
private GlobalSystemSection underTest = new GlobalSystemSection(settings.asConfig(),
- server, securityRealmFactory, identityProviderRepository, dockerSupport, sonarRuntime);
+ server, securityRealmFactory, identityProviderRepository, dockerSupport, statisticsSupport, sonarRuntime);
@Before
public void setUp() {
assertThatAttributeIs(protobuf, "Force authentication", false);
}
+ @Test
+ public void return_Lines_of_Codes_from_StatisticsSupport(){
+ when(statisticsSupport.getLinesOfCode()).thenReturn(17752L);
+ ProtobufSystemInfo.Section protobuf = underTest.toProtobuf();
+ assertThatAttributeIs(protobuf,"Lines of Code", 17752L);
+ }
+
@Test
@UseDataProvider("trueOrFalse")
public void get_docker_flag(boolean flag) {