]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 23 Jan 2015 18:10:08 +0000 (19:10 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 23 Jan 2015 18:10:08 +0000 (19:10 +0100)
server/sonar-process/src/main/java/org/sonar/process/Base64Cipher.java
server/sonar-server/src/main/java/org/sonar/server/computation/ComputationComponents.java
server/sonar-server/src/main/java/org/sonar/server/computation/issue/IssueComputation.java
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/RemoveSortFieldFromIssueFiltersMigration.java
server/sonar-server/src/main/java/org/sonar/server/platform/BackendCleanup.java
server/sonar-server/src/main/java/org/sonar/server/platform/SwitchLogbackAppender.java
server/sonar-server/src/test/java/org/sonar/server/computation/ComputationComponentsTest.java
sonar-application/src/test/java/org/sonar/application/PropsBuilderTest.java
sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java
sonar-plugin-api/src/main/java/org/sonar/api/config/Base64Cipher.java

index fb9503963525595475a062ce99f320cd1951cc10..ca9044850e91b0e49b182a55afb95caa77a821df 100644 (file)
@@ -26,7 +26,7 @@ import org.apache.commons.io.Charsets;
 final class Base64Cipher implements Cipher {
   @Override
   public String encrypt(String clearText) {
-    return Base64.encodeBase64String(clearText.getBytes());
+    return Base64.encodeBase64String(clearText.getBytes(Charsets.UTF_8));
   }
 
   @Override
index 46c1e3c82f3f7f1e97623242b5a9097a08400193..1225b7b0d9ba893141cea13988193fc85baead2e 100644 (file)
@@ -34,6 +34,10 @@ import java.util.List;
 
 public class ComputationComponents {
 
+  private ComputationComponents() {
+    // only static stuff
+  }
+
   /**
    * List of all objects to be injected in the picocontainer dedicated to computation stack. 
    * Does not contain the steps declared in {@link org.sonar.server.computation.step.ComputationSteps#orderedStepClasses()}.
index 27ed5fc60786909597cfb24475c39c449a528dce..420e0fe8a8f361733427d3355c16d5ac86bf2061 100644 (file)
@@ -60,8 +60,9 @@ public class IssueComputation {
   private void guessAuthor(DefaultIssue issue) {
     // issue.authorLogin() can be not-null when old developer cockpit plugin (or other plugin)
     // is still installed and executed during analysis
-    if (issue.authorLogin() == null && issue.line() != null) {
-      issue.setAuthorLogin(linesCache.lineAuthor(issue.line()));
+    Integer line = issue.line();
+    if (issue.authorLogin() == null && line != null) {
+      issue.setAuthorLogin(linesCache.lineAuthor(line));
     }
   }
 
index 46c05eca0e3b05e0f0d76930c79ea332f345c284..64d6dc0f4e9f594f78c83c31811a944f4472a33e 100644 (file)
@@ -49,34 +49,41 @@ public class RemoveSortFieldFromIssueFiltersMigration extends BaseDataChange {
 
   @Override
   public void execute(Context context) throws SQLException {
-    final Date now = new Date(system.now());
     MassUpdate massUpdate = context.prepareMassUpdate();
     massUpdate.select("select id,data from issue_filters where data like '%" + SORT_KEY + "%' or data like '%" + ASC_KEY +"%'");
     massUpdate.update("update issue_filters set data=?, updated_at=? where id=?");
     massUpdate.rowPluralName("issue filters");
-    massUpdate.execute(new MassUpdate.Handler() {
-      @Override
-      public boolean handle(Select.Row row, SqlStatement update) throws SQLException {
-        String data = row.getString(2);
-        String[] fields = StringUtils.split(data, FIELD_SEPARATOR);
+    massUpdate.execute(new FilterHandler(new Date(system.now())));
+  }
 
-        boolean found = false;
-        List<String> fieldsToKeep = Lists.newArrayList();
-        for (String field : fields) {
-          if (field.startsWith(SORT_KEY) || field.startsWith(ASC_KEY)) {
-            found = true;
-          } else {
-            fieldsToKeep.add(field);
-          }
-        }
-        if (found) {
-          // data without 'sort' field
-          update.setString(1, StringUtils.join(fieldsToKeep, FIELD_SEPARATOR));
-          update.setDate(2, now);
-          update.setLong(3, row.getLong(1));
+  private static class FilterHandler implements MassUpdate.Handler {
+    private final Date now;
+
+    private FilterHandler(Date now) {
+      this.now = now;
+    }
+
+    @Override
+    public boolean handle(Select.Row row, SqlStatement update) throws SQLException {
+      String data = row.getString(2);
+      String[] fields = StringUtils.split(data, FIELD_SEPARATOR);
+
+      boolean found = false;
+      List<String> fieldsToKeep = Lists.newArrayList();
+      for (String field : fields) {
+        if (field.startsWith(SORT_KEY) || field.startsWith(ASC_KEY)) {
+          found = true;
+        } else {
+          fieldsToKeep.add(field);
         }
-        return found;
       }
-    });
+      if (found) {
+        // data without 'sort' field
+        update.setString(1, StringUtils.join(fieldsToKeep, FIELD_SEPARATOR));
+        update.setDate(2, now);
+        update.setLong(3, row.getLong(1));
+      }
+      return found;
+    }
   }
 }
index ade65f30ba8bc77ba936b635f7d663de37b54478..310da3a462bf00a44e087d74c72f4c6a1124104b 100644 (file)
@@ -29,7 +29,6 @@ import org.sonar.core.persistence.MyBatis;
 import org.sonar.server.issue.index.IssueIndexDefinition;
 import org.sonar.server.search.IndexDefinition;
 import org.sonar.server.search.SearchClient;
-import org.sonar.server.source.index.SourceLineIndex;
 import org.sonar.server.source.index.SourceLineIndexDefinition;
 
 import java.sql.Connection;
index ed2d87f3ad88bbd49d18e2050adef002bddbf8ea..fbc46101522d0e3d7284259cd4b4185d2e139ea4 100644 (file)
@@ -31,9 +31,9 @@ import java.util.Iterator;
 
 public class SwitchLogbackAppender extends AppenderBase<ILoggingEvent> implements AppenderAttachable<ILoggingEvent> {
 
-  private transient AppenderAttachableImpl<ILoggingEvent> attachedAppenders = new AppenderAttachableImpl<ILoggingEvent>();
-  private transient Appender<ILoggingEvent> console = null;
-  private transient Appender<ILoggingEvent> analysisReports = null;
+  private AppenderAttachableImpl<ILoggingEvent> attachedAppenders = new AppenderAttachableImpl<>();
+  private Appender<ILoggingEvent> console = null;
+  private Appender<ILoggingEvent> analysisReports = null;
 
   @Override
   protected void append(ILoggingEvent event) {
index 87fff7340f54a21784d0bbbb988c861baef87dc8..ae7590ce6fe9fe4c6cabe5468399534f07224ce6 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.server.computation;
 
 import org.junit.Test;
+import org.sonar.test.TestUtils;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
@@ -29,4 +30,9 @@ public class ComputationComponentsTest {
   public void nonStepComponents() throws Exception {
     assertThat(ComputationComponents.nonStepComponents()).isNotEmpty();
   }
+
+  @Test
+  public void util_class() throws Exception {
+    assertThat(TestUtils.hasOnlyPrivateConstructors(ComputationComponents.class)).isTrue();
+  }
 }
index c54f8f4d2dcc0222171dc602cce75e4d8b490492..91f5d6f15d15d39c379813521e5943b1fec72044 100644 (file)
@@ -92,7 +92,6 @@ public class PropsBuilderTest {
     // <home>/data is missing
     FileUtils.forceMkdir(webDir);
     FileUtils.forceMkdir(logsDir);
-
     try {
       FileUtils.touch(dataDir);
       new PropsBuilder(new Properties(), jdbcSettings, homeDir).build();
@@ -118,6 +117,19 @@ public class PropsBuilderTest {
     assertThat(props.value("sonar.origin")).isEqualTo("raw");
   }
 
+  @Test
+  public void do_not_load_properties_file_if_not_exists() throws Exception {
+    FileUtils.forceMkdir(dataDir);
+    FileUtils.forceMkdir(webDir);
+    FileUtils.forceMkdir(logsDir);
+
+    Properties rawProperties = new Properties();
+    rawProperties.setProperty("sonar.origin", "raw");
+    Props props = new PropsBuilder(rawProperties, jdbcSettings, homeDir).build();
+
+    assertThat(props.value("sonar.origin")).isEqualTo("raw");
+  }
+
   @Test
   public void detectHomeDir() throws Exception {
     assertThat(PropsBuilder.detectHomeDir()).isDirectory().exists();
index c7a3fa9de4df2fb94f99425a450b483bcee5495d..be3805f5661a90010e6197333d1d3e9310eabbf4 100644 (file)
@@ -69,7 +69,7 @@ public final class RuleDto extends Dto<RuleKey> {
   private String tags;
   private String systemTags;
 
-  private transient RuleKey key;
+  private RuleKey key;
 
   @Override
   public RuleKey getKey() {
index f30467217b783de1f98870ec1edc1c9e7dcbc9ed..26f9212dc8c4f3c60c498917f2441e1c8eb7fe23 100644 (file)
@@ -25,7 +25,7 @@ import org.apache.commons.codec.binary.Base64;
 final class Base64Cipher extends Cipher {
   @Override
   String encrypt(String clearText) {
-    return Base64.encodeBase64String(clearText.getBytes());
+    return Base64.encodeBase64String(clearText.getBytes(Charsets.UTF_8));
   }
 
   @Override