aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-05-13 10:01:13 +0200
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-05-13 10:01:13 +0200
commit27aa656e1f6031e54f004c9f91d7919f3cb79722 (patch)
treea92a1f3787dc33fee29481ede7c998dd486fee0d
parent618a3af602f872b99aaaec3ef7b21510e36b45b0 (diff)
downloadsonarqube-27aa656e1f6031e54f004c9f91d7919f3cb79722.tar.gz
sonarqube-27aa656e1f6031e54f004c9f91d7919f3cb79722.zip
SONAR-7545 use ComponentKeys.MAX_COMPONENT_KEY_LENGTH
-rw-r--r--sonar-core/src/main/java/org/sonar/core/component/ComponentKeys.java6
-rw-r--r--sonar-db/src/main/java/org/sonar/db/component/ComponentValidator.java22
-rw-r--r--sonar-db/src/test/java/org/sonar/db/component/ComponentValidatorTest.java2
3 files changed, 12 insertions, 18 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/component/ComponentKeys.java b/sonar-core/src/main/java/org/sonar/core/component/ComponentKeys.java
index 64b7c7fa05f..defab7e80a0 100644
--- a/sonar-core/src/main/java/org/sonar/core/component/ComponentKeys.java
+++ b/sonar-core/src/main/java/org/sonar/core/component/ComponentKeys.java
@@ -28,7 +28,7 @@ import org.sonar.api.resources.Scopes;
public final class ComponentKeys {
- public static final int COMPONENT_KEY_SIZE = 400;
+ public static final int MAX_COMPONENT_KEY_LENGTH = 400;
/*
* Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit
@@ -54,7 +54,7 @@ public final class ComponentKeys {
String key = resource.getKey();
if (!StringUtils.equals(Scopes.PROJECT, resource.getScope())) {
// not a project nor a library
- key = new StringBuilder(COMPONENT_KEY_SIZE)
+ key = new StringBuilder(MAX_COMPONENT_KEY_LENGTH)
.append(project.getKey())
.append(':')
.append(resource.getKey())
@@ -68,7 +68,7 @@ public final class ComponentKeys {
}
public static String createEffectiveKey(String moduleKey, @Nullable String path) {
- StringBuilder sb = new StringBuilder(COMPONENT_KEY_SIZE);
+ StringBuilder sb = new StringBuilder(MAX_COMPONENT_KEY_LENGTH);
sb.append(moduleKey);
if (path != null) {
sb.append(':').append(path);
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentValidator.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentValidator.java
index eb628cdf6a0..c352c2471d4 100644
--- a/sonar-db/src/main/java/org/sonar/db/component/ComponentValidator.java
+++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentValidator.java
@@ -21,35 +21,31 @@
package org.sonar.db.component;
import static com.google.common.base.Preconditions.checkArgument;
+import static org.sonar.core.component.ComponentKeys.MAX_COMPONENT_KEY_LENGTH;
public class ComponentValidator {
- private static final int MAX_NAME_LENGTH = 2000;
- private static final int MAX_KEY_LENGTH = 400;
- private static final int MAX_QUALIFIER_LENGTH = 10;
+ private static final int MAX_COMPONENT_NAME_LENGTH = 2000;
+ private static final int MAX_COMPONENT_QUALIFIER_LENGTH = 10;
private ComponentValidator() {
// prevent instantiation
}
public static String checkComponentName(String name) {
- checkArgument(name.length() <= MAX_NAME_LENGTH, "Component name length (%s) is longer than the maximum authorized (%s). '%s' was provided.",
- name.length(), MAX_NAME_LENGTH, name);
+ checkArgument(name.length() <= MAX_COMPONENT_NAME_LENGTH, "Component name length (%s) is longer than the maximum authorized (%s). '%s' was provided.",
+ name.length(), MAX_COMPONENT_NAME_LENGTH, name);
return name;
}
public static String checkComponentKey(String key) {
- checkArgument(isComponentKeyValid(key), "Component key length (%s) is longer than the maximum authorized (%s). '%s' was provided.",
- key.length(), MAX_KEY_LENGTH, key);
+ checkArgument(key.length() <= MAX_COMPONENT_KEY_LENGTH, "Component key length (%s) is longer than the maximum authorized (%s). '%s' was provided.",
+ key.length(), MAX_COMPONENT_KEY_LENGTH, key);
return key;
}
- public static boolean isComponentKeyValid(String key) {
- return key.length() <= MAX_KEY_LENGTH;
- }
-
public static String checkComponentQualifier(String qualifier) {
- checkArgument(qualifier.length() <= MAX_QUALIFIER_LENGTH, "Component qualifier length (%s) is longer than the maximum authorized (%s). '%s' was provided.",
- qualifier.length(), MAX_QUALIFIER_LENGTH, qualifier);
+ checkArgument(qualifier.length() <= MAX_COMPONENT_QUALIFIER_LENGTH, "Component qualifier length (%s) is longer than the maximum authorized (%s). '%s' was provided.",
+ qualifier.length(), MAX_COMPONENT_QUALIFIER_LENGTH, qualifier);
return qualifier;
}
}
diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentValidatorTest.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentValidatorTest.java
index 8e15e278edb..a88b313d6c7 100644
--- a/sonar-db/src/test/java/org/sonar/db/component/ComponentValidatorTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentValidatorTest.java
@@ -51,7 +51,6 @@ public class ComponentValidatorTest {
public void check_key() {
String key = repeat("a", 400);
- assertThat(ComponentValidator.isComponentKeyValid(key)).isTrue();
assertThat(ComponentValidator.checkComponentKey(key)).isEqualTo(key);
}
@@ -61,7 +60,6 @@ public class ComponentValidatorTest {
expectedException.expectMessage("Component key length");
String key = repeat("a", 400 + 1);
- assertThat(ComponentValidator.isComponentKeyValid(key)).isFalse();
ComponentValidator.checkComponentKey(key);
}