aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-05-12 14:22:56 +0200
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-05-13 09:55:29 +0200
commit618a3af602f872b99aaaec3ef7b21510e36b45b0 (patch)
tree9d2688018fa8bb949dfcebf343768e8f20f6713b /server
parent9ac7dcbbf26081d499a2dbd40549ffeff159f93d (diff)
downloadsonarqube-618a3af602f872b99aaaec3ef7b21510e36b45b0.tar.gz
sonarqube-618a3af602f872b99aaaec3ef7b21510e36b45b0.zip
SONAR-7545 functional error when updating a project key
- when updating a project key and a sub-component has a key longer than 400 characters - when a component has a name longer than 2000 characters - when a component has a key longer than 400 characters
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/component/NewComponent.java21
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/component/NewComponentTest.java8
2 files changed, 12 insertions, 17 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/NewComponent.java b/server/sonar-server/src/main/java/org/sonar/server/component/NewComponent.java
index ad380eeee3f..ce0a0d60cf5 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/component/NewComponent.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/component/NewComponent.java
@@ -24,12 +24,12 @@ import javax.annotation.Nullable;
import org.sonar.api.resources.Qualifiers;
import static com.google.common.base.Preconditions.checkArgument;
+import static org.sonar.db.component.ComponentValidator.checkComponentKey;
+import static org.sonar.db.component.ComponentValidator.checkComponentName;
+import static org.sonar.db.component.ComponentValidator.checkComponentQualifier;
public class NewComponent {
- private static final int MAX_KEY_LENGHT = 400;
- private static final int MAX_NAME_LENGTH = 2000;
- private static final int MAX_QUALIFIER_LENGTH = 10;
private String key;
private String branch;
private String qualifier;
@@ -63,20 +63,15 @@ public class NewComponent {
}
public NewComponent setQualifier(@Nullable String qualifier) {
- if (qualifier != null) {
- checkArgument(qualifier.length() <= MAX_QUALIFIER_LENGTH,
- "Component qualifier length (%s) is longer than the maximum authorized (%s)", qualifier.length(), MAX_QUALIFIER_LENGTH);
- }
-
- this.qualifier = qualifier;
+ this.qualifier = qualifier == null ? null : checkComponentQualifier(qualifier);
return this;
}
public static NewComponent create(String key, String name) {
- checkArgument(key != null, "Key can't be null");
- checkArgument(key.length() <= MAX_KEY_LENGHT, "Component key length (%s) is longer than the maximum authorized (%s)", key.length(), MAX_KEY_LENGHT);
- checkArgument(name != null, "Name can't be null");
- checkArgument(name.length() <= MAX_NAME_LENGTH, "Component name length (%s) is longer than the maximum authorized (%s)", name.length(), MAX_NAME_LENGTH);
+ checkArgument(key!=null, "Key can't be null");
+ checkComponentKey(key);
+ checkArgument(name!=null, "Name can't be null");
+ checkComponentName(name);
return new NewComponent(key, name);
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/NewComponentTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/NewComponentTest.java
index 35e01685c8c..4312778d1dd 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/component/NewComponentTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/component/NewComponentTest.java
@@ -23,7 +23,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
+import static com.google.common.base.Strings.repeat;
public class NewComponentTest {
@Rule
@@ -42,7 +42,7 @@ public class NewComponentTest {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Component key length (401) is longer than the maximum authorized (400)");
- NewComponent.create(randomAlphabetic(401), "name");
+ NewComponent.create(repeat("a", 400 + 1), "name");
}
@Test
@@ -58,7 +58,7 @@ public class NewComponentTest {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Component name length (2001) is longer than the maximum authorized (2000)");
- NewComponent.create("key", randomAlphabetic(2001));
+ NewComponent.create("key", repeat("a", 2001));
}
@Test
@@ -66,6 +66,6 @@ public class NewComponentTest {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Component qualifier length (11) is longer than the maximum authorized (10)");
- NewComponent.create("key", "name").setQualifier(randomAlphabetic(11));
+ NewComponent.create("key", "name").setQualifier(repeat("a", 10 + 1));
}
}