import java.util.Set;
import java.util.stream.Stream;
import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
import org.sonar.api.SonarQubeSide;
import org.sonar.api.SonarRuntime;
import org.sonar.api.batch.fs.InputModule;
}
@CheckForNull
- public static Integer sumOrNull(Integer o1, Integer o2) {
+ public static Integer sumOrNull(@Nullable Integer o1, @Nullable Integer o2) {
return o1 == null ? o2 : (o1 + o2);
}
}
@CheckForNull
- public static Integer maxOrNull(Integer o1, Integer o2) {
+ public static Integer maxOrNull(@Nullable Integer o1, @Nullable Integer o2) {
return o1 == null ? o2 : Math.max(o1, o2);
}
}
private static void completeBatchExtensions(ComponentContainer container, List<Object> extensions, Class type) {
- if (container != null) {
- extensions.addAll(container.getComponentsByType(type));
- completeBatchExtensions(container.getParent(), extensions, type);
+ extensions.addAll(container.getComponentsByType(type));
+ ComponentContainer parentContainer = container.getParent();
+ if (parentContainer != null) {
+ completeBatchExtensions(parentContainer, extensions, type);
}
}
import java.io.Serializable;
import java.util.Collection;
+import javax.annotation.Nullable;
import org.sonar.api.SonarRuntime;
import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.SensorContext;
return null;
}
- private Resource resourceOrProject(Resource resource) {
+ private Resource resourceOrProject(@Nullable Resource resource) {
if (resource == null) {
return project;
}
*/
package org.sonar.scanner.issue.ignore.pattern;
-import org.sonar.api.scan.issue.filter.FilterableIssue;
-
import com.google.common.collect.Sets;
+import java.util.Set;
+import javax.annotation.Nullable;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.rule.RuleKey;
+import org.sonar.api.scan.issue.filter.FilterableIssue;
import org.sonar.api.utils.WildcardPattern;
-import java.util.Set;
-
public class IssuePattern {
private WildcardPattern resourcePattern;
}
boolean matchRule(RuleKey rule) {
- if (rule == null) {
- return false;
- }
-
String key = new StringBuilder().append(rule.repository()).append(':').append(rule.rule()).toString();
return rulePattern.match(key);
}
- boolean matchResource(String resource) {
+ boolean matchResource(@Nullable String resource) {
return resource != null && resourcePattern.match(resource);
}
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
+import javax.annotation.Nullable;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
}
- private void logDir(Logger logger, String label, File dir) {
+ private static void logDir(Logger logger, String label, @Nullable File dir) {
if (dir != null) {
logger.info(label + dir.getAbsolutePath());
}
package org.sonar.scanner.scan.report;
import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.ScannerSide;
}
}
- private static boolean validate(TrackedIssue issue, Rule rule, BatchComponent resource) {
+ private static boolean validate(TrackedIssue issue, @Nullable Rule rule, @Nullable BatchComponent resource) {
if (rule == null) {
LOG.warn("Unknow rule for issue {}", issue);
return false;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
+import javax.annotation.Nullable;
import org.sonar.api.batch.rule.Rule;
import org.sonar.api.rules.RulePriority;
import org.sonar.scanner.index.BatchComponent;
}
}
- public boolean isDisplayableLine(Integer lineNumber, boolean all) {
+ public boolean isDisplayableLine(@Nullable Integer lineNumber, boolean all) {
if (lineNumber == null || lineNumber < 1) {
return false;
}
*/
package org.sonar.scanner.issue.ignore.pattern;
-import org.sonar.api.scan.issue.filter.FilterableIssue;
-import org.sonar.scanner.issue.ignore.pattern.IssuePattern;
import org.junit.Test;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.Rule;
+import org.sonar.api.scan.issue.filter.FilterableIssue;
+
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
assertThat(pattern.match(create(rule, javaFile, null))).isFalse();
assertThat(pattern.match(create(rule, javaFile, 12))).isTrue();
- assertThat(pattern.match(create((Rule) null, javaFile, 5))).isFalse();
assertThat(pattern.match(create(rule, null, null))).isFalse();
- assertThat(pattern.match(create((Rule) null, null, null))).isFalse();
}
private FilterableIssue create(Rule rule, String component, Integer line) {
return mockIssue;
}
- @Test
- public void shouldNotMatchNullRule() {
- assertThat(new IssuePattern("*", "*").matchRule(null)).isFalse();
- }
-
@Test
public void shouldPrintPatternToString() {
IssuePattern pattern = new IssuePattern("*", "checkstyle:*");