diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2017-01-31 14:56:28 +0100 |
---|---|---|
committer | dbmeneses <duarte.meneses@sonarsource.com> | 2017-01-31 17:14:13 +0100 |
commit | f4e4e1f30da63c41701e237f92d55171c7d5b927 (patch) | |
tree | 16b1c2f08aff3354f4524e0a582633797f41b77a /sonar-scanner-engine/src | |
parent | 664d1ea8246b368222ca545e8a26f0b8c7acfabd (diff) | |
download | sonarqube-f4e4e1f30da63c41701e237f92d55171c7d5b927.tar.gz sonarqube-f4e4e1f30da63c41701e237f92d55171c7d5b927.zip |
Reduce dependency on guava
Diffstat (limited to 'sonar-scanner-engine/src')
42 files changed, 172 insertions, 159 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 bfd02386af7..0d4fbe7c475 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 @@ -20,9 +20,10 @@ package org.sonar.batch.bootstrapper; import com.google.common.base.Throwables; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; + +import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Nullable; @@ -39,11 +40,11 @@ public final class Batch { private boolean started = false; private LoggingConfiguration loggingConfig; private List<Object> components; - private Map<String, String> bootstrapProperties = Maps.newHashMap(); + private Map<String, String> bootstrapProperties = new HashMap<>(); private GlobalContainer bootstrapContainer; private Batch(Builder builder) { - components = Lists.newArrayList(); + components = new ArrayList<>(); components.addAll(builder.components); if (builder.environment != null) { components.add(builder.environment); @@ -203,7 +204,7 @@ public final class Batch { public static final class Builder { private Map<String, String> bootstrapProperties; private EnvironmentInformation environment; - private List<Object> components = Lists.newArrayList(); + private List<Object> components = new ArrayList<>(); private boolean enableLoggingConfiguration = true; private LogOutput logOutput; 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 a330b6c37d0..7307615a0e6 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 @@ -20,7 +20,8 @@ package org.sonar.batch.bootstrapper; import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Maps; + +import java.util.HashMap; import java.util.Map; import javax.annotation.CheckForNull; import javax.annotation.Nullable; @@ -48,7 +49,7 @@ public final class LoggingConfiguration { @VisibleForTesting static final String FORMAT_MAVEN = "[%level] [%d{HH:mm:ss.SSS}] %msg%n"; - private Map<String, String> substitutionVariables = Maps.newHashMap(); + private Map<String, String> substitutionVariables = new HashMap<>(); private LogOutput logOutput = null; private boolean verbose; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerExtensionDictionnary.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerExtensionDictionnary.java index a1f3451eaa8..1726adf4056 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerExtensionDictionnary.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerExtensionDictionnary.java @@ -19,9 +19,6 @@ */ package org.sonar.scanner.bootstrap; -import com.google.common.base.Predicates; -import com.google.common.collect.Collections2; -import com.google.common.collect.Lists; import java.lang.annotation.Annotation; import java.lang.reflect.Array; import java.lang.reflect.Method; @@ -30,6 +27,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.stream.Collectors; + import javax.annotation.Nullable; import org.apache.commons.lang.ClassUtils; import org.sonar.api.batch.CheckProject; @@ -94,7 +93,7 @@ public class ScannerExtensionDictionnary { } private <T> List<T> getFilteredExtensions(Class<T> type, @Nullable DefaultInputModule module, @Nullable ExtensionMatcher matcher) { - List<T> result = Lists.newArrayList(); + List<T> result = new ArrayList<>(); for (Object extension : getExtensions(type)) { if (org.sonar.api.batch.Sensor.class.equals(type) && extension instanceof Sensor) { extension = new SensorWrapper((Sensor) extension, sensorContext, sensorOptimizer); @@ -125,7 +124,7 @@ public class ScannerExtensionDictionnary { } protected <T> List<T> getExtensions(Class<T> type) { - List<T> extensions = Lists.newArrayList(); + List<T> extensions = new ArrayList<>(); completeBatchExtensions(componentContainer, extensions, type); return extensions; } @@ -153,7 +152,9 @@ public class ScannerExtensionDictionnary { } List<?> sortedList = dag.sort(); - return (Collection<T>) Collections2.filter(sortedList, Predicates.in(extensions)); + return (Collection<T>) sortedList.stream() + .filter(extensions::contains) + .collect(Collectors.toList()); } /** @@ -187,7 +188,7 @@ public class ScannerExtensionDictionnary { } protected List<Object> evaluateAnnotatedClasses(Object extension, Class<? extends Annotation> annotation) { - List<Object> results = Lists.newArrayList(); + List<Object> results = new ArrayList<>(); Class<? extends Object> aClass = extension.getClass(); while (aClass != null) { evaluateClass(aClass, annotation, results); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginInstaller.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginInstaller.java index 35b97e6ad7d..680b602566b 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginInstaller.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginInstaller.java @@ -20,11 +20,11 @@ package org.sonar.scanner.bootstrap; import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Lists; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.Reader; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -71,7 +71,7 @@ public class ScannerPluginInstaller implements PluginInstaller { } private Map<String, PluginInfo> loadPlugins(List<RemotePlugin> remotePlugins) { - Map<String, PluginInfo> infosByKey = new HashMap<>(); + Map<String, PluginInfo> infosByKey = new HashMap<>(remotePlugins.size()); Profiler profiler = Profiler.create(LOG).startDebug("Load plugins"); @@ -114,7 +114,7 @@ public class ScannerPluginInstaller implements PluginInstaller { try { String pluginIndex = loadPluginIndex(); String[] rows = StringUtils.split(pluginIndex, CharUtils.LF); - List<RemotePlugin> result = Lists.newArrayList(); + List<RemotePlugin> result = new ArrayList<>(); for (String row : rows) { result.add(RemotePlugin.unmarshal(row)); } @@ -131,10 +131,10 @@ public class ScannerPluginInstaller implements PluginInstaller { String str; try (Reader reader = wsClient.call(getRequest).contentReader()) { str = IOUtils.toString(reader); - } catch(IOException e) { + } catch (IOException e) { throw new IllegalStateException(e); } - + profiler.stopInfo(); return str; } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginPredicate.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginPredicate.java index e3d0e2daea4..8e635486712 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginPredicate.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginPredicate.java @@ -22,10 +22,11 @@ package org.sonar.scanner.bootstrap; import com.google.common.base.Joiner; import com.google.common.base.Predicate; import com.google.common.base.Splitter; -import com.google.common.collect.Lists; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; import javax.annotation.Nonnull; @@ -93,6 +94,7 @@ public class ScannerPluginPredicate implements Predicate<String> { private static List<String> propertyValues(Settings settings, String key, String defaultValue) { String s = StringUtils.defaultIfEmpty(settings.getString(key), defaultValue); - return Lists.newArrayList(Splitter.on(",").trimResults().omitEmptyStrings().split(s)); + return StreamSupport.stream(Splitter.on(",").trimResults().omitEmptyStrings().split(s).spliterator(), false) + .collect(Collectors.toList()); } } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/UserProperties.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/UserProperties.java index 6e63e8643d7..24ea4c95305 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/UserProperties.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/UserProperties.java @@ -19,11 +19,11 @@ */ package org.sonar.scanner.bootstrap; -import com.google.common.collect.Maps; import org.sonar.api.config.Encryption; import javax.annotation.Nullable; +import java.util.HashMap; import java.util.Map; /** @@ -36,7 +36,7 @@ public abstract class UserProperties { public UserProperties(Map<String, String> properties, @Nullable String pathToSecretKey) { encryption = new Encryption(pathToSecretKey); - Map<String, String> decryptedProps = Maps.newHashMap(); + Map<String, String> decryptedProps = new HashMap<>(properties.size()); for (Map.Entry<String, String> entry : properties.entrySet()) { String value = entry.getValue(); if (value != null && encryption.isEncrypted(value)) { @@ -48,7 +48,7 @@ public abstract class UserProperties { } decryptedProps.put(entry.getKey(), value); } - this.properties = Maps.newHashMap(decryptedProps); + this.properties = decryptedProps; } public Map<String, String> properties() { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/events/EventBus.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/events/EventBus.java index fbbccc6bf11..2529f434a31 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/events/EventBus.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/events/EventBus.java @@ -19,9 +19,9 @@ */ package org.sonar.scanner.events; -import com.google.common.collect.Lists; import org.sonar.api.batch.events.EventHandler; +import java.util.ArrayList; import java.util.List; /** @@ -51,7 +51,7 @@ public class EventBus { } private List<EventHandler> getDispatchList(Class<? extends EventHandler> handlerType) { - List<EventHandler> result = Lists.newArrayList(); + List<EventHandler> result = new ArrayList<>(registeredHandlers.length); for (EventHandler handler : registeredHandlers) { if (handlerType.isAssignableFrom(handler.getClass())) { result.add(handler); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/index/DefaultIndex.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/index/DefaultIndex.java index 9a4e49a4eb8..73614569260 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/index/DefaultIndex.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/index/DefaultIndex.java @@ -21,6 +21,7 @@ package org.sonar.scanner.index; import java.util.ArrayList; import java.util.Collection; +import java.util.stream.Collectors; import javax.annotation.CheckForNull; @@ -41,7 +42,6 @@ import org.sonar.api.resources.Directory; import org.sonar.api.resources.File; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; -import org.sonar.core.util.stream.Collectors; import org.sonar.scanner.scan.filesystem.InputComponentStore; import org.sonar.scanner.scan.measure.MeasureCache; import org.sonar.scanner.sensor.DefaultSensorStorage; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultIssueFilterChain.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultIssueFilterChain.java index 270665a3837..52d5bfb13da 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultIssueFilterChain.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultIssueFilterChain.java @@ -19,9 +19,10 @@ */ package org.sonar.scanner.issue; -import com.google.common.collect.ImmutableList; import org.sonar.api.scan.issue.filter.IssueFilter; +import java.util.Arrays; +import java.util.Collections; import java.util.List; import org.sonar.api.scan.issue.filter.FilterableIssue; @@ -31,11 +32,11 @@ public class DefaultIssueFilterChain implements IssueFilterChain { private final List<IssueFilter> filters; public DefaultIssueFilterChain(IssueFilter... filters) { - this.filters = ImmutableList.copyOf(filters); + this.filters = Collections.unmodifiableList(Arrays.asList(filters)); } public DefaultIssueFilterChain() { - this.filters = ImmutableList.of(); + this.filters = Collections.emptyList(); } private DefaultIssueFilterChain(List<IssueFilter> filters) { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultProjectIssues.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultProjectIssues.java index aa442f6ecf0..d3dc99fef58 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultProjectIssues.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DefaultProjectIssues.java @@ -19,12 +19,14 @@ */ package org.sonar.scanner.issue; -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; import org.sonar.api.issue.Issue; import org.sonar.api.issue.ProjectIssues; import org.sonar.scanner.issue.tracking.TrackedIssue; + +import java.util.function.Predicate; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; + import javax.annotation.Nullable; /** @@ -32,7 +34,8 @@ import javax.annotation.Nullable; * @since 4.0 */ public class DefaultProjectIssues implements ProjectIssues { - + private static final Predicate<TrackedIssue> RESOLVED = new ResolvedPredicate(true); + private static final Predicate<TrackedIssue> NOT_RESOLVED = new ResolvedPredicate(false); private final IssueCache cache; public DefaultProjectIssues(IssueCache cache) { @@ -41,16 +44,18 @@ public class DefaultProjectIssues implements ProjectIssues { @Override public Iterable<Issue> issues() { - return Iterables.transform( - Iterables.filter(cache.all(), new ResolvedPredicate(false)), - new IssueTransformer()); + return StreamSupport.stream(cache.all().spliterator(), false) + .filter(NOT_RESOLVED) + .map(TrackedIssueAdapter::new) + .collect(Collectors.toList()); } @Override public Iterable<Issue> resolvedIssues() { - return Iterables.transform( - Iterables.filter(cache.all(), new ResolvedPredicate(true)), - new IssueTransformer()); + return StreamSupport.stream(cache.all().spliterator(), false) + .filter(RESOLVED) + .map(TrackedIssueAdapter::new) + .collect(Collectors.toList()); } private static class ResolvedPredicate implements Predicate<TrackedIssue> { @@ -61,18 +66,11 @@ public class DefaultProjectIssues implements ProjectIssues { } @Override - public boolean apply(@Nullable TrackedIssue issue) { + public boolean test(@Nullable TrackedIssue issue) { if (issue != null) { return resolved ? (issue.resolution() != null) : (issue.resolution() == null); } return false; } } - - private static class IssueTransformer implements Function<TrackedIssue, Issue> { - @Override - public Issue apply(TrackedIssue issue) { - return new TrackedIssueAdapter(issue); - } - } } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DeprecatedIssueFilterChain.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DeprecatedIssueFilterChain.java index e3ec5e5517d..2e4cea8b814 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DeprecatedIssueFilterChain.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/DeprecatedIssueFilterChain.java @@ -19,11 +19,12 @@ */ package org.sonar.scanner.issue; -import com.google.common.collect.ImmutableList; import org.sonar.api.issue.Issue; import org.sonar.api.issue.batch.IssueFilter; import org.sonar.api.issue.batch.IssueFilterChain; +import java.util.Arrays; +import java.util.Collections; import java.util.List; /** @@ -35,11 +36,11 @@ public class DeprecatedIssueFilterChain implements IssueFilterChain { private final List<IssueFilter> filters; public DeprecatedIssueFilterChain(IssueFilter... filters) { - this.filters = ImmutableList.copyOf(filters); + this.filters = Arrays.asList(filters); } public DeprecatedIssueFilterChain() { - this.filters = ImmutableList.of(); + this.filters = Collections.emptyList(); } private DeprecatedIssueFilterChain(List<IssueFilter> filters) { 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 1c2064449ae..cd107be1223 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 @@ -20,11 +20,11 @@ package org.sonar.scanner.issue.ignore.pattern; import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Lists; import org.apache.commons.lang.StringUtils; import org.sonar.api.batch.ScannerSide; import org.sonar.api.config.Settings; +import java.util.ArrayList; import java.util.List; import static com.google.common.base.MoreObjects.firstNonNull; @@ -62,7 +62,7 @@ public abstract class AbstractPatternInitializer { @VisibleForTesting protected final void initPatterns() { // Patterns Multicriteria - multicriteriaPatterns = Lists.newArrayList(); + multicriteriaPatterns = new ArrayList<>(); String patternConf = StringUtils.defaultIfBlank(settings.getString(getMulticriteriaConfigurationKey()), ""); for (String id : StringUtils.split(patternConf, ',')) { String propPrefix = getMulticriteriaConfigurationKey() + "." + id + "."; 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 c1311a03b13..cde3c0ccb8b 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 @@ -20,11 +20,11 @@ package org.sonar.scanner.issue.ignore.pattern; import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Lists; import org.apache.commons.lang.StringUtils; import org.sonar.api.config.Settings; import org.sonar.core.config.IssueExclusionProperties; +import java.util.ArrayList; import java.util.List; import static com.google.common.base.Strings.nullToEmpty; @@ -67,7 +67,7 @@ public class IssueExclusionPatternInitializer extends AbstractPatternInitializer @VisibleForTesting protected final void loadFileContentPatterns() { // Patterns Block - blockPatterns = Lists.newArrayList(); + blockPatterns = new ArrayList<>(); String patternConf = StringUtils.defaultIfBlank(getSettings().getString(IssueExclusionProperties.PATTERNS_BLOCK_KEY), ""); for (String id : StringUtils.split(patternConf, ',')) { String propPrefix = IssueExclusionProperties.PATTERNS_BLOCK_KEY + "." + id + "."; @@ -80,7 +80,7 @@ public class IssueExclusionPatternInitializer extends AbstractPatternInitializer } // Patterns All File - allFilePatterns = Lists.newArrayList(); + allFilePatterns = new ArrayList<>(); patternConf = StringUtils.defaultIfBlank(getSettings().getString(IssueExclusionProperties.PATTERNS_ALLFILE_KEY), ""); for (String id : StringUtils.split(patternConf, ',')) { String propPrefix = IssueExclusionProperties.PATTERNS_ALLFILE_KEY + "." + id + "."; 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 80183709076..9f7face2823 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 @@ -20,8 +20,8 @@ package org.sonar.scanner.issue.ignore.pattern; import com.google.common.base.Preconditions; -import com.google.common.collect.Sets; +import java.util.LinkedHashSet; import java.util.Set; public class LineRange { @@ -40,7 +40,7 @@ public class LineRange { } public Set<Integer> toLines() { - Set<Integer> lines = Sets.newLinkedHashSet(); + Set<Integer> lines = new LinkedHashSet<>(to-from+1); for (int index = from; index <= to; index++) { lines.add(index); } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/PatternDecoder.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/PatternDecoder.java index a24e583aca0..ddf7c74ad73 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/PatternDecoder.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/PatternDecoder.java @@ -20,10 +20,10 @@ package org.sonar.scanner.issue.ignore.pattern; import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Lists; import org.apache.commons.lang.StringUtils; import org.sonar.api.utils.SonarException; +import java.util.LinkedList; import java.util.List; public class PatternDecoder { @@ -33,7 +33,7 @@ public class PatternDecoder { private static final String CONFIG_FORMAT_ERROR_PREFIX = "Exclusions > Issues : Invalid format. "; public List<IssuePattern> decode(String patternsList) { - List<IssuePattern> patterns = Lists.newLinkedList(); + List<IssuePattern> patterns = new LinkedList<>(); String[] patternsLines = StringUtils.split(patternsList, "\n"); for (String patternLine : patternsLines) { IssuePattern pattern = decodeLine(patternLine.trim()); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsRegexpScanner.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsRegexpScanner.java index c031ef90572..5e6ac3cd3b4 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsRegexpScanner.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsRegexpScanner.java @@ -19,9 +19,6 @@ */ package org.sonar.scanner.issue.ignore.scanner; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,6 +29,9 @@ import org.sonar.scanner.issue.ignore.pattern.LineRange; import java.io.File; import java.io.IOException; import java.nio.charset.Charset; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -53,9 +53,9 @@ public class IssueExclusionsRegexpScanner { public IssueExclusionsRegexpScanner(IssueExclusionPatternInitializer patternsInitializer) { this.exclusionPatternInitializer = patternsInitializer; - lineExclusions = Lists.newArrayList(); - allFilePatterns = Lists.newArrayList(); - blockMatchers = Lists.newArrayList(); + lineExclusions = new ArrayList<>(); + allFilePatterns = new ArrayList<>(); + blockMatchers = new ArrayList<>(); for (IssuePattern pattern : patternsInitializer.getAllFilePatterns()) { allFilePatterns.add(java.util.regex.Pattern.compile(pattern.getAllFileRegexp())); @@ -80,7 +80,7 @@ public class IssueExclusionsRegexpScanner { LOG.debug("Scanning {}", resource); init(); - List<String> lines = FileUtils.readLines(file, sourcesEncoding.name()); + List<String> lines = Files.readAllLines(file.toPath(), sourcesEncoding); int lineIndex = 0; for (String line : lines) { lineIndex++; @@ -117,7 +117,7 @@ public class IssueExclusionsRegexpScanner { } private Set<LineRange> convertLineExclusionsToLineRanges() { - Set<LineRange> lineRanges = Sets.newHashSet(); + Set<LineRange> lineRanges = new HashSet<>(lineExclusions.size()); for (LineExclusion lineExclusion : lineExclusions) { lineRanges.add(lineExclusion.toLineRange()); } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/ServerIssueRepository.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/ServerIssueRepository.java index f706da4e545..2398aa083a5 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/ServerIssueRepository.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/ServerIssueRepository.java @@ -19,7 +19,8 @@ */ package org.sonar.scanner.issue.tracking; -import com.google.common.base.Function; +import java.util.function.Function; + import javax.annotation.Nullable; import org.sonar.api.batch.ScannerSide; import org.sonar.api.batch.fs.InputComponent; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/SourceHashHolder.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/SourceHashHolder.java index 1a6c04912b7..7d9e32b27ae 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/SourceHashHolder.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/tracking/SourceHashHolder.java @@ -19,13 +19,13 @@ */ package org.sonar.scanner.issue.tracking; -import com.google.common.collect.ImmutableSet; import org.sonar.api.batch.fs.InputFile.Status; import org.sonar.api.batch.fs.internal.DefaultInputFile; import javax.annotation.CheckForNull; import java.util.Collection; +import java.util.Collections; public class SourceHashHolder { @@ -69,7 +69,7 @@ public class SourceHashHolder { public Collection<Integer> getNewLinesMatching(Integer originLine) { FileHashes reference = getHashedReference(); if (reference == null) { - return ImmutableSet.of(); + return Collections.emptySet(); } else { return getHashedSource().getLinesForHash(reference.getHash(originLine)); } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/PhasesTimeProfiler.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/PhasesTimeProfiler.java index 9d22f5409f9..e2688dcf468 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/PhasesTimeProfiler.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/PhasesTimeProfiler.java @@ -62,7 +62,7 @@ public class PhasesTimeProfiler implements SensorExecutionHandler, SensorsPhaseH } } - private ClassLoader getSensorClassLoader(Sensor sensor) { + private static ClassLoader getSensorClassLoader(Sensor sensor) { if (sensor instanceof SensorWrapper) { SensorWrapper wrapper = (SensorWrapper) sensor; return wrapper.wrappedSensor().getClass().getClassLoader(); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/PostJobsExecutor.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/PostJobsExecutor.java index 881a81df796..de3a57f3a9b 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/PostJobsExecutor.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/PostJobsExecutor.java @@ -19,7 +19,7 @@ */ package org.sonar.scanner.phases; -import com.google.common.collect.Lists; +import java.util.ArrayList; import java.util.Collection; import org.apache.commons.lang.StringUtils; import org.sonar.api.batch.PostJob; @@ -50,9 +50,9 @@ public class PostJobsExecutor { public void execute(SensorContext context) { Collection<PostJob> postJobs = selector.select(PostJob.class, module, true, null); - eventBus.fireEvent(new PostJobPhaseEvent(Lists.newArrayList(postJobs), true)); + eventBus.fireEvent(new PostJobPhaseEvent(new ArrayList<>(postJobs), true)); execute(context, postJobs); - eventBus.fireEvent(new PostJobPhaseEvent(Lists.newArrayList(postJobs), false)); + eventBus.fireEvent(new PostJobPhaseEvent(new ArrayList<>(postJobs), false)); } private void execute(SensorContext context, Collection<PostJob> postJobs) { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/postjob/DefaultPostJobContext.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/postjob/DefaultPostJobContext.java index a647c150cce..5222166320e 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/postjob/DefaultPostJobContext.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/postjob/DefaultPostJobContext.java @@ -19,9 +19,10 @@ */ package org.sonar.scanner.postjob; -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; + import javax.annotation.Nullable; import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.fs.InputComponent; @@ -63,7 +64,10 @@ public class DefaultPostJobContext implements PostJobContext { if (!analysisMode.isIssues()) { throw new UnsupportedOperationException("Issues are only available to PostJobs in 'issues' mode."); } - return Iterables.transform(Iterables.filter(cache.all(), new ResolvedPredicate(false)), new IssueTransformer()); + return StreamSupport.stream(cache.all().spliterator(), false) + .filter(new ResolvedPredicate(false)) + .map(DefaultIssueWrapper::new) + .collect(Collectors.toList()); } @Override @@ -71,7 +75,10 @@ public class DefaultPostJobContext implements PostJobContext { if (!analysisMode.isIssues()) { throw new UnsupportedOperationException("Resolved issues are only available to PostJobs in 'issues' mode."); } - return Iterables.transform(Iterables.filter(cache.all(), new ResolvedPredicate(true)), new IssueTransformer()); + return StreamSupport.stream(cache.all().spliterator(), false) + .filter(new ResolvedPredicate(true)) + .map(DefaultIssueWrapper::new) + .collect(Collectors.toList()); } private class DefaultIssueWrapper implements PostJobIssue { @@ -123,13 +130,6 @@ public class DefaultPostJobContext implements PostJobContext { } } - private class IssueTransformer implements Function<TrackedIssue, PostJobIssue> { - @Override - public PostJobIssue apply(TrackedIssue input) { - return new DefaultIssueWrapper(input); - } - } - private static class ResolvedPredicate implements Predicate<TrackedIssue> { private final boolean resolved; @@ -138,7 +138,7 @@ public class DefaultPostJobContext implements PostJobContext { } @Override - public boolean apply(@Nullable TrackedIssue issue) { + public boolean test(@Nullable TrackedIssue issue) { if (issue != null) { return resolved ? issue.resolution() != null : issue.resolution() == null; } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java index d51d3a4b1a4..f53c9c9e311 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java @@ -20,6 +20,7 @@ package org.sonar.scanner.report; import java.util.Collection; +import java.util.stream.Collectors; import javax.annotation.CheckForNull; import org.apache.commons.lang.StringUtils; @@ -36,7 +37,6 @@ import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.InputComponentTree; import org.sonar.api.batch.fs.internal.InputModuleHierarchy; import org.sonar.core.util.CloseableIterator; -import org.sonar.core.util.stream.Collectors; import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.protocol.output.ScannerReportReader; import org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ContextPropertiesPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ContextPropertiesPublisher.java index 60428aaa7fc..260ec9b4ce8 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ContextPropertiesPublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ContextPropertiesPublisher.java @@ -19,16 +19,17 @@ */ package org.sonar.scanner.report; -import com.google.common.base.Function; -import com.google.common.collect.Iterables; import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + import javax.annotation.Nonnull; import org.sonar.api.config.Settings; import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.protocol.output.ScannerReportWriter; import org.sonar.scanner.repository.ContextPropertiesCache; -import static com.google.common.collect.FluentIterable.from; import static org.sonar.core.config.WebhookProperties.ANALYSIS_PROPERTY_PREFIX; public class ContextPropertiesPublisher implements ReportPublisherStep { @@ -46,16 +47,15 @@ public class ContextPropertiesPublisher implements ReportPublisherStep { MapEntryToContextPropertyFunction transformer = new MapEntryToContextPropertyFunction(); // properties defined programmatically by plugins - Iterable<ScannerReport.ContextProperty> fromCache = from(cache.getAll().entrySet()) - .transform(transformer); + Stream<ScannerReport.ContextProperty> fromCache = cache.getAll().entrySet().stream().map(transformer); // properties that are automatically included to report so that // they can be included to webhook payloads - Iterable<ScannerReport.ContextProperty> fromSettings = from(settings.getProperties().entrySet()) + Stream<ScannerReport.ContextProperty> fromSettings = settings.getProperties().entrySet().stream() .filter(e -> e.getKey().startsWith(ANALYSIS_PROPERTY_PREFIX)) - .transform(transformer); + .map(transformer); - writer.writeContextProperties(Iterables.concat(fromCache, fromSettings)); + writer.writeContextProperties(Stream.concat(fromCache, fromSettings).collect(Collectors.toList())); } private static final class MapEntryToContextPropertyFunction implements Function<Map.Entry<String, String>, ScannerReport.ContextProperty> { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MeasuresPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MeasuresPublisher.java index ba283458e14..df616624a4e 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MeasuresPublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MeasuresPublisher.java @@ -23,6 +23,7 @@ import com.google.common.collect.Iterables; import java.io.Serializable; import java.util.Collections; import java.util.Map; +import java.util.stream.Collectors; import java.util.stream.StreamSupport; import org.sonar.api.batch.fs.InputComponent; @@ -35,7 +36,6 @@ import org.sonar.api.measures.CoreMetrics; import org.sonar.api.test.MutableTestPlan; import org.sonar.api.test.TestCase.Status; import org.sonar.api.utils.KeyValueFormat; -import org.sonar.core.util.stream.Collectors; import org.sonar.scanner.deprecated.test.TestPlanBuilder; import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.protocol.output.ScannerReport.Measure.BoolValue; 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 e0c50ecb416..1debaa7a665 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 @@ -21,13 +21,15 @@ package org.sonar.scanner.report; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Throwables; -import com.google.common.io.Files; + import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.Writer; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.LinkedHashMap; import java.util.Map; import javax.annotation.Nullable; @@ -222,8 +224,8 @@ public class ReportPublisher implements Startable { } private void dumpMetadata(Map<String, String> metadata) { - File file = new File(projectReactor.getRoot().getWorkDir(), METADATA_DUMP_FILENAME); - try (Writer output = Files.newWriter(file, StandardCharsets.UTF_8)) { + Path file = projectReactor.getRoot().getWorkDir().toPath().resolve(METADATA_DUMP_FILENAME); + try (Writer output = Files.newBufferedWriter(file, StandardCharsets.UTF_8)) { for (Map.Entry<String, String> entry : metadata.entrySet()) { output.write(entry.getKey()); output.write("="); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultServerIssuesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultServerIssuesLoader.java index 6c796eae544..77417c3448b 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultServerIssuesLoader.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultServerIssuesLoader.java @@ -19,9 +19,10 @@ */ package org.sonar.scanner.repository; -import com.google.common.base.Function; import java.io.IOException; import java.io.InputStream; +import java.util.function.Function; + import org.apache.commons.io.IOUtils; import org.sonar.scanner.bootstrap.ScannerWsClient; import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ServerIssuesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ServerIssuesLoader.java index 9d88cc7ff04..04bf5849806 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ServerIssuesLoader.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ServerIssuesLoader.java @@ -19,7 +19,8 @@ */ package org.sonar.scanner.repository; -import com.google.common.base.Function; +import java.util.function.Function; + import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue; public interface ServerIssuesLoader { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ModuleQProfiles.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ModuleQProfiles.java index e777a1643a8..421a1b5b9d7 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ModuleQProfiles.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ModuleQProfiles.java @@ -22,12 +22,13 @@ package org.sonar.scanner.rule; import org.sonar.api.utils.DateUtils; import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile; -import com.google.common.collect.ImmutableMap; import org.sonar.api.batch.ScannerSide; import javax.annotation.CheckForNull; import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; import java.util.Map; /** @@ -40,17 +41,17 @@ public class ModuleQProfiles { private final Map<String, QProfile> byLanguage; public ModuleQProfiles(Collection<QualityProfile> profiles) { - ImmutableMap.Builder<String, QProfile> builder = ImmutableMap.builder(); + Map<String, QProfile> map = new HashMap<>(profiles.size()); for (QualityProfile qProfile : profiles) { - builder.put(qProfile.getLanguage(), + map.put(qProfile.getLanguage(), new QProfile() .setKey(qProfile.getKey()) .setName(qProfile.getName()) .setLanguage(qProfile.getLanguage()) .setRulesUpdatedAt(DateUtils.parseDateTime(qProfile.getRulesUpdatedAt()))); } - byLanguage = builder.build(); + byLanguage = Collections.unmodifiableMap(map); } public Collection<QProfile> findAll() { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RuleFinderCompatibility.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RuleFinderCompatibility.java index ea78959f3c7..cefd47fa861 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RuleFinderCompatibility.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RuleFinderCompatibility.java @@ -22,6 +22,8 @@ package org.sonar.scanner.rule; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.stream.Collectors; + import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.commons.lang.builder.ReflectionToStringBuilder; @@ -31,7 +33,6 @@ import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; import org.sonar.api.rules.RuleQuery; -import org.sonar.core.util.stream.Collectors; public class RuleFinderCompatibility implements RuleFinder { @@ -87,7 +88,7 @@ public class RuleFinderCompatibility implements RuleFinder { private Collection<Rule> byRepository(RuleQuery query) { return rules.findByRepository(query.getRepositoryKey()).stream() .map(RuleFinderCompatibility::toRule) - .collect(Collectors.toArrayList()); + .collect(Collectors.toList()); } private Collection<Rule> byKey(RuleQuery query) { @@ -98,7 +99,7 @@ public class RuleFinderCompatibility implements RuleFinder { private Collection<Rule> byInternalKey(RuleQuery query) { return rules.findByInternalKey(query.getRepositoryKey(), query.getConfigKey()).stream() .map(RuleFinderCompatibility::toRule) - .collect(Collectors.toArrayList()); + .collect(Collectors.toList()); } @CheckForNull diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProfileProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProfileProvider.java index d96888bbe34..b1326433356 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProfileProvider.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProfileProvider.java @@ -19,7 +19,7 @@ */ package org.sonar.scanner.rule; -import com.google.common.collect.Lists; +import java.util.ArrayList; import java.util.Collection; import java.util.Map; import org.apache.commons.lang.StringUtils; @@ -57,12 +57,13 @@ public class RulesProfileProvider extends ProviderAdapter { if (qProfile != null) { return new RulesProfileWrapper(select(qProfile, activeRules)); } - return new RulesProfileWrapper(Lists.<RulesProfile>newArrayList()); + return new RulesProfileWrapper(new ArrayList<>()); } private static RulesProfile loadProfiles(ModuleQProfiles qProfiles, ActiveRules activeRules) { - Collection<RulesProfile> dtos = Lists.newArrayList(); - for (QProfile qProfile : qProfiles.findAll()) { + Collection<QProfile> profiles = qProfiles.findAll(); + Collection<RulesProfile> dtos = new ArrayList<>(profiles.size()); + for (QProfile qProfile : profiles) { dtos.add(select(qProfile, activeRules)); } return new RulesProfileWrapper(dtos); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProfileWrapper.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProfileWrapper.java index d71448d21cc..772891b7b9c 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProfileWrapper.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/RulesProfileWrapper.java @@ -19,7 +19,6 @@ */ package org.sonar.scanner.rule; -import com.google.common.collect.Lists; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.profiles.RulesProfile; @@ -29,6 +28,7 @@ import org.sonar.api.utils.SonarException; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; /** @@ -51,7 +51,7 @@ public class RulesProfileWrapper extends RulesProfile { } public RulesProfileWrapper(RulesProfile profile) { - this.profiles = Lists.newArrayList(profile); + this.profiles = Collections.singletonList(profile); this.singleLanguageProfile = profile; } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleSettings.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleSettings.java index c5f4dbaa3d7..b167347ad0c 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleSettings.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleSettings.java @@ -19,7 +19,7 @@ */ package org.sonar.scanner.scan; -import com.google.common.collect.Lists; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -79,7 +79,7 @@ public class ModuleSettings extends Settings { * From root to given project */ static List<ProjectDefinition> getTopDownParentProjects(ProjectDefinition project) { - List<ProjectDefinition> result = Lists.newArrayList(); + List<ProjectDefinition> result = new ArrayList<>(); ProjectDefinition p = project; while (p != null) { result.add(0, p); 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 3baf5893654..da55a202d6c 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 @@ -20,9 +20,9 @@ package org.sonar.scanner.scan.filesystem; import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Lists; import java.io.File; import java.nio.charset.Charset; +import java.util.ArrayList; import java.util.List; import org.apache.commons.lang.StringUtils; import org.sonar.api.CoreProperties; @@ -42,8 +42,8 @@ public class DefaultModuleFileSystem extends DefaultFileSystem { private FileIndexer indexer; private Settings settings; - private List<File> sourceDirsOrFiles = Lists.newArrayList(); - private List<File> testDirsOrFiles = Lists.newArrayList(); + private List<File> sourceDirsOrFiles = new ArrayList<>(); + private List<File> testDirsOrFiles = new ArrayList<>(); private boolean initialized; private Charset charset = null; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/LanguageDetection.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/LanguageDetection.java index 847f3f2f364..50b4c8cdf29 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/LanguageDetection.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/LanguageDetection.java @@ -20,9 +20,9 @@ package org.sonar.scanner.scan.filesystem; import com.google.common.base.Joiner; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import javax.annotation.CheckForNull; @@ -49,8 +49,8 @@ public class LanguageDetection { /** * Lower-case extension -> languages */ - private final Map<String, PathPattern[]> patternsByLanguage = Maps.newLinkedHashMap(); - private final List<String> languagesToConsider = Lists.newArrayList(); + private final Map<String, PathPattern[]> patternsByLanguage = new LinkedHashMap<>(); + private final List<String> languagesToConsider = new ArrayList<>(); private final String forcedLanguage; public LanguageDetection(Settings settings, LanguagesRepository languages) { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ModuleFileSystemInitializer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ModuleFileSystemInitializer.java index e0bdd64dc4b..f37c3267b0b 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ModuleFileSystemInitializer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ModuleFileSystemInitializer.java @@ -19,8 +19,8 @@ */ package org.sonar.scanner.scan.filesystem; -import com.google.common.collect.Lists; import java.io.File; +import java.util.ArrayList; import java.util.List; import org.apache.commons.io.FileUtils; import org.sonar.api.batch.ScannerSide; @@ -36,8 +36,8 @@ public class ModuleFileSystemInitializer { private File baseDir; private File workingDir; - private List<File> sourceDirsOrFiles = Lists.newArrayList(); - private List<File> testDirsOrFiles = Lists.newArrayList(); + private List<File> sourceDirsOrFiles = new ArrayList<>(); + private List<File> testDirsOrFiles = new ArrayList<>(); public ModuleFileSystemInitializer(ProjectDefinition module, TempFolder tempUtils, PathResolver pathResolver) { baseDir = module.getBaseDir(); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/measure/DeprecatedMetricFinder.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/measure/DeprecatedMetricFinder.java index ef64f649cf2..8507fbbfc69 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/measure/DeprecatedMetricFinder.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/measure/DeprecatedMetricFinder.java @@ -19,9 +19,9 @@ */ package org.sonar.scanner.scan.measure; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.LinkedList; import java.util.List; import java.util.Map; import org.sonar.api.measures.Metric; @@ -30,8 +30,8 @@ import org.sonar.scanner.repository.MetricsRepository; public final class DeprecatedMetricFinder implements MetricFinder { - private Map<String, Metric> metricsByKey = Maps.newLinkedHashMap(); - private Map<Integer, Metric> metricsById = Maps.newLinkedHashMap(); + private Map<String, Metric> metricsByKey = new LinkedHashMap<>(); + private Map<Integer, Metric> metricsById = new LinkedHashMap<>(); public DeprecatedMetricFinder(MetricsRepository metricsRepository) { for (Metric metric : metricsRepository.metrics()) { @@ -52,7 +52,7 @@ public final class DeprecatedMetricFinder implements MetricFinder { @Override public Collection<Metric> findAll(List<String> metricKeys) { - List<Metric> result = Lists.newLinkedList(); + List<Metric> result = new LinkedList<>(); for (String metricKey : metricKeys) { Metric metric = findByKey(metricKey); if (metric != null) { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/ResourceReport.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/ResourceReport.java index fb6782b3d91..8a70a49b7d5 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/ResourceReport.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/report/ResourceReport.java @@ -19,9 +19,10 @@ */ package org.sonar.scanner.scan.report; -import com.google.common.collect.Maps; import java.util.ArrayList; import java.util.Collections; +import java.util.EnumMap; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; @@ -40,13 +41,13 @@ import org.sonar.scanner.issue.tracking.TrackedIssue; public final class ResourceReport { private final InputComponent component; private final IssueVariation total = new IssueVariation(); - private final Map<ReportRuleKey, RuleReport> ruleReportByRuleKey = Maps.newHashMap(); + private final Map<ReportRuleKey, RuleReport> ruleReportByRuleKey = new HashMap<>(); private List<TrackedIssue> issues = new ArrayList<>(); - private Map<Integer, List<TrackedIssue>> issuesPerLine = Maps.newHashMap(); - private Map<Integer, List<TrackedIssue>> newIssuesPerLine = Maps.newHashMap(); - private Map<Rule, AtomicInteger> issuesByRule = Maps.newHashMap(); - private Map<RulePriority, AtomicInteger> issuesBySeverity = Maps.newHashMap(); + private Map<Integer, List<TrackedIssue>> issuesPerLine = new HashMap<>(); + private Map<Integer, List<TrackedIssue>> newIssuesPerLine = new HashMap<>(); + private Map<Rule, AtomicInteger> issuesByRule = new HashMap<>(); + private Map<RulePriority, AtomicInteger> issuesBySeverity = new EnumMap<>(RulePriority.class); public ResourceReport(InputComponent component) { this.component = component; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/source/CodeColorizers.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/source/CodeColorizers.java index c30dd8ea091..74d3672d506 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/source/CodeColorizers.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/source/CodeColorizers.java @@ -19,13 +19,13 @@ */ package org.sonar.scanner.source; -import com.google.common.collect.Lists; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.io.Reader; import java.nio.charset.Charset; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -62,7 +62,7 @@ public class CodeColorizers { * Used when no plugin is defining some CodeColorizerFormat */ public CodeColorizers() { - this(Lists.<CodeColorizerFormat>newArrayList()); + this(new ArrayList<>()); } @CheckForNull diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/source/ZeroCoverageSensor.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/source/ZeroCoverageSensor.java index 0d2b51a3f70..4ae016a71dc 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/source/ZeroCoverageSensor.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/source/ZeroCoverageSensor.java @@ -19,10 +19,11 @@ */ package org.sonar.scanner.source; -import com.google.common.base.Function; -import com.google.common.collect.Sets; import java.util.Map; import java.util.Set; +import java.util.function.Function; +import java.util.stream.StreamSupport; + import org.sonar.api.batch.Phase; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.fs.InputFile; @@ -36,11 +37,11 @@ import org.sonar.api.batch.sensor.coverage.NewCoverage; import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.utils.KeyValueFormat; +import org.sonar.core.util.stream.Collectors; import org.sonar.scanner.scan.measure.MeasureCache; import org.sonar.scanner.sensor.coverage.CoverageExclusions; -import static com.google.common.collect.Iterables.transform; -import static com.google.common.collect.Sets.newHashSet; +import com.google.common.collect.Sets; @Phase(name = Phase.Name.POST) public final class ZeroCoverageSensor implements Sensor { @@ -101,9 +102,10 @@ public final class ZeroCoverageSensor implements Sensor { } private boolean isCoverageMeasuresAlreadyDefined(InputFile f) { - Set<String> metricKeys = newHashSet(transform(measureCache.byComponentKey(f.key()), new MeasureToMetricKey())); + Set<String> metricKeys = StreamSupport.stream(measureCache.byComponentKey(f.key()).spliterator(), false) + .map(new MeasureToMetricKey()).collect(Collectors.toSet()); Function<Metric, String> metricToKey = new MetricToKey(); - Set<String> allCoverageMetricKeys = newHashSet(transform(CoverageType.UNIT.allMetrics(), metricToKey)); + Set<String> allCoverageMetricKeys = CoverageType.UNIT.allMetrics().stream().map(metricToKey).collect(Collectors.toSet()); return !Sets.intersection(metricKeys, allCoverageMetricKeys).isEmpty(); } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/storage/Storages.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/storage/Storages.java index 392f29c07b3..a8b403732b4 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/storage/Storages.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/storage/Storages.java @@ -20,7 +20,6 @@ package org.sonar.scanner.storage; import com.google.common.base.Preconditions; -import com.google.common.collect.Maps; import com.persistit.Exchange; import com.persistit.Persistit; import com.persistit.Value; @@ -28,6 +27,8 @@ import com.persistit.Volume; import com.persistit.encoding.CoderManager; import com.persistit.encoding.ValueCoder; import com.persistit.exception.PersistitException; + +import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import org.picocontainer.Startable; @@ -35,7 +36,7 @@ import org.sonar.api.batch.ScannerSide; @ScannerSide public class Storages implements Startable { - private final Map<String, Exchange> cacheMap = Maps.newHashMap(); + private final Map<String, Exchange> cacheMap = new HashMap<>(); private Persistit persistit; private Volume volume; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java index 83bbeff529f..d73e2703efb 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java @@ -19,7 +19,6 @@ */ package org.sonar.scanner.mediumtest; -import com.google.common.base.Function; import com.google.common.collect.HashBasedTable; import com.google.common.collect.Table; import java.io.File; @@ -37,6 +36,8 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.function.Function; + import javax.annotation.Nullable; import org.apache.commons.io.FileUtils; import org.sonar.api.CoreProperties; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultServerIssuesLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultServerIssuesLoaderTest.java index 00351ef8e61..09b6b8e281a 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultServerIssuesLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultServerIssuesLoaderTest.java @@ -21,10 +21,8 @@ package org.sonar.scanner.repository; import org.sonar.scanner.WsTestUtil; import org.sonar.scanner.bootstrap.ScannerWsClient; -import org.sonar.scanner.protocol.input.ScannerInput; import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue; import org.sonar.scanner.repository.DefaultServerIssuesLoader; -import com.google.common.base.Function; import org.junit.Before; import org.junit.Test; import java.io.ByteArrayInputStream; @@ -33,6 +31,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; +import java.util.function.Function; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -61,13 +60,9 @@ public class DefaultServerIssuesLoaderTest { WsTestUtil.mockStream(wsClient, "/batch/issues.protobuf?key=foo", is); final List<ServerIssue> result = new ArrayList<>(); - loader.load("foo", new Function<ScannerInput.ServerIssue, Void>() { - - @Override - public Void apply(ServerIssue input) { - result.add(input); - return null; - } + loader.load("foo", issue -> { + result.add(issue); + return null; }); assertThat(result).extracting("key").containsExactly("ab1", "ab2"); |