简体   繁体   English

SonarQube 语言插件开发

[英]SonarQube language plugin development

I started development of my own plugin and have a trouble about FileSystem:我开始开发自己的插件,但在 FileSystem 方面遇到了麻烦:

My Sensor implementation like a sonar-reference-plugin:我的传感器实现就像声纳参考插件:

public class PLPlusCodeSensor implements Sensor {
    private final Logger log = LoggerFactory.getLogger(this.getClass());
    private final FileSystem filesystem;
    private final Settings settings;

    public PLPlusCodeSensor(Settings settings, FileSystem filesystem) {
        this.filesystem = filesystem;
        this.settings = settings;
    }

    @Override
    public boolean shouldExecuteOnProject(Project project) {
        return true;
    }

    @Override
    public void analyse(Project project, SensorContext sensorContext) {
        for(InputFile file : filesystem.inputFiles(filesystem.predicates().all())) {
            log.info("Processing file " + file.absolutePath());
            Measure measure = new Measure(PLPlusMetrics.LineLength, 85d);
            sensorContext.saveMeasure(file, measure);
        }
    }

    @Override
    public String toString() {
        return this.getClass().getName();
    }
}

but there is no output about any file in source dir:但是没有关于源目录中任何文件的输出:

18:04:27.707 INFO  - Sensor com.sbt.tools.sonarqube.plplus.PLPlusCodeSensor
18:04:27.707 INFO  - Sensor com.sbt.tools.sonarqube.plplus.PLPlusCodeSensor (done) | time=0ms

here is my sonar-project.properties flie:这是我的 sonar-project.properties 飞行:

sonar.projectKey=plplus-test
sonar.projectName=PLPlus Test Analysis
sonar.projectVersion=1.0
sonar.sources=c:/dev/plplus/src

here is content of src dir:这是 src 目录的内容:

C:\dev\plplus\src>dir
 Том в устройстве C имеет метку Windows7_OS
 Серийный номер тома: 18DB-13C8

 Содержимое папки C:\dev\plplus\src

23.12.2015  17:59    <DIR>          .
23.12.2015  17:59    <DIR>          ..
23.12.2015  15:54                 0 test.plp
           1 файлов              0 байт
           2 папок  98 023 743 488 байт свободно

C:\dev\plplus\src>

Please, help me to understand, why filesystem.inputFiles(filesystem.predicates().all()) returns an empty iterator?请帮我理解,为什么 filesystem.inputFiles(filesystem.predicates().all()) 返回一个空的迭代器?

In order to get a file from fileSystem api it has to be indexed.为了从 fileSystem api 获取文件,它必须被索引。 In order to do so, you have to either define a language that will declare the extension you are looking for or import all source files using sonar.import_unknown_files=true (with SQ 5.1+)为此,您必须定义一种语言来声明您要查找的扩展名,或者使用sonar.import_unknown_files=true (使用 SQ 5.1+)导入所有源文件

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM