aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2015-01-23 19:10:08 +0100
committerSimon Brandhof <simon.brandhof@sonarsource.com>2015-01-23 19:10:08 +0100
commit7d09b43edee2aee10127e9f2f6a33f027bbb975d (patch)
tree4d960885ad3f2f3f2b6db65f6da65d2085c8f172
parent51b8c91b138aab690921e647e30deabbaf61e75b (diff)
downloadsonarqube-7d09b43edee2aee10127e9f2f6a33f027bbb975d.tar.gz
sonarqube-7d09b43edee2aee10127e9f2f6a33f027bbb975d.zip
Fix quality flaws
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/Base64Cipher.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/ComputationComponents.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/issue/IssueComputation.java5
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/RemoveSortFieldFromIssueFiltersMigration.java51
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/BackendCleanup.java1
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/SwitchLogbackAppender.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/ComputationComponentsTest.java6
-rw-r--r--sonar-application/src/test/java/org/sonar/application/PropsBuilderTest.java14
-rw-r--r--sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/config/Base64Cipher.java2
10 files changed, 61 insertions, 32 deletions
diff --git a/server/sonar-process/src/main/java/org/sonar/process/Base64Cipher.java b/server/sonar-process/src/main/java/org/sonar/process/Base64Cipher.java
index fb950396352..ca9044850e9 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/Base64Cipher.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/Base64Cipher.java
@@ -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
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationComponents.java b/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationComponents.java
index 46c1e3c82f3..1225b7b0d9b 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationComponents.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationComponents.java
@@ -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()}.
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/issue/IssueComputation.java b/server/sonar-server/src/main/java/org/sonar/server/computation/issue/IssueComputation.java
index 27ed5fc6078..420e0fe8a8f 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/issue/IssueComputation.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/issue/IssueComputation.java
@@ -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));
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/RemoveSortFieldFromIssueFiltersMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/RemoveSortFieldFromIssueFiltersMigration.java
index 46c05eca0e3..64d6dc0f4e9 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/RemoveSortFieldFromIssueFiltersMigration.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/RemoveSortFieldFromIssueFiltersMigration.java
@@ -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;
+ }
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/BackendCleanup.java b/server/sonar-server/src/main/java/org/sonar/server/platform/BackendCleanup.java
index ade65f30ba8..310da3a462b 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/BackendCleanup.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/BackendCleanup.java
@@ -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;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/SwitchLogbackAppender.java b/server/sonar-server/src/main/java/org/sonar/server/platform/SwitchLogbackAppender.java
index ed2d87f3ad8..fbc46101522 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/SwitchLogbackAppender.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/SwitchLogbackAppender.java
@@ -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) {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/ComputationComponentsTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/ComputationComponentsTest.java
index 87fff7340f5..ae7590ce6fe 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/ComputationComponentsTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/ComputationComponentsTest.java
@@ -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();
+ }
}
diff --git a/sonar-application/src/test/java/org/sonar/application/PropsBuilderTest.java b/sonar-application/src/test/java/org/sonar/application/PropsBuilderTest.java
index c54f8f4d2dc..91f5d6f15d1 100644
--- a/sonar-application/src/test/java/org/sonar/application/PropsBuilderTest.java
+++ b/sonar-application/src/test/java/org/sonar/application/PropsBuilderTest.java
@@ -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();
@@ -119,6 +118,19 @@ public class PropsBuilderTest {
}
@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();
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java
index c7a3fa9de4d..be3805f5661 100644
--- a/sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java
+++ b/sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java
@@ -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() {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/Base64Cipher.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/Base64Cipher.java
index f30467217b7..26f9212dc8c 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/config/Base64Cipher.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/Base64Cipher.java
@@ -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