aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2018-12-05 10:23:09 +0100
committersonartech <sonartech@sonarsource.com>2019-01-16 09:43:06 +0100
commit532850a387e483592e6f2f80a5e833bcf218a58f (patch)
treebb504874ef6a1f36059113c962132e27660cb33f /sonar-scanner-engine
parent55579a4572f8233957275c896139cb1dfedd2622 (diff)
downloadsonarqube-532850a387e483592e6f2f80a5e833bcf218a58f.tar.gz
sonarqube-532850a387e483592e6f2f80a5e833bcf218a58f.zip
Fix quality flaws
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/AbstractExtensionDictionnary.java4
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchComponents.java2
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/JavaCpdBlockIndexerSensor.java3
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/report/AnalysisContextReportPublisher.java5
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoader.java40
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleConfigurationProvider.java7
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleIndexer.java1
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectConfigurationProvider.java4
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java8
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java4
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectFileIndexer.java15
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/AbstractSensorWrapper.java63
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorExtensionDictionnary.java5
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorWrapper.java40
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorExtensionDictionnary.java11
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorWrapper.java38
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/DefaultFileLinesContextTest.java4
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java4
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java5
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileVerifierTest.java4
20 files changed, 120 insertions, 147 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 d4733375ba8..240c2c4da65 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
@@ -64,9 +64,9 @@ public abstract class AbstractExtensionDictionnary {
protected <T> List<T> getFilteredExtensions(Class<T> type, @Nullable ExtensionMatcher matcher) {
List<T> result = new ArrayList<>();
- for (Object extension : getExtensions(type)) {
+ for (T extension : getExtensions(type)) {
if (shouldKeep(type, extension, matcher)) {
- result.add((T) extension);
+ result.add(extension);
}
}
return result;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchComponents.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchComponents.java
index d5487c990ca..e9005b92353 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchComponents.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchComponents.java
@@ -25,6 +25,7 @@ import java.util.List;
import org.sonar.core.component.DefaultResourceTypes;
import org.sonar.core.config.CorePropertyDefinitions;
import org.sonar.core.issue.tracking.Tracker;
+import org.sonar.scanner.cpd.JavaCpdBlockIndexerSensor;
import org.sonar.scanner.externalissue.ExternalIssuesImportSensor;
import org.sonar.scanner.genericcoverage.GenericCoverageSensor;
import org.sonar.scanner.genericcoverage.GenericTestExecutionSensor;
@@ -44,6 +45,7 @@ public class BatchComponents {
components.addAll(CorePropertyDefinitions.all());
if (!analysisMode.isIssues()) {
components.add(ZeroCoverageSensor.class);
+ components.add(JavaCpdBlockIndexerSensor.class);
// Generic coverage
components.add(GenericCoverageSensor.class);
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/JavaCpdBlockIndexerSensor.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/JavaCpdBlockIndexerSensor.java
index defff497883..5770e8869ab 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/JavaCpdBlockIndexerSensor.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/JavaCpdBlockIndexerSensor.java
@@ -61,8 +61,7 @@ public class JavaCpdBlockIndexerSensor implements Sensor {
@Override
public void describe(SensorDescriptor descriptor) {
descriptor.name("Java CPD Block Indexer")
- .onlyOnLanguage("java")
- .global();
+ .onlyOnLanguage("java");
}
@Override
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/AnalysisContextReportPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/AnalysisContextReportPublisher.java
index 5c60eb4e2d2..ebb8a8facaa 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/AnalysisContextReportPublisher.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/AnalysisContextReportPublisher.java
@@ -64,10 +64,8 @@ public class AnalysisContextReportPublisher {
private final InputModuleHierarchy hierarchy;
private final InputComponentStore store;
- private ScannerReportWriter writer;
-
public AnalysisContextReportPublisher(ProjectServerSettings projectServerSettings, AnalysisMode mode, ScannerPluginRepository pluginRepo, System2 system,
- GlobalServerSettings globalServerSettings, InputModuleHierarchy hierarchy, InputComponentStore store) {
+ GlobalServerSettings globalServerSettings, InputModuleHierarchy hierarchy, InputComponentStore store) {
this.projectServerSettings = projectServerSettings;
this.mode = mode;
this.pluginRepo = pluginRepo;
@@ -81,7 +79,6 @@ public class AnalysisContextReportPublisher {
if (mode.isIssues()) {
return;
}
- this.writer = writer;
File analysisLog = writer.getFileStructure().analysisLog();
try (BufferedWriter fileWriter = Files.newBufferedWriter(analysisLog.toPath(), StandardCharsets.UTF_8)) {
if (LOG.isDebugEnabled()) {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoader.java
index 8a7d8c7f1e0..85e71d87100 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoader.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoader.java
@@ -27,7 +27,6 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
-import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.utils.MessageException;
@@ -51,8 +50,11 @@ public class DefaultProjectRepositoriesLoader implements ProjectRepositoriesLoad
public ProjectRepositories load(String projectKey, boolean issuesMode, @Nullable String branchBase) {
GetRequest request = new GetRequest(getUrl(projectKey, issuesMode, branchBase));
try (WsResponse response = wsClient.call(request)) {
- InputStream is = response.contentStream();
- return processStream(is, projectKey);
+ try (InputStream is = response.contentStream()) {
+ return processStream(is);
+ } catch (IOException e) {
+ throw new IllegalStateException("Couldn't load project repository for " + projectKey, e);
+ }
} catch (RuntimeException e) {
if (shouldThrow(e)) {
throw e;
@@ -91,26 +93,20 @@ public class DefaultProjectRepositoriesLoader implements ProjectRepositoriesLoad
return false;
}
- private ProjectRepositories processStream(InputStream is, String projectKey) {
- try {
- WsProjectResponse response = WsProjectResponse.parseFrom(is);
- if (response.getFileDataByModuleAndPathCount() == 0) {
- return new SingleProjectRepository(constructFileDataMap(response.getFileDataByPathMap()), new Date(response.getLastAnalysisDate()));
- } else {
- final Map<String, SingleProjectRepository> repositoriesPerModule = new HashMap<>();
- response.getFileDataByModuleAndPathMap().keySet().forEach(moduleKey -> {
- WsProjectResponse.FileDataByPath filePaths = response.getFileDataByModuleAndPathMap().get(moduleKey);
- repositoriesPerModule.put(moduleKey, new SingleProjectRepository(
- constructFileDataMap(filePaths.getFileDataByPathMap()), new Date(response.getLastAnalysisDate())));
- });
- return new MultiModuleProjectRepository(repositoriesPerModule, new Date(response.getLastAnalysisDate()));
- }
-
- } catch (IOException e) {
- throw new IllegalStateException("Couldn't load project repository for " + projectKey, e);
- } finally {
- IOUtils.closeQuietly(is);
+ private static ProjectRepositories processStream(InputStream is) throws IOException {
+ WsProjectResponse response = WsProjectResponse.parseFrom(is);
+ if (response.getFileDataByModuleAndPathCount() == 0) {
+ return new SingleProjectRepository(constructFileDataMap(response.getFileDataByPathMap()), new Date(response.getLastAnalysisDate()));
+ } else {
+ final Map<String, SingleProjectRepository> repositoriesPerModule = new HashMap<>();
+ response.getFileDataByModuleAndPathMap().keySet().forEach(moduleKey -> {
+ WsProjectResponse.FileDataByPath filePaths = response.getFileDataByModuleAndPathMap().get(moduleKey);
+ repositoriesPerModule.put(moduleKey, new SingleProjectRepository(
+ constructFileDataMap(filePaths.getFileDataByPathMap()), new Date(response.getLastAnalysisDate())));
+ });
+ return new MultiModuleProjectRepository(repositoriesPerModule, new Date(response.getLastAnalysisDate()));
}
+
}
private static Map<String, FileData> constructFileDataMap(Map<String, WsProjectResponse.FileData> content) {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleConfigurationProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleConfigurationProvider.java
index 556d09b9184..a60556dee6c 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleConfigurationProvider.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleConfigurationProvider.java
@@ -28,18 +28,15 @@ import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
import org.sonar.scanner.bootstrap.GlobalConfiguration;
-import org.sonar.scanner.report.AnalysisContextReportPublisher;
public class ModuleConfigurationProvider extends ProviderAdapter {
private ModuleConfiguration moduleConfiguration;
- public ModuleConfiguration provide(GlobalConfiguration globalConfig, DefaultInputModule module, ProjectServerSettings projectServerSettings,
- GlobalAnalysisMode analysisMode, AnalysisContextReportPublisher contextReportPublisher) {
+ public ModuleConfiguration provide(GlobalConfiguration globalConfig, DefaultInputModule module, ProjectServerSettings projectServerSettings, GlobalAnalysisMode analysisMode) {
if (moduleConfiguration == null) {
- Map<String, String> settings = new LinkedHashMap<>();
- settings.putAll(projectServerSettings.properties());
+ Map<String, String> settings = new LinkedHashMap<>(projectServerSettings.properties());
addScannerSideProperties(settings, module.definition());
moduleConfiguration = new ModuleConfiguration(globalConfig.getDefinitions(), globalConfig.getEncryption(), analysisMode, settings);
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleIndexer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleIndexer.java
index 4b85e732f66..da1c14363ca 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleIndexer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleIndexer.java
@@ -20,7 +20,6 @@
package org.sonar.scanner.scan;
import org.picocontainer.Startable;
-import org.sonar.api.batch.fs.internal.AbstractProjectOrModule;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
import org.sonar.scanner.scan.filesystem.InputComponentStore;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectConfigurationProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectConfigurationProvider.java
index 8c774902e88..8f5752d6a36 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectConfigurationProvider.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectConfigurationProvider.java
@@ -31,8 +31,8 @@ public class ProjectConfigurationProvider extends ProviderAdapter {
private ProjectConfiguration projectConfig;
- public ProjectConfiguration provide(DefaultInputProject project, GlobalConfiguration globalConfig, GlobalServerSettings globalServerSettings, ProjectServerSettings projectServerSettings,
- GlobalAnalysisMode mode, MutableProjectSettings projectSettings) {
+ public ProjectConfiguration provide(DefaultInputProject project, GlobalConfiguration globalConfig, GlobalServerSettings globalServerSettings,
+ ProjectServerSettings projectServerSettings, GlobalAnalysisMode mode, MutableProjectSettings projectSettings) {
if (projectConfig == null) {
Map<String, String> settings = new LinkedHashMap<>();
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 295417852b7..b3d656a55c3 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
@@ -261,7 +261,6 @@ public class ProjectScanContainer extends ComponentContainer {
CpdExecutor.class,
CpdSettings.class,
SonarCpdBlockIndex.class,
- JavaCpdBlockIndexerSensor.class,
// PostJobs
PostJobsExecutor.class,
@@ -327,7 +326,12 @@ public class ProjectScanContainer extends ComponentContainer {
@VisibleForTesting
static ExtensionMatcher getScannerProjectExtensionsFilter() {
- return extension -> isScannerSide(extension) || (isDeprecatedScannerSide(extension) && isInstantiationStrategy(extension, PER_BATCH));
+ return extension -> {
+ if (isDeprecatedScannerSide(extension)) {
+ return isInstantiationStrategy(extension, PER_BATCH);
+ }
+ return isScannerSide(extension);
+ };
}
@Override
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 46e60710237..e9721a38add 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
@@ -136,7 +136,7 @@ public class FileIndexer {
issueExclusionsLoader.addMulticriteriaPatterns(inputFile.getProjectRelativePath(), inputFile.key());
}
LOG.debug("'{}' indexed {}with language '{}'", projectRelativePath, type == Type.TEST ? "as test " : "", inputFile.language());
- evaluateCoverageExclusions(module, moduleCoverageExclusions, inputFile);
+ evaluateCoverageExclusions(moduleCoverageExclusions, inputFile);
if (properties.preloadFileMetadata()) {
inputFile.checkMetadata();
}
@@ -151,7 +151,7 @@ public class FileIndexer {
}
}
- private void evaluateCoverageExclusions(DefaultInputModule module, ModuleCoverageExclusions moduleCoverageExclusions, DefaultInputFile inputFile) {
+ private void evaluateCoverageExclusions(ModuleCoverageExclusions moduleCoverageExclusions, DefaultInputFile inputFile) {
boolean excludedByProjectConfiguration = projectCoverageExclusions.isExcluded(inputFile);
if (excludedByProjectConfiguration) {
inputFile.setExcludedForCoverage(true);
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 af87198823f..6663c08ec88 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
@@ -39,7 +39,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.fs.InputFile.Type;
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.util.ProgressReport;
@@ -51,21 +50,17 @@ public class ProjectFileIndexer {
private static final Logger LOG = LoggerFactory.getLogger(ProjectFileIndexer.class);
private final AbstractExclusionFilters projectExclusionFilters;
- private final DefaultInputProject project;
private final InputComponentStore componentStore;
private final InputModuleHierarchy inputModuleHierarchy;
- private final ProjectCoverageExclusions projectCoverageExclusions;
private final FileIndexer fileIndexer;
private ProgressReport progressReport;
- public ProjectFileIndexer(DefaultInputProject project, InputComponentStore componentStore, AbstractExclusionFilters exclusionFilters,
- InputModuleHierarchy inputModuleHierarchy, ProjectCoverageExclusions projectCoverageExclusions,
+ public ProjectFileIndexer(InputComponentStore componentStore, AbstractExclusionFilters exclusionFilters,
+ InputModuleHierarchy inputModuleHierarchy,
FileIndexer fileIndexer) {
- this.project = project;
this.componentStore = componentStore;
this.inputModuleHierarchy = inputModuleHierarchy;
- this.projectCoverageExclusions = projectCoverageExclusions;
this.fileIndexer = fileIndexer;
this.projectExclusionFilters = exclusionFilters;
}
@@ -95,7 +90,7 @@ public class ProjectFileIndexer {
private void index(DefaultInputModule module, AtomicInteger excludedByPatternsCount) {
if (componentStore.allModules().size() > 1) {
LOG.info(" Indexing files from module {}", module.getName());
- LOG.info(" Base dir: {}", module.getBaseDir().toAbsolutePath().toString());
+ LOG.info(" Base dir: {}", module.getBaseDir().toAbsolutePath());
logPaths(" Source paths: ", module.getBaseDir(), module.getSourceDirsOrFiles());
logPaths(" Test paths: ", module.getBaseDir(), module.getTestDirsOrFiles());
}
@@ -108,7 +103,7 @@ public class ProjectFileIndexer {
private static void logPaths(String label, Path baseDir, List<Path> paths) {
if (!paths.isEmpty()) {
StringBuilder sb = new StringBuilder(label);
- for (Iterator<Path> it = paths.iterator(); it.hasNext(); ) {
+ for (Iterator<Path> it = paths.iterator(); it.hasNext();) {
Path file = it.next();
Optional<String> relativePathToBaseDir = PathResolver.relativize(baseDir, file);
if (!relativePathToBaseDir.isPresent()) {
@@ -204,7 +199,7 @@ public class ProjectFileIndexer {
}
@Override
- public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
+ public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
return FileVisitResult.CONTINUE;
}
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/AbstractSensorWrapper.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/AbstractSensorWrapper.java
new file mode 100644
index 00000000000..0d9f8cf4e79
--- /dev/null
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/AbstractSensorWrapper.java
@@ -0,0 +1,63 @@
+/*
+ * 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.ProjectSensor;
+
+public abstract class AbstractSensorWrapper<G extends ProjectSensor> {
+ private final G wrappedSensor;
+ private final SensorContext context;
+ private final DefaultSensorDescriptor descriptor;
+ private final AbstractSensorOptimizer optimizer;
+
+ public AbstractSensorWrapper(G 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 G wrappedSensor() {
+ return wrappedSensor;
+ }
+
+ @Override
+ public String toString() {
+ return descriptor.name();
+ }
+
+ public boolean isGlobal() {
+ return descriptor.isGlobal();
+ }
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorExtensionDictionnary.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorExtensionDictionnary.java
index e90cb636063..ba024b3b60d 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorExtensionDictionnary.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorExtensionDictionnary.java
@@ -22,16 +22,15 @@ 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.bootstrap.AbstractExtensionDictionnary;
public class ModuleSensorExtensionDictionnary extends AbstractExtensionDictionnary {
- private final SensorContext sensorContext;
+ private final ModuleSensorContext sensorContext;
private final ModuleSensorOptimizer sensorOptimizer;
- public ModuleSensorExtensionDictionnary(ComponentContainer componentContainer, SensorContext sensorContext, ModuleSensorOptimizer sensorOptimizer) {
+ public ModuleSensorExtensionDictionnary(ComponentContainer componentContainer, ModuleSensorContext sensorContext, ModuleSensorOptimizer sensorOptimizer) {
super(componentContainer);
this.sensorContext = sensorContext;
this.sensorOptimizer = sensorOptimizer;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorWrapper.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorWrapper.java
index 541a8bee87e..8f968d72397 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorWrapper.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorWrapper.java
@@ -20,44 +20,10 @@
package org.sonar.scanner.sensor;
import org.sonar.api.batch.sensor.Sensor;
-import org.sonar.api.batch.sensor.SensorContext;
-import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
-public class ModuleSensorWrapper {
- private final Sensor wrappedSensor;
- private final SensorContext context;
- private final DefaultSensorDescriptor descriptor;
- private final ModuleSensorOptimizer optimizer;
+public class ModuleSensorWrapper extends AbstractSensorWrapper<Sensor> {
- public ModuleSensorWrapper(Sensor sensor, SensorContext context, ModuleSensorOptimizer 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();
- }
-
- public boolean isGlobal() {
- return descriptor.isGlobal();
+ public ModuleSensorWrapper(Sensor sensor, ModuleSensorContext context, ModuleSensorOptimizer optimizer) {
+ super(sensor, context, optimizer);
}
}
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
index 34a05fe0933..47e6b3720a6 100644
--- 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
@@ -22,15 +22,14 @@ 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.api.scanner.sensor.ProjectSensor;
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;
+ private final ProjectSensorContext sensorContext;
+ private final ProjectSensorOptimizer sensorOptimizer;
public ProjectSensorExtensionDictionnary(ComponentContainer componentContainer, ProjectSensorContext sensorContext, ProjectSensorOptimizer sensorOptimizer) {
super(componentContainer);
@@ -39,10 +38,10 @@ public class ProjectSensorExtensionDictionnary extends AbstractExtensionDictionn
}
public List<ProjectSensorWrapper> selectSensors() {
- Collection<Sensor> result = sort(getFilteredExtensions(Sensor.class, null));
+ Collection<ProjectSensor> result = sort(getFilteredExtensions(ProjectSensor.class, null));
return result.stream()
.map(s -> new ProjectSensorWrapper(s, sensorContext, sensorOptimizer))
- .filter(s -> s.shouldExecute())
+ .filter(ProjectSensorWrapper::shouldExecute)
.collect(Collectors.toList());
}
}
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
index b8463937f31..97afb6b9f33 100644
--- 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
@@ -19,42 +19,12 @@
*/
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;
+import org.sonar.api.scanner.sensor.ProjectSensor;
-public class ProjectSensorWrapper {
- private final Sensor wrappedSensor;
- private final SensorContext context;
- private final DefaultSensorDescriptor descriptor;
- private final AbstractSensorOptimizer optimizer;
+public class ProjectSensorWrapper extends AbstractSensorWrapper<ProjectSensor> {
- 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();
+ public ProjectSensorWrapper(ProjectSensor sensor, ProjectSensorContext context, ProjectSensorOptimizer optimizer) {
+ super(sensor, context, optimizer);
}
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/DefaultFileLinesContextTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/DefaultFileLinesContextTest.java
index 0983d76d2ae..7d28d497230 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/DefaultFileLinesContextTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/DefaultFileLinesContextTest.java
@@ -24,7 +24,6 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.junit.rules.TemporaryFolder;
import org.mockito.ArgumentCaptor;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
@@ -53,9 +52,6 @@ public class DefaultFileLinesContextTest {
private static final String BRANCHES_METRIC_KEY = "branches";
@Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
- @Rule
public ExpectedException thrown = ExpectedException.none();
private DefaultFileLinesContext fileLineMeasures;
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 211f289ec9f..20f8754b038 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
@@ -43,7 +43,7 @@ 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.global.GlobalProjectSensor;
import org.sonar.xoo.rule.XooRulesDefinition;
import static java.util.stream.Collectors.joining;
@@ -705,7 +705,7 @@ public class FileSystemMediumTest {
File projectDir = new File("test-resources/mediumtest/xoo/multi-modules-sample");
AnalysisResult result = tester
.newAnalysis(new File(projectDir, "sonar-project.properties"))
- .property(GlobalSensor.ENABLE_PROP, "true")
+ .property(GlobalProjectSensor.ENABLE_PROP, "true")
.execute();
assertThat(result.inputFiles()).hasSize(4);
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java
index f9381879df1..b9a9e561c0e 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java
@@ -22,9 +22,7 @@ package org.sonar.scanner.postjob;
import java.io.IOException;
import java.util.Arrays;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
import org.sonar.api.batch.postjob.issue.PostJobIssue;
@@ -41,9 +39,6 @@ import static org.mockito.Mockito.when;
public class DefaultPostJobContextTest {
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
private IssueCache issueCache;
private InputComponentStore componentStore;
private DefaultPostJobContext context;
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileVerifierTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileVerifierTest.java
index 18facbe6391..3b6188f4ca9 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileVerifierTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileVerifierTest.java
@@ -23,7 +23,6 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.junit.rules.TemporaryFolder;
import org.slf4j.Logger;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
import org.sonar.api.config.internal.MapSettings;
@@ -38,9 +37,6 @@ import static org.mockito.Mockito.when;
public class QProfileVerifierTest {
@Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
- @Rule
public ExpectedException thrown = ExpectedException.none();
private InputComponentStore store;