diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-08-05 10:34:26 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-08-05 13:52:59 +0200 |
commit | e2daa5befa8916b585567a942141edcb7eff9a19 (patch) | |
tree | 379a210d60f42922461a33e065f112ba710655d9 /sonar-batch | |
parent | 92ab7df5f6d58a9711cdc00dbaafd0648b22e940 (diff) | |
download | sonarqube-e2daa5befa8916b585567a942141edcb7eff9a19.tar.gz sonarqube-e2daa5befa8916b585567a942141edcb7eff9a19.zip |
Fix some quality flaws
Diffstat (limited to 'sonar-batch')
26 files changed, 224 insertions, 372 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/ProfileLoader.java b/sonar-batch/src/main/java/org/sonar/batch/ProfileLoader.java deleted file mode 100644 index bc00a1c1a31..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/ProfileLoader.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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; - -import org.sonar.api.config.Settings; -import org.sonar.api.profiles.RulesProfile; - -/** - * This interface is implemented by the views plugin!! - * - * @deprecated in 4.2 - */ -@Deprecated -public interface ProfileLoader { - - /** - * Loads quality profile for specified project. - */ - RulesProfile load(Settings settings); - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/Data.java b/sonar-batch/src/main/java/org/sonar/batch/index/Data.java deleted file mode 100644 index aa47c04e799..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/index/Data.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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.index; - -import java.io.Serializable; - -public interface Data extends Serializable { - - String writeString(); - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/ResourceNotPersistedException.java b/sonar-batch/src/main/java/org/sonar/batch/index/ResourceNotPersistedException.java deleted file mode 100644 index 1cf29c6fd76..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/index/ResourceNotPersistedException.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.index; - -import org.sonar.api.resources.Resource; -import org.sonar.api.utils.SonarException; - -/** - * @since 2.6 - */ -public final class ResourceNotPersistedException extends SonarException { - - public ResourceNotPersistedException(Resource resource) { - super(resource.toString()); - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/StringData.java b/sonar-batch/src/main/java/org/sonar/batch/index/StringData.java deleted file mode 100644 index 6a88b5979b2..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/index/StringData.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.index; - -public class StringData implements Data { - private String data = null; - - public StringData() { - } - - public StringData(String s) { - this.data = s; - } - - public String data() { - return data; - } - - @Override - public String writeString() { - return data; - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueWrapper.java b/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueWrapper.java index 752e1e92d2f..d1d2efdf8f1 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueWrapper.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueWrapper.java @@ -20,6 +20,7 @@ package org.sonar.batch.issue; import java.util.Collection; +import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Map; @@ -142,7 +143,7 @@ public class DeprecatedIssueWrapper implements Issue { @Override public List<IssueComment> comments() { - return null; + return Collections.emptyList(); } @Override @@ -172,7 +173,7 @@ public class DeprecatedIssueWrapper implements Issue { @Override public Collection<String> tags() { - return null; + return Collections.emptyList(); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/IssueFilters.java b/sonar-batch/src/main/java/org/sonar/batch/issue/IssueFilters.java index ed609db0370..093cef71355 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/IssueFilters.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/IssueFilters.java @@ -37,181 +37,186 @@ import org.sonar.batch.protocol.output.BatchReport; @BatchSide public class IssueFilters { - private final org.sonar.api.issue.IssueFilter[] exclusionFilters; - private final IssueFilter[] filters; - private final Project project; + private static final class IssueAdapterForFilter implements Issue { + private final Project project; + private final org.sonar.batch.protocol.output.BatchReport.Issue rawIssue; + private final String componentKey; + + private IssueAdapterForFilter(Project project, org.sonar.batch.protocol.output.BatchReport.Issue rawIssue, String componentKey) { + this.project = project; + this.rawIssue = rawIssue; + this.componentKey = componentKey; + } - public IssueFilters(Project project, org.sonar.api.issue.IssueFilter[] exclusionFilters, IssueFilter[] filters) { - this.project = project; - this.exclusionFilters = exclusionFilters; - this.filters = filters; - } + @Override + public String key() { + throw unsupported(); + } - public IssueFilters(Project project, org.sonar.api.issue.IssueFilter[] exclusionFilters) { - this(project, exclusionFilters, new IssueFilter[0]); - } + @Override + public String componentKey() { + return componentKey; + } - public IssueFilters(Project project, IssueFilter[] filters) { - this(project, new org.sonar.api.issue.IssueFilter[0], filters); - } + @Override + public RuleKey ruleKey() { + return RuleKey.of(rawIssue.getRuleRepository(), rawIssue.getRuleKey()); + } - public IssueFilters(Project project) { - this(project, new org.sonar.api.issue.IssueFilter[0], new IssueFilter[0]); - } + @Override + public String language() { + throw unsupported(); + } - public boolean accept(String componentKey, BatchReport.Issue rawIssue) { - Issue issue = toIssueForIssueFilter(componentKey, rawIssue); - if (new DefaultIssueFilterChain(filters).accept(issue)) { - // Apply deprecated rules only if filter chain accepts the current issue - for (org.sonar.api.issue.IssueFilter filter : exclusionFilters) { - if (!filter.accept(issue)) { - return false; - } - } - return true; - } else { - return false; + @Override + public String severity() { + return rawIssue.getSeverity().name(); } - } - private Issue toIssueForIssueFilter(final String componentKey, final BatchReport.Issue rawIssue) { - return new Issue() { + @Override + public String message() { + return rawIssue.getMsg(); + } - @Override - public String key() { - throw unsupported(); - } + @Override + public Integer line() { + return rawIssue.hasLine() ? rawIssue.getLine() : null; + } - @Override - public String componentKey() { - return componentKey; - } + @Override + public Double effortToFix() { + return rawIssue.hasEffortToFix() ? rawIssue.getEffortToFix() : null; + } - @Override - public RuleKey ruleKey() { - return RuleKey.of(rawIssue.getRuleRepository(), rawIssue.getRuleKey()); - } + @Override + public String status() { + return Issue.STATUS_OPEN; + } - @Override - public String language() { - throw unsupported(); - } + @Override + public String resolution() { + return null; + } - @Override - public String severity() { - return rawIssue.getSeverity().name(); - } + @Override + public String reporter() { + throw unsupported(); + } - @Override - public String message() { - return rawIssue.getMsg(); - } + @Override + public String assignee() { + return null; + } - @Override - public Integer line() { - return rawIssue.hasLine() ? rawIssue.getLine() : null; - } + @Override + public Date creationDate() { + return project.getAnalysisDate(); + } - @Override - public Double effortToFix() { - return rawIssue.hasEffortToFix() ? rawIssue.getEffortToFix() : null; - } + @Override + public Date updateDate() { + return null; + } - @Override - public String status() { - return Issue.STATUS_OPEN; - } + @Override + public Date closeDate() { + return null; + } - @Override - public String resolution() { - return null; - } + @Override + public String attribute(String key) { + return attributes().get(key); + } - @Override - public String reporter() { - throw unsupported(); - } + @Override + public Map<String, String> attributes() { + return rawIssue.hasAttributes() ? KeyValueFormat.parse(rawIssue.getAttributes()) : Collections.<String, String>emptyMap(); + } - @Override - public String assignee() { - return null; - } + @Override + public String authorLogin() { + throw unsupported(); + } - @Override - public Date creationDate() { - return project.getAnalysisDate(); - } + @Override + public String actionPlanKey() { + throw unsupported(); + } - @Override - public Date updateDate() { - return null; - } + @Override + public List<IssueComment> comments() { + throw unsupported(); + } - @Override - public Date closeDate() { - return null; - } + @Override + public boolean isNew() { + throw unsupported(); + } - @Override - public String attribute(String key) { - return attributes().get(key); - } + @Override + public Duration debt() { + throw unsupported(); + } - @Override - public Map<String, String> attributes() { - return rawIssue.hasAttributes() ? KeyValueFormat.parse(rawIssue.getAttributes()) : Collections.<String, String>emptyMap(); - } + @Override + public String projectKey() { + return project.getEffectiveKey(); + } - @Override - public String authorLogin() { - throw unsupported(); - } + @Override + public String projectUuid() { + throw unsupported(); + } - @Override - public String actionPlanKey() { - throw unsupported(); - } + @Override + public String componentUuid() { + throw unsupported(); + } - @Override - public List<IssueComment> comments() { - throw unsupported(); - } + @Override + public Collection<String> tags() { + throw unsupported(); + } - @Override - public boolean isNew() { - throw unsupported(); - } + private static UnsupportedOperationException unsupported() { + return new UnsupportedOperationException("Not available for issues filters"); + } + } - @Override - public Duration debt() { - throw unsupported(); - } + private final org.sonar.api.issue.IssueFilter[] exclusionFilters; + private final IssueFilter[] filters; + private final Project project; - @Override - public String projectKey() { - return project.getEffectiveKey(); - } + public IssueFilters(Project project, org.sonar.api.issue.IssueFilter[] exclusionFilters, IssueFilter[] filters) { + this.project = project; + this.exclusionFilters = exclusionFilters; + this.filters = filters; + } - @Override - public String projectUuid() { - throw unsupported(); - } + public IssueFilters(Project project, org.sonar.api.issue.IssueFilter[] exclusionFilters) { + this(project, exclusionFilters, new IssueFilter[0]); + } - @Override - public String componentUuid() { - throw unsupported(); - } + public IssueFilters(Project project, IssueFilter[] filters) { + this(project, new org.sonar.api.issue.IssueFilter[0], filters); + } - @Override - public Collection<String> tags() { - throw unsupported(); - } + public IssueFilters(Project project) { + this(project, new org.sonar.api.issue.IssueFilter[0], new IssueFilter[0]); + } - private UnsupportedOperationException unsupported() { - return new UnsupportedOperationException("Not available for issues filters"); + public boolean accept(String componentKey, BatchReport.Issue rawIssue) { + Issue issue = new IssueAdapterForFilter(project, rawIssue, componentKey); + if (new DefaultIssueFilterChain(filters).accept(issue)) { + // Apply deprecated rules only if filter chain accepts the current issue + for (org.sonar.api.issue.IssueFilter filter : exclusionFilters) { + if (!filter.accept(issue)) { + return false; + } } - - }; - + return true; + } else { + return false; + } } } 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 67d3c98bb94..4363a59853b 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 @@ -20,8 +20,8 @@ package org.sonar.batch.issue; import com.google.common.base.Strings; +import org.sonar.api.batch.fs.InputComponent; import org.sonar.api.batch.fs.TextRange; -import org.sonar.api.batch.fs.internal.DefaultInputComponent; import org.sonar.api.batch.rule.ActiveRule; import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.batch.rule.Rule; @@ -63,8 +63,8 @@ public class ModuleIssues { } public boolean initAndAddIssue(Issue issue) { - String key = ((DefaultInputComponent) issue.primaryLocation().inputComponent()).key(); - BatchComponent component = componentCache.get(key); + InputComponent inputComponent = issue.primaryLocation().inputComponent(); + BatchComponent component = componentCache.get(inputComponent); Rule rule = validateRule(issue); ActiveRule activeRule = activeRules.find(issue.ruleKey()); @@ -102,7 +102,7 @@ public class ModuleIssues { applyExecutionFlows(issue); BatchReport.Issue rawIssue = builder.build(); - if (filters.accept(key, rawIssue)) { + if (filters.accept(inputComponent.key(), rawIssue)) { write(component, rawIssue); return true; } @@ -112,8 +112,7 @@ public class ModuleIssues { private void applyAdditionalLocations(Issue issue) { for (org.sonar.api.batch.sensor.issue.IssueLocation additionalLocation : issue.locations()) { locationBuilder.clear(); - String locationComponentKey = ((DefaultInputComponent) additionalLocation.inputComponent()).key(); - locationBuilder.setComponentRef(componentCache.get(locationComponentKey).batchId()); + locationBuilder.setComponentRef(componentCache.get(additionalLocation.inputComponent()).batchId()); String message = additionalLocation.message(); if (message != null) { locationBuilder.setMsg(message); @@ -128,8 +127,7 @@ public class ModuleIssues { flowBuilder.clear(); for (org.sonar.api.batch.sensor.issue.IssueLocation location : executionFlow.locations()) { locationBuilder.clear(); - String locationComponentKey = ((DefaultInputComponent) location.inputComponent()).key(); - locationBuilder.setComponentRef(componentCache.get(locationComponentKey).batchId()); + locationBuilder.setComponentRef(componentCache.get(location.inputComponent()).batchId()); String message = location.message(); if (message != null) { locationBuilder.setMsg(message); diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTracking.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTracking.java index 5ed488efedb..b75d8501edb 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTracking.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTracking.java @@ -226,7 +226,7 @@ public class IssueTracking { return rawIssuesByLines; } - private Multimap<Integer, ServerIssue> lastIssuesByLines(Collection<ServerIssue> previousIssues, IssueTrackingBlocksRecognizer rec) { + private static Multimap<Integer, ServerIssue> lastIssuesByLines(Collection<ServerIssue> previousIssues, IssueTrackingBlocksRecognizer rec) { Multimap<Integer, ServerIssue> previousIssuesByLines = LinkedHashMultimap.create(); for (ServerIssue previousIssue : previousIssues) { if (rec.isValidLineInReference(previousIssue.line())) { @@ -272,15 +272,15 @@ public class IssueTracking { } @CheckForNull - private Integer line(BatchReport.Issue rawIssue) { + private static Integer line(BatchReport.Issue rawIssue) { return rawIssue.hasLine() ? rawIssue.getLine() : null; } - private boolean isNotAlreadyMapped(ServerIssue previousIssue, IssueTrackingResult result) { + private static boolean isNotAlreadyMapped(ServerIssue previousIssue, IssueTrackingResult result) { return result.unmatched().contains(previousIssue); } - private boolean isNotAlreadyMapped(BatchReport.Issue rawIssue, IssueTrackingResult result) { + private static boolean isNotAlreadyMapped(BatchReport.Issue rawIssue, IssueTrackingResult result) { return !result.isMatched(rawIssue); } @@ -297,11 +297,11 @@ public class IssueTracking { } @CheckForNull - private String message(BatchReport.Issue rawIssue) { + private static String message(BatchReport.Issue rawIssue) { return rawIssue.hasMsg() ? rawIssue.getMsg() : null; } - private void mapIssue(BatchReport.Issue rawIssue, @Nullable ServerIssue ref, IssueTrackingResult result) { + private static void mapIssue(BatchReport.Issue rawIssue, @Nullable ServerIssue ref, IssueTrackingResult result) { if (ref != null) { result.setMatch(rawIssue, ref); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingResult.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingResult.java index e55ef46b03f..58e42138412 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingResult.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingResult.java @@ -92,7 +92,7 @@ class IssueTrackingResult { unmatchedForRuleAndLine.put(checksumNotNull, i); } - private Integer lineNotNull(ServerIssue i) { + private static Integer lineNotNull(ServerIssue i) { Integer line = i.line(); return line != null ? line : 0; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java index 01a218c2ae9..f202e552613 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java @@ -29,8 +29,6 @@ import java.util.Date; import java.util.List; import java.util.Set; import javax.annotation.CheckForNull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.sonar.api.batch.BatchSide; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.rule.ActiveRule; @@ -57,8 +55,6 @@ import org.sonar.core.util.CloseableIterator; @BatchSide public class LocalIssueTracking { - private static final Logger LOG = LoggerFactory.getLogger(LocalIssueTracking.class); - private final IssueCache issueCache; private final IssueTracking tracking; private final ServerLineHashesLoader lastLineHashes; diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java index 1212dd7ceaf..e2d03e28ec9 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java @@ -20,9 +20,7 @@ package org.sonar.batch.issue.tracking; import com.google.common.base.Function; - import javax.annotation.Nullable; - import org.sonar.api.batch.BatchSide; import org.sonar.api.batch.InstantiationStrategy; import org.sonar.api.utils.log.Logger; diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java index e8d11a2d775..d9e1687930d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/ComponentsPublisher.java @@ -112,7 +112,7 @@ public class ComponentsPublisher implements ReportPublisherStep { } } - private String getVersion(ProjectDefinition def) { + private static String getVersion(ProjectDefinition def) { String version = def.getVersion(); return StringUtils.isNotBlank(version) ? version : getVersion(def.getParent()); } @@ -130,7 +130,7 @@ public class ComponentsPublisher implements ReportPublisherStep { } } - private void writeProjectLink(BatchReport.Component.Builder componentBuilder, ProjectDefinition def, ComponentLink.Builder linkBuilder, String linkProp, + private static void writeProjectLink(BatchReport.Component.Builder componentBuilder, ProjectDefinition def, ComponentLink.Builder linkBuilder, String linkProp, ComponentLinkType linkType) { String link = def.properties().get(linkProp); if (StringUtils.isNotBlank(link)) { @@ -142,19 +142,19 @@ public class ComponentsPublisher implements ReportPublisherStep { } @CheckForNull - private String getLanguageKey(Resource r) { + private static String getLanguageKey(Resource r) { Language language = r.getLanguage(); return ResourceUtils.isFile(r) && language != null ? language.getKey() : null; } @CheckForNull - private String getName(Resource r) { + private static String getName(Resource r) { // Don't return name for directories and files since it can be guessed from the path return (ResourceUtils.isFile(r) || ResourceUtils.isDirectory(r)) ? null : r.getName(); } @CheckForNull - private String getDescription(Resource r) { + private static String getDescription(Resource r) { // Only for projets and modules return ResourceUtils.isProject(r) ? r.getDescription() : null; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileProvider.java b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileProvider.java index 7ab4959321d..2928ede2bba 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileProvider.java @@ -52,7 +52,7 @@ public class RulesProfileProvider extends ProviderAdapter { return singleton; } - private RulesProfile loadSingleLanguageProfile(ModuleQProfiles qProfiles, ActiveRules activeRules, String language) { + private static RulesProfile loadSingleLanguageProfile(ModuleQProfiles qProfiles, ActiveRules activeRules, String language) { QProfile qProfile = qProfiles.findByLanguage(language); if (qProfile != null) { return new RulesProfileWrapper(select(qProfile, activeRules)); @@ -60,7 +60,7 @@ public class RulesProfileProvider extends ProviderAdapter { return new RulesProfileWrapper(Lists.<RulesProfile>newArrayList()); } - private RulesProfile loadProfiles(ModuleQProfiles qProfiles, ActiveRules activeRules) { + private static RulesProfile loadProfiles(ModuleQProfiles qProfiles, ActiveRules activeRules) { Collection<RulesProfile> dtos = Lists.newArrayList(); for (QProfile qProfile : qProfiles.findAll()) { dtos.add(select(qProfile, activeRules)); @@ -68,7 +68,7 @@ public class RulesProfileProvider extends ProviderAdapter { return new RulesProfileWrapper(dtos); } - private RulesProfile select(QProfile qProfile, ActiveRules activeRules) { + private static RulesProfile select(QProfile qProfile, ActiveRules activeRules) { RulesProfile deprecatedProfile = new RulesProfile(); // TODO deprecatedProfile.setVersion(qProfile.version()); deprecatedProfile.setName(qProfile.getName()); diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java index 10fa76df9be..9729e8c51b7 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java @@ -125,7 +125,7 @@ public class ProjectReactorBuilder { return new ProjectReactor(rootProject); } - private Map<String, Map<String, String>> extractPropertiesByModule(String currentModuleId, Map<String, String> parentProperties) { + private static Map<String, Map<String, String>> extractPropertiesByModule(String currentModuleId, Map<String, String> parentProperties) { Map<String, String> allProperties = new HashMap<>(); allProperties.putAll(parentProperties); Map<String, String> currentModuleProperties = new HashMap<>(); @@ -202,7 +202,7 @@ public class ProjectReactorBuilder { } @CheckForNull - private File initModuleBuildDir(File moduleBaseDir, Map<String, String> moduleProperties) { + private static File initModuleBuildDir(File moduleBaseDir, Map<String, String> moduleProperties) { String buildDir = moduleProperties.get(PROPERTY_PROJECT_BUILDDIR); if (StringUtils.isBlank(buildDir)) { return null; diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorValidator.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorValidator.java index af8b1a9b7b6..b53e457ab7c 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorValidator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorValidator.java @@ -62,7 +62,7 @@ public class ProjectReactorValidator { } } - private void validateModule(ProjectDefinition moduleDef, List<String> validationMessages, @Nullable String branch, String rootProjectKey) { + private static void validateModule(ProjectDefinition moduleDef, List<String> validationMessages, @Nullable String branch, String rootProjectKey) { if (!ComponentKeys.isValidModuleKey(moduleDef.getKey())) { validationMessages.add(String.format("\"%s\" is not a valid project or module key. " + "Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.", moduleDef.getKey())); @@ -75,7 +75,7 @@ public class ProjectReactorValidator { } } - private void validateBranch(List<String> validationMessages, @Nullable String branch) { + private static void validateBranch(List<String> validationMessages, @Nullable String branch) { if (StringUtils.isNotEmpty(branch) && !ComponentKeys.isValidBranch(branch)) { validationMessages.add(String.format("\"%s\" is not a valid branch name. " + "Allowed characters are alphanumeric, '-', '_', '.' and '/'.", branch)); diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java index 5809addf3f5..24e26f5eb94 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java @@ -24,6 +24,14 @@ import com.google.common.base.Function; import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; +import java.io.File; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; import org.sonar.api.CoreProperties; import org.sonar.api.batch.fs.FilePredicate; @@ -34,16 +42,6 @@ import org.sonar.api.scan.filesystem.FileQuery; import org.sonar.api.scan.filesystem.ModuleFileSystem; import org.sonar.api.utils.MessageException; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - -import java.io.File; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; - /** * @since 3.5 */ @@ -121,7 +119,7 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module return testDirsOrFiles; } - private List<File> keepOnlyDirs(List<File> dirsOrFiles) { + private static List<File> keepOnlyDirs(List<File> dirsOrFiles) { List<File> result = new ArrayList<>(); for (File f : dirsOrFiles) { if (f.isDirectory()) { @@ -173,7 +171,7 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module throw modificationNotPermitted(); } - private UnsupportedOperationException modificationNotPermitted() { + private static UnsupportedOperationException modificationNotPermitted() { return new UnsupportedOperationException("Modifications of the file system are not permitted"); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileSystemLogger.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileSystemLogger.java index c68995dfa3f..4baa10412bb 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileSystemLogger.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileSystemLogger.java @@ -20,17 +20,16 @@ package org.sonar.batch.scan.filesystem; import com.google.common.annotations.VisibleForTesting; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.scan.filesystem.PathResolver; - import java.io.File; import java.nio.charset.Charset; import java.util.Iterator; import java.util.List; import java.util.Locale; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.sonar.api.batch.BatchSide; +import org.sonar.api.scan.filesystem.PathResolver; @BatchSide public class FileSystemLogger { @@ -63,7 +62,7 @@ public class FileSystemLogger { } } - private void logPaths(Logger logger, String label, File baseDir, List<File> paths) { + private static void logPaths(Logger logger, String label, File baseDir, List<File> paths) { if (!paths.isEmpty()) { PathResolver resolver = new PathResolver(); StringBuilder sb = new StringBuilder(label); diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/measure/MeasureValueCoder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/measure/MeasureValueCoder.java index b9c8f06511b..5d740d3592e 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/measure/MeasureValueCoder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/measure/MeasureValueCoder.java @@ -58,7 +58,7 @@ class MeasureValueCoder implements ValueCoder { value.putString(persistenceMode != null ? persistenceMode.name() : null); } - private void putUTFOrNull(Value value, @Nullable String utfOrNull) { + private static void putUTFOrNull(Value value, @Nullable String utfOrNull) { if (utfOrNull != null) { value.putUTF(utfOrNull); } else { diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ConsoleReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ConsoleReport.java index 2634fdd9af9..0627d986451 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ConsoleReport.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ConsoleReport.java @@ -25,12 +25,12 @@ import org.sonar.api.Properties; import org.sonar.api.Property; import org.sonar.api.PropertyType; import org.sonar.api.config.Settings; -import org.sonar.core.issue.DefaultIssue; import org.sonar.api.rule.Severity; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.batch.issue.IssueCache; import org.sonar.batch.scan.filesystem.InputPathCache; +import org.sonar.core.issue.DefaultIssue; @Properties({ @Property(key = ConsoleReport.CONSOLE_REPORT_ENABLED_KEY, name = "Enable console report", description = "Set this to true to generate a report in console output", @@ -135,7 +135,7 @@ public class ConsoleReport implements Reporter { } } - private void printNewIssues(StringBuilder sb, int issueCount, String severity, String severityLabel) { + private static void printNewIssues(StringBuilder sb, int issueCount, String severity, String severityLabel) { if (issueCount > 0) { sb.append(StringUtils.leftPad("+" + issueCount, LEFT_PAD)).append(" ").append(severityLabel).append("\n"); } 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 37400982c11..ec89540927a 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,14 +19,13 @@ */ package org.sonar.batch.scan.report; -import org.sonar.api.batch.rule.Rule; - -import org.sonar.api.batch.rule.Rules; +import javax.annotation.CheckForNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.batch.BatchSide; +import org.sonar.api.batch.rule.Rule; +import org.sonar.api.batch.rule.Rules; import org.sonar.api.issue.Issue; -import org.sonar.core.issue.DefaultIssue; import org.sonar.api.resources.Project; import org.sonar.api.rules.RulePriority; import org.sonar.batch.DefaultProjectTree; @@ -34,8 +33,7 @@ import org.sonar.batch.index.BatchComponent; import org.sonar.batch.index.BatchComponentCache; import org.sonar.batch.issue.IssueCache; import org.sonar.batch.scan.filesystem.InputPathCache; - -import javax.annotation.CheckForNull; +import org.sonar.core.issue.DefaultIssue; @BatchSide public class IssuesReportBuilder { @@ -84,7 +82,7 @@ public class IssuesReportBuilder { } } - private boolean validate(Issue issue, Rule rule, BatchComponent resource) { + private static boolean validate(Issue issue, Rule rule, BatchComponent resource) { if (rule == null) { LOG.warn("Unknow rule for issue {}", issue); return false; diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleReportComparator.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleReportComparator.java index e4a9c06f8b8..e5fb62516af 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleReportComparator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/RuleReportComparator.java @@ -38,27 +38,27 @@ public class RuleReportComparator implements Comparator<RuleReport>, Serializabl } } - private int compareByRuleSeverityAndName(RuleReport o1, RuleReport o2) { + private static int compareByRuleSeverityAndName(RuleReport o1, RuleReport o2) { return o1.getReportRuleKey().compareTo(o2.getReportRuleKey()); } - private boolean sameNewIssueCount(RuleReport o1, RuleReport o2) { + private static boolean sameNewIssueCount(RuleReport o1, RuleReport o2) { return o2.getTotal().getNewIssuesCount() == o1.getTotal().getNewIssuesCount(); } - private boolean sameSeverity(RuleReport o1, RuleReport o2) { + private static boolean sameSeverity(RuleReport o1, RuleReport o2) { return o1.getSeverity().equals(o2.getSeverity()); } - private int compareNewIssueCount(RuleReport o1, RuleReport o2) { + private static int compareNewIssueCount(RuleReport o1, RuleReport o2) { return o2.getTotal().getNewIssuesCount() - o1.getTotal().getNewIssuesCount(); } - private boolean bothHaveNewIssues(RuleReport o1, RuleReport o2) { + private static boolean bothHaveNewIssues(RuleReport o1, RuleReport o2) { return o1.getTotal().getNewIssuesCount() > 0 && o2.getTotal().getNewIssuesCount() > 0; } - private boolean bothHaveNoNewIssue(RuleReport o1, RuleReport o2) { + private static boolean bothHaveNoNewIssue(RuleReport o1, RuleReport o2) { return o1.getTotal().getNewIssuesCount() == 0 && o2.getTotal().getNewIssuesCount() == 0; } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/SourceProvider.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/SourceProvider.java index dd7d4631138..38371c740b8 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/SourceProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/SourceProvider.java @@ -31,17 +31,14 @@ import org.sonar.api.batch.BatchSide; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.fs.InputFile; import org.sonar.batch.index.BatchComponent; -import org.sonar.batch.scan.filesystem.InputPathCache; @BatchSide public class SourceProvider { private static final Logger LOG = LoggerFactory.getLogger(SourceProvider.class); - private final InputPathCache inputPathCache; private final FileSystem fs; - public SourceProvider(InputPathCache inputPathCache, FileSystem fs) { - this.inputPathCache = inputPathCache; + public SourceProvider(FileSystem fs) { this.fs = fs; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java b/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java index 33ec11e25f5..f7ccc0b3e51 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java @@ -20,6 +20,16 @@ package org.sonar.batch.scm; import com.google.common.base.Preconditions; +import java.text.Normalizer; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import java.util.regex.Pattern; +import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,13 +43,6 @@ import org.sonar.batch.protocol.output.BatchReport.Changesets.Builder; import org.sonar.batch.protocol.output.BatchReportWriter; import org.sonar.batch.util.ProgressReport; -import javax.annotation.Nullable; - -import java.text.Normalizer; -import java.util.*; -import java.util.concurrent.TimeUnit; -import java.util.regex.Pattern; - class DefaultBlameOutput implements BlameOutput { private static final Logger LOG = LoggerFactory.getLogger(DefaultBlameOutput.class); @@ -99,7 +102,7 @@ class DefaultBlameOutput implements BlameOutput { progressReport.message(count + "/" + total + " files analyzed, last one was " + file.absolutePath()); } - private void addChangeset(Builder scmBuilder, BlameLine line) { + private static void addChangeset(Builder scmBuilder, BlameLine line) { BatchReport.Changesets.Changeset.Builder changesetBuilder = BatchReport.Changesets.Changeset.newBuilder(); if (StringUtils.isNotBlank(line.revision())) { changesetBuilder.setRevision(line.revision()); @@ -114,7 +117,7 @@ class DefaultBlameOutput implements BlameOutput { scmBuilder.addChangeset(changesetBuilder.build()); } - private String normalizeString(@Nullable String inputString) { + private static String normalizeString(@Nullable String inputString) { if (inputString == null) { return ""; } @@ -123,12 +126,12 @@ class DefaultBlameOutput implements BlameOutput { return removeNonAsciiCharacters(stringWithoutAccents); } - private String removeAccents(String inputString) { + private static String removeAccents(String inputString) { String unicodeDecomposedString = Normalizer.normalize(inputString, Normalizer.Form.NFD); return ACCENT_CODES.matcher(unicodeDecomposedString).replaceAll(""); } - private String removeNonAsciiCharacters(String inputString) { + private static String removeNonAsciiCharacters(String inputString) { return NON_ASCII_CHARS.matcher(inputString).replaceAll("_"); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java b/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java index a74ad87c3e1..a57fb5556c3 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java @@ -19,6 +19,8 @@ */ package org.sonar.batch.scm; +import java.util.LinkedList; +import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.CoreProperties; @@ -35,9 +37,6 @@ import org.sonar.batch.protocol.input.ProjectRepositories; import org.sonar.batch.report.ReportPublisher; import org.sonar.batch.scan.filesystem.InputPathCache; -import java.util.LinkedList; -import java.util.List; - public final class ScmSensor implements Sensor { private static final Logger LOG = LoggerFactory.getLogger(ScmSensor.class); @@ -105,7 +104,7 @@ public final class ScmSensor implements Sensor { return filesToBlame; } - private void addIfNotEmpty(List<InputFile> filesToBlame, InputFile f) { + private static void addIfNotEmpty(List<InputFile> filesToBlame, InputFile f) { if (!f.isEmpty()) { filesToBlame.add(f); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/sensor/coverage/CoverageExclusions.java b/sonar-batch/src/main/java/org/sonar/batch/sensor/coverage/CoverageExclusions.java index 89343b7274a..4439043e370 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/sensor/coverage/CoverageExclusions.java +++ b/sonar-batch/src/main/java/org/sonar/batch/sensor/coverage/CoverageExclusions.java @@ -124,7 +124,7 @@ public class CoverageExclusions { log("Excluded sources for coverage: ", resourcePatterns); } - private void log(String title, Collection<WildcardPattern> patterns) { + private static void log(String title, Collection<WildcardPattern> patterns) { if (!patterns.isEmpty()) { LOG.info(title); for (WildcardPattern pattern : patterns) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestable.java b/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestable.java index 6bfe739b196..8dc53a3cdfb 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestable.java +++ b/sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestable.java @@ -79,7 +79,7 @@ public class DefaultTestable implements MutableTestable { throw unsupported(); } - private UnsupportedOperationException unsupported() { + private static UnsupportedOperationException unsupported() { return new UnsupportedOperationException("No more available since SQ 5.2"); } |