]> source.dussan.org Git - sonarqube.git/commitdiff
Fix some quality flaws
authorJulien HENRY <julien.henry@sonarsource.com>
Fri, 20 Jun 2014 07:34:45 +0000 (09:34 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Fri, 20 Jun 2014 07:42:53 +0000 (09:42 +0200)
sonar-batch/src/main/java/org/sonar/batch/DefaultDecoratorContext.java
sonar-batch/src/main/java/org/sonar/batch/events/package-info.java [new file with mode: 0644]
sonar-batch/src/main/java/org/sonar/batch/index/ResourceKeyMigration.java
sonar-batch/src/main/java/org/sonar/batch/index/package-info.java [new file with mode: 0644]
sonar-batch/src/main/java/org/sonar/batch/language/package-info.java [new file with mode: 0644]
sonar-batch/src/main/java/org/sonar/batch/languages/package-info.java
sonar-batch/src/main/java/org/sonar/batch/package-info.java [new file with mode: 0644]
sonar-batch/src/main/java/org/sonar/batch/phases/package-info.java [new file with mode: 0644]
sonar-batch/src/main/java/org/sonar/batch/rule/QProfileDecorator.java
sonar-batch/src/main/java/org/sonar/batch/scan/maven/package-info.java [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/db/migrations/v44/MeasureDataMigration.java

index d31b204e93867257d4ec75d5828c6500a0c55e7a..4152792943126e3a4c10a33b6a84577e1f5f34a9 100644 (file)
@@ -48,7 +48,7 @@ import java.util.Set;
 public class DefaultDecoratorContext implements DecoratorContext {
 
   private static final String SAVE_MEASURE_METHOD = "saveMeasure";
-  private SonarIndex index;
+  private SonarIndex sonarIndex;
   private Resource resource;
   private MeasurementFilters measurementFilters;
   private boolean readOnly = false;
@@ -63,7 +63,7 @@ public class DefaultDecoratorContext implements DecoratorContext {
     SonarIndex index,
     List<DecoratorContext> childrenContexts,
     MeasurementFilters measurementFilters, MeasureCache measureCache, MetricFinder metricFinder) {
-    this.index = index;
+    this.sonarIndex = index;
     this.resource = resource;
     this.childrenContexts = childrenContexts;
     this.measurementFilters = measurementFilters;
@@ -88,7 +88,7 @@ public class DefaultDecoratorContext implements DecoratorContext {
   }
 
   public Project getProject() {
-    return index.getProject();
+    return sonarIndex.getProject();
   }
 
   public List<DecoratorContext> getChildren() {
@@ -181,50 +181,50 @@ public class DefaultDecoratorContext implements DecoratorContext {
   * {@inheritDoc}
   */
   public List<Violation> getViolations(ViolationQuery violationQuery) {
-    return index.getViolations(violationQuery);
+    return sonarIndex.getViolations(violationQuery);
   }
 
   /**
   * {@inheritDoc}
   */
   public List<Violation> getViolations() {
-    return index.getViolations(resource);
+    return sonarIndex.getViolations(resource);
   }
 
   public Dependency saveDependency(Dependency dependency) {
     checkReadOnly("addDependency");
-    return index.addDependency(dependency);
+    return sonarIndex.addDependency(dependency);
   }
 
   public Set<Dependency> getDependencies() {
-    return index.getDependencies();
+    return sonarIndex.getDependencies();
   }
 
   public Collection<Dependency> getIncomingDependencies() {
-    return index.getIncomingEdges(resource);
+    return sonarIndex.getIncomingEdges(resource);
   }
 
   public Collection<Dependency> getOutgoingDependencies() {
-    return index.getOutgoingEdges(resource);
+    return sonarIndex.getOutgoingEdges(resource);
   }
 
   public List<Event> getEvents() {
-    return index.getEvents(resource);
+    return sonarIndex.getEvents(resource);
   }
 
   public Event createEvent(String name, String description, String category, Date date) {
-    return index.addEvent(resource, name, description, category, date);
+    return sonarIndex.addEvent(resource, name, description, category, date);
   }
 
   public void deleteEvent(Event event) {
-    index.deleteEvent(event);
+    sonarIndex.deleteEvent(event);
   }
 
   public DefaultDecoratorContext saveViolation(Violation violation, boolean force) {
     if (violation.getResource() == null) {
       violation.setResource(resource);
     }
-    index.addViolation(violation, force);
+    sonarIndex.addViolation(violation, force);
     return this;
   }
 
diff --git a/sonar-batch/src/main/java/org/sonar/batch/events/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/events/package-info.java
new file mode 100644 (file)
index 0000000..a82eac1
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.batch.events;
+
+import javax.annotation.ParametersAreNonnullByDefault;
index 6e61e07d723b34d061fe84ae7961017fab2b7248..4276fddf6c2c345806da35c3f3eea62acf46e8f6 100644 (file)
@@ -183,11 +183,10 @@ public class ResourceKeyMigration implements BatchComponent {
   }
 
   private List<ResourceModel> loadEnabledResources(int moduleId, StringBuilder hql) {
-    List<ResourceModel> resources = session.createQuery(hql.toString())
+    return session.createQuery(hql.toString())
       .setParameter("rootId", moduleId)
       .setParameter("enabled", true)
       .getResultList();
-    return resources;
   }
 
   private Map<String, ResourceModel> loadDisabledResources(int moduleId, StringBuilder hql) {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/index/package-info.java
new file mode 100644 (file)
index 0000000..93a9239
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.batch.index;
+
+import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/language/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/language/package-info.java
new file mode 100644 (file)
index 0000000..78142a0
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.batch.language;
+
+import javax.annotation.ParametersAreNonnullByDefault;
index 5ce5bc10019df27458b6af68edb273c7a33be071..ef8790b337f1425ffcac77b18930020b2635aced 100644 (file)
@@ -17,4 +17,5 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
+@javax.annotation.ParametersAreNonnullByDefault
 package org.sonar.batch.languages;
\ No newline at end of file
diff --git a/sonar-batch/src/main/java/org/sonar/batch/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/package-info.java
new file mode 100644 (file)
index 0000000..5d2f07b
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.batch;
+
+import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/phases/package-info.java
new file mode 100644 (file)
index 0000000..a396408
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.batch.phases;
+
+import javax.annotation.ParametersAreNonnullByDefault;
index fce17de24731656a85493f64049ac2aabfa386a4..9c255f2a13eddcef4224069178dfa46d69690345 100644 (file)
@@ -40,7 +40,7 @@ public class QProfileDecorator implements Decorator {
   }
 
   public boolean shouldExecuteOnProject(Project project) {
-    return project.getModules().size() > 0;
+    return !project.getModules().isEmpty();
   }
 
   @Override
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/maven/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/scan/maven/package-info.java
new file mode 100644 (file)
index 0000000..e844336
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.batch.scan.maven;
+
+import javax.annotation.ParametersAreNonnullByDefault;
index 10bae82c4f664a45675b23db788035fafc0aaedd..fedeb01bd79d06778990b614a63b703510c0fd92 100644 (file)
@@ -85,14 +85,8 @@ public class MeasureDataMigration implements DatabaseMigration {
 
         @Override
         public boolean update(Connection connection) throws SQLException {
-          if (ids.size() > 0) {
-            String deleteSql = new StringBuilder().append("DELETE FROM measure_data WHERE id IN (")
-              .append(StringUtils.repeat("?", ",", ids.size())).append(")").toString();
-            PreparedStatement s = connection.prepareStatement(deleteSql);
-            int i = 1;
-            for (Long id : ids) {
-              s.setLong(i++, id);
-            }
+          if (!ids.isEmpty()) {
+            PreparedStatement s = prepareDeleteQuery(ids, connection);
             s.executeUpdate();
             s.close();
             ids.clear();
@@ -100,9 +94,21 @@ public class MeasureDataMigration implements DatabaseMigration {
           }
           return false;
         }
+      });
+  }
 
-      }
-      );
+  private PreparedStatement prepareDeleteQuery(final List<Long> ids, Connection connection) throws SQLException {
+    String deleteSql = new StringBuilder()
+      .append("DELETE FROM measure_data WHERE id IN (")
+      .append(StringUtils.repeat("?", ",", ids.size()))
+      .append(")").toString();
+    PreparedStatement s = connection.prepareStatement(deleteSql);
+    int i = 1;
+    for (Long id : ids) {
+      s.setLong(i, id);
+      i++;
+    }
+    return s;
   }
 
   private static class Row {