Browse Source

SONAR-4326 Create dummy plugin for backend tests

tags/4.2
Jean-Baptiste Lievremont 10 years ago
parent
commit
4e9d8ddd1d

+ 42
- 0
plugins/sonar-xoo-plugin/pom.xml View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar</artifactId>
<version>4.2-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<groupId>org.codehaus.sonar.plugins</groupId>
<artifactId>sonar-xoo-plugin</artifactId>
<name>SonarQube :: Plugins :: Xoo</name>
<packaging>sonar-plugin</packaging>
<description>Fake language plugin for backend tests.</description>

<dependencies>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-plugin-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-testing-harness</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-packaging-maven-plugin</artifactId>
<configuration>
<pluginKey>xoo</pluginKey>
<pluginName>Xoo</pluginName>
<pluginClass>org.sonar.plugins.xoo.XooPlugin</pluginClass>
</configuration>
</plugin>
</plugins>
</build>
</project>

+ 48
- 0
plugins/sonar-xoo-plugin/src/main/java/org/sonar/plugins/xoo/Xoo.java View File

@@ -0,0 +1,48 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 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.plugins.xoo;

import org.sonar.api.resources.Language;
import org.sonar.plugins.xoo.base.XooConstants;

public class Xoo implements Language {

public static final String XOO_LANGUAGE_NAME = "Xoo";
public static final String XOO_SUFFIX = ".xoo";

private static final String[] XOO_SUFFIXES = {
XOO_SUFFIX
};

@Override
public String getKey() {
return XooConstants.LANGUAGE_KEY;
}

@Override
public String getName() {
return XOO_LANGUAGE_NAME;
}

@Override
public String[] getFileSuffixes() {
return XOO_SUFFIXES;
}
}

+ 39
- 0
plugins/sonar-xoo-plugin/src/main/java/org/sonar/plugins/xoo/XooPlugin.java View File

@@ -0,0 +1,39 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 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.plugins.xoo;

import com.google.common.collect.ImmutableList;
import org.sonar.api.SonarPlugin;
import org.sonar.plugins.xoo.rules.XooRuleDefinitions;

import java.util.List;

public class XooPlugin extends SonarPlugin {

@Override
public List getExtensions() {
return ImmutableList.of(
Xoo.class,
XooRuleDefinitions.class,
XooProfile.class);
}


}

+ 40
- 0
plugins/sonar-xoo-plugin/src/main/java/org/sonar/plugins/xoo/XooProfile.java View File

@@ -0,0 +1,40 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 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.plugins.xoo;

import org.sonar.api.profiles.ProfileDefinition;
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.plugins.xoo.base.XooConstants;
import org.sonar.plugins.xoo.base.XooRuleKeys;

public class XooProfile extends ProfileDefinition {

@Override
public RulesProfile createProfile(ValidationMessages validation) {
final RulesProfile profile = RulesProfile.create("Basic", XooConstants.LANGUAGE_KEY);

profile.activateRule(Rule.create(XooConstants.REPOSITORY_KEY, XooRuleKeys.RULE_MINIMAL), RulePriority.MAJOR);

return profile;
}
}

+ 31
- 0
plugins/sonar-xoo-plugin/src/main/java/org/sonar/plugins/xoo/base/XooConstants.java View File

@@ -0,0 +1,31 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 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.plugins.xoo.base;

public final class XooConstants {

public static final String LANGUAGE_KEY = "xoo";
public static final String PROFILE_KEY = "xoo";
public static final String REPOSITORY_KEY = "xoo";

private XooConstants() {
// Only constants
}
}

+ 36
- 0
plugins/sonar-xoo-plugin/src/main/java/org/sonar/plugins/xoo/base/XooRuleKeys.java View File

@@ -0,0 +1,36 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 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.plugins.xoo.base;

public class XooRuleKeys {

public static final String RULE_MINIMAL = "minimal";
public static final String RULE_WITH_PARAMS = "params";

public static final String RULE_WITH_TAGS1 = "tags1";
public static final String RULE_WITH_TAGS12 = "tags12";
public static final String RULE_WITH_TAGS123 = "tags123";
public static final String RULE_WITH_TAGS23 = "tags23";
public static final String RULE_WITH_TAGS34 = "tags34";

private XooRuleKeys() {
// Only constants
}
}

+ 88
- 0
plugins/sonar-xoo-plugin/src/main/java/org/sonar/plugins/xoo/rules/XooRuleDefinitions.java View File

@@ -0,0 +1,88 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 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.plugins.xoo.rules;

import org.sonar.api.rule.RuleDefinitions;
import org.sonar.api.rule.RuleParamType;
import org.sonar.plugins.xoo.base.XooConstants;
import org.sonar.plugins.xoo.base.XooRuleKeys;

