]> source.dussan.org Git - sonarqube.git/commitdiff
API: improve the pattern to define quality profiles. The extension point is org.sonar...
authorsimonbrandhof <simon.brandhof@gmail.com>
Fri, 8 Oct 2010 14:38:32 +0000 (14:38 +0000)
committersimonbrandhof <simon.brandhof@gmail.com>
Fri, 8 Oct 2010 14:38:32 +0000 (14:38 +0000)
46 files changed:
plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/SonarWayProfile.java
plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/SonarWayWithFindbugsProfile.java
plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/SunConventionsProfile.java
plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SonarWayProfileTest.java
plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SonarWayWithFindbugsProfileTest.java
plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SunConventionsProfileTest.java
plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsRuleRepository.java
plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/SonarWayWithFindbugsProfileTest.java
plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SonarWayProfileTest.java
plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SonarWayWithFindbugsProfileTest.java
plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SunConventionsProfileTest.java
sonar-plugin-api/src/main/java/org/sonar/api/profiles/AnnotationProfileDefinition.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/profiles/AnnotationProfileParser.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileDefinition.java
sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileDefinition.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileExporter.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileImporter.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileSerializer.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/ModelDefinition.java
sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileDefinitionTest.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileParserTest.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileExporterTest.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileImporterTest.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileParserTest.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileSerializerTest.java [new file with mode: 0644]
sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileExporterTest/exportEmptyProfile.xml [deleted file]
sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileExporterTest/exportProfile.xml [deleted file]
sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileExporterTest/exportRuleParameters.xml [deleted file]
sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileImporterTest/importProfile.xml [deleted file]
sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileImporterTest/importProfileWithRuleParameters.xml [deleted file]
sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileImporterTest/importProfileWithUnknownRuleParameter.xml [deleted file]
sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileImporterTest/nameAndLanguageShouldBeMandatory.xml [deleted file]
sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileParserTest/importProfile.xml [new file with mode: 0644]
sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileParserTest/importProfileWithRuleParameters.xml [new file with mode: 0644]
sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileParserTest/importProfileWithUnknownRuleParameter.xml [new file with mode: 0644]
sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileParserTest/nameAndLanguageShouldBeMandatory.xml [new file with mode: 0644]
sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileSerializerTest/exportEmptyProfile.xml [new file with mode: 0644]
sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileSerializerTest/exportProfile.xml [new file with mode: 0644]
sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileSerializerTest/exportRuleParameters.xml [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/platform/Platform.java
sonar-server/src/main/java/org/sonar/server/qualitymodel/DefaultModelManager.java
sonar-server/src/main/java/org/sonar/server/rules/ProfilesConsole.java
sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java
sonar-server/src/test/java/org/sonar/server/qualitymodel/DefaultModelManagerTest.java
sonar-server/src/test/java/org/sonar/server/rules/DeprecatedProfilesTest.java

index a189560a695e33f2876770bfe7de3c7a22716859..a0cf3410ce057d543b934d4b7eef9642903257ca 100644 (file)
  */
 package org.sonar.plugins.checkstyle;
 
+import org.sonar.api.profiles.ProfileDefinition;
 import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.profiles.XMLProfileDefinition;
-import org.sonar.api.resources.Java;
-import org.sonar.api.rules.RuleFinder;
+import org.sonar.api.profiles.XMLProfileParser;
+import org.sonar.api.utils.ValidationMessages;
 
-public final class SonarWayProfile extends XMLProfileDefinition {
+public final class SonarWayProfile extends ProfileDefinition {
 
-  public SonarWayProfile(RuleFinder ruleFinder) {
-    super(SunConventionsProfile.class.getClassLoader(), "org/sonar/plugins/checkstyle/profile-sonar-way.xml", ruleFinder);
+  private XMLProfileParser xmlProfileParser;
+
+  public SonarWayProfile(XMLProfileParser xmlProfileParser) {
+    this.xmlProfileParser = xmlProfileParser;
+  }
+
+  public RulesProfile createProfile(ValidationMessages messages) {
+    return xmlProfileParser.parseResource(getClass().getClassLoader(), "org/sonar/plugins/checkstyle/profile-sonar-way.xml", messages);
   }
 }
index 398f137c45130abadb06ececa2ab9d918373c1ab..d9b26e2b43fdf79d573b00d4c11195c9b02bdc2f 100644 (file)
@@ -21,9 +21,6 @@ package org.sonar.plugins.checkstyle;
 
 import org.sonar.api.profiles.ProfileDefinition;
 import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.profiles.XMLProfileDefinition;
-import org.sonar.api.resources.Java;
-import org.sonar.api.rules.RuleFinder;
 import org.sonar.api.utils.ValidationMessages;
 
 public class SonarWayWithFindbugsProfile extends ProfileDefinition {
index 6351afed31c5fbd30d909ecda27c4796ca4d72f3..82b0e8b71770bf4f512ab2f8e3b50780ca9e88ea 100644 (file)
  */
 package org.sonar.plugins.checkstyle;
 
+import org.sonar.api.profiles.ProfileDefinition;
 import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.profiles.XMLProfileDefinition;
-import org.sonar.api.resources.Java;
-import org.sonar.api.rules.RuleFinder;
+import org.sonar.api.profiles.XMLProfileParser;
+import org.sonar.api.utils.ValidationMessages;
 
-public final class SunConventionsProfile extends XMLProfileDefinition {
+public final class SunConventionsProfile extends ProfileDefinition {
 
-  public SunConventionsProfile(RuleFinder ruleFinder) {
-    super(SunConventionsProfile.class.getClassLoader(), "org/sonar/plugins/checkstyle/profile-sun-conventions.xml", ruleFinder);
+  private XMLProfileParser xmlProfileParser;
+
+  public SunConventionsProfile(XMLProfileParser xmlProfileParser) {
+    this.xmlProfileParser = xmlProfileParser;
   }
+
+
+  public RulesProfile createProfile(ValidationMessages messages) {
+    return xmlProfileParser.parseResource(getClass().getClassLoader(), "org/sonar/plugins/checkstyle/profile-sun-conventions.xml", messages);
+  }
+
 }
index 268f94fe15b22799810cdb78051b4747cd955cf1..23a396505175ea34704fa7b8edb38aae807ef771 100644 (file)
@@ -24,6 +24,7 @@ import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 import org.sonar.api.profiles.ProfileDefinition;
 import org.sonar.api.profiles.RulesProfile;
+import org.sonar.api.profiles.XMLProfileParser;
 import org.sonar.api.rules.Rule;
 import org.sonar.api.rules.RuleFinder;
 import org.sonar.api.utils.ValidationMessages;
@@ -38,8 +39,8 @@ import static org.mockito.Mockito.when;
 public class SonarWayProfileTest {
 
   @Test
-  public void create() {
-    ProfileDefinition sonarWay = new SonarWayProfile(newRuleFinder());
+  public void shouldCreateProfile() {
+    ProfileDefinition sonarWay = new SonarWayProfile(new XMLProfileParser(newRuleFinder()));
     ValidationMessages validation = ValidationMessages.create();
     RulesProfile profile = sonarWay.createProfile(validation);
     assertThat(profile.getActiveRulesByRepository(CheckstyleConstants.REPOSITORY_KEY).size(), greaterThan(1));
index 6ed6bbca83c0b5ca8aa142ef1eeb26859883169d..d5af6c0b2367ad6bdc916b30040e14f60ae6cc0f 100644 (file)
@@ -23,11 +23,12 @@ import org.junit.Test;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 import org.sonar.api.profiles.RulesProfile;
+import org.sonar.api.profiles.XMLProfileParser;
 import org.sonar.api.rules.Rule;
 import org.sonar.api.rules.RuleFinder;
 import org.sonar.api.utils.ValidationMessages;
-import static org.hamcrest.core.Is.is;
 
+import static org.hamcrest.core.Is.is;
 import static org.junit.Assert.assertThat;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Mockito.mock;
@@ -36,9 +37,9 @@ import static org.mockito.Mockito.when;
 public class SonarWayWithFindbugsProfileTest {
 
   @Test
-  public void sameAsSonarWay() {
+  public void shouldBeSameAsSonarWay() {
     RuleFinder ruleFinder = newRuleFinder();
-    SonarWayProfile sonarWay = new SonarWayProfile(ruleFinder);
+    SonarWayProfile sonarWay = new SonarWayProfile(new XMLProfileParser(ruleFinder));
     RulesProfile withoutFindbugs = sonarWay.createProfile(ValidationMessages.create());
     RulesProfile withFindbugs = new SonarWayWithFindbugsProfile(sonarWay).createProfile(ValidationMessages.create());
     assertThat(withFindbugs.getActiveRules().size(), is(withoutFindbugs.getActiveRules().size()));
index ff80d97a02e365f207a0a1e339bb0b0e248e727b..147006e30eb764dd0d109fcb9060786d1ef584c1 100644 (file)
@@ -25,6 +25,7 @@ import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 import org.sonar.api.profiles.ProfileDefinition;
 import org.sonar.api.profiles.RulesProfile;
+import org.sonar.api.profiles.XMLProfileParser;
 import org.sonar.api.rules.Rule;
 import org.sonar.api.rules.RuleFinder;
 import org.sonar.api.utils.ValidationMessages;
@@ -37,8 +38,8 @@ import static org.mockito.Mockito.when;
 
 public class SunConventionsProfileTest {
   @Test
-  public void create() {
-    ProfileDefinition definition = new SunConventionsProfile(newRuleFinder());
+  public void shouldCreateProfile() {
+    ProfileDefinition definition = new SunConventionsProfile(new XMLProfileParser(newRuleFinder()));
     ValidationMessages validation = ValidationMessages.create();
     RulesProfile sunProfile = definition.createProfile(validation);
     assertThat(sunProfile.getActiveRulesByRepository(CheckstyleConstants.REPOSITORY_KEY).size(), greaterThan(1));
index bf4b11febb6206401002d7b6f797a0478b85ae22..0f43b2cd4d290f19a8752a7658305b46827d89b9 100644 (file)
  */
 package org.sonar.plugins.findbugs;
 
-import java.util.ArrayList;
-import java.util.List;
-
-import org.sonar.api.platform.ServerFileSystem;
 import org.sonar.api.resources.Java;
 import org.sonar.api.rules.Rule;
 import org.sonar.api.rules.RuleRepository;
 import org.sonar.api.rules.XMLRuleParser;
 
+import java.util.List;
+
 public final class FindbugsRuleRepository extends RuleRepository {
 
   public FindbugsRuleRepository() {
@@ -37,8 +35,6 @@ public final class FindbugsRuleRepository extends RuleRepository {
 
   @Override
   public List<Rule> createRules() {
-    List<Rule> rules = new ArrayList<Rule>();
-    rules.addAll(XMLRuleParser.parseXML(getClass().getResourceAsStream("/org/sonar/plugins/findbugs/rules.xml")));
-    return rules;
+    return XMLRuleParser.parseXML(getClass().getResourceAsStream("/org/sonar/plugins/findbugs/rules.xml"));
   }
 }
index 0d1e3b731125d68bef3823a090c5d1ab7019ee54..881fbf9a36b9fadac2cf7e069456a56ec47c6fc7 100644 (file)
@@ -30,7 +30,7 @@ import org.sonar.api.utils.ValidationMessages;
 public class SonarWayWithFindbugsProfileTest {
 
   @Test
-  public void create() {
+  public void shouldCreateProfile() {
     FindbugsProfileImporter importer = new FindbugsProfileImporter(new FindbugsRuleFinder());
     SonarWayWithFindbugsProfile sonarWayWithFindbugs = new SonarWayWithFindbugsProfile(importer);
     ValidationMessages validation = ValidationMessages.create();
index 966021adfc43dcbe27db28077a65fb7faefb673c..844dfa9100e6cf2deea627b1a76d5f13ec190deb 100644 (file)
@@ -40,7 +40,7 @@ import org.sonar.api.utils.ValidationMessages;
 public class SonarWayProfileTest {
 
   @Test
-  public void create() {
+  public void shouldCreateProfile() {
     ProfileDefinition sonarWay = new SonarWayProfile(createPmdProfileImporter());
     ValidationMessages validation = ValidationMessages.create();
     RulesProfile profile = sonarWay.createProfile(validation);
index 95f8ffc4592dd92cc9bcb35bef92e2bce111aafe..7f0aa81c9698dd17557e8cebbd3b7497c199f031 100644 (file)
@@ -39,7 +39,7 @@ import org.sonar.api.utils.ValidationMessages;
 public class SonarWayWithFindbugsProfileTest {
 
   @Test
-  public void create() {
+  public void shouldCreateProfile() {
     SonarWayWithFindbugsProfile sonarWayWithFindbugs = new SonarWayWithFindbugsProfile(new SonarWayProfile(createPmdProfileImporter()));
     ValidationMessages validation = ValidationMessages.create();
     RulesProfile profile = sonarWayWithFindbugs.createProfile(validation);
index bd9a6f9fffbe768524dc671bb58413c418120e1e..cdd9f1e396d383f6490caf73518c973ed94a6a77 100644 (file)
@@ -38,7 +38,7 @@ import org.sonar.api.utils.ValidationMessages;
 
 public class SunConventionsProfileTest {
   @Test
-  public void create() {
+  public void shouldCreateProfile() {
     SunConventionsProfile sunConvention = new SunConventionsProfile(createPmdProfileImporter());
     ValidationMessages validation = ValidationMessages.create();
     RulesProfile profile = sunConvention.createProfile(validation);
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/AnnotationProfileDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/AnnotationProfileDefinition.java
deleted file mode 100644 (file)
index a5cbf14..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * 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
- */
-package org.sonar.api.profiles;
-
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleAnnotationUtils;
-import org.sonar.api.rules.RuleFinder;
-import org.sonar.api.rules.RulePriority;
-import org.sonar.api.utils.ValidationMessages;
-import org.sonar.check.BelongsToProfile;
-
-import java.util.Collection;
-
-/**
- * @since 2.3
- */
-public abstract class AnnotationProfileDefinition extends ProfileDefinition {
-
-  private String name;
-  private String language;
-  private String repositoryKey;
-  private Collection<Class> annotatedClasses;
-  private RuleFinder ruleFinder;
-
-  protected AnnotationProfileDefinition(String repositoryKey, String profileName, String language, Collection<Class> annotatedClasses, RuleFinder ruleFinder) {
-    this.name = profileName;
-    this.language = language;
-    this.repositoryKey = repositoryKey;
-    this.annotatedClasses = annotatedClasses;
-    this.ruleFinder = ruleFinder;
-  }
-
-  @Override
-  public RulesProfile createProfile(ValidationMessages validation) {
-    RulesProfile profile = RulesProfile.create(name, language);
-    if (annotatedClasses != null) {
-      for (Class aClass : annotatedClasses) {
-        BelongsToProfile belongsToProfile = (BelongsToProfile) aClass.getAnnotation(BelongsToProfile.class);
-        registerRule(aClass, belongsToProfile, profile, validation);
-      }
-    }
-    return profile;
-  }
-
-  private void registerRule(Class aClass, BelongsToProfile belongsToProfile, RulesProfile profile, ValidationMessages validation) {
-    if (belongsToProfile != null) {
-      String ruleKey = RuleAnnotationUtils.getRuleKey(aClass);
-      Rule rule = ruleFinder.findByKey(repositoryKey, ruleKey);
-      if (rule == null) {
-        validation.addErrorText("Rule not found: [repository=" + repositoryKey + ", key=" + ruleKey + "]");
-
-      } else {
-        RulePriority priority = null;
-        if (belongsToProfile.priority() != null) {
-          priority = RulePriority.fromCheckPriority(belongsToProfile.priority());
-        }
-        profile.activateRule(rule, priority);
-      }
-    }
-  }
-}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/AnnotationProfileParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/AnnotationProfileParser.java
new file mode 100644 (file)
index 0000000..5fc713e
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * 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
+ */
+package org.sonar.api.profiles;
+
+import org.apache.commons.lang.StringUtils;
+import org.sonar.api.ServerComponent;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.RuleAnnotationUtils;
+import org.sonar.api.rules.RuleFinder;
+import org.sonar.api.rules.RulePriority;
+import org.sonar.api.utils.ValidationMessages;
+import org.sonar.check.BelongsToProfile;
+
+import java.util.Collection;
+
+/**
+ * @since 2.3
+ */
+public final class AnnotationProfileParser implements ServerComponent {
+
+  private RuleFinder ruleFinder;
+
+  public AnnotationProfileParser(RuleFinder ruleFinder) {
+    this.ruleFinder = ruleFinder;
+  }
+
+  public RulesProfile parse(String repositoryKey, String profileName, String language, Collection<Class> annotatedClasses, ValidationMessages messages) {
+    RulesProfile profile = RulesProfile.create(profileName, language);
+    for (Class aClass : annotatedClasses) {
+      BelongsToProfile belongsToProfile = (BelongsToProfile) aClass.getAnnotation(BelongsToProfile.class);
+      addRule(aClass, belongsToProfile, profile, repositoryKey, messages);
+    }
+    return profile;
+  }
+
+  private void addRule(Class aClass, BelongsToProfile annotation, RulesProfile profile, String repositoryKey, ValidationMessages messages) {
+    if (annotation != null && StringUtils.equals(annotation.title(), profile.getName())) {
+      String ruleKey = RuleAnnotationUtils.getRuleKey(aClass);
+      Rule rule = ruleFinder.findByKey(repositoryKey, ruleKey);
+      if (rule == null) {
+        messages.addWarningText("Rule not found: [repository=" + repositoryKey + ", key=" + ruleKey + "]");
+
+      } else {
+        RulePriority priority = null;
+        if (annotation.priority() != null) {
+          priority = RulePriority.fromCheckPriority(annotation.priority());
+        }
+        profile.activateRule(rule, priority);
+      }
+    }
+  }
+}
index e37343a9abfcb4448e2c63c07d8fe6e1fa54d47f..69aa3c99b73993d48cc9e75f890d7b703217a364 100644 (file)
@@ -23,6 +23,9 @@ import org.sonar.api.ServerExtension;
 import org.sonar.api.utils.ValidationMessages;
 
 /**
+ * Define a profile which is automatically registered during sonar startup.
+ * The components <code>AnnotationProfileParser</code> and <code>XMLProfileParser</code> can be used to help implementing the method create().
+ *
  * @since 2.3
  */
 public abstract class ProfileDefinition implements ServerExtension {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileDefinition.java
deleted file mode 100644 (file)
index 9cbbe4e..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * 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
- */
-package org.sonar.api.profiles;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.CharEncoding;
-import org.sonar.api.rules.RuleFinder;
-import org.sonar.api.utils.SonarException;
-import org.sonar.api.utils.ValidationMessages;
-
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.nio.charset.Charset;
-import java.util.List;
-
-/**
- * @since 2.3
- */
-public abstract class XMLProfileDefinition extends ProfileDefinition {
-
-  private RuleFinder ruleFinder;
-  private ClassLoader classloader;
-  private String xmlClassPath;
-
-  protected XMLProfileDefinition(ClassLoader classloader, String xmlClassPath, RuleFinder ruleFinder) {
-    this.ruleFinder = ruleFinder;
-    this.classloader = classloader;
-    this.xmlClassPath = xmlClassPath;
-  }
-
-  @Override
-  public final RulesProfile createProfile(ValidationMessages validation) {
-    Reader reader = new InputStreamReader(classloader.getResourceAsStream(xmlClassPath), Charset.forName(CharEncoding.UTF_8));
-    try {
-      return XMLProfileImporter.create(ruleFinder).importProfile(reader, validation);
-
-    } finally {
-      IOUtils.closeQuietly(reader);
-    }
-  }
-}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileExporter.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileExporter.java
deleted file mode 100644 (file)
index ee78f36..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * 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
- */
-package org.sonar.api.profiles;
-
-import org.apache.commons.lang.StringEscapeUtils;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.rules.ActiveRule;
-import org.sonar.api.rules.ActiveRuleParam;
-import org.sonar.api.utils.SonarException;
-
-import java.io.IOException;
-import java.io.Writer;
-
-/**
- * @since 2.3
- */
-public final class XMLProfileExporter  {
-
-  public static XMLProfileExporter create() {
-    return new XMLProfileExporter();
-  }
-
-  public void exportProfile(RulesProfile profile, Writer writer) {
-    try {
-      appendHeader(profile, writer);
-      appendRules(profile, writer);
-      appendFooter(writer);
-
-    } catch (IOException e) {
-      throw new SonarException("Fail to export the profile " + profile, e);
-    }
-  }
-
-  private void appendHeader(RulesProfile profile, Writer writer) throws IOException {
-    writer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
-        + "<!-- Generated by Sonar -->"
-        + "<profile><name>");
-    StringEscapeUtils.escapeXml(writer, profile.getName());
-    writer.append("</name><language>");
-    StringEscapeUtils.escapeXml(writer, profile.getLanguage());
-    writer.append("</language>");
-  }
-
-  private void appendRules(RulesProfile profile, Writer writer) throws IOException {
-    if (!profile.getActiveRules().isEmpty()) {
-      writer.append("<rules>");
-      for (ActiveRule activeRule : profile.getActiveRules()) {
-        appendRule(activeRule, writer);
-      }
-      writer.append("</rules>");
-    }
-  }
-
-  private void appendRule(ActiveRule activeRule, Writer writer) throws IOException {
-    writer.append("<rule><repositoryKey>");
-    writer.append(activeRule.getRepositoryKey());
-    writer.append("</repositoryKey><key>");
-    StringEscapeUtils.escapeXml(writer, activeRule.getRuleKey());
-    writer.append("</key>");
-    if (activeRule.getPriority() != null) {
-      writer.append("<priority>");
-      writer.append(activeRule.getPriority().name());
-      writer.append("</priority>");
-    }
-    appendRuleParameters(activeRule, writer);
-    writer.append("</rule>");
-  }
-
-  private void appendRuleParameters(ActiveRule activeRule, Writer writer) throws IOException {
-    if (activeRule.getActiveRuleParams() != null && !activeRule.getActiveRuleParams().isEmpty()) {
-      writer.append("<parameters>");
-      for (ActiveRuleParam activeRuleParam : activeRule.getActiveRuleParams()) {
-        appendRuleParameter(writer, activeRuleParam);
-      }
-      writer.append("</parameters>");
-    }
-  }
-
-  private void appendRuleParameter(Writer writer, ActiveRuleParam activeRuleParam) throws IOException {
-    if (StringUtils.isNotBlank(activeRuleParam.getValue())) {
-      writer.append("<parameter><key>");
-      StringEscapeUtils.escapeXml(writer, activeRuleParam.getKey());
-      writer.append("</key><value>");
-      StringEscapeUtils.escapeXml(writer, activeRuleParam.getValue());
-      writer.append("</value>");
-      writer.append("</parameter>");
-    }
-  }
-
-  private void appendFooter(Writer writer) throws IOException {
-    writer.append("</profile>");
-  }
-}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileImporter.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileImporter.java
deleted file mode 100644 (file)
index 3a13d82..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * 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
- */
-package org.sonar.api.profiles;
-
-import org.apache.commons.lang.StringUtils;
-import org.codehaus.stax2.XMLInputFactory2;
-import org.codehaus.staxmate.SMInputFactory;
-import org.codehaus.staxmate.in.SMHierarchicCursor;
-import org.codehaus.staxmate.in.SMInputCursor;
-import org.sonar.api.rules.ActiveRule;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleFinder;
-import org.sonar.api.rules.RulePriority;
-import org.sonar.api.utils.ValidationMessages;
-
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-import java.io.Reader;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @since 2.3
- */
-public final class XMLProfileImporter {
-
-  private RuleFinder ruleFinder;
-
-  private XMLProfileImporter(RuleFinder ruleFinder) {
-    this.ruleFinder = ruleFinder;
-  }
-
-  public static XMLProfileImporter create(RuleFinder ruleFinder) {
-    return new XMLProfileImporter(ruleFinder);
-  }
-
-  public RulesProfile importProfile(Reader reader, ValidationMessages messages) {
-    RulesProfile profile = RulesProfile.create();
-    SMInputFactory inputFactory = initStax();
-    try {
-      SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader);
-      rootC.advance(); // <profile>
-      SMInputCursor cursor = rootC.childElementCursor();
-      while (cursor.getNext() != null) {
-        String nodeName = cursor.getLocalName();
-        if (StringUtils.equals("rules", nodeName)) {
-          SMInputCursor rulesCursor = cursor.childElementCursor("rule");
-          processRules(rulesCursor, profile, messages);
-
-        } else if (StringUtils.equals("name", nodeName)) {
-          profile.setName(StringUtils.trim(cursor.collectDescendantText(false)));
-
-        } else if (StringUtils.equals("language", nodeName)) {
-          profile.setLanguage(StringUtils.trim(cursor.collectDescendantText(false)));
-        }
-      }
-    } catch (XMLStreamException e) {
-      messages.addErrorText("XML is not valid: " + e.getMessage());
-    }
-    checkProfile(profile, messages);
-    return profile;
-  }
-
-  private void checkProfile(RulesProfile profile, ValidationMessages messages) {
-    if (StringUtils.isBlank(profile.getName())) {
-      messages.addErrorText("The mandatory node <name> is missing.");
-    }
-    if (StringUtils.isBlank(profile.getLanguage())) {
-      messages.addErrorText("The mandatory node <language> is missing.");
-    }
-  }
-
-  private SMInputFactory initStax() {
-    XMLInputFactory xmlFactory = XMLInputFactory2.newInstance();
-    xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
-    xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE);
-    // just so it won't try to load DTD in if there's DOCTYPE
-    xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
-    xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
-    SMInputFactory inputFactory = new SMInputFactory(xmlFactory);
-    return inputFactory;
-  }
-
-  private void processRules(SMInputCursor rulesCursor, RulesProfile profile, ValidationMessages messages) throws XMLStreamException {
-    Map<String, String> parameters = new HashMap<String, String>();
-    while (rulesCursor.getNext() != null) {
-      SMInputCursor ruleCursor = rulesCursor.childElementCursor();
-
-      String repositoryKey = null, key = null;
-      RulePriority priority = null;
-      parameters.clear();
-
-      while (ruleCursor.getNext() != null) {
-        String nodeName = ruleCursor.getLocalName();
-
-        if (StringUtils.equals("repositoryKey", nodeName)) {
-          repositoryKey = StringUtils.trim(ruleCursor.collectDescendantText(false));
-
-        } else if (StringUtils.equals("key", nodeName)) {
-          key = StringUtils.trim(ruleCursor.collectDescendantText(false));
-
-        } else if (StringUtils.equals("priority", nodeName)) {
-          priority = RulePriority.valueOf(StringUtils.trim(ruleCursor.collectDescendantText(false)));
-
-        } else if (StringUtils.equals("parameters", nodeName)) {
-          SMInputCursor propsCursor = ruleCursor.childElementCursor("parameter");
-          processParameters(propsCursor, parameters);
-        }
-      }
-
-      Rule rule = ruleFinder.findByKey(repositoryKey, key);
-      if (rule == null) {
-        messages.addWarningText("Rule not found: [repository=" + repositoryKey + ", key=" + key + "]");
-
-      } else {
-        ActiveRule activeRule = profile.activateRule(rule, priority);
-        for (Map.Entry<String, String> entry : parameters.entrySet()) {
-          if (rule.getParam(entry.getKey()) == null) {
-            messages.addWarningText("The parameter '" + entry.getKey() + "' does not exist in the rule: [repository=" + repositoryKey + ", key=" + key + "]");
-          } else {
-            activeRule.setParameter(entry.getKey(), entry.getValue());
-          }
-        }
-      }
-    }
-  }
-
-  private void processParameters(SMInputCursor propsCursor, Map<String, String> parameters) throws XMLStreamException {
-    while (propsCursor.getNext() != null) {
-      SMInputCursor propCursor = propsCursor.childElementCursor();
-      String key = null;
-      String value = null;
-      while (propCursor.getNext() != null) {
-        String nodeName = propCursor.getLocalName();
-        if (StringUtils.equals("key", nodeName)) {
-          key = StringUtils.trim(propCursor.collectDescendantText(false));
-
-        } else if (StringUtils.equals("value", nodeName)) {
-          value = StringUtils.trim(propCursor.collectDescendantText(false));
-        }
-      }
-      if (key != null) {
-        parameters.put(key, value);
-      }
-    }
-  }
-
-
-}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java
new file mode 100644 (file)
index 0000000..571e2fd
--- /dev/null
@@ -0,0 +1,177 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * 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
+ */
+package org.sonar.api.profiles;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.CharEncoding;
+import org.apache.commons.lang.StringUtils;
+import org.codehaus.stax2.XMLInputFactory2;
+import org.codehaus.staxmate.SMInputFactory;
+import org.codehaus.staxmate.in.SMHierarchicCursor;
+import org.codehaus.staxmate.in.SMInputCursor;
+import org.sonar.api.ServerComponent;
+import org.sonar.api.rules.ActiveRule;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.RuleFinder;
+import org.sonar.api.rules.RulePriority;
+import org.sonar.api.utils.ValidationMessages;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.nio.charset.Charset;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @since 2.3
+ */
+public final class XMLProfileParser implements ServerComponent {
+
+  private RuleFinder ruleFinder;
+
+  public XMLProfileParser(RuleFinder ruleFinder) {
+    this.ruleFinder = ruleFinder;
+  }
+
+  public RulesProfile parseResource(ClassLoader classloader, String xmlClassPath, ValidationMessages messages) {
+    Reader reader = new InputStreamReader(classloader.getResourceAsStream(xmlClassPath), Charset.forName(CharEncoding.UTF_8));
+    try {
+      return parse(reader, messages);
+
+    } finally {
+      IOUtils.closeQuietly(reader);
+    }
+  }
+
+  public RulesProfile parse(Reader reader, ValidationMessages messages) {
+    RulesProfile profile = RulesProfile.create();
+    SMInputFactory inputFactory = initStax();
+    try {
+      SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader);
+      rootC.advance(); // <profile>
+      SMInputCursor cursor = rootC.childElementCursor();
+      while (cursor.getNext() != null) {
+        String nodeName = cursor.getLocalName();
+        if (StringUtils.equals("rules", nodeName)) {
+          SMInputCursor rulesCursor = cursor.childElementCursor("rule");
+          processRules(rulesCursor, profile, messages);
+
+        } else if (StringUtils.equals("name", nodeName)) {
+          profile.setName(StringUtils.trim(cursor.collectDescendantText(false)));
+
+        } else if (StringUtils.equals("language", nodeName)) {
+          profile.setLanguage(StringUtils.trim(cursor.collectDescendantText(false)));
+        }
+      }
+    } catch (XMLStreamException e) {
+      messages.addErrorText("XML is not valid: " + e.getMessage());
+    }
+    checkProfile(profile, messages);
+    return profile;
+  }
+
+  private void checkProfile(RulesProfile profile, ValidationMessages messages) {
+    if (StringUtils.isBlank(profile.getName())) {
+      messages.addErrorText("The mandatory node <name> is missing.");
+    }
+    if (StringUtils.isBlank(profile.getLanguage())) {
+      messages.addErrorText("The mandatory node <language> is missing.");
+    }
+  }
+
+  private SMInputFactory initStax() {
+    XMLInputFactory xmlFactory = XMLInputFactory2.newInstance();
+    xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
+    xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE);
+    // just so it won't try to load DTD in if there's DOCTYPE
+    xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
+    xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
+    SMInputFactory inputFactory = new SMInputFactory(xmlFactory);
+    return inputFactory;
+  }
+
+  private void processRules(SMInputCursor rulesCursor, RulesProfile profile, ValidationMessages messages) throws XMLStreamException {
+    Map<String, String> parameters = new HashMap<String, String>();
+    while (rulesCursor.getNext() != null) {
+      SMInputCursor ruleCursor = rulesCursor.childElementCursor();
+
+      String repositoryKey = null, key = null;
+      RulePriority priority = null;
+      parameters.clear();
+
+      while (ruleCursor.getNext() != null) {
+        String nodeName = ruleCursor.getLocalName();
+
+        if (StringUtils.equals("repositoryKey", nodeName)) {
+          repositoryKey = StringUtils.trim(ruleCursor.collectDescendantText(false));
+
+        } else if (StringUtils.equals("key", nodeName)) {
+          key = StringUtils.trim(ruleCursor.collectDescendantText(false));
+
+        } else if (StringUtils.equals("priority", nodeName)) {
+          priority = RulePriority.valueOf(StringUtils.trim(ruleCursor.collectDescendantText(false)));
+
+        } else if (StringUtils.equals("parameters", nodeName)) {
+          SMInputCursor propsCursor = ruleCursor.childElementCursor("parameter");
+          processParameters(propsCursor, parameters);
+        }
+      }
+
+      Rule rule = ruleFinder.findByKey(repositoryKey, key);
+      if (rule == null) {
+        messages.addWarningText("Rule not found: [repository=" + repositoryKey + ", key=" + key + "]");
+
+      } else {
+        ActiveRule activeRule = profile.activateRule(rule, priority);
+        for (Map.Entry<String, String> entry : parameters.entrySet()) {
+          if (rule.getParam(entry.getKey()) == null) {
+            messages.addWarningText("The parameter '" + entry.getKey() + "' does not exist in the rule: [repository=" + repositoryKey + ", key=" + key + "]");
+          } else {
+            activeRule.setParameter(entry.getKey(), entry.getValue());
+          }
+        }
+      }
+    }
+  }
+
+  private void processParameters(SMInputCursor propsCursor, Map<String, String> parameters) throws XMLStreamException {
+    while (propsCursor.getNext() != null) {
+      SMInputCursor propCursor = propsCursor.childElementCursor();
+      String key = null;
+      String value = null;
+      while (propCursor.getNext() != null) {
+        String nodeName = propCursor.getLocalName();
+        if (StringUtils.equals("key", nodeName)) {
+          key = StringUtils.trim(propCursor.collectDescendantText(false));
+
+        } else if (StringUtils.equals("value", nodeName)) {
+          value = StringUtils.trim(propCursor.collectDescendantText(false));
+        }
+      }
+      if (key != null) {
+        parameters.put(key, value);
+      }
+    }
+  }
+
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileSerializer.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileSerializer.java
new file mode 100644 (file)
index 0000000..e670002
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * 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
+ */
+package org.sonar.api.profiles;
+
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.lang.StringUtils;
+import org.sonar.api.ServerComponent;
+import org.sonar.api.rules.ActiveRule;
+import org.sonar.api.rules.ActiveRuleParam;
+import org.sonar.api.utils.SonarException;
+
+import java.io.IOException;
+import java.io.Writer;
+
+/**
+ * @since 2.3
+ */
+public final class XMLProfileSerializer implements ServerComponent {
+
+  public void write(RulesProfile profile, Writer writer) {
+    try {
+      appendHeader(profile, writer);
+      appendRules(profile, writer);
+      appendFooter(writer);
+
+    } catch (IOException e) {
+      throw new SonarException("Fail to export the profile " + profile, e);
+    }
+  }
+
+  private void appendHeader(RulesProfile profile, Writer writer) throws IOException {
+    writer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+        + "<!-- Generated by Sonar -->"
+        + "<profile><name>");
+    StringEscapeUtils.escapeXml(writer, profile.getName());
+    writer.append("</name><language>");
+    StringEscapeUtils.escapeXml(writer, profile.getLanguage());
+    writer.append("</language>");
+  }
+
+  private void appendRules(RulesProfile profile, Writer writer) throws IOException {
+    if (!profile.getActiveRules().isEmpty()) {
+      writer.append("<rules>");
+      for (ActiveRule activeRule : profile.getActiveRules()) {
+        appendRule(activeRule, writer);
+      }
+      writer.append("</rules>");
+    }
+  }
+
+  private void appendRule(ActiveRule activeRule, Writer writer) throws IOException {
+    writer.append("<rule><repositoryKey>");
+    writer.append(activeRule.getRepositoryKey());
+    writer.append("</repositoryKey><key>");
+    StringEscapeUtils.escapeXml(writer, activeRule.getRuleKey());
+    writer.append("</key>");
+    if (activeRule.getPriority() != null) {
+      writer.append("<priority>");
+      writer.append(activeRule.getPriority().name());
+      writer.append("</priority>");
+    }
+    appendRuleParameters(activeRule, writer);
+    writer.append("</rule>");
+  }
+
+  private void appendRuleParameters(ActiveRule activeRule, Writer writer) throws IOException {
+    if (activeRule.getActiveRuleParams() != null && !activeRule.getActiveRuleParams().isEmpty()) {
+      writer.append("<parameters>");
+      for (ActiveRuleParam activeRuleParam : activeRule.getActiveRuleParams()) {
+        appendRuleParameter(writer, activeRuleParam);
+      }
+      writer.append("</parameters>");
+    }
+  }
+
+  private void appendRuleParameter(Writer writer, ActiveRuleParam activeRuleParam) throws IOException {
+    if (StringUtils.isNotBlank(activeRuleParam.getValue())) {
+      writer.append("<parameter><key>");
+      StringEscapeUtils.escapeXml(writer, activeRuleParam.getKey());
+      writer.append("</key><value>");
+      StringEscapeUtils.escapeXml(writer, activeRuleParam.getValue());
+      writer.append("</value>");
+      writer.append("</parameter>");
+    }
+  }
+
+  private void appendFooter(Writer writer) throws IOException {
+    writer.append("</profile>");
+  }
+}
index 416059c0cad37c2579ced8376878a45bed6a31a2..6a8eb7aaf7ca15d1f0d992aa776d96f132cbea17 100644 (file)
@@ -41,7 +41,7 @@ public abstract class ModelDefinition implements ServerExtension {
     return name;
   }
 
-  public abstract Model create();
+  public abstract Model createModel();
 
   @Override
   public final boolean equals(Object o) {
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileDefinitionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileDefinitionTest.java
deleted file mode 100644 (file)
index 45e6bee..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * 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
- */
-package org.sonar.api.profiles;
-
-import org.junit.Test;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleFinder;
-import org.sonar.api.rules.RulePriority;
-import org.sonar.api.utils.ValidationMessages;
-import org.sonar.check.BelongsToProfile;
-import org.sonar.check.Check;
-import org.sonar.check.IsoCategory;
-import org.sonar.check.Priority;
-
-import java.util.Arrays;
-import java.util.Collection;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class AnnotationProfileDefinitionTest {
-
-  @Test
-  public void importProfile() {
-    RuleFinder ruleFinder = mock(RuleFinder.class);
-    when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>(){
-      public Rule answer(InvocationOnMock iom) throws Throwable {
-        return Rule.create((String)iom.getArguments()[0], (String)iom.getArguments()[1], (String)iom.getArguments()[1]);
-      }
-    });
-
-    ProfileDefinition definition = new FakeDefinition(ruleFinder);
-    ValidationMessages validation = ValidationMessages.create();
-    RulesProfile profile = definition.createProfile(validation);
-    assertThat(profile.getActiveRule("squid", "fake").getPriority(), is(RulePriority.BLOCKER));
-    assertThat(validation.hasErrors(), is(false));
-  }
-}
-
-@BelongsToProfile(title = "not used !", priority = Priority.BLOCKER)
-@Check(key = "fake", isoCategory = IsoCategory.Efficiency, priority = Priority.CRITICAL)
-class FakeRule {
-
-}
-
-
-class FakeDefinition extends AnnotationProfileDefinition {
-
-  public FakeDefinition(RuleFinder ruleFinder) {
-    super("squid", "sonar way", "java", Arrays.<Class>asList(FakeRule.class), ruleFinder);
-  }
-}
\ No newline at end of file
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileParserTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileParserTest.java
new file mode 100644 (file)
index 0000000..a6d0c6a
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * 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
+ */
+package org.sonar.api.profiles;
+
+import com.google.common.collect.Lists;
+import org.junit.Test;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.RuleFinder;
+import org.sonar.api.rules.RulePriority;
+import org.sonar.api.utils.ValidationMessages;
+import org.sonar.check.BelongsToProfile;
+import org.sonar.check.IsoCategory;
+import org.sonar.check.Priority;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.*;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class AnnotationProfileParserTest {
+
+  @Test
+  public void shouldParseAnnotatedClasses() {
+    RuleFinder ruleFinder = mock(RuleFinder.class);
+    when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() {
+      public Rule answer(InvocationOnMock iom) throws Throwable {
+        return Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]);
+      }
+    });
+
+    ValidationMessages messages = ValidationMessages.create();
+    RulesProfile profile = new AnnotationProfileParser(ruleFinder).parse("squid", "Foo way", "java", Lists.<Class>newArrayList(FakeRule.class), messages);
+
+    assertThat(profile.getName(), is("Foo way"));
+    assertThat(profile.getLanguage(), is("java"));
+    assertThat(profile.getActiveRule("squid", "fake").getPriority(), is(RulePriority.BLOCKER));
+    assertThat(messages.hasErrors(), is(false));
+  }
+
+  @Test
+  public void shouldParseOnlyWantedProfile() {
+    RuleFinder ruleFinder = mock(RuleFinder.class);
+    when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() {
+      public Rule answer(InvocationOnMock iom) throws Throwable {
+        return Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]);
+      }
+    });
+
+    ValidationMessages messages = ValidationMessages.create();
+    RulesProfile profile = new AnnotationProfileParser(ruleFinder).parse("squid", "Foo way", "java", Lists.<Class>newArrayList(FakeRule.class, RuleOnOtherProfile.class), messages);
+
+    assertNotNull(profile.getActiveRule("squid", "fake"));
+    assertNull(profile.getActiveRule("squid", "other"));
+  }
+}
+
+@BelongsToProfile(title = "Other profile", priority = Priority.BLOCKER)
+@org.sonar.check.Rule(key = "other", isoCategory = IsoCategory.Efficiency, priority = Priority.CRITICAL)
+class RuleOnOtherProfile {
+}
+
+@BelongsToProfile(title = "Foo way", priority = Priority.BLOCKER)
+@org.sonar.check.Rule(key = "fake", isoCategory = IsoCategory.Efficiency, priority = Priority.CRITICAL)
+class FakeRule {
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileExporterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileExporterTest.java
deleted file mode 100644 (file)
index e43ce06..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * 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
- */
-package org.sonar.api.profiles;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.CharUtils;
-import org.custommonkey.xmlunit.Diff;
-import org.custommonkey.xmlunit.XMLUnit;
-import org.junit.Test;
-import org.sonar.api.rules.ActiveRule;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RulePriority;
-import org.xml.sax.SAXException;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringWriter;
-import java.io.Writer;
-
-import static org.junit.Assert.assertTrue;
-
-public class XMLProfileExporterTest {
-
-  @Test
-  public void exportEmptyProfile() throws IOException, SAXException {
-    Writer writer = new StringWriter();
-    RulesProfile profile = RulesProfile.create("sonar way", "java");
-    XMLProfileExporter.create().exportProfile(profile, writer);
-
-    assertSimilarXml("/org/sonar/api/profiles/XMLProfileExporterTest/exportEmptyProfile.xml", writer.toString());
-  }
-
-  @Test
-  public void exportProfile() throws IOException, SAXException {
-    Writer writer = new StringWriter();
-    RulesProfile profile = RulesProfile.create("sonar way", "java");
-    profile.activateRule(Rule.create("checkstyle", "IllegalRegexp", "illegal regexp"), RulePriority.BLOCKER);
-    XMLProfileExporter.create().exportProfile(profile, writer);
-
-    assertSimilarXml("/org/sonar/api/profiles/XMLProfileExporterTest/exportProfile.xml", writer.toString());
-  }
-
-  @Test
-  public void exportRuleParameters() throws IOException, SAXException {
-    Writer writer = new StringWriter();
-    RulesProfile profile = RulesProfile.create("sonar way", "java");
-    Rule rule = Rule.create("checkstyle", "IllegalRegexp", "illegal regexp");
-    rule.createParameter("format");
-    rule.createParameter("message");
-    rule.createParameter("tokens");
-
-    ActiveRule activeRule = profile.activateRule(rule, RulePriority.BLOCKER);
-    activeRule.setParameter("format", "foo");
-    activeRule.setParameter("message", "with special characters < > &");
-    // the tokens parameter is not set
-    XMLProfileExporter.create().exportProfile(profile, writer);
-
-    assertSimilarXml("/org/sonar/api/profiles/XMLProfileExporterTest/exportRuleParameters.xml", writer.toString());
-  }
-
-  public static void assertSimilarXml(String pathToExpectedXml, String xml) throws IOException, SAXException {
-    InputStream stream = XMLProfileExporterTest.class.getResourceAsStream(pathToExpectedXml);
-    try {
-      Diff diff = isSimilarXml(IOUtils.toString(stream), xml);
-      String message = "Diff: " + diff.toString() + CharUtils.LF + "XML: " + xml;
-      assertTrue(message, diff.similar());
-
-    } finally {
-      IOUtils.closeQuietly(stream);
-    }
-  }
-
-  static Diff isSimilarXml(String expectedXml, String xml) throws IOException, SAXException {
-    XMLUnit.setIgnoreWhitespace(true);
-    Diff diff = XMLUnit.compareXML(xml, expectedXml);
-    return diff;
-  }
-}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileImporterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileImporterTest.java
deleted file mode 100644 (file)
index 6358f1d..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * 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
- */
-package org.sonar.api.profiles;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.CharEncoding;
-import org.junit.Test;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.sonar.api.rules.ActiveRule;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleFinder;
-import org.sonar.api.rules.RulePriority;
-import org.sonar.api.utils.ValidationMessages;
-
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.io.UnsupportedEncodingException;
-
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.internal.matchers.StringContains.containsString;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class XMLProfileImporterTest {
-
-  @Test
-  public void importProfile() throws UnsupportedEncodingException {
-    Reader reader = new InputStreamReader(getClass().getResourceAsStream("/org/sonar/api/profiles/XMLProfileImporterTest/importProfile.xml"), CharEncoding.UTF_8);
-    try {
-      ValidationMessages validation = ValidationMessages.create();
-      RuleFinder ruleFinder = newRuleFinder();
-      RulesProfile profile = XMLProfileImporter.create(ruleFinder).importProfile(reader, validation);
-
-      assertThat(profile.getLanguage(), is("java"));
-      assertThat(profile.getName(), is("sonar way"));
-      assertThat(validation.hasErrors(), is(false));
-      assertNotNull(profile);
-      assertThat(profile.getActiveRule("checkstyle", "IllegalRegexp").getPriority(), is(RulePriority.CRITICAL));
-      
-    } finally {
-      IOUtils.closeQuietly(reader);
-    }
-  }
-
-  @Test
-  public void nameAndLanguageShouldBeMandatory() throws UnsupportedEncodingException {
-    Reader reader = new InputStreamReader(getClass().getResourceAsStream("/org/sonar/api/profiles/XMLProfileImporterTest/nameAndLanguageShouldBeMandatory.xml"), CharEncoding.UTF_8);
-    try {
-      ValidationMessages validation = ValidationMessages.create();
-      RuleFinder ruleFinder = newRuleFinder();
-      RulesProfile profile = XMLProfileImporter.create(ruleFinder).importProfile(reader, validation);
-
-      assertThat(validation.getErrors().size(), is(2));
-      assertThat(validation.getErrors().get(0) , containsString(""));
-
-    } finally {
-      IOUtils.closeQuietly(reader);
-    }
-  }
-
-  @Test
-  public void importProfileWithRuleParameters() throws UnsupportedEncodingException {
-    Reader reader = new InputStreamReader(getClass().getResourceAsStream("/org/sonar/api/profiles/XMLProfileImporterTest/importProfileWithRuleParameters.xml"), CharEncoding.UTF_8);
-    try {
-      ValidationMessages validation = ValidationMessages.create();
-      RuleFinder ruleFinder = newRuleFinder();
-      RulesProfile profile = XMLProfileImporter.create(ruleFinder).importProfile(reader, validation);
-
-      assertThat(validation.hasErrors(), is(false));
-      assertThat(validation.hasWarnings(), is(false));
-      ActiveRule rule = profile.getActiveRule("checkstyle", "IllegalRegexp");
-      assertThat(rule.getParameter("format"), is("foo"));
-      assertThat(rule.getParameter("message"), is("with special characters < > &"));
-
-    } finally {
-      IOUtils.closeQuietly(reader);
-    }
-  }
-
-  @Test
-  public void importProfileWithUnknownRuleParameter() throws UnsupportedEncodingException {
-    Reader reader = new InputStreamReader(getClass().getResourceAsStream("/org/sonar/api/profiles/XMLProfileImporterTest/importProfileWithUnknownRuleParameter.xml"), CharEncoding.UTF_8);
-    try {
-      ValidationMessages validation = ValidationMessages.create();
-      RuleFinder ruleFinder = newRuleFinder();
-      RulesProfile profile = XMLProfileImporter.create(ruleFinder).importProfile(reader, validation);
-
-      assertThat(validation.getWarnings().size(), is(1));
-      ActiveRule rule = profile.getActiveRule("checkstyle", "IllegalRegexp");
-      assertThat(rule.getParameter("unknown"), nullValue());
-
-    } finally {
-      IOUtils.closeQuietly(reader);
-    }
-  }
-
-  private RuleFinder newRuleFinder() {
-    RuleFinder ruleFinder = mock(RuleFinder.class);
-    when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>(){
-      public Rule answer(InvocationOnMock iom) throws Throwable {
-        Rule rule = Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]);
-        rule.createParameter("format");
-        rule.createParameter("message");
-        return rule;
-      }
-    });
-    return ruleFinder;
-  }
-}
\ No newline at end of file
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileParserTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileParserTest.java
new file mode 100644 (file)
index 0000000..3167cb9
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * 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
+ */
+package org.sonar.api.profiles;
+
+import org.junit.Test;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.sonar.api.rules.ActiveRule;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.RuleFinder;
+import org.sonar.api.rules.RulePriority;
+import org.sonar.api.utils.ValidationMessages;
+
+import java.io.UnsupportedEncodingException;
+
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.internal.matchers.StringContains.containsString;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class XMLProfileParserTest {
+
+  @Test
+  public void importProfile() throws UnsupportedEncodingException {
+    ValidationMessages validation = ValidationMessages.create();
+    RuleFinder ruleFinder = newRuleFinder();
+    RulesProfile profile = new XMLProfileParser(ruleFinder).parseResource(getClass().getClassLoader(), "org/sonar/api/profiles/XMLProfileParserTest/importProfile.xml", validation);
+
+    assertThat(profile.getLanguage(), is("java"));
+    assertThat(profile.getName(), is("sonar way"));
+    assertThat(validation.hasErrors(), is(false));
+    assertNotNull(profile);
+    assertThat(profile.getActiveRule("checkstyle", "IllegalRegexp").getPriority(), is(RulePriority.CRITICAL));
+  }
+
+  @Test
+  public void nameAndLanguageShouldBeMandatory() throws UnsupportedEncodingException {
+    ValidationMessages validation = ValidationMessages.create();
+    RuleFinder ruleFinder = newRuleFinder();
+    RulesProfile profile = new XMLProfileParser(ruleFinder).parseResource(getClass().getClassLoader(), "org/sonar/api/profiles/XMLProfileParserTest/nameAndLanguageShouldBeMandatory.xml", validation);
+
+    assertThat(validation.getErrors().size(), is(2));
+    assertThat(validation.getErrors().get(0), containsString(""));
+
+  }
+
+  @Test
+  public void importProfileWithRuleParameters() throws UnsupportedEncodingException {
+    ValidationMessages validation = ValidationMessages.create();
+    RuleFinder ruleFinder = newRuleFinder();
+    RulesProfile profile = new XMLProfileParser(ruleFinder).parseResource(getClass().getClassLoader(), "org/sonar/api/profiles/XMLProfileParserTest/importProfileWithRuleParameters.xml", validation);
+
+    assertThat(validation.hasErrors(), is(false));
+    assertThat(validation.hasWarnings(), is(false));
+    ActiveRule rule = profile.getActiveRule("checkstyle", "IllegalRegexp");
+    assertThat(rule.getParameter("format"), is("foo"));
+    assertThat(rule.getParameter("message"), is("with special characters < > &"));
+  }
+
+  @Test
+  public void importProfileWithUnknownRuleParameter() throws UnsupportedEncodingException {
+    ValidationMessages validation = ValidationMessages.create();
+    RuleFinder ruleFinder = newRuleFinder();
+    RulesProfile profile = new XMLProfileParser(ruleFinder).parseResource(getClass().getClassLoader(), "org/sonar/api/profiles/XMLProfileParserTest/importProfileWithUnknownRuleParameter.xml", validation);
+
+    assertThat(validation.getWarnings().size(), is(1));
+    ActiveRule rule = profile.getActiveRule("checkstyle", "IllegalRegexp");
+    assertThat(rule.getParameter("unknown"), nullValue());
+  }
+
+  private RuleFinder newRuleFinder() {
+    RuleFinder ruleFinder = mock(RuleFinder.class);
+    when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() {
+      public Rule answer(InvocationOnMock iom) throws Throwable {
+        Rule rule = Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]);
+        rule.createParameter("format");
+        rule.createParameter("message");
+        return rule;
+      }
+    });
+    return ruleFinder;
+  }
+}
\ No newline at end of file
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileSerializerTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileSerializerTest.java
new file mode 100644 (file)
index 0000000..90169f1
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * 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
+ */
+package org.sonar.api.profiles;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.CharUtils;
+import org.custommonkey.xmlunit.Diff;
+import org.custommonkey.xmlunit.XMLUnit;
+import org.junit.Test;
+import org.sonar.api.rules.ActiveRule;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.RulePriority;
+import org.xml.sax.SAXException;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import static org.junit.Assert.assertTrue;
+
+public class XMLProfileSerializerTest {
+
+  @Test
+  public void exportEmptyProfile() throws IOException, SAXException {
+    Writer writer = new StringWriter();
+    RulesProfile profile = RulesProfile.create("sonar way", "java");
+    new XMLProfileSerializer().write(profile, writer);
+
+    assertSimilarXml("/org/sonar/api/profiles/XMLProfileSerializerTest/exportEmptyProfile.xml", writer.toString());
+  }
+
+  @Test
+  public void exportProfile() throws IOException, SAXException {
+    Writer writer = new StringWriter();
+    RulesProfile profile = RulesProfile.create("sonar way", "java");
+    profile.activateRule(Rule.create("checkstyle", "IllegalRegexp", "illegal regexp"), RulePriority.BLOCKER);
+    new XMLProfileSerializer().write(profile, writer);
+
+    assertSimilarXml("/org/sonar/api/profiles/XMLProfileSerializerTest/exportProfile.xml", writer.toString());
+  }
+
+  @Test
+  public void exportRuleParameters() throws IOException, SAXException {
+    Writer writer = new StringWriter();
+    RulesProfile profile = RulesProfile.create("sonar way", "java");
+    Rule rule = Rule.create("checkstyle", "IllegalRegexp", "illegal regexp");
+    rule.createParameter("format");
+    rule.createParameter("message");
+    rule.createParameter("tokens");
+
+    ActiveRule activeRule = profile.activateRule(rule, RulePriority.BLOCKER);
+    activeRule.setParameter("format", "foo");
+    activeRule.setParameter("message", "with special characters < > &");
+    // the tokens parameter is not set
+    new XMLProfileSerializer().write(profile, writer);
+
+    assertSimilarXml("/org/sonar/api/profiles/XMLProfileSerializerTest/exportRuleParameters.xml", writer.toString());
+  }
+
+  public static void assertSimilarXml(String pathToExpectedXml, String xml) throws IOException, SAXException {
+    InputStream stream = XMLProfileSerializerTest.class.getResourceAsStream(pathToExpectedXml);
+    try {
+      Diff diff = isSimilarXml(IOUtils.toString(stream), xml);
+      String message = "Diff: " + diff.toString() + CharUtils.LF + "XML: " + xml;
+      assertTrue(message, diff.similar());
+
+    } finally {
+      IOUtils.closeQuietly(stream);
+    }
+  }
+
+  static Diff isSimilarXml(String expectedXml, String xml) throws IOException, SAXException {
+    XMLUnit.setIgnoreWhitespace(true);
+    Diff diff = XMLUnit.compareXML(xml, expectedXml);
+    return diff;
+  }
+}
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileExporterTest/exportEmptyProfile.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileExporterTest/exportEmptyProfile.xml
deleted file mode 100644 (file)
index 3bdb8fc..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated by Sonar -->
-<profile>
-  <name>sonar way</name>
-  <language>java</language>
-</profile>
\ No newline at end of file
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileExporterTest/exportProfile.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileExporterTest/exportProfile.xml
deleted file mode 100644 (file)
index 76779cd..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated by Sonar -->
-<profile>
-  <name>sonar way</name>
-  <language>java</language>
-  <rules>
-    <rule>
-      <repositoryKey>checkstyle</repositoryKey>
-      <key>IllegalRegexp</key>
-      <priority>BLOCKER</priority>
-    </rule>
-  </rules>
-</profile>
\ No newline at end of file
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileExporterTest/exportRuleParameters.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileExporterTest/exportRuleParameters.xml
deleted file mode 100644 (file)
index f3e2758..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated by Sonar -->
-<profile>
-  <name>sonar way</name>
-  <language>java</language>
-  <rules>
-    <rule>
-      <repositoryKey>checkstyle</repositoryKey>
-      <key>IllegalRegexp</key>
-      <priority>BLOCKER</priority>
-      <parameters>
-        <parameter>
-          <key>format</key>
-          <value>foo</value>
-        </parameter>
-        <parameter>
-          <key>message</key>
-          <value>with special characters &lt; &gt; &amp;</value>
-        </parameter>
-      </parameters>
-    </rule>
-  </rules>
-</profile>
\ No newline at end of file
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileImporterTest/importProfile.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileImporterTest/importProfile.xml
deleted file mode 100644 (file)
index 047c4c7..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated by Sonar -->
-<profile>
-  <name>sonar way</name>
-  <language>java</language>
-  <rules>
-    <rule>
-      <repositoryKey>checkstyle</repositoryKey>
-      <key>IllegalRegexp</key>
-      <priority>CRITICAL</priority>
-    </rule>
-  </rules>
-</profile>
\ No newline at end of file
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileImporterTest/importProfileWithRuleParameters.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileImporterTest/importProfileWithRuleParameters.xml
deleted file mode 100644 (file)
index f3e2758..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated by Sonar -->
-<profile>
-  <name>sonar way</name>
-  <language>java</language>
-  <rules>
-    <rule>
-      <repositoryKey>checkstyle</repositoryKey>
-      <key>IllegalRegexp</key>
-      <priority>BLOCKER</priority>
-      <parameters>
-        <parameter>
-          <key>format</key>
-          <value>foo</value>
-        </parameter>
-        <parameter>
-          <key>message</key>
-          <value>with special characters &lt; &gt; &amp;</value>
-        </parameter>
-      </parameters>
-    </rule>
-  </rules>
-</profile>
\ No newline at end of file
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileImporterTest/importProfileWithUnknownRuleParameter.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileImporterTest/importProfileWithUnknownRuleParameter.xml
deleted file mode 100644 (file)
index eb4a460..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated by Sonar -->
-<profile>
-  <name>sonar way</name>
-  <language>java</language>
-  <rules>
-    <rule>
-      <repositoryKey>checkstyle</repositoryKey>
-      <key>IllegalRegexp</key>
-      <priority>BLOCKER</priority>
-      <parameters>
-        <parameter>
-          <key>unknown</key>
-          <value>foo</value>
-        </parameter>
-      </parameters>
-    </rule>
-  </rules>
-</profile>
\ No newline at end of file
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileImporterTest/nameAndLanguageShouldBeMandatory.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileImporterTest/nameAndLanguageShouldBeMandatory.xml
deleted file mode 100644 (file)
index 303494e..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated by Sonar -->
-<profile>
-  <rules>
-    <rule>
-      <repositoryKey>checkstyle</repositoryKey>
-      <key>IllegalRegexp</key>
-      <priority>CRITICAL</priority>
-    </rule>
-  </rules>
-</profile>
\ No newline at end of file
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileParserTest/importProfile.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileParserTest/importProfile.xml
new file mode 100644 (file)
index 0000000..047c4c7
--- /dev/null
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated by Sonar -->
+<profile>
+  <name>sonar way</name>
+  <language>java</language>
+  <rules>
+    <rule>
+      <repositoryKey>checkstyle</repositoryKey>
+      <key>IllegalRegexp</key>
+      <priority>CRITICAL</priority>
+    </rule>
+  </rules>
+</profile>
\ No newline at end of file
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileParserTest/importProfileWithRuleParameters.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileParserTest/importProfileWithRuleParameters.xml
new file mode 100644 (file)
index 0000000..f3e2758
--- /dev/null
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated by Sonar -->
+<profile>
+  <name>sonar way</name>
+  <language>java</language>
+  <rules>
+    <rule>
+      <repositoryKey>checkstyle</repositoryKey>
+      <key>IllegalRegexp</key>
+      <priority>BLOCKER</priority>
+      <parameters>
+        <parameter>
+          <key>format</key>
+          <value>foo</value>
+        </parameter>
+        <parameter>
+          <key>message</key>
+          <value>with special characters &lt; &gt; &amp;</value>
+        </parameter>
+      </parameters>
+    </rule>
+  </rules>
+</profile>
\ No newline at end of file
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileParserTest/importProfileWithUnknownRuleParameter.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileParserTest/importProfileWithUnknownRuleParameter.xml
new file mode 100644 (file)
index 0000000..eb4a460
--- /dev/null
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated by Sonar -->
+<profile>
+  <name>sonar way</name>
+  <language>java</language>
+  <rules>
+    <rule>
+      <repositoryKey>checkstyle</repositoryKey>
+      <key>IllegalRegexp</key>
+      <priority>BLOCKER</priority>
+      <parameters>
+        <parameter>
+          <key>unknown</key>
+          <value>foo</value>
+        </parameter>
+      </parameters>
+    </rule>
+  </rules>
+</profile>
\ No newline at end of file
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileParserTest/nameAndLanguageShouldBeMandatory.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileParserTest/nameAndLanguageShouldBeMandatory.xml
new file mode 100644 (file)
index 0000000..303494e
--- /dev/null
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated by Sonar -->
+<profile>
+  <rules>
+    <rule>
+      <repositoryKey>checkstyle</repositoryKey>
+      <key>IllegalRegexp</key>
+      <priority>CRITICAL</priority>
+    </rule>
+  </rules>
+</profile>
\ No newline at end of file
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileSerializerTest/exportEmptyProfile.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileSerializerTest/exportEmptyProfile.xml
new file mode 100644 (file)
index 0000000..3bdb8fc
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated by Sonar -->
+<profile>
+  <name>sonar way</name>
+  <language>java</language>
+</profile>
\ No newline at end of file
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileSerializerTest/exportProfile.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileSerializerTest/exportProfile.xml
new file mode 100644 (file)
index 0000000..76779cd
--- /dev/null
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated by Sonar -->
+<profile>
+  <name>sonar way</name>
+  <language>java</language>
+  <rules>
+    <rule>
+      <repositoryKey>checkstyle</repositoryKey>
+      <key>IllegalRegexp</key>
+      <priority>BLOCKER</priority>
+    </rule>
+  </rules>
+</profile>
\ No newline at end of file
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileSerializerTest/exportRuleParameters.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileSerializerTest/exportRuleParameters.xml
new file mode 100644 (file)
index 0000000..f3e2758
--- /dev/null
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated by Sonar -->
+<profile>
+  <name>sonar way</name>
+  <language>java</language>
+  <rules>
+    <rule>
+      <repositoryKey>checkstyle</repositoryKey>
+      <key>IllegalRegexp</key>
+      <priority>BLOCKER</priority>
+      <parameters>
+        <parameter>
+          <key>format</key>
+          <value>foo</value>
+        </parameter>
+        <parameter>
+          <key>message</key>
+          <value>with special characters &lt; &gt; &amp;</value>
+        </parameter>
+      </parameters>
+    </rule>
+  </rules>
+</profile>
\ No newline at end of file
index 145ba28e3f43097cc7301d6752023a56d7c56c4e..48c321c0c0254d5cf49aa26fd061f8fb060a1faa 100644 (file)
@@ -28,6 +28,9 @@ import org.sonar.api.Plugins;
 import org.sonar.api.database.configuration.DatabaseConfiguration;
 import org.sonar.api.platform.Environment;
 import org.sonar.api.platform.Server;
+import org.sonar.api.profiles.AnnotationProfileParser;
+import org.sonar.api.profiles.XMLProfileParser;
+import org.sonar.api.profiles.XMLProfileSerializer;
 import org.sonar.api.resources.Languages;
 import org.sonar.api.rules.DefaultRulesManager;
 import org.sonar.api.utils.HttpDownloader;
@@ -169,6 +172,9 @@ public final class Platform {
     servicesContainer.as(Characteristics.NO_CACHE).addComponent(Backup.class);
     servicesContainer.as(Characteristics.CACHE).addComponent(AuthenticatorFactory.class);
     servicesContainer.as(Characteristics.CACHE).addComponent(ServerLifecycleNotifier.class);
+    servicesContainer.as(Characteristics.CACHE).addComponent(AnnotationProfileParser.class);
+    servicesContainer.as(Characteristics.CACHE).addComponent(XMLProfileParser.class);
+    servicesContainer.as(Characteristics.CACHE).addComponent(XMLProfileSerializer.class);
     servicesContainer.as(Characteristics.CACHE).addComponent(DefaultRuleFinder.class);
     servicesContainer.as(Characteristics.CACHE).addComponent(DeprecatedRuleRepositories.class);
     servicesContainer.as(Characteristics.CACHE).addComponent(DeprecatedProfiles.class);
index 84ccb3999bb6fb02ab0ad998dd60847769f1d4b4..0e5290a00128aaf26f37bd399b66d3263eeeaf06 100644 (file)
@@ -57,7 +57,7 @@ public final class DefaultModelManager implements ServerComponent, ModelManager
     for (ModelDefinition definition : definitions) {
       if (StringUtils.isNotBlank(definition.getName()) && !exists(session, definition.getName())) {
         Logs.INFO.info("Register quality model: " + definition.getName());
-        Model model = definition.create();
+        Model model = definition.createModel();
         if (StringUtils.isBlank(model.getName())) {
           model.setName(definition.getName());
         }
@@ -75,7 +75,7 @@ public final class DefaultModelManager implements ServerComponent, ModelManager
     }
 
     LoggerFactory.getLogger(getClass()).info("Reset quality model: " + name);
-    Model model = definition.create();
+    Model model = definition.createModel();
     return reset(model);
   }
 
index 64d525939bc1d91609f97c38b3cf3d28bc383f70..20b9605c86385bea812cc0d3363b29dddb5634f0 100644 (file)
@@ -40,14 +40,16 @@ import java.util.List;
 public final class ProfilesConsole implements ServerComponent {
 
   private DatabaseSessionFactory sessionFactory;
-  private RuleFinder ruleFinder;
+  private XMLProfileParser xmlProfileParser;
+  private XMLProfileSerializer xmlProfileSerializer;
   private List<ProfileExporter> exporters = new ArrayList<ProfileExporter>();
   private List<ProfileImporter> importers = new ArrayList<ProfileImporter>();
 
-  public ProfilesConsole(DatabaseSessionFactory sessionFactory, RuleFinder ruleFinder,
+  public ProfilesConsole(DatabaseSessionFactory sessionFactory, XMLProfileParser xmlProfileParser, XMLProfileSerializer xmlProfileSerializer,
                          ProfileExporter[] exporters, DeprecatedProfileExporters deprecatedExporters,
                          ProfileImporter[] importers, DeprecatedProfileImporters deprecatedImporters) {
-    this.ruleFinder = ruleFinder;
+    this.xmlProfileParser = xmlProfileParser;
+    this.xmlProfileSerializer = xmlProfileSerializer;
     this.sessionFactory = sessionFactory;
     initProfileExporters(exporters, deprecatedExporters);
     initProfileImporters(importers, deprecatedImporters);
@@ -72,7 +74,7 @@ public final class ProfilesConsole implements ServerComponent {
     RulesProfile profile = loadProfile(session, profileId);
     if (profile != null) {
       Writer writer = new StringWriter();
-      XMLProfileExporter.create().exportProfile(profile, writer);
+      xmlProfileSerializer.write(profile, writer);
       return writer.toString();
     }
     return null;
@@ -80,7 +82,7 @@ public final class ProfilesConsole implements ServerComponent {
 
   public ValidationMessages restoreProfile(String xmlBackup) {
     ValidationMessages messages = ValidationMessages.create();
-    RulesProfile profile = XMLProfileImporter.create(ruleFinder).importProfile(new StringReader(xmlBackup), messages);
+    RulesProfile profile = xmlProfileParser.parse(new StringReader(xmlBackup), messages);
     if (profile != null) {
       DatabaseSession session = sessionFactory.getSession();
       RulesProfile existingProfile = session.getSingleResult(RulesProfile.class, "name", profile.getName(), "language", profile.getLanguage());
index ad5ee2559d265a9633bc78d25f57d9d02d071b8e..82f0c94de889ad316555d64b229a3485a3e390b7 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.startup;
 
+import com.google.common.collect.Lists;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -40,7 +41,7 @@ public final class RegisterProvidedProfiles {
   private static final Logger LOGGER = LoggerFactory.getLogger(RegisterProvidedProfiles.class);
 
   private DatabaseSessionFactory sessionFactory;
-  private List<ProfileDefinition> definitions = new ArrayList<ProfileDefinition>();
+  private List<ProfileDefinition> definitions = Lists.newArrayList();
   private DeprecatedProfiles deprecatedProfiles = null;
   private RuleFinder ruleFinder;
 
@@ -71,7 +72,7 @@ public final class RegisterProvidedProfiles {
   }
 
   List<RulesProfile> createProfiles() {
-    List<RulesProfile> result = new ArrayList<RulesProfile>();
+    List<RulesProfile> result = Lists.newArrayList();
 
     // this must not be moved in the constructor, because rules are still not saved
     definitions.addAll(deprecatedProfiles.getProfiles());
index 058e649d5bce292baa3bdc371f724a2097538d09..73d2e9b893830169dbf3544766e8a8091f14073f 100644 (file)
@@ -114,7 +114,7 @@ class FakeDefinition extends ModelDefinition {
   }
 
   @Override
-  public Model create() {
+  public Model createModel() {
     return model;
   }
 
index cd5b40f38ab7157af525f251b746fcd164d268b6..187a3ed8e1f6b39b54fbe80e180f005f270576d2 100644 (file)
@@ -23,7 +23,6 @@ import org.junit.Test;
 import org.sonar.api.rules.Rule;
 import org.sonar.api.rules.RulePriority;
 import org.sonar.api.utils.ValidationMessages;
-import org.sonar.server.rules.DeprecatedProfiles;
 
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.core.IsNull.nullValue;
@@ -31,7 +30,7 @@ import static org.junit.Assert.assertThat;
 
 public class DeprecatedProfilesTest {
   @Test
-  public void testCreate() {
+  public void shouldCreateProfile() {
     DeprecatedProfiles.DefaultProfileDefinition def = DeprecatedProfiles.DefaultProfileDefinition.create("sonar way", "java");
     assertThat(def.createProfile(ValidationMessages.create()).getName(), is("sonar way"));
     assertThat(def.createProfile(ValidationMessages.create()).getLanguage(), is("java"));