aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-batch/src/main/java/org')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java7
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/cpd/CpdComponents.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java16
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java52
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java1
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/rule/DefaultRulesLoader.java54
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/rule/RuleFinderCompatibility.java26
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/rule/RulesLoader.java26
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java53
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ProjectWSLoaderProvider.java58
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReport.java3
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReportBuilder.java14
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java15
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/report/ReportRuleKey.java5
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/report/ReportSummary.java13
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/report/ResourceReport.java3
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleNameProvider.java18
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleReport.java3
22 files changed, 314 insertions, 67 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java
index cb6f40dafc1..acf0515fbf5 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java
@@ -42,8 +42,8 @@ public class BatchComponents {
// only static stuff
}
- public static Collection all(GlobalMode analysisMode) {
- List components = Lists.newArrayList(
+ public static Collection<Object> all(GlobalMode analysisMode) {
+ List<Object> components = Lists.newArrayList(
DefaultResourceTypes.get(),
// SCM
ScmConfiguration.class,
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
index cea1eabf7ba..db806c103c9 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
@@ -19,6 +19,11 @@
*/
package org.sonar.batch.bootstrap;
+import org.sonar.batch.rule.RulesLoader;
+
+import org.sonar.batch.rule.DefaultRulesLoader;
+import org.sonar.batch.rule.RulesProvider;
+
import java.util.List;
import java.util.Map;
import org.sonar.api.CoreProperties;
@@ -81,6 +86,7 @@ public class GlobalContainer extends ComponentContainer {
CachesManager.class,
GlobalMode.class,
GlobalSettings.class,
+ new RulesProvider(),
ServerClient.class,
Logback.class,
DefaultServer.class,
@@ -94,6 +100,7 @@ public class GlobalContainer extends ComponentContainer {
new GlobalRepositoriesProvider(),
UserRepository.class);
addIfMissing(BatchPluginInstaller.class, PluginInstaller.class);
+ addIfMissing(DefaultRulesLoader.class, RulesLoader.class);
addIfMissing(DefaultGlobalRepositoriesLoader.class, GlobalRepositoriesLoader.class);
addIfMissing(DefaultProjectRepositoriesLoader.class, ProjectRepositoriesLoader.class);
addIfMissing(DefaultServerIssuesLoader.class, ServerIssuesLoader.class);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java
index b10f996f20f..197544db075 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java
@@ -72,7 +72,7 @@ public class ServerClient {
}
public URI getURI(String pathStartingWithSlash) {
- Preconditions.checkArgument(pathStartingWithSlash.startsWith("/"), "Path must start with slash /");
+ Preconditions.checkArgument(pathStartingWithSlash.startsWith("/"), "Path must start with slash /: " + pathStartingWithSlash);
String path = StringEscapeUtils.escapeHtml(pathStartingWithSlash);
return URI.create(getURL() + path);
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/cpd/CpdComponents.java b/sonar-batch/src/main/java/org/sonar/batch/cpd/CpdComponents.java
index 7d6a6be2a94..a30c6d0d832 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/cpd/CpdComponents.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/cpd/CpdComponents.java
@@ -20,7 +20,9 @@
package org.sonar.batch.cpd;
import com.google.common.collect.ImmutableList;
+
import java.util.List;
+
import org.sonar.batch.cpd.index.IndexFactory;
public final class CpdComponents {
@@ -28,7 +30,7 @@ public final class CpdComponents {
private CpdComponents() {
}
- public static List all() {
+ public static List<? extends Object> all() {
return ImmutableList.of(
CpdSensor.class,
CpdMappings.class,
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java
index 5fad21f0905..a27b4c272a3 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java
@@ -25,7 +25,6 @@ import org.sonar.api.batch.rule.ActiveRule;
import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.batch.rule.Rule;
import org.sonar.api.batch.rule.Rules;
-import org.sonar.api.batch.rule.internal.DefaultActiveRule;
import org.sonar.api.resources.Project;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.MessageException;
@@ -42,7 +41,7 @@ public class ModuleIssues {
private final Project project;
private final IssueFilters filters;
- public ModuleIssues(ActiveRules activeRules, @Nullable Rules rules, IssueCache cache, Project project, IssueFilters filters) {
+ public ModuleIssues(ActiveRules activeRules, Rules rules, IssueCache cache, Project project, IssueFilters filters) {
this.activeRules = activeRules;
this.rules = rules;
this.cache = cache;
@@ -50,17 +49,10 @@ public class ModuleIssues {
this.filters = filters;
}
- public ModuleIssues(ActiveRules activeRules, IssueCache cache, Project project, IssueFilters filters) {
- this(activeRules, null, cache, project, filters);
- }
-
public boolean initAndAddIssue(DefaultIssue issue) {
RuleKey ruleKey = issue.ruleKey();
- Rule rule = null;
- if (rules != null) {
- rule = rules.find(ruleKey);
- validateRule(issue, rule);
- }
+ Rule rule = rules.find(ruleKey);
+ validateRule(issue, rule);
ActiveRule activeRule = activeRules.find(ruleKey);
if (activeRule == null) {
// rule does not exist or is not enabled -> ignore the issue
@@ -86,7 +78,7 @@ public class ModuleIssues {
private void updateIssue(DefaultIssue issue, @Nullable Rule rule, ActiveRule activeRule) {
if (Strings.isNullOrEmpty(issue.message())) {
- issue.setMessage(((DefaultActiveRule) activeRule).name());
+ issue.setMessage(rule.name());
}
if (project != null) {
issue.setCreationDate(project.getAnalysisDate());
diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java
index 370c3f32ca9..6cf1c15157d 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java
@@ -19,8 +19,15 @@
*/
package org.sonar.batch.mediumtest;
+import org.sonar.api.server.rule.RulesDefinition.Repository;
+
+import org.sonar.api.server.rule.RulesDefinition;
+import org.sonar.batch.protocol.input.RulesSearchResult;
+import org.sonar.batch.rule.RulesLoader;
+import org.sonar.batch.protocol.input.Rule;
import com.google.common.base.Function;
import com.google.common.io.Files;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
@@ -29,9 +36,11 @@ import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
+
import org.sonar.api.CoreProperties;
import org.sonar.api.SonarPlugin;
import org.sonar.api.batch.bootstrap.ProjectReactor;
@@ -78,6 +87,7 @@ public class BatchMediumTester {
private final FakeServerIssuesLoader serverIssues = new FakeServerIssuesLoader();
private final FakeServerLineHashesLoader serverLineHashes = new FakeServerLineHashesLoader();
private final Map<String, String> bootstrapProperties = new HashMap<>();
+ private final FakeRulesLoader rulesLoader = new FakeRulesLoader();
private LogOutput logOutput = null;
public BatchMediumTester build() {
@@ -116,6 +126,30 @@ public class BatchMediumTester {
return this;
}
+ public BatchMediumTesterBuilder addRule(Rule rule) {
+ rulesLoader.addRule(rule);
+ return this;
+ }
+
+ public BatchMediumTesterBuilder addRules(List<Rule> rules) {
+ for (Rule r : rules) {
+ rulesLoader.addRule(r);
+ }
+ return this;
+ }
+
+ public BatchMediumTesterBuilder addRules(RulesDefinition rulesDefinition) {
+ RulesDefinition.Context context = new RulesDefinition.Context();
+ rulesDefinition.define(context);
+ List<Repository> repositories = context.repositories();
+ for (Repository repo : repositories) {
+ for (RulesDefinition.Rule rule : repo.rules()) {
+ this.addRule(new Rule(rule.repository().key() + ":" + rule.key(), rule.repository().key(), rule.internalKey(), rule.name(), rule.severity(), repo.language()));
+ }
+ }
+ return this;
+ }
+
public BatchMediumTesterBuilder addDefaultQProfile(String language, String name) {
addQProfile(language, name);
globalRefProvider.globalSettings().put("sonar.profile." + language, name);
@@ -171,6 +205,7 @@ public class BatchMediumTester {
builder.projectRefProvider,
builder.serverIssues,
builder.serverLineHashes,
+ builder.rulesLoader,
new DefaultDebtModel())
.setBootstrapProperties(builder.bootstrapProperties)
.setLogOutput(builder.logOutput)
@@ -223,6 +258,23 @@ public class BatchMediumTester {
}
}
+ private static class FakeRulesLoader implements RulesLoader {
+ private List<Rule> rules = new LinkedList<>();
+
+ public FakeRulesLoader addRule(Rule rule) {
+ rules.add(rule);
+ return this;
+ }
+
+ @Override
+ public RulesSearchResult load() {
+ RulesSearchResult r = new RulesSearchResult();
+ r.setRules(rules);
+ return r;
+ }
+
+ }
+
private static class FakeGlobalRepositoriesLoader implements GlobalRepositoriesLoader {
private int metricId = 1;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java
index 388faf11b6a..564ce0f3658 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java
@@ -64,5 +64,4 @@ public class DefaultProjectRepositoriesLoader implements ProjectRepositoriesLoad
throw MessageException.of("No quality profiles has been found this project, you probably don't have any language plugin suitable for this analysis.");
}
}
-
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java b/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java
index 532547dc16d..5bb0a4a86bd 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java
@@ -44,7 +44,7 @@ public class ActiveRulesProvider extends ProviderAdapter {
return singleton;
}
- private ActiveRules load(ProjectRepositories ref) {
+ private static ActiveRules load(ProjectRepositories ref) {
ActiveRulesBuilder builder = new ActiveRulesBuilder();
for (ActiveRule activeRule : ref.activeRules()) {
NewActiveRule newActiveRule = builder.create(RuleKey.of(activeRule.repositoryKey(), activeRule.ruleKey()));
diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/DefaultRulesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/rule/DefaultRulesLoader.java
new file mode 100644
index 00000000000..9ab9c176ae6
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/rule/DefaultRulesLoader.java
@@ -0,0 +1,54 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.batch.rule;
+
+import org.sonar.batch.protocol.input.Rule;
+
+import org.sonar.batch.protocol.input.RulesSearchResult;
+import org.sonar.batch.bootstrap.WSLoader;
+
+public class DefaultRulesLoader implements RulesLoader {
+ private static final String RULES_SEARCH_URL = "/api/rules/search?ps=500&f=repo,name,internalKey,severity,lang";
+
+ private final WSLoader wsLoader;
+
+ public DefaultRulesLoader(WSLoader wsLoader) {
+ this.wsLoader = wsLoader;
+ }
+
+ @Override
+ public RulesSearchResult load() {
+
+ RulesSearchResult rules = RulesSearchResult.fromJson(wsLoader.loadString(getUrl(1)));
+
+ for (int i = 2; i < 100; i++) {
+ RulesSearchResult moreRules = RulesSearchResult.fromJson(wsLoader.loadString(getUrl(i)));
+ if (moreRules.getRules().isEmpty()) {
+ break;
+ }
+ rules.getRules().addAll(moreRules.getRules());
+ }
+ return rules;
+ }
+
+ private String getUrl(int page) {
+ return RULES_SEARCH_URL + "&p=" + page;
+ }
+}
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 6dab1413350..fc0f28ed66e 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
@@ -19,13 +19,12 @@
*/
package org.sonar.batch.rule;
+import org.sonar.api.batch.rule.Rules;
+
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
-import org.sonar.api.batch.rule.ActiveRule;
-import org.sonar.api.batch.rule.ActiveRules;
-import org.sonar.api.batch.rule.internal.DefaultActiveRule;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleFinder;
@@ -46,10 +45,10 @@ import java.util.Collections;
*/
public class RuleFinderCompatibility implements RuleFinder {
- private final ActiveRules activeRules;
+ private final Rules rules;
- public RuleFinderCompatibility(ActiveRules activeRules) {
- this.activeRules = activeRules;
+ public RuleFinderCompatibility(Rules rules) {
+ this.rules = rules;
}
@Override
@@ -64,7 +63,7 @@ public class RuleFinderCompatibility implements RuleFinder {
@Override
public Rule findByKey(RuleKey key) {
- return toRule(activeRules.find(key));
+ return toRule(rules.find(key));
}
@Override
@@ -96,28 +95,27 @@ public class RuleFinderCompatibility implements RuleFinder {
}
private Collection<Rule> byRepository(RuleQuery query) {
- return Collections2.transform(activeRules.findByRepository(query.getRepositoryKey()), new Function<ActiveRule, Rule>() {
+ return Collections2.transform(rules.findByRepository(query.getRepositoryKey()), new Function<org.sonar.api.batch.rule.Rule, Rule>() {
@Override
- public Rule apply(@Nonnull ActiveRule input) {
+ public Rule apply(@Nonnull org.sonar.api.batch.rule.Rule input) {
return toRule(input);
}
});
}
private Collection<Rule> byKey(RuleQuery query) {
- Rule rule = toRule(activeRules.find(RuleKey.of(query.getRepositoryKey(), query.getKey())));
+ Rule rule = toRule(rules.find(RuleKey.of(query.getRepositoryKey(), query.getKey())));
return rule != null ? Arrays.asList(rule) : Collections.<Rule>emptyList();
}
private Collection<Rule> byInternalKey(RuleQuery query) {
- Rule rule = toRule(activeRules.findByInternalKey(query.getRepositoryKey(), query.getConfigKey()));
+ Rule rule = toRule(rules.findByInternalKey(query.getRepositoryKey(), query.getConfigKey()));
return rule != null ? Arrays.asList(rule) : Collections.<Rule>emptyList();
}
@CheckForNull
- private Rule toRule(@Nullable ActiveRule rule) {
- DefaultActiveRule ar = (DefaultActiveRule) rule;
- return ar == null ? null : Rule.create(ar.ruleKey().repository(), ar.ruleKey().rule()).setName(ar.name()).setConfigKey(ar.internalKey()).setLanguage(ar.language());
+ private static Rule toRule(@Nullable org.sonar.api.batch.rule.Rule ar) {
+ return ar == null ? null : Rule.create(ar.key().repository(), ar.key().rule()).setName(ar.name()).setConfigKey(ar.internalKey());
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesLoader.java
new file mode 100644
index 00000000000..84a937b05e5
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesLoader.java
@@ -0,0 +1,26 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.batch.rule;
+
+import org.sonar.batch.protocol.input.RulesSearchResult;
+
+public interface RulesLoader {
+ RulesSearchResult load();
+}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java
new file mode 100644
index 00000000000..c864489149c
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java
@@ -0,0 +1,53 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.batch.rule;
+
+import org.picocontainer.injectors.ProviderAdapter;
+
+import org.sonar.api.rule.RuleKey;
+import org.sonar.api.batch.rule.internal.RulesBuilder;
+import org.sonar.api.batch.rule.internal.NewRule;
+import org.sonar.batch.protocol.input.Rule;
+import org.sonar.api.batch.rule.Rules;
+
+public class RulesProvider extends ProviderAdapter {
+ private Rules singleton = null;
+
+ public Rules provide(RulesLoader ref) {
+ if (singleton == null) {
+ singleton = load(ref);
+ }
+ return singleton;
+ }
+
+ private static Rules load(RulesLoader ref) {
+ RulesBuilder builder = new RulesBuilder();
+
+ for (Rule inputRule : ref.load().getRules()) {
+ NewRule newRule = builder.add(RuleKey.parse(inputRule.ruleKey()));
+ newRule.setName(inputRule.name());
+ newRule.setSeverity(inputRule.severity());
+ newRule.setInternalKey(inputRule.internalKey());
+ }
+
+ return builder.build();
+ }
+
+}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
index 1e0b5d4571b..30bd5a2ff26 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
@@ -132,7 +132,7 @@ public class ProjectScanContainer extends ComponentContainer {
ProjectExclusions.class,
ProjectReactorValidator.class,
new ProjectRepositoriesProvider(),
- new WSLoaderProjectProvider(),
+ new ProjectWSLoaderProvider(),
DefaultResourceCreationLock.class,
CodeColorizers.class,
MetricProvider.class,
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectWSLoaderProvider.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectWSLoaderProvider.java
new file mode 100644
index 00000000000..e3caa1daaba
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectWSLoaderProvider.java
@@ -0,0 +1,58 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.batch.scan;
+
+import org.picocontainer.injectors.ProviderAdapter;
+
+import java.util.Map;
+
+import org.sonar.batch.bootstrap.AnalysisProperties;
+import org.sonar.batch.bootstrap.ServerClient;
+import org.sonar.batch.bootstrap.WSLoader;
+import org.sonar.home.cache.PersistentCache;
+import org.sonar.api.batch.AnalysisMode;
+import org.sonar.batch.bootstrap.WSLoader.LoadStrategy;
+
+public class ProjectWSLoaderProvider extends ProviderAdapter {
+ private WSLoader wsLoader;
+
+ public WSLoader provide(AnalysisProperties props, AnalysisMode mode, PersistentCache cache, ServerClient client) {
+ if (wsLoader == null) {
+ // recreate cache directory if needed for this analysis
+ cache.reconfigure();
+ wsLoader = new WSLoader(isCacheEnabled(props.properties(), mode.isPreview()), cache, client);
+ wsLoader.setStrategy(getStrategy(mode));
+ }
+ return wsLoader;
+ }
+
+ private static LoadStrategy getStrategy(AnalysisMode mode) {
+ if (mode.isQuick()) {
+ return LoadStrategy.CACHE_FIRST;
+ }
+
+ return LoadStrategy.SERVER_FIRST;
+ }
+
+ private static boolean isCacheEnabled(Map<String, String> props, boolean isPreview) {
+ String enableOffline = props.get("sonar.enableOffline");
+ return isPreview && "true".equals(enableOffline);
+ }
+}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReport.java
index c087219e1f2..1f2b551ef2f 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReport.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReport.java
@@ -19,9 +19,10 @@
*/
package org.sonar.batch.scan.report;
+import org.sonar.api.batch.rule.Rule;
+
import com.google.common.collect.Maps;
import org.sonar.api.issue.Issue;
-import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RulePriority;
import org.sonar.batch.index.BatchComponent;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReportBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReportBuilder.java
index 43e423e7fa7..9be4093233a 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReportBuilder.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReportBuilder.java
@@ -19,6 +19,9 @@
*/
package org.sonar.batch.scan.report;
+import org.sonar.api.batch.rule.Rule;
+
+import org.sonar.api.batch.rule.Rules;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.BatchSide;
@@ -26,8 +29,6 @@ import org.sonar.api.issue.Issue;
import org.sonar.core.issue.DefaultIssue;
import org.sonar.api.resources.Project;
import org.sonar.api.rule.RuleKey;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleFinder;
import org.sonar.api.rules.RulePriority;
import org.sonar.batch.DefaultProjectTree;
import org.sonar.batch.index.BatchComponent;
@@ -43,14 +44,14 @@ public class IssuesReportBuilder {
private static final Logger LOG = LoggerFactory.getLogger(IssuesReportBuilder.class);
private final IssueCache issueCache;
- private final RuleFinder ruleFinder;
+ private final Rules rules;
private final BatchComponentCache resourceCache;
private final DefaultProjectTree projectTree;
private final InputPathCache inputPathCache;
- public IssuesReportBuilder(IssueCache issueCache, RuleFinder ruleFinder, BatchComponentCache resourceCache, DefaultProjectTree projectTree, InputPathCache inputPathCache) {
+ public IssuesReportBuilder(IssueCache issueCache, Rules rules, BatchComponentCache resourceCache, DefaultProjectTree projectTree, InputPathCache inputPathCache) {
this.issueCache = issueCache;
- this.ruleFinder = ruleFinder;
+ this.rules = rules;
this.resourceCache = resourceCache;
this.projectTree = projectTree;
this.inputPathCache = inputPathCache;
@@ -98,8 +99,7 @@ public class IssuesReportBuilder {
@CheckForNull
private Rule findRule(Issue issue) {
- RuleKey ruleKey = issue.ruleKey();
- return ruleFinder.findByKey(ruleKey);
+ return rules.find(issue.ruleKey());
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java
index b13b5468d67..7dd9db0d18d 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java
@@ -19,6 +19,9 @@
*/
package org.sonar.batch.scan.report;
+import org.sonar.api.batch.rule.Rule;
+
+import org.sonar.api.batch.rule.Rules;
import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
@@ -31,8 +34,6 @@ import org.sonar.api.batch.fs.InputDir;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputDir;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.batch.rule.ActiveRules;
-import org.sonar.api.batch.rule.internal.DefaultActiveRule;
import org.sonar.api.config.Settings;
import org.sonar.core.issue.DefaultIssue;
import org.sonar.api.platform.Server;
@@ -72,18 +73,18 @@ public class JSONReport implements Reporter {
private final Settings settings;
private final FileSystem fileSystem;
private final Server server;
- private final ActiveRules activeRules;
+ private final Rules rules;
private final IssueCache issueCache;
private final InputPathCache fileCache;
private final Project rootModule;
private final UserRepository userRepository;
- public JSONReport(Settings settings, FileSystem fileSystem, Server server, ActiveRules activeRules, IssueCache issueCache,
+ public JSONReport(Settings settings, FileSystem fileSystem, Server server, Rules rules, IssueCache issueCache,
Project rootModule, InputPathCache fileCache, UserRepository userRepository) {
this.settings = settings;
this.fileSystem = fileSystem;
this.server = server;
- this.activeRules = activeRules;
+ this.rules = rules;
this.issueCache = issueCache;
this.rootModule = rootModule;
this.fileCache = fileCache;
@@ -214,7 +215,7 @@ public class JSONReport implements Reporter {
json.endArray();
}
- private void writeUsers(JsonWriter json, Collection<BatchInput.User> users) throws IOException {
+ private static void writeUsers(JsonWriter json, Collection<BatchInput.User> users) throws IOException {
json.name("users").beginArray();
for (BatchInput.User user : users) {
json
@@ -227,7 +228,7 @@ public class JSONReport implements Reporter {
}
private String getRuleName(RuleKey ruleKey) {
- DefaultActiveRule rule = (DefaultActiveRule) activeRules.find(ruleKey);
+ Rule rule = rules.find(ruleKey);
return rule != null ? rule.name() : null;
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ReportRuleKey.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ReportRuleKey.java
index 99549c2ac1d..0373e62c504 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ReportRuleKey.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ReportRuleKey.java
@@ -19,9 +19,10 @@
*/
package org.sonar.batch.scan.report;
+import org.sonar.api.batch.rule.Rule;
+
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
-import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RulePriority;
/**
@@ -68,7 +69,7 @@ public class ReportRuleKey implements Comparable<ReportRuleKey> {
@Override
public int compareTo(ReportRuleKey o) {
if (severity == o.getSeverity()) {
- return getRule().ruleKey().toString().compareTo(o.getRule().ruleKey().toString());
+ return getRule().key().toString().compareTo(o.getRule().key().toString());
}
return o.getSeverity().compareTo(severity);
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ReportSummary.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ReportSummary.java
index 18e964fa262..680b4f086ec 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ReportSummary.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ReportSummary.java
@@ -19,9 +19,10 @@
*/
package org.sonar.batch.scan.report;
+import org.sonar.api.batch.rule.Rule;
+
import com.google.common.collect.Maps;
import org.sonar.api.issue.Issue;
-import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RulePriority;
import java.util.ArrayList;
@@ -49,12 +50,12 @@ public class ReportSummary {
initMaps(reportRuleKey);
ruleReportByRuleKey.get(reportRuleKey).getTotal().incrementCountInCurrentAnalysis();
total.incrementCountInCurrentAnalysis();
- totalByRuleKey.get(rule.ruleKey().toString()).incrementCountInCurrentAnalysis();
+ totalByRuleKey.get(rule.key().toString()).incrementCountInCurrentAnalysis();
totalBySeverity.get(severity.toString()).incrementCountInCurrentAnalysis();
if (issue.isNew()) {
total.incrementNewIssuesCount();
ruleReportByRuleKey.get(reportRuleKey).getTotal().incrementNewIssuesCount();
- totalByRuleKey.get(rule.ruleKey().toString()).incrementNewIssuesCount();
+ totalByRuleKey.get(rule.key().toString()).incrementNewIssuesCount();
totalBySeverity.get(severity.toString()).incrementNewIssuesCount();
}
}
@@ -72,7 +73,7 @@ public class ReportSummary {
initMaps(reportRuleKey);
total.incrementResolvedIssuesCount();
ruleReportByRuleKey.get(reportRuleKey).getTotal().incrementResolvedIssuesCount();
- totalByRuleKey.get(rule.ruleKey().toString()).incrementResolvedIssuesCount();
+ totalByRuleKey.get(rule.key().toString()).incrementResolvedIssuesCount();
totalBySeverity.get(severity.toString()).incrementResolvedIssuesCount();
}
@@ -80,8 +81,8 @@ public class ReportSummary {
if (!ruleReportByRuleKey.containsKey(reportRuleKey)) {
ruleReportByRuleKey.put(reportRuleKey, new RuleReport(reportRuleKey));
}
- if (!totalByRuleKey.containsKey(reportRuleKey.getRule().ruleKey().toString())) {
- totalByRuleKey.put(reportRuleKey.getRule().ruleKey().toString(), new IssueVariation());
+ if (!totalByRuleKey.containsKey(reportRuleKey.getRule().key().toString())) {
+ totalByRuleKey.put(reportRuleKey.getRule().key().toString(), new IssueVariation());
}
if (!totalBySeverity.containsKey(reportRuleKey.getSeverity().toString())) {
totalBySeverity.put(reportRuleKey.getSeverity().toString(), new IssueVariation());
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ResourceReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ResourceReport.java
index 4a4329f908d..2a6135e5c17 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ResourceReport.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ResourceReport.java
@@ -19,9 +19,10 @@
*/
package org.sonar.batch.scan.report;
+import org.sonar.api.batch.rule.Rule;
+
import com.google.common.collect.Maps;
import org.sonar.api.issue.Issue;
-import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RulePriority;
import org.sonar.batch.index.BatchComponent;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleNameProvider.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleNameProvider.java
index 6fa0a7da42e..9f61793cb73 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleNameProvider.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleNameProvider.java
@@ -19,26 +19,27 @@
*/
package org.sonar.batch.scan.report;
+import org.sonar.api.batch.rule.Rule;
+
+import org.sonar.api.batch.rule.Rules;
import org.apache.commons.lang.StringEscapeUtils;
import org.sonar.api.batch.BatchSide;
import org.sonar.api.rule.RuleKey;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleFinder;
import javax.annotation.CheckForNull;
@BatchSide
public class RuleNameProvider {
- private RuleFinder ruleFinder;
+ private Rules rules;
- public RuleNameProvider(RuleFinder ruleFinder) {
- this.ruleFinder = ruleFinder;
+ public RuleNameProvider(Rules rules) {
+ this.rules = rules;
}
@CheckForNull
private String nameFromDB(RuleKey ruleKey) {
- Rule r = ruleFinder.findByKey(ruleKey);
- return r != null ? r.getName() : null;
+ Rule r = rules.find(ruleKey);
+ return r != null ? r.name() : null;
}
public String nameForHTML(RuleKey ruleKey) {
@@ -52,8 +53,7 @@ public class RuleNameProvider {
}
public String nameForHTML(Rule rule) {
- String name = nameFromDB(RuleKey.of(rule.getRepositoryKey(), rule.getKey()));
- return StringEscapeUtils.escapeHtml(name != null ? name : rule.getName());
+ return StringEscapeUtils.escapeHtml(rule.name());
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleReport.java
index 1ddf1b38282..16d6b4cf999 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleReport.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleReport.java
@@ -19,8 +19,9 @@
*/
package org.sonar.batch.scan.report;
+import org.sonar.api.batch.rule.Rule;
+
import org.apache.commons.lang.builder.ToStringBuilder;
-import org.sonar.api.rules.Rule;
public final class RuleReport {
private final ReportRuleKey reportRuleKey;