public class XooRuleDefinitions implements RuleDefinitions {

private static final String TAG1 = "tag1", TAG2 = "tag2", TAG3 = "tag3", TAG4 = "tag4";

@Override
public void define(Context context) {
final NewRepository xooRepository = context.newRepository(XooConstants.REPOSITORY_KEY, XooConstants.LANGUAGE_KEY).setName("Xoo");


xooRepository.newRule(XooRuleKeys.RULE_MINIMAL)
.setName("Minimal rule")
.setHtmlDescription("Minimal rule, with only required fields");

final NewRule ruleWithParams = xooRepository.newRule(XooRuleKeys.RULE_WITH_PARAMS)
.setName("Rule with parameters")
.setHtmlDescription("This rule defines parameters, one for each supported type");
ruleWithParams.newParam("string")
.setName("String")
.setType(RuleParamType.STRING)
.setDescription("A string parameter");
ruleWithParams.newParam("text")
.setName("Text")
.setType(RuleParamType.TEXT)
.setDescription("A text parameter");
ruleWithParams.newParam("bool")
.setName("Boolean")
.setType(RuleParamType.BOOLEAN)
.setDescription("A boolean parameter");
ruleWithParams.newParam("float")
.setName("Float")
.setType(RuleParamType.FLOAT)
.setDescription("A float parameter");
ruleWithParams.newParam("int")
.setName("Integer")
.setType(RuleParamType.INTEGER)
.setDescription("An integer parameter");

xooRepository.newRule(XooRuleKeys.RULE_WITH_TAGS1)
.setName("Tag 1")
.setHtmlDescription("Rule with tag <code>tag1</code>")
.setTags(TAG1);
xooRepository.newRule(XooRuleKeys.RULE_WITH_TAGS12)
.setName("Tags 1 and 2")
.setHtmlDescription("Rule with tags <code>tag1</code> and <code>tag2</code>")
.setTags(TAG1, TAG2);
xooRepository.newRule(XooRuleKeys.RULE_WITH_TAGS123)
.setName("Tags 1, 2 and 3")
.setHtmlDescription("Rule with tags <code>tag1</code>, <code>tag2</code> and <code>tag3</code>")
.setTags(TAG1, TAG2, TAG3);
xooRepository.newRule(XooRuleKeys.RULE_WITH_TAGS23)
.setName("Tags 2 and 3")
.setHtmlDescription("Rule with tags <code>tag2</code> and <code>tag3</code>")
.setTags(TAG2, TAG3);
xooRepository.newRule(XooRuleKeys.RULE_WITH_TAGS34)
.setName("Tags 3 and 4")
.setHtmlDescription("Rule with tags <code>tag3</code> and <code>tag4</code>")
.setTags(TAG3, TAG4);

xooRepository.done();
}

}

+ 33
- 0
plugins/sonar-xoo-plugin/src/test/java/org/sonar/plugins/xoo/XooPluginTest.java View File

@@ -0,0 +1,33 @@
package org.sonar.plugins.xoo;

import org.junit.Test;
import org.sonar.plugins.xoo.rules.XooRuleDefinitions;
import static org.fest.assertions.Assertions.assertThat;

/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 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.
*/

public class XooPluginTest {

@Test
public void should_provide_rule_repository() {
assertThat(new XooPlugin().getExtensions()).containsOnly(Xoo.class, XooRuleDefinitions.class, XooProfile.class);
}
}

+ 45
- 0
plugins/sonar-xoo-plugin/src/test/java/org/sonar/plugins/xoo/rules/XooRuleDefinitionsTest.java View File

@@ -0,0 +1,45 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 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.plugins.xoo.rules;

import org.junit.Test;
import org.sonar.api.rule.RuleDefinitions;
import org.sonar.api.rule.RuleDefinitions.Repository;

import static org.fest.assertions.Assertions.assertThat;

public class XooRuleDefinitionsTest {


@Test
public void should_define_xoo_repository() {
RuleDefinitions.Context context = new RuleDefinitions.Context();
new XooRuleDefinitions().define(context);

assertThat(context.repositories()).hasSize(1);

Repository xooRepository = context.repositories().get(0);
assertThat(xooRepository.key()).isEqualTo("xoo");
assertThat(xooRepository.language()).isEqualTo("xoo");
assertThat(xooRepository.name()).isEqualTo("Xoo");

assertThat(xooRepository.rules()).hasSize(7);
}
}

+ 1
- 0
pom.xml View File

@@ -40,6 +40,7 @@
<module>plugins/sonar-l10n-en-plugin</module>
<module>plugins/sonar-email-notifications-plugin</module>
<module>plugins/sonar-maven-batch-plugin</module>
<module>plugins/sonar-xoo-plugin</module>
</modules>

<organization>

Loading…
Cancel
Save