use of org.sonarsource.sonarlint.core.analysis.container.analysis.filesystem.SonarLintInputFile in project sonarlint-core by SonarSource.
the class IssueExclusionsRegexpScannerTests method init.
@BeforeEach
void init() {
MockitoAnnotations.initMocks(this);
blockPatterns = Arrays.asList(new DoubleRegexpMatcher(Pattern.compile("// SONAR-OFF"), Pattern.compile("// SONAR-ON")), new DoubleRegexpMatcher(Pattern.compile("// FOO-OFF"), Pattern.compile("// FOO-ON")));
allFilePatterns = Collections.singletonList(Pattern.compile("@SONAR-IGNORE-ALL"));
javaFile = new SonarLintInputFile(new OnDiskTestClientInputFile(Paths.get("src/Foo.java"), "src/Foo.java", false, StandardCharsets.UTF_8), f -> mock(Metadata.class));
regexpScanner = new IssueExclusionsRegexpScanner(javaFile, allFilePatterns, blockPatterns);
}
use of org.sonarsource.sonarlint.core.analysis.container.analysis.filesystem.SonarLintInputFile in project sonarlint-core by SonarSource.
the class EnforceIssuesFilter method accept.
@Override
public boolean accept(FilterableIssue issue, IssueFilterChain chain) {
var atLeastOneRuleMatched = false;
var atLeastOnePatternFullyMatched = false;
IssuePattern matchingPattern = null;
for (IssuePattern pattern : multicriteriaPatterns) {
if (pattern.matchRule(issue.ruleKey())) {
atLeastOneRuleMatched = true;
var component = ((DefaultFilterableIssue) issue).getComponent();
if (component.isFile()) {
var file = (SonarLintInputFile) component;
if (pattern.matchFile(file.relativePath())) {
atLeastOnePatternFullyMatched = true;
matchingPattern = pattern;
}
}
}
}
if (atLeastOneRuleMatched) {
if (atLeastOnePatternFullyMatched) {
LOG.debug("Issue {} enforced by pattern {}", issue, matchingPattern);
}
return atLeastOnePatternFullyMatched;
} else {
return chain.accept(issue);
}
}
use of org.sonarsource.sonarlint.core.analysis.container.analysis.filesystem.SonarLintInputFile in project sonarlint-core by SonarSource.
the class ModuleInputFileBuilder method create.
public SonarLintInputFile create(ClientInputFile inputFile) {
var defaultInputFile = new SonarLintInputFile(inputFile, f -> {
LOG.debug("Initializing metadata of file {}", f.uri());
var charset = f.charset();
InputStream stream;
try {
stream = f.inputStream();
} catch (IOException e) {
throw new IllegalStateException("Failed to open a stream on file: " + f.uri(), e);
}
return fileMetadata.readMetadata(stream, charset != null ? charset : Charset.defaultCharset(), f.uri(), null);
});
defaultInputFile.setType(inputFile.isTest() ? Type.TEST : Type.MAIN);
var fileLanguage = inputFile.language();
if (fileLanguage != null) {
LOG.debug("Language of file '{}' is set to '{}'", inputFile.uri(), fileLanguage);
defaultInputFile.setLanguage(fileLanguage);
} else {
defaultInputFile.setLanguage(langDetection.language(defaultInputFile));
}
return defaultInputFile;
}
Aggregations