From: Belen Pruvost Date: Thu, 16 Sep 2021 07:53:08 +0000 (+0200) Subject: [NO-JIRA] Addressing some code smells X-Git-Tag: 9.1.0.47736~20 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2af2f20c35b324fc5f9a5bced333cbdaa64cbe96;p=sonarqube.git [NO-JIRA] Addressing some code smells --- diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/ComponentNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/ComponentNewValue.java index 75b64af6947..73e0b0c2e72 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/ComponentNewValue.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/ComponentNewValue.java @@ -90,7 +90,7 @@ public class ComponentNewValue extends NewValue { } @CheckForNull - public boolean isPrivate() { + public Boolean isPrivate() { return isPrivate; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/package-info.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/package-info.java new file mode 100644 index 00000000000..77b47ce1862 --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/package-info.java @@ -0,0 +1,24 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 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. + */ +@ParametersAreNonnullByDefault +package org.sonar.db.audit.model; + +import javax.annotation.ParametersAreNonnullByDefault; + diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java index 80638b887e6..489e9d4c31c 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java @@ -156,10 +156,6 @@ public class ComponentKeyUpdaterDao implements Dao { } } - private static ComponentKeyUpdaterMapper mapper(DbSession dbSession) { - return dbSession.getMapper(ComponentKeyUpdaterMapper.class); - } - public static void checkExistentKey(ComponentKeyUpdaterMapper mapper, String resourceKey) { if (mapper.countResourceByKey(resourceKey) > 0) { throw new IllegalArgumentException("Impossible to update key: a component with key \"" + resourceKey + "\" already exists."); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/package-info.java b/server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/package-info.java new file mode 100644 index 00000000000..9a2d320b660 --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/package-info.java @@ -0,0 +1,24 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 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. + */ +@ParametersAreNonnullByDefault +package org.sonar.db.portfolio; + +import javax.annotation.ParametersAreNonnullByDefault; + diff --git a/server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java b/server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java index 140a0f6944a..aef62f21922 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java +++ b/server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java @@ -136,13 +136,13 @@ public class ClusterSettings implements Consumer { } private Set parseAndCheckHosts(Property property, String value) { - Set res = parseHosts( value); + Set res = parseHosts(value); checkValidHosts(property, res); return res; } private void checkValidHosts(Property property, Set addressAndPorts) { - List invalidHosts = addressAndPorts.stream() + List invalidHosts = addressAndPorts.stream() .map(AddressAndPort::getHost) .filter(t -> !network.toInetAddress(t).isPresent()) .sorted() @@ -231,7 +231,9 @@ public class ClusterSettings implements Consumer { private static class AddressAndPort { private static final int NO_PORT = -1; - /** the host from setting, can be a hostname or an IP address */ + /** + * the host from setting, can be a hostname or an IP address + */ private final String host; private final int port; diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/package-info.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/package-info.java new file mode 100644 index 00000000000..d96ac2b2bec --- /dev/null +++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/package-info.java @@ -0,0 +1,24 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 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. + */ +@ParametersAreNonnullByDefault +package org.sonar.server.rule; + +import javax.annotation.ParametersAreNonnullByDefault; + diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/DefaultAdminCredentialsVerifierImpl.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/DefaultAdminCredentialsVerifierImpl.java index b1e11e52d67..d89132956dd 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/DefaultAdminCredentialsVerifierImpl.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/DefaultAdminCredentialsVerifierImpl.java @@ -19,7 +19,6 @@ */ package org.sonar.server.authentication; -import org.picocontainer.Startable; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.db.DbClient; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java index bf0cb210972..84f491d1742 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java @@ -35,7 +35,6 @@ import java.util.function.Function; import java.util.stream.Collectors; import javax.annotation.CheckForNull; import javax.annotation.Nullable; -import org.sonar.api.config.Configuration; import org.sonar.api.config.PropertyDefinition; import org.sonar.api.config.PropertyDefinitions; import org.sonar.api.server.ws.Change; @@ -60,7 +59,6 @@ import static org.sonar.api.CoreProperties.SERVER_ID; import static org.sonar.api.CoreProperties.SERVER_STARTTIME; import static org.sonar.api.PropertyType.PROPERTY_SET; import static org.sonar.api.web.UserRole.USER; -import static org.sonar.process.ProcessProperties.Property.SONARCLOUD_ENABLED; import static org.sonar.server.setting.ws.PropertySetExtractor.extractPropertySetKeys; import static org.sonar.server.setting.ws.SettingsWsParameters.PARAM_COMPONENT; import static org.sonar.server.setting.ws.SettingsWsParameters.PARAM_KEYS; @@ -81,16 +79,14 @@ public class ValuesAction implements SettingsWsAction { private final UserSession userSession; private final PropertyDefinitions propertyDefinitions; private final SettingsWsSupport settingsWsSupport; - private final boolean isSonarCloud; public ValuesAction(DbClient dbClient, ComponentFinder componentFinder, UserSession userSession, PropertyDefinitions propertyDefinitions, - SettingsWsSupport settingsWsSupport, Configuration configuration) { + SettingsWsSupport settingsWsSupport) { this.dbClient = dbClient; this.componentFinder = componentFinder; this.userSession = userSession; this.propertyDefinitions = propertyDefinitions; this.settingsWsSupport = settingsWsSupport; - this.isSonarCloud = configuration.getBoolean(SONARCLOUD_ENABLED.getKey()).orElse(false); } @Override diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java index 8ac58cda4e2..7bf27b1ae0b 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java @@ -21,7 +21,6 @@ package org.sonar.server.setting.ws; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableMap; -import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -31,7 +30,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.PropertyType; -import org.sonar.api.config.Configuration; import org.sonar.api.config.PropertyDefinition; import org.sonar.api.config.PropertyDefinitions; import org.sonar.api.config.PropertyFieldDefinition; @@ -72,7 +70,6 @@ import static org.sonar.db.component.ComponentTesting.newModuleDto; import static org.sonar.db.permission.GlobalPermission.SCAN; import static org.sonar.db.property.PropertyTesting.newComponentPropertyDto; import static org.sonar.db.property.PropertyTesting.newGlobalPropertyDto; -import static org.sonar.process.ProcessProperties.Property.SONARCLOUD_ENABLED; import static org.sonarqube.ws.MediaTypes.JSON; import static org.sonarqube.ws.Settings.Setting.ParentValueOneOfCase.PARENTVALUEONEOF_NOT_SET; @@ -935,13 +932,7 @@ public class ValuesActionTest { private WsActionTester newTester() { MapSettings settings = new MapSettings(); - Configuration configuration = settings.asConfig(); - return new WsActionTester(new ValuesAction(dbClient, TestComponentFinder.from(db), userSession, definitions, support, configuration)); + return new WsActionTester(new ValuesAction(dbClient, TestComponentFinder.from(db), userSession, definitions, support)); } - private WsActionTester newSonarCloudTester() { - MapSettings settings = new MapSettings().setProperty(SONARCLOUD_ENABLED.getKey(), "true"); - Configuration configuration = settings.asConfig(); - return new WsActionTester(new ValuesAction(dbClient, TestComponentFinder.from(db), userSession, definitions, support, configuration)); - } } diff --git a/sonar-core/src/main/java/org/sonar/core/config/SvnProperties.java b/sonar-core/src/main/java/org/sonar/core/config/SvnProperties.java index 1c282cc846d..3e4d7704c43 100644 --- a/sonar-core/src/main/java/org/sonar/core/config/SvnProperties.java +++ b/sonar-core/src/main/java/org/sonar/core/config/SvnProperties.java @@ -19,16 +19,8 @@ */ package org.sonar.core.config; -import java.util.Arrays; -import java.util.List; -import org.sonar.api.CoreProperties; -import org.sonar.api.PropertyType; -import org.sonar.api.config.PropertyDefinition; -import org.sonar.api.resources.Qualifiers; - public class SvnProperties { - private static final String CATEGORY_SVN = "SVN"; public static final String USER_PROP_KEY = "sonar.svn.username"; public static final String PRIVATE_KEY_PATH_PROP_KEY = "sonar.svn.privateKeyPath"; public static final String PASSWORD_PROP_KEY = "sonar.svn.password.secured";