From b85d63707cb6f0d6bff9968a9d5333fcd3406928 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Wed, 13 May 2015 09:29:45 +0200 Subject: [PATCH] Fix some quality flaws --- .../java/org/sonar/xoo/lang/XooTokenizer.java | 5 +-- .../batch/maven/MavenProjectConverter.java | 3 +- .../TestExecutionAndCoveragePublisher.java | 6 ++-- .../batch/rule/RuleFinderCompatibility.java | 33 +++++++++++++------ 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooTokenizer.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooTokenizer.java index 760249e9235..2d5325bcbb0 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooTokenizer.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/XooTokenizer.java @@ -25,13 +25,14 @@ import net.sourceforge.pmd.cpd.TokenEntry; import net.sourceforge.pmd.cpd.Tokenizer; import net.sourceforge.pmd.cpd.Tokens; import org.apache.commons.io.FileUtils; -import org.sonar.api.BatchComponent; +import org.sonar.api.BatchSide; import org.sonar.api.batch.fs.FileSystem; import java.io.File; import java.io.IOException; -public class XooTokenizer implements Tokenizer, BatchComponent { +@BatchSide +public class XooTokenizer implements Tokenizer { private FileSystem fs; diff --git a/sonar-batch/src/main/java/org/sonar/batch/maven/MavenProjectConverter.java b/sonar-batch/src/main/java/org/sonar/batch/maven/MavenProjectConverter.java index 754472f6722..21623db784d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/maven/MavenProjectConverter.java +++ b/sonar-batch/src/main/java/org/sonar/batch/maven/MavenProjectConverter.java @@ -38,6 +38,7 @@ import org.sonar.api.task.TaskExtension; import org.sonar.api.utils.MessageException; import org.sonar.java.api.JavaUtils; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.io.File; @@ -292,7 +293,7 @@ public class MavenProjectConverter implements TaskExtension { private static String[] toPaths(Collection dirs) { Collection paths = Collections2.transform(dirs, new Function() { @Override - public String apply(File dir) { + public String apply(@Nonnull File dir) { return dir.getAbsolutePath(); } }); diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/TestExecutionAndCoveragePublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/TestExecutionAndCoveragePublisher.java index 9144de126bf..344ba437ce9 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/TestExecutionAndCoveragePublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/TestExecutionAndCoveragePublisher.java @@ -36,6 +36,8 @@ import org.sonar.batch.protocol.output.BatchReport.Test; import org.sonar.batch.protocol.output.BatchReportWriter; import org.sonar.core.test.TestPlanBuilder; +import javax.annotation.Nonnull; + import java.util.HashSet; import java.util.Set; @@ -50,7 +52,7 @@ public class TestExecutionAndCoveragePublisher implements ReportPublisherStep { } @Override - public Test apply(MutableTestCase testCase) { + public Test apply(@Nonnull MutableTestCase testCase) { builder.clear(); builder.setName(testCase.name()); if (testCase.doesCover()) { @@ -86,7 +88,7 @@ public class TestExecutionAndCoveragePublisher implements ReportPublisherStep { } @Override - public CoverageDetail apply(String testName) { + public CoverageDetail apply(@Nonnull String testName) { // Take first test with provided name MutableTestCase testCase = testPlan.testCasesByName(testName).iterator().next(); builder.clear(); diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/RuleFinderCompatibility.java b/sonar-batch/src/main/java/org/sonar/batch/rule/RuleFinderCompatibility.java index dc497d31886..6dab1413350 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/RuleFinderCompatibility.java +++ b/sonar-batch/src/main/java/org/sonar/batch/rule/RuleFinderCompatibility.java @@ -32,6 +32,7 @@ import org.sonar.api.rules.RuleFinder; import org.sonar.api.rules.RuleQuery; import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.Arrays; @@ -82,25 +83,37 @@ public class RuleFinderCompatibility implements RuleFinder { public Collection findAll(RuleQuery query) { if (query.getConfigKey() != null) { if (query.getRepositoryKey() != null && query.getKey() == null) { - Rule rule = toRule(activeRules.findByInternalKey(query.getRepositoryKey(), query.getConfigKey())); - return rule != null ? Arrays.asList(rule) : Collections.emptyList(); + return byInternalKey(query); } } else if (query.getRepositoryKey() != null) { if (query.getKey() != null) { - Rule rule = toRule(activeRules.find(RuleKey.of(query.getRepositoryKey(), query.getKey()))); - return rule != null ? Arrays.asList(rule) : Collections.emptyList(); + return byKey(query); } else { - return Collections2.transform(activeRules.findByRepository(query.getRepositoryKey()), new Function() { - @Override - public Rule apply(ActiveRule input) { - return toRule(input); - } - }); + return byRepository(query); } } throw new UnsupportedOperationException("Unable to find rule by query"); } + private Collection byRepository(RuleQuery query) { + return Collections2.transform(activeRules.findByRepository(query.getRepositoryKey()), new Function() { + @Override + public Rule apply(@Nonnull ActiveRule input) { + return toRule(input); + } + }); + } + + private Collection byKey(RuleQuery query) { + Rule rule = toRule(activeRules.find(RuleKey.of(query.getRepositoryKey(), query.getKey()))); + return rule != null ? Arrays.asList(rule) : Collections.emptyList(); + } + + private Collection byInternalKey(RuleQuery query) { + Rule rule = toRule(activeRules.findByInternalKey(query.getRepositoryKey(), query.getConfigKey())); + return rule != null ? Arrays.asList(rule) : Collections.emptyList(); + } + @CheckForNull private Rule toRule(@Nullable ActiveRule rule) { DefaultActiveRule ar = (DefaultActiveRule) rule; -- 2.39.5