import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.ResourceUtils;
+import org.sonar.batch.qualitygate.QualityGate;
import java.util.List;
public class GenerateAlertEvents implements Decorator {
private final RulesProfile profile;
+ private final QualityGate qualityGate;
private final TimeMachine timeMachine;
private NotificationManager notificationManager;
- public GenerateAlertEvents(RulesProfile profile, TimeMachine timeMachine, NotificationManager notificationManager) {
+ public GenerateAlertEvents(RulesProfile profile, QualityGate qualityGate, TimeMachine timeMachine, NotificationManager notificationManager) {
this.profile = profile;
+ this.qualityGate = qualityGate;
this.timeMachine = timeMachine;
this.notificationManager = notificationManager;
}
public boolean shouldExecuteOnProject(Project project) {
- return profile != null && profile.getAlerts() != null && !profile.getAlerts().isEmpty();
+ return profile != null && profile.getAlerts() != null && !profile.getAlerts().isEmpty()
+ || qualityGate.isEnabled();
}
@DependsUpon
import org.sonar.api.resources.File;
import org.sonar.api.resources.Project;
import org.sonar.api.test.ProjectTestBuilder;
+import org.sonar.batch.qualitygate.QualityGate;
import java.util.Arrays;
import java.util.Date;
private GenerateAlertEvents decorator;
private DecoratorContext context;
private RulesProfile profile;
+ private QualityGate qualityGate;
private TimeMachine timeMachine;
private NotificationManager notificationManager;
private Project project;
context = mock(DecoratorContext.class);
timeMachine = mock(TimeMachine.class);
profile = mock(RulesProfile.class);
+ qualityGate = mock(QualityGate.class);
notificationManager = mock(NotificationManager.class);
- decorator = new GenerateAlertEvents(profile, timeMachine, notificationManager);
+ decorator = new GenerateAlertEvents(profile, qualityGate, timeMachine, notificationManager);
project = new ProjectTestBuilder().build();
}
assertThat(decorator.shouldExecuteOnProject(project)).isFalse();
}
+ @Test
+ public void shouldDecorateIfQualityGateEnabled() {
+ when(qualityGate.isEnabled()).thenReturn(true);
+ assertThat(decorator.shouldExecuteOnProject(project)).isTrue();
+ }
+
@Test
public void shouldDecorateIfThresholds() {
when(profile.getAlerts()).thenReturn(Arrays.asList(new Alert()));