我对 Sonar 比较陌生——尤其是在编写我自己的 Sonar 插件方面。经过一些成功的试验后,我现在陷入了困境。我编写了一个简单的插件,它只应该将源文件(*.abap -Files)传输到声纳服务器。
在我的插件中,我有一个 AbapLangauge(从 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
package sonarplugin;
import org.sonar.api.batch.AbstractSourceImporter;
public final class AbapSourceImporter extends AbstractSourceImporter {
public AbapSourceImporter(AbapLanguage language) {
super(language);
}
}
我将这两个类注册为扩展点。在我想用我在 sonar-project.properties 中设置的 sonar-runner 分析的测试项目中
sonar.language=sap
但是当我启动声纳跑步者时,我得到了以下错误:
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”的插件?我的插件配置不对吗?
感谢高级伯恩哈德