diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2018-08-30 11:07:00 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-09-07 20:20:56 +0200 |
commit | 469af3846a5ca3f78b2b190ec4a2b27e3c7fd11f (patch) | |
tree | 02d491f891943febf90f0baec493b953bad7703d /server/sonar-server-common | |
parent | 8fc5a9f6296fef6d63b746ab7dae0a1080ab1272 (diff) | |
download | sonarqube-469af3846a5ca3f78b2b190ec4a2b27e3c7fd11f.tar.gz sonarqube-469af3846a5ca3f78b2b190ec4a2b27e3c7fd11f.zip |
SONAR-11185 Allow portfolio to define projects by tags
* SONAR-11199 Allow selection of no project mode
* Add tags in views definition
* Create api/views/set_tags_mode
* Return tags mode in api/views/show
* Take into account tags during portfolio computation
Diffstat (limited to 'server/sonar-server-common')
8 files changed, 102 insertions, 29 deletions
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java index 077bd3b6a1c..7f5abde500d 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java @@ -24,7 +24,6 @@ import java.time.temporal.ChronoUnit; import java.util.Collection; import java.util.Date; import java.util.HashSet; -import java.util.Locale; import java.util.Objects; import java.util.Set; import javax.annotation.Nullable; @@ -36,7 +35,6 @@ import org.sonar.api.utils.Duration; import org.sonar.core.issue.DefaultIssue; import org.sonar.core.issue.DefaultIssueComment; import org.sonar.core.issue.IssueChangeContext; -import org.sonar.core.util.stream.MoreCollectors; import org.sonar.db.user.UserDto; import static com.google.common.base.Preconditions.checkState; @@ -318,11 +316,7 @@ public class IssueFieldsSetter { } public boolean setTags(DefaultIssue issue, Collection<String> tags, IssueChangeContext context) { - Set<String> newTags = tags.stream() - .filter(Objects::nonNull) - .filter(tag -> !tag.isEmpty()) - .map(tag -> RuleTagFormat.validate(tag.toLowerCase(Locale.ENGLISH))) - .collect(MoreCollectors.toSet()); + Set<String> newTags = RuleTagFormat.validate(tags); Set<String> oldTags = new HashSet<>(issue.tags()); if (!oldTags.equals(newTags)) { diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/project/Project.java b/server/sonar-server-common/src/main/java/org/sonar/server/project/Project.java index af220370e34..4576e716aae 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/project/Project.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/project/Project.java @@ -19,6 +19,7 @@ */ package org.sonar.server.project; +import java.util.List; import java.util.Objects; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; @@ -31,20 +32,18 @@ public class Project { private final String key; private final String name; private final String description; + private final List<String> tags; - public Project(String uuid, String key, String name) { - this(uuid, key, name, null); - } - - public Project(String uuid, String key, String name, @Nullable String description) { + public Project(String uuid, String key, String name, @Nullable String description, List<String> tags) { this.uuid = uuid; this.key = key; this.name = name; this.description = description; + this.tags = tags; } public static Project from(ComponentDto project) { - return new Project(project.uuid(), project.getDbKey(), project.name(), project.description()); + return new Project(project.uuid(), project.getKey(), project.name(), project.description(), project.getTags()); } /** @@ -69,6 +68,10 @@ public class Project { return description; } + public List<String> getTags() { + return tags; + } + @Override public boolean equals(Object o) { if (this == o) { diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/webhook/Project.java b/server/sonar-server-common/src/main/java/org/sonar/server/webhook/Project.java new file mode 100644 index 00000000000..9ec7c2c6764 --- /dev/null +++ b/server/sonar-server-common/src/main/java/org/sonar/server/webhook/Project.java @@ -0,0 +1,79 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 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. + */ +package org.sonar.server.webhook; + +import java.util.Objects; +import javax.annotation.concurrent.Immutable; + +@Immutable +public class Project { + + private final String uuid; + private final String key; + private final String name; + + public Project(String uuid, String key, String name) { + this.uuid = uuid; + this.key = key; + this.name = name; + } + + public String getUuid() { + return uuid; + } + + public String getKey() { + return key; + } + + public String getName() { + return name; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Project project = (Project) o; + return Objects.equals(uuid, project.uuid) && + Objects.equals(key, project.key) && + Objects.equals(name, project.name); + } + + @Override + public int hashCode() { + return Objects.hash(uuid, key, name); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("Project{"); + sb.append("uuid='").append(uuid).append('\''); + sb.append(", key='").append(key).append('\''); + sb.append(", name='").append(name).append('\''); + sb.append('}'); + return sb.toString(); + } + +} diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/webhook/ProjectAnalysis.java b/server/sonar-server-common/src/main/java/org/sonar/server/webhook/ProjectAnalysis.java index 3a9175adbfb..2e055ad77f6 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/webhook/ProjectAnalysis.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/webhook/ProjectAnalysis.java @@ -23,7 +23,6 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; import javax.annotation.Nullable; -import org.sonar.server.project.Project; import org.sonar.server.qualitygate.EvaluatedQualityGate; import static com.google.common.collect.ImmutableMap.copyOf; diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/webhook/WebhookPayloadFactoryImpl.java b/server/sonar-server-common/src/main/java/org/sonar/server/webhook/WebhookPayloadFactoryImpl.java index d6b9b298ec6..51f93e22328 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/webhook/WebhookPayloadFactoryImpl.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/webhook/WebhookPayloadFactoryImpl.java @@ -31,7 +31,6 @@ import org.sonar.api.platform.Server; import org.sonar.api.server.ServerSide; import org.sonar.api.utils.System2; import org.sonar.api.utils.text.JsonWriter; -import org.sonar.server.project.Project; import org.sonar.server.qualitygate.Condition; import org.sonar.server.qualitygate.EvaluatedCondition; import org.sonar.server.qualitygate.EvaluatedQualityGate; diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/project/ProjectTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/project/ProjectTest.java index 4f2a351e844..0f620f33b2b 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/project/ProjectTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/project/ProjectTest.java @@ -21,13 +21,14 @@ package org.sonar.server.project; import org.junit.Test; +import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; public class ProjectTest { @Test public void test_bean_without_description() { - Project project1 = new Project("U1", "K1", "N1"); - Project project2 = new Project("U1", "K1", "N1", null); + Project project1 = new Project("U1", "K1", "N1", null, emptyList()); + Project project2 = new Project("U1", "K1", "N1", null, emptyList()); assertThat(project1.getUuid()).isEqualTo(project2.getUuid()).isEqualTo("U1"); assertThat(project1.getKey()).isEqualTo(project2.getKey()).isEqualTo("K1"); @@ -41,7 +42,7 @@ public class ProjectTest { @Test public void test_bean_with_description() { - Project project1 = new Project("U1", "K1", "N1", "D1"); + Project project1 = new Project("U1", "K1", "N1", "D1", emptyList()); assertThat(project1.getUuid()).isEqualTo("U1"); assertThat(project1.getKey()).isEqualTo("K1"); @@ -55,23 +56,23 @@ public class ProjectTest { @Test public void test_equals_and_hashCode() { - Project project1 = new Project("U1", "K1", "N1"); - Project project2 = new Project("U1", "K1", "N1", "D1"); + Project project1 = new Project("U1", "K1", "N1", null, emptyList()); + Project project2 = new Project("U1", "K1", "N1", "D1", emptyList()); assertThat(project1).isEqualTo(project1); assertThat(project1).isNotEqualTo(null); assertThat(project1).isNotEqualTo(new Object()); - assertThat(project1).isEqualTo(new Project("U1", "K1", "N1", null)); - assertThat(project1).isNotEqualTo(new Project("U1", "K2", "N1", null)); - assertThat(project1).isNotEqualTo(new Project("U1", "K1", "N2", null)); + assertThat(project1).isEqualTo(new Project("U1", "K1", "N1", null, emptyList())); + assertThat(project1).isNotEqualTo(new Project("U1", "K2", "N1", null, emptyList())); + assertThat(project1).isNotEqualTo(new Project("U1", "K1", "N2", null, emptyList())); assertThat(project1).isEqualTo(project2); assertThat(project1.hashCode()).isEqualTo(project1.hashCode()); assertThat(project1.hashCode()).isNotEqualTo(null); assertThat(project1.hashCode()).isNotEqualTo(new Object().hashCode()); - assertThat(project1.hashCode()).isEqualTo(new Project("U1", "K1", "N1", null).hashCode()); - assertThat(project1.hashCode()).isNotEqualTo(new Project("U1", "K2", "N1", null).hashCode()); - assertThat(project1.hashCode()).isNotEqualTo(new Project("U1", "K1", "N2", null).hashCode()); + assertThat(project1.hashCode()).isEqualTo(new Project("U1", "K1", "N1", null, emptyList()).hashCode()); + assertThat(project1.hashCode()).isNotEqualTo(new Project("U1", "K2", "N1", null, emptyList()).hashCode()); + assertThat(project1.hashCode()).isNotEqualTo(new Project("U1", "K1", "N2", null, emptyList()).hashCode()); assertThat(project1.hashCode()).isEqualTo(project2.hashCode()); } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/webhook/ProjectAnalysisTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/webhook/ProjectAnalysisTest.java index 0a453709b67..21c7cb87390 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/webhook/ProjectAnalysisTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/webhook/ProjectAnalysisTest.java @@ -25,7 +25,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.measures.Metric; -import org.sonar.server.project.Project; import org.sonar.server.qualitygate.EvaluatedQualityGate; import org.sonar.server.qualitygate.QualityGate; @@ -149,6 +148,6 @@ public class ProjectAnalysisTest { @Test public void verify_toString() { assertThat(underTest.toString()).isEqualTo( - "ProjectAnalysis{project=Project{uuid='uuid', key='key', name='name', description=null}, ceTask=CeTask{id='id', status=SUCCESS}, branch=Branch{main=true, name='name', type=SHORT}, qualityGate=EvaluatedQualityGate{qualityGate=QualityGate{id=id, name='name', conditions=[]}, status=WARN, evaluatedConditions=[]}, updatedAt=1, properties={a=b}, analysis=Analysis{uuid='analysis_uuid', date=1500}}"); + "ProjectAnalysis{project=Project{uuid='uuid', key='key', name='name'}, ceTask=CeTask{id='id', status=SUCCESS}, branch=Branch{main=true, name='name', type=SHORT}, qualityGate=EvaluatedQualityGate{qualityGate=QualityGate{id=id, name='name', conditions=[]}, status=WARN, evaluatedConditions=[]}, updatedAt=1, properties={a=b}, analysis=Analysis{uuid='analysis_uuid', date=1500}}"); } } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/webhook/WebhookPayloadFactoryImplTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/webhook/WebhookPayloadFactoryImplTest.java index a494b9a86e7..be8df1f933e 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/webhook/WebhookPayloadFactoryImplTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/webhook/WebhookPayloadFactoryImplTest.java @@ -27,7 +27,6 @@ import org.junit.Test; import org.sonar.api.measures.Metric; import org.sonar.api.platform.Server; import org.sonar.api.utils.System2; -import org.sonar.server.project.Project; import org.sonar.server.qualitygate.Condition; import org.sonar.server.qualitygate.EvaluatedCondition; import org.sonar.server.qualitygate.EvaluatedQualityGate; |