aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2017-09-14 14:05:32 +0200
committerDuarte Meneses <duarte.meneses@sonarsource.com>2017-09-14 15:40:11 +0200
commitd37a06d8bb263713e3e2c99b977806a41dec15a6 (patch)
treeb42c27ab89a4965d9f68c61dcf707eb7686bc797 /server
parentc9975c3520d55d9f79cb04468fa5a64da8ed5dfa (diff)
downloadsonarqube-d37a06d8bb263713e3e2c99b977806a41dec15a6.tar.gz
sonarqube-d37a06d8bb263713e3e2c99b977806a41dec15a6.zip
Improve quality
Diffstat (limited to 'server')
-rw-r--r--server/sonar-cluster/src/main/java/org/sonar/cluster/internal/package-info.java23
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueLifecycle.java48
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStep.java5
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/BranchesWs.java16
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/DeleteAction.java12
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/RenameAction.java12
7 files changed, 65 insertions, 53 deletions
diff --git a/server/sonar-cluster/src/main/java/org/sonar/cluster/internal/package-info.java b/server/sonar-cluster/src/main/java/org/sonar/cluster/internal/package-info.java
new file mode 100644
index 00000000000..42de29c670c
--- /dev/null
+++ b/server/sonar-cluster/src/main/java/org/sonar/cluster/internal/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.cluster.internal;
+
+import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
index d911187f8a0..b8df226eb4e 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
@@ -174,7 +174,7 @@ public class ComponentDao implements Dao {
public List<ComponentDto> selectByKeysAndBranch(DbSession session, Collection<String> keys, String branch) {
List<String> dbKeys = keys.stream().map(k -> generateBranchKey(k, branch)).collect(toList());
- List<String> allKeys = Stream.of(keys, dbKeys) .flatMap(x -> x.stream()) .collect(toList());
+ List<String> allKeys = Stream.of(keys, dbKeys) .flatMap(Collection::stream) .collect(toList());
return executeLargeInputs(allKeys, subKeys -> mapper(session).selectByKeysAndBranch(subKeys, branch));
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueLifecycle.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueLifecycle.java
index 15c8e0017c9..8bfc6fe06d5 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueLifecycle.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueLifecycle.java
@@ -69,40 +69,19 @@ public class IssueLifecycle {
raw.setKey(Uuids.create());
raw.setNew(false);
raw.setCopied(true);
- raw.setType(base.type());
- raw.setCreationDate(base.creationDate());
- raw.setUpdateDate(base.updateDate());
- raw.setCloseDate(base.closeDate());
- raw.setResolution(base.resolution());
- raw.setStatus(base.status());
- raw.setAssignee(base.assignee());
- raw.setAuthorLogin(base.authorLogin());
- raw.setTags(base.tags());
- raw.setAttributes(base.attributes());
- raw.setEffort(debtCalculator.calculate(raw));
- raw.setOnDisabledRule(base.isOnDisabledRule());
+ copyFields(raw, base);
+
if (base.manualSeverity()) {
raw.setManualSeverity(true);
raw.setSeverity(base.severity());
}
- raw.setSelectedAt(base.selectedAt());
}
public void mergeExistingOpenIssue(DefaultIssue raw, DefaultIssue base) {
- raw.setNew(false);
raw.setKey(base.key());
- raw.setType(base.type());
- raw.setCreationDate(base.creationDate());
- raw.setUpdateDate(base.updateDate());
- raw.setCloseDate(base.closeDate());
- raw.setResolution(base.resolution());
- raw.setStatus(base.status());
- raw.setAssignee(base.assignee());
- raw.setAuthorLogin(base.authorLogin());
- raw.setTags(base.tags());
- raw.setAttributes(base.attributes());
- raw.setEffort(debtCalculator.calculate(raw));
- raw.setOnDisabledRule(base.isOnDisabledRule());
+ raw.setNew(false);
+ copyFields(raw, base);
+
if (base.manualSeverity()) {
raw.setManualSeverity(true);
raw.setSeverity(base.severity());
@@ -122,10 +101,25 @@ public class IssueLifecycle {
updater.setPastMessage(raw, base.getMessage(), changeContext);
updater.setPastGap(raw, base.gap(), changeContext);
updater.setPastEffort(raw, base.effort(), changeContext);
- raw.setSelectedAt(base.selectedAt());
}
public void doAutomaticTransition(DefaultIssue issue) {
workflow.doAutomaticTransition(issue, changeContext);
}
+
+ private void copyFields(DefaultIssue toIssue, DefaultIssue fromIssue) {
+ toIssue.setType(fromIssue.type());
+ toIssue.setCreationDate(fromIssue.creationDate());
+ toIssue.setUpdateDate(fromIssue.updateDate());
+ toIssue.setCloseDate(fromIssue.closeDate());
+ toIssue.setResolution(fromIssue.resolution());
+ toIssue.setStatus(fromIssue.status());
+ toIssue.setAssignee(fromIssue.assignee());
+ toIssue.setAuthorLogin(fromIssue.authorLogin());
+ toIssue.setTags(fromIssue.tags());
+ toIssue.setAttributes(fromIssue.attributes());
+ toIssue.setEffort(debtCalculator.calculate(toIssue));
+ toIssue.setOnDisabledRule(fromIssue.isOnDisabledRule());
+ toIssue.setSelectedAt(fromIssue.selectedAt());
+ }
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStep.java
index 32d0b4a1abc..930a75192be 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStep.java
@@ -22,7 +22,6 @@ package org.sonar.server.computation.task.projectanalysis.step;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import java.util.Date;
-import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
@@ -64,7 +63,7 @@ public class SendIssueNotificationsStep implements ComputationStep {
private final NotificationService service;
private final AnalysisMetadataHolder analysisMetadataHolder;
private final NewIssuesNotificationFactory newIssuesNotificationFactory;
- private Map<String, Component> componentsByDbKey = new HashMap<>();
+ private Map<String, Component> componentsByDbKey;
public SendIssueNotificationsStep(IssueCache issueCache, RuleRepository rules, TreeRootHolder treeRootHolder,
NotificationService service, AnalysisMetadataHolder analysisMetadataHolder,
@@ -150,7 +149,7 @@ public class SendIssueNotificationsStep implements ComputationStep {
}
private Optional<Component> getComponentKey(DefaultIssue issue) {
- if (componentsByDbKey.isEmpty()) {
+ if (componentsByDbKey == null) {
final ImmutableMap.Builder<String, Component> builder = ImmutableMap.builder();
new DepthTraversalTypeAwareCrawler(
new TypeAwareVisitorAdapter(CrawlerDepthLimit.LEAVES, POST_ORDER) {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/BranchesWs.java b/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/BranchesWs.java
index 82a8f525cd0..1492cef02dd 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/BranchesWs.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/BranchesWs.java
@@ -22,7 +22,10 @@ package org.sonar.server.projectbranch.ws;
import java.util.Arrays;
import org.sonar.api.server.ws.WebService;
+import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.CONTROLLER;
+import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.PARAM_BRANCH;
+import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.PARAM_PROJECT;
public class BranchesWs implements WebService {
private final BranchWsAction[] actions;
@@ -39,4 +42,17 @@ public class BranchesWs implements WebService {
controller.done();
}
+ static void addProjectBranchParams(NewAction action) {
+ action
+ .createParam(PARAM_PROJECT)
+ .setDescription("Project key")
+ .setExampleValue(KEY_PROJECT_EXAMPLE_001)
+ .setRequired(true);
+ action
+ .createParam(PARAM_BRANCH)
+ .setDescription("Name of the branch to delete. Can't be the main branch of the project.")
+ .setExampleValue("branch1")
+ .setRequired(true);
+ }
+
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/DeleteAction.java b/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/DeleteAction.java
index fa61c63d39e..f907be4dfc0 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/DeleteAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/DeleteAction.java
@@ -34,7 +34,6 @@ import org.sonar.server.component.ComponentCleanerService;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.user.UserSession;
-import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
import static org.sonar.server.ws.WsUtils.checkFoundWithOptional;
import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.ACTION_DELETE;
import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.PARAM_BRANCH;
@@ -63,16 +62,7 @@ public class DeleteAction implements BranchWsAction {
.setPost(true)
.setHandler(this);
- action
- .createParam(PARAM_PROJECT)
- .setDescription("Project key")
- .setExampleValue(KEY_PROJECT_EXAMPLE_001)
- .setRequired(true);
- action
- .createParam(PARAM_BRANCH)
- .setDescription("Name of the branch to delete. Can't be the main branch of the project.")
- .setExampleValue("branch1")
- .setRequired(true);
+ BranchesWs.addProjectBranchParams(action);
}
@Override
diff --git a/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/RenameAction.java b/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/RenameAction.java
index 3cf4e7d93fa..498c629db75 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/RenameAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/RenameAction.java
@@ -33,7 +33,6 @@ import org.sonar.db.component.ComponentDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.user.UserSession;
-import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.ACTION_RENAME;
import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.PARAM_BRANCH;
import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.PARAM_PROJECT;
@@ -59,16 +58,7 @@ public class RenameAction implements BranchWsAction {
.setPost(true)
.setHandler(this);
- action
- .createParam(PARAM_PROJECT)
- .setDescription("Project key")
- .setExampleValue(KEY_PROJECT_EXAMPLE_001)
- .setRequired(true);
- action
- .createParam(PARAM_BRANCH)
- .setDescription("New name of the main branch")
- .setExampleValue("master")
- .setRequired(true);
+ BranchesWs.addProjectBranchParams(action);
}
@Override