From 42f17286694370e73b48db38cbc3b328ff10764c Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 7 Dec 2012 15:45:24 +0100 Subject: [PATCH] Fix quality flaws --- plugins/sonar-l10n-en-plugin/pom.xml | 15 +++++++- .../sonar/plugins/l10n/EnglishPackPlugin.java | 4 +-- .../plugins/l10n/EnglishPackPluginTest.java | 31 ++++++++++++++++ .../org/sonar/batch/index/DefaultIndex.java | 35 +++++++++++++------ .../api/measures/CoverageMeasuresBuilder.java | 32 +++++++++-------- 5 files changed, 87 insertions(+), 30 deletions(-) create mode 100644 plugins/sonar-l10n-en-plugin/src/test/java/org/sonar/plugins/l10n/EnglishPackPluginTest.java diff --git a/plugins/sonar-l10n-en-plugin/pom.xml b/plugins/sonar-l10n-en-plugin/pom.xml index 33651911c6e..43d7967b0f6 100644 --- a/plugins/sonar-l10n-en-plugin/pom.xml +++ b/plugins/sonar-l10n-en-plugin/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 @@ -20,6 +21,18 @@ sonar-plugin-api provided + + + junit + junit + test + + + org.easytesting + fest-assert + test + + diff --git a/plugins/sonar-l10n-en-plugin/src/main/java/org/sonar/plugins/l10n/EnglishPackPlugin.java b/plugins/sonar-l10n-en-plugin/src/main/java/org/sonar/plugins/l10n/EnglishPackPlugin.java index 19e8bb2262e..787788fc8ad 100644 --- a/plugins/sonar-l10n-en-plugin/src/main/java/org/sonar/plugins/l10n/EnglishPackPlugin.java +++ b/plugins/sonar-l10n-en-plugin/src/main/java/org/sonar/plugins/l10n/EnglishPackPlugin.java @@ -19,8 +19,6 @@ */ package org.sonar.plugins.l10n; -import org.sonar.api.Extension; - import org.sonar.api.SonarPlugin; import java.util.Collections; @@ -28,7 +26,7 @@ import java.util.List; public final class EnglishPackPlugin extends SonarPlugin { - public List> getExtensions() { + public List getExtensions() { return Collections.emptyList(); } } diff --git a/plugins/sonar-l10n-en-plugin/src/test/java/org/sonar/plugins/l10n/EnglishPackPluginTest.java b/plugins/sonar-l10n-en-plugin/src/test/java/org/sonar/plugins/l10n/EnglishPackPluginTest.java new file mode 100644 index 00000000000..6987233f554 --- /dev/null +++ b/plugins/sonar-l10n-en-plugin/src/test/java/org/sonar/plugins/l10n/EnglishPackPluginTest.java @@ -0,0 +1,31 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2012 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.plugins.l10n; + +import org.junit.Test; + +import static org.fest.assertions.Assertions.assertThat; + +public class EnglishPackPluginTest { + @Test + public void no_extensions() { + assertThat(new EnglishPackPlugin().getExtensions()).isEmpty(); + } +} diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java index af56d4a04dc..79e4e2db95d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java @@ -30,9 +30,17 @@ import org.sonar.api.batch.Event; import org.sonar.api.batch.SonarIndex; import org.sonar.api.database.model.ResourceModel; import org.sonar.api.design.Dependency; -import org.sonar.api.measures.*; +import org.sonar.api.measures.Measure; +import org.sonar.api.measures.MeasuresFilter; +import org.sonar.api.measures.MeasuresFilters; +import org.sonar.api.measures.Metric; +import org.sonar.api.measures.MetricFinder; import org.sonar.api.profiles.RulesProfile; -import org.sonar.api.resources.*; +import org.sonar.api.resources.Project; +import org.sonar.api.resources.ProjectLink; +import org.sonar.api.resources.Resource; +import org.sonar.api.resources.ResourceUtils; +import org.sonar.api.resources.Scopes; import org.sonar.api.rules.ActiveRule; import org.sonar.api.rules.Violation; import org.sonar.api.utils.SonarException; @@ -42,7 +50,14 @@ import org.sonar.batch.ProjectTree; import org.sonar.batch.ResourceFilters; import org.sonar.batch.ViolationFilters; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; public class DefaultIndex extends SonarIndex { @@ -448,10 +463,10 @@ public class DefaultIndex extends SonarIndex { if (!StringUtils.equals(Scopes.PROJECT, resource.getScope())) { // not a project nor a library uid = new StringBuilder(ResourceModel.KEY_SIZE) - .append(project.getKey()) - .append(':') - .append(resource.getKey()) - .toString(); + .append(project.getKey()) + .append(':') + .append(resource.getKey()) + .toString(); } return uid; } @@ -540,10 +555,8 @@ public class DefaultIndex extends SonarIndex { } private void checkLock(Resource resource) { - if (lock.isLocked() && !ResourceUtils.isLibrary(resource)) { - if (lock.isFailWhenLocked()) { - throw new SonarException("Index is locked, resource can not be indexed: " + resource); - } + if (lock.isLocked() && !ResourceUtils.isLibrary(resource) && lock.isFailWhenLocked()) { + throw new SonarException("Index is locked, resource can not be indexed: " + resource); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoverageMeasuresBuilder.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoverageMeasuresBuilder.java index e9ebaf22a6e..a1f886cd561 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoverageMeasuresBuilder.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoverageMeasuresBuilder.java @@ -23,7 +23,11 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import org.sonar.api.utils.KeyValueFormat; -import java.util.*; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.SortedMap; /** * @since 2.7 @@ -34,9 +38,9 @@ public final class CoverageMeasuresBuilder { * Metrics of generated measures */ public static final List METRICS = Arrays.asList( - CoreMetrics.LINES_TO_COVER, CoreMetrics.UNCOVERED_LINES, CoreMetrics.COVERAGE_LINE_HITS_DATA, - CoreMetrics.CONDITIONS_TO_COVER, CoreMetrics.UNCOVERED_CONDITIONS, CoreMetrics.CONDITIONS_BY_LINE, - CoreMetrics.COVERED_CONDITIONS_BY_LINE); + CoreMetrics.LINES_TO_COVER, CoreMetrics.UNCOVERED_LINES, CoreMetrics.COVERAGE_LINE_HITS_DATA, + CoreMetrics.CONDITIONS_TO_COVER, CoreMetrics.UNCOVERED_CONDITIONS, CoreMetrics.CONDITIONS_BY_LINE, + CoreMetrics.COVERED_CONDITIONS_BY_LINE); private int totalCoveredLines = 0, totalConditions = 0, totalCoveredConditions = 0; @@ -69,13 +73,11 @@ public final class CoverageMeasuresBuilder { } public CoverageMeasuresBuilder setConditions(int lineId, int conditions, int coveredConditions) { - if (!conditionsByLine.containsKey(lineId)) { - if (conditions > 0) { - totalConditions += conditions; - totalCoveredConditions += coveredConditions; - conditionsByLine.put(lineId, conditions); - coveredConditionsByLine.put(lineId, coveredConditions); - } + if (conditions > 0 && !conditionsByLine.containsKey(lineId)) { + totalConditions += conditions; + totalCoveredConditions += coveredConditions; + conditionsByLine.put(lineId, conditions); + coveredConditionsByLine.put(lineId, coveredConditions); } return this; } @@ -126,14 +128,14 @@ public final class CoverageMeasuresBuilder { private Measure createCoveredConditionsByLine() { return new Measure(CoreMetrics.COVERED_CONDITIONS_BY_LINE) - .setData(KeyValueFormat.format(coveredConditionsByLine)) - .setPersistenceMode(PersistenceMode.DATABASE); + .setData(KeyValueFormat.format(coveredConditionsByLine)) + .setPersistenceMode(PersistenceMode.DATABASE); } private Measure createConditionsByLine() { return new Measure(CoreMetrics.CONDITIONS_BY_LINE) - .setData(KeyValueFormat.format(conditionsByLine)) - .setPersistenceMode(PersistenceMode.DATABASE); + .setData(KeyValueFormat.format(conditionsByLine)) + .setPersistenceMode(PersistenceMode.DATABASE); } public static CoverageMeasuresBuilder create() { -- 2.39.5