diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2016-12-09 09:33:49 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2016-12-12 14:55:41 +0100 |
commit | ea21e551a7b27ca7c0ababba410941982ffbd523 (patch) | |
tree | 212cedbfa01af32c807b960358a7dd1ca4c76b33 | |
parent | 26a23900c46eb0d0e9352704710dd58c2e62f924 (diff) | |
download | sonarqube-ea21e551a7b27ca7c0ababba410941982ffbd523.tar.gz sonarqube-ea21e551a7b27ca7c0ababba410941982ffbd523.zip |
SONAR-7291 Rename IssueUpdater to IssueFieldsSetter
A new IssueUpdater used to update issue in db needs to be created
32 files changed, 101 insertions, 121 deletions
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java index c671a6a2f87..4bc68e4546c 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java @@ -64,8 +64,8 @@ import org.sonar.db.DbClient; import org.sonar.db.DefaultDatabase; import org.sonar.db.purge.PurgeProfiler; import org.sonar.db.version.DatabaseVersion; -import org.sonar.process.logging.LogbackHelper; import org.sonar.process.Props; +import org.sonar.process.logging.LogbackHelper; import org.sonar.server.component.ComponentCleanerService; import org.sonar.server.component.ComponentFinder; import org.sonar.server.component.ComponentService; @@ -76,7 +76,7 @@ import org.sonar.server.computation.taskprocessor.CeTaskProcessorModule; import org.sonar.server.debt.DebtModelPluginRepository; import org.sonar.server.debt.DebtRulesXMLImporter; import org.sonar.server.event.NewAlerts; -import org.sonar.server.issue.IssueUpdater; +import org.sonar.server.issue.IssueFieldsSetter; import org.sonar.server.issue.index.IssueIndex; import org.sonar.server.issue.index.IssueIndexer; import org.sonar.server.issue.notification.ChangesOnMyIssueNotificationDispatcher; @@ -345,7 +345,7 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer { // issues IssueIndexer.class, PermissionIndexer.class, - IssueUpdater.class, // used in Web Services and CE's DebtCalculator + IssueFieldsSetter.class, // used in Web Services and CE's DebtCalculator FunctionExecutor.class, // used by IssueWorkflow IssueWorkflow.class, // used in Web Services and CE's DebtCalculator NewIssuesEmailTemplate.class, diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueAssigner.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueAssigner.java index 749e8508327..34faf8d77c1 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueAssigner.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueAssigner.java @@ -32,7 +32,7 @@ import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetada import org.sonar.server.computation.task.projectanalysis.component.Component; import org.sonar.server.computation.task.projectanalysis.scm.ScmInfo; import org.sonar.server.computation.task.projectanalysis.scm.ScmInfoRepository; -import org.sonar.server.issue.IssueUpdater; +import org.sonar.server.issue.IssueFieldsSetter; import static org.apache.commons.lang.StringUtils.defaultIfEmpty; import static org.sonar.core.issue.IssueChangeContext.createScan; @@ -52,7 +52,7 @@ public class IssueAssigner extends IssueVisitor { private final ScmInfoRepository scmInfoRepository; private final DefaultAssignee defaultAssignee; - private final IssueUpdater issueUpdater; + private final IssueFieldsSetter issueUpdater; private final ScmAccountToUser scmAccountToUser; private final IssueChangeContext changeContext; @@ -60,7 +60,7 @@ public class IssueAssigner extends IssueVisitor { private ScmInfo scmChangesets = null; public IssueAssigner(AnalysisMetadataHolder analysisMetadataHolder, ScmInfoRepository scmInfoRepository, ScmAccountToUser scmAccountToUser, DefaultAssignee defaultAssignee, - IssueUpdater issueUpdater) { + IssueFieldsSetter issueUpdater) { this.scmInfoRepository = scmInfoRepository; this.scmAccountToUser = scmAccountToUser; this.defaultAssignee = defaultAssignee; diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueLifecycle.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueLifecycle.java index 32be9da4747..154385873d9 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueLifecycle.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueLifecycle.java @@ -26,7 +26,7 @@ import org.sonar.core.issue.DefaultIssue; import org.sonar.core.issue.IssueChangeContext; import org.sonar.core.util.Uuids; import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder; -import org.sonar.server.issue.IssueUpdater; +import org.sonar.server.issue.IssueFieldsSetter; import org.sonar.server.issue.workflow.IssueWorkflow; /** @@ -41,15 +41,15 @@ public class IssueLifecycle { private final IssueWorkflow workflow; private final IssueChangeContext changeContext; - private final IssueUpdater updater; + private final IssueFieldsSetter updater; private final DebtCalculator debtCalculator; - public IssueLifecycle(AnalysisMetadataHolder analysisMetadataHolder, IssueWorkflow workflow, IssueUpdater updater, DebtCalculator debtCalculator) { + public IssueLifecycle(AnalysisMetadataHolder analysisMetadataHolder, IssueWorkflow workflow, IssueFieldsSetter updater, DebtCalculator debtCalculator) { this(IssueChangeContext.createScan(new Date(analysisMetadataHolder.getAnalysisDate())), workflow, updater, debtCalculator); } @VisibleForTesting - IssueLifecycle(IssueChangeContext changeContext, IssueWorkflow workflow, IssueUpdater updater, DebtCalculator debtCalculator) { + IssueLifecycle(IssueChangeContext changeContext, IssueWorkflow workflow, IssueFieldsSetter updater, DebtCalculator debtCalculator) { this.workflow = workflow; this.updater = updater; this.debtCalculator = debtCalculator; diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/MovedIssueVisitor.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/MovedIssueVisitor.java index 68fde5d1c45..d5883de11b7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/MovedIssueVisitor.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/MovedIssueVisitor.java @@ -27,16 +27,16 @@ import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetada import org.sonar.server.computation.task.projectanalysis.component.Component; import org.sonar.server.computation.task.projectanalysis.filemove.MovedFilesRepository; import org.sonar.server.computation.task.projectanalysis.filemove.MovedFilesRepository.OriginalFile; -import org.sonar.server.issue.IssueUpdater; +import org.sonar.server.issue.IssueFieldsSetter; import static com.google.common.base.Preconditions.checkState; public class MovedIssueVisitor extends IssueVisitor { private final AnalysisMetadataHolder analysisMetadataHolder; private final MovedFilesRepository movedFilesRepository; - private final IssueUpdater issueUpdater; + private final IssueFieldsSetter issueUpdater; - public MovedIssueVisitor(AnalysisMetadataHolder analysisMetadataHolder, MovedFilesRepository movedFilesRepository, IssueUpdater issueUpdater) { + public MovedIssueVisitor(AnalysisMetadataHolder analysisMetadataHolder, MovedFilesRepository movedFilesRepository, IssueFieldsSetter issueUpdater) { this.analysisMetadataHolder = analysisMetadataHolder; this.movedFilesRepository = movedFilesRepository; this.issueUpdater = issueUpdater; diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/NewEffortCalculator.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/NewEffortCalculator.java index 5c201a284f8..e970c0c8e79 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/NewEffortCalculator.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/NewEffortCalculator.java @@ -38,7 +38,7 @@ import org.sonar.core.issue.DefaultIssue; import org.sonar.core.issue.FieldDiffs; import org.sonar.db.issue.IssueChangeDto; import org.sonar.server.computation.task.projectanalysis.period.Period; -import org.sonar.server.issue.IssueUpdater; +import org.sonar.server.issue.IssueFieldsSetter; import static com.google.common.collect.FluentIterable.from; @@ -108,7 +108,7 @@ public class NewEffortCalculator { } private static FieldDiffs.Diff debtDiff(FieldDiffs diffs) { - return diffs.diffs().get(IssueUpdater.TECHNICAL_DEBT); + return diffs.diffs().get(IssueFieldsSetter.TECHNICAL_DEBT); } private enum ToFieldDiffs implements Function<IssueChangeDto, FieldDiffs> { @@ -123,7 +123,7 @@ public class NewEffortCalculator { INSTANCE; @Override public boolean apply(@Nonnull FieldDiffs diffs) { - return diffs.diffs().containsKey(IssueUpdater.TECHNICAL_DEBT); + return diffs.diffs().containsKey(IssueFieldsSetter.TECHNICAL_DEBT); } } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/AbstractChangeTagsAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/AbstractChangeTagsAction.java index a54f6ffc302..0f270b58088 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/AbstractChangeTagsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/AbstractChangeTagsAction.java @@ -22,25 +22,24 @@ package org.sonar.server.issue; import com.google.common.base.Splitter; import com.google.common.base.Strings; import com.google.common.collect.Sets; -import org.sonar.api.server.ServerSide; +import java.util.Collection; +import java.util.Map; +import java.util.Set; import org.sonar.api.issue.Issue; import org.sonar.api.issue.condition.IsUnResolved; -import org.sonar.core.issue.DefaultIssue; +import org.sonar.api.server.ServerSide; import org.sonar.api.server.rule.RuleTagFormat; +import org.sonar.core.issue.DefaultIssue; import org.sonar.server.user.UserSession; -import java.util.Collection; -import java.util.Map; -import java.util.Set; - @ServerSide public abstract class AbstractChangeTagsAction extends Action { private static final Splitter TAGS_SPLITTER = Splitter.on(',').trimResults().omitEmptyStrings(); - private final IssueUpdater issueUpdater; + private final IssueFieldsSetter issueUpdater; - protected AbstractChangeTagsAction(String key, IssueUpdater issueUpdater) { + protected AbstractChangeTagsAction(String key, IssueFieldsSetter issueUpdater) { super(key); this.issueUpdater = issueUpdater; super.setConditions(new IsUnResolved()); diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/AddTagsAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/AddTagsAction.java index 4e27a00de11..f13c7f0f759 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/AddTagsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/AddTagsAction.java @@ -20,17 +20,16 @@ package org.sonar.server.issue; import com.google.common.collect.Sets; -import org.sonar.api.server.ServerSide; - import java.util.Collection; import java.util.Set; +import org.sonar.api.server.ServerSide; @ServerSide public class AddTagsAction extends AbstractChangeTagsAction { public static final String KEY = "add_tags"; - public AddTagsAction(IssueUpdater issueUpdater) { + public AddTagsAction(IssueFieldsSetter issueUpdater) { super(KEY, issueUpdater); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/AssignAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/AssignAction.java index 19a44bb3d6f..bed36da03f1 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/AssignAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/AssignAction.java @@ -37,9 +37,9 @@ public class AssignAction extends Action { public static final String VERIFIED_ASSIGNEE = "verifiedAssignee"; private final UserFinder userFinder; - private final IssueUpdater issueUpdater; + private final IssueFieldsSetter issueUpdater; - public AssignAction(UserFinder userFinder, IssueUpdater issueUpdater) { + public AssignAction(UserFinder userFinder, IssueFieldsSetter issueUpdater) { super(ASSIGN_KEY); this.userFinder = userFinder; this.issueUpdater = issueUpdater; diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/CommentAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/CommentAction.java index 2c56f233220..6ad3f457480 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/CommentAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/CommentAction.java @@ -33,9 +33,9 @@ public class CommentAction extends Action { public static final String COMMENT_KEY = "comment"; public static final String COMMENT_PROPERTY = "comment"; - private final IssueUpdater issueUpdater; + private final IssueFieldsSetter issueUpdater; - public CommentAction(IssueUpdater issueUpdater) { + public CommentAction(IssueFieldsSetter issueUpdater) { super(COMMENT_KEY); this.issueUpdater = issueUpdater; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueChangelog.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueChangelog.java index cdb8db9bf46..a7ab42dfb3c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueChangelog.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueChangelog.java @@ -51,9 +51,9 @@ public class IssueChangelog { private static void replacedTechnicalDebtByEffort(List<FieldDiffs> changes) { for (FieldDiffs fieldDiffs : changes) { Map<String, FieldDiffs.Diff> diffs = fieldDiffs.diffs(); - if (diffs.containsKey(IssueUpdater.TECHNICAL_DEBT)) { - FieldDiffs.Diff value = diffs.get(IssueUpdater.TECHNICAL_DEBT); - diffs.remove(IssueUpdater.TECHNICAL_DEBT); + if (diffs.containsKey(IssueFieldsSetter.TECHNICAL_DEBT)) { + FieldDiffs.Diff value = diffs.get(IssueFieldsSetter.TECHNICAL_DEBT); + diffs.remove(IssueFieldsSetter.TECHNICAL_DEBT); diffs.put("effort", value); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueCommentService.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueCommentService.java index 8893f23e2b5..b39f3c89024 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueCommentService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueCommentService.java @@ -45,10 +45,10 @@ public class IssueCommentService { private final DbClient dbClient; private final IssueService issueService; - private final IssueUpdater updater; + private final IssueFieldsSetter updater; private final UserSession userSession; - public IssueCommentService(DbClient dbClient, IssueService issueService, IssueUpdater updater, UserSession userSession) { + public IssueCommentService(DbClient dbClient, IssueService issueService, IssueFieldsSetter updater, UserSession userSession) { this.dbClient = dbClient; this.issueService = issueService; this.updater = updater; diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueUpdater.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java index 1d62b3de561..d604a124a56 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueUpdater.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java @@ -19,12 +19,9 @@ */ package org.sonar.server.issue; -import com.google.common.base.Function; import com.google.common.base.Joiner; -import com.google.common.base.Predicate; -import com.google.common.collect.Collections2; import com.google.common.collect.Sets; -import java.util.Calendar; +import java.time.temporal.ChronoUnit; import java.util.Collection; import java.util.Date; import java.util.Locale; @@ -32,7 +29,6 @@ import java.util.Objects; import java.util.Set; import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.time.DateUtils; import org.sonar.api.ce.ComputeEngineSide; import org.sonar.api.rules.RuleType; import org.sonar.api.server.ServerSide; @@ -42,6 +38,7 @@ import org.sonar.api.utils.Duration; import org.sonar.core.issue.DefaultIssue; import org.sonar.core.issue.DefaultIssueComment; import org.sonar.core.issue.IssueChangeContext; +import org.sonar.core.util.stream.Collectors; import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Strings.isNullOrEmpty; @@ -51,7 +48,7 @@ import static com.google.common.base.Strings.isNullOrEmpty; */ @ServerSide @ComputeEngineSide -public class IssueUpdater { +public class IssueFieldsSetter { public static final String UNUSED = ""; public static final String SEVERITY = "severity"; @@ -253,7 +250,7 @@ public class IssueUpdater { } public void setCloseDate(DefaultIssue issue, @Nullable Date d, IssueChangeContext context) { - Date dateWithoutMilliseconds = d == null ? null : DateUtils.truncate(d, Calendar.SECOND); + Date dateWithoutMilliseconds = d == null ? null : Date.from(d.toInstant().truncatedTo(ChronoUnit.SECONDS)); if (!Objects.equals(dateWithoutMilliseconds, issue.closeDate())) { issue.setCloseDate(d); issue.setUpdateDate(context.date()); @@ -310,23 +307,13 @@ public class IssueUpdater { } public boolean setTags(DefaultIssue issue, Collection<String> tags, IssueChangeContext context) { - Set<String> newTags = Sets.newHashSet(Collections2.transform( - Collections2.filter(tags, new Predicate<String>() { - @Override - public boolean apply(@Nullable String tag) { - return tag != null && !tag.isEmpty(); - } - }), new Function<String, String>() { - @Override - public String apply(String tag) { - String lowerCaseTag = tag.toLowerCase(Locale.ENGLISH); - RuleTagFormat.validate(lowerCaseTag); - return lowerCaseTag; - } - })); + Set<String> newTags = tags.stream() + .filter(Objects::nonNull) + .filter(tag -> !tag.isEmpty()) + .map(tag -> RuleTagFormat.validate(tag.toLowerCase(Locale.ENGLISH))) + .collect(Collectors.toSet()); Set<String> oldTags = Sets.newHashSet(issue.tags()); - if (!oldTags.equals(newTags)) { issue.setFieldChange(context, TAGS, oldTags.isEmpty() ? null : CHANGELOG_TAG_JOINER.join(oldTags), diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java index dcb4d0bd274..6b8b7b4a5e5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java @@ -61,7 +61,7 @@ public class IssueService { private final IssueIndex issueIndex; private final IssueWorkflow workflow; - private final IssueUpdater issueUpdater; + private final IssueFieldsSetter issueUpdater; private final IssueStorage issueStorage; private final NotificationManager notificationService; private final UserFinder userFinder; @@ -70,7 +70,7 @@ public class IssueService { public IssueService(DbClient dbClient, IssueIndex issueIndex, IssueWorkflow workflow, IssueStorage issueStorage, - IssueUpdater issueUpdater, + IssueFieldsSetter issueUpdater, NotificationManager notificationService, UserFinder userFinder, UserSession userSession) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/RemoveTagsAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/RemoveTagsAction.java index c9cb09c465b..5d8a93a5d88 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/RemoveTagsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/RemoveTagsAction.java @@ -20,17 +20,16 @@ package org.sonar.server.issue; import com.google.common.collect.Sets; -import org.sonar.api.server.ServerSide; - import java.util.Collection; import java.util.Set; +import org.sonar.api.server.ServerSide; @ServerSide public class RemoveTagsAction extends AbstractChangeTagsAction { public static final String KEY = "remove_tags"; - public RemoveTagsAction(IssueUpdater issueUpdater) { + public RemoveTagsAction(IssueFieldsSetter issueUpdater) { super(KEY, issueUpdater); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/SetSeverityAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/SetSeverityAction.java index 75656f961ad..8a521e5f097 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/SetSeverityAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/SetSeverityAction.java @@ -35,10 +35,10 @@ public class SetSeverityAction extends Action { public static final String SET_SEVERITY_KEY = "set_severity"; - private final IssueUpdater issueUpdater; + private final IssueFieldsSetter issueUpdater; private final UserSession userSession; - public SetSeverityAction(IssueUpdater issueUpdater, UserSession userSession) { + public SetSeverityAction(IssueFieldsSetter issueUpdater, UserSession userSession) { super(SET_SEVERITY_KEY); this.issueUpdater = issueUpdater; this.userSession = userSession; diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/SetTypeAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/SetTypeAction.java index a1b2fbb1b98..0f4529b500a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/SetTypeAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/SetTypeAction.java @@ -35,9 +35,9 @@ public class SetTypeAction extends Action { private static final String SET_TYPE_KEY = "set_type"; private static final String TYPE_PARAMETER = "type"; - private final IssueUpdater issueUpdater; + private final IssueFieldsSetter issueUpdater; - public SetTypeAction(IssueUpdater issueUpdater) { + public SetTypeAction(IssueFieldsSetter issueUpdater) { super(SET_TYPE_KEY); this.issueUpdater = issueUpdater; super.setConditions(new IsUnResolved()); diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/workflow/FunctionExecutor.java b/server/sonar-server/src/main/java/org/sonar/server/issue/workflow/FunctionExecutor.java index 129c55b2864..7d32d8de180 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/workflow/FunctionExecutor.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/workflow/FunctionExecutor.java @@ -20,21 +20,21 @@ package org.sonar.server.issue.workflow; import javax.annotation.Nullable; -import org.sonar.api.issue.Issue; import org.sonar.api.ce.ComputeEngineSide; +import org.sonar.api.issue.Issue; import org.sonar.api.server.ServerSide; import org.sonar.api.user.User; import org.sonar.core.issue.DefaultIssue; import org.sonar.core.issue.IssueChangeContext; -import org.sonar.server.issue.IssueUpdater; +import org.sonar.server.issue.IssueFieldsSetter; @ServerSide @ComputeEngineSide public class FunctionExecutor { - private final IssueUpdater updater; + private final IssueFieldsSetter updater; - public FunctionExecutor(IssueUpdater updater) { + public FunctionExecutor(IssueFieldsSetter updater) { this.updater = updater; } @@ -48,11 +48,11 @@ public class FunctionExecutor { } static class FunctionContext implements Function.Context { - private final IssueUpdater updater; + private final IssueFieldsSetter updater; private final DefaultIssue issue; private final IssueChangeContext changeContext; - FunctionContext(IssueUpdater updater, DefaultIssue issue, IssueChangeContext changeContext) { + FunctionContext(IssueFieldsSetter updater, DefaultIssue issue, IssueChangeContext changeContext) { this.updater = updater; this.issue = issue; this.changeContext = changeContext; diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/workflow/IssueWorkflow.java b/server/sonar-server/src/main/java/org/sonar/server/issue/workflow/IssueWorkflow.java index f0ad17fa053..c9768eefb99 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/workflow/IssueWorkflow.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/workflow/IssueWorkflow.java @@ -30,7 +30,7 @@ import org.sonar.api.server.ServerSide; import org.sonar.api.web.UserRole; import org.sonar.core.issue.DefaultIssue; import org.sonar.core.issue.IssueChangeContext; -import org.sonar.server.issue.IssueUpdater; +import org.sonar.server.issue.IssueFieldsSetter; @ServerSide @ComputeEngineSide @@ -38,10 +38,10 @@ public class IssueWorkflow implements Startable { public static final String AUTOMATIC_CLOSE_TRANSITION = "automaticclose"; private final FunctionExecutor functionExecutor; - private final IssueUpdater updater; + private final IssueFieldsSetter updater; private StateMachine machine; - public IssueWorkflow(FunctionExecutor functionExecutor, IssueUpdater updater) { + public IssueWorkflow(FunctionExecutor functionExecutor, IssueFieldsSetter updater) { this.functionExecutor = functionExecutor; this.updater = updater; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java index 3255dc6f23d..bd21067dd59 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java @@ -65,9 +65,9 @@ import org.sonar.server.issue.InternalRubyIssueService; import org.sonar.server.issue.IssueBulkChangeService; import org.sonar.server.issue.IssueChangelogService; import org.sonar.server.issue.IssueCommentService; +import org.sonar.server.issue.IssueFieldsSetter; import org.sonar.server.issue.IssueQueryService; import org.sonar.server.issue.IssueService; -import org.sonar.server.issue.IssueUpdater; import org.sonar.server.issue.RemoveTagsAction; import org.sonar.server.issue.ServerIssueStorage; import org.sonar.server.issue.SetSeverityAction; @@ -398,7 +398,7 @@ public class PlatformLevel4 extends PlatformLevel { IssueIndexer.class, PermissionIndexer.class, ServerIssueStorage.class, - IssueUpdater.class, + IssueFieldsSetter.class, FunctionExecutor.class, IssueWorkflow.class, IssueCommentService.class, diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueAssignerTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueAssignerTest.java index d38e6cf9564..75837fa82a4 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueAssignerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueAssignerTest.java @@ -28,7 +28,7 @@ import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetada import org.sonar.server.computation.task.projectanalysis.component.Component; import org.sonar.server.computation.task.projectanalysis.scm.Changeset; import org.sonar.server.computation.task.projectanalysis.scm.ScmInfoRepositoryRule; -import org.sonar.server.issue.IssueUpdater; +import org.sonar.server.issue.IssueFieldsSetter; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -52,7 +52,7 @@ public class IssueAssignerTest { ScmAccountToUser scmAccountToUser = mock(ScmAccountToUser.class); DefaultAssignee defaultAssignee = mock(DefaultAssignee.class); - IssueAssigner underTest = new IssueAssigner(analysisMetadataHolder, scmInfoRepository, scmAccountToUser, defaultAssignee, new IssueUpdater()); + IssueAssigner underTest = new IssueAssigner(analysisMetadataHolder, scmInfoRepository, scmAccountToUser, defaultAssignee, new IssueFieldsSetter()); @Test public void nothing_to_do_if_no_changeset() throws Exception { diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueLifecycleTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueLifecycleTest.java index f8145d4eef8..fb5fe17d304 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueLifecycleTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueLifecycleTest.java @@ -27,7 +27,7 @@ import org.sonar.core.issue.DefaultIssue; import org.sonar.core.issue.IssueChangeContext; import org.sonar.db.protobuf.DbCommons; import org.sonar.db.protobuf.DbIssues; -import org.sonar.server.issue.IssueUpdater; +import org.sonar.server.issue.IssueFieldsSetter; import org.sonar.server.issue.workflow.IssueWorkflow; import static com.google.common.collect.Lists.newArrayList; @@ -52,7 +52,7 @@ public class IssueLifecycleTest { IssueWorkflow workflow = mock(IssueWorkflow.class); - IssueUpdater updater = mock(IssueUpdater.class); + IssueFieldsSetter updater = mock(IssueFieldsSetter.class); DebtCalculator debtCalculator = mock(DebtCalculator.class); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/MovedIssueVisitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/MovedIssueVisitorTest.java index 2e2095a5864..a98fcfd456f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/MovedIssueVisitorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/MovedIssueVisitorTest.java @@ -31,7 +31,7 @@ import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetada import org.sonar.server.computation.task.projectanalysis.component.Component; import org.sonar.server.computation.task.projectanalysis.component.ReportComponent; import org.sonar.server.computation.task.projectanalysis.filemove.MovedFilesRepository; -import org.sonar.server.issue.IssueUpdater; +import org.sonar.server.issue.IssueFieldsSetter; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.any; @@ -53,7 +53,7 @@ public class MovedIssueVisitorTest { public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule(); private MovedFilesRepository movedFilesRepository = mock(MovedFilesRepository.class); - private MovedIssueVisitor underTest = new MovedIssueVisitor(analysisMetadataHolder, movedFilesRepository, new IssueUpdater()); + private MovedIssueVisitor underTest = new MovedIssueVisitor(analysisMetadataHolder, movedFilesRepository, new IssueFieldsSetter()); @Before public void setUp() throws Exception { diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/AddTagsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/AddTagsActionTest.java index ec27342bf6c..673c864f2ec 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/AddTagsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/AddTagsActionTest.java @@ -20,6 +20,8 @@ package org.sonar.server.issue; import com.google.common.collect.ImmutableSet; +import java.util.Collection; +import java.util.Map; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -28,9 +30,6 @@ import org.mockito.Matchers; import org.sonar.core.issue.DefaultIssue; import org.sonar.core.issue.IssueChangeContext; -import java.util.Collection; -import java.util.Map; - import static com.google.common.collect.Maps.newHashMap; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; @@ -42,7 +41,7 @@ public class AddTagsActionTest { private AddTagsAction action; - private IssueUpdater issueUpdater = mock(IssueUpdater.class); + private IssueFieldsSetter issueUpdater = mock(IssueFieldsSetter.class); @Rule public ExpectedException throwable = ExpectedException.none(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/AssignActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/AssignActionTest.java index e9462422ecd..d18e5d5f2f5 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/AssignActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/AssignActionTest.java @@ -19,32 +19,35 @@ */ package org.sonar.server.issue; +import java.util.List; +import java.util.Map; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.issue.Issue; -import org.sonar.core.issue.DefaultIssue; -import org.sonar.core.issue.IssueChangeContext; import org.sonar.api.user.User; import org.sonar.api.user.UserFinder; +import org.sonar.core.issue.DefaultIssue; +import org.sonar.core.issue.IssueChangeContext; import org.sonar.core.user.DefaultUser; import org.sonar.server.user.ThreadLocalUserSession; -import java.util.List; -import java.util.Map; - import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.Maps.newHashMap; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class AssignActionTest { private AssignAction action; private final UserFinder userFinder = mock(UserFinder.class); - private IssueUpdater issueUpdater = mock(IssueUpdater.class); + private IssueFieldsSetter issueUpdater = mock(IssueFieldsSetter.class); @Rule public ExpectedException throwable = ExpectedException.none(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/CommentActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/CommentActionTest.java index dea9d87c82c..f437af156d5 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/CommentActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/CommentActionTest.java @@ -42,7 +42,7 @@ public class CommentActionTest { private CommentAction action; - private IssueUpdater issueUpdater = mock(IssueUpdater.class); + private IssueFieldsSetter issueUpdater = mock(IssueFieldsSetter.class); @Before public void before(){ diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceTest.java index 60707a7b75a..cc84fb71ed1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceTest.java @@ -33,11 +33,11 @@ import org.sonar.core.issue.IssueChangeContext; import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbClient; import org.sonar.db.DbSession; +import org.sonar.db.component.ComponentTesting; import org.sonar.db.issue.IssueChangeDao; import org.sonar.db.issue.IssueChangeDto; import org.sonar.db.issue.IssueDto; import org.sonar.db.rule.RuleTesting; -import org.sonar.db.component.ComponentTesting; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; @@ -68,7 +68,7 @@ public class IssueCommentServiceTest { private IssueService issueService; @Mock - private IssueUpdater updater; + private IssueFieldsSetter updater; @Mock private IssueChangeDao changeDao; diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueUpdaterTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueFieldsSetterTest.java index 4c6ba39c997..fb79a2ec90b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueUpdaterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueFieldsSetterTest.java @@ -23,7 +23,6 @@ import java.util.Calendar; import java.util.Date; import java.util.Map; import org.apache.commons.lang.time.DateUtils; -import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -35,14 +34,14 @@ import org.sonar.core.issue.IssueChangeContext; import org.sonar.core.user.DefaultUser; import static org.assertj.core.api.Assertions.assertThat; -import static org.sonar.server.issue.IssueUpdater.ASSIGNEE; -import static org.sonar.server.issue.IssueUpdater.RESOLUTION; -import static org.sonar.server.issue.IssueUpdater.SEVERITY; -import static org.sonar.server.issue.IssueUpdater.STATUS; -import static org.sonar.server.issue.IssueUpdater.TECHNICAL_DEBT; -import static org.sonar.server.issue.IssueUpdater.UNUSED; +import static org.sonar.server.issue.IssueFieldsSetter.ASSIGNEE; +import static org.sonar.server.issue.IssueFieldsSetter.RESOLUTION; +import static org.sonar.server.issue.IssueFieldsSetter.SEVERITY; +import static org.sonar.server.issue.IssueFieldsSetter.STATUS; +import static org.sonar.server.issue.IssueFieldsSetter.TECHNICAL_DEBT; +import static org.sonar.server.issue.IssueFieldsSetter.UNUSED; -public class IssueUpdaterTest { +public class IssueFieldsSetterTest { @Rule public ExpectedException thrown = ExpectedException.none(); @@ -50,12 +49,7 @@ public class IssueUpdaterTest { DefaultIssue issue = new DefaultIssue(); IssueChangeContext context = IssueChangeContext.createUser(new Date(), "emmerik"); - IssueUpdater updater; - - @Before - public void setUp() { - updater = new IssueUpdater(); - } + IssueFieldsSetter updater = new IssueFieldsSetter(); @Test public void assign() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/RemoveTagsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/RemoveTagsActionTest.java index efe5914e89c..7fd1fa2e693 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/RemoveTagsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/RemoveTagsActionTest.java @@ -20,6 +20,8 @@ package org.sonar.server.issue; import com.google.common.collect.ImmutableSet; +import java.util.Collection; +import java.util.Map; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -28,9 +30,6 @@ import org.mockito.Matchers; import org.sonar.core.issue.DefaultIssue; import org.sonar.core.issue.IssueChangeContext; -import java.util.Collection; -import java.util.Map; - import static com.google.common.collect.Maps.newHashMap; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; @@ -42,7 +41,7 @@ public class RemoveTagsActionTest { private RemoveTagsAction action; - private IssueUpdater issueUpdater = mock(IssueUpdater.class); + private IssueFieldsSetter issueUpdater = mock(IssueFieldsSetter.class); @Rule public ExpectedException throwable = ExpectedException.none(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/SetSeverityActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/SetSeverityActionTest.java index 2a6d4613c2e..993c09d2b3d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/SetSeverityActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/SetSeverityActionTest.java @@ -51,7 +51,7 @@ public class SetSeverityActionTest { private SetSeverityAction action; - private IssueUpdater issueUpdater = mock(IssueUpdater.class); + private IssueFieldsSetter issueUpdater = mock(IssueFieldsSetter.class); @Before public void before() { diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/SetTypeActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/SetTypeActionTest.java index 3ee8f3972b2..b08c06fba76 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/SetTypeActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/SetTypeActionTest.java @@ -48,7 +48,7 @@ public class SetTypeActionTest { public UserSessionRule userSessionRule = UserSessionRule.standalone(); UserSession userSessionMock = mock(UserSession.class); - IssueUpdater issueUpdater = mock(IssueUpdater.class); + IssueFieldsSetter issueUpdater = mock(IssueFieldsSetter.class); SetTypeAction underTest; @Before diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/workflow/IssueWorkflowTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/workflow/IssueWorkflowTest.java index 44bbc214efb..2df5937330e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/workflow/IssueWorkflowTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/workflow/IssueWorkflowTest.java @@ -32,7 +32,7 @@ import org.sonar.api.issue.DefaultTransitions; import org.sonar.api.rule.RuleKey; import org.sonar.core.issue.DefaultIssue; import org.sonar.core.issue.IssueChangeContext; -import org.sonar.server.issue.IssueUpdater; +import org.sonar.server.issue.IssueFieldsSetter; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; @@ -47,7 +47,7 @@ import static org.sonar.api.issue.Issue.STATUS_RESOLVED; public class IssueWorkflowTest { - IssueUpdater updater = new IssueUpdater(); + IssueFieldsSetter updater = new IssueFieldsSetter(); IssueWorkflow workflow = new IssueWorkflow(new FunctionExecutor(updater), updater); @Test diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleTagFormat.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleTagFormat.java index 149e73a27fe..60f35ca61b2 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleTagFormat.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleTagFormat.java @@ -39,9 +39,10 @@ public class RuleTagFormat { return StringUtils.isNotBlank(tag) && tag.matches(VALID_CHARACTERS_REGEX); } - public static void validate(String tag) { + public static String validate(String tag) { if (!isValid(tag)) { throw new IllegalArgumentException(String.format("Tag '%s' is invalid. Rule tags accept only the characters: a-z, 0-9, '+', '-', '#', '.'", tag)); } + return tag; } } |