Browse Source

[NO-JIRA] Addressing some code smells

tags/9.1.0.47736
Belen Pruvost 2 years ago
parent
commit
2af2f20c35

+ 1
- 1
server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/ComponentNewValue.java View File

} }


@CheckForNull @CheckForNull
public boolean isPrivate() {
public Boolean isPrivate() {
return isPrivate; return isPrivate;
} }



+ 24
- 0
server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/package-info.java View File

/*
* 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;


+ 0
- 4
server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java View File

} }
} }


private static ComponentKeyUpdaterMapper mapper(DbSession dbSession) {
return dbSession.getMapper(ComponentKeyUpdaterMapper.class);
}

public static void checkExistentKey(ComponentKeyUpdaterMapper mapper, String resourceKey) { public static void checkExistentKey(ComponentKeyUpdaterMapper mapper, String resourceKey) {
if (mapper.countResourceByKey(resourceKey) > 0) { if (mapper.countResourceByKey(resourceKey) > 0) {
throw new IllegalArgumentException("Impossible to update key: a component with key \"" + resourceKey + "\" already exists."); throw new IllegalArgumentException("Impossible to update key: a component with key \"" + resourceKey + "\" already exists.");

+ 24
- 0
server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/package-info.java View File

/*
* 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;


+ 5
- 3
server/sonar-main/src/main/java/org/sonar/application/config/ClusterSettings.java View File

} }


private Set<AddressAndPort> parseAndCheckHosts(Property property, String value) { private Set<AddressAndPort> parseAndCheckHosts(Property property, String value) {
Set<AddressAndPort> res = parseHosts( value);
Set<AddressAndPort> res = parseHosts(value);
checkValidHosts(property, res); checkValidHosts(property, res);
return res; return res;
} }


private void checkValidHosts(Property property, Set<AddressAndPort> addressAndPorts) { private void checkValidHosts(Property property, Set<AddressAndPort> addressAndPorts) {
List<String> invalidHosts = addressAndPorts.stream()
List<String> invalidHosts = addressAndPorts.stream()
.map(AddressAndPort::getHost) .map(AddressAndPort::getHost)
.filter(t -> !network.toInetAddress(t).isPresent()) .filter(t -> !network.toInetAddress(t).isPresent())
.sorted() .sorted()
private static class AddressAndPort { private static class AddressAndPort {
private static final int NO_PORT = -1; 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 String host;
private final int port; private final int port;



+ 24
- 0
server/sonar-webserver-api/src/main/java/org/sonar/server/rule/package-info.java View File

/*
* 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;


+ 0
- 1
server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/DefaultAdminCredentialsVerifierImpl.java View File

*/ */
package org.sonar.server.authentication; package org.sonar.server.authentication;


import org.picocontainer.Startable;
import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers; import org.sonar.api.utils.log.Loggers;
import org.sonar.db.DbClient; import org.sonar.db.DbClient;

+ 1
- 5
server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java View File

import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.annotation.CheckForNull; import javax.annotation.CheckForNull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.sonar.api.config.Configuration;
import org.sonar.api.config.PropertyDefinition; import org.sonar.api.config.PropertyDefinition;
import org.sonar.api.config.PropertyDefinitions; import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.server.ws.Change; import org.sonar.api.server.ws.Change;
import static org.sonar.api.CoreProperties.SERVER_STARTTIME; import static org.sonar.api.CoreProperties.SERVER_STARTTIME;
import static org.sonar.api.PropertyType.PROPERTY_SET; import static org.sonar.api.PropertyType.PROPERTY_SET;
import static org.sonar.api.web.UserRole.USER; 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.PropertySetExtractor.extractPropertySetKeys;
import static org.sonar.server.setting.ws.SettingsWsParameters.PARAM_COMPONENT; import static org.sonar.server.setting.ws.SettingsWsParameters.PARAM_COMPONENT;
import static org.sonar.server.setting.ws.SettingsWsParameters.PARAM_KEYS; import static org.sonar.server.setting.ws.SettingsWsParameters.PARAM_KEYS;
private final UserSession userSession; private final UserSession userSession;
private final PropertyDefinitions propertyDefinitions; private final PropertyDefinitions propertyDefinitions;
private final SettingsWsSupport settingsWsSupport; private final SettingsWsSupport settingsWsSupport;
private final boolean isSonarCloud;


public ValuesAction(DbClient dbClient, ComponentFinder componentFinder, UserSession userSession, PropertyDefinitions propertyDefinitions, public ValuesAction(DbClient dbClient, ComponentFinder componentFinder, UserSession userSession, PropertyDefinitions propertyDefinitions,
SettingsWsSupport settingsWsSupport, Configuration configuration) {
SettingsWsSupport settingsWsSupport) {
this.dbClient = dbClient; this.dbClient = dbClient;
this.componentFinder = componentFinder; this.componentFinder = componentFinder;
this.userSession = userSession; this.userSession = userSession;
this.propertyDefinitions = propertyDefinitions; this.propertyDefinitions = propertyDefinitions;
this.settingsWsSupport = settingsWsSupport; this.settingsWsSupport = settingsWsSupport;
this.isSonarCloud = configuration.getBoolean(SONARCLOUD_ENABLED.getKey()).orElse(false);
} }


@Override @Override

+ 1
- 10
server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java View File



import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.sonar.api.PropertyType; import org.sonar.api.PropertyType;
import org.sonar.api.config.Configuration;
import org.sonar.api.config.PropertyDefinition; import org.sonar.api.config.PropertyDefinition;
import org.sonar.api.config.PropertyDefinitions; import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.config.PropertyFieldDefinition; import org.sonar.api.config.PropertyFieldDefinition;
import static org.sonar.db.permission.GlobalPermission.SCAN; import static org.sonar.db.permission.GlobalPermission.SCAN;
import static org.sonar.db.property.PropertyTesting.newComponentPropertyDto; import static org.sonar.db.property.PropertyTesting.newComponentPropertyDto;
import static org.sonar.db.property.PropertyTesting.newGlobalPropertyDto; 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.MediaTypes.JSON;
import static org.sonarqube.ws.Settings.Setting.ParentValueOneOfCase.PARENTVALUEONEOF_NOT_SET; import static org.sonarqube.ws.Settings.Setting.ParentValueOneOfCase.PARENTVALUEONEOF_NOT_SET;




private WsActionTester newTester() { private WsActionTester newTester() {
MapSettings settings = new MapSettings(); 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));
}
} }

+ 0
- 8
sonar-core/src/main/java/org/sonar/core/config/SvnProperties.java View File

*/ */
package org.sonar.core.config; 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 { public class SvnProperties {


private static final String CATEGORY_SVN = "SVN";
public static final String USER_PROP_KEY = "sonar.svn.username"; 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 PRIVATE_KEY_PATH_PROP_KEY = "sonar.svn.privateKeyPath";
public static final String PASSWORD_PROP_KEY = "sonar.svn.password.secured"; public static final String PASSWORD_PROP_KEY = "sonar.svn.password.secured";

Loading…
Cancel
Save