自己的声纳插件-如何设置语言? [英] Own Sonar Plugin - How to set the Language?

查看:136
本文介绍了自己的声纳插件-如何设置语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Sonar不太熟悉,尤其是在编写自己的Sonar插件方面.经过一些成功的试验后,我现在陷入困境.我编写了一个简单的插件,该插件仅应将源文件(* .abap -Files)传输到声纳服务器.

I'm relative new to Sonar - especially to writing my own Sonar Plugin. After some successful trials, I got stuck now. I have written a simple Plugin which only should transfer source files (*.abap -Files) to the sonar server.

在我的插件中,我有一个AbapLangauge(从AbstractLangauge扩展)

and in my plugin I have an AbapLangauge (extended from AbstractLangauge)

package sonarplugin;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.resources.AbstractLanguage;

public class AbapLanguage extends AbstractLanguage {
  public static final String DEFAULT_SOURCE_SUFFIXES = "abap";
  public static final String KEY = "sap";

  private String[] fileSuffixes;
  private static final Logger LOG = LoggerFactory.getLogger(AbapLanguage.class);

  public AbapLanguage() {   
    super(KEY, "sap");
    LOG.info("SETTING LANGUAGE TO SAP: " + KEY);
    fileSuffixes = createStringArray(null, DEFAULT_SOURCE_SUFFIXES);
  }

  public String[] getFileSuffixes() {
      return fileSuffixes;
  }

  private String[] createStringArray(String[] values, String defaultValues) {
    if (values == null || values.length == 0) {
      return StringUtils.split(defaultValues, ",");
    }
    return values;
  }

}

我还有一个SourceImporter

And I also have an SourceImporter

package sonarplugin;

import org.sonar.api.batch.AbstractSourceImporter;

public final class AbapSourceImporter extends AbstractSourceImporter {

public AbapSourceImporter(AbapLanguage language) {
    super(language);
}
}

我将这两个类注册为扩展点. 在我想使用声纳运行器进行分析的测试项目中,我已经在sonar-project.properties中设置了

I registered these two classes as extension points. In my testproject which I want to analyse with the sonar-runner I have set in the sonar-project.properties

sonar.language=sap

但是当我启动声纳运行器时,出现以下错误:

But when I start the sonar runner I get the follwing error:

15:11:36.148 INFO  - -------------  Executing Project Scan
15:11:36.386 INFO  - ABAPIMPORTGERPLUGIN has just started.
15:11:36.924 INFO  - Install JDBC driver
15:11:36.929 INFO  - Apply project exclusions
15:11:36.937 WARN  - H2 database should be used for evaluation purpose only
15:11:36.937 INFO  - Create JDBC datasource for jdbc:h2:tcp://localhost:9092/sonar
15:11:37.051 INFO  - Initializing Hibernate
15:11:42.669 INFO  - -------------  Inspecting MeinTestprojekt
15:11:42.683 INFO  - Load module settings
15:11:43.062 INFO  - ABAPIMPORTGERPLUGIN has just started.
15:11:43.244 INFO  - SETTING LANGUAGE TO SAP: sap
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 15.544s
INFO: Final Memory: 10M/158M
INFO: ------------------------------------------------------------------------
ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR: Caused by: You must install a plugin that supports the language 'sap'

有人可以帮助我吗?为什么sonar-runner会说没有支持语言"sap"的插件?我的插件配置不正确吗?

Can somebody help me? Why sonar-runner says that there is no plugin that supports the language 'sap'? Isn't my plugin configured right?

非常感谢 伯恩哈德

推荐答案

在您的特定情况下,问题出在以下事实:您尚未为新语言定义任何规则存储库(甚至是一个空的规则存储库),因此Sonar认为您的新语言不受支持.

In your specific case, the problem comes from the fact that you do not have defined any rule repository (even an empty one) for your new language, so Sonar thinks that your new language is not supported.

更一般而言,最适合您的选择是看看我们为Sonar开发的一些开源语言插件.例如,您可以查看 JavaScript插件.

More generally, the best option for you is to take a look at some open-source language plugins that we develop for Sonar. For instance, you can go and see the Javascript plugin.

这篇关于自己的声纳插件-如何设置语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