aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2018-12-04 14:51:21 +0100
committersonartech <sonartech@sonarsource.com>2019-01-16 09:43:05 +0100
commit4660315c13ba09f58f5034ca99b855ece9f75e25 (patch)
tree97152755ad675a2b77ca36d9889558c280988e14 /sonar-scanner-engine/src
parent19a03e51f75d342155079b808fa879ece194a196 (diff)
downloadsonarqube-4660315c13ba09f58f5034ca99b855ece9f75e25.tar.gz
sonarqube-4660315c13ba09f58f5034ca99b855ece9f75e25.zip
SONAR-11465 Add project level Sensor EP
Diffstat (limited to 'sonar-scanner-engine/src')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/AbstractExtensionDictionnary.java2
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleScanContainer.java22
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java15
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/AbstractCoverageExclusions.java (renamed from sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/AbstractCoverageExclusions.java)2
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java2
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ModuleCoverageExclusions.java (renamed from sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/ModuleCoverageExclusions.java)2
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectCoverageExclusions.java (renamed from sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/ProjectCoverageExclusions.java)2
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectFileIndexer.java2
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/AbstractSensorOptimizer.java (renamed from sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/SensorOptimizer.java)6
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorContext.java49
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorExtensionDictionnary.java (renamed from sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SensorExtensionDictionnary.java)15
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorOptimizer.java (renamed from sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/package-info.java)17
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorWrapper.java (renamed from sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/SensorWrapper.java)12
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorsExecutor.java (renamed from sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/SensorsExecutor.java)34
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorContext.java (renamed from sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorContext.java)8
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorExtensionDictionnary.java48
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorOptimizer.java32
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorWrapper.java60
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorsExecutor.java66
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ModuleSensorExtensionDictionnaryTest.java (renamed from sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/SensorExtensionDictionnaryTest.java)45
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java17
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/ModuleCoverageExclusionsTest.java1
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/ModuleSensorsExecutorTest.java (renamed from sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/SensorsExecutorTest.java)21
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/ProjectCoverageExclusionsTest.java1
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorContextTest.java (renamed from sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java)23
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorOptimizerTest.java (renamed from sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/SensorOptimizerTest.java)10
26 files changed, 398 insertions, 116 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/AbstractExtensionDictionnary.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/AbstractExtensionDictionnary.java
index 811a6569695..d4733375ba8 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/AbstractExtensionDictionnary.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/AbstractExtensionDictionnary.java
@@ -132,7 +132,7 @@ public abstract class AbstractExtensionDictionnary {
}
}
- List<Object> evaluateAnnotatedClasses(Object extension, Class<? extends Annotation> annotation) {
+ public List<Object> evaluateAnnotatedClasses(Object extension, Class<? extends Annotation> annotation) {
List<Object> results = new ArrayList<>();
Class<?> aClass = extension.getClass();
while (aClass != null) {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleScanContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleScanContainer.java
index 58ef061c2c0..e771f958e7c 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleScanContainer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleScanContainer.java
@@ -19,26 +19,23 @@
*/
package org.sonar.scanner.scan;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.scan.filesystem.FileExclusions;
import org.sonar.core.platform.ComponentContainer;
import org.sonar.scanner.bootstrap.ExtensionInstaller;
-import org.sonar.scanner.bootstrap.SensorExtensionDictionnary;
import org.sonar.scanner.deprecated.perspectives.ScannerPerspectives;
-import org.sonar.scanner.phases.SensorsExecutor;
import org.sonar.scanner.scan.filesystem.DefaultModuleFileSystem;
import org.sonar.scanner.scan.filesystem.ModuleInputComponentStore;
-import org.sonar.scanner.sensor.DefaultSensorContext;
-import org.sonar.scanner.sensor.SensorOptimizer;
+import org.sonar.scanner.sensor.ModuleSensorContext;
+import org.sonar.scanner.sensor.ModuleSensorExtensionDictionnary;
+import org.sonar.scanner.sensor.ModuleSensorOptimizer;
+import org.sonar.scanner.sensor.ModuleSensorsExecutor;
import static org.sonar.api.batch.InstantiationStrategy.PER_PROJECT;
import static org.sonar.scanner.bootstrap.ExtensionUtils.isDeprecatedScannerSide;
import static org.sonar.scanner.bootstrap.ExtensionUtils.isInstantiationStrategy;
public class ModuleScanContainer extends ComponentContainer {
- private static final Logger LOG = LoggerFactory.getLogger(ModuleScanContainer.class);
private final DefaultInputModule module;
public ModuleScanContainer(ProjectScanContainer parent, DefaultInputModule module) {
@@ -48,7 +45,6 @@ public class ModuleScanContainer extends ComponentContainer {
@Override
protected void doBeforeStart() {
- LOG.info("------------- Scan {}", module.definition().getName());
addCoreComponents();
addExtensions();
}
@@ -60,17 +56,17 @@ public class ModuleScanContainer extends ComponentContainer {
MutableModuleSettings.class,
new ModuleConfigurationProvider(),
- SensorsExecutor.class,
+ ModuleSensorsExecutor.class,
// file system
ModuleInputComponentStore.class,
FileExclusions.class,
DefaultModuleFileSystem.class,
- SensorOptimizer.class,
+ ModuleSensorOptimizer.class,
- DefaultSensorContext.class,
- SensorExtensionDictionnary.class,
+ ModuleSensorContext.class,
+ ModuleSensorExtensionDictionnary.class,
// Perspectives
ScannerPerspectives.class);
@@ -83,7 +79,7 @@ public class ModuleScanContainer extends ComponentContainer {
@Override
protected void doAfterStart() {
- getComponentByType(SensorsExecutor.class).execute();
+ getComponentByType(ModuleSensorsExecutor.class).execute();
}
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java
index 633efa40caa..295417852b7 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java
@@ -68,7 +68,6 @@ import org.sonar.scanner.issue.tracking.ServerIssueRepository;
import org.sonar.scanner.issue.tracking.ServerLineHashesLoader;
import org.sonar.scanner.mediumtest.AnalysisObservers;
import org.sonar.scanner.notifications.DefaultAnalysisWarnings;
-import org.sonar.scanner.phases.ProjectCoverageExclusions;
import org.sonar.scanner.postjob.DefaultPostJobContext;
import org.sonar.scanner.postjob.PostJobOptimizer;
import org.sonar.scanner.postjob.PostJobsExecutor;
@@ -112,6 +111,7 @@ import org.sonar.scanner.scan.filesystem.FileIndexer;
import org.sonar.scanner.scan.filesystem.InputComponentStore;
import org.sonar.scanner.scan.filesystem.LanguageDetection;
import org.sonar.scanner.scan.filesystem.MetadataGenerator;
+import org.sonar.scanner.scan.filesystem.ProjectCoverageExclusions;
import org.sonar.scanner.scan.filesystem.ProjectExclusionFilters;
import org.sonar.scanner.scan.filesystem.ProjectFileIndexer;
import org.sonar.scanner.scan.filesystem.ScannerComponentIdGenerator;
@@ -123,6 +123,10 @@ import org.sonar.scanner.scm.ScmChangedFilesProvider;
import org.sonar.scanner.scm.ScmConfiguration;
import org.sonar.scanner.scm.ScmPublisher;
import org.sonar.scanner.sensor.DefaultSensorStorage;
+import org.sonar.scanner.sensor.ProjectSensorContext;
+import org.sonar.scanner.sensor.ProjectSensorExtensionDictionnary;
+import org.sonar.scanner.sensor.ProjectSensorOptimizer;
+import org.sonar.scanner.sensor.ProjectSensorsExecutor;
import org.sonar.scanner.storage.Storages;
import static org.sonar.api.batch.InstantiationStrategy.PER_BATCH;
@@ -272,6 +276,10 @@ public class ProjectScanContainer extends ComponentContainer {
// Sensors
DefaultSensorStorage.class,
DefaultFileLinesContextFactory.class,
+ ProjectSensorContext.class,
+ ProjectSensorOptimizer.class,
+ ProjectSensorsExecutor.class,
+ ProjectSensorExtensionDictionnary.class,
// Filesystem
DefaultProjectFileSystem.class,
@@ -350,9 +358,11 @@ public class ProjectScanContainer extends ComponentContainer {
// Log detected languages and their profiles after FS is indexed and languages detected
getComponentByType(QProfileVerifier.class).execute();
- LOG.debug("Start recursive analysis of project modules");
scanRecursively(tree, tree.root());
+ LOG.info("------------- Run sensors on project");
+ getComponentByType(ProjectSensorsExecutor.class).execute();
+
getComponentByType(ScmPublisher.class).publish();
if (analysisMode.isIssues()) {
@@ -390,6 +400,7 @@ public class ProjectScanContainer extends ComponentContainer {
for (DefaultInputModule child : tree.children(module)) {
scanRecursively(tree, child);
}
+ LOG.info("------------- Run sensors on module {}", module.definition().getName());
scan(module);
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/AbstractCoverageExclusions.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/AbstractCoverageExclusions.java
index a47155b9b99..2d1abe07a67 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/AbstractCoverageExclusions.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/AbstractCoverageExclusions.java
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-package org.sonar.scanner.phases;
+package org.sonar.scanner.scan.filesystem;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java
index 801a68e4070..304f49ef624 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java
@@ -38,8 +38,6 @@ import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsLoader;
-import org.sonar.scanner.phases.ModuleCoverageExclusions;
-import org.sonar.scanner.phases.ProjectCoverageExclusions;
import org.sonar.scanner.scan.ScanProperties;
import org.sonar.scanner.util.ProgressReport;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/ModuleCoverageExclusions.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ModuleCoverageExclusions.java
index ae264222e19..ba870bc2a17 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/ModuleCoverageExclusions.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ModuleCoverageExclusions.java
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-package org.sonar.scanner.phases;
+package org.sonar.scanner.scan.filesystem;
import javax.annotation.concurrent.Immutable;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/ProjectCoverageExclusions.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectCoverageExclusions.java
index e6ba6a10753..e100450144d 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/ProjectCoverageExclusions.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectCoverageExclusions.java
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-package org.sonar.scanner.phases;
+package org.sonar.scanner.scan.filesystem;
import javax.annotation.concurrent.Immutable;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectFileIndexer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectFileIndexer.java
index 525165f18eb..af87198823f 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectFileIndexer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectFileIndexer.java
@@ -42,8 +42,6 @@ import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.fs.internal.DefaultInputProject;
import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
import org.sonar.api.scan.filesystem.PathResolver;
-import org.sonar.scanner.phases.ModuleCoverageExclusions;
-import org.sonar.scanner.phases.ProjectCoverageExclusions;
import org.sonar.scanner.util.ProgressReport;
/**
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/SensorOptimizer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/AbstractSensorOptimizer.java
index 87e70a4bf8f..f9dae8328e6 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/SensorOptimizer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/AbstractSensorOptimizer.java
@@ -27,15 +27,15 @@ import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
import org.sonar.api.config.Configuration;
-public class SensorOptimizer {
+public abstract class AbstractSensorOptimizer {
- private static final Logger LOG = LoggerFactory.getLogger(SensorOptimizer.class);
+ private static final Logger LOG = LoggerFactory.getLogger(AbstractSensorOptimizer.class);
private final FileSystem fs;
private final ActiveRules activeRules;
private final Configuration config;
- public SensorOptimizer(FileSystem fs, ActiveRules activeRules, Configuration config) {
+ public AbstractSensorOptimizer(FileSystem fs, ActiveRules activeRules, Configuration config) {
this.fs = fs;
this.activeRules = activeRules;
this.config = config;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorContext.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorContext.java
new file mode 100644
index 00000000000..b4ba2b9898c
--- /dev/null
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorContext.java
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.scanner.sensor;
+
+import javax.annotation.concurrent.ThreadSafe;
+import org.sonar.api.SonarRuntime;
+import org.sonar.api.batch.AnalysisMode;
+import org.sonar.api.batch.fs.FileSystem;
+import org.sonar.api.batch.fs.InputModule;
+import org.sonar.api.batch.fs.internal.DefaultInputProject;
+import org.sonar.api.batch.rule.ActiveRules;
+import org.sonar.api.batch.sensor.internal.SensorStorage;
+import org.sonar.api.config.Configuration;
+import org.sonar.api.config.Settings;
+
+@ThreadSafe
+public class ModuleSensorContext extends ProjectSensorContext {
+
+ private final InputModule module;
+
+ public ModuleSensorContext(DefaultInputProject project, InputModule module, Configuration config, Settings mutableSettings, FileSystem fs, ActiveRules activeRules,
+ AnalysisMode analysisMode, SensorStorage sensorStorage, SonarRuntime sonarRuntime) {
+ super(project, config, mutableSettings, fs, activeRules, analysisMode, sensorStorage, sonarRuntime);
+ this.module = module;
+ }
+
+ @Override
+ public InputModule module() {
+ return module;
+ }
+
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SensorExtensionDictionnary.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorExtensionDictionnary.java
index 34ac2dd1105..e90cb636063 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SensorExtensionDictionnary.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorExtensionDictionnary.java
@@ -17,31 +17,30 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-package org.sonar.scanner.bootstrap;
+package org.sonar.scanner.sensor;
import java.util.Collection;
import java.util.stream.Collectors;
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.core.platform.ComponentContainer;
-import org.sonar.scanner.sensor.SensorOptimizer;
-import org.sonar.scanner.sensor.SensorWrapper;
+import org.sonar.scanner.bootstrap.AbstractExtensionDictionnary;
-public class SensorExtensionDictionnary extends AbstractExtensionDictionnary {
+public class ModuleSensorExtensionDictionnary extends AbstractExtensionDictionnary {
private final SensorContext sensorContext;
- private final SensorOptimizer sensorOptimizer;
+ private final ModuleSensorOptimizer sensorOptimizer;
- public SensorExtensionDictionnary(ComponentContainer componentContainer, SensorContext sensorContext, SensorOptimizer sensorOptimizer) {
+ public ModuleSensorExtensionDictionnary(ComponentContainer componentContainer, SensorContext sensorContext, ModuleSensorOptimizer sensorOptimizer) {
super(componentContainer);
this.sensorContext = sensorContext;
this.sensorOptimizer = sensorOptimizer;
}
- public Collection<SensorWrapper> selectSensors(boolean global) {
+ public Collection<ModuleSensorWrapper> selectSensors(boolean global) {
Collection<Sensor> result = sort(getFilteredExtensions(Sensor.class, null));
return result.stream()
- .map(s -> new SensorWrapper(s, sensorContext, sensorOptimizer))
+ .map(s -> new ModuleSensorWrapper(s, sensorContext, sensorOptimizer))
.filter(s -> global == s.isGlobal() && s.shouldExecute())
.collect(Collectors.toList());
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/package-info.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorOptimizer.java
index b15e4568298..a52a9efea42 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/package-info.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorOptimizer.java
@@ -1,6 +1,6 @@
/*
* SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
+ * Copyright (C) 2009-2018 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
@@ -17,7 +17,16 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-@ParametersAreNonnullByDefault
-package org.sonar.scanner.phases;
+package org.sonar.scanner.sensor;
-import javax.annotation.ParametersAreNonnullByDefault;
+import org.sonar.api.batch.fs.FileSystem;
+import org.sonar.api.batch.rule.ActiveRules;
+import org.sonar.api.config.Configuration;
+
+public class ModuleSensorOptimizer extends AbstractSensorOptimizer {
+
+ public ModuleSensorOptimizer(FileSystem fs, ActiveRules activeRules, Configuration config) {
+ super(fs, activeRules, config);
+ }
+
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/SensorWrapper.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorWrapper.java
index 7779529c67f..541a8bee87e 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/SensorWrapper.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorWrapper.java
@@ -23,20 +23,20 @@ import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
-public class SensorWrapper {
+public class ModuleSensorWrapper {
private final Sensor wrappedSensor;
private final SensorContext context;
private final DefaultSensorDescriptor descriptor;
- private final SensorOptimizer optimizer;
+ private final ModuleSensorOptimizer optimizer;
- public SensorWrapper(Sensor newSensor, SensorContext context, SensorOptimizer optimizer) {
- this.wrappedSensor = newSensor;
+ public ModuleSensorWrapper(Sensor sensor, SensorContext context, ModuleSensorOptimizer optimizer) {
+ this.wrappedSensor = sensor;
this.optimizer = optimizer;
this.context = context;
this.descriptor = new DefaultSensorDescriptor();
- newSensor.describe(this.descriptor);
+ sensor.describe(this.descriptor);
if (descriptor.name() == null) {
- descriptor.name(newSensor.getClass().getName());
+ descriptor.name(sensor.getClass().getName());
}
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/SensorsExecutor.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorsExecutor.java
index 002ebf4207a..ba78bb1a758 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/SensorsExecutor.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorsExecutor.java
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-package org.sonar.scanner.phases;
+package org.sonar.scanner.sensor;
import java.util.ArrayList;
import java.util.Collection;
@@ -29,20 +29,18 @@ import org.sonar.api.batch.fs.internal.SensorStrategy;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.core.util.logs.Profiler;
-import org.sonar.scanner.bootstrap.SensorExtensionDictionnary;
import org.sonar.scanner.bootstrap.ScannerPluginRepository;
-import org.sonar.scanner.sensor.SensorWrapper;
-public class SensorsExecutor {
- private static final Logger LOG = Loggers.get(SensorsExecutor.class);
+public class ModuleSensorsExecutor {
+ private static final Logger LOG = Loggers.get(ModuleSensorsExecutor.class);
private static final Profiler profiler = Profiler.create(LOG);
- private final SensorExtensionDictionnary selector;
+ private final ModuleSensorExtensionDictionnary selector;
private final SensorStrategy strategy;
private final ScannerPluginRepository pluginRepo;
private final boolean isRoot;
- public SensorsExecutor(SensorExtensionDictionnary selector, DefaultInputModule module, InputModuleHierarchy hierarchy,
- SensorStrategy strategy, ScannerPluginRepository pluginRepo) {
+ public ModuleSensorsExecutor(ModuleSensorExtensionDictionnary selector, DefaultInputModule module, InputModuleHierarchy hierarchy,
+ SensorStrategy strategy, ScannerPluginRepository pluginRepo) {
this.selector = selector;
this.strategy = strategy;
this.pluginRepo = pluginRepo;
@@ -50,22 +48,22 @@ public class SensorsExecutor {
}
public void execute() {
- Collection<SensorWrapper> moduleSensors = new ArrayList<>();
+ Collection<ModuleSensorWrapper> moduleSensors = new ArrayList<>();
withModuleStrategy(() -> moduleSensors.addAll(selector.selectSensors(false)));
- Collection<SensorWrapper> globalSensors = new ArrayList<>();
+ Collection<ModuleSensorWrapper> deprecatedGlobalSensors = new ArrayList<>();
if (isRoot) {
- globalSensors.addAll(selector.selectSensors(true));
+ deprecatedGlobalSensors.addAll(selector.selectSensors(true));
}
- printSensors(moduleSensors, globalSensors);
+ printSensors(moduleSensors, deprecatedGlobalSensors);
withModuleStrategy(() -> execute(moduleSensors));
if (isRoot) {
- execute(globalSensors);
+ execute(deprecatedGlobalSensors);
}
}
- private void printSensors(Collection<SensorWrapper> moduleSensors, Collection<SensorWrapper> globalSensors) {
+ private void printSensors(Collection<ModuleSensorWrapper> moduleSensors, Collection<ModuleSensorWrapper> globalSensors) {
String sensors = Stream
.concat(moduleSensors.stream(), globalSensors.stream())
.map(Object::toString)
@@ -80,8 +78,8 @@ public class SensorsExecutor {
strategy.setGlobal(orig);
}
- private void execute(Collection<SensorWrapper> sensors) {
- for (SensorWrapper sensor : sensors) {
+ private void execute(Collection<ModuleSensorWrapper> sensors) {
+ for (ModuleSensorWrapper sensor : sensors) {
String sensorName = getSensorName(sensor);
profiler.startInfo("Sensor " + sensorName);
sensor.analyse();
@@ -89,7 +87,7 @@ public class SensorsExecutor {
}
}
- private String getSensorName(SensorWrapper sensor) {
+ private String getSensorName(ModuleSensorWrapper sensor) {
ClassLoader cl = getSensorClassLoader(sensor);
String pluginKey = pluginRepo.getPluginKey(cl);
if (pluginKey != null) {
@@ -98,7 +96,7 @@ public class SensorsExecutor {
return sensor.toString();
}
- private static ClassLoader getSensorClassLoader(SensorWrapper sensor) {
+ private static ClassLoader getSensorClassLoader(ModuleSensorWrapper sensor) {
return sensor.wrappedSensor().getClass().getClassLoader();
}
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorContext.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorContext.java
index a151e90c60c..ba2418dd296 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorContext.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorContext.java
@@ -63,7 +63,7 @@ import org.sonar.scanner.sensor.noop.NoOpNewSignificantCode;
import org.sonar.scanner.sensor.noop.NoOpNewSymbolTable;
@ThreadSafe
-public class DefaultSensorContext implements SensorContext {
+public class ProjectSensorContext implements SensorContext {
static final NoOpNewHighlighting NO_OP_NEW_HIGHLIGHTING = new NoOpNewHighlighting();
static final NoOpNewSymbolTable NO_OP_NEW_SYMBOL_TABLE = new NoOpNewSymbolTable();
@@ -79,14 +79,12 @@ public class DefaultSensorContext implements SensorContext {
private final SensorStorage sensorStorage;
private final AnalysisMode analysisMode;
private final DefaultInputProject project;
- private final InputModule module;
private final SonarRuntime sonarRuntime;
private final Configuration config;
- public DefaultSensorContext(DefaultInputProject project, InputModule module, Configuration config, Settings mutableSettings, FileSystem fs, ActiveRules activeRules,
+ public ProjectSensorContext(DefaultInputProject project, Configuration config, Settings mutableSettings, FileSystem fs, ActiveRules activeRules,
AnalysisMode analysisMode, SensorStorage sensorStorage, SonarRuntime sonarRuntime) {
this.project = project;
- this.module = module;
this.config = config;
this.mutableSettings = mutableSettings;
this.fs = fs;
@@ -118,7 +116,7 @@ public class DefaultSensorContext implements SensorContext {
@Override
public InputModule module() {
- return module;
+ throw new UnsupportedOperationException("No modules for global Sensors");
}
@Override
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorExtensionDictionnary.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorExtensionDictionnary.java
new file mode 100644
index 00000000000..34a05fe0933
--- /dev/null
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorExtensionDictionnary.java
@@ -0,0 +1,48 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.scanner.sensor;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.sonar.api.batch.sensor.SensorContext;
+import org.sonar.api.scanner.sensor.Sensor;
+import org.sonar.core.platform.ComponentContainer;
+import org.sonar.scanner.bootstrap.AbstractExtensionDictionnary;
+
+public class ProjectSensorExtensionDictionnary extends AbstractExtensionDictionnary {
+
+ private final SensorContext sensorContext;
+ private final AbstractSensorOptimizer sensorOptimizer;
+
+ public ProjectSensorExtensionDictionnary(ComponentContainer componentContainer, ProjectSensorContext sensorContext, ProjectSensorOptimizer sensorOptimizer) {
+ super(componentContainer);
+ this.sensorContext = sensorContext;
+ this.sensorOptimizer = sensorOptimizer;
+ }
+
+ public List<ProjectSensorWrapper> selectSensors() {
+ Collection<Sensor> result = sort(getFilteredExtensions(Sensor.class, null));
+ return result.stream()
+ .map(s -> new ProjectSensorWrapper(s, sensorContext, sensorOptimizer))
+ .filter(s -> s.shouldExecute())
+ .collect(Collectors.toList());
+ }
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorOptimizer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorOptimizer.java
new file mode 100644
index 00000000000..bbf4f78c8ec
--- /dev/null
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorOptimizer.java
@@ -0,0 +1,32 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.scanner.sensor;
+
+import org.sonar.api.batch.rule.ActiveRules;
+import org.sonar.scanner.scan.ProjectConfiguration;
+import org.sonar.scanner.scan.filesystem.DefaultProjectFileSystem;
+
+public class ProjectSensorOptimizer extends AbstractSensorOptimizer {
+
+ public ProjectSensorOptimizer(DefaultProjectFileSystem fs, ActiveRules activeRules, ProjectConfiguration config) {
+ super(fs, activeRules, config);
+ }
+
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorWrapper.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorWrapper.java
new file mode 100644
index 00000000000..b8463937f31
--- /dev/null
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorWrapper.java
@@ -0,0 +1,60 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.scanner.sensor;
+
+import org.sonar.api.batch.sensor.SensorContext;
+import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
+import org.sonar.api.scanner.sensor.Sensor;
+
+public class ProjectSensorWrapper {
+ private final Sensor wrappedSensor;
+ private final SensorContext context;
+ private final DefaultSensorDescriptor descriptor;
+ private final AbstractSensorOptimizer optimizer;
+
+ public ProjectSensorWrapper(Sensor sensor, SensorContext context, AbstractSensorOptimizer optimizer) {
+ this.wrappedSensor = sensor;
+ this.optimizer = optimizer;
+ this.context = context;
+ this.descriptor = new DefaultSensorDescriptor();
+ sensor.describe(this.descriptor);
+ if (descriptor.name() == null) {
+ descriptor.name(sensor.getClass().getName());
+ }
+ }
+
+ public boolean shouldExecute() {
+ return optimizer.shouldExecute(descriptor);
+ }
+
+ public void analyse() {
+ wrappedSensor.execute(context);
+ }
+
+ public Sensor wrappedSensor() {
+ return wrappedSensor;
+ }
+
+ @Override
+ public String toString() {
+ return descriptor.name();
+ }
+
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorsExecutor.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorsExecutor.java
new file mode 100644
index 00000000000..0938792dc1b
--- /dev/null
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorsExecutor.java
@@ -0,0 +1,66 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.scanner.sensor;
+
+import java.util.List;
+import java.util.stream.Collectors;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
+import org.sonar.core.util.logs.Profiler;
+import org.sonar.scanner.bootstrap.ScannerPluginRepository;
+
+public class ProjectSensorsExecutor {
+ private static final Logger LOG = Loggers.get(ProjectSensorsExecutor.class);
+ private static final Profiler profiler = Profiler.create(LOG);
+ private final ProjectSensorExtensionDictionnary selector;
+ private final ScannerPluginRepository pluginRepo;
+
+ public ProjectSensorsExecutor(ProjectSensorExtensionDictionnary selector, ScannerPluginRepository pluginRepo) {
+ this.selector = selector;
+ this.pluginRepo = pluginRepo;
+ }
+
+ public void execute() {
+ List<ProjectSensorWrapper> sensors = selector.selectSensors();
+
+ LOG.debug("Sensors : {}", sensors.stream()
+ .map(Object::toString)
+ .collect(Collectors.joining(" -> ")));
+ for (ProjectSensorWrapper sensor : sensors) {
+ String sensorName = getSensorName(sensor);
+ profiler.startInfo("Sensor " + sensorName);
+ sensor.analyse();
+ profiler.stopInfo();
+ }
+ }
+
+ private String getSensorName(ProjectSensorWrapper sensor) {
+ ClassLoader cl = getSensorClassLoader(sensor);
+ String pluginKey = pluginRepo.getPluginKey(cl);
+ if (pluginKey != null) {
+ return sensor.toString() + " [" + pluginKey + "]";
+ }
+ return sensor.toString();
+ }
+
+ private static ClassLoader getSensorClassLoader(ProjectSensorWrapper sensor) {
+ return sensor.wrappedSensor().getClass().getClassLoader();
+ }
+}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/SensorExtensionDictionnaryTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ModuleSensorExtensionDictionnaryTest.java
index b922b3a99ad..4d63704cae0 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/SensorExtensionDictionnaryTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ModuleSensorExtensionDictionnaryTest.java
@@ -35,9 +35,10 @@ import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.SensorDescriptor;
import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
import org.sonar.core.platform.ComponentContainer;
-import org.sonar.scanner.sensor.DefaultSensorContext;
-import org.sonar.scanner.sensor.SensorOptimizer;
-import org.sonar.scanner.sensor.SensorWrapper;
+import org.sonar.scanner.sensor.ModuleSensorContext;
+import org.sonar.scanner.sensor.ModuleSensorExtensionDictionnary;
+import org.sonar.scanner.sensor.ModuleSensorOptimizer;
+import org.sonar.scanner.sensor.ModuleSensorWrapper;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
@@ -45,20 +46,20 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-public class SensorExtensionDictionnaryTest {
- private SensorOptimizer sensorOptimizer = mock(SensorOptimizer.class);
+public class ModuleSensorExtensionDictionnaryTest {
+ private ModuleSensorOptimizer sensorOptimizer = mock(ModuleSensorOptimizer.class);
@Before
public void setUp() {
when(sensorOptimizer.shouldExecute(any(DefaultSensorDescriptor.class))).thenReturn(true);
}
- private SensorExtensionDictionnary newSelector(Object... extensions) {
+ private ModuleSensorExtensionDictionnary newSelector(Object... extensions) {
ComponentContainer iocContainer = new ComponentContainer();
for (Object extension : extensions) {
iocContainer.addSingleton(extension);
}
- return new SensorExtensionDictionnary(iocContainer, mock(DefaultSensorContext.class), sensorOptimizer);
+ return new ModuleSensorExtensionDictionnary(iocContainer, mock(ModuleSensorContext.class), sensorOptimizer);
}
@Test
@@ -66,7 +67,7 @@ public class SensorExtensionDictionnaryTest {
final Sensor sensor1 = new FakeSensor();
final Sensor sensor2 = new FakeSensor();
- SensorExtensionDictionnary selector = newSelector(sensor1, sensor2);
+ ModuleSensorExtensionDictionnary selector = newSelector(sensor1, sensor2);
Collection<Sensor> sensors = selector.select(Sensor.class, true, extension -> extension.equals(sensor1));
assertThat(sensors).contains(sensor1);
assertEquals(1, sensors.size());
@@ -78,7 +79,7 @@ public class SensorExtensionDictionnaryTest {
Sensor sensor2 = new FakeSensor();
FieldDecorated.Decorator decorator = mock(FieldDecorated.Decorator.class);
- SensorExtensionDictionnary selector = newSelector(sensor1, sensor2, decorator);
+ ModuleSensorExtensionDictionnary selector = newSelector(sensor1, sensor2, decorator);
Collection<Sensor> sensors = selector.select(Sensor.class, false, null);
assertThat(sensors).containsOnly(sensor1, sensor2);
@@ -99,7 +100,7 @@ public class SensorExtensionDictionnaryTest {
ComponentContainer child = parent.createChild();
child.addSingleton(c);
- SensorExtensionDictionnary dictionnary = new SensorExtensionDictionnary(child, mock(DefaultSensorContext.class), mock(SensorOptimizer.class));
+ ModuleSensorExtensionDictionnary dictionnary = new ModuleSensorExtensionDictionnary(child, mock(ModuleSensorContext.class), mock(ModuleSensorOptimizer.class));
assertThat(dictionnary.select(Sensor.class, true, null)).containsOnly(a, b, c);
}
@@ -109,7 +110,7 @@ public class SensorExtensionDictionnaryTest {
Object b = new MethodDependentOf(a);
Object c = new MethodDependentOf(b);
- SensorExtensionDictionnary selector = newSelector(b, c, a);
+ ModuleSensorExtensionDictionnary selector = newSelector(b, c, a);
List<Object> extensions = Lists.newArrayList(selector.select(Marker.class, true, null));
assertThat(extensions).hasSize(3);
@@ -123,7 +124,7 @@ public class SensorExtensionDictionnaryTest {
Object a = new GeneratesSomething("foo");
Object b = new MethodDependentOf("foo");
- SensorExtensionDictionnary selector = newSelector(a, b);
+ ModuleSensorExtensionDictionnary selector = newSelector(a, b);
List<Object> extensions = Lists.newArrayList(selector.select(Marker.class, true, null));
assertThat(extensions.size()).isEqualTo(2);
@@ -144,7 +145,7 @@ public class SensorExtensionDictionnaryTest {
Object a = new GeneratesSomething("foo");
Object b = new MethodDependentOf(Arrays.asList("foo"));
- SensorExtensionDictionnary selector = newSelector(a, b);
+ ModuleSensorExtensionDictionnary selector = newSelector(a, b);
List<Object> extensions = Lists.newArrayList(selector.select(Marker.class, true, null));
assertThat(extensions).hasSize(2);
@@ -165,7 +166,7 @@ public class SensorExtensionDictionnaryTest {
Object a = new GeneratesSomething("foo");
Object b = new MethodDependentOf(new String[] {"foo"});
- SensorExtensionDictionnary selector = newSelector(a, b);
+ ModuleSensorExtensionDictionnary selector = newSelector(a, b);
List<Object> extensions = Lists.newArrayList(selector.select(Marker.class, true, null));
assertThat(extensions).hasSize(2);
@@ -186,7 +187,7 @@ public class SensorExtensionDictionnaryTest {
Object a = new ClassDependedUpon();
Object b = new ClassDependsUpon();
- SensorExtensionDictionnary selector = newSelector(a, b);
+ ModuleSensorExtensionDictionnary selector = newSelector(a, b);
List<Object> extensions = Lists.newArrayList(selector.select(Marker.class, true, null));
assertThat(extensions).hasSize(2);
@@ -209,7 +210,7 @@ public class SensorExtensionDictionnaryTest {
Object b = new InterfaceDependsUpon() {
};
- SensorExtensionDictionnary selector = newSelector(a, b);
+ ModuleSensorExtensionDictionnary selector = newSelector(a, b);
List<Object> extensions = Lists.newArrayList(selector.select(Marker.class, true, null));
assertThat(extensions).hasSize(2);
@@ -230,7 +231,7 @@ public class SensorExtensionDictionnaryTest {
Object a = new SubClass("foo");
Object b = new MethodDependentOf("foo");
- SensorExtensionDictionnary selector = newSelector(b, a);
+ ModuleSensorExtensionDictionnary selector = newSelector(b, a);
List<Object> extensions = Lists.newArrayList(selector.select(Marker.class, true, null));
assertThat(extensions).hasSize(2);
@@ -248,7 +249,7 @@ public class SensorExtensionDictionnaryTest {
@Test(expected = IllegalStateException.class)
public void annotatedMethodsCanNotBePrivate() {
- SensorExtensionDictionnary selector = newSelector();
+ ModuleSensorExtensionDictionnary selector = newSelector();
Object wrong = new Object() {
@DependsUpon
private Object foo() {
@@ -264,7 +265,7 @@ public class SensorExtensionDictionnaryTest {
NormalSensor normal = new NormalSensor();
PostSensor post = new PostSensor();
- SensorExtensionDictionnary selector = newSelector(normal, post, pre);
+ ModuleSensorExtensionDictionnary selector = newSelector(normal, post, pre);
assertThat(selector.selectSensors(false)).extracting("wrappedSensor").containsExactly(pre, normal, post);
}
@@ -274,7 +275,7 @@ public class SensorExtensionDictionnaryTest {
NormalSensor normal = new NormalSensor();
PostSensorSubclass post = new PostSensorSubclass();
- SensorExtensionDictionnary selector = newSelector(normal, post, pre);
+ ModuleSensorExtensionDictionnary selector = newSelector(normal, post, pre);
List extensions = Lists.newArrayList(selector.select(Sensor.class, true, null));
assertThat(extensions).containsExactly(pre, normal, post);
@@ -284,10 +285,10 @@ public class SensorExtensionDictionnaryTest {
public void selectSensors() {
FakeSensor nonGlobalSensor = new FakeSensor();
FakeGlobalSensor globalSensor = new FakeGlobalSensor();
- SensorExtensionDictionnary selector = newSelector(nonGlobalSensor, globalSensor);
+ ModuleSensorExtensionDictionnary selector = newSelector(nonGlobalSensor, globalSensor);
// verify non-global sensor
- Collection<SensorWrapper> extensions = selector.selectSensors(false);
+ Collection<ModuleSensorWrapper> extensions = selector.selectSensors(false);
assertThat(extensions).hasSize(1);
assertThat(extensions).extracting("wrappedSensor").containsExactly(nonGlobalSensor);
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java
index 6c2f47ff34c..608028aad12 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java
@@ -42,6 +42,7 @@ import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.scanner.mediumtest.AnalysisResult;
import org.sonar.scanner.mediumtest.ScannerMediumTester;
import org.sonar.xoo.XooPlugin;
+import org.sonar.xoo.global.DeprecatedGlobalSensor;
import org.sonar.xoo.global.GlobalSensor;
import org.sonar.xoo.rule.XooRulesDefinition;
@@ -723,6 +724,22 @@ public class FileSystemMediumTest {
}
@Test
+ public void deprecated_global_sensor_should_see_project_relative_paths() {
+ File projectDir = new File("test-resources/mediumtest/xoo/multi-modules-sample");
+ AnalysisResult result = tester
+ .newAnalysis(new File(projectDir, "sonar-project.properties"))
+ .property(DeprecatedGlobalSensor.ENABLE_PROP, "true")
+ .execute();
+
+ assertThat(result.inputFiles()).hasSize(4);
+ assertThat(logTester.logs(LoggerLevel.INFO)).contains(
+ "Deprecated Global Sensor: module_a/module_a1/src/main/xoo/com/sonar/it/samples/modules/a1/HelloA1.xoo",
+ "Deprecated Global Sensor: module_a/module_a2/src/main/xoo/com/sonar/it/samples/modules/a2/HelloA2.xoo",
+ "Deprecated Global Sensor: module_b/module_b1/src/main/xoo/com/sonar/it/samples/modules/b1/HelloB1.xoo",
+ "Deprecated Global Sensor: module_b/module_b2/src/main/xoo/com/sonar/it/samples/modules/b2/HelloB2.xoo");
+ }
+
+ @Test
public void global_sensor_should_see_project_relative_paths() {
File projectDir = new File("test-resources/mediumtest/xoo/multi-modules-sample");
AnalysisResult result = tester
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/ModuleCoverageExclusionsTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/ModuleCoverageExclusionsTest.java
index 6be5efa45a9..88c746ba89a 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/ModuleCoverageExclusionsTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/ModuleCoverageExclusionsTest.java
@@ -31,6 +31,7 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
import org.sonar.scanner.scan.ModuleConfiguration;
+import org.sonar.scanner.scan.filesystem.ModuleCoverageExclusions;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/SensorsExecutorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/ModuleSensorsExecutorTest.java
index de31e20e3c3..c715462d0ca 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/SensorsExecutorTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/ModuleSensorsExecutorTest.java
@@ -31,9 +31,10 @@ import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
import org.sonar.api.batch.fs.internal.SensorStrategy;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
import org.sonar.api.batch.sensor.Sensor;
-import org.sonar.scanner.bootstrap.SensorExtensionDictionnary;
+import org.sonar.scanner.sensor.ModuleSensorExtensionDictionnary;
import org.sonar.scanner.bootstrap.ScannerPluginRepository;
-import org.sonar.scanner.sensor.SensorWrapper;
+import org.sonar.scanner.sensor.ModuleSensorsExecutor;
+import org.sonar.scanner.sensor.ModuleSensorWrapper;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -41,17 +42,17 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
-public class SensorsExecutorTest {
+public class ModuleSensorsExecutorTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
- private SensorsExecutor rootModuleExecutor;
- private SensorsExecutor subModuleExecutor;
+ private ModuleSensorsExecutor rootModuleExecutor;
+ private ModuleSensorsExecutor subModuleExecutor;
private SensorStrategy strategy = new SensorStrategy();
- private SensorWrapper perModuleSensor = mock(SensorWrapper.class);
- private SensorWrapper globalSensor = mock(SensorWrapper.class);
+ private ModuleSensorWrapper perModuleSensor = mock(ModuleSensorWrapper.class);
+ private ModuleSensorWrapper globalSensor = mock(ModuleSensorWrapper.class);
private ScannerPluginRepository pluginRepository = mock(ScannerPluginRepository.class);
@Before
@@ -64,7 +65,7 @@ public class SensorsExecutorTest {
when(globalSensor.shouldExecute()).thenReturn(true);
when(globalSensor.wrappedSensor()).thenReturn(mock(Sensor.class));
- SensorExtensionDictionnary selector = mock(SensorExtensionDictionnary.class);
+ ModuleSensorExtensionDictionnary selector = mock(ModuleSensorExtensionDictionnary.class);
when(selector.selectSensors(false)).thenReturn(Collections.singleton(perModuleSensor));
when(selector.selectSensors(true)).thenReturn(Collections.singleton(globalSensor));
@@ -77,8 +78,8 @@ public class SensorsExecutorTest {
InputModuleHierarchy hierarchy = mock(InputModuleHierarchy.class);
when(hierarchy.isRoot(rootModule)).thenReturn(true);
- rootModuleExecutor = new SensorsExecutor(selector, rootModule, hierarchy, strategy, pluginRepository);
- subModuleExecutor = new SensorsExecutor(selector, subModule, hierarchy, strategy, pluginRepository);
+ rootModuleExecutor = new ModuleSensorsExecutor(selector, rootModule, hierarchy, strategy, pluginRepository);
+ subModuleExecutor = new ModuleSensorsExecutor(selector, subModule, hierarchy, strategy, pluginRepository);
}
@Test
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/ProjectCoverageExclusionsTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/ProjectCoverageExclusionsTest.java
index e55df705a6d..822c44b6c03 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/ProjectCoverageExclusionsTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/ProjectCoverageExclusionsTest.java
@@ -27,6 +27,7 @@ import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
import org.sonar.scanner.scan.ProjectConfiguration;
+import org.sonar.scanner.scan.filesystem.ProjectCoverageExclusions;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorContextTest.java
index 1c7d17b4e13..3a939bd3f7b 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorContextTest.java
@@ -40,7 +40,6 @@ import org.sonar.api.batch.sensor.internal.SensorStorage;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.internal.SonarRuntimeImpl;
import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.scanner.fs.InputProject;
import org.sonar.api.utils.Version;
import org.sonar.scanner.scan.DefaultInputModuleHierarchy;
@@ -48,7 +47,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-public class DefaultSensorContextTest {
+public class ModuleSensorContextTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
@@ -58,7 +57,7 @@ public class DefaultSensorContextTest {
private ActiveRules activeRules;
private DefaultFileSystem fs;
- private DefaultSensorContext adaptor;
+ private ModuleSensorContext adaptor;
private MapSettings settings;
private SensorStorage sensorStorage;
private AnalysisMode analysisMode;
@@ -79,7 +78,7 @@ public class DefaultSensorContextTest {
hierarchy = new DefaultInputModuleHierarchy(new DefaultInputModule(ProjectDefinition.create()
.setWorkDir(temp.newFolder())
.setBaseDir(temp.newFolder()).setKey("foo")));
- adaptor = new DefaultSensorContext(mock(DefaultInputProject.class), mock(InputModule.class), settings.asConfig(), settings, fs, activeRules, analysisMode, sensorStorage, runtime);
+ adaptor = new ModuleSensorContext(mock(DefaultInputProject.class), mock(InputModule.class), settings.asConfig(), settings, fs, activeRules, analysisMode, sensorStorage, runtime);
}
@Test
@@ -94,7 +93,7 @@ public class DefaultSensorContextTest {
assertThat(adaptor.newExternalIssue()).isNotNull();
assertThat(adaptor.newAdHocRule()).isNotNull();
assertThat(adaptor.newMeasure()).isNotNull();
- assertThat(adaptor.newAnalysisError()).isEqualTo(DefaultSensorContext.NO_OP_NEW_ANALYSIS_ERROR);
+ assertThat(adaptor.newAnalysisError()).isEqualTo(ModuleSensorContext.NO_OP_NEW_ANALYSIS_ERROR);
assertThat(adaptor.isCancelled()).isFalse();
assertThat(adaptor.newSignificantCode()).isNotNull();
}
@@ -102,7 +101,7 @@ public class DefaultSensorContextTest {
@Test
public void shouldSkipSignificantCodeOnPreviewMode() {
when(analysisMode.isIssues()).thenReturn(true);
- assertThat(adaptor.newSignificantCode()).isEqualTo(DefaultSensorContext.NO_OP_NEW_SIGNIFICANT_CODE);
+ assertThat(adaptor.newSignificantCode()).isEqualTo(ModuleSensorContext.NO_OP_NEW_SIGNIFICANT_CODE);
}
@@ -110,16 +109,16 @@ public class DefaultSensorContextTest {
public void shouldSkipSeveralObjectsInPreviewMode() {
when(analysisMode.isIssues()).thenReturn(true);
when(analysisMode.isPreview()).thenReturn(true);
- assertThat(adaptor.newCpdTokens()).isEqualTo(DefaultSensorContext.NO_OP_NEW_CPD_TOKENS);
- assertThat(adaptor.newSymbolTable()).isEqualTo(DefaultSensorContext.NO_OP_NEW_SYMBOL_TABLE);
- assertThat(adaptor.newExternalIssue()).isEqualTo(DefaultSensorContext.NO_OP_NEW_EXTERNAL_ISSUE);
- assertThat(adaptor.newAdHocRule()).isEqualTo(DefaultSensorContext.NO_OP_NEW_AD_HOC_RULE);
- assertThat(adaptor.newHighlighting()).isEqualTo(DefaultSensorContext.NO_OP_NEW_HIGHLIGHTING);
+ assertThat(adaptor.newCpdTokens()).isEqualTo(ModuleSensorContext.NO_OP_NEW_CPD_TOKENS);
+ assertThat(adaptor.newSymbolTable()).isEqualTo(ModuleSensorContext.NO_OP_NEW_SYMBOL_TABLE);
+ assertThat(adaptor.newExternalIssue()).isEqualTo(ModuleSensorContext.NO_OP_NEW_EXTERNAL_ISSUE);
+ assertThat(adaptor.newAdHocRule()).isEqualTo(ModuleSensorContext.NO_OP_NEW_AD_HOC_RULE);
+ assertThat(adaptor.newHighlighting()).isEqualTo(ModuleSensorContext.NO_OP_NEW_HIGHLIGHTING);
}
@Test
public void shouldSkipDupsOnIssuesMode() {
when(analysisMode.isIssues()).thenReturn(true);
- assertThat(adaptor.newCpdTokens()).isEqualTo(DefaultSensorContext.NO_OP_NEW_CPD_TOKENS);
+ assertThat(adaptor.newCpdTokens()).isEqualTo(ModuleSensorContext.NO_OP_NEW_CPD_TOKENS);
}
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/SensorOptimizerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorOptimizerTest.java
index ff53dd278a5..7c5fe360a59 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/SensorOptimizerTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorOptimizerTest.java
@@ -36,7 +36,7 @@ import org.sonar.api.rule.RuleKey;
import static org.assertj.core.api.Assertions.assertThat;
-public class SensorOptimizerTest {
+public class ModuleSensorOptimizerTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
@@ -45,14 +45,14 @@ public class SensorOptimizerTest {
public ExpectedException thrown = ExpectedException.none();
private DefaultFileSystem fs;
- private SensorOptimizer optimizer;
+ private ModuleSensorOptimizer optimizer;
private MapSettings settings;
@Before
public void prepare() throws Exception {
fs = new DefaultFileSystem(temp.newFolder().toPath());
settings = new MapSettings();
- optimizer = new SensorOptimizer(fs, new ActiveRulesBuilder().build(), settings.asConfig());
+ optimizer = new ModuleSensorOptimizer(fs, new ActiveRulesBuilder().build(), settings.asConfig());
}
@Test
@@ -109,7 +109,7 @@ public class SensorOptimizerTest {
ActiveRules activeRules = new ActiveRulesBuilder()
.addRule(new NewActiveRule.Builder().setRuleKey(RuleKey.of("repo1", "foo")).build())
.build();
- optimizer = new SensorOptimizer(fs, activeRules, settings.asConfig());
+ optimizer = new ModuleSensorOptimizer(fs, activeRules, settings.asConfig());
assertThat(optimizer.shouldExecute(descriptor)).isFalse();
@@ -117,7 +117,7 @@ public class SensorOptimizerTest {
.addRule(new NewActiveRule.Builder().setRuleKey(RuleKey.of("repo1", "foo")).build())
.addRule(new NewActiveRule.Builder().setRuleKey(RuleKey.of("squid", "rule")).build())
.build();
- optimizer = new SensorOptimizer(fs, activeRules, settings.asConfig());
+ optimizer = new ModuleSensorOptimizer(fs, activeRules, settings.asConfig());
assertThat(optimizer.shouldExecute(descriptor)).isTrue();
}