*/
package org.sonar.batch.bootstrapper;
-import com.google.common.base.Throwables;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
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;
}
*/
package org.sonar.batch.bootstrapper;
-import com.google.common.annotations.VisibleForTesting;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.CheckForNull;
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<>();
return addSubstitutionVariable(PROPERTY_ROOT_LOGGER_LEVEL, level);
}
- @VisibleForTesting
LoggingConfiguration setFormat(String format) {
return addSubstitutionVariable(PROPERTY_FORMAT, StringUtils.defaultIfBlank(format, FORMAT_DEFAULT));
}
return this;
}
- @VisibleForTesting
String getSubstitutionVariable(String key) {
return substitutionVariables.get(key);
}
@Override
public void setIntValue(String metricKey, int line, int value) {
- Preconditions.checkNotNull(metricKey);
+ checkNotNull(metricKey);
checkLineRange(line);
setValue(metricKey, line, value);
@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);
*/
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;
}
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);
*/
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;
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) {
*/
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 {
@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());
}
*/
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;
}
public Map<String, String> properties() {
- return ImmutableMap.copyOf(properties);
+ return Collections.unmodifiableMap(new HashMap<>(properties));
}
public String property(String key) {
*/
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;
}
decryptedProps.put(entry.getKey(), value);
}
- this.properties = decryptedProps;
+ this.properties = Collections.unmodifiableMap(new HashMap<>(decryptedProps));
}
public Encryption getEncryption() {
}
public Map<String, String> properties() {
- return ImmutableMap.copyOf(properties);
+ return properties;
}
public String property(String key) {
*/
package org.sonar.scanner.bootstrap;
-import com.google.common.base.Preconditions;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
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
@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;
}
*/
package org.sonar.scanner.cpd;
-import com.google.common.annotations.VisibleForTesting;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
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;
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;
execute(TIMEOUT);
}
- @VisibleForTesting
void execute(long timeout) {
List<FileBlocks> components = new ArrayList<>(index.noResources());
Iterator<ResourceBlocks> it = index.iterator();
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()));
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);
*/
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;
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) {
*/
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 {
@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");
*/
package org.sonar.scanner.deprecated.test;
-import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.CheckForNull;
@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);
*/
package org.sonar.scanner.externalissue;
-import com.google.common.base.MoreObjects;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.stream.Collectors;
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) {
*/
package org.sonar.scanner.genericcoverage;
-import com.google.common.base.Preconditions;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
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";
}
continue;
}
- Preconditions.checkState(
+ checkState(
inputFile.language() != null,
"Line %s of report refers to a file with an unknown language: %s",
fileCursor.getCursorLocation().getLineNumber(),
*/
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;
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.")
.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
*/
package org.sonar.scanner.genericcoverage;
-import com.google.common.base.Preconditions;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
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;
}
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(),
*/
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;
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")
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;
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.
*/
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();
*/
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;
return !multicriteriaPatterns.isEmpty();
}
- @VisibleForTesting
protected final void initPatterns() {
// Patterns Multicriteria
multicriteriaPatterns = new ArrayList<>();
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";
allFilePatterns = Collections.unmodifiableList(allFilePatterns);
}
+ private String nullToEmpty(@Nullable String str) {
+ if (str == null) {
+ return "";
+ }
+ return str;
+ }
+
public List<BlockIssuePattern> getBlockPatterns() {
return blockPatterns;
}
*/
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;
}
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;
@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
*/
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;
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;
}
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());
}
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());
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);
}
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;
*/
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;
/**
* 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();
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");
*/
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;
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();
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 {
*/
package org.sonar.scanner.repository;
-import com.google.common.base.Throwables;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
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;
}
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;
}
*/
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;
public MultiModuleProjectRepository(Map<String, SingleProjectRepository> repositoriesPerModule) {
super(true);
- this.repositoriesPerModule = ImmutableMap.copyOf(repositoriesPerModule);
+ this.repositoriesPerModule = Collections.unmodifiableMap(new HashMap<>(repositoriesPerModule));
}
@CheckForNull
*/
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;
@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
*/
package org.sonar.scanner.repository.settings;
-import com.google.common.annotations.VisibleForTesting;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
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;
}
}
- @VisibleForTesting
static Map<String, String> toMap(List<Settings.Setting> settingsList) {
Map<String, String> result = new LinkedHashMap<>();
for (Settings.Setting s : settingsList) {
*/
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;
execute(LOG);
}
- @VisibleForTesting
void execute(Logger logger) {
for (String lang : store.languages()) {
QProfile profile = profiles.findByLanguage(lang);
*/
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;
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;
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;
}
}
- @VisibleForTesting
protected File initRootProjectWorkDir(File baseDir, Map<String, String> rootProperties) {
String workDir = rootProperties.get(CoreProperties.WORKING_DIRECTORY);
if (StringUtils.isBlank(workDir)) {
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)) {
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)) {
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())) {
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) {
}
}
- @VisibleForTesting
protected static void cleanAndCheckProjectDefinitions(ProjectDefinition project) {
if (project.getSubProjects().isEmpty()) {
cleanAndCheckModuleProperties(project);
}
}
- @VisibleForTesting
protected static void cleanAndCheckModuleProperties(ProjectDefinition project) {
Map<String, String> properties = project.properties();
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();
}
}
- @VisibleForTesting
protected static void checkExistenceOfPaths(String moduleRef, File baseDir, String[] paths, String propName) {
for (String path : paths) {
File sourceFolder = resolvePath(baseDir, path);
*/
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;
.install(this, getScannerProjectExtensionsFilter());
}
- @VisibleForTesting
static ExtensionMatcher getScannerProjectExtensionsFilter() {
return extension -> {
if (isDeprecatedScannerSide(extension)) {
scan(module);
}
- @VisibleForTesting
void scan(DefaultInputModule module) {
new ModuleScanContainer(this, module).execute();
}
*/
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;
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) {
*/
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;
initFields(module);
}
- @VisibleForTesting
public DefaultModuleFileSystem(DefaultInputModule module) {
super(module.getBaseDir());
initFields(module);
*/
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;
setFields(project);
}
- @VisibleForTesting
public DefaultProjectFileSystem(DefaultInputProject project) {
super(project.getBaseDir());
setFields(project);
*/
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;
*/
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;
@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) {
*/
package org.sonar.scanner.scm;
-import com.google.common.base.Preconditions;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
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);
@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());
}
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) {
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()) {