summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-06-30 16:34:38 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-06-30 16:35:10 +0200
commitd44ef046f3dd7d59397c681cb79ebe3173d915bb (patch)
tree2851cb4dfd1c297e3e2cbdefb8b54d59f0ce06e0
parentef9b3e8704be8de9f30c42f9e8034588309f6e16 (diff)
downloadsonarqube-d44ef046f3dd7d59397c681cb79ebe3173d915bb.tar.gz
sonarqube-d44ef046f3dd7d59397c681cb79ebe3173d915bb.zip
Fix some quality flaws
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ManualMeasureDecorator.java7
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java9
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java12
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/DependencyPersister.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/AnalyzerContextAdaptor.java3
6 files changed, 29 insertions, 8 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ManualMeasureDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ManualMeasureDecorator.java
index 41c093c5994..1f9c5728c9d 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ManualMeasureDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ManualMeasureDecorator.java
@@ -24,6 +24,7 @@ import org.sonar.api.batch.DecoratorContext;
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;
@@ -56,7 +57,11 @@ public class ManualMeasureDecorator implements Decorator {
}
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());
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java
index 8c8a6b622bf..19d1dd93207 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java
@@ -107,7 +107,14 @@ public class VariationDecorator implements Decorator {
// 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();
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java
index ac107141bc3..b448c2ad076 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java
@@ -62,7 +62,7 @@ public final class Batch {
* @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;
@@ -105,6 +105,8 @@ public final class Batch {
}
bootstrapContainer.stopComponents();
+
+ this.started = false;
}
private void configureLogging() {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java
index 689b6a0e4cd..7eeb87ea4f9 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java
@@ -19,6 +19,8 @@
*/
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;
@@ -294,8 +296,9 @@ public final class DefaultResourcePersister implements ResourcePersister {
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());
@@ -327,8 +330,9 @@ public final class DefaultResourcePersister implements ResourcePersister {
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());
}
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DependencyPersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/DependencyPersister.java
index 514bbc9d3d4..e20680b10fc 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/DependencyPersister.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/DependencyPersister.java
@@ -38,7 +38,7 @@ public final class DependencyPersister {
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());
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/AnalyzerContextAdaptor.java b/sonar-batch/src/main/java/org/sonar/batch/scan/AnalyzerContextAdaptor.java
index bac550fd878..e1bf875059f 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/AnalyzerContextAdaptor.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/AnalyzerContextAdaptor.java
@@ -146,6 +146,9 @@ public class AnalyzerContextAdaptor implements AnalyzerContext {
@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()) {