From 4775c5bb1c3e28b986a21059e349d3a65ef159b4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Tue, 27 Feb 2018 18:08:41 +0100 Subject: [PATCH] GOV-231 add step to trigger view refresh at end of report processing --- .../step/ReportComputationSteps.java | 3 +- .../step/TriggerViewRefreshStep.java | 64 ++++++++++++++++++ .../view/TriggerViewRefreshDelegate.java | 27 ++++++++ .../projectanalysis/view/package-info.java | 23 +++++++ .../step/TriggerViewRefreshStepTest.java | 66 +++++++++++++++++++ 5 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/TriggerViewRefreshStep.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/view/TriggerViewRefreshDelegate.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/view/package-info.java create mode 100644 server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/TriggerViewRefreshStepTest.java diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/ReportComputationSteps.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/ReportComputationSteps.java index 514498778be..9c9aa5116ea 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/ReportComputationSteps.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/ReportComputationSteps.java @@ -104,7 +104,8 @@ public class ReportComputationSteps extends AbstractComputationSteps { // notifications are sent at the end, so that webapp displays up-to-date information SendIssueNotificationsStep.class, - PublishTaskResultStep.class); + PublishTaskResultStep.class, + TriggerViewRefreshStep.class); public ReportComputationSteps(TaskContainer taskContainer) { super(taskContainer); diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/TriggerViewRefreshStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/TriggerViewRefreshStep.java new file mode 100644 index 00000000000..fd397e13a28 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/TriggerViewRefreshStep.java @@ -0,0 +1,64 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program 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. + * + * This program 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. + */ + +package org.sonar.server.computation.task.projectanalysis.step; + +import javax.annotation.CheckForNull; +import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder; +import org.sonar.server.computation.task.projectanalysis.view.TriggerViewRefreshDelegate; +import org.sonar.server.computation.task.step.ComputationStep; + +/** + * This step will trigger refresh of Portfolios and Applications that include the current project. + */ +public class TriggerViewRefreshStep implements ComputationStep { + + @CheckForNull + private final TriggerViewRefreshDelegate triggerViewRefreshDelegate; + private final AnalysisMetadataHolder analysisMetadata; + + /** + * Constructor used by Pico when no implementation of {@link TriggerViewRefreshDelegate} is available + */ + public TriggerViewRefreshStep(AnalysisMetadataHolder analysisMetadata) { + this.analysisMetadata = analysisMetadata; + this.triggerViewRefreshDelegate = null; + } + + /** + * Constructor used by Pico when an implementation of {@link TriggerViewRefreshDelegate} is available + */ + public TriggerViewRefreshStep(AnalysisMetadataHolder analysisMetadata, TriggerViewRefreshDelegate triggerViewRefreshDelegate) { + this.analysisMetadata = analysisMetadata; + this.triggerViewRefreshDelegate = triggerViewRefreshDelegate; + } + + @Override + public String getDescription() { + return "Trigger refresh of Portfolios and Applications"; + } + + @Override + public void execute() { + if (triggerViewRefreshDelegate != null) { + triggerViewRefreshDelegate.accept(analysisMetadata.getProject()); + } + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/view/TriggerViewRefreshDelegate.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/view/TriggerViewRefreshDelegate.java new file mode 100644 index 00000000000..e36832051b6 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/view/TriggerViewRefreshDelegate.java @@ -0,0 +1,27 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program 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. + * + * This program 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. + */ + +package org.sonar.server.computation.task.projectanalysis.view; + +import java.util.function.Consumer; +import org.sonar.server.computation.task.projectanalysis.analysis.Project; + +public interface TriggerViewRefreshDelegate extends Consumer { +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/view/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/view/package-info.java new file mode 100644 index 00000000000..71d363304b5 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/view/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program 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. + * + * This program 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.server.computation.task.projectanalysis.view; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/TriggerViewRefreshStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/TriggerViewRefreshStepTest.java new file mode 100644 index 00000000000..155475b5ac5 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/TriggerViewRefreshStepTest.java @@ -0,0 +1,66 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program 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. + * + * This program 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. + */ +package org.sonar.server.computation.task.projectanalysis.step; + +import org.junit.Test; +import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder; +import org.sonar.server.computation.task.projectanalysis.analysis.Project; +import org.sonar.server.computation.task.projectanalysis.view.TriggerViewRefreshDelegate; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; + +public class TriggerViewRefreshStepTest { + private AnalysisMetadataHolder analysisMetadataHolder = mock(AnalysisMetadataHolder.class); + + + @Test + public void execute_has_no_effect_if_constructor_without_delegate() { + TriggerViewRefreshStep underTest = new TriggerViewRefreshStep(analysisMetadataHolder); + + underTest.execute(); + + verifyZeroInteractions(analysisMetadataHolder); + } + + @Test + public void execute_has_no_effect_if_constructor_with_null_delegate() { + TriggerViewRefreshStep underTest = new TriggerViewRefreshStep(analysisMetadataHolder, null); + + underTest.execute(); + + verifyZeroInteractions(analysisMetadataHolder); + } + + @Test + public void execute_calls_delegate_with_project_from_holder_if_passed_to_constructor() { + TriggerViewRefreshDelegate delegate = mock(TriggerViewRefreshDelegate.class); + Project project = mock(Project.class); + when(analysisMetadataHolder.getProject()).thenReturn(project); + TriggerViewRefreshStep underTest = new TriggerViewRefreshStep(analysisMetadataHolder, delegate); + + underTest.execute(); + + verify(analysisMetadataHolder).getProject(); + verify(delegate).accept(project); + } +} -- 2.39.5