diff options
Diffstat (limited to 'sonar-batch')
32 files changed, 123 insertions, 86 deletions
diff --git a/sonar-batch/pom.xml b/sonar-batch/pom.xml index 1db1f35f0e9..db45a80e535 100644 --- a/sonar-batch/pom.xml +++ b/sonar-batch/pom.xml @@ -42,10 +42,6 @@ </dependency> <dependency> <groupId>org.codehaus.sonar</groupId> - <artifactId>sonar-batch-plugin-api</artifactId> - </dependency> - <dependency> - <groupId>org.codehaus.sonar</groupId> <artifactId>sonar-plugin-api</artifactId> <exclusions> <exclusion> diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionDictionnary.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionDictionnary.java index 538e3091e42..b5979b998ea 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionDictionnary.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchExtensionDictionnary.java @@ -19,6 +19,9 @@ */ package org.sonar.batch.bootstrap; +import org.sonar.api.batch.analyzer.Analyzer; +import org.sonar.api.batch.analyzer.AnalyzerContext; + import com.google.common.collect.Lists; import org.apache.commons.lang.ClassUtils; import org.sonar.api.batch.CheckProject; @@ -26,8 +29,6 @@ import org.sonar.api.batch.Sensor; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.platform.ComponentContainer; import org.sonar.api.resources.Project; -import org.sonar.batch.api.analyzer.Analyzer; -import org.sonar.batch.api.analyzer.AnalyzerContext; import org.sonar.batch.scan.SensorWrapper; import java.util.Collection; diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java index ae75f47f2a4..2f35ec81bc0 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java @@ -178,7 +178,7 @@ public class DefaultIndex extends SonarIndex { } @Override - public Measure getMeasure(Resource resource, org.sonar.batch.api.measures.Metric<?> metric) { + public Measure getMeasure(Resource resource, org.sonar.api.batch.measures.Metric<?> metric) { return getMeasures(resource, MeasuresFilters.metric(metric)); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/languages/DeprecatedLanguagesReferential.java b/sonar-batch/src/main/java/org/sonar/batch/languages/DeprecatedLanguagesReferential.java index 1084b7d49a2..ce8f60d9057 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/languages/DeprecatedLanguagesReferential.java +++ b/sonar-batch/src/main/java/org/sonar/batch/languages/DeprecatedLanguagesReferential.java @@ -19,8 +19,9 @@ */ package org.sonar.batch.languages; +import org.sonar.api.batch.languages.Language; + import org.sonar.api.resources.Languages; -import org.sonar.batch.api.languages.Language; import javax.annotation.CheckForNull; diff --git a/sonar-batch/src/main/java/org/sonar/batch/languages/LanguagesReferential.java b/sonar-batch/src/main/java/org/sonar/batch/languages/LanguagesReferential.java index bf9fcd00de5..761a03945c2 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/languages/LanguagesReferential.java +++ b/sonar-batch/src/main/java/org/sonar/batch/languages/LanguagesReferential.java @@ -19,8 +19,9 @@ */ package org.sonar.batch.languages; +import org.sonar.api.batch.languages.Language; + import org.sonar.api.BatchComponent; -import org.sonar.batch.api.languages.Language; import javax.annotation.CheckForNull; diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/SensorMatcher.java b/sonar-batch/src/main/java/org/sonar/batch/phases/SensorMatcher.java index 6328ac77a46..169683b4235 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/SensorMatcher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/phases/SensorMatcher.java @@ -19,11 +19,12 @@ */ package org.sonar.batch.phases; +import org.sonar.api.batch.analyzer.Analyzer; + import org.apache.commons.lang.ClassUtils; import org.sonar.api.BatchExtension; import org.sonar.api.batch.InstantiationStrategy; import org.sonar.api.batch.Sensor; -import org.sonar.batch.api.analyzer.Analyzer; import org.sonar.batch.bootstrap.ExtensionMatcher; /** diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java b/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java index a7aea325d48..49f762ef811 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java @@ -19,6 +19,8 @@ */ package org.sonar.batch.rule; +import org.sonar.api.batch.rules.QProfile; + import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ListMultimap; import org.picocontainer.injectors.ProviderAdapter; @@ -28,7 +30,6 @@ import org.sonar.api.batch.rule.internal.NewActiveRule; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; import org.sonar.api.rules.RuleParam; -import org.sonar.batch.api.rules.QProfile; import org.sonar.batch.rules.QProfileWithId; import org.sonar.core.qualityprofile.db.ActiveRuleDao; import org.sonar.core.qualityprofile.db.ActiveRuleDto; diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/ModuleQProfiles.java b/sonar-batch/src/main/java/org/sonar/batch/rule/ModuleQProfiles.java index 674fbb59a56..6abaa3e4ef3 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/ModuleQProfiles.java +++ b/sonar-batch/src/main/java/org/sonar/batch/rule/ModuleQProfiles.java @@ -19,13 +19,14 @@ */ package org.sonar.batch.rule; +import org.sonar.api.batch.languages.Language; +import org.sonar.api.batch.rules.QProfile; + import com.google.common.collect.ImmutableMap; import org.apache.commons.lang.StringUtils; import org.sonar.api.BatchComponent; import org.sonar.api.config.Settings; import org.sonar.api.utils.MessageException; -import org.sonar.batch.api.languages.Language; -import org.sonar.batch.api.rules.QProfile; import org.sonar.batch.languages.LanguagesReferential; import org.sonar.batch.rules.QProfilesReferential; diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileVerifier.java b/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileVerifier.java index 10e110b6ee9..52004908844 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileVerifier.java +++ b/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileVerifier.java @@ -19,6 +19,8 @@ */ package org.sonar.batch.rule; +import org.sonar.api.batch.rules.QProfile; + import com.google.common.annotations.VisibleForTesting; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; @@ -27,7 +29,6 @@ import org.sonar.api.BatchComponent; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.config.Settings; import org.sonar.api.utils.MessageException; -import org.sonar.batch.api.rules.QProfile; public class QProfileVerifier implements BatchComponent { diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileProvider.java b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileProvider.java index 2c5ec75a235..67c6a739f14 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileProvider.java @@ -19,6 +19,8 @@ */ package org.sonar.batch.rule; +import org.sonar.api.batch.rules.QProfile; + import com.google.common.collect.Lists; import org.apache.commons.lang.StringUtils; import org.picocontainer.injectors.ProviderAdapter; @@ -30,7 +32,6 @@ import org.sonar.api.rules.ActiveRule; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; import org.sonar.api.rules.RulePriority; -import org.sonar.batch.api.rules.QProfile; import java.util.Collection; import java.util.Map; diff --git a/sonar-batch/src/main/java/org/sonar/batch/rules/DefaultQProfileReferential.java b/sonar-batch/src/main/java/org/sonar/batch/rules/DefaultQProfileReferential.java index 936b17e63fe..c3d66b0df45 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/rules/DefaultQProfileReferential.java +++ b/sonar-batch/src/main/java/org/sonar/batch/rules/DefaultQProfileReferential.java @@ -19,7 +19,8 @@ */ package org.sonar.batch.rules; -import org.sonar.batch.api.rules.QProfile; +import org.sonar.api.batch.rules.QProfile; + import org.sonar.core.qualityprofile.db.QualityProfileDao; import org.sonar.core.qualityprofile.db.QualityProfileDto; diff --git a/sonar-batch/src/main/java/org/sonar/batch/rules/QProfileWithId.java b/sonar-batch/src/main/java/org/sonar/batch/rules/QProfileWithId.java index 4d2511676a9..c441b7ff4e7 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/rules/QProfileWithId.java +++ b/sonar-batch/src/main/java/org/sonar/batch/rules/QProfileWithId.java @@ -19,7 +19,7 @@ */ package org.sonar.batch.rules; -import org.sonar.batch.api.rules.QProfile; +import org.sonar.api.batch.rules.QProfile; public class QProfileWithId extends QProfile { private final int id; diff --git a/sonar-batch/src/main/java/org/sonar/batch/rules/QProfilesReferential.java b/sonar-batch/src/main/java/org/sonar/batch/rules/QProfilesReferential.java index aec78dc14c8..5fc80852778 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/rules/QProfilesReferential.java +++ b/sonar-batch/src/main/java/org/sonar/batch/rules/QProfilesReferential.java @@ -19,8 +19,9 @@ */ package org.sonar.batch.rules; +import org.sonar.api.batch.rules.QProfile; + import org.sonar.api.BatchComponent; -import org.sonar.batch.api.rules.QProfile; import javax.annotation.CheckForNull; 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 a3f125d9c4f..97bf89d1aa9 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 @@ -20,7 +20,13 @@ package org.sonar.batch.scan; import org.sonar.api.batch.SensorContext; +import org.sonar.api.batch.analyzer.AnalyzerContext; +import org.sonar.api.batch.analyzer.issue.AnalyzerIssue; +import org.sonar.api.batch.analyzer.measure.AnalyzerMeasure; +import org.sonar.api.batch.analyzer.measure.AnalyzerMeasureBuilder; +import org.sonar.api.batch.analyzer.measure.internal.DefaultAnalyzerMeasureBuilder; import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.measures.Metric; import org.sonar.api.component.ResourcePerspectives; import org.sonar.api.issue.Issuable; import org.sonar.api.measures.Measure; @@ -29,10 +35,6 @@ import org.sonar.api.resources.File; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; import org.sonar.api.rule.RuleKey; -import org.sonar.batch.api.analyzer.AnalyzerContext; -import org.sonar.batch.api.analyzer.issue.AnalyzerIssue; -import org.sonar.batch.api.analyzer.measure.AnalyzerMeasure; -import org.sonar.batch.api.measures.Metric; import java.io.Serializable; import java.util.Collection; @@ -52,6 +54,11 @@ public class AnalyzerContextAdaptor implements AnalyzerContext { } @Override + public <G extends Serializable> AnalyzerMeasureBuilder<G> measureBuilder() { + return new DefaultAnalyzerMeasureBuilder<G>(); + } + + @Override public AnalyzerMeasure<?> getMeasure(String metricKey) { Metric<?> m = metricFinder.findByKey(metricKey); if (m == null) { @@ -67,7 +74,7 @@ public class AnalyzerContextAdaptor implements AnalyzerContext { if (measure == null) { return null; } - return AnalyzerMeasure.<G>builder() + return this.<G>measureBuilder() .onProject() .forMetric(metric) .withValue(measure.value()) @@ -91,7 +98,7 @@ public class AnalyzerContextAdaptor implements AnalyzerContext { if (measure == null) { return null; } - return AnalyzerMeasure.<G>builder() + return this.<G>measureBuilder() .onFile(file) .forMetric(metric) .withValue(measure.value()) diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/LanguageVerifier.java b/sonar-batch/src/main/java/org/sonar/batch/scan/LanguageVerifier.java index 7f32e03e98e..88cc4365bed 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/LanguageVerifier.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/LanguageVerifier.java @@ -19,6 +19,8 @@ */ package org.sonar.batch.scan; +import org.sonar.api.batch.languages.Language; + import org.picocontainer.Startable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -26,7 +28,6 @@ import org.sonar.api.CoreProperties; import org.sonar.api.batch.fs.internal.DefaultFileSystem; import org.sonar.api.config.Settings; import org.sonar.api.utils.MessageException; -import org.sonar.batch.api.languages.Language; import org.sonar.batch.languages.LanguagesReferential; /** diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java index 6b1e0e1a501..a0584e490d9 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java @@ -200,8 +200,7 @@ public class ModuleScanContainer extends ComponentContainer { // Example : C# plugin adds sub-projects at runtime, even if they are not defined in root pom. return !ExtensionUtils.isMavenExtensionOnly(extension) || module.getPom() != null; } - return ExtensionUtils.isType(extension, org.sonar.batch.api.BatchComponent.class) - && ExtensionUtils.isInstantiationStrategy(extension, org.sonar.batch.api.InstantiationStrategy.PER_PROJECT); + return false; } }); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java index 8d4dfa22df7..12eaf5aa378 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java @@ -100,23 +100,26 @@ public class ProjectScanContainer extends ComponentContainer { } private void projectBootstrap() { - ProjectReactor reactor; - // OK, not present, so look for a custom ProjectBootstrapper - ProjectBootstrapper bootstrapper = getComponentByType(ProjectBootstrapper.class); - Settings settings = getComponentByType(Settings.class); - if (bootstrapper == null - // Starting from Maven plugin 2.3 then only DefaultProjectBootstrapper should be used. - || "true".equals(settings.getString("sonar.mojoUseRunner"))) { - // Use default SonarRunner project bootstrapper - ProjectReactorBuilder builder = getComponentByType(ProjectReactorBuilder.class); - reactor = builder.execute(); - } else { - reactor = bootstrapper.bootstrap(); - } + // Views pass a custom ProjectReactor + ProjectReactor reactor = getComponentByType(ProjectReactor.class); if (reactor == null) { - throw new SonarException(bootstrapper + " has returned null as ProjectReactor"); + // OK, not present, so look for a deprecated custom ProjectBootstrapper for old versions of SQ Runner + ProjectBootstrapper bootstrapper = getComponentByType(ProjectBootstrapper.class); + Settings settings = getComponentByType(Settings.class); + if (bootstrapper == null + // Starting from Maven plugin 2.3 then only DefaultProjectBootstrapper should be used. + || "true".equals(settings.getString("sonar.mojoUseRunner"))) { + // Use default SonarRunner project bootstrapper + ProjectReactorBuilder builder = getComponentByType(ProjectReactorBuilder.class); + reactor = builder.execute(); + } else { + reactor = bootstrapper.bootstrap(); + } + if (reactor == null) { + throw new SonarException(bootstrapper + " has returned null as ProjectReactor"); + } + add(reactor); } - add(reactor); } private void addBatchComponents() { diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ScanTask.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ScanTask.java index 33285ae2be6..0ff2d3be352 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ScanTask.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ScanTask.java @@ -19,6 +19,8 @@ */ package org.sonar.batch.scan; +import org.sonar.batch.scan2.ProjectScanContainer; + import org.sonar.api.CoreProperties; import org.sonar.api.platform.ComponentContainer; import org.sonar.api.task.Task; @@ -27,7 +29,6 @@ import org.sonar.batch.DefaultProjectTree; import org.sonar.batch.bootstrap.BootstrapProperties; import org.sonar.batch.bootstrap.TaskContainer; import org.sonar.batch.phases.Phases; -import org.sonar.batch.scan2.ProjectScanContainer; public class ScanTask implements Task { public static final TaskDefinition DEFINITION = TaskDefinition.builder() diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/SensorWrapper.java b/sonar-batch/src/main/java/org/sonar/batch/scan/SensorWrapper.java index ae9a25c59dc..ac53dbec1db 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/SensorWrapper.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/SensorWrapper.java @@ -23,11 +23,12 @@ import org.sonar.api.batch.DependedUpon; import org.sonar.api.batch.DependsUpon; import org.sonar.api.batch.Sensor; import org.sonar.api.batch.SensorContext; +import org.sonar.api.batch.analyzer.Analyzer; +import org.sonar.api.batch.analyzer.AnalyzerContext; +import org.sonar.api.batch.analyzer.internal.DefaultAnalyzerDescriptor; import org.sonar.api.batch.fs.FileSystem; +import org.sonar.api.batch.measures.Metric; import org.sonar.api.resources.Project; -import org.sonar.batch.api.analyzer.Analyzer; -import org.sonar.batch.api.analyzer.AnalyzerContext; -import org.sonar.batch.api.measures.Metric; import java.util.Arrays; import java.util.List; @@ -37,31 +38,34 @@ public class SensorWrapper implements Sensor { private Analyzer analyzer; private AnalyzerContext adaptor; private FileSystem fs; + private DefaultAnalyzerDescriptor descriptor; public SensorWrapper(Analyzer analyzer, AnalyzerContext adaptor, FileSystem fs) { this.analyzer = analyzer; + descriptor = new DefaultAnalyzerDescriptor(); + analyzer.describe(descriptor); this.adaptor = adaptor; this.fs = fs; } @DependedUpon public List<Metric<?>> provides() { - return Arrays.asList(analyzer.describe().provides()); + return Arrays.asList(descriptor.provides()); } @DependsUpon public List<Metric<?>> depends() { - return Arrays.asList(analyzer.describe().dependsOn()); + return Arrays.asList(descriptor.dependsOn()); } @Override public boolean shouldExecuteOnProject(Project project) { - if (!analyzer.describe().languages().isEmpty()) { - if (project.getLanguageKey() != null && !analyzer.describe().languages().contains(project.getLanguageKey())) { + if (!descriptor.languages().isEmpty()) { + if (project.getLanguageKey() != null && !descriptor.languages().contains(project.getLanguageKey())) { return false; } boolean hasFile = false; - for (String languageKey : analyzer.describe().languages()) { + for (String languageKey : descriptor.languages()) { hasFile |= fs.hasFiles(fs.predicates().hasLanguage(languageKey)); } if (!hasFile) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/LanguageDetection.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/LanguageDetection.java index 7256c5592a3..8bdddc89c90 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/LanguageDetection.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/LanguageDetection.java @@ -19,6 +19,8 @@ */ package org.sonar.batch.scan.filesystem; +import org.sonar.api.batch.languages.Language; + import com.google.common.base.Joiner; import com.google.common.collect.Lists; import com.google.common.collect.Maps; @@ -30,7 +32,6 @@ import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.PathPattern; import org.sonar.api.config.Settings; import org.sonar.api.utils.MessageException; -import org.sonar.batch.api.languages.Language; import org.sonar.batch.languages.LanguagesReferential; import javax.annotation.CheckForNull; diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/MeasureCache.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzerMeasureCache.java index 96ab8adc9de..593324a1c73 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan2/MeasureCache.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzerMeasureCache.java @@ -21,7 +21,7 @@ package org.sonar.batch.scan2; import com.google.common.base.Preconditions; import org.sonar.api.BatchComponent; -import org.sonar.batch.api.analyzer.measure.AnalyzerMeasure; +import org.sonar.api.batch.analyzer.measure.internal.DefaultAnalyzerMeasure; import org.sonar.batch.index.Cache; import org.sonar.batch.index.Cache.Entry; import org.sonar.batch.index.Caches; @@ -29,36 +29,36 @@ import org.sonar.batch.index.Caches; /** * Cache of all measures. This cache is shared amongst all project modules. */ -public class MeasureCache implements BatchComponent { +public class AnalyzerMeasureCache implements BatchComponent { - private final Cache<AnalyzerMeasure<?>> cache; + private final Cache<DefaultAnalyzerMeasure> cache; - public MeasureCache(Caches caches) { + public AnalyzerMeasureCache(Caches caches) { cache = caches.createCache("measures"); } - public Iterable<Entry<AnalyzerMeasure<?>>> entries() { + public Iterable<Entry<DefaultAnalyzerMeasure>> entries() { return cache.entries(); } - public AnalyzerMeasure<?> byMetric(String resourceKey, String metricKey) { + public DefaultAnalyzerMeasure<?> byMetric(String resourceKey, String metricKey) { return cache.get(resourceKey, metricKey); } - public MeasureCache put(String resourceKey, AnalyzerMeasure<?> measure) { + public AnalyzerMeasureCache put(String resourceKey, DefaultAnalyzerMeasure<?> measure) { Preconditions.checkNotNull(resourceKey); Preconditions.checkNotNull(measure.metricKey()); cache.put(resourceKey, measure.metricKey(), measure); return this; } - public boolean contains(String resourceKey, AnalyzerMeasure<?> measure) { + public boolean contains(String resourceKey, DefaultAnalyzerMeasure<?> measure) { Preconditions.checkNotNull(resourceKey); Preconditions.checkNotNull(measure); return cache.containsKey(resourceKey, measure.metricKey()); } - public Iterable<AnalyzerMeasure<?>> all() { + public Iterable<DefaultAnalyzerMeasure> all() { return cache.values(); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzersExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzersExecutor.java index c0ae6dbbaab..ce2d9e3effb 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzersExecutor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan2/AnalyzersExecutor.java @@ -22,10 +22,10 @@ package org.sonar.batch.scan2; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.BatchComponent; +import org.sonar.api.batch.analyzer.Analyzer; +import org.sonar.api.batch.analyzer.AnalyzerContext; +import org.sonar.api.batch.analyzer.internal.DefaultAnalyzerDescriptor; import org.sonar.api.platform.ComponentContainer; -import org.sonar.batch.api.analyzer.Analyzer; -import org.sonar.batch.api.analyzer.AnalyzerContext; -import org.sonar.batch.api.analyzer.AnalyzerDescriptor; import java.util.Collection; @@ -44,7 +44,8 @@ public class AnalyzersExecutor implements BatchComponent { for (Analyzer analyzer : analyzers) { - AnalyzerDescriptor descriptor = analyzer.describe(); + DefaultAnalyzerDescriptor descriptor = new DefaultAnalyzerDescriptor(); + analyzer.describe(descriptor); LOG.info("Execute analyzer: " + descriptor.name()); diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultAnalyzerContext.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultAnalyzerContext.java index 253bf0cab41..5fc2961ef84 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultAnalyzerContext.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultAnalyzerContext.java @@ -19,14 +19,17 @@ */ package org.sonar.batch.scan2; +import org.sonar.api.batch.analyzer.AnalyzerContext; +import org.sonar.api.batch.analyzer.issue.AnalyzerIssue; +import org.sonar.api.batch.analyzer.measure.AnalyzerMeasure; +import org.sonar.api.batch.analyzer.measure.AnalyzerMeasureBuilder; +import org.sonar.api.batch.analyzer.measure.internal.DefaultAnalyzerMeasure; +import org.sonar.api.batch.analyzer.measure.internal.DefaultAnalyzerMeasureBuilder; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.measures.Metric; import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.rule.RuleKey; -import org.sonar.batch.api.analyzer.AnalyzerContext; -import org.sonar.batch.api.analyzer.issue.AnalyzerIssue; -import org.sonar.batch.api.analyzer.measure.AnalyzerMeasure; -import org.sonar.batch.api.measures.Metric; import org.sonar.batch.issue.ModuleIssues; import org.sonar.core.component.ComponentKeys; import org.sonar.core.issue.DefaultIssueBuilder; @@ -36,17 +39,22 @@ import java.util.Collection; public class DefaultAnalyzerContext implements AnalyzerContext { - private final MeasureCache measureCache; + private final AnalyzerMeasureCache measureCache; private ProjectDefinition def; private ModuleIssues moduleIssues; - public DefaultAnalyzerContext(ProjectDefinition def, MeasureCache measureCache, ModuleIssues moduleIssues) { + public DefaultAnalyzerContext(ProjectDefinition def, AnalyzerMeasureCache measureCache, ModuleIssues moduleIssues) { this.def = def; this.measureCache = measureCache; this.moduleIssues = moduleIssues; } @Override + public <G extends Serializable> AnalyzerMeasureBuilder<G> measureBuilder() { + return new DefaultAnalyzerMeasureBuilder<G>(); + } + + @Override public AnalyzerMeasure getMeasure(String metricKey) { return measureCache.byMetric(def.getKey(), metricKey); } @@ -67,11 +75,11 @@ public class DefaultAnalyzerContext implements AnalyzerContext { } @Override - public void addMeasure(org.sonar.batch.api.analyzer.measure.AnalyzerMeasure<?> measure) { + public void addMeasure(AnalyzerMeasure<?> measure) { if (measure.inputFile() != null) { - measureCache.put(ComponentKeys.createEffectiveKey(def.getKey(), measure.inputFile()), measure); + measureCache.put(ComponentKeys.createEffectiveKey(def.getKey(), measure.inputFile()), (DefaultAnalyzerMeasure) measure); } else { - measureCache.put(def.getKey(), measure); + measureCache.put(def.getKey(), (DefaultAnalyzerMeasure) measure); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanContainer.java index 24435c0dc55..6982d3da3b2 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanContainer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanContainer.java @@ -21,12 +21,12 @@ package org.sonar.batch.scan2; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.sonar.api.BatchComponent; +import org.sonar.api.batch.InstantiationStrategy; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.rule.CheckFactory; import org.sonar.api.platform.ComponentContainer; import org.sonar.api.scan.filesystem.FileExclusions; -import org.sonar.batch.api.BatchComponent; -import org.sonar.batch.api.InstantiationStrategy; import org.sonar.batch.bootstrap.BatchExtensionDictionnary; import org.sonar.batch.bootstrap.ExtensionInstaller; import org.sonar.batch.bootstrap.ExtensionMatcher; diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/Phase2Executor.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/Phase2Executor.java index fcbec9bf4b4..0b6f2071df9 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan2/Phase2Executor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan2/Phase2Executor.java @@ -19,11 +19,12 @@ */ package org.sonar.batch.scan2; +import org.sonar.api.batch.analyzer.AnalyzerContext; + import com.google.common.collect.Lists; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.batch.api.analyzer.AnalyzerContext; import org.sonar.batch.issue.ignore.scanner.IssueExclusionsLoader; import org.sonar.batch.phases.SensorsExecutor; import org.sonar.batch.rule.QProfileVerifier; diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/ProjectScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/ProjectScanContainer.java index 6a3d9bfcfac..f5dd041678e 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan2/ProjectScanContainer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan2/ProjectScanContainer.java @@ -20,7 +20,9 @@ package org.sonar.batch.scan2; import com.google.common.annotations.VisibleForTesting; +import org.sonar.api.BatchComponent; import org.sonar.api.CoreProperties; +import org.sonar.api.batch.InstantiationStrategy; import org.sonar.api.batch.bootstrap.ProjectBootstrapper; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.bootstrap.ProjectReactor; @@ -28,8 +30,6 @@ import org.sonar.api.config.Settings; import org.sonar.api.platform.ComponentContainer; import org.sonar.api.scan.filesystem.PathResolver; import org.sonar.api.utils.SonarException; -import org.sonar.batch.api.BatchComponent; -import org.sonar.batch.api.InstantiationStrategy; import org.sonar.batch.bootstrap.ExtensionInstaller; import org.sonar.batch.bootstrap.ExtensionMatcher; import org.sonar.batch.bootstrap.ExtensionUtils; @@ -105,7 +105,7 @@ public class ProjectScanContainer extends ComponentContainer { ResourceCache.class, ComponentDataCache.class, ComponentDataPersister.class, - MeasureCache.class, + AnalyzerMeasureCache.class, // file system InputFileCache.class, diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/ScanTaskObserver.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/ScanTaskObserver.java index 89f5c7694cc..636ed9f34ed 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan2/ScanTaskObserver.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan2/ScanTaskObserver.java @@ -19,7 +19,7 @@ */ package org.sonar.batch.scan2; -import org.sonar.batch.api.BatchExtension; +import org.sonar.api.BatchExtension; public interface ScanTaskObserver extends BatchExtension { diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionDictionnaryTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionDictionnaryTest.java index d7f5df2e761..ff878582c68 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionDictionnaryTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionDictionnaryTest.java @@ -19,6 +19,8 @@ */ package org.sonar.batch.bootstrap; +import org.sonar.api.batch.analyzer.AnalyzerContext; + import org.junit.Test; import org.sonar.api.BatchExtension; import org.sonar.api.batch.Sensor; @@ -26,7 +28,6 @@ import org.sonar.api.batch.SensorContext; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.platform.ComponentContainer; import org.sonar.api.resources.Project; -import org.sonar.batch.api.analyzer.AnalyzerContext; import java.util.Collection; diff --git a/sonar-batch/src/test/java/org/sonar/batch/rule/ActiveRulesProviderTest.java b/sonar-batch/src/test/java/org/sonar/batch/rule/ActiveRulesProviderTest.java index 205fe2e8a8c..cf809549abd 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/rule/ActiveRulesProviderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/rule/ActiveRulesProviderTest.java @@ -19,6 +19,8 @@ */ package org.sonar.batch.rule; +import org.sonar.api.batch.rules.QProfile; + import org.junit.Before; import org.junit.Test; import org.sonar.api.batch.rule.ActiveRule; @@ -27,7 +29,6 @@ import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.Severity; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; -import org.sonar.batch.api.rules.QProfile; import org.sonar.batch.rules.QProfileWithId; import org.sonar.core.persistence.AbstractDaoTestCase; import org.sonar.core.qualityprofile.db.ActiveRuleDao; diff --git a/sonar-batch/src/test/java/org/sonar/batch/rule/ModuleQProfilesTest.java b/sonar-batch/src/test/java/org/sonar/batch/rule/ModuleQProfilesTest.java index 6b3102206f3..60af454bf0b 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/rule/ModuleQProfilesTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/rule/ModuleQProfilesTest.java @@ -19,13 +19,14 @@ */ package org.sonar.batch.rule; +import org.sonar.api.batch.rules.QProfile; + import com.google.common.collect.Lists; import org.junit.Test; import org.sonar.api.config.Settings; import org.sonar.api.resources.Language; import org.sonar.api.resources.Languages; import org.sonar.api.utils.MessageException; -import org.sonar.batch.api.rules.QProfile; import org.sonar.batch.languages.DeprecatedLanguagesReferential; import org.sonar.batch.languages.LanguagesReferential; import org.sonar.batch.rules.DefaultQProfileReferential; diff --git a/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileSensorTest.java b/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileSensorTest.java index 04ba7b1c251..1bc8325f531 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileSensorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileSensorTest.java @@ -19,13 +19,14 @@ */ package org.sonar.batch.rule; +import org.sonar.api.batch.rules.QProfile; + import org.junit.Test; import org.sonar.api.batch.SensorContext; import org.sonar.api.batch.fs.internal.DefaultFileSystem; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.resources.Project; import org.sonar.api.test.IsMeasure; -import org.sonar.batch.api.rules.QProfile; import org.sonar.batch.rules.QProfileWithId; import org.sonar.core.persistence.AbstractDaoTestCase; import org.sonar.core.qualityprofile.db.QualityProfileDao; diff --git a/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProfileProviderTest.java b/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProfileProviderTest.java index 789f4a35485..499e3605220 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProfileProviderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProfileProviderTest.java @@ -19,12 +19,13 @@ */ package org.sonar.batch.rule; +import org.sonar.api.batch.rules.QProfile; + import org.junit.Test; import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.config.Settings; import org.sonar.api.profiles.RulesProfile; import org.sonar.api.rules.RuleFinder; -import org.sonar.batch.api.rules.QProfile; import org.sonar.batch.rules.QProfileWithId; import java.util.Arrays; |