aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/Batch.java7
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java5
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/DefaultFileLinesContext.java12
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/BatchComponents.java6
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalServerSettings.java7
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/MetricProvider.java6
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ProcessedScannerProperties.java4
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/RawScannerProperties.java6
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginRepository.java6
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/CpdExecutor.java8
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/perspectives/ScannerPerspectives.java4
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestCase.java7
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestPlan.java3
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/ExternalIssueImporter.java3
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericCoverageReportParser.java5
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericCoverageSensor.java12
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParser.java6
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericTestExecutionSensor.java7
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssuePublisher.java10
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/AbstractPatternInitializer.java2
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/IssueExclusionPatternInitializer.java10
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/LineRange.java12
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/AnalysisResult.java18
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/notifications/DefaultAnalysisWarnings.java2
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java6
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionPublisher.java3
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ContextPropertiesCache.java2
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoader.java10
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/MultiModuleProjectRepository.java5
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/SingleProjectRepository.java9
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/settings/AbstractSettingsLoader.java4
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/QProfileVerifier.java2
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java12
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java3
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectServerSettings.java7
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/DefaultModuleFileSystem.java2
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/DefaultProjectFileSystem.java2
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/MetadataGenerator.java7
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/measure/DefaultMetricFinder.java6
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/DefaultBlameOutput.java21
40 files changed, 130 insertions, 139 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/Batch.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/Batch.java
index ae16e5c247d..c7da2076698 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/Batch.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/Batch.java
@@ -19,7 +19,6 @@
*/
package org.sonar.batch.bootstrapper;
-import com.google.common.base.Throwables;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -104,11 +103,13 @@ public final class Batch {
return t;
}
- for (Throwable y : Throwables.getCausalChain(t)) {
+ Throwable y = t;
+ do {
if (y instanceof MessageException) {
return (MessageException) y;
}
- }
+ y = y.getCause();
+ } while (y != null);
return t;
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java
index 94c6175298d..bf7b4f63d6c 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java
@@ -19,7 +19,6 @@
*/
package org.sonar.batch.bootstrapper;
-import com.google.common.annotations.VisibleForTesting;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.CheckForNull;
@@ -43,9 +42,7 @@ public final class LoggingConfiguration {
public static final String LEVEL_ROOT_VERBOSE = "DEBUG";
public static final String LEVEL_ROOT_DEFAULT = "INFO";
- @VisibleForTesting
static final String FORMAT_DEFAULT = "%d{HH:mm:ss.SSS} %-5level - %msg%n";
- @VisibleForTesting
static final String FORMAT_MAVEN = "[%level] [%d{HH:mm:ss.SSS}] %msg%n";
private Map<String, String> substitutionVariables = new HashMap<>();
@@ -110,7 +107,6 @@ public final class LoggingConfiguration {
return addSubstitutionVariable(PROPERTY_ROOT_LOGGER_LEVEL, level);
}
- @VisibleForTesting
LoggingConfiguration setFormat(String format) {
return addSubstitutionVariable(PROPERTY_FORMAT, StringUtils.defaultIfBlank(format, FORMAT_DEFAULT));
}
@@ -120,7 +116,6 @@ public final class LoggingConfiguration {
return this;
}
- @VisibleForTesting
String getSubstitutionVariable(String key) {
return substitutionVariables.get(key);
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/DefaultFileLinesContext.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/DefaultFileLinesContext.java
index e0481cfb52d..802c5ff112c 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/DefaultFileLinesContext.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/DefaultFileLinesContext.java
@@ -53,7 +53,7 @@ public class DefaultFileLinesContext implements FileLinesContext {
@Override
public void setIntValue(String metricKey, int line, int value) {
- Preconditions.checkNotNull(metricKey);
+ checkNotNull(metricKey);
checkLineRange(line);
setValue(metricKey, line, value);
@@ -66,13 +66,19 @@ public class DefaultFileLinesContext implements FileLinesContext {
@Override
public void setStringValue(String metricKey, int line, String value) {
- Preconditions.checkNotNull(metricKey);
+ checkNotNull(metricKey);
checkLineRange(line);
- Preconditions.checkNotNull(value);
+ checkNotNull(value);
setValue(metricKey, line, value);
}
+ private static void checkNotNull(Object object) {
+ if (object == null) {
+ throw new NullPointerException();
+ }
+ }
+
private void setValue(String metricKey, int line, Object value) {
map.computeIfAbsent(metricKey, k -> new HashMap<>())
.put(line, value);
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 479304d2587..13914743e38 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
@@ -19,7 +19,7 @@
*/
package org.sonar.scanner.bootstrap;
-import com.google.common.collect.Lists;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.sonar.core.component.DefaultResourceTypes;
@@ -36,8 +36,8 @@ public class BatchComponents {
}
public static Collection<Object> all() {
- List<Object> components = Lists.newArrayList(
- DefaultResourceTypes.get());
+ List<Object> components = new ArrayList<>();
+ components.add(DefaultResourceTypes.get());
components.addAll(CorePropertyDefinitions.all());
components.add(ZeroCoverageSensor.class);
components.add(JavaCpdBlockIndexerSensor.class);
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalServerSettings.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalServerSettings.java
index 643fc27cc55..dcb80cf4e2f 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalServerSettings.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalServerSettings.java
@@ -19,7 +19,8 @@
*/
package org.sonar.scanner.bootstrap;
-import com.google.common.collect.ImmutableMap;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
import javax.annotation.concurrent.Immutable;
@@ -32,11 +33,11 @@ public class GlobalServerSettings {
private final Map<String, String> properties;
public GlobalServerSettings(Map<String, String> properties) {
- this.properties = properties;
+ this.properties = Collections.unmodifiableMap(new HashMap<>(properties));
}
public Map<String, String> properties() {
- return ImmutableMap.copyOf(properties);
+ return properties;
}
public String property(String key) {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/MetricProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/MetricProvider.java
index 5d3fb8158db..b0685d8815c 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/MetricProvider.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/MetricProvider.java
@@ -19,13 +19,13 @@
*/
package org.sonar.scanner.bootstrap;
-import com.google.common.collect.Lists;
+import java.util.ArrayList;
import java.util.List;
import org.sonar.api.ExtensionProvider;
-import org.sonar.api.scanner.ScannerSide;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Metric;
import org.sonar.api.measures.Metrics;
+import org.sonar.api.scanner.ScannerSide;
@ScannerSide
public class MetricProvider extends ExtensionProvider {
@@ -42,7 +42,7 @@ public class MetricProvider extends ExtensionProvider {
@Override
public List<Metric> provide() {
- List<Metric> metrics = Lists.newArrayList(CoreMetrics.getMetrics());
+ List<Metric> metrics = new ArrayList<>(CoreMetrics.getMetrics());
for (Metrics factory : factories) {
metrics.addAll(factory.getMetrics());
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ProcessedScannerProperties.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ProcessedScannerProperties.java
index 1c9b77ba22e..f3765a5ed53 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ProcessedScannerProperties.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ProcessedScannerProperties.java
@@ -19,7 +19,7 @@
*/
package org.sonar.scanner.bootstrap;
-import com.google.common.collect.ImmutableMap;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.CheckForNull;
@@ -50,7 +50,7 @@ public class ProcessedScannerProperties implements ProjectKey {
}
public Map<String, String> properties() {
- return ImmutableMap.copyOf(properties);
+ return Collections.unmodifiableMap(new HashMap<>(properties));
}
public String property(String key) {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/RawScannerProperties.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/RawScannerProperties.java
index 343e08c3d50..77f64bf4ad8 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/RawScannerProperties.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/RawScannerProperties.java
@@ -19,7 +19,7 @@
*/
package org.sonar.scanner.bootstrap;
-import com.google.common.collect.ImmutableMap;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.concurrent.Immutable;
@@ -49,7 +49,7 @@ public class RawScannerProperties {
}
decryptedProps.put(entry.getKey(), value);
}
- this.properties = decryptedProps;
+ this.properties = Collections.unmodifiableMap(new HashMap<>(decryptedProps));
}
public Encryption getEncryption() {
@@ -57,7 +57,7 @@ public class RawScannerProperties {
}
public Map<String, String> properties() {
- return ImmutableMap.copyOf(properties);
+ return properties;
}
public String property(String key) {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginRepository.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginRepository.java
index d7e8341cafe..b3a0f286394 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginRepository.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginRepository.java
@@ -19,7 +19,6 @@
*/
package org.sonar.scanner.bootstrap;
-import com.google.common.base.Preconditions;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@@ -35,6 +34,7 @@ import org.sonar.core.platform.PluginRepository;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;
+import static org.sonar.api.utils.Preconditions.checkState;
/**
* Orchestrates the installation and loading of plugins
@@ -116,14 +116,14 @@ public class ScannerPluginRepository implements PluginRepository, Startable {
@Override
public PluginInfo getPluginInfo(String key) {
ScannerPlugin info = pluginsByKeys.get(key);
- Preconditions.checkState(info != null, "Plugin [%s] does not exist", key);
+ checkState(info != null, "Plugin [%s] does not exist", key);
return info.getInfo();
}
@Override
public Plugin getPluginInstance(String key) {
Plugin instance = pluginInstancesByKeys.get(key);
- Preconditions.checkState(instance != null, "Plugin [%s] does not exist", key);
+ checkState(instance != null, "Plugin [%s] does not exist", key);
return instance;
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/CpdExecutor.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/CpdExecutor.java
index 74684a0019b..5f6cfd1a5f7 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/CpdExecutor.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/CpdExecutor.java
@@ -19,7 +19,6 @@
*/
package org.sonar.scanner.cpd;
-import com.google.common.annotations.VisibleForTesting;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
@@ -34,6 +33,8 @@ import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.sonar.api.batch.fs.InputComponent;
+import org.sonar.api.impl.fs.DefaultInputComponent;
+import org.sonar.api.impl.fs.DefaultInputFile;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.duplications.block.Block;
@@ -42,8 +43,6 @@ import org.sonar.duplications.index.CloneGroup;
import org.sonar.duplications.index.ClonePart;
import org.sonar.duplications.index.PackedMemoryCloneIndex.ResourceBlocks;
import org.sonar.scanner.cpd.index.SonarCpdBlockIndex;
-import org.sonar.api.impl.fs.DefaultInputComponent;
-import org.sonar.api.impl.fs.DefaultInputFile;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.protocol.output.ScannerReport.Duplicate;
import org.sonar.scanner.protocol.output.ScannerReport.Duplication;
@@ -90,7 +89,6 @@ public class CpdExecutor {
execute(TIMEOUT);
}
- @VisibleForTesting
void execute(long timeout) {
List<FileBlocks> components = new ArrayList<>(index.noResources());
Iterator<ResourceBlocks> it = index.iterator();
@@ -129,7 +127,6 @@ public class CpdExecutor {
return files == 1 ? "file" : "files";
}
- @VisibleForTesting
void runCpdAnalysis(ExecutorService executorService, DefaultInputFile inputFile, Collection<Block> fileBlocks, long timeout) {
LOG.debug("Detection of duplications for {}", inputFile.absolutePath());
progressReport.message(String.format("%d/%d - current file: %s", count, total, inputFile.absolutePath()));
@@ -160,7 +157,6 @@ public class CpdExecutor {
saveDuplications(inputFile, filtered);
}
- @VisibleForTesting
final void saveDuplications(final DefaultInputComponent component, List<CloneGroup> duplications) {
if (duplications.size() > MAX_CLONE_GROUP_PER_FILE) {
LOG.warn("Too many duplication groups on file {}. Keep only the first {} groups.", component, MAX_CLONE_GROUP_PER_FILE);
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/perspectives/ScannerPerspectives.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/perspectives/ScannerPerspectives.java
index c685cbe68fb..b7416245b9b 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/perspectives/ScannerPerspectives.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/perspectives/ScannerPerspectives.java
@@ -19,7 +19,7 @@
*/
package org.sonar.scanner.deprecated.perspectives;
-import com.google.common.collect.Maps;
+import java.util.HashMap;
import java.util.Map;
import org.sonar.api.batch.fs.InputPath;
import org.sonar.api.component.Perspective;
@@ -27,7 +27,7 @@ import org.sonar.api.component.ResourcePerspectives;
public class ScannerPerspectives implements ResourcePerspectives {
- private final Map<Class<?>, PerspectiveBuilder<?>> builders = Maps.newHashMap();
+ private final Map<Class<?>, PerspectiveBuilder<?>> builders = new HashMap<>();
public ScannerPerspectives(PerspectiveBuilder[] builders) {
for (PerspectiveBuilder builder : builders) {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestCase.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestCase.java
index 74113b9ed68..a694f434fd9 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestCase.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestCase.java
@@ -19,20 +19,21 @@
*/
package org.sonar.scanner.deprecated.test;
-import com.google.common.base.Preconditions;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.InputFile.Type;
+import org.sonar.api.impl.fs.DefaultInputFile;
import org.sonar.api.test.CoverageBlock;
import org.sonar.api.test.MutableTestCase;
import org.sonar.api.test.TestPlan;
import org.sonar.api.test.Testable;
import org.sonar.api.test.exception.CoverageAlreadyExistsException;
import org.sonar.api.test.exception.IllegalDurationException;
-import org.sonar.api.impl.fs.DefaultInputFile;
+
+import static org.sonar.api.utils.Preconditions.checkArgument;
public class DefaultTestCase implements MutableTestCase {
@@ -125,7 +126,7 @@ public class DefaultTestCase implements MutableTestCase {
@Override
public MutableTestCase setCoverageBlock(InputFile mainFile, List<Integer> lines) {
- Preconditions.checkArgument(mainFile.type() == Type.MAIN, "Test file can only cover a main file");
+ checkArgument(mainFile.type() == Type.MAIN, "Test file can only cover a main file");
DefaultInputFile coveredFile = (DefaultInputFile) mainFile;
if (coverageBlocksByTestedFile.containsKey(coveredFile)) {
throw new CoverageAlreadyExistsException("The link between " + name() + " and " + coveredFile.key() + " already exists");
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestPlan.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestPlan.java
index 3e765e3f752..8fc9981a85c 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestPlan.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/test/DefaultTestPlan.java
@@ -19,7 +19,6 @@
*/
package org.sonar.scanner.deprecated.test;
-import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.CheckForNull;
@@ -32,7 +31,7 @@ public class DefaultTestPlan implements MutableTestPlan {
@Override
@CheckForNull
public Iterable<MutableTestCase> testCasesByName(String name) {
- List<MutableTestCase> result = Lists.newArrayList();
+ List<MutableTestCase> result = new ArrayList<>();
for (MutableTestCase testCase : testCases()) {
if (name.equals(testCase.name())) {
result.add(testCase);
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/ExternalIssueImporter.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/ExternalIssueImporter.java
index f4ff8a26d16..55266ae8a20 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/ExternalIssueImporter.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/ExternalIssueImporter.java
@@ -19,7 +19,6 @@
*/
package org.sonar.scanner.externalissue;
-import com.google.common.base.MoreObjects;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.stream.Collectors;
@@ -121,7 +120,7 @@ public class ExternalIssueImporter {
if (location.textRange != null) {
if (location.textRange.startColumn != null) {
TextPointer start = file.newPointer(location.textRange.startLine, location.textRange.startColumn);
- int endLine = MoreObjects.firstNonNull(location.textRange.endLine, location.textRange.startLine);
+ int endLine = (location.textRange.endLine != null) ? location.textRange.endLine : location.textRange.startLine;
int endColumn;
if (location.textRange.endColumn == null) {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericCoverageReportParser.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericCoverageReportParser.java
index 6499aa11ae4..c3ee0a32a7b 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericCoverageReportParser.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericCoverageReportParser.java
@@ -19,7 +19,6 @@
*/
package org.sonar.scanner.genericcoverage;
-import com.google.common.base.Preconditions;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
@@ -35,6 +34,8 @@ import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.coverage.NewCoverage;
import org.sonar.api.utils.MessageException;
+import static org.sonar.api.utils.Preconditions.checkState;
+
public class GenericCoverageReportParser {
private static final String LINE_NUMBER_ATTR = "lineNumber";
@@ -85,7 +86,7 @@ public class GenericCoverageReportParser {
}
continue;
}
- Preconditions.checkState(
+ checkState(
inputFile.language() != null,
"Line %s of report refers to a file with an unknown language: %s",
fileCursor.getCursorLocation().getLineNumber(),
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericCoverageSensor.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericCoverageSensor.java
index e11b403b0b6..537f8a1857a 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericCoverageSensor.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericCoverageSensor.java
@@ -19,10 +19,11 @@
*/
package org.sonar.scanner.genericcoverage;
-import com.google.common.collect.ImmutableList;
import java.io.File;
import java.util.Arrays;
+import java.util.Collections;
import java.util.LinkedHashSet;
+import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.sonar.api.batch.sensor.Sensor;
@@ -69,9 +70,8 @@ public class GenericCoverageSensor implements Sensor {
this.config = config;
}
- public static ImmutableList<PropertyDefinition> properties() {
- return ImmutableList.of(
-
+ public static List<PropertyDefinition> properties() {
+ return Collections.singletonList(
PropertyDefinition.builder(REPORT_PATHS_PROPERTY_KEY)
.name("Coverage report paths")
.description("List of comma-separated paths (absolute or relative) containing coverage report.")
@@ -103,8 +103,8 @@ public class GenericCoverageSensor implements Sensor {
.global()
.onlyWhenConfiguration(c -> asList(REPORT_PATHS_PROPERTY_KEY, OLD_REPORT_PATH_PROPERTY_KEY, OLD_COVERAGE_REPORT_PATHS_PROPERTY_KEY,
OLD_IT_COVERAGE_REPORT_PATHS_PROPERTY_KEY, OLD_OVERALL_COVERAGE_REPORT_PATHS_PROPERTY_KEY)
- .stream()
- .anyMatch(c::hasKey));
+ .stream()
+ .anyMatch(c::hasKey));
}
@Override
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParser.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParser.java
index 62c54dba30b..69002e47d75 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParser.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParser.java
@@ -19,7 +19,6 @@
*/
package org.sonar.scanner.genericcoverage;
-import com.google.common.base.Preconditions;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
@@ -40,6 +39,7 @@ import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.scanner.deprecated.test.TestPlanBuilder;
+import static org.sonar.api.utils.Preconditions.checkState;
import static org.sonar.scanner.genericcoverage.GenericCoverageReportParser.checkElementName;
import static org.sonar.scanner.genericcoverage.GenericCoverageReportParser.longValue;
import static org.sonar.scanner.genericcoverage.GenericCoverageReportParser.mandatoryAttribute;
@@ -116,12 +116,12 @@ public class GenericTestExecutionReportParser {
}
continue;
}
- Preconditions.checkState(
+ checkState(
inputFile.language() != null,
"Line %s of report refers to a file with an unknown language: %s",
fileCursor.getCursorLocation().getLineNumber(),
filePath);
- Preconditions.checkState(
+ checkState(
inputFile.type() != InputFile.Type.MAIN,
"Line %s of report refers to a file which is not configured as a test file: %s",
fileCursor.getCursorLocation().getLineNumber(),
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericTestExecutionSensor.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericTestExecutionSensor.java
index 1cad4d799d3..297f9fc41ac 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericTestExecutionSensor.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericTestExecutionSensor.java
@@ -19,8 +19,9 @@
*/
package org.sonar.scanner.genericcoverage;
-import com.google.common.collect.ImmutableList;
import java.io.File;
+import java.util.Collections;
+import java.util.List;
import java.util.stream.Collectors;
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.batch.sensor.SensorContext;
@@ -53,8 +54,8 @@ public class GenericTestExecutionSensor implements Sensor {
this.configuration = configuration;
}
- public static ImmutableList<PropertyDefinition> properties() {
- return ImmutableList.of(
+ public static List<PropertyDefinition> properties() {
+ return Collections.singletonList(
PropertyDefinition.builder(REPORT_PATHS_PROPERTY_KEY)
.name("Unit tests results report paths")
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssuePublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssuePublisher.java
index 1bbf26f6bd1..326f38e6b83 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssuePublisher.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssuePublisher.java
@@ -21,6 +21,7 @@ package org.sonar.scanner.issue;
import java.util.Collection;
import java.util.function.Consumer;
+import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.batch.fs.TextRange;
@@ -37,8 +38,6 @@ import org.sonar.scanner.protocol.output.ScannerReport.IssueLocation;
import org.sonar.scanner.protocol.output.ScannerReport.IssueType;
import org.sonar.scanner.report.ReportPublisher;
-import static com.google.common.base.Strings.nullToEmpty;
-
/**
* Initialize the issues raised during scan.
*/
@@ -91,6 +90,13 @@ public class IssuePublisher {
write(inputComponent.scannerId(), rawExternalIssue);
}
+ private static String nullToEmpty(@Nullable String str) {
+ if (str == null) {
+ return "";
+ }
+ return str;
+ }
+
private static ScannerReport.Issue createReportIssue(Issue issue, int componentRef, String activeRuleSeverity) {
String primaryMessage = nullToEmpty(issue.primaryLocation().message());
org.sonar.api.batch.rule.Severity overriddenSeverity = issue.overriddenSeverity();
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/AbstractPatternInitializer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/AbstractPatternInitializer.java
index 4b85daf89e4..3fac8b8ed86 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/AbstractPatternInitializer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/AbstractPatternInitializer.java
@@ -19,7 +19,6 @@
*/
package org.sonar.scanner.issue.ignore.pattern;
-import com.google.common.annotations.VisibleForTesting;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
@@ -53,7 +52,6 @@ public abstract class AbstractPatternInitializer {
return !multicriteriaPatterns.isEmpty();
}
- @VisibleForTesting
protected final void initPatterns() {
// Patterns Multicriteria
multicriteriaPatterns = new ArrayList<>();
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/IssueExclusionPatternInitializer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/IssueExclusionPatternInitializer.java
index 16c3163cbf7..51c10c1e3cf 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/IssueExclusionPatternInitializer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/IssueExclusionPatternInitializer.java
@@ -22,13 +22,12 @@ package org.sonar.scanner.issue.ignore.pattern;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import javax.annotation.Nullable;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.config.Configuration;
import org.sonar.api.utils.MessageException;
import org.sonar.core.config.IssueExclusionProperties;
-import static com.google.common.base.Strings.nullToEmpty;
-
public class IssueExclusionPatternInitializer extends AbstractPatternInitializer {
public static final String CONFIG_KEY = IssueExclusionProperties.EXCLUSION_KEY_PREFIX + ".multicriteria";
@@ -79,6 +78,13 @@ public class IssueExclusionPatternInitializer extends AbstractPatternInitializer
allFilePatterns = Collections.unmodifiableList(allFilePatterns);
}
+ private String nullToEmpty(@Nullable String str) {
+ if (str == null) {
+ return "";
+ }
+ return str;
+ }
+
public List<BlockIssuePattern> getBlockPatterns() {
return blockPatterns;
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/LineRange.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/LineRange.java
index 7c873cde4e5..d95ee67d9b1 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/LineRange.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/LineRange.java
@@ -19,10 +19,12 @@
*/
package org.sonar.scanner.issue.ignore.pattern;
-import com.google.common.base.Preconditions;
import java.util.LinkedHashSet;
+import java.util.Objects;
import java.util.Set;
+import static org.sonar.api.utils.Preconditions.checkArgument;
+
public class LineRange {
private int from;
private int to;
@@ -32,7 +34,7 @@ public class LineRange {
}
public LineRange(int from, int to) {
- Preconditions.checkArgument(from <= to, "Line range is not valid: %s must be greater or equal than %s", to, from);
+ checkArgument(from <= to, "Line range is not valid: %s must be greater or equal than %s", to, from);
this.from = from;
this.to = to;
@@ -65,11 +67,7 @@ public class LineRange {
@Override
public int hashCode() {
- final int PRIME = 31;
- int result = 1;
- result = PRIME * result + from;
- result = PRIME * result + to;
- return result;
+ return Objects.hash(from, to);
}
@Override
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/AnalysisResult.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/AnalysisResult.java
index 0e851054801..7770db3b479 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/AnalysisResult.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/AnalysisResult.java
@@ -19,8 +19,6 @@
*/
package org.sonar.scanner.mediumtest;
-import com.google.common.collect.Iterators;
-import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -35,10 +33,10 @@ import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.TextPointer;
import org.sonar.api.batch.fs.TextRange;
import org.sonar.api.batch.sensor.highlighting.TypeOfText;
-import org.sonar.api.scanner.fs.InputProject;
-import org.sonar.core.util.CloseableIterator;
import org.sonar.api.impl.fs.DefaultInputComponent;
import org.sonar.api.impl.fs.DefaultInputFile;
+import org.sonar.api.scanner.fs.InputProject;
+import org.sonar.core.util.CloseableIterator;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.protocol.output.ScannerReport.Component;
import org.sonar.scanner.protocol.output.ScannerReport.Symbol;
@@ -100,7 +98,7 @@ public class AnalysisResult implements AnalysisObserver {
}
private List<ScannerReport.Issue> issuesFor(int ref) {
- List<ScannerReport.Issue> result = Lists.newArrayList();
+ List<ScannerReport.Issue> result = new ArrayList<>();
try (CloseableIterator<ScannerReport.Issue> it = reader.readComponentIssues(ref)) {
while (it.hasNext()) {
result.add(it.next());
@@ -110,7 +108,7 @@ public class AnalysisResult implements AnalysisObserver {
}
private List<ScannerReport.ExternalIssue> externalIssuesFor(int ref) {
- List<ScannerReport.ExternalIssue> result = Lists.newArrayList();
+ List<ScannerReport.ExternalIssue> result = new ArrayList<>();
try (CloseableIterator<ScannerReport.ExternalIssue> it = reader.readComponentExternalIssues(ref)) {
while (it.hasNext()) {
result.add(it.next());
@@ -136,13 +134,17 @@ public class AnalysisResult implements AnalysisObserver {
Map<String, List<ScannerReport.Measure>> result = new HashMap<>();
List<ScannerReport.Measure> projectMeasures = new ArrayList<>();
try (CloseableIterator<ScannerReport.Measure> it = reader.readComponentMeasures(((DefaultInputComponent) project).scannerId())) {
- Iterators.addAll(projectMeasures, it);
+ while (it.hasNext()) {
+ projectMeasures.add(it.next());
+ }
}
result.put(project.key(), projectMeasures);
for (InputFile inputFile : inputFilesByKeys.values()) {
List<ScannerReport.Measure> measures = new ArrayList<>();
try (CloseableIterator<ScannerReport.Measure> it = reader.readComponentMeasures(((DefaultInputComponent) inputFile).scannerId())) {
- Iterators.addAll(measures, it);
+ while (it.hasNext()) {
+ measures.add(it.next());
+ }
}
result.put(inputFile.key(), measures);
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/notifications/DefaultAnalysisWarnings.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/notifications/DefaultAnalysisWarnings.java
index 7113af8d2f2..c8d141aced1 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/notifications/DefaultAnalysisWarnings.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/notifications/DefaultAnalysisWarnings.java
@@ -28,7 +28,7 @@ import javax.annotation.concurrent.Immutable;
import org.sonar.api.notifications.AnalysisWarnings;
import org.sonar.api.utils.System2;
-import static com.google.common.base.Preconditions.checkArgument;
+import static org.sonar.api.utils.Preconditions.checkArgument;
public class DefaultAnalysisWarnings implements AnalysisWarnings {
private final System2 system2;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java
index 46078b34f84..218f55877d8 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java
@@ -19,8 +19,6 @@
*/
package org.sonar.scanner.report;
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Throwables;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -168,7 +166,6 @@ public class ReportPublisher implements Startable {
/**
* Uploads the report file to server and returns the generated task id
*/
- @VisibleForTesting
String upload(File report) {
LOG.debug("Upload report");
long startTime = System.currentTimeMillis();
@@ -201,14 +198,13 @@ public class ReportPublisher implements Startable {
try (InputStream protobuf = response.contentStream()) {
return Ce.SubmitResponse.parser().parseFrom(protobuf).getTaskId();
} catch (Exception e) {
- throw Throwables.propagate(e);
+ throw new RuntimeException(e);
} finally {
long stopTime = System.currentTimeMillis();
LOG.info("Analysis report uploaded in " + (stopTime - startTime) + "ms");
}
}
- @VisibleForTesting
void logSuccess(@Nullable String taskId) {
if (taskId == null) {
LOG.info("ANALYSIS SUCCESSFUL");
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionPublisher.java
index 2aa1802f814..da6d8fc3dde 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionPublisher.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/TestExecutionPublisher.java
@@ -19,7 +19,6 @@
*/
package org.sonar.scanner.report;
-import com.google.common.collect.Iterables;
import java.util.Objects;
import java.util.stream.StreamSupport;
import org.sonar.api.batch.fs.InputComponent;
@@ -68,7 +67,7 @@ public class TestExecutionPublisher implements ReportPublisherStep {
private void updateTestExecutionFromTestPlan(final InputFile inputFile, ScannerReportWriter writer) {
final MutableTestPlan testPlan = testPlanBuilder.getTestPlanByFile(inputFile);
- if (testPlan == null || Iterables.isEmpty(testPlan.testCases())) {
+ if (testPlan == null || !testPlan.testCases().iterator().hasNext()) {
return;
}
long nonSkippedTests = StreamSupport.stream(testPlan.testCases().spliterator(), false).filter(t -> t.status() != Status.SKIPPED).count();
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ContextPropertiesCache.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ContextPropertiesCache.java
index 9d363ce09a1..93372b0367a 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ContextPropertiesCache.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ContextPropertiesCache.java
@@ -22,7 +22,7 @@ package org.sonar.scanner.repository;
import java.util.HashMap;
import java.util.Map;
-import static com.google.common.base.Preconditions.checkArgument;
+import static org.sonar.api.utils.Preconditions.checkArgument;
public class ContextPropertiesCache {
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 3c7e7ad5484..c1a330be2f1 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
@@ -19,7 +19,6 @@
*/
package org.sonar.scanner.repository;
-import com.google.common.base.Throwables;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
@@ -28,8 +27,8 @@ import java.util.Map;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.sonar.scanner.bootstrap.DefaultScannerWsClient;
import org.sonar.api.impl.utils.ScannerUtils;
+import org.sonar.scanner.bootstrap.DefaultScannerWsClient;
import org.sonarqube.ws.Batch.WsProjectResponse;
import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.HttpException;
@@ -75,11 +74,14 @@ public class DefaultProjectRepositoriesLoader implements ProjectRepositoriesLoad
}
private static boolean shouldThrow(Exception e) {
- for (Throwable t : Throwables.getCausalChain(e)) {
+ Throwable t = e;
+
+ do {
if (t instanceof HttpException && ((HttpException) t).code() == HttpURLConnection.HTTP_NOT_FOUND) {
return false;
}
- }
+ t = t.getCause();
+ } while (t != null);
return true;
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/MultiModuleProjectRepository.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/MultiModuleProjectRepository.java
index 0f33e38d1c7..0f8f7494c4c 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/MultiModuleProjectRepository.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/MultiModuleProjectRepository.java
@@ -19,7 +19,8 @@
*/
package org.sonar.scanner.repository;
-import com.google.common.collect.ImmutableMap;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
import javax.annotation.CheckForNull;
import javax.annotation.concurrent.Immutable;
@@ -31,7 +32,7 @@ public class MultiModuleProjectRepository extends ProjectRepositories {
public MultiModuleProjectRepository(Map<String, SingleProjectRepository> repositoriesPerModule) {
super(true);
- this.repositoriesPerModule = ImmutableMap.copyOf(repositoriesPerModule);
+ this.repositoriesPerModule = Collections.unmodifiableMap(new HashMap<>(repositoriesPerModule));
}
@CheckForNull
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/SingleProjectRepository.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/SingleProjectRepository.java
index bc0bc325a5b..13af495ecd7 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/SingleProjectRepository.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/SingleProjectRepository.java
@@ -19,7 +19,8 @@
*/
package org.sonar.scanner.repository;
-import com.google.common.collect.ImmutableMap;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
import javax.annotation.CheckForNull;
import javax.annotation.concurrent.Immutable;
@@ -27,16 +28,16 @@ import javax.annotation.concurrent.Immutable;
@Immutable
public class SingleProjectRepository extends ProjectRepositories {
- private final ImmutableMap<String, FileData> fileDataByPath;
+ private final Map<String, FileData> fileDataByPath;
public SingleProjectRepository() {
super(false);
- this.fileDataByPath = ImmutableMap.<String, FileData>builder().build();
+ this.fileDataByPath = Collections.emptyMap();
}
public SingleProjectRepository(Map<String, FileData> fileDataByPath) {
super(true);
- this.fileDataByPath = ImmutableMap.copyOf(fileDataByPath);
+ this.fileDataByPath = Collections.unmodifiableMap(new HashMap<>(fileDataByPath));
}
@CheckForNull
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/settings/AbstractSettingsLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/settings/AbstractSettingsLoader.java
index 795a217b5a1..69b83e98f3c 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/settings/AbstractSettingsLoader.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/settings/AbstractSettingsLoader.java
@@ -19,7 +19,6 @@
*/
package org.sonar.scanner.repository.settings;
-import com.google.common.annotations.VisibleForTesting;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
@@ -31,11 +30,11 @@ import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.apache.commons.lang.StringEscapeUtils;
+import org.sonar.api.impl.utils.ScannerUtils;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.api.utils.log.Profiler;
import org.sonar.scanner.bootstrap.DefaultScannerWsClient;
-import org.sonar.api.impl.utils.ScannerUtils;
import org.sonarqube.ws.Settings;
import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.HttpException;
@@ -72,7 +71,6 @@ public abstract class AbstractSettingsLoader {
}
}
- @VisibleForTesting
static Map<String, String> toMap(List<Settings.Setting> settingsList) {
Map<String, String> result = new LinkedHashMap<>();
for (Settings.Setting s : settingsList) {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/QProfileVerifier.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/QProfileVerifier.java
index 26b476e82c1..660ae686d22 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/QProfileVerifier.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/QProfileVerifier.java
@@ -19,7 +19,6 @@
*/
package org.sonar.scanner.rule;
-import com.google.common.annotations.VisibleForTesting;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.scanner.scan.filesystem.InputComponentStore;
@@ -40,7 +39,6 @@ public class QProfileVerifier {
execute(LOG);
}
- @VisibleForTesting
void execute(Logger logger) {
for (String lang : store.languages()) {
QProfile profile = profiles.findByLanguage(lang);
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java
index e15525df2d2..da610c5ac34 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java
@@ -19,7 +19,6 @@
*/
package org.sonar.scanner.scan;
-import com.google.common.annotations.VisibleForTesting;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -40,6 +39,7 @@ import org.apache.commons.lang.StringUtils;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.impl.utils.ScannerUtils;
import org.sonar.api.notifications.AnalysisWarnings;
import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.log.Logger;
@@ -49,7 +49,6 @@ import org.sonar.core.config.IssueExclusionProperties;
import org.sonar.scanner.bootstrap.ProcessedScannerProperties;
import org.sonar.scanner.issue.ignore.pattern.IssueExclusionPatternInitializer;
import org.sonar.scanner.issue.ignore.pattern.IssueInclusionPatternInitializer;
-import org.sonar.api.impl.utils.ScannerUtils;
import static java.util.Arrays.asList;
import static java.util.stream.Collectors.toList;
@@ -209,7 +208,6 @@ public class ProjectReactorBuilder {
}
}
- @VisibleForTesting
protected File initRootProjectWorkDir(File baseDir, Map<String, String> rootProperties) {
String workDir = rootProperties.get(CoreProperties.WORKING_DIRECTORY);
if (StringUtils.isBlank(workDir)) {
@@ -223,7 +221,6 @@ public class ProjectReactorBuilder {
return new File(baseDir, customWorkDir.getPath());
}
- @VisibleForTesting
protected File initModuleWorkDir(File moduleBaseDir, Map<String, String> moduleProperties) {
String workDir = moduleProperties.get(CoreProperties.WORKING_DIRECTORY);
if (StringUtils.isBlank(workDir)) {
@@ -289,7 +286,6 @@ public class ProjectReactorBuilder {
return createModuleDefinition(moduleProps, parentProject);
}
- @VisibleForTesting
protected static void setModuleKeyAndNameIfNotDefined(Map<String, String> childProps, String moduleId, String parentKey) {
if (!childProps.containsKey(MODULE_KEY_PROPERTY)) {
if (!childProps.containsKey(CoreProperties.PROJECT_KEY_PROPERTY)) {
@@ -306,7 +302,6 @@ public class ProjectReactorBuilder {
childProps.put(CoreProperties.PROJECT_KEY_PROPERTY, childProps.get(MODULE_KEY_PROPERTY));
}
- @VisibleForTesting
protected static void checkUniquenessOfChildKey(ProjectDefinition childProject, ProjectDefinition parentProject) {
for (ProjectDefinition definition : parentProject.getSubProjects()) {
if (definition.getKey().equals(childProject.getKey())) {
@@ -322,7 +317,6 @@ public class ProjectReactorBuilder {
childProps.put(PROPERTY_PROJECT_BASEDIR, baseDir.getAbsolutePath());
}
- @VisibleForTesting
protected static void checkMandatoryProperties(Map<String, String> props, String[] mandatoryProps) {
StringBuilder missing = new StringBuilder();
for (String mandatoryProperty : mandatoryProps) {
@@ -349,7 +343,6 @@ public class ProjectReactorBuilder {
}
}
- @VisibleForTesting
protected static void cleanAndCheckProjectDefinitions(ProjectDefinition project) {
if (project.getSubProjects().isEmpty()) {
cleanAndCheckModuleProperties(project);
@@ -380,7 +373,6 @@ public class ProjectReactorBuilder {
}
}
- @VisibleForTesting
protected static void cleanAndCheckModuleProperties(ProjectDefinition project) {
Map<String, String> properties = project.properties();
@@ -389,7 +381,6 @@ public class ProjectReactorBuilder {
checkExistenceOfPaths(project.getKey(), project.getBaseDir(), sourcePaths, PROPERTY_SOURCES);
}
- @VisibleForTesting
protected static void mergeParentProperties(Map<String, String> childProps, Map<String, String> parentProps) {
for (Map.Entry<String, String> entry : parentProps.entrySet()) {
String key = entry.getKey();
@@ -400,7 +391,6 @@ public class ProjectReactorBuilder {
}
}
- @VisibleForTesting
protected static void checkExistenceOfPaths(String moduleRef, File baseDir, String[] paths, String propName) {
for (String path : paths) {
File sourceFolder = resolvePath(baseDir, path);
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 3fd76637dd5..0f0d81d1b8d 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
@@ -19,7 +19,6 @@
*/
package org.sonar.scanner.scan;
-import com.google.common.annotations.VisibleForTesting;
import javax.annotation.Nullable;
import org.sonar.api.SonarEdition;
import org.sonar.api.SonarRuntime;
@@ -309,7 +308,6 @@ public class ProjectScanContainer extends ComponentContainer {
.install(this, getScannerProjectExtensionsFilter());
}
- @VisibleForTesting
static ExtensionMatcher getScannerProjectExtensionsFilter() {
return extension -> {
if (isDeprecatedScannerSide(extension)) {
@@ -395,7 +393,6 @@ public class ProjectScanContainer extends ComponentContainer {
scan(module);
}
- @VisibleForTesting
void scan(DefaultInputModule module) {
new ModuleScanContainer(this, module).execute();
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectServerSettings.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectServerSettings.java
index 2892b2cae55..1933db604ec 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectServerSettings.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectServerSettings.java
@@ -19,7 +19,8 @@
*/
package org.sonar.scanner.scan;
-import com.google.common.collect.ImmutableMap;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
import javax.annotation.concurrent.Immutable;
@@ -32,11 +33,11 @@ public class ProjectServerSettings {
private final Map<String, String> properties;
public ProjectServerSettings(Map<String, String> properties) {
- this.properties = properties;
+ this.properties = Collections.unmodifiableMap(new HashMap<>(properties));
}
public Map<String, String> properties() {
- return ImmutableMap.copyOf(properties);
+ return properties;
}
public String property(String key) {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/DefaultModuleFileSystem.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/DefaultModuleFileSystem.java
index 3792a52e8a2..de87c63286b 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/DefaultModuleFileSystem.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/DefaultModuleFileSystem.java
@@ -19,7 +19,6 @@
*/
package org.sonar.scanner.scan.filesystem;
-import com.google.common.annotations.VisibleForTesting;
import org.sonar.api.impl.fs.DefaultFileSystem;
import org.sonar.api.impl.fs.DefaultInputModule;
import org.sonar.api.impl.fs.predicates.DefaultFilePredicates;
@@ -31,7 +30,6 @@ public class DefaultModuleFileSystem extends DefaultFileSystem {
initFields(module);
}
- @VisibleForTesting
public DefaultModuleFileSystem(DefaultInputModule module) {
super(module.getBaseDir());
initFields(module);
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/DefaultProjectFileSystem.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/DefaultProjectFileSystem.java
index d7892ce887b..d04ee42d47d 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/DefaultProjectFileSystem.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/DefaultProjectFileSystem.java
@@ -19,7 +19,6 @@
*/
package org.sonar.scanner.scan.filesystem;
-import com.google.common.annotations.VisibleForTesting;
import org.sonar.api.impl.fs.DefaultFileSystem;
import org.sonar.api.impl.fs.DefaultInputProject;
import org.sonar.api.impl.fs.predicates.DefaultFilePredicates;
@@ -31,7 +30,6 @@ public class DefaultProjectFileSystem extends DefaultFileSystem {
setFields(project);
}
- @VisibleForTesting
public DefaultProjectFileSystem(DefaultInputProject project) {
super(project.getBaseDir());
setFields(project);
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/MetadataGenerator.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/MetadataGenerator.java
index c15c9cdb5c6..9954b92eee0 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/MetadataGenerator.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/MetadataGenerator.java
@@ -19,23 +19,20 @@
*/
package org.sonar.scanner.scan.filesystem;
-import com.google.common.annotations.VisibleForTesting;
import java.io.InputStream;
import java.nio.charset.Charset;
import org.sonar.api.batch.fs.InputFile.Type;
+import org.sonar.api.impl.fs.DefaultInputFile;
+import org.sonar.api.impl.fs.FileMetadata;
import org.sonar.api.impl.fs.Metadata;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
-import org.sonar.api.impl.fs.DefaultInputFile;
-import org.sonar.api.impl.fs.FileMetadata;
import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsLoader;
public class MetadataGenerator {
private static final Logger LOG = Loggers.get(MetadataGenerator.class);
- @VisibleForTesting
static final Charset UTF_32BE = Charset.forName("UTF-32BE");
- @VisibleForTesting
static final Charset UTF_32LE = Charset.forName("UTF-32LE");
private final StatusDetection statusDetection;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/measure/DefaultMetricFinder.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/measure/DefaultMetricFinder.java
index b0e23ba7e0a..5176dd5892c 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/measure/DefaultMetricFinder.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/measure/DefaultMetricFinder.java
@@ -19,16 +19,14 @@
*/
package org.sonar.scanner.scan.measure;
-import com.google.common.collect.Lists;
import java.io.Serializable;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-
import javax.annotation.concurrent.ThreadSafe;
-
import org.sonar.api.batch.measure.Metric;
import org.sonar.api.batch.measure.MetricFinder;
import org.sonar.scanner.repository.MetricsRepository;
@@ -53,7 +51,7 @@ public class DefaultMetricFinder implements MetricFinder {
@Override
public Collection<Metric<Serializable>> findAll(List<String> metricKeys) {
- List<Metric<Serializable>> result = Lists.newLinkedList();
+ List<Metric<Serializable>> result = new ArrayList<>();
for (String metricKey : metricKeys) {
Metric<Serializable> metric = findByKey(metricKey);
if (metric != null) {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/DefaultBlameOutput.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/DefaultBlameOutput.java
index 885de1be663..8049abe2532 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/DefaultBlameOutput.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/DefaultBlameOutput.java
@@ -19,7 +19,6 @@
*/
package org.sonar.scanner.scm;
-import com.google.common.base.Preconditions;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
@@ -32,14 +31,16 @@ import org.apache.commons.lang.StringUtils;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.scm.BlameCommand.BlameOutput;
import org.sonar.api.batch.scm.BlameLine;
+import org.sonar.api.impl.fs.DefaultInputFile;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
-import org.sonar.api.impl.fs.DefaultInputFile;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.protocol.output.ScannerReport.Changesets.Builder;
import org.sonar.scanner.protocol.output.ScannerReportWriter;
import org.sonar.scanner.util.ProgressReport;
+import static org.sonar.api.utils.Preconditions.checkArgument;
+
class DefaultBlameOutput implements BlameOutput {
private static final Logger LOG = Loggers.get(DefaultBlameOutput.class);
@@ -61,9 +62,9 @@ class DefaultBlameOutput implements BlameOutput {
@Override
public synchronized void blameResult(InputFile file, List<BlameLine> lines) {
- Preconditions.checkNotNull(file);
- Preconditions.checkNotNull(lines);
- Preconditions.checkArgument(allFilesToBlame.contains(file), "It was not expected to blame file %s", file);
+ checkNotNull(file);
+ checkNotNull(lines);
+ checkArgument(allFilesToBlame.contains(file), "It was not expected to blame file %s", file);
if (lines.size() != file.lines()) {
LOG.debug("Ignoring blame result since provider returned {} blame lines but file {} has {} lines", lines.size(), file, file.lines());
@@ -94,8 +95,8 @@ class DefaultBlameOutput implements BlameOutput {
}
private static void validateLine(BlameLine line, int lineId, InputFile file) {
- Preconditions.checkArgument(StringUtils.isNotBlank(line.revision()), "Blame revision is blank for file %s at line %s", file, lineId);
- Preconditions.checkArgument(line.date() != null, "Blame date is null for file %s at line %s", file, lineId);
+ checkArgument(StringUtils.isNotBlank(line.revision()), "Blame revision is blank for file %s at line %s", file, lineId);
+ checkArgument(line.date() != null, "Blame date is null for file %s at line %s", file, lineId);
}
private static void addChangeset(Builder scmBuilder, BlameLine line) {
@@ -116,6 +117,12 @@ class DefaultBlameOutput implements BlameOutput {
return inputString.toLowerCase(Locale.US);
}
+ private static void checkNotNull(@Nullable Object obj) {
+ if (obj == null) {
+ throw new NullPointerException();
+ }
+ }
+
public void finish(boolean success) {
progressReport.stop(count + "/" + total + " files analyzed");
if (success && !allFilesToBlame.isEmpty()) {