简体   繁体   English

使用RPG在SonarQube中添加我自己的规则

[英]Add my own rules in SonarQube with RPG

I want to create my own SonarQube Plugin for the RPG language. 我想为RPG语言创建自己的SonarQube插件。 I have the following problem. 我有以下问题。

I start by created the RpgLanguage class that extends to AbstractLanguage. 我首先创建了RpgLanguage类,该类扩展到AbstractLanguage。 In this class, I defined my new language "Rpg". 在这一节课中,我定义了新语言“ Rpg”。 You can see my class in the following code : 您可以在以下代码中看到我的课程:

public class RpgLanguage extends AbstractLanguage{


     public static final String KEY = "rpg";

      private Settings settings;

      public RpgLanguage(Settings settings) {
        super(KEY, "Rpg");
        this.settings = settings;
      }

      public String[] getFileSuffixes() {
        String[] suffixes = settings.getStringArray("");
        if (suffixes == null || suffixes.length == 0) {
          suffixes = StringUtils.split(".RPG", ",");
        }
        return suffixes;
      }
}

After, I have created my RpgRulesDefinition class that implements RulesDefinition. 之后,我创建了实现RulesDefinition的RpgRulesDefinition类。 In this class, I create a new repository for the language RPG and I want to add a rule in this repository (empty rules). 在此类中,我为语言RPG创建了一个新的存储库,并希望在该存储库中添加一个规则(空规则)。 The code is like below : 代码如下:

public static final String REPOSITORY_KEY = "rpg_repository_mkoza";

    public void define(Context context) {

        NewRepository repo = context.createRepository(REPOSITORY_KEY, "rpg");
        repo.setName("Mkoza Analyser rules RPG");

        // We could use a XML or JSON file to load all rule metadata, but
        // we prefer use annotations in order to have all information in a single place
        RulesDefinitionAnnotationLoader annotationLoader = new RulesDefinitionAnnotationLoader();
        annotationLoader.load(repo, RpgFileCheckRegistrar.checkClasses());

        repo.done();
    }

My class RpgFileCheckRegistrar that call my Rules : 我的类RpgFileCheckRegistrar调用了我的规则:

 /**
       * Register the classes that will be used to instantiate checks during analysis.
       */
    public void register(RegistrarContext registrarContext) {
        // Call to registerClassesForRepository to associate the classes with the correct repository key
        registrarContext.registerClassesForRepository(RpgRulesDefinition.REPOSITORY_KEY, Arrays.asList(checkClasses()), Arrays.asList(testCheckClasses()));

    }

      /**
       * Lists all the checks provided by the plugin
       */
      public static Class<? extends JavaCheck>[] checkClasses() {
        return new Class[] {
          RulesExampleCheck.class
          };
      }

      /**
       * Lists all the test checks provided by the plugin
       */
      public static Class<? extends JavaCheck>[] testCheckClasses() {
        return new Class[] {};
      }

My Rule class (still empty): 我的规则类(仍然为空):

 @Rule(
      key = "Rule1",
      name = "Rule that make nothing",
      priority = Priority.MAJOR,
      tags = {"example"}
      )
public class RulesExampleCheck extends BaseTreeVisitor{

    /**
     * Right in java code your rule
     */

}

And the class SonarPlugin that call all these extensions : 还有调用所有这些扩展的SonarPlugin类:

public final class RpgSonarPlugin extends SonarPlugin
{
     // This is where you're going to declare all your Sonar extensions
      public List getExtensions() {
       return Arrays.asList(
            RpgLanguage.class,
            RpgRulesDefinition.class,
            RpgFileCheckRegistrar.class
        );
      }
}

The problem when I want to start the server sonar, I obtain this error stack : 当我想启动服务器声纳时的问题,我得到了这个错误堆栈:

Exception sending context initialized event to listener instance of class org.sonar.server.platform.PlatformServletContextListener
java.lang.IllegalStateException: One of HTML description or Markdown description must be defined for rule [repository=rpg_repository_mkoza, key=Rule1]

I try different things but I don't understand why there are these error. 我尝试了不同的方法,但我不明白为什么会有这些错误。 Of course I want that my repository "rpg_repository_mkoza" is display in the RPG's repository in SonarQube with the Rules : RulesExampleCheck. 当然,我希望我的存储库“ rpg_repository_mkoza”通过“ Rules:RulesExampleCheck”显示在SonarQube的RPG存储库中。

My sonar-plugin-version is the 3.7.1 我的声纳插件版本是3.7.1

I find my problem. 我发现我的问题。 There are need to add the field 'description' in @Rule. 需要在@Rule中添加字段“说明”

For example : 例如 :

@Rule(
  key = "Rule1",
  name = "RuleExampleCheck",
  description = "This rule do nothing",
  priority = Priority.INFO,
  tags = {"try"}
  )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SonarQube 如何创建配置文件并向其导入新规则 - SonarQube how to create Profile and import new rules to it 是否有允许我的网站成员添加自己的图片的插件? - Is there any plugin who allows members of my website to add images of their own? 使用PropertyDefinition在sonarqube上添加属性 - Add a property on sonarqube using PropertyDefinition SonarQube插件在服务器启动后创建新规则 - SonarQube Plugin create new rules after server start 如何让我的wordpress插件向.htaccess添加重写规则? - How do I get my wordpress plugin to add rewrite rules to the .htaccess? 如何将第三方分析仪添加到 sonarqube? - How to add third party analyzer to sonarqube? 如何将自己的插件添加到IE,以便在我访问网页时,IE应该要求安装该插件 - How to add my own plugin to IE, so that if I visit the webpage, IE should ask for installation of that plugin 如何将我自己编写的插件添加到我的世界服务器中? - How do I add my own plugin that I coded into a minecraft server? SonarQube 上的两个不同项目使用相同的插件,但应用来自插件的不同规则 - Two Different Projects on SonarQube using same plugin, but applying different rules from Plugin 创建我自己的插件-不起作用 - Creating my own plugin - Not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM