import org.sonar.api.resources.Resource;
import org.sonar.api.resources.ResourceUtils;
import org.sonar.api.rule.RuleKey;
-import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleFinder;
import org.sonar.api.rules.RulePriority;
import org.sonar.batch.components.Period;
}
for (RuleKey ruleKey : ruleKeys) {
- Rule rule = rulefinder.findByKey(ruleKey);
- RuleMeasure measure = RuleMeasure.createForRule(metric, rule, null);
+ RuleMeasure measure = RuleMeasure.createForRule(metric, ruleKey, null);
measure.setSeverity(severity);
for (Period period : timeMachineConfiguration.periods()) {
int variationIndex = period.getIndex();
- double sum = MeasureUtils.sumOnVariation(true, variationIndex, childMeasuresPerRuleKeys.get(rule.ruleKey())) + countIssues(issuesPerRuleKeys.get(rule.ruleKey()), period);
+ double sum = MeasureUtils.sumOnVariation(true, variationIndex, childMeasuresPerRuleKeys.get(ruleKey)) + countIssues(issuesPerRuleKeys.get(ruleKey), period);
measure.setVariation(variationIndex, sum);
}
context.saveMeasure(measure);
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.Scopes;
+import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleFinder;
import org.sonar.api.technicaldebt.batch.Characteristic;
import org.sonar.batch.components.PastMeasuresLoader;
import org.sonar.batch.components.PastSnapshot;
import org.sonar.batch.components.TimeMachineConfiguration;
+import javax.annotation.Nullable;
+
import java.util.Collection;
import java.util.List;
import java.util.Map;
Characteristic characteristic = measure.getCharacteristic();
Integer characteristicId = characteristic != null ? characteristic.id() : null;
Integer personId = measure.getPersonId();
- Integer ruleId = measure instanceof RuleMeasure ? ruleFinder.findByKey(((RuleMeasure) measure).ruleKey()).getId() : null;
+ Integer ruleId = null;
+ if (measure instanceof RuleMeasure) {
+ Rule rule = ruleFinder.findByKey(((RuleMeasure) measure).ruleKey());
+ if (rule != null) {
+ ruleId = rule.getId();
+ }
+ }
Object[] pastMeasure = pastMeasuresByKey.get(new MeasureKey(metricId, characteristicId, personId, ruleId));
if (updateVariation(measure, pastMeasure, index)) {
ruleId = PastMeasuresLoader.getRuleId(pastFields);
}
- MeasureKey(int metricId, Integer characteristicId, Integer personId, Integer ruleId) {
+ MeasureKey(int metricId, Integer characteristicId, Integer personId, @Nullable Integer ruleId) {
this.metricId = metricId;
this.characteristicId = characteristicId;
this.personId = personId;
KeyFilter filter = new KeyFilter().append(KeyFilter.simpleTerm(firstKey)).append(KeyFilter.simpleTerm(secondKey));
return new ValueIterable<V>(iteratorExchange, filter);
} catch (Exception e) {
- throw new IllegalStateException("Fail to get values from cache " + name, e);
+ throw failToGetValues(e);
}
}
+ private IllegalStateException failToGetValues(Exception e) {
+ return new IllegalStateException("Fail to get values from cache " + name, e);
+ }
+
/**
* Lazy-loading values for a given key
*/
KeyFilter filter = new KeyFilter().append(KeyFilter.simpleTerm(firstKey));
return new ValueIterable<V>(iteratorExchange, filter);
} catch (Exception e) {
- throw new IllegalStateException("Fail to get values from cache " + name, e);
+ throw failToGetValues(e);
}
}
KeyFilter filter = new KeyFilter().append(KeyFilter.ALL);
return new ValueIterable<V>(iteratorExchange, filter);
} catch (Exception e) {
- throw new IllegalStateException("Fail to get values from cache " + name, e);
+ throw failToGetValues(e);
}
}
public <M> M getMeasures(Resource resource, MeasuresFilter<M> filter) {
// Reload resource so that effective key is populated
Resource indexedResource = getResource(resource);
+ if (indexedResource == null) {
+ throw new IllegalStateException("Resource is not indexed " + resource);
+ }
Iterable<Measure> unfiltered;
if (filter instanceof MeasuresFilters.MetricFilter) {
// optimization
import org.sonar.api.measures.MetricFinder;
import org.sonar.api.measures.RuleMeasure;
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.Cache;
import org.sonar.batch.index.Cache.Entry;
sb.append(m.getMetricKey());
}
sb.append("|");
- if (m.getCharacteristic() != null) {
- sb.append(m.getCharacteristic().key());
+ Characteristic characteristic = m.getCharacteristic();
+ if (characteristic != null) {
+ sb.append(characteristic.key());
}
sb.append("|");
- if (m.getPersonId() != null) {
- sb.append(m.getPersonId());
+ Integer personId = m.getPersonId();
+ if (personId != null) {
+ sb.append(personId);
}
if (m instanceof RuleMeasure) {
sb.append("|");
/**
* @since 2.14
*/
+ @CheckForNull
@Beta
public Integer getPersonId() {
return personId;
public Row load(ResultSet rs) throws SQLException {
Row row = new Row();
row.id = SqlUtil.getLong(rs, 1);
- row.measure_id = SqlUtil.getLong(rs, 2);
+ row.measureId = SqlUtil.getLong(rs, 2);
return row;
}
},
public boolean convert(Row row, PreparedStatement updateStatement) throws SQLException {
ids.add(row.id);
updateStatement.setLong(1, row.id);
- updateStatement.setLong(2, row.measure_id);
+ updateStatement.setLong(2, row.measureId);
return true;
}
},
private static class Row {
private Long id;
- private Long measure_id;
+ private Long measureId;
}
}