From: Jacek Poreda Date: Wed, 21 Jun 2023 13:00:34 +0000 (+0200) Subject: [NO-JIRA] Fix Code Smells X-Git-Tag: 10.2.0.77647~604 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d349b4f3f74a5d1882e5d1f15cacc504cc629bb5;p=sonarqube.git [NO-JIRA] Fix Code Smells --- diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java index 50b8333a826..9a6b970265d 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java @@ -26,8 +26,6 @@ import java.util.Optional; import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; import org.sonar.api.resources.Qualifiers; import org.sonar.api.resources.Scopes; diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/taskprocessor/ProjectDescriptor.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/taskprocessor/ProjectDescriptor.java index 282bc315bc8..6eaf9fddc69 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/taskprocessor/ProjectDescriptor.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/taskprocessor/ProjectDescriptor.java @@ -22,7 +22,6 @@ package org.sonar.ce.task.projectexport.taskprocessor; import java.util.Objects; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; -import org.sonar.db.component.ComponentDto; import org.sonar.db.project.ProjectDto; import static java.util.Objects.requireNonNull; diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/entity/package-info.java b/server/sonar-db-dao/src/main/java/org/sonar/db/entity/package-info.java new file mode 100644 index 00000000000..c43df27d13a --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/entity/package-info.java @@ -0,0 +1,24 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.entity; + +import javax.annotation.ParametersAreNonnullByDefault; + diff --git a/server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java b/server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java index b438fd88684..7ff0eb4993d 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java +++ b/server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java @@ -151,7 +151,7 @@ public class EsSettings { } if (!path.toFile().canRead()) { throw new MessageException("Unable to configure: " + processProperty.getKey() + ". " - + "Could not get read access to [" + processPropertyPath + "]"); + + "Could not get read access to [" + processPropertyPath + "]"); } return path.getFileName().toString(); } diff --git a/server/sonar-main/src/test/java/org/sonar/application/es/EsSettingsTest.java b/server/sonar-main/src/test/java/org/sonar/application/es/EsSettingsTest.java index 8c2518d12a9..a5ad3d8159f 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/es/EsSettingsTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/es/EsSettingsTest.java @@ -28,7 +28,6 @@ import java.io.File; import java.io.IOException; import java.util.Map; import java.util.Properties; -import java.util.Random; import javax.annotation.Nullable; import org.junit.After; import org.junit.Rule; @@ -243,7 +242,7 @@ public class EsSettingsTest { File data = new File(foo, "data"); when(mockedEsInstallation.getDataDirectory()).thenReturn(data); - EsSettings underTest = new EsSettings(minProps(new Random().nextBoolean()), mockedEsInstallation, system); + EsSettings underTest = new EsSettings(minProps(true), mockedEsInstallation, system); Map generated = underTest.build(); assertThat(generated) @@ -306,7 +305,7 @@ public class EsSettingsTest { @Test @UseDataProvider("clusterEnabledOrNot") public void enable_http_connector_on_specified_port(boolean clusterEnabled) throws Exception { - String port = "" + new Random().nextInt(49151); + String port = "" + 49150; Props props = minProps(clusterEnabled, null, port); Map settings = new EsSettings(props, new EsInstallation(props), System2.INSTANCE).build(); diff --git a/server/sonar-process/src/main/java/org/sonar/process/logging/PatternLayoutEncoder.java b/server/sonar-process/src/main/java/org/sonar/process/logging/PatternLayoutEncoder.java index 8540951cae3..03d53997a2a 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/logging/PatternLayoutEncoder.java +++ b/server/sonar-process/src/main/java/org/sonar/process/logging/PatternLayoutEncoder.java @@ -22,7 +22,6 @@ package org.sonar.process.logging; import ch.qos.logback.classic.PatternLayout; import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.pattern.PatternLayoutEncoderBase; -import com.google.common.collect.ImmutableMap; import java.util.Map; public class PatternLayoutEncoder extends PatternLayoutEncoderBase { @@ -40,7 +39,7 @@ public class PatternLayoutEncoder extends PatternLayoutEncoderBase getEscapedMessageConverterConfig() { - return ImmutableMap.of( + return Map.of( "m", EscapedMessageConverter.class.getName(), "msg", EscapedMessageConverter.class.getName(), "message", EscapedMessageConverter.class.getName()); diff --git a/server/sonar-process/src/test/java/org/sonar/process/ProcessPropertiesTest.java b/server/sonar-process/src/test/java/org/sonar/process/ProcessPropertiesTest.java index fb4aace41d2..5d53560d3dd 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/ProcessPropertiesTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/ProcessPropertiesTest.java @@ -24,7 +24,6 @@ import com.google.common.collect.ImmutableSet; import java.net.InetAddress; import java.util.Map; import java.util.Properties; -import java.util.Random; import org.junit.Test; import org.sonar.core.extension.CoreExtension; import org.sonar.core.extension.ServiceLoaderWrapper; @@ -229,7 +228,7 @@ public class ProcessPropertiesTest { @Test public void parseTimeoutMs_returns_long_from_value() { - long expected = 1 + new Random().nextInt(5_999_663); + long expected = 5_999_664; long res = parseTimeoutMs(ProcessProperties.Property.WEB_GRACEFUL_STOP_TIMEOUT, expected + ""); @@ -245,7 +244,7 @@ public class ProcessPropertiesTest { @Test public void parseTimeoutMs_throws_ISE_if_value_is_less_than_0() { - int timeoutValue = -(1 + new Random().nextInt(5_999_663)); + int timeoutValue = -5_999_664; assertThatThrownBy(() -> parseTimeoutMs(ProcessProperties.Property.WEB_GRACEFUL_STOP_TIMEOUT, timeoutValue + "")) .isInstanceOf(IllegalStateException.class) .hasMessage("value of WEB_GRACEFUL_STOP_TIMEOUT must be >= 1"); diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/http/package-info.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/http/package-info.java new file mode 100644 index 00000000000..ef6023816b5 --- /dev/null +++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/http/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.http; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-webserver-pushapi/src/main/java/org/sonar/server/pushapi/hotspots/package-info.java b/server/sonar-webserver-pushapi/src/main/java/org/sonar/server/pushapi/hotspots/package-info.java new file mode 100644 index 00000000000..8f7e2226696 --- /dev/null +++ b/server/sonar-webserver-pushapi/src/main/java/org/sonar/server/pushapi/hotspots/package-info.java @@ -0,0 +1,21 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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. + */ +@javax.annotation.ParametersAreNonnullByDefault +package org.sonar.server.pushapi.hotspots; diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/notification/ws/AddActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/notification/ws/AddActionIT.java index e2a8ab14bfe..aa16e260b37 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/notification/ws/AddActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/notification/ws/AddActionIT.java @@ -216,7 +216,8 @@ public class AddActionIT { userSession.logIn(user).setNonSystemAdministrator(); when(dispatchers.getGlobalDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); - assertThatThrownBy(() -> call(NOTIF_MY_NEW_ISSUES, null, null, user.getLogin())) + String login = user.getLogin(); + assertThatThrownBy(() -> call(NOTIF_MY_NEW_ISSUES, null, null, login)) .isInstanceOf(ForbiddenException.class); } @@ -227,7 +228,8 @@ public class AddActionIT { userSession.logIn(user); when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); - assertThatThrownBy(() -> call(NOTIF_MY_NEW_ISSUES, null, project.getKey(), null)) + String projectKey = project.getKey(); + assertThatThrownBy(() -> call(NOTIF_MY_NEW_ISSUES, null, projectKey, null)) .isInstanceOf(ForbiddenException.class); } @@ -267,7 +269,8 @@ public class AddActionIT { when(dispatchers.getGlobalDispatchers()).thenReturn(asList(NOTIF_MY_NEW_ISSUES, NOTIF_NEW_ISSUES)); when(dispatchers.getProjectDispatchers()).thenReturn(asList(NOTIF_MY_NEW_ISSUES, NOTIF_NEW_ISSUES)); - assertThatThrownBy(() -> call("Dispatcher42", null, project.getKey(), null)) + String projectKey = project.getKey(); + assertThatThrownBy(() -> call("Dispatcher42", null, projectKey, null)) .isInstanceOf(BadRequestException.class) .hasMessageContaining("Value of parameter 'type' (Dispatcher42) must be one of: [Dispatcher1, Dispatcher2]"); } @@ -280,14 +283,16 @@ public class AddActionIT { when(dispatchers.getGlobalDispatchers()).thenReturn(asList(NOTIF_MY_NEW_ISSUES, NOTIF_NEW_ISSUES)); when(dispatchers.getProjectDispatchers()).thenReturn(asList(NOTIF_MY_NEW_ISSUES, NOTIF_NEW_ISSUES)); - assertThatThrownBy(() -> call("Dispatcher42", null, project.getKey(), null)) + String projectKey = project.getKey(); + assertThatThrownBy(() -> call("Dispatcher42", null, projectKey, null)) .isInstanceOf(BadRequestException.class) .hasMessageContaining("Value of parameter 'type' (Dispatcher42) must be one of: [Dispatcher1, Dispatcher2]"); } @Test public void fail_when_no_dispatcher() { - assertThatThrownBy(() -> ws.newRequest().execute()) + TestRequest request = ws.newRequest(); + assertThatThrownBy(request::execute) .isInstanceOf(IllegalArgumentException.class); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/github/config/package-info.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/github/config/package-info.java new file mode 100644 index 00000000000..29faef48272 --- /dev/null +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/github/config/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.almintegration.ws.github.config; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/management/package-info.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/management/package-info.java new file mode 100644 index 00000000000..22b8574d3b3 --- /dev/null +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/management/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.management; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/package-info.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/package-info.java new file mode 100644 index 00000000000..9503830b1c6 --- /dev/null +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.newcodeperiod; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/ProjectWsRef.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/ProjectWsRef.java index 32d49574c73..d9d6f5b44a6 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/ProjectWsRef.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/ProjectWsRef.java @@ -19,7 +19,6 @@ */ package org.sonar.server.permission.ws; -import java.util.Optional; import javax.annotation.CheckForNull; import javax.annotation.Nullable; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/ApplyTemplateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/ApplyTemplateAction.java index 377f1d2c7b6..f7e4995fd46 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/ApplyTemplateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/ApplyTemplateAction.java @@ -29,7 +29,6 @@ import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; import org.sonar.db.DbClient; import org.sonar.db.DbSession; -import org.sonar.db.component.ComponentDto; import org.sonar.db.entity.EntityDto; import org.sonar.db.permission.template.PermissionTemplateDto; import org.sonar.server.exceptions.NotFoundException; @@ -40,7 +39,6 @@ import org.sonar.server.permission.ws.ProjectWsRef; import org.sonar.server.user.UserSession; import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobalAdmin; -import static org.sonar.server.permission.ws.ProjectWsRef.newWsProjectRef; import static org.sonar.server.permission.ws.WsParameters.createProjectParameters; import static org.sonar.server.permission.ws.WsParameters.createTemplateParameters; import static org.sonar.server.permission.ws.template.WsTemplateRef.newTemplateRef;