summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-12-09 22:02:28 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2013-12-09 22:02:28 +0100
commitf0cbff8e9697dd5cb4999eee5e6f92871eacdfe2 (patch)
tree300024d21d9653b784d0eca86d9b818631f3612e
parent9b8d4d064f0c719ae1a96fc2140912a90b367706 (diff)
downloadsonarqube-f0cbff8e9697dd5cb4999eee5e6f92871eacdfe2.tar.gz
sonarqube-f0cbff8e9697dd5cb4999eee5e6f92871eacdfe2.zip
Fix some quality flaws
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/web/package-info.java23
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/report/JsonReport.java2
-rw-r--r--sonar-core/src/main/java/org/sonar/core/i18n/RuleI18nManager.java14
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/IssueNotifications.java17
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/workflow/IssueWorkflow.java48
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/IssueNotificationsTest.java5
-rw-r--r--sonar-home/src/main/java/org/sonar/home/cache/FileCache.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/issue/batch/IssueFilter.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/issue/batch/IssueFilterChain.java3
-rw-r--r--sonar-server/src/main/java/org/sonar/server/notifications/NotificationCenter.java5
-rw-r--r--sonar-server/src/main/java/org/sonar/server/ui/DatabaseSessionFilter.java4
-rw-r--r--sonar-server/src/main/java/org/sonar/server/user/UserSession.java1
-rw-r--r--sonar-server/src/main/java/org/sonar/server/user/UserSessionFilter.java2
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient4Connector.java7
14 files changed, 82 insertions, 55 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/web/package-info.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/web/package-info.java
new file mode 100644
index 00000000000..f24f4d329a4
--- /dev/null
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/web/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.plugins.core.web;
+
+import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/JsonReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/JsonReport.java
index 2d924d02043..c6f9bf8530a 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/JsonReport.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/JsonReport.java
@@ -216,7 +216,7 @@ public class JsonReport implements BatchComponent {
}
private String getRuleName(RuleKey ruleKey) {
- return ruleI18nManager.getName(ruleKey.repository(), ruleKey.rule(), Locale.getDefault());
+ return ruleI18nManager.getName(ruleKey.repository(), ruleKey.rule());
}
@VisibleForTesting
diff --git a/sonar-core/src/main/java/org/sonar/core/i18n/RuleI18nManager.java b/sonar-core/src/main/java/org/sonar/core/i18n/RuleI18nManager.java
index 5c0a63317a1..4bf4f2c7301 100644
--- a/sonar-core/src/main/java/org/sonar/core/i18n/RuleI18nManager.java
+++ b/sonar-core/src/main/java/org/sonar/core/i18n/RuleI18nManager.java
@@ -57,27 +57,39 @@ public class RuleI18nManager implements RuleI18n, ServerExtension, BatchExtensio
@Override
public void stop() {
-
+ // nothing to do
}
+ /**
+ * @deprecated in 4.1. Rules are not localized anymore. See http://jira.codehaus.org/browse/SONAR-4885
+ */
@Override
@Deprecated
public String getName(String repositoryKey, String ruleKey, Locale locale) {
return getName(repositoryKey, ruleKey);
}
+ /**
+ * @deprecated in 4.1. Rules are not localized anymore. See http://jira.codehaus.org/browse/SONAR-4885
+ */
@Override
@Deprecated
public String getName(Rule rule, Locale locale) {
return getName(rule);
}
+ /**
+ * @deprecated in 4.1. Rules are not localized anymore. See http://jira.codehaus.org/browse/SONAR-4885
+ */
@Override
@Deprecated
public String getDescription(String repositoryKey, String ruleKey, Locale locale) {
return getDescription(repositoryKey, ruleKey);
}
+ /**
+ * @deprecated in 4.1. Rules are not localized anymore. See http://jira.codehaus.org/browse/SONAR-4885
+ */
@Override
@Deprecated
public String getParamDescription(String repositoryKey, String ruleKey, String paramKey, Locale locale) {
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/IssueNotifications.java b/sonar-core/src/main/java/org/sonar/core/issue/IssueNotifications.java
index 4203c1dcb95..9af55101a5a 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/IssueNotifications.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/IssueNotifications.java
@@ -34,14 +34,11 @@ import org.sonar.api.resources.Project;
import org.sonar.api.rule.Severity;
import org.sonar.api.rules.Rule;
import org.sonar.api.utils.DateUtils;
-import org.sonar.core.i18n.RuleI18nManager;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-
import java.io.Serializable;
import java.util.List;
-import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
@@ -53,11 +50,9 @@ import java.util.Map.Entry;
public class IssueNotifications implements BatchComponent, ServerComponent {
private final NotificationManager notificationsManager;
- private final RuleI18nManager ruleI18n;
- public IssueNotifications(NotificationManager notificationsManager, RuleI18nManager ruleI18n) {
+ public IssueNotifications(NotificationManager notificationsManager) {
this.notificationsManager = notificationsManager;
- this.ruleI18n = ruleI18n;
}
public Notification sendNewIssues(Project project, IssuesBySeverity newIssues) {
@@ -66,7 +61,7 @@ public class IssueNotifications implements BatchComponent, ServerComponent {
.setFieldValue("projectDate", DateUtils.formatDateTime(project.getAnalysisDate()))
.setFieldValue("count", String.valueOf(newIssues.size()));
for (String severity : Severity.ALL) {
- notification.setFieldValue("count-"+ severity, String.valueOf(newIssues.issues(severity)));
+ notification.setFieldValue("count-" + severity, String.valueOf(newIssues.issues(severity)));
}
notificationsManager.scheduleForSending(notification);
return notification;
@@ -103,7 +98,7 @@ public class IssueNotifications implements BatchComponent, ServerComponent {
@CheckForNull
private Notification createChangeNotification(DefaultIssue issue, IssueChangeContext context, Rule rule, Component project,
- @Nullable Component component, @Nullable String comment) {
+ @Nullable Component component, @Nullable String comment) {
Notification notification = null;
if (comment != null || issue.mustSendNotifications()) {
FieldDiffs currentChange = issue.currentChange();
@@ -141,11 +136,7 @@ public class IssueNotifications implements BatchComponent, ServerComponent {
if (rule == null) {
return null;
}
- String name = ruleI18n.getName(rule.getRepositoryKey(), rule.getKey(), Locale.ENGLISH);
- if (name == null) {
- name = rule.getName();
- }
- return name;
+ return rule.getName();
}
private Notification newNotification(Component project, String key) {
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/workflow/IssueWorkflow.java b/sonar-core/src/main/java/org/sonar/core/issue/workflow/IssueWorkflow.java
index 39105951297..5cec83e94b7 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/workflow/IssueWorkflow.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/workflow/IssueWorkflow.java
@@ -45,15 +45,20 @@ public class IssueWorkflow implements BatchComponent, ServerComponent, Startable
@Override
public void start() {
- machine = StateMachine.builder()
-
+ StateMachine.Builder builder = StateMachine.builder()
// order is important for UI
- .states(Issue.STATUS_OPEN, Issue.STATUS_CONFIRMED, Issue.STATUS_REOPENED, Issue.STATUS_RESOLVED, Issue.STATUS_CLOSED)
+ .states(Issue.STATUS_OPEN, Issue.STATUS_CONFIRMED, Issue.STATUS_REOPENED, Issue.STATUS_RESOLVED, Issue.STATUS_CLOSED);
- .transition(Transition.builder(DefaultTransitions.CONFIRM)
- .from(Issue.STATUS_OPEN).to(Issue.STATUS_CONFIRMED)
- .functions(new SetResolution(null))
- .build())
+ buildManualTransitions(builder);
+ buildAutomaticTransitions(builder);
+ machine = builder.build();
+ }
+
+ private void buildManualTransitions(StateMachine.Builder builder) {
+ builder.transition(Transition.builder(DefaultTransitions.CONFIRM)
+ .from(Issue.STATUS_OPEN).to(Issue.STATUS_CONFIRMED)
+ .functions(new SetResolution(null))
+ .build())
.transition(Transition.builder(DefaultTransitions.CONFIRM)
.from(Issue.STATUS_REOPENED).to(Issue.STATUS_CONFIRMED)
.functions(new SetResolution(null))
@@ -84,7 +89,7 @@ public class IssueWorkflow implements BatchComponent, ServerComponent, Startable
.functions(new SetResolution(null), new SetCloseDate(false))
.build())
- // resolve as false-positive
+ // resolve as false-positive
.transition(Transition.builder(DefaultTransitions.FALSE_POSITIVE)
.from(Issue.STATUS_OPEN).to(Issue.STATUS_RESOLVED)
.functions(new SetResolution(Issue.RESOLUTION_FALSE_POSITIVE), SetAssignee.UNASSIGN)
@@ -99,17 +104,17 @@ public class IssueWorkflow implements BatchComponent, ServerComponent, Startable
.from(Issue.STATUS_CONFIRMED).to(Issue.STATUS_RESOLVED)
.functions(new SetResolution(Issue.RESOLUTION_FALSE_POSITIVE), SetAssignee.UNASSIGN)
.requiredProjectPermission(UserRole.ISSUE_ADMIN)
- .build())
-
- // automatic transitions
+ .build());
+ }
- // Close the "end of life" issues (disabled/deleted rule, deleted component)
- .transition(Transition.builder("automaticclose")
- .from(Issue.STATUS_OPEN).to(Issue.STATUS_CLOSED)
- .conditions(new IsEndOfLife(true))
- .functions(new SetEndOfLifeResolution(), new SetCloseDate(true))
- .automatic()
- .build())
+ private void buildAutomaticTransitions(StateMachine.Builder builder) {
+ // Close the "end of life" issues (disabled/deleted rule, deleted component)
+ builder.transition(Transition.builder("automaticclose")
+ .from(Issue.STATUS_OPEN).to(Issue.STATUS_CLOSED)
+ .conditions(new IsEndOfLife(true))
+ .functions(new SetEndOfLifeResolution(), new SetCloseDate(true))
+ .automatic()
+ .build())
.transition(Transition.builder("automaticclose")
.from(Issue.STATUS_REOPENED).to(Issue.STATUS_CLOSED)
.conditions(new IsEndOfLife(true))
@@ -135,16 +140,15 @@ public class IssueWorkflow implements BatchComponent, ServerComponent, Startable
.automatic()
.build())
- // Reopen issues that are marked as resolved but that are still alive.
- // Manual issues are kept resolved.
+ // Reopen issues that are marked as resolved but that are still alive.
+ // Manual issues are kept resolved.
.transition(Transition.builder("automaticreopen")
.from(Issue.STATUS_RESOLVED).to(Issue.STATUS_REOPENED)
.conditions(new IsEndOfLife(false), new HasResolution(Issue.RESOLUTION_FIXED), new IsManual(false))
.functions(new SetResolution(null), new SetCloseDate(false))
.automatic()
.build()
- )
- .build();
+ );
}
@Override
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/IssueNotificationsTest.java b/sonar-core/src/test/java/org/sonar/core/issue/IssueNotificationsTest.java
index 18f6d635cda..1b817929d45 100644
--- a/sonar-core/src/test/java/org/sonar/core/issue/IssueNotificationsTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/issue/IssueNotificationsTest.java
@@ -51,14 +51,11 @@ public class IssueNotificationsTest {
@Mock
NotificationManager manager;
- @Mock
- RuleI18nManager ruleI18n;
-
IssueNotifications issueNotifications;
@Before
public void setUp() throws Exception {
- issueNotifications = new IssueNotifications(manager, ruleI18n);
+ issueNotifications = new IssueNotifications(manager);
}
@Test
diff --git a/sonar-home/src/main/java/org/sonar/home/cache/FileCache.java b/sonar-home/src/main/java/org/sonar/home/cache/FileCache.java
index bed2671dc6a..1b12814c1df 100644
--- a/sonar-home/src/main/java/org/sonar/home/cache/FileCache.java
+++ b/sonar-home/src/main/java/org/sonar/home/cache/FileCache.java
@@ -144,7 +144,7 @@ public class FileCache {
} catch (IOException e) {
// ignore except the last try
if (counter == TEMP_FILE_ATTEMPTS - 1) {
- throw new IllegalStateException();
+ throw new IllegalStateException("Fail to create temp file", e);
}
}
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/batch/IssueFilter.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/batch/IssueFilter.java
index ac20b11c6b3..c05d4cea49a 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/batch/IssueFilter.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/batch/IssueFilter.java
@@ -36,10 +36,10 @@ public interface IssueFilter extends BatchExtension {
* <li>Switching-off an issue based on its context (<code>//NOSONAR</code> comments, semantic annotations)</li>
* </ul>
* The <code>chain</code> parameter allows for fine control of the filtering logic: it is each filter's duty to either pass the issue to the next filter, by calling
- * the {@link IssueFilterChain#accept()} method, or return directly if the issue has to be accepted or not
+ * the {@link IssueFilterChain#accept(org.sonar.api.issue.Issue)} method, or return directly if the issue has to be accepted or not
* @param issue the issue being filtered
* @param chain the rest of the filters
- * @return <code>true</code> to accept the issue, <code>false</code> to reject it, {@link IssueFilterChain#accept()} to let the other filters decide.
+ * @return <code>true</code> to accept the issue, <code>false</code> to reject it, {@link IssueFilterChain#accept(org.sonar.api.issue.Issue)} to let the other filters decide.
*/
boolean accept(Issue issue, IssueFilterChain chain);
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/batch/IssueFilterChain.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/batch/IssueFilterChain.java
index b147e2761e3..bb4a81d6471 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/batch/IssueFilterChain.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/batch/IssueFilterChain.java
@@ -29,14 +29,11 @@ import org.sonar.api.issue.Issue;
* <li>Let downstream filters decide by passing the issue to the rest of the chain</li>
* </ul>
* @since 4.0
- *
*/
public interface IssueFilterChain {
/**
* Called by a filter to let downstream filters decide the fate of the issue
- * @param issue
- * @return
*/
boolean accept(Issue issue);
}
diff --git a/sonar-server/src/main/java/org/sonar/server/notifications/NotificationCenter.java b/sonar-server/src/main/java/org/sonar/server/notifications/NotificationCenter.java
index c59d73ecbf1..b6a77d1a271 100644
--- a/sonar-server/src/main/java/org/sonar/server/notifications/NotificationCenter.java
+++ b/sonar-server/src/main/java/org/sonar/server/notifications/NotificationCenter.java
@@ -27,7 +27,6 @@ import org.sonar.api.notifications.NotificationChannel;
import org.sonar.api.notifications.NotificationDispatcherMetadata;
import javax.annotation.Nullable;
-
import java.util.Arrays;
import java.util.List;
@@ -42,7 +41,7 @@ public class NotificationCenter implements ServerComponent {
private final NotificationChannel[] channels;
/**
- * Constructor for {@link NotificationCenter}
+ * Constructor for {@link NotificationCenter}
*/
public NotificationCenter(NotificationDispatcherMetadata[] metadata, NotificationChannel[] channels) {
this.dispatchersMetadata = metadata;
@@ -90,7 +89,7 @@ public class NotificationCenter implements ServerComponent {
String dispatcherKey = metadata.getDispatcherKey();
String value = metadata.getProperty(propertyKey);
if (value != null && (propertyValue == null || value.equals(propertyValue))) {
- keys.add(dispatcherKey);
+ keys.add(dispatcherKey);
}
}
return keys;
diff --git a/sonar-server/src/main/java/org/sonar/server/ui/DatabaseSessionFilter.java b/sonar-server/src/main/java/org/sonar/server/ui/DatabaseSessionFilter.java
index 4a1ff66835f..d05bbeb6d02 100644
--- a/sonar-server/src/main/java/org/sonar/server/ui/DatabaseSessionFilter.java
+++ b/sonar-server/src/main/java/org/sonar/server/ui/DatabaseSessionFilter.java
@@ -28,7 +28,7 @@ import javax.servlet.*;
public class DatabaseSessionFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
-
+ // nothing to do
}
@Override
@@ -43,6 +43,6 @@ public class DatabaseSessionFilter implements Filter {
@Override
public void destroy() {
-
+ // nothing to do
}
}
diff --git a/sonar-server/src/main/java/org/sonar/server/user/UserSession.java b/sonar-server/src/main/java/org/sonar/server/user/UserSession.java
index b28e5d65fbd..9a991ff175c 100644
--- a/sonar-server/src/main/java/org/sonar/server/user/UserSession.java
+++ b/sonar-server/src/main/java/org/sonar/server/user/UserSession.java
@@ -32,7 +32,6 @@ import org.sonar.server.platform.Platform;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
diff --git a/sonar-server/src/main/java/org/sonar/server/user/UserSessionFilter.java b/sonar-server/src/main/java/org/sonar/server/user/UserSessionFilter.java
index 80b6613a56c..d172a398913 100644
--- a/sonar-server/src/main/java/org/sonar/server/user/UserSessionFilter.java
+++ b/sonar-server/src/main/java/org/sonar/server/user/UserSessionFilter.java
@@ -28,10 +28,12 @@ import java.io.IOException;
public class UserSessionFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
+ // nothing to do
}
@Override
public void destroy() {
+ // nothing to do
}
@Override
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient4Connector.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient4Connector.java
index d82e6b80ac3..a61ec552346 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient4Connector.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/connectors/HttpClient4Connector.java
@@ -146,7 +146,7 @@ public class HttpClient4Connector extends Connector {
// Generate BASIC scheme object and stick it to the local
// execution context
BasicScheme basicAuth = new BasicScheme();
- localcontext.setAttribute("preemptive-auth", basicAuth);
+ localcontext.setAttribute(PreemptiveAuth.ATTRIBUTE, basicAuth);
// Add as the first request interceptor
client.addRequestInterceptor(new PreemptiveAuth(), 0);
@@ -200,6 +200,9 @@ public class HttpClient4Connector extends Connector {
}
static final class PreemptiveAuth implements HttpRequestInterceptor {
+
+ static final String ATTRIBUTE = "preemptive-auth";
+
public void process(
final HttpRequest request,
final HttpContext context) throws HttpException {
@@ -208,7 +211,7 @@ public class HttpClient4Connector extends Connector {
// If no auth scheme available yet, try to initialize it preemptively
if (authState.getAuthScheme() == null) {
- AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth");
+ AuthScheme authScheme = (AuthScheme) context.getAttribute(ATTRIBUTE);
CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
if (authScheme != null) {