]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorSimon Brandhof <simon.brandhof@gmail.com>
Fri, 7 Dec 2012 14:45:24 +0000 (15:45 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Fri, 7 Dec 2012 15:02:17 +0000 (16:02 +0100)
plugins/sonar-l10n-en-plugin/pom.xml
plugins/sonar-l10n-en-plugin/src/main/java/org/sonar/plugins/l10n/EnglishPackPlugin.java
plugins/sonar-l10n-en-plugin/src/test/java/org/sonar/plugins/l10n/EnglishPackPluginTest.java [new file with mode: 0644]
sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
sonar-plugin-api/src/main/java/org/sonar/api/measures/CoverageMeasuresBuilder.java

index 33651911c6eb006bc33e44ecbce6fb8fa9f2cbab..43d7967b0f6052e0b7f11ef337dd50d34fe5211a 100644 (file)
@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
 
   <parent>
       <artifactId>sonar-plugin-api</artifactId>
       <scope>provided</scope>
     </dependency>
+
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.easytesting</groupId>
+      <artifactId>fest-assert</artifactId>
+      <scope>test</scope>
+    </dependency>
+
   </dependencies>
 
   <build>
index 19e8bb2262e27e6b9245a499b7107b53ee55b5b7..787788fc8ad139f77470ac547dbbb9b47eb1f6a1 100644 (file)
@@ -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<Class<? extends Extension>> 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 (file)
index 0000000..6987233
--- /dev/null
@@ -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();
+  }
+}
index af56d4a04dc640b3fb7ccfb79925a643f75ff06f..79e4e2db95d229853c3ba3a0ed1c6d157782bc4c 100644 (file)
@@ -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);
     }
   }
 
index e9ebaf22a6e17806f30ce1b6812405d04c26d78b..a1f886cd56165a358361f0091a2d97476f3fe75f 100644 (file)
@@ -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<Metric> 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() {