aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-09-06 17:22:57 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-09-06 17:22:57 +0000
commitaef2286bf00aca219862aa62ef5dcac4bb9d2e9a (patch)
tree185ed172e4fd630b1b14c07b072e049fee6c4494 /sonar-plugin-api
parent4592819b97fd656bd857e319b6c26c008e2f50f2 (diff)
downloadsonarqube-aef2286bf00aca219862aa62ef5dcac4bb9d2e9a.tar.gz
sonarqube-aef2286bf00aca219862aa62ef5dcac4bb9d2e9a.zip
SONAR-1229 Export/Import a given Sonar quality profile
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/profiles/AnnotationProfileDefinition.java (renamed from sonar-plugin-api/src/main/java/org/sonar/api/profiles/AnnotationProfileImporter.java)13
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileDefinition.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileExporter.java71
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileImporter.java58
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileExporter.java7
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileImporter.java3
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/RulesManager.java16
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileDefinitionTest.java (renamed from sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileImporterTest.java)18
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/profiles/ProfileExporterTest.java18
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/profiles/ProfileImporterTest.java18
10 files changed, 156 insertions, 70 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/AnnotationProfileImporter.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/AnnotationProfileDefinition.java
index 83eec7a46a2..b071a24df8e 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/AnnotationProfileImporter.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/AnnotationProfileDefinition.java
@@ -20,32 +20,27 @@
package org.sonar.api.profiles;
import org.sonar.api.rules.RulePriority;
-import org.sonar.api.utils.ValidationMessages;
import org.sonar.check.AnnotationIntrospector;
import org.sonar.check.BelongsToProfile;
-import java.io.Reader;
import java.util.Collection;
/**
* @since 2.3
*/
-public final class AnnotationProfileImporter extends ProfileImporter {
+public abstract class AnnotationProfileDefinition extends ProfileDefinition {
private String repositoryKey;
private Collection<Class> annotatedClasses;
- AnnotationProfileImporter(String repositoryKey, Collection<Class> annotatedClasses) {
+ protected AnnotationProfileDefinition(String repositoryKey, String profileName, String language, Collection<Class> annotatedClasses) {
+ super(profileName, language);
this.repositoryKey = repositoryKey;
this.annotatedClasses = annotatedClasses;
}
- public static AnnotationProfileImporter create(String repositoryKey, Collection<Class> annotatedClasses) {
- return new AnnotationProfileImporter(repositoryKey, annotatedClasses);
- }
-
@Override
- public ProfilePrototype importProfile(Reader reader, ValidationMessages messages) {
+ public ProfilePrototype createPrototype() {
ProfilePrototype profile = ProfilePrototype.create();
if (annotatedClasses != null) {
for (Class aClass : annotatedClasses) {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileDefinition.java
index fb945bde59f..c722e5f7c5e 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileDefinition.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileDefinition.java
@@ -32,8 +32,8 @@ public abstract class ProfileDefinition implements ServerExtension {
protected ProfileDefinition() {
}
- protected ProfileDefinition(String name, String language) {
- this.name = name;
+ protected ProfileDefinition(String profileName, String language) {
+ this.name = profileName;
this.language = language;
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileExporter.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileExporter.java
index e439a4635ae..58e9a6b0b0e 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileExporter.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileExporter.java
@@ -19,6 +19,7 @@
*/
package org.sonar.api.profiles;
+import org.apache.commons.lang.StringUtils;
import org.sonar.api.BatchExtension;
import org.sonar.api.ServerExtension;
@@ -29,18 +30,76 @@ import java.io.Writer;
*/
public abstract class ProfileExporter implements BatchExtension, ServerExtension {
- private String[] supportedRepositories = new String[0];
+ private String[] supportedLanguages = new String[0];
+ private String key;
+ private String name;
+ private String mimeType = "plain/text";
+
+ protected ProfileExporter(String key, String name) {
+ this.key = key;
+ this.name = name;
+ }
public abstract void exportProfile(RulesProfile profile, Writer writer);
- protected final void setSupportedRepositories(String... repositoryKeys) {
- supportedRepositories = (repositoryKeys != null ? repositoryKeys : new String[0]);
+ public final String getKey() {
+ return key;
+ }
+
+ public final ProfileExporter setKey(String s) {
+ this.key = s;
+ return this;
+ }
+
+ public final String getName() {
+ return name;
+ }
+
+ public final ProfileExporter setName(String s) {
+ this.name = s;
+ return this;
+ }
+
+ protected final ProfileExporter setSupportedLanguages(String... languages) {
+ supportedLanguages = (languages != null ? languages : new String[0]);
+ return this;
+ }
+
+ public final String getMimeType() {
+ return mimeType;
+ }
+
+ public final ProfileExporter setMimeType(String s) {
+ if (StringUtils.isNotBlank(s)) {
+ this.mimeType = s;
+ }
+ return this;
}
/**
- * @return if empty, then all repositories are supported.
+ * @return if empty, then any languages are supported.
*/
- public final String[] getSupportedRepositories() {
- return supportedRepositories;
+ public final String[] getSupportedLanguages() {
+ return supportedLanguages;
+ }
+
+ @Override
+ public final boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ ProfileExporter that = (ProfileExporter) o;
+ if (key != null ? !key.equals(that.key) : that.key != null) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public final int hashCode() {
+ return key != null ? key.hashCode() : 0;
}
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileImporter.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileImporter.java
index 3df8020f539..8cceb8be6ed 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileImporter.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileImporter.java
@@ -29,18 +29,64 @@ import java.io.Reader;
*/
public abstract class ProfileImporter implements ServerExtension {
- private String[] supportedRepositories = new String[0];
+ private String[] supportedLanguages = new String[0];
+ private String key;
+ private String name;
+
+ protected ProfileImporter(String key, String name) {
+ this.key = key;
+ this.name = name;
+ }
public abstract ProfilePrototype importProfile(Reader reader, ValidationMessages messages);
- protected final void setSupportedRepositories(String... repositoryKeys) {
- supportedRepositories = (repositoryKeys != null ? repositoryKeys : new String[0]);
+ public final String getKey() {
+ return key;
+ }
+
+ public final ProfileImporter setKey(String s) {
+ this.key = s;
+ return this;
+ }
+
+ public final String getName() {
+ return name;
+ }
+
+ public final ProfileImporter setName(String s) {
+ this.name = s;
+ return this;
+ }
+
+ protected final ProfileImporter setSupportedLanguages(String... languages) {
+ supportedLanguages = (languages != null ? languages : new String[0]);
+ return this;
}
/**
- * @return if empty, then all repositories are supported.
+ * @return if empty, then any languages are supported.
*/
- public final String[] getSupportedRepositories() {
- return supportedRepositories;
+ public final String[] getSupportedLanguages() {
+ return supportedLanguages;
+ }
+
+ @Override
+ public final boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ ProfileImporter that = (ProfileImporter) o;
+ if (key != null ? !key.equals(that.key) : that.key != null) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public final int hashCode() {
+ return key != null ? key.hashCode() : 0;
}
}
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
index de76bd3aba6..a045499060c 100644
--- 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
@@ -31,17 +31,12 @@ import java.io.Writer;
/**
* @since 2.3
*/
-public final class XMLProfileExporter extends ProfileExporter {
-
- private XMLProfileExporter() {
- // support all repositories
- }
+public final class XMLProfileExporter {
public static XMLProfileExporter create() {
return new XMLProfileExporter();
}
- @Override
public void exportProfile(RulesProfile profile, Writer writer) {
try {
appendHeader(writer);
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
index d0b9c4be653..fe5633c055f 100644
--- 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
@@ -36,7 +36,7 @@ import java.util.List;
/**
* @since 2.3
*/
-public final class XMLProfileImporter extends ProfileImporter {
+public final class XMLProfileImporter {
private XMLProfileImporter() {
// support all repositories
@@ -46,7 +46,6 @@ public final class XMLProfileImporter extends ProfileImporter {
return new XMLProfileImporter();
}
- @Override
public ProfilePrototype importProfile(Reader reader, ValidationMessages messages) {
ProfilePrototype profile = ProfilePrototype.create();
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RulesManager.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RulesManager.java
index 1f87fabe09e..976fa2f6f35 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RulesManager.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RulesManager.java
@@ -65,22 +65,6 @@ public abstract class RulesManager {
public abstract List<Plugin> getPlugins(Language language);
/**
- * Gets count of rules by categories defined for a given language
- *
- * @param language the language
- * @return a Map with the category as key and the count as value
- */
- public abstract Map<String, Long> countRulesByCategory(Language language);
-
-
- /**
- * Get the list of rules plugin that implement a mechanism of export for a given language
- *
- * @param language the language
- * @return the list of plugins
- */
- public abstract List<Plugin> getExportablePlugins(Language language);
- /**
* Get the list of rules plugin that implement a mechanism of import for a given language
*
* @param language the language
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileImporterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileDefinitionTest.java
index 308ed354d06..995a4aeb626 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileImporterTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileDefinitionTest.java
@@ -28,18 +28,18 @@ 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;
-public class AnnotationProfileImporterTest {
+public class AnnotationProfileDefinitionTest {
@Test
public void importProfile() {
- AnnotationProfileImporter importer = AnnotationProfileImporter.create("checkstyle", Arrays.<Class>asList(FakeRule.class));
- ValidationMessages validation = ValidationMessages.create();
- ProfilePrototype profile = importer.importProfile(null, validation);
- assertThat(profile.getRule("checkstyle", "fake").getPriority(), is(RulePriority.BLOCKER));
+ ProfileDefinition definition = new FakeDefinition();
+ ProfilePrototype profile = definition.createPrototype();
+ assertThat(profile.getRule("squid", "fake").getPriority(), is(RulePriority.BLOCKER));
}
}
@@ -48,3 +48,11 @@ public class AnnotationProfileImporterTest {
class FakeRule {
}
+
+
+class FakeDefinition extends AnnotationProfileDefinition {
+
+ public FakeDefinition() {
+ super("squid", "sonar way", "java", Arrays.<Class>asList(FakeRule.class));
+ }
+} \ No newline at end of file
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/ProfileExporterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/ProfileExporterTest.java
index 3dd63aa7481..7db9a3f6897 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/ProfileExporterTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/ProfileExporterTest.java
@@ -30,29 +30,29 @@ public class ProfileExporterTest {
@Test
public void testSupportedRepositories() {
- ProfileExporter exporter = new ProfileExporter() {
+ ProfileExporter exporter = new ProfileExporter("all", "All") {
@Override
public void exportProfile(RulesProfile profile, Writer writer) {
}
};
- exporter.setSupportedRepositories("checkstyle", "pmd");
+ exporter.setSupportedLanguages("java", "php");
- assertThat(exporter.getSupportedRepositories().length, is(2));
- assertThat(exporter.getSupportedRepositories()[0], is("checkstyle"));
- assertThat(exporter.getSupportedRepositories()[1], is("pmd"));
+ assertThat(exporter.getSupportedLanguages().length, is(2));
+ assertThat(exporter.getSupportedLanguages()[0], is("java"));
+ assertThat(exporter.getSupportedLanguages()[1], is("php"));
}
@Test
public void supportAllRepositories() {
- ProfileExporter exporter = new ProfileExporter() {
+ ProfileExporter exporter = new ProfileExporter("all", "All") {
@Override
public void exportProfile(RulesProfile profile, Writer writer) {
}
};
- assertThat(exporter.getSupportedRepositories().length, is(0));
+ assertThat(exporter.getSupportedLanguages().length, is(0));
- exporter.setSupportedRepositories(null);
- assertThat(exporter.getSupportedRepositories().length, is(0));
+ exporter.setSupportedLanguages(null);
+ assertThat(exporter.getSupportedLanguages().length, is(0));
}
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/ProfileImporterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/ProfileImporterTest.java
index 48d1388639e..13e5eb7ea5c 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/ProfileImporterTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/ProfileImporterTest.java
@@ -31,31 +31,31 @@ public class ProfileImporterTest {
@Test
public void testSupportedRepositories() {
- ProfileImporter inmporter = new ProfileImporter() {
+ ProfileImporter inmporter = new ProfileImporter("all", "All") {
@Override
public ProfilePrototype importProfile(Reader reader, ValidationMessages messages) {
return null;
}
};
- inmporter.setSupportedRepositories("checkstyle", "pmd");
+ inmporter.setSupportedLanguages("java", "php");
- assertThat(inmporter.getSupportedRepositories().length, is(2));
- assertThat(inmporter.getSupportedRepositories()[0], is("checkstyle"));
- assertThat(inmporter.getSupportedRepositories()[1], is("pmd"));
+ assertThat(inmporter.getSupportedLanguages().length, is(2));
+ assertThat(inmporter.getSupportedLanguages()[0], is("java"));
+ assertThat(inmporter.getSupportedLanguages()[1], is("php"));
}
@Test
public void supportAllRepositories() {
- ProfileImporter importer = new ProfileImporter() {
+ ProfileImporter importer = new ProfileImporter("all", "All") {
@Override
public ProfilePrototype importProfile(Reader reader, ValidationMessages messages) {
return null;
}
};
- assertThat(importer.getSupportedRepositories().length, is(0));
+ assertThat(importer.getSupportedLanguages().length, is(0));
- importer.setSupportedRepositories(null);
- assertThat(importer.getSupportedRepositories().length, is(0));
+ importer.setSupportedLanguages(null);
+ assertThat(importer.getSupportedLanguages().length, is(0));
}
}