]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4366 Remove Alert class and related code
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Thu, 13 Mar 2014 14:33:07 +0000 (15:33 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Thu, 13 Mar 2014 15:16:21 +0000 (16:16 +0100)
18 files changed:
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/GenerateAlertEvents.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/GenerateAlertEventsTest.java
sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileProvider.java
sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileWrapper.java
sonar-batch/src/test/java/org/sonar/batch/rule/RulesProfileProviderTest.java
sonar-core/src/main/java/org/sonar/core/persistence/PreviewDatabaseFactory.java
sonar-core/src/main/resources/META-INF/persistence.xml
sonar-core/src/test/java/org/sonar/core/persistence/PreviewDatabaseFactoryTest.java
sonar-plugin-api/src/main/java/org/sonar/api/profiles/Alert.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java
sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java
sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileSerializer.java
sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileParserTest.java
sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileSerializerTest.java
sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileParserTest/importProfileWithAlerts.xml [deleted file]
sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileSerializerTest/exportAlerts.xml [deleted file]
sonar-server/src/main/java/org/sonar/server/qualityprofile/ProfilesBackup.java
sonar-server/src/main/java/org/sonar/server/startup/RegisterMetrics.java

index 9fb6f2d732d4d335fed1c58c5672b28477f55a81..4d6a8550dbe99174b6ac9aa80eab0919f184c6e0 100644 (file)
@@ -36,21 +36,18 @@ 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, QualityGate qualityGate, TimeMachine timeMachine, NotificationManager notificationManager) {
-    this.profile = profile;
+  public GenerateAlertEvents(QualityGate qualityGate, TimeMachine timeMachine, NotificationManager notificationManager) {
     this.qualityGate = qualityGate;
     this.timeMachine = timeMachine;
     this.notificationManager = notificationManager;
   }
 
   public boolean shouldExecuteOnProject(Project project) {
-    return profile != null && profile.getAlerts() != null && !profile.getAlerts().isEmpty()
-      || qualityGate.isEnabled();
+    return qualityGate.isEnabled();
   }
 
   @DependsUpon
index 76649d6b4582fe43cad5cd72860e3fca7e76c8fb..8d6b8a10b229073f95e8fe042407b19104609cb1 100644 (file)
@@ -30,8 +30,6 @@ import org.sonar.api.measures.Measure;
 import org.sonar.api.measures.Metric;
 import org.sonar.api.notifications.Notification;
 import org.sonar.api.notifications.NotificationManager;
-import org.sonar.api.profiles.Alert;
-import org.sonar.api.profiles.RulesProfile;
 import org.sonar.api.resources.File;
 import org.sonar.api.resources.Project;
 import org.sonar.api.test.ProjectTestBuilder;
@@ -41,16 +39,12 @@ import java.util.Arrays;
 import java.util.Date;
 
 import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Matchers.isNull;
+import static org.mockito.Matchers.*;
 import static org.mockito.Mockito.*;
 
 public class GenerateAlertEventsTest {
   private GenerateAlertEvents decorator;
   private DecoratorContext context;
-  private RulesProfile profile;
   private QualityGate qualityGate;
   private TimeMachine timeMachine;
   private NotificationManager notificationManager;
@@ -60,10 +54,9 @@ public class GenerateAlertEventsTest {
   public void setup() {
     context = mock(DecoratorContext.class);
     timeMachine = mock(TimeMachine.class);
-    profile = mock(RulesProfile.class);
     qualityGate = mock(QualityGate.class);
     notificationManager = mock(NotificationManager.class);
-    decorator = new GenerateAlertEvents(profile, qualityGate, timeMachine, notificationManager);
+    decorator = new GenerateAlertEvents(qualityGate, timeMachine, notificationManager);
     project = new ProjectTestBuilder().build();
   }
 
@@ -83,12 +76,6 @@ public class GenerateAlertEventsTest {
     assertThat(decorator.shouldExecuteOnProject(project)).isTrue();
   }
 
-  @Test
-  public void shouldDecorateIfThresholds() {
-    when(profile.getAlerts()).thenReturn(Arrays.asList(new Alert()));
-    assertThat(decorator.shouldExecuteOnProject(project)).isTrue();
-  }
-
   @Test
   public void shouldNotDecorateIfNotRootProject() {
     decorator.decorate(new File("Foo"), context);
index a203e6056121616a722d0a80a9da33d37df37085..2e082bb32210070f67d1cd458ece592072c6b91c 100644 (file)
@@ -78,7 +78,6 @@ public class RulesProfileProvider extends ProviderAdapter {
       activeRule.getActiveRuleParams().size();
       activeRule.getRule().getParams().size();
     }
-    profile.getAlerts().size();
     return profile;
   }
 }
index 0b604aeb03556e452f8ba991785fbe49241913d7..0d8369734a62151afe9cca6ba6488ed5be7e6e40 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.batch.rule;
 import com.google.common.collect.Lists;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.sonar.api.profiles.Alert;
 import org.sonar.api.profiles.RulesProfile;
 import org.sonar.api.rules.ActiveRule;
 import org.sonar.api.rules.Rule;
@@ -94,15 +93,6 @@ public class RulesProfileWrapper extends RulesProfile {
     return null;
   }
 
-  @Override
-  public List<Alert> getAlerts() {
-    List<Alert> result = new ArrayList<Alert>();
-    for (RulesProfile profile : profiles) {
-      result.addAll(profile.getAlerts());
-    }
-    return result;
-  }
-
   @Override
   public List<ActiveRule> getActiveRules() {
     List<ActiveRule> activeRules = new ArrayList<ActiveRule>();
index 178f46355020e8b1f86eaf59fac686cc1355fe36..52e122ecbf550560ac34df08af684c9cdf75255a 100644 (file)
@@ -51,7 +51,6 @@ public class RulesProfileProviderTest {
     assertThat(profile).isNotNull().isInstanceOf(RulesProfileWrapper.class);
     assertThat(profile.getLanguage()).isEqualTo("");
     assertThat(profile.getName()).isEqualTo("SonarQube");
-    assertThat(profile.getAlerts()).isEmpty();
     assertThat(profile.getActiveRules()).isEmpty();
     try {
       profile.getId();
index f105c5b084d38b16dc6d1d047b5530a629edefe9..aa581189dee73380afa6edcd15c8a645e62c04d5 100644 (file)
@@ -95,7 +95,6 @@ public class PreviewDatabaseFactory implements ServerComponent {
       .copyTable(source, dest, "rules")
       .copyTable(source, dest, "rules_parameters")
       .copyTable(source, dest, "rules_profiles")
-      .copyTable(source, dest, "alerts")
       .copyTableColumns(source, dest, "users", new String[] {"id", "login", "name", "active"});
     if (projectId != null) {
       template.copyTable(source, dest, "projects", projectQuery(projectId, false));
index b51f8a6acb9e64c96223b73b4669429b1105a239..034e3dffd100c2ce9484b322e34aaa580645d147 100644 (file)
@@ -24,7 +24,6 @@
     <class>org.sonar.api.rules.ActiveRule</class>
     <class>org.sonar.api.rules.ActiveRuleParam</class>
     <class>org.sonar.api.batch.Event</class>
-    <class>org.sonar.api.profiles.Alert</class>
     <class>org.sonar.api.rules.ActiveRuleChange</class>
     <class>org.sonar.api.rules.ActiveRuleParamChange</class>
 
index 6e8c079c8e64d03b9eae6f0730c3e67f9705db24..8dc96b897c22aaf59853d87959c3bd176379ad01 100644 (file)
@@ -70,7 +70,6 @@ public class PreviewDatabaseFactoryTest extends AbstractDaoTestCase {
 
     assertThat(rowCount("metrics")).isEqualTo(2);
     assertThat(rowCount("projects")).isZero();
-    assertThat(rowCount("alerts")).isEqualTo(1);
     assertThat(rowCount("events")).isZero();
     assertThat(rowCount("users")).isEqualTo(3);
     // Verify that password column was not exported into dryRun DB
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/Alert.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/Alert.java
deleted file mode 100644 (file)
index 0de990c..0000000
+++ /dev/null
@@ -1,275 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.api.profiles;
-
-import org.hibernate.annotations.Cache;
-import org.hibernate.annotations.CacheConcurrencyStrategy;
-import org.sonar.api.database.BaseIdentifiable;
-import org.sonar.api.measures.Metric;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.Table;
-
-/**
- * Class to map alerts with hibernate model
- */
-@Entity
-@Table(name = "alerts")
-public class Alert extends BaseIdentifiable implements Cloneable {
-  /**
-   * Operator strictly greater than
-   */
-  public static final String OPERATOR_GREATER = ">";
-
-  /**
-   * Operator strictly lesser than
-   */
-  public static final String OPERATOR_SMALLER = "<";
-
-  /**
-   * Operator equals
-   */
-  public static final String OPERATOR_EQUALS = "=";
-
-  /**
-   * Operator not equals
-   */
-  public static final String OPERATOR_NOT_EQUALS = "!=";
-
-  @ManyToOne(fetch = FetchType.LAZY)
-  @JoinColumn(name = "profile_id")
-  @Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
-  private RulesProfile rulesProfile;
-
-  @ManyToOne(fetch = FetchType.EAGER)
-  @JoinColumn(name = "metric_id", nullable = true)
-  @Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
-  private Metric metric;
-
-  @Column(name = "operator", updatable = false, nullable = true, length = 3)
-  private String operator;
-
-  @Column(name = "value_error", updatable = false, nullable = true, length = 64)
-  private String valueError;
-
-  @Column(name = "value_warning", updatable = false, nullable = true, length = 64)
-  private String valueWarning;
-
-  @Column(name = "period", updatable = false, nullable = true)
-  private Integer period;
-
-  /**
-   * Default constructor
-   */
-  public Alert() {
-  }
-
-  /**
-   * Creates an alert
-   *
-   * @param rulesProfile the profile used to trigger the alert
-   * @param metric the metric tested for the alert
-   * @param operator the operator defined
-   * @param valueError the error value
-   * @param valueWarning the warning value
-   */
-  public Alert(RulesProfile rulesProfile, Metric metric, String operator, String valueError, String valueWarning) {
-    super();
-    this.rulesProfile = rulesProfile;
-    this.metric = metric;
-    this.operator = operator;
-    this.valueError = valueError;
-    this.valueWarning = valueWarning;
-  }
-
-  /**
-   * Creates an alert
-   *
-   * @param rulesProfile the profile used to trigger the alert
-   * @param metric the metric tested for the alert
-   * @param operator the operator defined
-   * @param valueError the error value
-   * @param valueWarning the warning value
-   */
-  public Alert(RulesProfile rulesProfile, Metric metric, String operator, String valueError, String valueWarning, Integer period) {
-    this(rulesProfile, metric, operator, valueError, valueWarning);
-    this.period = period;
-  }
-
-  /**
-   * @return the alert profile
-   */
-  public RulesProfile getRulesProfile() {
-    return rulesProfile;
-  }
-
-  /**
-   * Sets the alert profile
-   */
-  public void setRulesProfile(RulesProfile rulesProfile) {
-    this.rulesProfile = rulesProfile;
-  }
-
-  /**
-   * @return the alert metric
-   */
-  public Metric getMetric() {
-    return metric;
-  }
-
-  /**
-   * Sets the alert metric
-   */
-  public void setMetric(Metric metric) {
-    this.metric = metric;
-  }
-
-  /**
-   * @return the alert operator
-   */
-  public String getOperator() {
-    return operator;
-  }
-
-  /**
-   * Sets the alert operator
-   */
-  public void setOperator(String operator) {
-    this.operator = operator;
-  }
-
-  /**
-   * @return the error value
-   */
-  public String getValueError() {
-    return valueError;
-  }
-
-  /**
-   * Sets the error value if any
-   */
-  public void setValueError(String valueError) {
-    this.valueError = valueError;
-  }
-
-  /**
-   * @return the warning value
-   */
-  public String getValueWarning() {
-    return valueWarning;
-  }
-
-  /**
-   * Sets the warning value if any
-   */
-  public void setValueWarning(String valueWarning) {
-    this.valueWarning = valueWarning;
-  }
-
-  /**
-   * @return the period
-   */
-  public Integer getPeriod() {
-    return period;
-  }
-
-  /**
-   * Sets the period if any
-   */
-  public void setPeriod(Integer period) {
-    this.period = period;
-  }
-
-  /**
-   * @return whether the operator is greater than
-   */
-  public boolean isGreaterOperator() {
-    return operator.equals(OPERATOR_GREATER);
-  }
-
-  /**
-   * @return whether the operator is lesser than
-   */
-  public boolean isSmallerOperator() {
-    return operator.equals(OPERATOR_SMALLER);
-  }
-
-  /**
-   * @return whether the operator is equals
-   */
-  public boolean isEqualsOperator() {
-    return operator.equals(OPERATOR_EQUALS);
-  }
-
-  /**
-   * @return whether the operator is not equals
-   */
-  public boolean isNotEqualsOperator() {
-    return operator.equals(OPERATOR_NOT_EQUALS);
-  }
-
-  /**
-   * @deprecated since 3.4 because it does not manage alerts with variation
-   */
-  @Deprecated
-  public String getAlertLabel(Metric.Level level) {
-    return new StringBuilder()
-        .append(getMetric().getName())
-        .append(" ").append(getOperator())
-        .append(" ")
-        .append(level.equals(Metric.Level.ERROR) ? getValueError() : getValueWarning()).toString();
-  }
-
-  @Override
-  public Object clone() {
-    return new Alert(getRulesProfile(), getMetric(), getOperator(), getValueError(), getValueWarning(), getPeriod());
-  }
-
-  @Override
-  public boolean equals(Object o) {
-    if (this == o) {
-      return true;
-    }
-    if (o == null || getClass() != o.getClass()) {
-      return false;
-    }
-    Alert alert = (Alert) o;
-    if (metric != null ? !metric.equals(alert.metric) : alert.metric != null) {
-      return false;
-    }
-    if (period != null ? !period.equals(alert.period) : alert.period != null) {
-      return false;
-    }
-    return !(rulesProfile != null ? !rulesProfile.equals(alert.rulesProfile) : alert.rulesProfile != null);
-  }
-
-  @Override
-  public int hashCode() {
-    int result = rulesProfile != null ? rulesProfile.hashCode() : 0;
-    result = 31 * result + (metric != null ? metric.hashCode() : 0);
-    result = 31 * result + (period != null ? period.hashCode() : 0);
-    return result;
-  }
-}
index 3691d6792628efb4ffc9f36e2c0dc712b3218bcf..088235051b5b03be763ac662568358128c258559 100644 (file)
@@ -92,9 +92,6 @@ public class RulesProfile implements Cloneable {
   @OneToMany(mappedBy = "rulesProfile", fetch = FetchType.LAZY, cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE})
   private List<ActiveRule> activeRules = Lists.newArrayList();
 
-  @OneToMany(mappedBy = "rulesProfile", fetch = FetchType.LAZY, cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE})
-  private List<Alert> alerts = Lists.newArrayList();
-
   /**
    * @deprecated use the factory method create()
    */
@@ -110,7 +107,6 @@ public class RulesProfile implements Cloneable {
     this.name = name;
     this.language = language;
     this.activeRules = Lists.newArrayList();
-    this.alerts = Lists.newArrayList();
   }
 
   /**
@@ -287,20 +283,6 @@ public class RulesProfile implements Cloneable {
     this.parentName = parentName;
   }
 
-  /**
-   * @return the list of alerts defined in the profile
-   */
-  public List<Alert> getAlerts() {
-    return alerts;
-  }
-
-  /**
-   * Sets the list of alerts for the profile
-   */
-  public void setAlerts(List<Alert> alerts) {
-    this.alerts = alerts;
-  }
-
   /**
    * Note: disabled rules are excluded.
    *
@@ -425,13 +407,6 @@ public class RulesProfile implements Cloneable {
         }
       })));
     }
-    if (CollectionUtils.isNotEmpty(getAlerts())) {
-      clone.setAlerts(new ArrayList<Alert>(CollectionUtils.collect(getAlerts(), new Transformer() {
-        public Object transform(Object input) {
-          return ((Alert) input).clone();
-        }
-      })));
-    }
     return clone;
   }
 
index adb0bc1e9116f4ca6cdfa3218c751be49fd3cd6d..e22e9c2292a75b369cee42570925e77cf7b2381a 100644 (file)
@@ -26,13 +26,11 @@ import org.codehaus.staxmate.SMInputFactory;
 import org.codehaus.staxmate.in.SMHierarchicCursor;
 import org.codehaus.staxmate.in.SMInputCursor;
 import org.sonar.api.ServerComponent;
-import org.sonar.api.measures.Metric;
 import org.sonar.api.measures.MetricFinder;
 import org.sonar.api.rules.ActiveRule;
 import org.sonar.api.rules.Rule;
 import org.sonar.api.rules.RuleFinder;
 import org.sonar.api.rules.RulePriority;
-import org.sonar.api.utils.Logs;
 import org.sonar.api.utils.ValidationMessages;
 
 import javax.xml.stream.XMLInputFactory;
@@ -97,10 +95,6 @@ public class XMLProfileParser implements ServerComponent {
           SMInputCursor rulesCursor = cursor.childElementCursor("rule");
           processRules(rulesCursor, profile, messages);
 
-        } else if (StringUtils.equals("alerts", nodeName)) {
-          SMInputCursor alertsCursor = cursor.childElementCursor("alert");
-          processAlerts(alertsCursor, profile, messages);
-
         } else if (StringUtils.equals("name", nodeName)) {
           profile.setName(StringUtils.trim(cursor.collectDescendantText(false)));
 
@@ -202,48 +196,4 @@ public class XMLProfileParser implements ServerComponent {
     }
   }
 
-  private void processAlerts(SMInputCursor alertsCursor, RulesProfile profile, ValidationMessages messages) throws XMLStreamException {
-    if (metricFinder == null) {
-      // TODO remove when constructor without MetricFinder would be removed
-      Logs.INFO.error("Unable to parse alerts, because MetricFinder not available.");
-      return;
-    }
-    while (alertsCursor.getNext() != null) {
-      SMInputCursor alertCursor = alertsCursor.childElementCursor();
-
-      String metricKey = null, operator = "", valueError = "", valueWarning = "";
-      Integer period = null;
-
-      while (alertCursor.getNext() != null) {
-        String nodeName = alertCursor.getLocalName();
-
-        if (StringUtils.equals("metric", nodeName)) {
-          metricKey = StringUtils.trim(alertCursor.collectDescendantText(false));
-
-        } else if (StringUtils.equals("period", nodeName)) {
-          String periodParameter = StringUtils.trim(alertCursor.collectDescendantText(false));
-          if (StringUtils.isNotBlank(periodParameter)) {
-            period = Integer.parseInt(periodParameter);
-          }
-        } else if (StringUtils.equals("operator", nodeName)) {
-          operator = StringUtils.trim(alertCursor.collectDescendantText(false));
-
-        } else if (StringUtils.equals("warning", nodeName)) {
-          valueWarning = StringUtils.trim(alertCursor.collectDescendantText(false));
-
-        } else if (StringUtils.equals("error", nodeName)) {
-          valueError = StringUtils.trim(alertCursor.collectDescendantText(false));
-        }
-      }
-
-      Metric metric = metricFinder.findByKey(metricKey);
-      if (metric == null) {
-        messages.addWarningText("Metric '" + metricKey + "' does not exist");
-      } else {
-        Alert alert = new Alert(profile, metric, operator, valueError, valueWarning, period);
-        profile.getAlerts().add(alert);
-      }
-    }
-  }
-
 }
index 8e4721d814bf0061446ef10c9b38957cec7bf086..47822090414f8ab46eeec0e960f451dd07d11138 100644 (file)
@@ -38,7 +38,6 @@ public class XMLProfileSerializer implements ServerComponent {
     try {
       appendHeader(profile, writer);
       appendRules(profile, writer);
-      appendAlerts(profile, writer);
       appendFooter(writer);
 
     } catch (IOException e) {
@@ -102,36 +101,6 @@ public class XMLProfileSerializer implements ServerComponent {
     }
   }
 
-  private void appendAlerts(RulesProfile profile, Writer writer) throws IOException {
-    if (!profile.getAlerts().isEmpty()) {
-      writer.append("<alerts>");
-      for (Alert alert : profile.getAlerts()) {
-        appendAlert(alert, writer);
-      }
-      writer.append("</alerts>");
-    }
-  }
-
-  private void appendAlert(Alert alert, Writer writer) throws IOException {
-    writer.append("<alert><metric>");
-    StringEscapeUtils.escapeXml(writer, alert.getMetric().getKey());
-    writer.append("</metric>");
-    if (alert.getPeriod() !=null) {
-      writer.append("<period>");
-      StringEscapeUtils.escapeXml(writer, Integer.toString(alert.getPeriod()));
-      writer.append("</period>");
-    }
-    writer.append("<operator>");
-    StringEscapeUtils.escapeXml(writer, alert.getOperator());
-    writer.append("</operator>");
-    writer.append("<warning>");
-    StringEscapeUtils.escapeXml(writer, alert.getValueWarning());
-    writer.append("</warning>");
-    writer.append("<error>");
-    StringEscapeUtils.escapeXml(writer, alert.getValueError());
-    writer.append("</error></alert>");
-  }
-
   private void appendFooter(Writer writer) throws IOException {
     writer.append("</profile>");
   }
index 4b4173fa26249737a13a902a95afab95c928b7d0..7913751ccaa8b9098921ec7bd32e8393749d3cec 100644 (file)
@@ -82,37 +82,6 @@ public class XMLProfileParserTest {
     assertThat(rule.getParameter("unknown")).isNull();
   }
 
-  @Test
-  public void importProfileWithAlerts() {
-    ValidationMessages validation = ValidationMessages.create();
-    RulesProfile profile = parse("importProfileWithAlerts.xml", validation);
-
-    assertThat(profile.getAlerts()).hasSize(2);
-
-    Alert alert = profile.getAlerts().get(0);
-    assertThat(alert.getMetric().getKey()).isEqualTo("lines");
-    assertThat(alert.getOperator()).isEqualTo(Alert.OPERATOR_SMALLER);
-    assertThat(alert.getValueWarning()).isEqualTo("0");
-    assertThat(alert.getValueError()).isEqualTo("10");
-    assertThat(alert.getPeriod()).isNull();
-
-    alert = profile.getAlerts().get(1);
-    assertThat(alert.getMetric().getKey()).isEqualTo("complexity");
-    assertThat(alert.getOperator()).isEqualTo(Alert.OPERATOR_GREATER);
-    assertThat(alert.getValueWarning()).isEqualTo("10");
-    assertThat(alert.getValueError()).isEqualTo("12");
-    assertThat(alert.getPeriod()).isEqualTo(1);
-  }
-
-  @Test
-  public void shouldNotFailWhenNoMetricFinder() {
-    ValidationMessages validation = ValidationMessages.create();
-    RulesProfile profile = new XMLProfileParser(newRuleFinder(), null)
-        .parseResource(getClass().getClassLoader(), getResourcePath("importProfileWithAlerts.xml"), validation);
-
-    assertThat(profile.getAlerts()).isEmpty();
-  }
-
   private RulesProfile parse(String resource, ValidationMessages validation) {
     return new XMLProfileParser(newRuleFinder(), newMetricFinder())
         .parseResource(getClass().getClassLoader(), getResourcePath(resource), validation);
index 118ac0d54feab7996908a95982be112cf831dee3..2a96d5fedafc64256d7088c025f44ecbb31707d8 100644 (file)
@@ -77,20 +77,6 @@ public class XMLProfileSerializerTest {
     assertSimilarXml("exportRuleParameters.xml", writer.toString());
   }
 
-  @Test
-  public void exportAlerts() throws Exception {
-    Writer writer = new StringWriter();
-    RulesProfile profile = RulesProfile.create("sonar way", "java");
-    List<Alert> alerts = profile.getAlerts();
-    Alert alert1 = new Alert(profile, new Metric("coverage"), Alert.OPERATOR_SMALLER, "60", "80");
-    alerts.add(alert1);
-    Alert alert2 = new Alert(profile, new Metric("complexity"), Alert.OPERATOR_GREATER, "12", "10", 1);
-    alerts.add(alert2);
-    new XMLProfileSerializer().write(profile, writer);
-
-    assertSimilarXml("exportAlerts.xml", writer.toString());
-  }
-
   public static void assertSimilarXml(String fileWithExpectedXml, String xml) throws IOException, SAXException {
     String pathToExpectedXml = "/org/sonar/api/profiles/XMLProfileSerializerTest/" + fileWithExpectedXml;
     InputStream stream = XMLProfileSerializerTest.class.getResourceAsStream(pathToExpectedXml);
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileParserTest/importProfileWithAlerts.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileParserTest/importProfileWithAlerts.xml
deleted file mode 100644 (file)
index 523f237..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated by SonarQube -->
-<profile>
-  <name>sonar way</name>
-  <language>java</language>
-  <rules>
-    <rule>
-      <repositoryKey>checkstyle</repositoryKey>
-      <key>IllegalRegexp</key>
-      <priority>CRITICAL</priority>
-    </rule>
-  </rules>
-  <alerts>
-    <alert>
-      <metric>lines</metric>
-      <operator>&lt;</operator>
-      <warning>0</warning>
-      <error>10</error>
-    </alert>
-    <alert>
-      <metric>complexity</metric>
-      <period>1</period>
-      <operator>&gt;</operator>
-      <error>12</error>
-      <warning>10</warning>
-    </alert>
-  </alerts>
-</profile>
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileSerializerTest/exportAlerts.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileSerializerTest/exportAlerts.xml
deleted file mode 100644 (file)
index f64b493..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated by SonarQube -->
-<profile>
-  <name>sonar way</name>
-  <language>java</language>
-  <alerts>
-    <alert>
-      <metric>coverage</metric>
-      <operator>&lt;</operator>
-      <error>60</error>
-      <warning>80</warning>
-    </alert>
-    <alert>
-      <metric>complexity</metric>
-      <period>1</period>
-      <operator>&gt;</operator>
-      <error>12</error>
-      <warning>10</warning>
-    </alert>
-  </alerts>
-</profile>
index b6018cfd8f9363e899a251129f016c4a23dfbd79..2c62146be3587727b8053fd0ccb72a1c3ce35787 100644 (file)
@@ -25,11 +25,8 @@ import com.thoughtworks.xstream.converters.MarshallingContext;
 import com.thoughtworks.xstream.converters.UnmarshallingContext;
 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
-import org.apache.commons.lang.StringUtils;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.profiles.Alert;
 import org.sonar.api.profiles.RulesProfile;
 import org.sonar.api.rules.*;
 import org.sonar.core.preview.PreviewCache;
@@ -63,7 +60,6 @@ public class ProfilesBackup {
     String defaultProfile = "defaultProfile";
 
     xStream.alias("profile", RulesProfile.class);
-    xStream.alias("alert", Alert.class);
     xStream.alias("active-rule", ActiveRule.class);
     xStream.aliasField("active-rules", RulesProfile.class, "activeRules");
     xStream.aliasField("default-profile", RulesProfile.class, defaultProfile);
@@ -73,7 +69,6 @@ public class ProfilesBackup {
     xStream.omitField(RulesProfile.class, defaultProfile);
     xStream.omitField(RulesProfile.class, "enabled");
     xStream.registerConverter(getActiveRuleConverter());
-    xStream.registerConverter(getAlertsConverter());
   }
 
   public void importProfile(RulesDao rulesDao, RulesProfile toImport) {
@@ -86,29 +81,10 @@ public class ProfilesBackup {
       toImport.setUsed(false);
     }
     importActiveRules(rulesDao, toImport);
-    importAlerts(toImport);
     session.save(toImport);
     dryRunCache.reportGlobalModification();
   }
 
-  private void importAlerts(RulesProfile profile) {
-    if (profile.getAlerts() != null) {
-      for (Iterator<Alert> ia = profile.getAlerts().iterator(); ia.hasNext(); ) {
-        Alert alert = ia.next();
-        Metric unMarshalledMetric = alert.getMetric();
-        String validKey = unMarshalledMetric.getKey();
-        Metric matchingMetricInDb = session.getSingleResult(Metric.class, KEY, validKey);
-        if (matchingMetricInDb == null) {
-          LoggerFactory.getLogger(getClass()).error("Unable to find metric " + validKey);
-          ia.remove();
-          continue;
-        }
-        alert.setMetric(matchingMetricInDb);
-        alert.setRulesProfile(profile);
-      }
-    }
-  }
-
   private void importActiveRules(RulesDao rulesDao, RulesProfile profile) {
     for (Iterator<ActiveRule> iar = profile.getActiveRules(true).iterator(); iar.hasNext(); ) {
       ActiveRule activeRule = iar.next();
@@ -138,37 +114,6 @@ public class ProfilesBackup {
     }
   }
 
-  private Converter getAlertsConverter() {
-    return new Converter() {
-
-      public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
-        Alert alert = (Alert) source;
-        writeNode(writer, OPERATOR, alert.getOperator());
-        writeNode(writer, VALUE_ERROR, alert.getValueError());
-        writeNode(writer, VALUE_WARNING, alert.getValueWarning());
-        if (alert.getPeriod() != null) {
-          writeNode(writer, PERIOD, Integer.toString(alert.getPeriod()));
-        }
-        writeNode(writer, METRIC_KEY, alert.getMetric().getKey());
-      }
-
-      public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
-        Map<String, String> values = readNode(reader);
-        Alert alert = new Alert(null, new Metric(values.get(METRIC_KEY)), values.get(OPERATOR), values.get(VALUE_ERROR),
-          values.get(VALUE_WARNING));
-        String periodText = values.get(PERIOD);
-        if (StringUtils.isNotEmpty(periodText)) {
-          alert.setPeriod(Integer.parseInt(periodText));
-        }
-        return alert;
-      }
-
-      public boolean canConvert(Class type) {
-        return type.equals(Alert.class);
-      }
-    };
-  }
-
   private Converter getActiveRuleConverter() {
     return new Converter() {
 
index 5668b8e297edef4ba751a92c57d9c25d69c260d2..df5cda6489c2c602514c0635382e28780ded0264 100644 (file)
@@ -19,8 +19,6 @@
  */
 package org.sonar.server.startup;
 
-import org.sonar.core.qualitygate.db.QualityGateConditionDao;
-
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Predicate;
 import com.google.common.collect.Iterables;
@@ -31,12 +29,10 @@ import org.sonar.api.database.DatabaseSession;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.measures.Metric;
 import org.sonar.api.measures.Metrics;
-import org.sonar.api.profiles.Alert;
 import org.sonar.api.utils.TimeProfiler;
+import org.sonar.core.qualitygate.db.QualityGateConditionDao;
 import org.sonar.jpa.dao.MeasuresDao;
 
-import javax.persistence.Query;
-
 import java.util.List;
 import java.util.Map;