]> source.dussan.org Git - sonarqube.git/commitdiff
GOV-231 add step to trigger view refresh at end of report processing
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 27 Feb 2018 17:08:41 +0000 (18:08 +0100)
committerSonarTech <sonartech@sonarsource.com>
Fri, 23 Mar 2018 19:20:52 +0000 (20:20 +0100)
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/ReportComputationSteps.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/TriggerViewRefreshStep.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/view/TriggerViewRefreshDelegate.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/view/package-info.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/TriggerViewRefreshStepTest.java [new file with mode: 0644]

index 514498778be9549ca1ba00215e25626cb1a1b9db..9c9aa5116ea14e88209ee13c0bd06f1de8eb7943 100644 (file)
@@ -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 (file)
index 0000000..fd397e1
--- /dev/null
@@ -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 (file)
index 0000000..e368320
--- /dev/null
@@ -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<Project> {
+}
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 (file)
index 0000000..71d3633
--- /dev/null
@@ -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 (file)
index 0000000..155475b
--- /dev/null
@@ -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);
+  }
+}