aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2016-08-31 10:14:02 +0200
committerDuarte Meneses <duarte.meneses@sonarsource.com>2016-08-31 10:14:02 +0200
commit58dc45e13628ccb7026719dce110f592c9ce5a35 (patch)
treead72ec3b1d687984624cb7ebdaeeada0b32257c0 /sonar-plugin-api/src
parentecc4bd7d1f79eaf255a91cc29d825193cfded8e0 (diff)
downloadsonarqube-58dc45e13628ccb7026719dce110f592c9ce5a35.tar.gz
sonarqube-58dc45e13628ccb7026719dce110f592c9ce5a35.zip
SONAR-7722 The project name should not be mandatory
Diffstat (limited to 'sonar-plugin-api/src')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java13
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/resources/ProjectTest.java20
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");
+ }
}