From 58dc45e13628ccb7026719dce110f592c9ce5a35 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Wed, 31 Aug 2016 10:14:02 +0200 Subject: [PATCH] SONAR-7722 The project name should not be mandatory --- .../java/org/sonar/api/resources/Project.java | 13 +++++++----- .../org/sonar/api/resources/ProjectTest.java | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java index 31b7bcdf639..490a0a5e6ce 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java @@ -77,12 +77,11 @@ public class Project extends Resource implements Component { if (StringUtils.isNotBlank(branch)) { setKey(String.format(BRANCH_KEY_FORMAT, key, branch)); this.name = String.format("%s %s", name, branch); - this.originalName = String.format("%s %s", name, branch); } else { setKey(key); this.name = name; - this.originalName = name; } + this.originalName = this.name; setEffectiveKey(getKey()); this.branch = branch; } @@ -98,14 +97,18 @@ public class Project extends Resource implements Component { this.branch = branch; return this; } - + @CheckForNull public String getOriginalName() { return originalName; } - + public void setOriginalName(String originalName) { - this.originalName = originalName; + if (StringUtils.isNotBlank(branch)) { + this.originalName = String.format("%s %s", originalName, branch); + } else { + this.originalName = originalName; + } } @Override diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ProjectTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ProjectTest.java index 1029f84fa65..7805c2ec453 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ProjectTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ProjectTest.java @@ -36,5 +36,25 @@ public class ProjectTest { assertThat(project.getKey()).isEqualTo("my:artifact"); } + + @Test + public void setNameWithBranch() { + Project project = new Project("key", "branch", "name"); + assertThat(project.getName()).isEqualTo("name branch"); + assertThat(project.getOriginalName()).isEqualTo("name branch"); + + project.setOriginalName("Project1"); + assertThat(project.getOriginalName()).isEqualTo("Project1 branch"); + } + + @Test + public void setNameWithoutBranch() { + Project project = new Project("key", null, "name"); + assertThat(project.getName()).isEqualTo("name"); + assertThat(project.getOriginalName()).isEqualTo("name"); + + project.setOriginalName("Project1"); + assertThat(project.getOriginalName()).isEqualTo("Project1"); + } } -- 2.39.5