本文整理汇总了Java中org.sonar.api.batch.sensor.SensorContext.fileSystem方法的典型用法代码示例。如果您正苦于以下问题:Java SensorContext.fileSystem方法的具体用法?Java SensorContext.fileSystem怎么用?Java SensorContext.fileSystem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.sonar.api.batch.sensor.SensorContext
的用法示例。
在下文中一共展示了SensorContext.fileSystem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.sonar.api.batch.sensor.SensorContext; //导入方法依赖的package包/类
@Override
public void execute(SensorContext context) {
LOGGER.info("FramaCSensor is running...");
FileSystem fs = context.fileSystem();
LOGGER.info("FramaCSensor : file system base dir = " + fs.baseDir());
FilePredicates p = fs.predicates();
LOGGER.info("FramaCSensor : file system base dir = " + fs.hasFiles(p.all()));
readPluginSettings(context);
// Only "main" files, but not "tests"
String[] aMatchingPatterns = matchingPatterns();
Iterable<InputFile> filesC = fs.inputFiles(fs.predicates().matchesPathPatterns(aMatchingPatterns));
for (InputFile file : filesC) {
LOGGER.debug("FramaCSensor : current input file = " + file.absolutePath());
// Check for report out
String fileRelativePathNameReportOut = outReportFileName(file);
// Analyse report out
analyseReportOut(context, file, fileRelativePathNameReportOut);
}
LOGGER.info("FramaCSensor done!");
}
示例2: mkInputFileOrNullFromPath
import org.sonar.api.batch.sensor.SensorContext; //导入方法依赖的package包/类
private InputFile mkInputFileOrNullFromPath(final XMLReportNode node,
final SensorContext sensorContext) {
final FileSystem fs = sensorContext.fileSystem();
/*
* Create the relative path from the persistence string
*/
final String relativePath = node.getRelativePathOrNull();
if (relativePath != null) {
final Iterable<InputFile> inputFilesIterable = sensorContext.fileSystem()
.inputFiles(fs.predicates().hasRelativePath(relativePath));
// Use first matching input file
for (final InputFile inputFile : inputFilesIterable) {
return inputFile;
}
}
return null;
}
示例3: execute
import org.sonar.api.batch.sensor.SensorContext; //导入方法依赖的package包/类
@Override
public void execute(SensorContext context) {
// disable IssueFilter
checker.disabled = true;
Set<InputDir> inputDirs = new HashSet<>();
FileSystem fs = context.fileSystem();
for (InputFile inputFile : fs.inputFiles(fs.predicates().all())) {
InputDir inputDir = fs.inputDir(inputFile.file());
if (inputDir != null && !inputDirs.contains(inputDir)) {
createMissingIssues(context, inputDir);
inputDirs.add(inputDir);
}
createMissingIssues(context, inputFile);
}
save();
}
示例4: execute
import org.sonar.api.batch.sensor.SensorContext; //导入方法依赖的package包/类
@Override
public void execute(SensorContext context) {
FileSystem fileSystem = context.fileSystem();
FilePredicates predicates = fileSystem.predicates();
List<SquidAstVisitor<LexerlessGrammar>> visitors = new ArrayList<>(checks.all());
visitors.add(new FileLinesVisitor(fileLinesContextFactory, fileSystem));
LuaConfiguration configuration = new LuaConfiguration(fileSystem.encoding());
scanner = LuaAstScanner.create(configuration, visitors);
Iterable<java.io.File> files = fileSystem.files(
predicates.and(
predicates.hasType(InputFile.Type.MAIN),
predicates.hasLanguage(Lua.KEY),
inputFile -> !inputFile.absolutePath().endsWith("mxml")
));
scanner.scanFiles(ImmutableList.copyOf(files));
Collection<SourceCode> squidSourceFiles = scanner.getIndex().search(new QueryByType(SourceFile.class));
save(context, squidSourceFiles);
}
示例5: buildModel
import org.sonar.api.batch.sensor.SensorContext; //导入方法依赖的package包/类
@Override
protected Model<Location> buildModel(final SensorContext context) {
// Result
final Model<Location> model = new Model<>();
final ModelCreatingTreeVisitor visitor = new ModelCreatingTreeVisitor(model);
// Read all source files
final ActionParser<Tree> parser = JavaParser.createParser();
final JavaClasspath javaClassPath = new JavaClasspath(settings, context.fileSystem());
final FileSystem fs = context.fileSystem();
// Scan only main files for the 'current' language.
final FilePredicate filesToScan = fs.predicates().and(fs.predicates().hasType(Type.MAIN),
fs.predicates().hasLanguage(LANGUAGE));
for (final InputFile file : fs.inputFiles(filesToScan)) {
// Parse source
LOGGER.debug("Analyzing source file: {}", file.relativePath());
try {
visitor.on(file);
final Tree tree = parser.parse(file.contents());
// Create semantic model
LOGGER.debug("Creating semantic model ...");
SemanticModel.createFor((CompilationUnitTree) tree, javaClassPath.getElements());
// Read into model
LOGGER.debug("Reading model ...");
tree.accept(visitor);
} catch (final IOException e) {
LOGGER.warn("Could not read contents for {}", file.relativePath(), e);
}
}
return model;
}
示例6: execute
import org.sonar.api.batch.sensor.SensorContext; //导入方法依赖的package包/类
@Override
public void execute(final SensorContext context) {
final FileSystem fileSystem = context.fileSystem();
final FilePredicates predicates = fileSystem.predicates();
for (final InputFile inputFile : context.fileSystem().inputFiles(
predicates.and(predicates.hasLanguage(Rules.LANGUAGE_JAVA), predicates.hasType(Type.MAIN)))) {
if (inputFile.relativePath().endsWith("/package-info.java")) {
addMetric(context, inputFile, PackagesMetrics.PACKAGE_INFO_COUNT);
}
addMetric(context, inputFile, PackagesMetrics.JAVA_COUNT);
}
}
示例7: execute
import org.sonar.api.batch.sensor.SensorContext; //导入方法依赖的package包/类
@Override
public void execute(SensorContext context) {
FileSystem fileSystem = context.fileSystem();
FilePredicate mainFilePredicate = fileSystem.predicates().and(
fileSystem.predicates().hasType(InputFile.Type.MAIN),
fileSystem.predicates().hasLanguage(PerlLanguage.KEY));
List<InputFile> inputFiles = new ArrayList<>();
fileSystem.inputFiles(mainFilePredicate).forEach(inputFiles::add);
for (InputFile inputFile : inputFiles) {
this.analyseFile(inputFile, fileSystem.encoding(), context);
}
}
示例8: fill
import org.sonar.api.batch.sensor.SensorContext; //导入方法依赖的package包/类
@Override
public void fill(final SensorContext context, final InputFile inputFile,
final TsqlIssue... issues) {
for (final TsqlIssue error : issues) {
InputFile file = inputFile;
try {
if (error.getLine() < 1) {
LOGGER.warn(
format("Can't add issue %s on file %s as line is 0", error.getType(), error.getFilePath()));
continue;
}
if (file == null){
final FileSystem fileSystem = context.fileSystem();
file = fileSystem.inputFile(fileSystem.predicates().and(error.getPredicate()));
if (file == null) {
LOGGER.debug(format("Cound not find file %s to add issue %s at line %d.", error.getFilePath(),
error.getType(), error.getLine()));
continue;
}
}
final RuleKey rule = RuleKey.of(error.getRepositoryKey(), error.getType());
final NewIssue issue = context.newIssue().forRule(rule);
final NewIssueLocation loc = issue.newLocation().on(file).at(file.selectLine(error.getLine()));
if (error.getDescription() != null) {
loc.message(error.getDescription());
}
issue.at(loc).save();
} catch (final Throwable e) {
LOGGER.warn(format("Can't add issue %s on file %s at line %d.", error.getType(), file.absolutePath(),
error.getLine()), e);
}
}
}
示例9: collectFileMeasures
import org.sonar.api.batch.sensor.SensorContext; //导入方法依赖的package包/类
private static void collectFileMeasures(SensorContext context, SMInputCursor clazz) throws XMLStreamException {
FileSystem fileSystem = context.fileSystem();
FilePredicates predicates = fileSystem.predicates();
Map<String, InputFile> inputFileByFilename = new HashMap<>();
while (clazz.getNext() != null) {
String fileName = clazz.getAttrValue("filename");
InputFile inputFile;
// mxml files are not supported by the plugin
if (inputFileByFilename.containsKey(fileName)) {
inputFile = inputFileByFilename.get(fileName);
} else {
String key = fileName.startsWith(File.separator) ? fileName : (File.separator + fileName);
inputFile = fileSystem.inputFile(predicates.and(
predicates.matchesPathPattern("file:**" + key.replace(File.separator, "/")),
predicates.hasType(InputFile.Type.MAIN),
predicates.hasLanguage(Lua.KEY)));
inputFileByFilename.put(fileName, inputFile);
if (inputFile == null && !fileName.endsWith(".mxml")) {
LOG.warn("Cannot save coverage result for file: {}, because resource not found.", fileName);
}
}
if (inputFile != null) {
collectFileData(
clazz,
context.newCoverage()
.onFile(inputFile)
.ofType(CoverageType.UNIT)
);
} else {
SMInputCursor line = clazz.childElementCursor("lines").advance().childElementCursor("line");
while (line.getNext() != null) {
// advance
}
}
}
}
示例10: save
import org.sonar.api.batch.sensor.SensorContext; //导入方法依赖的package包/类
private void save(SensorContext context, Collection<SourceCode> squidSourceFiles) {
FileSystem fileSystem = context.fileSystem();
for (SourceCode squidSourceFile : squidSourceFiles) {
SourceFile squidFile = (SourceFile) squidSourceFile;
InputFile inputFile = fileSystem.inputFile(fileSystem.predicates().hasPath(squidFile.getKey()));
saveClassComplexity(context, inputFile, squidFile);
saveMeasures(context, inputFile, squidFile);
saveFunctionsComplexityDistribution(context, inputFile, squidFile);
saveFilesComplexityDistribution(context, inputFile, squidFile);
visitors.add(new LuaTokensVisitor(context, LuaLexer.create(configuration)));
saveViolations(context, inputFile, squidFile);
}
}
示例11: execute
import org.sonar.api.batch.sensor.SensorContext; //导入方法依赖的package包/类
@Override
public void execute(SensorContext sensorContext) {
// configure the lexer
final PageLexer lexer = new PageLexer();
FileSystem fileSystem = sensorContext.fileSystem();
// configure page scanner and the visitors
final HtmlAstScanner scanner = setupScanner(sensorContext);
FilePredicates predicates = fileSystem.predicates();
Iterable<InputFile> inputFiles = fileSystem.inputFiles(
predicates.and(
predicates.hasType(InputFile.Type.MAIN),
predicates.hasLanguage(WebConstants.LANGUAGE_KEY))
);
for (InputFile inputFile : inputFiles) {
WebSourceCode sourceCode = new WebSourceCode(inputFile);
try (FileReader reader = new FileReader(inputFile.file())) {
scanner.scan(lexer.parse(reader), sourceCode, fileSystem.encoding());
saveMetrics(sensorContext, sourceCode);
saveLineLevelMeasures(inputFile, sourceCode);
} catch (Exception e) {
LOG.error("Cannot analyze file " + inputFile.file().getAbsolutePath(), e);
}
}
}
示例12: CpdVisitor
import org.sonar.api.batch.sensor.SensorContext; //导入方法依赖的package包/类
public CpdVisitor(SensorContext sensorContext) {
this.sensorContext = sensorContext;
this.fileSystem = sensorContext.fileSystem();
}
示例13: CssSyntaxHighlighterVisitor
import org.sonar.api.batch.sensor.SensorContext; //导入方法依赖的package包/类
public CssSyntaxHighlighterVisitor(SensorContext sensorContext) {
this.sensorContext = sensorContext;
fileSystem = sensorContext.fileSystem();
}
示例14: AbstractMetricsVisitor
import org.sonar.api.batch.sensor.SensorContext; //导入方法依赖的package包/类
public AbstractMetricsVisitor(SensorContext sensorContext, NoSonarFilter noSonarFilter) {
this.sensorContext = sensorContext;
this.fileSystem = sensorContext.fileSystem();
this.noSonarFilter = noSonarFilter;
}
示例15: IssueSaver
import org.sonar.api.batch.sensor.SensorContext; //导入方法依赖的package包/类
public IssueSaver(SensorContext sensorContext, Checks checks) {
this.sensorContext = sensorContext;
this.fileSystem = sensorContext.fileSystem();
this.checks = checks;
}