}
public boolean isIgnoreAllIssues() {
+ checkMetadata();
return ignoreAllIssues;
}
}
public boolean isIgnoreAllIssuesOnLine(@Nullable Integer line) {
+ checkMetadata();
if (line == null || ignoreIssuesOnlineRanges == null) {
return false;
}
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
+import java.util.function.Consumer;
import java.util.stream.Collectors;
import org.junit.Before;
import org.junit.Rule;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
public class DefaultInputFileTest {
@Override
public boolean accept(FilterableIssue issue, IssueFilterChain chain) {
InputComponent component = ((DefaultFilterableIssue) issue).getComponent();
- if (component.isFile() && ((DefaultInputFile) component).isIgnoreAllIssues()) {
- return false;
- }
- if (component.isFile() && ((DefaultInputFile) component).isIgnoreAllIssuesOnLine(issue.line())) {
+
+ if (isIgnoreIssue(component, issue)) {
return false;
}
+
if (hasRuleMatchFor(component, issue)) {
return false;
}
return chain.accept(issue);
}
+ private static boolean isIgnoreIssue(InputComponent component, FilterableIssue issue) {
+ if (component.isFile()) {
+ DefaultInputFile inputFile = (DefaultInputFile) component;
+ return inputFile.isIgnoreAllIssues() || inputFile.isIgnoreAllIssuesOnLine(issue.line());
+ }
+ return false;
+ }
+
public void addRuleExclusionPatternForComponent(DefaultInputFile inputFile, WildcardPattern rulePattern) {
if ("*".equals(rulePattern.toString())) {
inputFile.setIgnoreAllIssues(true);
private LineExclusion currentLineExclusion = null;
private int fileLength = 0;
private DoubleRegexpMatcher currentMatcher;
+ private boolean ignoreAllIssues;
IssueExclusionsRegexpScanner(DefaultInputFile inputFile, List<Pattern> allFilePatterns, List<DoubleRegexpMatcher> blockMatchers) {
this.allFilePatterns = allFilePatterns;
@Override
public void handleIgnoreEoL(char c) {
- if (inputFile.isIgnoreAllIssues()) {
+ if (ignoreAllIssues) {
return;
}
sb.append(c);
@Override
public void newLine() {
- if (inputFile.isIgnoreAllIssues()) {
+ if (ignoreAllIssues) {
return;
}
processLine(sb.toString());
@Override
public void eof() {
- if (inputFile.isIgnoreAllIssues()) {
+ if (ignoreAllIssues) {
return;
}
processLine(sb.toString());
if (pattern.matcher(line).find()) {
// nothing more to do on this file
LOG.debug(" - Exclusion pattern '{}': all issues in this file will be ignored.", pattern);
+ ignoreAllIssues = true;
inputFile.setIgnoreAllIssues(true);
return;
}
import java.util.stream.IntStream;
import org.junit.Before;
import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.FileMetadata;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+import static org.mockito.Mockito.mock;
public class IssueExclusionsRegexpScannerTest {
private DefaultInputFile javaFile;
-
- @Mock
- private IssueExclusionPatternInitializer patternsInitializer;
+ private IssueExclusionPatternInitializer patternsInitializer = mock(IssueExclusionPatternInitializer.class);
private List<Pattern> allFilePatterns;
private List<DoubleRegexpMatcher> blockPatterns;
@Before
public void init() {
- MockitoAnnotations.initMocks(this);
-
blockPatterns = Arrays.asList(new DoubleRegexpMatcher[] {
new DoubleRegexpMatcher(Pattern.compile("// SONAR-OFF"), Pattern.compile("// SONAR-ON")),
new DoubleRegexpMatcher(Pattern.compile("// FOO-OFF"), Pattern.compile("// FOO-ON"))