]> source.dussan.org Git - sonarqube.git/commitdiff
Drop support of org.sonar.api.batch.TimeMachine
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 12 Jun 2015 16:01:10 +0000 (18:01 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 12 Jun 2015 16:01:10 +0000 (18:01 +0200)
It can't be supported anymore by design. Analyzers do not connect to database anymore.

sonar-batch/src/main/java/org/sonar/batch/deprecated/components/DefaultTimeMachine.java [deleted file]
sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/TimeMachine.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/TimeMachineQuery.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/batch/TimeMachineQueryTest.java [deleted file]

diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/DefaultTimeMachine.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/DefaultTimeMachine.java
deleted file mode 100644 (file)
index 2cd1898..0000000
+++ /dev/null
@@ -1,168 +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.batch.deprecated.components;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import javax.annotation.Nullable;
-import javax.persistence.Query;
-import org.sonar.api.batch.TimeMachine;
-import org.sonar.api.batch.TimeMachineQuery;
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.database.model.MeasureModel;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.measures.MetricFinder;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.technicaldebt.batch.Characteristic;
-import org.sonar.api.technicaldebt.batch.TechnicalDebtModel;
-import org.sonar.batch.index.DefaultIndex;
-
-import static org.sonar.api.utils.DateUtils.dateToLong;
-
-public class DefaultTimeMachine implements TimeMachine {
-
-  private DatabaseSession session;
-  private DefaultIndex index;
-  private MetricFinder metricFinder;
-  private TechnicalDebtModel techDebtModel;
-
-  public DefaultTimeMachine(DatabaseSession session, DefaultIndex index, MetricFinder metricFinder, TechnicalDebtModel techDebtModel) {
-    this.session = session;
-    this.index = index;
-    this.metricFinder = metricFinder;
-    this.techDebtModel = techDebtModel;
-  }
-
-  @Override
-  public List<Measure> getMeasures(TimeMachineQuery query) {
-    Map<Integer, Metric> metricById = getMetricsById(query);
-
-    List<Object[]> objects = execute(query, metricById.keySet());
-    List<Measure> result = Lists.newArrayList();
-
-    for (Object[] object : objects) {
-      MeasureModel model = (MeasureModel) object[0];
-      Integer characteristicId = model.getCharacteristicId();
-      Characteristic characteristic = techDebtModel.characteristicById(characteristicId);
-      Measure measure = toMeasure(model, metricById.get(model.getMetricId()), characteristic);
-      measure.setDate(new Date((Long) object[1]));
-      result.add(measure);
-    }
-    return result;
-  }
-
-  @Override
-  public List<Object[]> getMeasuresFields(TimeMachineQuery query) {
-    return Collections.emptyList();
-  }
-
-  protected List<Object[]> execute(TimeMachineQuery query, Set<Integer> metricIds) {
-    Resource resource = query.getResource();
-    if (resource != null && resource.getId() == null) {
-      resource = index.getResource(query.getResource());
-    }
-    if (resource == null) {
-      return Collections.emptyList();
-    }
-
-    StringBuilder sb = new StringBuilder();
-    Map<String, Object> params = Maps.newHashMap();
-
-    sb.append("SELECT m, s.createdAt ");
-    sb.append(" FROM ")
-      .append(MeasureModel.class.getSimpleName())
-      .append(" m, ")
-      .append(Snapshot.class.getSimpleName())
-      .append(" s WHERE m.snapshotId=s.id AND s.resourceId=:resourceId AND s.status=:status");
-    params.put("resourceId", resource.getId());
-    params.put("status", Snapshot.STATUS_PROCESSED);
-
-    sb.append(" AND m.characteristicId IS NULL");
-    sb.append(" AND m.personId IS NULL");
-    sb.append(" AND m.ruleId IS NULL AND m.rulePriority IS NULL");
-    if (!metricIds.isEmpty()) {
-      sb.append(" AND m.metricId IN (:metricIds) ");
-      params.put("metricIds", metricIds);
-    }
-    if (query.isFromCurrentAnalysis()) {
-      sb.append(" AND s.createdAt>=:from ");
-      params.put("from", index.getProject().getAnalysisDate());
-
-    } else if (query.getFrom() != null) {
-      sb.append(" AND s.createdAt>=:from ");
-      params.put("from", dateToLong(query.getFrom()));
-    }
-    if (query.isToCurrentAnalysis()) {
-      sb.append(" AND s.createdAt<=:to ");
-      params.put("to", dateToLong(index.getProject().getAnalysisDate()));
-
-    } else if (query.getTo() != null) {
-      sb.append(" AND s.createdAt<=:to ");
-      params.put("to", dateToLong(query.getTo()));
-    }
-    if (query.isOnlyLastAnalysis()) {
-      sb.append(" AND s.last=:last ");
-      params.put("last", Boolean.TRUE);
-    }
-    sb.append(" ORDER BY s.createdAt ");
-
-    Query jpaQuery = session.createQuery(sb.toString());
-
-    for (Map.Entry<String, Object> entry : params.entrySet()) {
-      jpaQuery.setParameter(entry.getKey(), entry.getValue());
-    }
-    return jpaQuery.getResultList();
-  }
-
-  public Map<Integer, Metric> getMetricsById(TimeMachineQuery query) {
-    Collection<Metric> metrics = metricFinder.findAll(query.getMetricKeys());
-    Map<Integer, Metric> result = Maps.newHashMap();
-    for (Metric metric : metrics) {
-      result.put(metric.getId(), metric);
-    }
-    return result;
-  }
-
-  static Measure toMeasure(MeasureModel model, Metric metric, @Nullable Characteristic characteristic) {
-    // NOTE: measures on rule are not supported
-    Measure measure = new Measure(metric);
-    measure.setDescription(model.getDescription());
-    measure.setValue(model.getValue());
-    measure.setData(model.getData(metric));
-    measure.setAlertStatus(model.getAlertStatus());
-    measure.setAlertText(model.getAlertText());
-    measure.setVariation1(model.getVariationValue1());
-    measure.setVariation2(model.getVariationValue2());
-    measure.setVariation3(model.getVariationValue3());
-    measure.setVariation4(model.getVariationValue4());
-    measure.setVariation5(model.getVariationValue5());
-    measure.setCharacteristic(characteristic);
-    measure.setPersonId(model.getPersonId());
-    return measure;
-  }
-}
index 1809108f70fff77e395f881d2f3fecc08dcd95fa..4d4fb03fff9bc136859cb64266458a76adecf3a0 100644 (file)
@@ -36,7 +36,6 @@ import org.sonar.batch.bootstrap.ExtensionMatcher;
 import org.sonar.batch.bootstrap.ExtensionUtils;
 import org.sonar.batch.deprecated.DeprecatedSensorContext;
 import org.sonar.batch.deprecated.ResourceFilters;
-import org.sonar.batch.deprecated.components.DefaultTimeMachine;
 import org.sonar.batch.deprecated.perspectives.BatchPerspectives;
 import org.sonar.batch.events.EventBus;
 import org.sonar.batch.index.DefaultIndex;
@@ -153,7 +152,6 @@ public class ModuleScanContainer extends ComponentContainer {
       DefaultSensorStorage.class,
       DeprecatedSensorContext.class,
       BatchExtensionDictionnary.class,
-      DefaultTimeMachine.class,
       IssueFilters.class,
       CoverageExclusions.class,
       ResourceFilters.class,
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/TimeMachine.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/TimeMachine.java
deleted file mode 100644 (file)
index 4183d18..0000000
+++ /dev/null
@@ -1,49 +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.batch;
-
-import org.sonar.api.measures.Measure;
-
-import java.util.List;
-
-/**
- * The TimeMachine component
- *
- * @since 1.10
- * @deprecated since 5.1 ability to access previous data from batch side will soon be removed
- */
-@Deprecated
-@RequiresDB
-@BatchSide
-public interface TimeMachine {
-
-  /**
-   * Past measures, sorted by date. Returns all fields.
-   * <p/>
-   * <p>Measures of current analysis are not included.</p>
-   */
-  List<Measure> getMeasures(TimeMachineQuery query);
-
-  /**
-   * Return an empty list since 5.2. See https://jira.sonarsource.com/browse/SONAR-6392
-   */
-  List<Object[]> getMeasuresFields(TimeMachineQuery query);
-
-}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/TimeMachineQuery.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/TimeMachineQuery.java
deleted file mode 100644 (file)
index e4d5482..0000000
+++ /dev/null
@@ -1,234 +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.batch;
-
-import org.apache.commons.lang.builder.ToStringBuilder;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.resources.Resource;
-
-import java.util.Arrays;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * A class to query TimeMachine on a given resource
- * <p/>
- * <p>The query is constructed by setting filters on metrics and on dates</p>
- * <p>It is to be noted that all filters will be applied regardless of their coherence</p>
- *
- * @since 1.10
- */
-public class TimeMachineQuery {
-
-  private Resource resource;
-  private List<Metric> metrics;
-  private List<String> metricKeys;
-  private Date from;
-  private Date to;
-  private boolean onlyLastAnalysis = false;
-  private boolean fromCurrentAnalysis = false;
-  private boolean toCurrentAnalysis = false;
-
-  /**
-   * <p>Create a TimeMachine query for a given resource
-   * </p>
-   * Apart from the resource the query is empty, i.e. will return all data for the resource
-   *
-   * @param resource the resource
-   */
-  public TimeMachineQuery(Resource resource) {
-    this.resource = resource;
-  }
-
-  /**
-   * @return the resource of the Query
-   */
-  public Resource getResource() {
-    return resource;
-  }
-
-  /**
-   * Sets the resource of the query
-   *
-   * @param resource the resource
-   * @return this
-   */
-  public TimeMachineQuery setResource(Resource resource) {
-    this.resource = resource;
-    return this;
-  }
-
-  /**
-   * @return the metrics beloging to the query
-   */
-  public List<Metric> getMetrics() {
-    return metrics;
-  }
-
-  /**
-   * Sets the metrics to return
-   *
-   * @param metrics the list of metrics
-   * @return this
-   */
-  public TimeMachineQuery setMetrics(List<Metric> metrics) {
-    this.metrics = metrics;
-    this.metricKeys = new LinkedList<>();
-    for (Metric metric : this.metrics) {
-      this.metricKeys.add(metric.getKey());
-    }
-    return this;
-  }
-
-  public TimeMachineQuery setMetricKeys(String... metricKeys) {
-    this.metricKeys = Arrays.asList(metricKeys);
-    return this;
-  }
-
-  public List<String> getMetricKeys() {
-    return metricKeys;
-  }
-
-  public TimeMachineQuery setMetricKeys(List<String> metricKeys) {
-    this.metricKeys = metricKeys;
-    return this;
-  }
-
-  /**
-   * Sets the metrics to return
-   *
-   * @param metrics the list of metrics
-   * @return this
-   */
-  public TimeMachineQuery setMetrics(Metric... metrics) {
-    this.metrics = Arrays.asList(metrics);
-    this.metricKeys = new LinkedList<>();
-    for (Metric metric : this.metrics) {
-      this.metricKeys.add(metric.getKey());
-    }
-    return this;
-  }
-
-  /**
-   * Unsets the metrics
-   *
-   * @return this
-   */
-  public TimeMachineQuery unsetMetrics() {
-    this.metrics = null;
-    return this;
-  }
-
-  /**
-   * @return the from date of the query
-   */
-  public Date getFrom() {
-    return from;
-  }
-
-  /**
-   * Sets the from date to be used in the query
-   *
-   * @param from the from date
-   * @return this
-   */
-  public TimeMachineQuery setFrom(Date from) {
-    this.from = from;
-    return this;
-  }
-
-  /**
-   * @param b whether to use the latest analysis as a from date
-   * @return this
-   */
-  public TimeMachineQuery setFromCurrentAnalysis(boolean b) {
-    this.fromCurrentAnalysis = b;
-    return this;
-  }
-
-  /**
-   * @param b whether to use the latest analysis as a to date
-   * @return this
-   */
-  public TimeMachineQuery setToCurrentAnalysis(boolean b) {
-    this.toCurrentAnalysis = b;
-    return this;
-  }
-
-  /**
-   * @return whether the latest analysis is used as a from date
-   */
-  public boolean isFromCurrentAnalysis() {
-    return fromCurrentAnalysis;
-  }
-
-  /**
-   * @return whether the latest analysis is used as a to date
-   */
-  public boolean isToCurrentAnalysis() {
-    return toCurrentAnalysis;
-  }
-
-  /**
-   * @return the to date of the query
-   */
-  public Date getTo() {
-    return to;
-  }
-
-  /**
-   * Sets the to date to be used in the query
-   *
-   * @param to the to date
-   * @return this
-   */
-  public TimeMachineQuery setTo(Date to) {
-    this.to = to;
-    return this;
-  }
-
-  /**
-   * @return whether to return only the latest analysis
-   */
-  public boolean isOnlyLastAnalysis() {
-    return onlyLastAnalysis;
-  }
-
-  /**
-   *
-   * @param onlyLastAnalysis whether to only return the latest analysis
-   * @return this
-   */
-  public TimeMachineQuery setOnlyLastAnalysis(boolean onlyLastAnalysis) {
-    this.onlyLastAnalysis = onlyLastAnalysis;
-    return this;
-  }
-
-  @Override
-  public String toString() {
-    return new ToStringBuilder(this)
-      .append("resource", resource)
-      .append("metrics", metrics)
-      .append("from", from)
-      .append("to", to)
-      .toString();
-  }
-}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/TimeMachineQueryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/TimeMachineQueryTest.java
deleted file mode 100644 (file)
index 9599f16..0000000
+++ /dev/null
@@ -1,43 +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.batch;
-
-import org.junit.Test;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Metric;
-
-import java.util.Arrays;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class TimeMachineQueryTest {
-
-  @Test
-  public void setNullMetrics() {
-    TimeMachineQuery query = new TimeMachineQuery(null).setMetrics(Arrays.<Metric>asList(CoreMetrics.LINES));
-    assertThat(query.getMetrics()).contains(CoreMetrics.LINES);
-
-    query.unsetMetrics();
-    assertThat(query.getMetrics()).isNull();
-
-    query.setMetrics(CoreMetrics.LINES, CoreMetrics.COVERAGE);
-    assertThat(query.getMetrics()).contains(CoreMetrics.LINES, CoreMetrics.COVERAGE);
-  }
-}