aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2016-11-08 16:46:36 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2016-11-08 16:46:52 +0100
commitcbce11b666ab221d1c2da35ef5082e18bf8fd573 (patch)
treef50b0f5528f37c2ba05cb4c95aeee4e7150c5347
parent90b80bd13929daf105060524bd5170b1b0d30e96 (diff)
downloadsonarqube-cbce11b666ab221d1c2da35ef5082e18bf8fd573.tar.gz
sonarqube-cbce11b666ab221d1c2da35ef5082e18bf8fd573.zip
Fix quality flaws
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java5
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchExtensionDictionnary.java7
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/DeprecatedSensorContext.java3
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/IssuePattern.java13
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileSystemLogger.java3
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/IssuesReportBuilder.java3
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/ResourceReport.java3
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/IssuePatternTest.java11
8 files changed, 21 insertions, 27 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java
index e1820ef53c9..b94287ce6aa 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java
@@ -32,6 +32,7 @@ import java.util.Objects;
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;
@@ -220,7 +221,7 @@ public class SensorContextTester implements SensorContext {
}
@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);
}
@@ -243,7 +244,7 @@ public class SensorContextTester implements SensorContext {
}
@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);
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchExtensionDictionnary.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchExtensionDictionnary.java
index 6023bb1d0fb..6aac81cf120 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchExtensionDictionnary.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchExtensionDictionnary.java
@@ -130,9 +130,10 @@ public class BatchExtensionDictionnary {
}
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);
}
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/DeprecatedSensorContext.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/DeprecatedSensorContext.java
index 8a5df01a559..4b19f7d70d2 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/DeprecatedSensorContext.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/DeprecatedSensorContext.java
@@ -21,6 +21,7 @@ package org.sonar.scanner.deprecated;
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;
@@ -135,7 +136,7 @@ public class DeprecatedSensorContext extends DefaultSensorContext implements Sen
return null;
}
- private Resource resourceOrProject(Resource resource) {
+ private Resource resourceOrProject(@Nullable Resource resource) {
if (resource == null) {
return project;
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/IssuePattern.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/IssuePattern.java
index 7518f1af4da..60e2869f568 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/IssuePattern.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/IssuePattern.java
@@ -19,16 +19,15 @@
*/
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;
@@ -144,15 +143,11 @@ public class IssuePattern {
}
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);
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileSystemLogger.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileSystemLogger.java
index 2bebaa7fd29..879abdec13d 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileSystemLogger.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileSystemLogger.java
@@ -25,6 +25,7 @@ import java.nio.charset.Charset;
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;
@@ -83,7 +84,7 @@ public class FileSystemLogger {
}
}
- 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());
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/IssuesReportBuilder.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/IssuesReportBuilder.java
index d69ba0f70f3..cd39b0750c2 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/IssuesReportBuilder.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/IssuesReportBuilder.java
@@ -20,6 +20,7 @@
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;
@@ -81,7 +82,7 @@ public class IssuesReportBuilder {
}
}
- 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;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/ResourceReport.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/ResourceReport.java
index 22ae24470b1..e0bf1df43ca 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/ResourceReport.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/ResourceReport.java
@@ -25,6 +25,7 @@ import java.util.Collections;
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;
@@ -127,7 +128,7 @@ public final class ResourceReport {
}
}
- public boolean isDisplayableLine(Integer lineNumber, boolean all) {
+ public boolean isDisplayableLine(@Nullable Integer lineNumber, boolean all) {
if (lineNumber == null || lineNumber < 1) {
return false;
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/IssuePatternTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/IssuePatternTest.java
index bb14aa84f96..99149437811 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/IssuePatternTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/pattern/IssuePatternTest.java
@@ -19,11 +19,11 @@
*/
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;
@@ -82,9 +82,7 @@ public class IssuePatternTest {
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) {
@@ -100,11 +98,6 @@ public class IssuePatternTest {
}
@Test
- public void shouldNotMatchNullRule() {
- assertThat(new IssuePattern("*", "*").matchRule(null)).isFalse();
- }
-
- @Test
public void shouldPrintPatternToString() {
IssuePattern pattern = new IssuePattern("*", "checkstyle:*");