From: Fabrice Bellingard Date: Fri, 28 Sep 2012 14:49:27 +0000 (+0200) Subject: SONAR-2203 Increase the size of language key from 5 to 20 X-Git-Tag: 3.3~172 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bb5de6261ddf342ae15cd56cd81458760b94a6f8;p=sonarqube.git SONAR-2203 Increase the size of language key from 5 to 20 --- diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java index 8d7f02e6d08..3c58a5b8187 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java @@ -35,7 +35,7 @@ import java.util.List; */ public class DatabaseVersion implements BatchComponent, ServerComponent { - public static final int LAST_VERSION = 332; + public static final int LAST_VERSION = 333; public static enum Status { UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql index f96ebf5ccc8..cec3ca8ecf6 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql @@ -174,6 +174,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('321'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('330'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('331'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('332'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('333'); INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null); ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2; diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl index 6b469747ce3..9bdff3635cf 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl @@ -69,7 +69,7 @@ CREATE TABLE "RULES_PROFILES" ( "NAME" VARCHAR(100) NOT NULL, "DEFAULT_PROFILE" BOOLEAN DEFAULT FALSE, "PROVIDED" BOOLEAN NOT NULL DEFAULT FALSE, - "LANGUAGE" VARCHAR(16), + "LANGUAGE" VARCHAR(20), "PARENT_NAME" VARCHAR(100), "VERSION" INTEGER DEFAULT 1, "USED_PROFILE" BOOLEAN DEFAULT FALSE @@ -292,7 +292,7 @@ CREATE TABLE "PROJECTS" ( "QUALIFIER" VARCHAR(10), "KEE" VARCHAR(400), "ROOT_ID" INTEGER, - "LANGUAGE" VARCHAR(5), + "LANGUAGE" VARCHAR(20), "COPY_RESOURCE_ID" INTEGER, "LONG_NAME" VARCHAR(256), "PERSON_ID" INTEGER, 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; + } + } + } diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/333_update_language_key_max_size.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/333_update_language_key_max_size.rb new file mode 100644 index 00000000000..9ad14e01203 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/333_update_language_key_max_size.rb @@ -0,0 +1,31 @@ +# +# Sonar, entreprise quality control tool. +# Copyright (C) 2008-2012 SonarSource +# mailto:contact AT sonarsource DOT com +# +# Sonar is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# Sonar is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with Sonar; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 +# + +# +# Sonar 3.3 +# +class UpdateLanguageKeyMaxSize < ActiveRecord::Migration + + def self.up + change_column :projects, :language, :string, :null => true, :limit => 20 + change_column :rules_profiles, :language, :string, :null => true, :limit => 20 + end + +end