aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2015-02-23 00:41:42 +0100
committerSimon Brandhof <simon.brandhof@sonarsource.com>2015-02-23 00:41:42 +0100
commite0a45822f9a18b4b1d0d22f53b2218cd60795f6f (patch)
tree69ad0eb029b46fb0a0abbc8cfed2c79ea6816294
parentc4e7fb294ca6b445db2a59336913642dd7273f2b (diff)
downloadsonarqube-e0a45822f9a18b4b1d0d22f53b2218cd60795f6f.tar.gz
sonarqube-e0a45822f9a18b4b1d0d22f53b2218cd60795f6f.zip
Fix some quality flaws
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java17
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java5
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineDoc.java10
-rw-r--r--sonar-core/src/main/resources/org/sonar/l10n/core.properties1
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/ValidationMessages.java21
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/log/ListInterceptor.java6
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/log/LogInterceptor.java6
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/ValidationMessagesTest.java12
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/log/ConsoleFormatterTest.java1
9 files changed, 58 insertions, 21 deletions
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java
index 118fe828243..e90feb4310f 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java
@@ -62,16 +62,17 @@ public class SymbolReferencesSensor implements Sensor {
List<String> lines = FileUtils.readLines(symbolFile, context.fileSystem().encoding().name());
int lineNumber = 0;
Symbolizable symbolizable = perspectives.as(Symbolizable.class, inputFile);
-
- Symbolizable.SymbolTableBuilder symbolTableBuilder = symbolizable.newSymbolTableBuilder();
- for (String line : lines) {
- lineNumber++;
- if (StringUtils.isBlank(line) || line.startsWith("#")) {
- continue;
+ if (symbolizable != null) {
+ Symbolizable.SymbolTableBuilder symbolTableBuilder = symbolizable.newSymbolTableBuilder();
+ for (String line : lines) {
+ lineNumber++;
+ if (StringUtils.isBlank(line) || line.startsWith("#")) {
+ continue;
+ }
+ processLine(symbolFile, lineNumber, symbolTableBuilder, line);
}
- processLine(symbolFile, lineNumber, symbolTableBuilder, line);
+ symbolizable.setSymbolTable(symbolTableBuilder.build());
}
- symbolizable.setSymbolTable(symbolTableBuilder.build());
} catch (IOException e) {
throw new IllegalStateException(e);
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java
index 52572d1529c..c5e4b4770a0 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java
@@ -416,9 +416,10 @@ public class SearchAction implements BaseIssuesWsAction {
json.beginObject();
json.prop("property", facetName);
json.name("values").beginArray();
- if (results.getFacets().contains(facetName)) {
+ LinkedHashMap<String, Long> buckets = results.getFacets().get(facetName);
+ if (buckets != null) {
Set<String> itemsFromFacets = Sets.newHashSet();
- for (Map.Entry<String, Long> bucket : results.getFacets().get(facetName).entrySet()) {
+ for (Map.Entry<String, Long> bucket : buckets.entrySet()) {
itemsFromFacets.add(bucket.getKey());
json.beginObject();
json.prop("val", bucket.getKey());
diff --git a/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineDoc.java b/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineDoc.java
index 45fb14630c4..fd8e475a4d1 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineDoc.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineDoc.java
@@ -74,7 +74,7 @@ public class SourceLineDoc extends BaseDoc {
return getNullableField(SourceLineIndexDefinition.FIELD_SCM_REVISION);
}
- public SourceLineDoc setScmRevision(String scmRevision) {
+ public SourceLineDoc setScmRevision(@Nullable String scmRevision) {
setField(SourceLineIndexDefinition.FIELD_SCM_REVISION, scmRevision);
return this;
}
@@ -84,7 +84,7 @@ public class SourceLineDoc extends BaseDoc {
return getNullableField(SourceLineIndexDefinition.FIELD_SCM_AUTHOR);
}
- public SourceLineDoc setScmAuthor(String scmAuthor) {
+ public SourceLineDoc setScmAuthor(@Nullable String scmAuthor) {
setField(SourceLineIndexDefinition.FIELD_SCM_AUTHOR, scmAuthor);
return this;
}
@@ -104,7 +104,7 @@ public class SourceLineDoc extends BaseDoc {
return getNullableField(SourceLineIndexDefinition.FIELD_HIGHLIGHTING);
}
- public SourceLineDoc setHighlighting(String s) {
+ public SourceLineDoc setHighlighting(@Nullable String s) {
setField(SourceLineIndexDefinition.FIELD_HIGHLIGHTING, s);
return this;
}
@@ -113,7 +113,7 @@ public class SourceLineDoc extends BaseDoc {
return getField(SourceLineIndexDefinition.FIELD_SOURCE);
}
- public SourceLineDoc setSource(String source) {
+ public SourceLineDoc setSource(@Nullable String source) {
setField(SourceLineIndexDefinition.FIELD_SOURCE, source);
return this;
}
@@ -122,7 +122,7 @@ public class SourceLineDoc extends BaseDoc {
return getFieldAsDate(BaseNormalizer.UPDATED_AT_FIELD);
}
- public SourceLineDoc setUpdateDate(Date updatedAt) {
+ public SourceLineDoc setUpdateDate(@Nullable Date updatedAt) {
setField(BaseNormalizer.UPDATED_AT_FIELD, updatedAt);
return this;
}
diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties
index b52bc563e9f..cd929d05a36 100644
--- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties
+++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties
@@ -476,7 +476,6 @@ project_roles.page.description2=Grant and revoke project-level permissions. Perm
settings.page=General Settings
settings.page.description=Edit global settings for this SonarQube instance.
system_info.page=System Info
-system_info.page.description=This page provides system statistics, including plugin versions, environmental variables, and data on SonarQube itself.
users.page=Users
users.page.description=Create and administer individual users.
user_groups.page=Groups
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/ValidationMessages.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/ValidationMessages.java
index e2455ef29e2..967bcd67dbb 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/ValidationMessages.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/ValidationMessages.java
@@ -21,7 +21,7 @@ package org.sonar.api.utils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
-import org.sonar.api.utils.log.Logger;
+import org.slf4j.Logger;
import java.util.ArrayList;
import java.util.List;
@@ -81,6 +81,25 @@ public final class ValidationMessages {
return this;
}
+ /**
+ * @since 5.1
+ */
+ public void log(org.sonar.api.utils.log.Logger logger) {
+ for (String error : getErrors()) {
+ logger.error(error);
+ }
+ for (String warning : getWarnings()) {
+ logger.warn(warning);
+ }
+ for (String info : getInfos()) {
+ logger.info(info);
+ }
+ }
+
+ /**
+ * @deprecated replaced by {@link #log(org.sonar.api.utils.log.Logger)} since deprecation of slf4j in 5.1
+ */
+ @Deprecated
public void log(Logger logger) {
for (String error : getErrors()) {
logger.error(error);
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/ListInterceptor.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/ListInterceptor.java
index 58c86d8387a..76e3c444829 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/ListInterceptor.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/ListInterceptor.java
@@ -19,6 +19,8 @@
*/
package org.sonar.api.utils.log;
+import javax.annotation.Nullable;
+
import java.util.ArrayList;
import java.util.List;
@@ -32,12 +34,12 @@ class ListInterceptor extends LogInterceptor {
}
@Override
- public void log(String msg, Object arg) {
+ public void log(String msg, @Nullable Object arg) {
logs.add(ConsoleFormatter.format(msg, arg));
}
@Override
- public void log(String msg, Object arg1, Object arg2) {
+ public void log(String msg, @Nullable Object arg1, @Nullable Object arg2) {
logs.add(ConsoleFormatter.format(msg, arg1, arg2));
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/LogInterceptor.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/LogInterceptor.java
index 49701a01df3..bccd7e9797a 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/LogInterceptor.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/LogInterceptor.java
@@ -19,13 +19,15 @@
*/
package org.sonar.api.utils.log;
+import javax.annotation.Nullable;
+
abstract class LogInterceptor {
abstract void log(String msg);
- abstract void log(String msg, Object arg);
+ abstract void log(String msg, @Nullable Object arg);
- abstract void log(String msg, Object arg1, Object arg2);
+ abstract void log(String msg, @Nullable Object arg1, @Nullable Object arg2);
abstract void log(String msg, Object... args);
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/ValidationMessagesTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/ValidationMessagesTest.java
index 7a4e3468362..6217e6d4f1b 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/ValidationMessagesTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/ValidationMessagesTest.java
@@ -40,6 +40,12 @@ public class ValidationMessagesTest {
verify(logger, never()).error(anyString());
verify(logger, never()).warn(anyString());
verify(logger, never()).info(anyString());
+
+ org.slf4j.Logger slf4j = mock(org.slf4j.Logger.class);
+ messages.log(slf4j);
+ verify(slf4j, never()).error(anyString());
+ verify(slf4j, never()).warn(anyString());
+ verify(slf4j, never()).info(anyString());
}
@Test
@@ -58,5 +64,11 @@ public class ValidationMessagesTest {
verify(logger, times(1)).error("my error");
verify(logger, never()).warn(anyString());
verify(logger, never()).info(anyString());
+
+ org.slf4j.Logger slf4j = mock(org.slf4j.Logger.class);
+ messages.log(slf4j);
+ verify(slf4j, times(1)).error("my error");
+ verify(slf4j, never()).warn(anyString());
+ verify(slf4j, never()).info(anyString());
}
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/ConsoleFormatterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/ConsoleFormatterTest.java
index 4e2280fe775..834860d7a83 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/ConsoleFormatterTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/ConsoleFormatterTest.java
@@ -32,6 +32,7 @@ public class ConsoleFormatterTest {
assertThat(ConsoleFormatter.format("arg: {}", "foo")).isEqualTo("arg: foo");
assertThat(ConsoleFormatter.format("two args: {} and {}", "foo", 42)).isEqualTo("two args: foo and 42");
assertThat(ConsoleFormatter.format("args: {}, {} and {}", true, 42, 2L)).isEqualTo("args: true, 42 and 2");
+ assertThat(ConsoleFormatter.format("args: {}, {} and {}", null, null, null)).isEqualTo("args: null, null and null");
}
@Test