aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java44
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/AbstractLanguage.java7
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/Language.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/resources/AbstractLanguageTest.java27
5 files changed, 57 insertions, 27 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java
index b4731d84746..47aa665e31d 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java
@@ -76,7 +76,7 @@ public class ResourceModel extends BaseIdentifiable implements Cloneable {
@Column(name = "kee", updatable = false, nullable = false, length = KEY_SIZE)
private String key;
- @Column(name = "language", updatable = true, nullable = true, length = 5)
+ @Column(name = "language", updatable = true, nullable = true, length = 20)
private String languageKey;
@Column(name = "root_id", updatable = true, nullable = true)
@@ -283,37 +283,37 @@ public class ResourceModel extends BaseIdentifiable implements Cloneable {
}
ResourceModel other = (ResourceModel) obj;
return new EqualsBuilder()
- .append(key, other.key)
- .append(enabled, other.enabled)
- .append(rootId, other.rootId)
- .isEquals();
+ .append(key, other.key)
+ .append(enabled, other.enabled)
+ .append(rootId, other.rootId)
+ .isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
- .append(key)
- .append(enabled)
- .append(rootId)
- .toHashCode();
+ .append(key)
+ .append(enabled)
+ .append(rootId)
+ .toHashCode();
}
@Override
public String toString() {
return new ToStringBuilder(this)
- .append("id", getId())
- .append("key", key)
- .append("scope", scope)
- .append("qualifier", qualifier)
- .append("name", name)
- .append("longName", longName)
- .append("lang", languageKey)
- .append("enabled", enabled)
- .append("rootId", rootId)
- .append("copyResourceId", copyResourceId)
- .append("personId", personId)
- .append("createdAt", createdAt)
- .toString();
+ .append("id", getId())
+ .append("key", key)
+ .append("scope", scope)
+ .append("qualifier", qualifier)
+ .append("name", name)
+ .append("longName", longName)
+ .append("lang", languageKey)
+ .append("enabled", enabled)
+ .append("rootId", rootId)
+ .append("copyResourceId", copyResourceId)
+ .append("personId", personId)
+ .append("createdAt", createdAt)
+ .toString();
}
@Override
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java
index c8eccd712bf..6c9d01b51b0 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java
@@ -83,7 +83,7 @@ public class RulesProfile implements Cloneable {
@Column(name = "used_profile", updatable = true, nullable = false)
private Boolean used = Boolean.FALSE;
- @Column(name = "language", updatable = true, nullable = false)
+ @Column(name = "language", updatable = true, nullable = false, length = 20)
private String language;
@Column(name = "parent_name", updatable = true, nullable = true)
@@ -243,7 +243,7 @@ public class RulesProfile implements Cloneable {
* @deprecated since 3.3. Always return true.
* @return
*/
-@Deprecated
+ @Deprecated
public boolean isEnabled() {
return true;
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/AbstractLanguage.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/AbstractLanguage.java
index 0370894e471..267e945a284 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/AbstractLanguage.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/AbstractLanguage.java
@@ -19,6 +19,8 @@
*/
package org.sonar.api.resources;
+import com.google.common.base.Preconditions;
+
import java.util.Locale;
/**
@@ -32,6 +34,8 @@ public abstract class AbstractLanguage implements Language {
/**
* Better to use AbstractLanguage(key, name). In this case, key and name will be the same
+ *
+ * @param key The key of the language. Must not be more than 20 chars.
*/
public AbstractLanguage(String key) {
this(key, key);
@@ -40,10 +44,11 @@ public abstract class AbstractLanguage implements Language {
/**
* Should be the constructor used to build an AbstractLanguage.
*
- * @param key the key that will be used to retrieve the language. This key is important as it will be used to teint rules repositories...
+ * @param key the key that will be used to retrieve the language. Must not be more than 20 chars. This key is important as it will be used to teint rules repositories...
* @param name the display name of the language in the interface
*/
public AbstractLanguage(String key, String name) {
+ Preconditions.checkArgument(key.length() < 21, "The following language key exceeds 20 characters: '" + key + "'");
this.key = key.toLowerCase(Locale.ENGLISH);
this.name = name;
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Language.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Language.java
index 9b484c0afcc..5544ee479cf 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Language.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Language.java
@@ -32,7 +32,7 @@ import org.sonar.api.batch.InstantiationStrategy;
public interface Language extends BatchExtension, ServerExtension {
/**
- * For example "java". Should not be more than 5 chars.
+ * For example "java". Should not be more than 20 chars.
*/
String getKey();
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/AbstractLanguageTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/AbstractLanguageTest.java
index a284f4041c8..019b9ea88eb 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/AbstractLanguageTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/AbstractLanguageTest.java
@@ -19,14 +19,39 @@
*/
package org.sonar.api.resources;
-import static org.junit.Assert.assertEquals;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.junit.Assert.assertEquals;
public class AbstractLanguageTest {
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
@Test
public void aLanguageShouldEqualItselft() {
assertEquals(new Java(), new Java());
}
+ @Test
+ public void shouldNotDefineLanguageWithTooLongKey() {
+ thrown.expect(IllegalArgumentException.class);
+ thrown.expectMessage("The following language key exceeds 20 characters: 'aKeyWhichIsVeryVeryVeryVeryVeryLong'");
+
+ new TooLongKeyLanguage();
+ }
+
+ class TooLongKeyLanguage extends AbstractLanguage {
+ public TooLongKeyLanguage() {
+ super("aKeyWhichIsVeryVeryVeryVeryVeryLong");
+ }
+
+ public String[] getFileSuffixes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ }
+
}