diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-06-03 12:40:18 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-06-03 12:40:24 +0200 |
commit | 81c526901fb2f10eca77c7cccb306c959da4469b (patch) | |
tree | 9bbbd17d6675aa3ae3b2f78503a77e1f3d93ba6a /sonar-batch | |
parent | cf6e592d4967864c8a7f1ed8a0676ab1add70748 (diff) | |
download | sonarqube-81c526901fb2f10eca77c7cccb306c959da4469b.tar.gz sonarqube-81c526901fb2f10eca77c7cccb306c959da4469b.zip |
Fix quality flaws
Diffstat (limited to 'sonar-batch')
12 files changed, 55 insertions, 68 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContext.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContext.java index 9118dc3450e..d10f6ba5fab 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContext.java +++ b/sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContext.java @@ -23,6 +23,7 @@ import com.google.common.base.Objects; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; +import java.util.Map; import org.sonar.api.batch.SonarIndex; import org.sonar.api.measures.FileLinesContext; import org.sonar.api.measures.Measure; @@ -33,8 +34,6 @@ import org.sonar.api.resources.ResourceUtils; import org.sonar.api.utils.KeyValueFormat; import org.sonar.api.utils.KeyValueFormat.Converter; -import java.util.Map; - public class DefaultFileLinesContext implements FileLinesContext { private final SonarIndex index; @@ -143,7 +142,7 @@ public class DefaultFileLinesContext implements FileLinesContext { * @see #loadData(String, Converter) * @see #save() */ - private boolean shouldSave(Map<Integer, Object> lines) { + private static boolean shouldSave(Map<Integer, Object> lines) { return !(lines instanceof ImmutableMap); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/compute/AbstractNewCoverageFileAnalyzer.java b/sonar-batch/src/main/java/org/sonar/batch/compute/AbstractNewCoverageFileAnalyzer.java index 446c0820244..6f17ffc0341 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/compute/AbstractNewCoverageFileAnalyzer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/compute/AbstractNewCoverageFileAnalyzer.java @@ -175,7 +175,7 @@ public abstract class AbstractNewCoverageFileAnalyzer implements Decorator { context.saveMeasure(newUncoveredConditions); } - private Map<Integer, Integer> parseCountByLine(@Nullable Measure measure) { + private static Map<Integer, Integer> parseCountByLine(@Nullable Measure measure) { if (measure != null && measure.hasData()) { return KeyValueFormat.parseIntInt(measure.getData()); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/compute/CountUnresolvedIssuesDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/compute/CountUnresolvedIssuesDecorator.java index cd57819911a..53dd6a49d51 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/compute/CountUnresolvedIssuesDecorator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/compute/CountUnresolvedIssuesDecorator.java @@ -146,7 +146,7 @@ public class CountUnresolvedIssuesDecorator implements Decorator { } } - private void saveTotalIssues(DecoratorContext context, Collection<Issue> issues) { + private static void saveTotalIssues(DecoratorContext context, Collection<Issue> issues) { if (context.getMeasure(CoreMetrics.VIOLATIONS) == null) { Collection<Measure> childrenIssues = context.getChildrenMeasures(CoreMetrics.VIOLATIONS); Double sum = MeasureUtils.sum(true, childrenIssues); @@ -161,7 +161,7 @@ public class CountUnresolvedIssuesDecorator implements Decorator { } } - private void saveIssuesForSeverity(DecoratorContext context, RulePriority ruleSeverity, Multiset<RulePriority> severitiesBag) { + private static void saveIssuesForSeverity(DecoratorContext context, RulePriority ruleSeverity, Multiset<RulePriority> severitiesBag) { Metric metric = SeverityUtils.severityToIssueMetric(ruleSeverity); if (context.getMeasure(metric) == null) { Collection<Measure> children = context.getChildrenMeasures(MeasuresFilters.metric(metric)); @@ -248,11 +248,11 @@ public class CountUnresolvedIssuesDecorator implements Decorator { context.saveMeasure(measure); } - private void saveMeasure(DecoratorContext context, Metric metric, int value) { + private static void saveMeasure(DecoratorContext context, Metric metric, int value) { context.saveMeasure(metric, (double) (value + sumChildren(context, metric))); } - private int sumChildren(DecoratorContext context, Metric metric) { + private static int sumChildren(DecoratorContext context, Metric metric) { int sum = 0; if (!ResourceUtils.isFile(context.getResource())) { sum = MeasureUtils.sum(true, context.getChildrenMeasures(metric)).intValue(); @@ -260,7 +260,7 @@ public class CountUnresolvedIssuesDecorator implements Decorator { return sum; } - private Multiset<RuleKey> initRules(Map<RulePriority, Multiset<RuleKey>> rulesPerSeverity, RulePriority severity) { + private static Multiset<RuleKey> initRules(Map<RulePriority, Multiset<RuleKey>> rulesPerSeverity, RulePriority severity) { Multiset<RuleKey> rulesBag = rulesPerSeverity.get(severity); if (rulesBag == null) { rulesBag = HashMultiset.create(); @@ -289,11 +289,11 @@ public class CountUnresolvedIssuesDecorator implements Decorator { return count; } - private boolean isAfter(Issue issue, @Nullable Date date) { + private static boolean isAfter(Issue issue, @Nullable Date date) { return date == null || (issue.creationDate() != null && DateUtils.truncatedCompareTo(issue.creationDate(), date, Calendar.SECOND) > 0); } - private boolean shouldSaveNewMetrics(DecoratorContext context) { + private static boolean shouldSaveNewMetrics(DecoratorContext context) { return context.getMeasure(CoreMetrics.NEW_VIOLATIONS) == null; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/compute/TimeMachineConfigurationPersister.java b/sonar-batch/src/main/java/org/sonar/batch/compute/TimeMachineConfigurationPersister.java index 1255c64a35f..68b5e1a8330 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/compute/TimeMachineConfigurationPersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/compute/TimeMachineConfigurationPersister.java @@ -74,7 +74,7 @@ public final class TimeMachineConfigurationPersister implements Decorator { return true; } - private void updatePeriodParams(Snapshot snapshot, PastSnapshot pastSnapshot) { + private static void updatePeriodParams(Snapshot snapshot, PastSnapshot pastSnapshot) { int periodIndex = pastSnapshot.getIndex(); snapshot.setPeriodMode(periodIndex, pastSnapshot.getMode()); snapshot.setPeriodModeParameter(periodIndex, pastSnapshot.getModeParameter()); diff --git a/sonar-batch/src/main/java/org/sonar/batch/debt/DebtDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/debt/DebtDecorator.java index c2f4c97b9a6..237f27bae67 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/debt/DebtDecorator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/debt/DebtDecorator.java @@ -21,6 +21,12 @@ package org.sonar.batch.debt; import com.google.common.annotations.VisibleForTesting; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; import org.sonar.api.batch.Decorator; import org.sonar.api.batch.DecoratorBarriers; import org.sonar.api.batch.DecoratorContext; @@ -47,14 +53,6 @@ import org.sonar.api.rules.RuleFinder; import org.sonar.api.technicaldebt.batch.Characteristic; import org.sonar.api.technicaldebt.batch.TechnicalDebtModel; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Set; - import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.Maps.newHashMap; @@ -182,7 +180,7 @@ public final class DebtDecorator implements Decorator { } } - private void saveMeasure(DecoratorContext context, Measure measure, Double value, boolean inMemory) { + private static void saveMeasure(DecoratorContext context, Measure measure, Double value, boolean inMemory) { measure.setValue(value); if (inMemory) { measure.setPersistenceMode(PersistenceMode.MEMORY); diff --git a/sonar-batch/src/main/java/org/sonar/batch/debt/DebtModelProvider.java b/sonar-batch/src/main/java/org/sonar/batch/debt/DebtModelProvider.java index 7ce8c610ba5..dc95f8e8679 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/debt/DebtModelProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/debt/DebtModelProvider.java @@ -22,6 +22,8 @@ package org.sonar.batch.debt; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; +import java.util.List; +import javax.annotation.Nullable; import org.picocontainer.injectors.ProviderAdapter; import org.sonar.api.batch.debt.DebtCharacteristic; import org.sonar.api.batch.debt.DebtModel; @@ -32,9 +34,6 @@ import org.sonar.api.utils.log.Profiler; import org.sonar.core.technicaldebt.db.CharacteristicDao; import org.sonar.core.technicaldebt.db.CharacteristicDto; -import javax.annotation.Nullable; -import java.util.List; - public class DebtModelProvider extends ProviderAdapter { private DebtModel model; @@ -48,7 +47,7 @@ public class DebtModelProvider extends ProviderAdapter { return model; } - private DebtModel load(CharacteristicDao dao) { + private static DebtModel load(CharacteristicDao dao) { DefaultDebtModel debtModel = new DefaultDebtModel(); List<CharacteristicDto> allCharacteristics = dao.selectEnabledCharacteristics(); diff --git a/sonar-batch/src/main/java/org/sonar/batch/debt/IssueChangelogDebtCalculator.java b/sonar-batch/src/main/java/org/sonar/batch/debt/IssueChangelogDebtCalculator.java index 9d6e0fca14c..fb882a7a0eb 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/debt/IssueChangelogDebtCalculator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/debt/IssueChangelogDebtCalculator.java @@ -22,16 +22,6 @@ package org.sonar.batch.debt; import com.google.common.base.Function; import com.google.common.collect.Ordering; -import org.apache.commons.lang.time.DateUtils; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.issue.Issue; -import org.sonar.api.issue.internal.DefaultIssue; -import org.sonar.api.issue.internal.FieldDiffs; -import org.sonar.core.issue.IssueUpdater; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - import java.util.Calendar; import java.util.Collection; import java.util.Collections; @@ -39,6 +29,14 @@ import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.Map; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; +import org.apache.commons.lang.time.DateUtils; +import org.sonar.api.batch.BatchSide; +import org.sonar.api.issue.Issue; +import org.sonar.api.issue.internal.DefaultIssue; +import org.sonar.api.issue.internal.FieldDiffs; +import org.sonar.core.issue.IssueUpdater; import static com.google.common.collect.Lists.newArrayList; @@ -82,7 +80,7 @@ public class IssueChangelogDebtCalculator { * SONAR-5059 */ @CheckForNull - private Long subtractNeverNegative(@Nullable Long value, Long with) { + private static Long subtractNeverNegative(@Nullable Long value, @Nullable Long with) { Long result = (value != null ? value : 0) - (with != null ? with : 0); return result > 0 ? result : null; } @@ -103,7 +101,7 @@ public class IssueChangelogDebtCalculator { return Collections.emptyList(); } - private List<FieldDiffs> changesOnField(Collection<FieldDiffs> fieldDiffs) { + private static List<FieldDiffs> changesOnField(Collection<FieldDiffs> fieldDiffs) { List<FieldDiffs> diffs = newArrayList(); for (FieldDiffs fieldDiff : fieldDiffs) { if (fieldDiff.diffs().containsKey(IssueUpdater.TECHNICAL_DEBT)) { @@ -114,7 +112,7 @@ public class IssueChangelogDebtCalculator { } @CheckForNull - private Long newValue(FieldDiffs fieldDiffs) { + private static Long newValue(FieldDiffs fieldDiffs) { for (Map.Entry<String, FieldDiffs.Diff> entry : fieldDiffs.diffs().entrySet()) { if (entry.getKey().equals(IssueUpdater.TECHNICAL_DEBT)) { return entry.getValue().newValueLong(); @@ -124,7 +122,7 @@ public class IssueChangelogDebtCalculator { } @CheckForNull - private Long oldValue(FieldDiffs fieldDiffs) { + private static Long oldValue(FieldDiffs fieldDiffs) { for (Map.Entry<String, FieldDiffs.Diff> entry : fieldDiffs.diffs().entrySet()) { if (entry.getKey().equals(IssueUpdater.TECHNICAL_DEBT)) { return entry.getValue().oldValueLong(); @@ -133,11 +131,11 @@ public class IssueChangelogDebtCalculator { return null; } - private boolean isAfter(@Nullable Date currentDate, @Nullable Date pastDate) { + private static boolean isAfter(@Nullable Date currentDate, @Nullable Date pastDate) { return pastDate == null || (currentDate != null && DateUtils.truncatedCompareTo(currentDate, pastDate, Calendar.SECOND) > 0); } - private boolean isLesserOrEqual(@Nullable Date currentDate, @Nullable Date pastDate) { + private static boolean isLesserOrEqual(@Nullable Date currentDate, @Nullable Date pastDate) { return (currentDate != null) && (pastDate == null || (DateUtils.truncatedCompareTo(currentDate, pastDate, Calendar.SECOND) <= 0)); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/debt/NewDebtDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/debt/NewDebtDecorator.java index 9909fc47476..c334520aa79 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/debt/NewDebtDecorator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/debt/NewDebtDecorator.java @@ -21,6 +21,10 @@ package org.sonar.batch.debt; import com.google.common.collect.ImmutableList; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import javax.annotation.Nullable; import org.sonar.api.batch.Decorator; import org.sonar.api.batch.DecoratorBarriers; import org.sonar.api.batch.DecoratorContext; @@ -39,12 +43,6 @@ import org.sonar.api.resources.Resource; import org.sonar.batch.components.Period; import org.sonar.batch.components.TimeMachineConfiguration; -import javax.annotation.Nullable; - -import java.util.Collection; -import java.util.Date; -import java.util.List; - import static com.google.common.collect.Lists.newArrayList; /** @@ -109,7 +107,7 @@ public final class NewDebtDecorator implements Decorator { return result; } - private boolean shouldSaveNewMetrics(DecoratorContext context) { + private static boolean shouldSaveNewMetrics(DecoratorContext context) { return context.getMeasure(CoreMetrics.NEW_TECHNICAL_DEBT) == null; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/debt/SqaleRatingDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/debt/SqaleRatingDecorator.java index 666ec9b633f..38dc3bd658d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/debt/SqaleRatingDecorator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/debt/SqaleRatingDecorator.java @@ -22,6 +22,10 @@ package org.sonar.batch.debt; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Lists; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import javax.annotation.Nullable; import org.sonar.api.batch.Decorator; import org.sonar.api.batch.DecoratorContext; import org.sonar.api.batch.DependedUpon; @@ -35,12 +39,6 @@ import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; import org.sonar.api.resources.ResourceUtils; -import javax.annotation.Nullable; - -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - /** * Decorator that computes Sqale Rating metric */ @@ -95,7 +93,7 @@ public class SqaleRatingDecorator implements Decorator { } } - private Measure createRatingMeasure(int rating) { + private static Measure createRatingMeasure(int rating) { return new Measure(CoreMetrics.SQALE_RATING).setIntValue(rating).setData(toRatingLetter(rating)); } @@ -132,7 +130,7 @@ public class SqaleRatingDecorator implements Decorator { return sum; } - private long getMeasureValue(DecoratorContext context, Metric metric) { + private static long getMeasureValue(DecoratorContext context, Metric metric) { Measure measure = context.getMeasure(metric); if (measure != null) { return measure.getValue().longValue(); diff --git a/sonar-batch/src/main/java/org/sonar/batch/debt/SqaleRatingSettings.java b/sonar-batch/src/main/java/org/sonar/batch/debt/SqaleRatingSettings.java index bb186b177fc..ca80f62a96b 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/debt/SqaleRatingSettings.java +++ b/sonar-batch/src/main/java/org/sonar/batch/debt/SqaleRatingSettings.java @@ -20,13 +20,12 @@ package org.sonar.batch.debt; -import org.sonar.api.batch.BatchSide; +import javax.annotation.Nullable; import org.sonar.api.CoreProperties; +import org.sonar.api.batch.BatchSide; import org.sonar.api.config.Settings; import org.sonar.api.measures.Metric; -import javax.annotation.Nullable; - @BatchSide public class SqaleRatingSettings { @@ -76,7 +75,7 @@ public class SqaleRatingSettings { return getMetricForKey(settings.getString(CoreProperties.SIZE_METRIC), metrics); } - private Metric getMetricForKey(String sizeMetricKey, Metric[] metrics) { + private static Metric getMetricForKey(String sizeMetricKey, Metric[] metrics) { for (Metric metric : metrics) { if (metric.getKey().equals(sizeMetricKey)) { return metric; 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 f17b42c18db..2586d4f898a 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 @@ -21,6 +21,7 @@ package org.sonar.batch.issue; import com.google.common.base.Objects; import com.google.common.base.Strings; +import javax.annotation.Nullable; import org.sonar.api.batch.debt.DebtRemediationFunction; import org.sonar.api.batch.rule.ActiveRule; import org.sonar.api.batch.rule.ActiveRules; @@ -35,8 +36,6 @@ import org.sonar.api.utils.Duration; import org.sonar.api.utils.MessageException; import org.sonar.core.issue.DefaultIssueBuilder; -import javax.annotation.Nullable; - /** * Initialize the issues raised during scan. */ @@ -98,7 +97,7 @@ public class ModuleIssues { return false; } - private void validateRule(DefaultIssue issue, Rule rule) { + private static void validateRule(DefaultIssue issue, @Nullable Rule rule) { RuleKey ruleKey = issue.ruleKey(); if (rule == null) { throw MessageException.of(String.format("The rule '%s' does not exist.", ruleKey)); 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 index c886d93bf51..9a8af6d87ef 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java @@ -22,6 +22,8 @@ package org.sonar.batch.rule; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ListMultimap; +import java.util.List; +import javax.annotation.Nullable; import org.picocontainer.injectors.ProviderAdapter; import org.sonar.api.batch.debt.DebtCharacteristic; import org.sonar.api.batch.debt.DebtModel; @@ -38,9 +40,6 @@ import org.sonar.core.rule.RuleDao; import org.sonar.core.rule.RuleDto; import org.sonar.core.rule.RuleParamDto; -import javax.annotation.Nullable; -import java.util.List; - /** * Loads all enabled and non manual rules */ @@ -88,7 +87,7 @@ public class RulesProvider extends ProviderAdapter { return rulesBuilder.build(); } - private DebtCharacteristic effectiveCharacteristic(RuleDto ruleDto, RuleKey ruleKey, DefaultDebtModel debtModel) { + private static DebtCharacteristic effectiveCharacteristic(RuleDto ruleDto, RuleKey ruleKey, DefaultDebtModel debtModel) { Integer subCharacteristicId = ruleDto.getSubCharacteristicId(); Integer defaultSubCharacteristicId = ruleDto.getDefaultSubCharacteristicId(); Integer effectiveSubCharacteristicId = subCharacteristicId != null ? subCharacteristicId : defaultSubCharacteristicId; @@ -121,7 +120,7 @@ public class RulesProvider extends ProviderAdapter { * Return true is the characteristic has not been overridden and a default characteristic is existing or * if the characteristic has been overridden but is not disabled */ - private boolean hasCharacteristic(RuleDto ruleDto) { + private static boolean hasCharacteristic(RuleDto ruleDto) { Integer subCharacteristicId = ruleDto.getSubCharacteristicId(); return (subCharacteristicId == null && ruleDto.getDefaultSubCharacteristicId() != null) || (subCharacteristicId != null && !RuleDto.DISABLED_CHARACTERISTIC_ID.equals(subCharacteristicId)); |