import org.sonar.api.measures.Measure;
import org.sonar.api.measures.Metric;
import org.sonar.api.measures.MetricFinder;
+import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.batch.index.DefaultIndex;
} else {
sb.append("SELECT s.createdAt, m.metricId, m.value ");
}
- sb.append(" FROM " + MeasureModel.class.getSimpleName() + " m, " + Snapshot.class.getSimpleName() + " s WHERE m.snapshotId=s.id AND s.resourceId=:resourceId AND s.status=:status AND m.characteristic IS NULL ");
+ sb.append(" FROM " + MeasureModel.class.getSimpleName() + " m, " + Snapshot.class.getSimpleName() + " s WHERE m.snapshotId=s.id AND s.resourceId=:resourceId AND s.status=:status AND m.characteristic IS NULL AND s.qualifier<>:lib");
params.put("resourceId", resource.getId());
params.put("status", Snapshot.STATUS_PROCESSED);
+ params.put("lib", Project.QUALIFIER_LIB);
sb.append(" AND m.ruleId IS NULL AND m.rulePriority IS NULL ");
if (!metricIds.isEmpty()) {
import org.sonar.api.BatchExtension;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
+import org.sonar.api.resources.Project;
import java.text.SimpleDateFormat;
import java.util.Date;
}
PastSnapshot findByDate(Snapshot projectSnapshot, Date date) {
- String hql = "from " + Snapshot.class.getSimpleName() + " where createdAt>=:date AND resourceId=:resourceId AND status=:status order by createdAt asc";
+ String hql = "from " + Snapshot.class.getSimpleName() + " where createdAt>=:date AND resourceId=:resourceId AND status=:status AND qualifier<>:lib order by createdAt asc";
List<Snapshot> snapshots = session.createQuery(hql)
.setParameter("date", date)
.setParameter("resourceId", projectSnapshot.getResourceId())
.setParameter("status", Snapshot.STATUS_PROCESSED)
+ .setParameter("lib", Project.QUALIFIER_LIB)
.setMaxResults(1)
.getResultList();
if (snapshots.isEmpty()) {
import org.sonar.api.BatchExtension;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
+import org.sonar.api.resources.Project;
import java.util.Date;
import java.util.List;
PastSnapshot findFromDays(Snapshot projectSnapshot, int days) {
Date targetDate = DateUtils.addDays(projectSnapshot.getCreatedAt(), -days);
- String hql = "from " + Snapshot.class.getSimpleName() + " where resourceId=:resourceId AND status=:status AND createdAt<:date order by createdAt asc";
+ String hql = "from " + Snapshot.class.getSimpleName() + " where resourceId=:resourceId AND status=:status AND createdAt<:date AND qualifier<>:lib order by createdAt asc";
List<Snapshot> snapshots = session.createQuery(hql)
.setParameter("date", projectSnapshot.getCreatedAt())
.setParameter("resourceId", projectSnapshot.getResourceId())
.setParameter("status", Snapshot.STATUS_PROCESSED)
+ .setParameter("lib", Project.QUALIFIER_LIB)
.getResultList();
if (snapshots.isEmpty()) {
import org.sonar.api.CoreProperties;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
+import org.sonar.api.resources.Project;
import java.text.SimpleDateFormat;
import java.util.List;
}
PastSnapshot findByPreviousAnalysis(Snapshot projectSnapshot) {
- String hql = "from " + Snapshot.class.getSimpleName() + " where createdAt<:date AND resourceId=:resourceId AND status=:status and last=true order by createdAt desc";
+ String hql = "from " + Snapshot.class.getSimpleName() + " where createdAt<:date AND resourceId=:resourceId AND status=:status and last=:last and qualifier<>:lib order by createdAt desc";
List<Snapshot> snapshots = session.createQuery(hql)
.setParameter("date", projectSnapshot.getCreatedAt())
.setParameter("resourceId", projectSnapshot.getResourceId())
.setParameter("status", Snapshot.STATUS_PROCESSED)
+ .setParameter("last", true)
+ .setParameter("lib", Project.QUALIFIER_LIB)
.setMaxResults(1)
.getResultList();
import org.sonar.api.BatchExtension;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
+import org.sonar.api.resources.Project;
import java.util.List;
}
PastSnapshot findByVersion(Snapshot projectSnapshot, String version) {
- String hql = "from " + Snapshot.class.getSimpleName() + " where version=:version AND resourceId=:resourceId AND status=:status order by createdAt desc";
+ String hql = "from " + Snapshot.class.getSimpleName() + " where version=:version AND resourceId=:resourceId AND status=:status AND qualifier<>:lib order by createdAt desc";
List<Snapshot> snapshots = session.createQuery(hql)
.setParameter("version", version)
.setParameter("resourceId", projectSnapshot.getResourceId())
.setParameter("status", Snapshot.STATUS_PROCESSED)
+ .setParameter("lib", Project.QUALIFIER_LIB)
.setMaxResults(1)
.getResultList();