如何在分析项目时访问声纳属性文件。我需要在声纳项目属性文件中提及的基本文件夹。
答案 0 :(得分:1)
您必须实现传感器实现类的构造函数,如下所示:
public class CodeSensor implements Sensor {
private final Logger log = LoggerFactory.getLogger(this.getClass());
private final FileSystem filesystem;
private final Settings settings;
private final ResourcePerspectives perspectives;
public CodeSensor(Settings settings, FileSystem filesystem, ResourcePerspectives perspectives) {
this.filesystem = filesystem;
this.settings = settings;
this.perspectives = perspectives;
try (DirectoryStream<Path> stream =
Files.newDirectoryStream(filesystem.baseDir().toPath().toAbsolutePath(),
settings.getString("sonar.sources"))) {
for (Path entry : stream) {
DirectoryStream<Path> file =
Files.newDirectoryStream(entry, "*.q");
for (Path path : file) {
path.toFile().delete();
}
}
} catch (IOException e1) {
log.error("Can't clean src dir", e1);
}
}
}
这是您的设置参数的路径:settings.getString(“sonar.sources”)
这是您的基本文件夹的路径:filesystem.baseDir()。toPath()。toAbsolutePath()