From 7f8bce0bf7dcf96495fa1a55d82a39ce2a106f66 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 31 May 2013 00:33:32 +0200 Subject: [PATCH] Fix some quality flaws --- .../core/issue/CountUnresolvedIssuesDecorator.java | 10 +++------- .../issue/notification/NewIssuesEmailTemplate.java | 8 +++----- .../notification/NewIssuesEmailTemplateTest.java | 1 - .../java/org/sonar/core/issue/ActionPlanStats.java | 4 ++-- .../main/java/org/sonar/api/issue/Issuable.java | 4 ++-- .../java/org/sonar/server/issue/IssueService.java | 14 ++++++++------ .../java/org/sonar/server/platform/Platform.java | 1 + .../main/java/org/sonar/server/ui/JRubyFacade.java | 1 + .../server/{platform => user}/NewUserNotifier.java | 2 +- .../{platform => user}/NewUserNotifierTest.java | 4 ++-- 10 files changed, 23 insertions(+), 26 deletions(-) rename sonar-server/src/main/java/org/sonar/server/{platform => user}/NewUserNotifier.java (97%) rename sonar-server/src/test/java/org/sonar/server/{platform => user}/NewUserNotifierTest.java (91%) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecorator.java index 643bb8d9041..17ca21170d6 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecorator.java @@ -20,7 +20,6 @@ package org.sonar.plugins.core.issue; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Predicate; import com.google.common.collect.*; import org.apache.commons.lang.time.DateUtils; import org.sonar.api.batch.*; @@ -38,11 +37,8 @@ import org.sonar.batch.components.PastSnapshot; import org.sonar.batch.components.TimeMachineConfiguration; import javax.annotation.Nullable; - import java.util.*; -import static com.google.common.collect.Lists.newArrayList; - /** * Computes metrics related to number of issues. * @@ -105,13 +101,13 @@ public class CountUnresolvedIssuesDecorator implements Decorator { rulesBag.add(rulefinder.findByKey(issue.ruleKey().repository(), issue.ruleKey().rule())); issuesPerSeverity.put(RulePriority.valueOf(issue.severity()), issue); - if (Issue.STATUS_OPEN.equals(issue.status())){ + if (Issue.STATUS_OPEN.equals(issue.status())) { countOpen++; } - if (Issue.STATUS_REOPENED.equals(issue.status())){ + if (Issue.STATUS_REOPENED.equals(issue.status())) { countReopened++; } - if (Issue.STATUS_CONFIRMED.equals(issue.status())){ + if (Issue.STATUS_CONFIRMED.equals(issue.status())) { countConfirmed++; } } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/NewIssuesEmailTemplate.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/NewIssuesEmailTemplate.java index 1199da9ff11..b3e883b273e 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/NewIssuesEmailTemplate.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/NewIssuesEmailTemplate.java @@ -66,11 +66,9 @@ public class NewIssuesEmailTemplate extends EmailTemplate { String projectKey = notification.getFieldValue("projectKey"); String dateString = notification.getFieldValue("projectDate"); Date date = DateUtils.parseDateTime(dateString); - String url = String.format("%s/issues/search?componentRoots=%s&createdAfter=%s", settings.getServerBaseURL(), URLEncoder.encode(projectKey), DateUtils.formatDate(date)); - sb.append("\n") - .append("See it in SonarQube: ") - .append(url) - .append("\n"); + String url = String.format("%s/issues/search?componentRoots=%s&createdAfter=%s", + settings.getServerBaseURL(), URLEncoder.encode(projectKey), DateUtils.formatDate(date)); + sb.append("\n").append("See it in SonarQube: ").append(url).append("\n"); } } diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/notification/NewIssuesEmailTemplateTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/notification/NewIssuesEmailTemplateTest.java index af3cc7e4430..238b6810901 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/notification/NewIssuesEmailTemplateTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/notification/NewIssuesEmailTemplateTest.java @@ -75,5 +75,4 @@ public class NewIssuesEmailTemplateTest { "\n" + "See it in SonarQube: http://nemo.sonarsource.org/issues/search?componentRoots=org.apache%3Astruts&createdAfter=2010-05-18\n"); } - } diff --git a/sonar-core/src/main/java/org/sonar/core/issue/ActionPlanStats.java b/sonar-core/src/main/java/org/sonar/core/issue/ActionPlanStats.java index dc42120042a..371125642c5 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/ActionPlanStats.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/ActionPlanStats.java @@ -67,10 +67,10 @@ public class ActionPlanStats extends DefaultActionPlan { } public boolean isOpen(){ - return ActionPlan.STATUS_OPEN.equals(super.status()); + return ActionPlan.STATUS_OPEN.equals(status()); } public boolean overDue(){ - return super.status() == ActionPlan.STATUS_OPEN && super.deadLine() != null && new Date().after(super.deadLine()); + return isOpen() && deadLine() != null && new Date().after(deadLine()); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issuable.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issuable.java index 7af6bef3bf8..cab1cc90818 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issuable.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issuable.java @@ -38,9 +38,9 @@ public interface Issuable extends Perspective { IssueBuilder message(@Nullable String message); - IssueBuilder severity(String severity); + IssueBuilder severity(@Nullable String severity); - IssueBuilder reporter(String reporter); + IssueBuilder reporter(@Nullable String reporter); IssueBuilder effortToFix(@Nullable Double d); diff --git a/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java b/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java index 27f0b0efbbc..adeed87cf63 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java @@ -36,8 +36,8 @@ import org.sonar.core.issue.workflow.IssueWorkflow; import org.sonar.core.issue.workflow.Transition; import org.sonar.server.user.UserSession; +import javax.annotation.CheckForNull; import javax.annotation.Nullable; - import java.util.Arrays; import java.util.Collections; import java.util.Date; @@ -108,11 +108,13 @@ public class IssueService implements ServerComponent { IssueQueryResult queryResult = loadIssue(issueKey); DefaultIssue issue = (DefaultIssue) queryResult.first(); - // TODO check that assignee exists - IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.login()); - if (issueUpdater.assign(issue, assignee, context)) { - issueStorage.save(issue); - issueNotifications.sendChanges(issue, context, queryResult); + if (issue != null) { + // TODO check that assignee exists + IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.login()); + if (issueUpdater.assign(issue, assignee, context)) { + issueStorage.save(issue); + issueNotifications.sendChanges(issue, context, queryResult); + } } return issue; } diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java index fcf02b695f8..aeba75ab896 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java @@ -84,6 +84,7 @@ import org.sonar.server.text.MacroInterpreter; import org.sonar.server.text.RubyTextService; import org.sonar.server.ui.*; import org.sonar.server.user.DefaultRubyUserService; +import org.sonar.server.user.NewUserNotifier; import javax.servlet.ServletContext; diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java index c4df84c368c..5c2626bf14c 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java @@ -58,6 +58,7 @@ import org.sonar.server.platform.*; import org.sonar.server.plugins.*; import org.sonar.server.rules.ProfilesConsole; import org.sonar.server.rules.RulesConsole; +import org.sonar.server.user.NewUserNotifier; import org.sonar.updatecenter.common.PluginReferential; import org.sonar.updatecenter.common.UpdateCenter; import org.sonar.updatecenter.common.Version; diff --git a/sonar-server/src/main/java/org/sonar/server/platform/NewUserNotifier.java b/sonar-server/src/main/java/org/sonar/server/user/NewUserNotifier.java similarity index 97% rename from sonar-server/src/main/java/org/sonar/server/platform/NewUserNotifier.java rename to sonar-server/src/main/java/org/sonar/server/user/NewUserNotifier.java index 2d92b86ca64..ed94c4c0e4f 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/NewUserNotifier.java +++ b/sonar-server/src/main/java/org/sonar/server/user/NewUserNotifier.java @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.platform; +package org.sonar.server.user; import org.slf4j.LoggerFactory; import org.sonar.api.ServerComponent; diff --git a/sonar-server/src/test/java/org/sonar/server/platform/NewUserNotifierTest.java b/sonar-server/src/test/java/org/sonar/server/user/NewUserNotifierTest.java similarity index 91% rename from sonar-server/src/test/java/org/sonar/server/platform/NewUserNotifierTest.java rename to sonar-server/src/test/java/org/sonar/server/user/NewUserNotifierTest.java index 230540f68be..c69b4675c90 100644 --- a/sonar-server/src/test/java/org/sonar/server/platform/NewUserNotifierTest.java +++ b/sonar-server/src/test/java/org/sonar/server/user/NewUserNotifierTest.java @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.platform; +package org.sonar.server.user; import org.junit.Test; import org.sonar.api.platform.NewUserHandler; @@ -27,7 +27,7 @@ import static org.mockito.Mockito.verify; public class NewUserNotifierTest { - private NewUserHandler.Context context = NewUserHandler.Context.builder().setLogin("marius").setName("Marius").build(); + NewUserHandler.Context context = NewUserHandler.Context.builder().setLogin("marius").setName("Marius").build(); @Test public void do_not_fail_if_no_handlers() { -- 2.39.5