diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-10-13 12:40:37 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-10-13 12:57:27 +0200 |
commit | 3ac8de59552f3d38f9b952079cbffa8572840731 (patch) | |
tree | e2c353cba55e9d2db47f7801a64d408a3fe30885 /plugins | |
parent | bd18f3974b18e03f40ca14b86b82a8851124b107 (diff) | |
download | sonarqube-3ac8de59552f3d38f9b952079cbffa8572840731.tar.gz sonarqube-3ac8de59552f3d38f9b952079cbffa8572840731.zip |
SONAR-5673 Creating a new profile from a configuration file is not working
Diffstat (limited to 'plugins')
5 files changed, 159 insertions, 11 deletions
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java index 3477fab825c..8715210be75 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java @@ -20,16 +20,8 @@ package org.sonar.xoo; import org.sonar.api.SonarPlugin; -import org.sonar.xoo.lang.MeasureSensor; -import org.sonar.xoo.lang.ScmActivitySensor; -import org.sonar.xoo.lang.SymbolReferencesSensor; -import org.sonar.xoo.lang.SyntaxHighlightingSensor; -import org.sonar.xoo.lang.XooTokenizerSensor; -import org.sonar.xoo.rule.CreateIssueByInternalKeySensor; -import org.sonar.xoo.rule.OneIssueOnDirPerFileSensor; -import org.sonar.xoo.rule.OneIssuePerLineSensor; -import org.sonar.xoo.rule.XooQualityProfile; -import org.sonar.xoo.rule.XooRulesDefinition; +import org.sonar.xoo.lang.*; +import org.sonar.xoo.rule.*; import java.util.Arrays; import java.util.List; @@ -49,6 +41,10 @@ public class XooPlugin extends SonarPlugin { XooRulesDefinition.class, XooQualityProfile.class, + XooFakeExporter.class, + XooFakeImporter.class, + XooFakeImporterWithMessages.class, + // sensors MeasureSensor.class, ScmActivitySensor.class, diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooFakeExporter.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooFakeExporter.java new file mode 100644 index 00000000000..b8375db463f --- /dev/null +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooFakeExporter.java @@ -0,0 +1,55 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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 this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.xoo.rule; + +import org.sonar.api.profiles.ProfileExporter; +import org.sonar.api.profiles.RulesProfile; +import org.sonar.xoo.Xoo; + +import java.io.IOException; +import java.io.Writer; + +/** + * Fake exporter just for test + */ +public class XooFakeExporter extends ProfileExporter { + public XooFakeExporter() { + super("XooFakeExporter", "Xoo Fake Exporter"); + } + + @Override + public String[] getSupportedLanguages() { + return new String[]{Xoo.KEY}; + } + + @Override + public String getMimeType() { + return "plain/custom"; + } + + @Override + public void exportProfile(RulesProfile profile, Writer writer) { + try { + writer.write("xoo -> " + profile.getName() + " -> " + profile.getActiveRules().size()); + } catch (IOException e) { + throw new IllegalStateException(e); + } + } +} diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooFakeImporter.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooFakeImporter.java new file mode 100644 index 00000000000..867c11100dc --- /dev/null +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooFakeImporter.java @@ -0,0 +1,50 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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 this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.xoo.rule; + +import org.sonar.api.profiles.ProfileImporter; +import org.sonar.api.profiles.RulesProfile; +import org.sonar.api.rules.Rule; +import org.sonar.api.rules.RulePriority; +import org.sonar.api.utils.ValidationMessages; +import org.sonar.xoo.Xoo; + +import java.io.Reader; + +/** + * Fake importer just for test, it will NOT take into account the given file but will create some hard-coded rules + */ +public class XooFakeImporter extends ProfileImporter { + public XooFakeImporter() { + super("XooProfileImporter", "Xoo Profile Importer"); + } + + @Override + public String[] getSupportedLanguages() { + return new String[] {Xoo.KEY}; + } + + @Override + public RulesProfile importProfile(Reader reader, ValidationMessages messages) { + RulesProfile rulesProfile = RulesProfile.create(); + rulesProfile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, "x1"), RulePriority.CRITICAL); + return rulesProfile; + } +} diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooFakeImporterWithMessages.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooFakeImporterWithMessages.java new file mode 100644 index 00000000000..a11e3a2cca0 --- /dev/null +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooFakeImporterWithMessages.java @@ -0,0 +1,47 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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 this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.xoo.rule; + +import org.sonar.api.profiles.ProfileImporter; +import org.sonar.api.profiles.RulesProfile; +import org.sonar.api.utils.ValidationMessages; + +import java.io.Reader; + +/** + * Fake importer just for test, it will NOT take into account the given file but will display some info and warning messages + */ +public class XooFakeImporterWithMessages extends ProfileImporter { + public XooFakeImporterWithMessages() { + super("XooFakeImporterWithMessages", "Xoo Profile Importer With Messages"); + } + + @Override + public String[] getSupportedLanguages() { + return new String[] {}; + } + + @Override + public RulesProfile importProfile(Reader reader, ValidationMessages messages) { + messages.addWarningText("a warning"); + messages.addInfoText("an info"); + return RulesProfile.create(); + } +} diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java index bfe1fd99afa..e8100740345 100644 --- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java +++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/XooPluginTest.java @@ -27,6 +27,6 @@ public class XooPluginTest { @Test public void provide_extensions() { - assertThat(new XooPlugin().getExtensions()).hasSize(11); + assertThat(new XooPlugin().getExtensions()).hasSize(14); } } |