import org.sonar.api.batch.Phase;
import org.sonar.api.database.DatabaseSession;
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;
}
private Measure copy(ManualMeasure manualMeasure) {
- Measure measure = new Measure(metricFinder.findById(manualMeasure.getMetricId()));
+ Metric metric = metricFinder.findById(manualMeasure.getMetricId());
+ if (metric == null) {
+ throw new IllegalStateException("Unable to find manual metric with id: " + manualMeasure.getMetricId());
+ }
+ Measure measure = new Measure(metric);
measure.setValue(manualMeasure.getValue(), 5);
measure.setData(manualMeasure.getTextValue());
measure.setDescription(manualMeasure.getDescription());
// for each measure, search equivalent past measure
for (Measure measure : context.getMeasures(MeasuresFilters.all())) {
// compare with past measure
- Integer metricId = measure.getMetric().getId() != null ? measure.getMetric().getId() : metricFinder.findByKey(measure.getMetric().getKey()).getId();
+ Integer metricId = measure.getMetric().getId();
+ if (metricId == null) {
+ Metric metric = metricFinder.findByKey(measure.getMetric().getKey());
+ if (metric == null) {
+ throw new IllegalStateException("Unknow metric with key: " + measure.getMetric().getKey());
+ }
+ metricId = metric.getId();
+ }
Characteristic characteristic = measure.getCharacteristic();
Integer characteristicId = characteristic != null ? characteristic.id() : null;
Integer personId = measure.getPersonId();
* @deprecated since 4.4 use {@link #start()}, {@link #executeTask(Map)} and then {@link #stop()}
*/
@Deprecated
- public Batch execute() {
+ public synchronized Batch execute() {
configureLogging();
start().executeTask(bootstrapProperties).stop();
return this;
}
bootstrapContainer.stopComponents();
+
+ this.started = false;
}
private void configureLogging() {
*/
package org.sonar.batch.index;
+import org.sonar.api.resources.Language;
+
import com.google.common.collect.Maps;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
model.setDescription(resource.getDescription());
model.setKey(resource.getEffectiveKey());
model.setPath(resource.getPath());
- if (resource.getLanguage() != null) {
- model.setLanguageKey(resource.getLanguage().getKey());
+ Language language = resource.getLanguage();
+ if (language != null) {
+ model.setLanguageKey(language.getKey());
}
if (StringUtils.isNotBlank(resource.getName())) {
model.setName(resource.getName());
model.setScope(resource.getScope());
model.setQualifier(resource.getQualifier());
}
- if (resource.getLanguage() != null) {
- model.setLanguageKey(resource.getLanguage().getKey());
+ Language language = resource.getLanguage();
+ if (language != null) {
+ model.setLanguageKey(language.getKey());
}
}
}
public void saveDependency(Project project, Dependency dependency, Dependency parentDependency) {
Snapshot fromSnapshot = resourcePersister.saveResource(project, dependency.getFrom());
Snapshot toSnapshot = resourcePersister.saveResource(project, dependency.getTo());
- Snapshot projectSnapshot = resourcePersister.getSnapshot(project);
+ Snapshot projectSnapshot = resourcePersister.getSnapshotOrFail(project);
DependencyDto model = new DependencyDto();
model.setProjectSnapshotId(projectSnapshot.getId());
@Override
public void addMeasure(AnalyzerMeasure<?> measure) {
org.sonar.api.measures.Metric<?> m = metricFinder.findByKey(measure.metric().key());
+ if (m == null) {
+ throw new IllegalStateException("Unknow metric with key: " + measure.metric().key());
+ }
Measure measureToSave = new Measure(m);
switch (m.getType()) {