From 254ecf6ea64ef887eacde7ed181305e2481b4b7e Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 30 May 2013 11:44:22 +0200 Subject: [PATCH] Fix quality flaws --- .../org/sonar/core/issue/ActionPlanDeadlineComparator.java | 3 ++- .../java/org/sonar/core/issue/DefaultIssueBuilder.java | 4 ++-- .../src/main/java/org/sonar/core/persistence/MyBatis.java | 7 +++++-- .../java/org/sonar/core/issue/DefaultIssueBuilderTest.java | 2 ++ .../main/java/org/sonar/server/issue/IssuesFinderSort.java | 5 +++-- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/sonar-core/src/main/java/org/sonar/core/issue/ActionPlanDeadlineComparator.java b/sonar-core/src/main/java/org/sonar/core/issue/ActionPlanDeadlineComparator.java index 0deb1837dbf..6078aaed3d7 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/ActionPlanDeadlineComparator.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/ActionPlanDeadlineComparator.java @@ -21,6 +21,7 @@ package org.sonar.core.issue; import org.sonar.api.issue.ActionPlan; +import java.io.Serializable; import java.util.Comparator; import java.util.Date; @@ -28,7 +29,7 @@ import java.util.Date; * Sort action plans by chronological deadlines. Plans without deadline are * located after plans with deadline. */ -public class ActionPlanDeadlineComparator implements Comparator { +public class ActionPlanDeadlineComparator implements Comparator, Serializable { @Override public int compare(ActionPlan a1, ActionPlan a2) { diff --git a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueBuilder.java b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueBuilder.java index e187b923dd2..1c4dcf208fb 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueBuilder.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueBuilder.java @@ -27,6 +27,7 @@ import org.sonar.api.issue.Issue; import org.sonar.api.rule.RuleKey; import javax.annotation.Nullable; + import java.util.Map; import java.util.UUID; @@ -104,8 +105,7 @@ public class DefaultIssueBuilder implements Issuable.IssueBuilder { @Override public DefaultIssue build() { Preconditions.checkNotNull(componentKey, "Component key must be set"); - // TODO - //Preconditions.checkNotNull(projectKey, "Project key must be set"); + Preconditions.checkNotNull(projectKey, "Project key must be set"); Preconditions.checkNotNull(ruleKey, "Rule key must be set"); DefaultIssue issue = new DefaultIssue(); diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java index af3619bd53c..a1660f4a28e 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java @@ -120,12 +120,15 @@ public class MyBatis implements BatchComponent, ServerComponent { loadAlias(conf, "ActionPlanStats", ActionPlanStatsDto.class); Class[] mappers = {ActiveDashboardMapper.class, AuthorMapper.class, DashboardMapper.class, - DependencyMapper.class, DuplicationMapper.class, GraphDtoMapper.class, IssueMapper.class, IssueStatsMapper.class, IssueChangeMapper.class, LoadedTemplateMapper.class, - MeasureFilterMapper.class, PropertiesMapper.class, PurgeMapper.class, ResourceKeyUpdaterMapper.class, ResourceIndexerMapper.class, ResourceMapper.class, + DependencyMapper.class, DuplicationMapper.class, GraphDtoMapper.class, + // ResourceMapper has to be loaded before IssueMapper because this last one used it + ResourceMapper.class, IssueMapper.class, IssueStatsMapper.class, IssueChangeMapper.class, + LoadedTemplateMapper.class, MeasureFilterMapper.class, PropertiesMapper.class, PurgeMapper.class, ResourceKeyUpdaterMapper.class, ResourceIndexerMapper.class, ResourceSnapshotMapper.class, RoleMapper.class, RuleMapper.class, SchemaMigrationMapper.class, SemaphoreMapper.class, UserMapper.class, WidgetMapper.class, WidgetPropertyMapper.class, MeasureMapper.class, SnapshotDataMapper.class, SnapshotSourceMapper.class, ActionPlanMapper.class, ActionPlanStatsMapper.class }; + // AuthorizationMapper has to be loaded before IssueMapper because this last one used it loadMapper(conf, "org.sonar.core.user.AuthorizationMapper"); loadMappers(conf, mappers); configureLogback(mappers); diff --git a/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueBuilderTest.java b/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueBuilderTest.java index eb55c784461..61d3db092f9 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueBuilderTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueBuilderTest.java @@ -33,6 +33,7 @@ public class DefaultIssueBuilderTest { String componentKey = "org.apache.struts:struts-core:Action.java"; DefaultIssue issue = (DefaultIssue) new DefaultIssueBuilder() .componentKey(componentKey) + .projectKey("org.apache.struts:struts-parent") .message("the message") .line(123) .effortToFix(10000.0) @@ -64,6 +65,7 @@ public class DefaultIssueBuilderTest { public void should_not_set_default_severity() { DefaultIssue issue = (DefaultIssue) new DefaultIssueBuilder() .componentKey("Action.java") + .projectKey("org.apache.struts:struts-parent") .ruleKey(RuleKey.of("squid", "NullDereference")) .build(); diff --git a/sonar-server/src/main/java/org/sonar/server/issue/IssuesFinderSort.java b/sonar-server/src/main/java/org/sonar/server/issue/IssuesFinderSort.java index 64e394bb731..9862a23d8ef 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/IssuesFinderSort.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/IssuesFinderSort.java @@ -41,8 +41,9 @@ class IssuesFinderSort { public List sort() { String sort = query.sort(); - if (sort != null) { - return getIssueProcessor(sort).sort(issues, query.asc()); + Boolean asc = query.asc(); + if (sort != null && asc != null) { + return getIssueProcessor(sort).sort(issues, asc); } return issues; } -- 2.39.5