You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LoadChangedIssuesStep.java 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2024 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.ce.task.projectanalysis.step;
  21. import org.sonar.ce.task.projectanalysis.issue.ChangedIssuesRepository;
  22. import org.sonar.ce.task.projectanalysis.issue.ProtoIssueCache;
  23. import org.sonar.ce.task.projectanalysis.period.PeriodHolder;
  24. import org.sonar.ce.task.step.ComputationStep;
  25. import org.sonar.core.issue.DefaultIssue;
  26. import org.sonar.core.util.CloseableIterator;
  27. import org.sonar.db.newcodeperiod.NewCodePeriodType;
  28. public class LoadChangedIssuesStep implements ComputationStep {
  29. private final PeriodHolder periodHolder;
  30. private final ProtoIssueCache protoIssueCache;
  31. private final ChangedIssuesRepository changedIssuesRepository;
  32. public LoadChangedIssuesStep(PeriodHolder periodHolder, ProtoIssueCache protoIssueCache, ChangedIssuesRepository changedIssuesRepository) {
  33. this.periodHolder = periodHolder;
  34. this.protoIssueCache = protoIssueCache;
  35. this.changedIssuesRepository = changedIssuesRepository;
  36. }
  37. @Override
  38. public void execute(Context context) {
  39. try (CloseableIterator<DefaultIssue> issues = protoIssueCache.traverse()) {
  40. while (issues.hasNext()) {
  41. DefaultIssue issue = issues.next();
  42. if (shouldUpdateIndexForIssue(issue)) {
  43. changedIssuesRepository.addIssueKey(issue.key());
  44. }
  45. }
  46. }
  47. }
  48. private boolean shouldUpdateIndexForIssue(DefaultIssue issue) {
  49. return issue.isNew() || issue.isCopied() || issue.isChanged()
  50. || (isOnBranchUsingReferenceBranch() && (issue.isNoLongerNewCodeReferenceIssue() || issue.isToBeMigratedAsNewCodeReferenceIssue()));
  51. }
  52. private boolean isOnBranchUsingReferenceBranch() {
  53. if (periodHolder.hasPeriod()) {
  54. return NewCodePeriodType.REFERENCE_BRANCH.name().equals(periodHolder.getPeriod().getMode());
  55. }
  56. return false;
  57. }
  58. @Override
  59. public String getDescription() {
  60. return "Load changed issues for indexing";
  61. }
  62. }