]> source.dussan.org Git - sonarqube.git/commitdiff
[NO-JIRA] Fix Code Smells
authorJacek Poreda <jacek.poreda@sonarsource.com>
Wed, 21 Jun 2023 13:00:34 +0000 (15:00 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 22 Jun 2023 20:02:53 +0000 (20:02 +0000)
15 files changed:
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/taskprocessor/ProjectDescriptor.java
server/sonar-db-dao/src/main/java/org/sonar/db/entity/package-info.java [new file with mode: 0644]
server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java
server/sonar-main/src/test/java/org/sonar/application/es/EsSettingsTest.java
server/sonar-process/src/main/java/org/sonar/process/logging/PatternLayoutEncoder.java
server/sonar-process/src/test/java/org/sonar/process/ProcessPropertiesTest.java
server/sonar-webserver-api/src/main/java/org/sonar/server/http/package-info.java [new file with mode: 0644]
server/sonar-webserver-pushapi/src/main/java/org/sonar/server/pushapi/hotspots/package-info.java [new file with mode: 0644]
server/sonar-webserver-webapi/src/it/java/org/sonar/server/notification/ws/AddActionIT.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/github/config/package-info.java [new file with mode: 0644]
server/sonar-webserver-webapi/src/main/java/org/sonar/server/management/package-info.java [new file with mode: 0644]
server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/package-info.java [new file with mode: 0644]
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/ProjectWsRef.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/ApplyTemplateAction.java

index 50b8333a8269e9a3774ab04c90aeba7a4d29ec2c..9a6b970265db82d46bedbee38b38d2e9aaa5a39b 100644 (file)
@@ -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;
index 282bc315bc89af75d5b50fbc1a8f7bff0122aa92..6eaf9fddc698211fd4567d9e7b31ae36c873dcd9 100644 (file)
@@ -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 (file)
index 0000000..c43df27
--- /dev/null
@@ -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;
+
index b438fd886849c188a6a610f84a193d32678c0f78..7ff0eb4993d5cfeffa266ffb74aec89f707ffec3 100644 (file)
@@ -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();
   }
index 8c2518d12a9f01eb3105b60634d89e05b4684242..a5ad3d8159f5b9d1b58c51f7ad9961f8e4f90247 100644 (file)
@@ -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<String, String> 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<String, String> settings = new EsSettings(props, new EsInstallation(props), System2.INSTANCE).build();
 
index 8540951cae3299a2f908cd758186ed392e3f4582..03d53997a2abf42d06c5120f1d54711ed16640d5 100644 (file)
@@ -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<ILoggingEvent> {
@@ -40,7 +39,7 @@ public class PatternLayoutEncoder extends PatternLayoutEncoderBase<ILoggingEvent
   }
 
   private static Map<String, String> getEscapedMessageConverterConfig() {
-    return ImmutableMap.of(
+    return Map.of(
       "m", EscapedMessageConverter.class.getName(),
       "msg", EscapedMessageConverter.class.getName(),
       "message", EscapedMessageConverter.class.getName());
index fb4aace41d2c23f08c1d05e7acae5df54dc136ba..5d53560d3dd95a90944305bcdd9d99f6e54142ff 100644 (file)
@@ -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 (file)
index 0000000..ef60238
--- /dev/null
@@ -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 (file)
index 0000000..8f7e222
--- /dev/null
@@ -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;
index e2a8ab14bfeec6fc58ca8dfa18df83f28fd46606..aa16e260b373188d6eb951d890d616320a1a4f72 100644 (file)
@@ -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 (file)
index 0000000..29faef4
--- /dev/null
@@ -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 (file)
index 0000000..22b8574
--- /dev/null
@@ -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 (file)
index 0000000..9503830
--- /dev/null
@@ -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;
index 32d49574c736d481cb747250749e33e6fd948aca..d9d6f5b44a6f2b55494effc2c2caea37ded49574 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.server.permission.ws;
 
-import java.util.Optional;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 
index 377f1d2c7b6a71b7a450403eee362f59676eead8..f7e4995fd46cb1fdc49dd2c715a00d99f1cfa08c 100644 (file)
@@ -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;