diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2013-01-14 18:30:18 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2013-01-14 18:31:18 +0100 |
commit | 5d39faf6f9ed9b2951044060ecd1602cd8931eec (patch) | |
tree | 44e7e9970861ace6cc490525f072e603180d7552 /sonar-batch/src/main | |
parent | 119b927a38df901bfc0d3e97c47b517cdb9f21a3 (diff) | |
download | sonarqube-5d39faf6f9ed9b2951044060ecd1602cd8931eec.tar.gz sonarqube-5d39faf6f9ed9b2951044060ecd1602cd8931eec.zip |
SONAR-4069 Fix issue with decorators dynamically created for metrics with formula
Diffstat (limited to 'sonar-batch/src/main')
5 files changed, 23 insertions, 16 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/DecoratorsSelector.java b/sonar-batch/src/main/java/org/sonar/batch/DecoratorsSelector.java index 645cd938603..b96e0d648da 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/DecoratorsSelector.java +++ b/sonar-batch/src/main/java/org/sonar/batch/DecoratorsSelector.java @@ -23,35 +23,40 @@ import com.google.common.collect.HashMultimap; import com.google.common.collect.SetMultimap; import org.sonar.api.batch.BatchExtensionDictionnary; import org.sonar.api.batch.Decorator; +import org.sonar.api.batch.TaskExtensionDictionnary; import org.sonar.api.measures.Metric; import org.sonar.api.resources.Project; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; public final class DecoratorsSelector { - private BatchExtensionDictionnary dictionnary; + private BatchExtensionDictionnary batchExtDictionnary; + private TaskExtensionDictionnary taskExtDictionnary; - public DecoratorsSelector(BatchExtensionDictionnary dictionnary) { - this.dictionnary = dictionnary; + public DecoratorsSelector(TaskExtensionDictionnary taskExtDictionnary, BatchExtensionDictionnary dictionnary) { + this.taskExtDictionnary = taskExtDictionnary; + this.batchExtDictionnary = dictionnary; } public Collection<Decorator> select(Project project) { - List<Decorator> decorators = new ArrayList<Decorator>(dictionnary.select(Decorator.class, project, false)); + List<Decorator> decorators = new ArrayList<Decorator>(batchExtDictionnary.select(Decorator.class, project, false)); SetMultimap<Metric, Decorator> decoratorsByGeneratedMetric = getDecoratorsByMetric(decorators); - for (Metric metric : dictionnary.select(Metric.class)) { + for (Metric metric : taskExtDictionnary.select(Metric.class)) { if (metric.getFormula() != null) { decorators.add(new FormulaDecorator(metric, decoratorsByGeneratedMetric.get(metric))); } } - return dictionnary.sort(decorators); + return batchExtDictionnary.sort(decorators); } private SetMultimap<Metric, Decorator> getDecoratorsByMetric(Collection<Decorator> pluginDecorators) { SetMultimap<Metric, Decorator> decoratorsByGeneratedMetric = HashMultimap.create(); for (Decorator decorator : pluginDecorators) { - List dependents = dictionnary.getDependents(decorator); + List dependents = batchExtDictionnary.getDependents(decorator); for (Object dependent : dependents) { if (dependent instanceof Metric) { decoratorsByGeneratedMetric.put((Metric) dependent, decorator); diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/AbstractTaskModule.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/AbstractTaskModule.java index 86199c7780d..651d24ef9b9 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/AbstractTaskModule.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/AbstractTaskModule.java @@ -22,6 +22,7 @@ package org.sonar.batch.bootstrap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.batch.TaskDefinition; +import org.sonar.api.batch.TaskExtensionDictionnary; import org.sonar.api.config.EmailSettings; import org.sonar.api.resources.ResourceTypes; import org.sonar.batch.DefaultResourceCreationLock; @@ -108,6 +109,7 @@ public abstract class AbstractTaskModule extends Module { container.addSingleton(ResourceTypes.class); container.addSingleton(MetricProvider.class); container.addSingleton(SemaphoresImpl.class); + container.addSingleton(TaskExtensionDictionnary.class); } private void registerDatabaseComponents() { diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/MetricProvider.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/MetricProvider.java index 139b1f73df1..0cf3af16bc2 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/MetricProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/MetricProvider.java @@ -21,17 +21,15 @@ package org.sonar.batch.bootstrap; import com.google.common.collect.Lists; import org.slf4j.LoggerFactory; -import org.sonar.api.BatchExtension; import org.sonar.api.ExtensionProvider; -import org.sonar.api.batch.InstantiationStrategy; +import org.sonar.api.TaskExtension; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Metric; import org.sonar.api.measures.Metrics; import java.util.List; -@InstantiationStrategy(InstantiationStrategy.PER_BATCH) -public class MetricProvider extends ExtensionProvider implements BatchExtension { +public class MetricProvider extends ExtensionProvider implements TaskExtension { private Metrics[] factories; @@ -43,6 +41,7 @@ public class MetricProvider extends ExtensionProvider implements BatchExtension this.factories = new Metrics[0]; } + @Override public List<Metric> provide() { LoggerFactory.getLogger(MetricProvider.class).debug("Load metrics"); List<Metric> metrics = Lists.newArrayList(CoreMetrics.getMetrics()); diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java index ec036f13da4..eb038eca0ae 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java @@ -75,7 +75,6 @@ public final class MeasurePersister { unsavedMeasuresByResource.put(resource, measure); return; } - MeasureModel model = insertOrUpdate(resource, measure); if (model != null) { memoryOptimizer.evictDataMeasure(measure, model); diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java index c33a6fdf6b3..0a298869676 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java @@ -25,6 +25,7 @@ import org.sonar.api.batch.BatchExtensionDictionnary; import org.sonar.api.batch.Decorator; import org.sonar.api.batch.DecoratorContext; import org.sonar.api.batch.SonarIndex; +import org.sonar.api.batch.TaskExtensionDictionnary; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; import org.sonar.api.utils.SonarException; @@ -42,8 +43,9 @@ public class DecoratorsExecutor implements BatchComponent { private EventBus eventBus; private Project project; - public DecoratorsExecutor(BatchExtensionDictionnary extensionDictionnary, Project project, SonarIndex index, EventBus eventBus) { - this.decoratorsSelector = new DecoratorsSelector(extensionDictionnary); + public DecoratorsExecutor(TaskExtensionDictionnary taskExtDictionnary, BatchExtensionDictionnary batchExtDictionnary, + Project project, SonarIndex index, EventBus eventBus) { + this.decoratorsSelector = new DecoratorsSelector(taskExtDictionnary, batchExtDictionnary); this.index = index; this.eventBus = eventBus; this.project = project; @@ -78,7 +80,7 @@ public class DecoratorsExecutor implements BatchComponent { eventBus.fireEvent(new DecoratorExecutionEvent(decorator, true)); decorator.decorate(resource, context); eventBus.fireEvent(new DecoratorExecutionEvent(decorator, false)); - + } catch (Exception e) { // SONAR-2278 the resource should not be lost in exception stacktrace. throw new SonarException("Fail to decorate '" + resource + "'", e); |