From bf83c5fa2ea42614dfd9ab90cddcf5fc5902d4e7 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 12 Apr 2017 22:43:10 +0200 Subject: [PATCH] Remove some usages of Guava in API --- .../sonar/server/util/ClassLoaderUtils.java | 9 +- .../batch/debt/DebtRemediationFunction.java | 36 +++--- .../fs/internal/AbstractFilePredicate.java | 6 +- .../api/batch/fs/internal/AndPredicate.java | 2 - .../batch/fs/internal/DefaultFileSystem.java | 6 +- .../org/sonar/api/batch/rule/RuleParam.java | 3 - .../org/sonar/api/batch/rule/Severity.java | 3 - .../rule/internal/DefaultActiveRule.java | 5 +- .../api/batch/rule/internal/DefaultRule.java | 17 ++- .../batch/sensor/coverage/CoverageType.java | 7 +- .../sensor/cpd/internal/DefaultCpdTokens.java | 17 +-- .../sensor/internal/DefaultStorable.java | 4 +- .../sensor/internal/SensorContextTester.java | 6 +- .../sensor/issue/internal/DefaultIssue.java | 4 +- .../measure/internal/DefaultMeasure.java | 10 +- .../symbol/internal/DefaultSymbolTable.java | 6 +- .../sonar/api/ce/measure/test/TestIssue.java | 12 +- .../test/TestMeasureComputerDefinition.java | 7 +- .../org/sonar/api/config/EmailSettings.java | 8 +- .../java/org/sonar/api/config/Encryption.java | 12 +- .../java/org/sonar/api/config/License.java | 21 ++-- .../org/sonar/api/config/MapSettings.java | 5 +- .../sonar/api/config/PropertyDefinition.java | 30 ++--- .../sonar/api/config/PropertyDefinitions.java | 3 +- .../api/config/PropertyFieldDefinition.java | 16 +-- .../java/org/sonar/api/config/Settings.java | 8 +- .../org/sonar/api/database/model/User.java | 9 +- .../java/org/sonar/api/design/Dependency.java | 43 ++++--- .../sonar/api/issue/DefaultTransitions.java | 6 +- .../main/java/org/sonar/api/issue/Issue.java | 7 +- .../org/sonar/api/issue/NoSonarFilter.java | 14 +-- .../sonar/api/issue/condition/Condition.java | 2 - .../condition/HasIssuePropertyCondition.java | 10 +- .../api/issue/condition/HasResolution.java | 11 +- .../sonar/api/issue/condition/HasStatus.java | 15 +-- .../api/issue/condition/IsUnResolved.java | 2 - .../api/issue/condition/NotCondition.java | 2 - .../api/measures/CoverageMeasuresBuilder.java | 8 +- .../java/org/sonar/api/measures/Measure.java | 3 - .../measures/RangeDistributionBuilder.java | 2 +- .../sonar/api/notifications/Notification.java | 10 +- .../sonar/api/platform/NewUserHandler.java | 8 +- .../org/sonar/api/profiles/RulesProfile.java | 22 ++-- .../org/sonar/api/resources/Languages.java | 4 +- .../org/sonar/api/resources/ResourceType.java | 24 ++-- .../sonar/api/resources/ResourceTypeTree.java | 31 +++-- .../sonar/api/resources/ResourceTypes.java | 111 +++++++----------- .../main/java/org/sonar/api/rule/RuleKey.java | 7 +- .../java/org/sonar/api/rule/Severity.java | 6 +- .../java/org/sonar/api/rules/ActiveRule.java | 15 ++- .../sonar/api/rules/AnnotationRuleParser.java | 4 +- .../main/java/org/sonar/api/rules/Rule.java | 7 +- .../java/org/sonar/api/rules/RuleType.java | 21 ++-- .../org/sonar/api/rules/XMLRuleParser.java | 27 ++--- .../api/scan/filesystem/FileExclusions.java | 32 ++--- .../api/scan/filesystem/PathResolver.java | 5 +- .../org/sonar/api/security/Authenticator.java | 8 +- .../server/authentication/UserIdentity.java | 21 +--- .../DefaultDebtRemediationFunction.java | 1 + .../sonar/api/server/rule/RuleParamType.java | 5 +- .../api/server/rule/RulesDefinition.java | 34 +++--- .../org/sonar/api/server/ws/WebService.java | 15 +-- .../server/ws/internal/SimpleGetRequest.java | 13 +- .../server/ws/internal/ValidatingRequest.java | 4 +- .../java/org/sonar/api/utils/FieldUtils2.java | 11 +- .../sonar/api/utils/LocalizedMessages.java | 22 ++-- .../org/sonar/api/utils/MessageException.java | 11 +- .../java/org/sonar/api/utils/UriReader.java | 4 +- .../org/sonar/api/utils/command/Command.java | 26 ++-- .../java/org/sonar/api/web/Dashboard.java | 4 +- .../java/org/sonar/api/web/ServletFilter.java | 6 +- .../java/org/sonar/api/web/page/Page.java | 4 +- .../debt/DebtRemediationFunctionTest.java | 3 +- 73 files changed, 428 insertions(+), 495 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/util/ClassLoaderUtils.java b/server/sonar-server/src/main/java/org/sonar/server/util/ClassLoaderUtils.java index 49496730b6e..76922996f03 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/util/ClassLoaderUtils.java +++ b/server/sonar-server/src/main/java/org/sonar/server/util/ClassLoaderUtils.java @@ -20,19 +20,20 @@ package org.sonar.server.util; import com.google.common.base.Throwables; -import com.google.common.collect.Lists; import java.net.URL; import java.net.URLDecoder; +import java.util.ArrayList; import java.util.Collection; import java.util.Enumeration; import java.util.function.Predicate; import java.util.jar.JarEntry; import java.util.jar.JarFile; import javax.annotation.Nullable; -import org.apache.commons.lang.CharEncoding; import org.apache.commons.lang.StringUtils; import org.sonar.api.utils.log.Loggers; +import static java.nio.charset.StandardCharsets.UTF_8; + public class ClassLoaderUtils { private ClassLoaderUtils() { @@ -62,7 +63,7 @@ public class ClassLoaderUtils { String jarPath = null; JarFile jar = null; try { - Collection paths = Lists.newArrayList(); + Collection paths = new ArrayList<>(); URL root = classLoader.getResource(rootPath); if (root != null) { checkJarFile(root); @@ -78,7 +79,7 @@ public class ClassLoaderUtils { } // strip out only the JAR file jarPath = root.getPath().substring(5, root.getPath().indexOf('!')); - jar = new JarFile(URLDecoder.decode(jarPath, CharEncoding.UTF_8)); + jar = new JarFile(URLDecoder.decode(jarPath, UTF_8.name())); Enumeration entries = jar.entries(); while (entries.hasMoreElements()) { String name = entries.nextElement().getName(); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/DebtRemediationFunction.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/DebtRemediationFunction.java index caed8fb3749..602d8ebeb1a 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/DebtRemediationFunction.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/DebtRemediationFunction.java @@ -19,14 +19,9 @@ */ package org.sonar.api.batch.debt; -import org.apache.commons.lang.builder.EqualsBuilder; -import org.apache.commons.lang.builder.HashCodeBuilder; -import org.apache.commons.lang.builder.ReflectionToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; -import org.sonar.api.utils.Duration; - import javax.annotation.CheckForNull; import javax.annotation.Nullable; +import org.sonar.api.utils.Duration; /** * @since 4.3 @@ -85,25 +80,32 @@ public class DebtRemediationFunction { if (o == null || getClass() != o.getClass()) { return false; } + DebtRemediationFunction that = (DebtRemediationFunction) o; - return new EqualsBuilder() - .append(type, that.type()) - .append(coefficient, that.coefficient()) - .append(offset, that.offset()) - .isEquals(); + if (type != that.type) { + return false; + } + if (coefficient != null ? !coefficient.equals(that.coefficient) : that.coefficient != null) { + return false; + } + return offset != null ? offset.equals(that.offset) : that.offset == null; } @Override public int hashCode() { - return new HashCodeBuilder(15, 31) - .append(type) - .append(coefficient) - .append(offset) - .toHashCode(); + int result = type.hashCode(); + result = 31 * result + (coefficient != null ? coefficient.hashCode() : 0); + result = 31 * result + (offset != null ? offset.hashCode() : 0); + return result; } @Override public String toString() { - return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString(); + StringBuilder sb = new StringBuilder("DebtRemediationFunction{"); + sb.append("type=").append(type); + sb.append(", coefficient=").append(coefficient); + sb.append(", offset=").append(offset); + sb.append('}'); + return sb.toString(); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AbstractFilePredicate.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AbstractFilePredicate.java index 9cb641b17f9..a4de39904e5 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AbstractFilePredicate.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AbstractFilePredicate.java @@ -19,7 +19,7 @@ */ package org.sonar.api.batch.fs.internal; -import com.google.common.collect.Iterables; +import java.util.stream.StreamSupport; import org.sonar.api.batch.fs.FileSystem.Index; import org.sonar.api.batch.fs.InputFile; @@ -34,7 +34,9 @@ public abstract class AbstractFilePredicate implements OptimizedFilePredicate { @Override public Iterable filter(Iterable target) { - return Iterables.filter(target, this::apply); + return () -> StreamSupport.stream(target.spliterator(), false) + .filter(this::apply) + .iterator(); } @Override diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AndPredicate.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AndPredicate.java index 5c12e74c5a7..863864c185c 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AndPredicate.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AndPredicate.java @@ -19,7 +19,6 @@ */ package org.sonar.api.batch.fs.internal; -import com.google.common.annotations.VisibleForTesting; import org.sonar.api.batch.fs.FilePredicate; import org.sonar.api.batch.fs.FileSystem.Index; import org.sonar.api.batch.fs.InputFile; @@ -91,7 +90,6 @@ class AndPredicate extends AbstractFilePredicate { return result; } - @VisibleForTesting Collection predicates() { return predicates; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFileSystem.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFileSystem.java index dda12ece0fd..f7d2858a7a3 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFileSystem.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFileSystem.java @@ -19,7 +19,6 @@ */ package org.sonar.api.batch.fs.internal; -import com.google.common.collect.Iterables; import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.SetMultimap; import java.io.File; @@ -36,7 +35,6 @@ import java.util.TreeSet; import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.StreamSupport; - import javax.annotation.Nullable; import org.sonar.api.batch.fs.FilePredicate; import org.sonar.api.batch.fs.FilePredicates; @@ -175,7 +173,9 @@ public class DefaultFileSystem implements FileSystem { @Override public Iterable files(FilePredicate predicate) { doPreloadFiles(); - return Iterables.transform(inputFiles(predicate), InputFile::file); + return () -> StreamSupport.stream(inputFiles(predicate).spliterator(), false) + .map(InputFile::file) + .iterator(); } @Override diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/RuleParam.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/RuleParam.java index 83e96fe9d74..7c06501dfbe 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/RuleParam.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/RuleParam.java @@ -19,12 +19,9 @@ */ package org.sonar.api.batch.rule; -import com.google.common.annotations.Beta; - /** * @since 4.2 */ -@Beta public interface RuleParam { String key(); String description(); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Severity.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Severity.java index aa849c68052..d0e708e53e1 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Severity.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Severity.java @@ -19,12 +19,9 @@ */ package org.sonar.api.batch.rule; -import com.google.common.annotations.Beta; - /** * @since 5.2 */ -@Beta public enum Severity { INFO, MINOR, diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultActiveRule.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultActiveRule.java index f84f33f3a09..fe94301af85 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultActiveRule.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultActiveRule.java @@ -19,7 +19,8 @@ */ package org.sonar.api.batch.rule.internal; -import com.google.common.collect.ImmutableMap; +import java.util.Collections; +import java.util.HashMap; import java.util.Map; import javax.annotation.concurrent.Immutable; import org.sonar.api.batch.rule.ActiveRule; @@ -40,7 +41,7 @@ public class DefaultActiveRule implements ActiveRule { this.internalKey = newActiveRule.internalKey; this.templateRuleKey = newActiveRule.templateRuleKey; this.ruleKey = newActiveRule.ruleKey; - this.params = ImmutableMap.copyOf(newActiveRule.params); + this.params = Collections.unmodifiableMap(new HashMap<>(newActiveRule.params)); this.language = newActiveRule.language; this.createdAt = newActiveRule.createdAt; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultRule.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultRule.java index 7d9ae403b1d..d3bb39702a2 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultRule.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultRule.java @@ -19,19 +19,18 @@ */ package org.sonar.api.batch.rule.internal; -import com.google.common.collect.ImmutableMap; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import javax.annotation.CheckForNull; +import javax.annotation.concurrent.Immutable; import org.sonar.api.batch.debt.DebtRemediationFunction; import org.sonar.api.batch.rule.Rule; import org.sonar.api.batch.rule.RuleParam; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.RuleStatus; -import javax.annotation.CheckForNull; -import javax.annotation.concurrent.Immutable; - -import java.util.Collection; -import java.util.Map; - @Immutable public class DefaultRule implements Rule { @@ -55,11 +54,11 @@ public class DefaultRule implements Rule { this.internalKey = newRule.internalKey; this.status = newRule.status; - ImmutableMap.Builder builder = ImmutableMap.builder(); + Map builder = new HashMap<>(); for (NewRuleParam newRuleParam : newRule.params.values()) { builder.put(newRuleParam.key, new DefaultRuleParam(newRuleParam)); } - params = builder.build(); + params = Collections.unmodifiableMap(builder); } @Override diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/CoverageType.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/CoverageType.java index 913449c521e..b0f397623fc 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/CoverageType.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/CoverageType.java @@ -19,7 +19,9 @@ */ package org.sonar.api.batch.sensor.coverage; -import com.google.common.collect.ImmutableSet; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedHashSet; import java.util.Set; import org.sonar.api.measures.Metric; @@ -77,7 +79,8 @@ public enum CoverageType { this.uncoveredConditions = uncoveredConditions; this.coveredConditionsByLine = coveredConditionsByLine; this.conditionsByLine = conditionsByLine; - this.all = ImmutableSet.of(linesToCover, uncoveredLines, lineHitsData, conditionsToCover, uncoveredConditions, coveredConditionsByLine, conditionsByLine); + this.all = Collections + .unmodifiableSet(new LinkedHashSet<>(Arrays.asList(linesToCover, uncoveredLines, lineHitsData, conditionsToCover, uncoveredConditions, coveredConditionsByLine, conditionsByLine))); } public Set allMetrics() { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokens.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokens.java index 78a4d700151..3ff672988da 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokens.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokens.java @@ -19,8 +19,7 @@ */ package org.sonar.api.batch.sensor.cpd.internal; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; +import java.util.ArrayList; import java.util.List; import org.sonar.api.CoreProperties; import org.sonar.api.batch.fs.InputFile; @@ -32,12 +31,14 @@ import org.sonar.api.batch.sensor.internal.SensorStorage; import org.sonar.api.config.Settings; import org.sonar.duplications.internal.pmd.TokensLine; +import static com.google.common.base.Preconditions.checkState; +import static java.util.Collections.unmodifiableList; import static java.util.Objects.requireNonNull; public class DefaultCpdTokens extends DefaultStorable implements NewCpdTokens { private final Settings settings; - private final ImmutableList.Builder result = ImmutableList.builder(); + private final ArrayList result = new ArrayList<>(); private InputFile inputFile; private int startLine = Integer.MIN_VALUE; private int startIndex = 0; @@ -87,7 +88,7 @@ public class DefaultCpdTokens extends DefaultStorable implements NewCpdTokens { if (excluded) { return this; } - Preconditions.checkState(lastRange == null || lastRange.end().compareTo(range.start()) <= 0, + checkState(lastRange == null || lastRange.end().compareTo(range.start()) <= 0, "Tokens of file %s should be provided in order.\nPrevious token: %s\nLast token: %s", inputFile, lastRange, range); String value = image; @@ -106,10 +107,10 @@ public class DefaultCpdTokens extends DefaultStorable implements NewCpdTokens { } public List getTokenLines() { - return result.build(); + return unmodifiableList(new ArrayList<>(result)); } - private static void addNewTokensLine(ImmutableList.Builder result, int startUnit, int endUnit, int startLine, StringBuilder sb) { + private static void addNewTokensLine(List result, int startUnit, int endUnit, int startLine, StringBuilder sb) { if (sb.length() != 0) { result.add(new TokensLine(startUnit, endUnit, startLine, sb.toString())); sb.setLength(0); @@ -118,7 +119,7 @@ public class DefaultCpdTokens extends DefaultStorable implements NewCpdTokens { @Override protected void doSave() { - Preconditions.checkState(inputFile != null, "Call onFile() first"); + checkState(inputFile != null, "Call onFile() first"); if (excluded) { return; } @@ -127,6 +128,6 @@ public class DefaultCpdTokens extends DefaultStorable implements NewCpdTokens { } private void checkInputFileNotNull() { - Preconditions.checkState(inputFile != null, "Call onFile() first"); + checkState(inputFile != null, "Call onFile() first"); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/DefaultStorable.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/DefaultStorable.java index 784f057ee38..9b37630425b 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/DefaultStorable.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/DefaultStorable.java @@ -24,6 +24,8 @@ import javax.annotation.Nullable; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; +import static java.util.Objects.requireNonNull; + public abstract class DefaultStorable { protected final transient SensorStorage storage; @@ -38,7 +40,7 @@ public abstract class DefaultStorable { } public final void save() { - Preconditions.checkNotNull(this.storage, "No persister on this object"); + requireNonNull(this.storage, "No persister on this object"); Preconditions.checkState(!saved, "This object was already saved"); doSave(); this.saved = true; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java index b423754a1e6..4a3d60763ec 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java @@ -19,8 +19,6 @@ */ package org.sonar.api.batch.sensor.internal; -import com.google.common.collect.ImmutableMap; - import java.io.File; import java.io.Serializable; import java.nio.file.Path; @@ -75,6 +73,8 @@ import org.sonar.api.utils.System2; import org.sonar.api.utils.Version; import org.sonar.duplications.internal.pmd.TokensLine; +import static java.util.Collections.unmodifiableMap; + /** * Utility class to help testing {@link Sensor}. This is not an API and method signature may evolve. * @@ -337,7 +337,7 @@ public class SensorContextTester implements SensorContext { * @since 6.1 */ public Map getContextProperties() { - return ImmutableMap.copyOf(sensorStorage.contextProperties); + return unmodifiableMap(sensorStorage.contextProperties); } @Override diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java index fda7d880565..d2522731106 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java @@ -20,7 +20,6 @@ package org.sonar.api.batch.sensor.issue.internal; import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -36,6 +35,7 @@ import org.sonar.api.rule.RuleKey; import static com.google.common.base.Preconditions.checkState; import static java.lang.String.format; +import static java.util.Collections.unmodifiableList; import static java.util.Objects.requireNonNull; import static java.util.stream.Collectors.toList; @@ -137,7 +137,7 @@ public class DefaultIssue extends DefaultStorable implements Issue, NewIssue { @Override public List flows() { return this.flows.stream() - .map(l -> () -> ImmutableList.copyOf(l)) + .map(l -> () -> unmodifiableList(new ArrayList<>(l))) .collect(toList()); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasure.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasure.java index e199d79cf79..f95bf82c817 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasure.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasure.java @@ -31,6 +31,8 @@ import org.sonar.api.batch.sensor.internal.SensorStorage; import org.sonar.api.batch.sensor.measure.Measure; import org.sonar.api.batch.sensor.measure.NewMeasure; +import static java.util.Objects.requireNonNull; + public class DefaultMeasure extends DefaultStorable implements Measure, NewMeasure { private InputComponent component; @@ -57,7 +59,7 @@ public class DefaultMeasure extends DefaultStorable impl @Override public DefaultMeasure forMetric(Metric metric) { Preconditions.checkState(this.metric == null, "Metric already defined"); - Preconditions.checkNotNull(metric, "metric should be non null"); + requireNonNull(metric, "metric should be non null"); this.metric = metric; return this; } @@ -65,7 +67,7 @@ public class DefaultMeasure extends DefaultStorable impl @Override public DefaultMeasure withValue(G value) { Preconditions.checkState(this.value == null, "Measure value already defined"); - Preconditions.checkNotNull(value, "Measure value can't be null"); + requireNonNull(value, "Measure value can't be null"); this.value = value; return this; } @@ -87,8 +89,8 @@ public class DefaultMeasure extends DefaultStorable impl @Override public void doSave() { - Preconditions.checkNotNull(this.value, "Measure value can't be null"); - Preconditions.checkNotNull(this.metric, "Measure metric can't be null"); + requireNonNull(this.value, "Measure value can't be null"); + requireNonNull(this.metric, "Measure metric can't be null"); Preconditions.checkState(this.metric.valueType().equals(this.value.getClass()), "Measure value should be of type %s", this.metric.valueType()); storage.store(this); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/internal/DefaultSymbolTable.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/internal/DefaultSymbolTable.java index 9045923c7b3..8a355709dc7 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/internal/DefaultSymbolTable.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/symbol/internal/DefaultSymbolTable.java @@ -33,6 +33,8 @@ import org.sonar.api.batch.sensor.internal.SensorStorage; import org.sonar.api.batch.sensor.symbol.NewSymbol; import org.sonar.api.batch.sensor.symbol.NewSymbolTable; +import static java.util.Objects.requireNonNull; + public class DefaultSymbolTable extends DefaultStorable implements NewSymbolTable { private final Map> referencesBySymbol; @@ -49,7 +51,7 @@ public class DefaultSymbolTable extends DefaultStorable implements NewSymbolTabl @Override public DefaultSymbolTable onFile(InputFile inputFile) { - Preconditions.checkNotNull(inputFile, "file can't be null"); + requireNonNull(inputFile, "file can't be null"); this.inputFile = (DefaultInputFile) inputFile; return this; } @@ -126,7 +128,7 @@ public class DefaultSymbolTable extends DefaultStorable implements NewSymbolTabl @Override public NewSymbol newReference(TextRange range) { - Preconditions.checkNotNull(range, "Provided range is null"); + requireNonNull(range, "Provided range is null"); Preconditions.checkArgument(!declaration.overlap(range), "Overlapping symbol declaration and reference for symbol at %s", declaration); references.add(range); return this; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/test/TestIssue.java b/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/test/TestIssue.java index e81dee6efa0..e25a964cc81 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/test/TestIssue.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/test/TestIssue.java @@ -29,7 +29,7 @@ import org.sonar.api.rules.RuleType; import org.sonar.api.utils.Duration; import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.Objects.requireNonNull; @Immutable public class TestIssue implements Issue { @@ -163,12 +163,12 @@ public class TestIssue implements Issue { } private static String validateKey(String key) { - checkNotNull(key, "key cannot be null"); + requireNonNull(key, "key cannot be null"); return key; } private static RuleKey validateRuleKey(RuleKey ruleKey) { - checkNotNull(ruleKey, "ruleKey cannot be null"); + requireNonNull(ruleKey, "ruleKey cannot be null"); return ruleKey; } @@ -178,19 +178,19 @@ public class TestIssue implements Issue { } private static String validateSeverity(String severity) { - checkNotNull(severity, "severity cannot be null"); + requireNonNull(severity, "severity cannot be null"); checkArgument(Severity.ALL.contains(severity), String.format("severity '%s' is invalid", severity)); return severity; } private static String validateStatus(String status) { - checkNotNull(status, "status cannot be null"); + requireNonNull(status, "status cannot be null"); checkArgument(org.sonar.api.issue.Issue.STATUSES.contains(status), String.format("status '%s' is invalid", status)); return status; } private static RuleType validateType(RuleType type) { - checkNotNull(type, "type cannot be null"); + requireNonNull(type, "type cannot be null"); return type; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/test/TestMeasureComputerDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/test/TestMeasureComputerDefinition.java index 0b6d54e93b7..f1b5c41435f 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/test/TestMeasureComputerDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/test/TestMeasureComputerDefinition.java @@ -19,7 +19,7 @@ */ package org.sonar.api.ce.measure.test; -import com.google.common.collect.ImmutableSet; +import java.util.HashSet; import java.util.List; import java.util.Set; import org.sonar.api.ce.measure.MeasureComputer; @@ -28,6 +28,7 @@ import org.sonar.api.measures.Metric; import static com.google.common.base.Preconditions.checkArgument; import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableSet; import static java.util.Objects.requireNonNull; public class TestMeasureComputerDefinition implements MeasureComputer.MeasureComputerDefinition { @@ -36,8 +37,8 @@ public class TestMeasureComputerDefinition implements MeasureComputer.MeasureCom private final Set outputMetrics; private TestMeasureComputerDefinition(MeasureComputerDefinitionBuilderImpl builder) { - this.inputMetricKeys = ImmutableSet.copyOf(builder.inputMetricKeys); - this.outputMetrics = ImmutableSet.copyOf(builder.outputMetrics); + this.inputMetricKeys = unmodifiableSet(new HashSet<>(asList(builder.inputMetricKeys))); + this.outputMetrics = unmodifiableSet(new HashSet<>(asList(builder.outputMetrics))); } @Override diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/EmailSettings.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/EmailSettings.java index 043809b7335..dc449884522 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/EmailSettings.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/EmailSettings.java @@ -19,14 +19,13 @@ */ package org.sonar.api.config; -import com.google.common.base.MoreObjects; -import com.google.common.collect.ImmutableList; import java.util.List; import org.sonar.api.PropertyType; import org.sonar.api.batch.ScannerSide; import org.sonar.api.ce.ComputeEngineSide; import org.sonar.api.server.ServerSide; +import static java.util.Arrays.asList; import static org.sonar.api.CoreProperties.CATEGORY_GENERAL; import static org.sonar.api.CoreProperties.SERVER_BASE_URL; import static org.sonar.api.CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE; @@ -97,14 +96,15 @@ public class EmailSettings { } private String get(String key, String defaultValue) { - return MoreObjects.firstNonNull(settings.getString(key), defaultValue); + String value = settings.getString(key); + return value != null ? value : defaultValue; } /** * @since 6.1 */ public static List definitions() { - return ImmutableList.of( + return asList( PropertyDefinition.builder(SMTP_HOST) .name("SMTP host") .description("For example \"smtp.gmail.com\". Leave blank to disable email sending.") diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/Encryption.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/Encryption.java index 837a098f292..2ae93590224 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/Encryption.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/Encryption.java @@ -19,14 +19,12 @@ */ package org.sonar.api.config; -import com.google.common.collect.ImmutableMap; - -import javax.annotation.Nullable; - +import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.annotation.Nullable; /** * @since 3.0 @@ -43,9 +41,9 @@ public final class Encryption { public Encryption(@Nullable String pathToSecretKey) { aesCipher = new AesCipher(pathToSecretKey); - ciphers = ImmutableMap.of( - BASE64_ALGORITHM, new Base64Cipher(), - AES_ALGORITHM, aesCipher); + ciphers = new HashMap<>(); + ciphers.put(BASE64_ALGORITHM, new Base64Cipher()); + ciphers.put(AES_ALGORITHM, aesCipher); } public void setPathToSecretKey(@Nullable String pathToSecretKey) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/License.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/License.java index a55afbed25a..6b3facf42bd 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/License.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/License.java @@ -20,14 +20,6 @@ package org.sonar.api.config; import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Maps; -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.utils.DateUtils; - -import javax.annotation.Nullable; - import java.io.IOException; import java.io.StringReader; import java.nio.charset.StandardCharsets; @@ -36,6 +28,11 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.annotation.Nullable; +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; +import org.sonar.api.utils.DateUtils; /** * SonarSource license. This class aims to extract metadata but not to validate or - of course - @@ -130,10 +127,9 @@ public final class License { @VisibleForTesting static License readPlainText(String data) { - Map props = Maps.newHashMap(); - StringReader reader = new StringReader(data); + Map props = new HashMap<>(); try { - List lines = IOUtils.readLines(reader); + List lines = IOUtils.readLines(new StringReader(data)); for (String line : lines) { if (StringUtils.isNotBlank(line) && line.indexOf(':') > 0) { String key = StringUtils.substringBefore(line, ":"); @@ -144,9 +140,6 @@ public final class License { } catch (IOException e) { // silently ignore - - } finally { - IOUtils.closeQuietly(reader); } return new License(props); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/MapSettings.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/MapSettings.java index 346f00568fb..5a73567a808 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/MapSettings.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/MapSettings.java @@ -19,11 +19,12 @@ */ package org.sonar.api.config; -import com.google.common.collect.ImmutableMap; import java.util.HashMap; import java.util.Map; import java.util.Optional; +import static java.util.Collections.unmodifiableMap; + /** * In-memory map-based implementation of {@link Settings}. It must be used * only for unit tests. This is not the implementation @@ -61,7 +62,7 @@ public class MapSettings extends Settings { @Override public Map getProperties() { - return ImmutableMap.copyOf(props); + return unmodifiableMap(props); } /** diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java index 305fb5492c2..02d64853e8e 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java @@ -19,14 +19,10 @@ */ package org.sonar.api.config; -import com.google.common.base.Strings; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; import java.util.ArrayList; -import java.util.Arrays; import java.util.EnumMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import java.util.function.Function; @@ -46,8 +42,12 @@ import org.sonar.api.server.ServerSide; import org.sonarsource.api.sonarlint.SonarLintSide; import static com.google.common.base.Preconditions.checkArgument; +import static java.util.Arrays.asList; +import static java.util.Arrays.stream; +import static java.util.Collections.unmodifiableSet; import static java.util.Objects.requireNonNull; import static org.apache.commons.lang.StringUtils.isBlank; +import static org.apache.commons.lang.StringUtils.isEmpty; import static org.sonar.api.PropertyType.BOOLEAN; import static org.sonar.api.PropertyType.FLOAT; import static org.sonar.api.PropertyType.INTEGER; @@ -93,7 +93,7 @@ import static org.sonar.api.PropertyType.SINGLE_SELECT_LIST; @ExtensionPoint public final class PropertyDefinition { - private static final Set SUPPORTED_QUALIFIERS = ImmutableSet.of(Qualifiers.PROJECT, Qualifiers.VIEW, Qualifiers.MODULE, Qualifiers.SUBVIEW); + private static final Set SUPPORTED_QUALIFIERS = unmodifiableSet(new LinkedHashSet<>(asList(Qualifiers.PROJECT, Qualifiers.VIEW, Qualifiers.MODULE, Qualifiers.SUBVIEW))); private String key; private String defaultValue; @@ -147,7 +147,7 @@ public final class PropertyDefinition { .description(annotation.description()) .category(annotation.category()) .type(annotation.type()) - .options(Arrays.asList(annotation.options())) + .options(asList(annotation.options())) .multiValues(annotation.multiValues()) .propertySetKey(annotation.propertySetKey()) .fields(PropertyFieldDefinition.create(annotation.fields())) @@ -332,7 +332,7 @@ public final class PropertyDefinition { @Override public String toString() { - if (StringUtils.isEmpty(propertySetKey)) { + if (isEmpty(propertySetKey)) { return key; } return new StringBuilder().append(propertySetKey).append('|').append(key).toString(); @@ -504,7 +504,7 @@ public final class PropertyDefinition { } private static void addQualifiers(List target, String first, String... rest) { - Stream.concat(Stream.of(first), Arrays.stream(rest)).peek(PropertyDefinition.Builder::validateQualifier).forEach(target::add); + Stream.concat(Stream.of(first), stream(rest)).peek(PropertyDefinition.Builder::validateQualifier).forEach(target::add); } private static void addQualifiers(List target, List qualifiers) { @@ -525,12 +525,13 @@ public final class PropertyDefinition { } public Builder options(String first, String... rest) { - this.options.addAll(Lists.asList(first, rest)); + this.options.add(first); + stream(rest).forEach(o -> options.add(o)); return this; } public Builder options(List options) { - this.options.addAll(ImmutableList.copyOf(options)); + this.options.addAll(options); return this; } @@ -549,12 +550,13 @@ public final class PropertyDefinition { } public Builder fields(PropertyFieldDefinition first, PropertyFieldDefinition... rest) { - this.fields.addAll(Lists.asList(first, rest)); + this.fields.add(first); + this.fields.addAll(asList(rest)); return this; } public Builder fields(List fields) { - this.fields.addAll(ImmutableList.copyOf(fields)); + this.fields.addAll(fields); return this; } @@ -582,7 +584,7 @@ public final class PropertyDefinition { } public PropertyDefinition build() { - checkArgument(!Strings.isNullOrEmpty(key), "Key must be set"); + checkArgument(!isEmpty(key), "Key must be set"); fixType(key, type); checkArgument(onQualifiers.isEmpty() || onlyOnQualifiers.isEmpty(), "Cannot define both onQualifiers and onlyOnQualifiers"); checkArgument(!hidden || (onQualifiers.isEmpty() && onlyOnQualifiers.isEmpty()), "Cannot be hidden and defining qualifiers on which to display"); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java index 195a9a34977..9a0834b62be 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java @@ -19,7 +19,6 @@ */ package org.sonar.api.config; -import com.google.common.base.Strings; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -111,7 +110,7 @@ public final class PropertyDefinitions { categories.put(definition.key(), new Category(category)); String subcategory = StringUtils.defaultIfBlank(definition.subCategory(), category); subcategories.put(definition.key(), new SubCategory(subcategory)); - if (!Strings.isNullOrEmpty(definition.deprecatedKey()) && !definition.deprecatedKey().equals(definition.key())) { + if (!StringUtils.isEmpty(definition.deprecatedKey()) && !definition.deprecatedKey().equals(definition.key())) { deprecatedKeys.put(definition.deprecatedKey(), definition.key()); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyFieldDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyFieldDefinition.java index 4886c474bc0..cc82c60087f 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyFieldDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyFieldDefinition.java @@ -20,14 +20,15 @@ package org.sonar.api.config; import com.google.common.base.Preconditions; -import com.google.common.base.Strings; -import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.List; import javax.annotation.Nullable; +import org.apache.commons.lang.StringUtils; import org.sonar.api.PropertyField; import org.sonar.api.PropertyType; +import static java.util.Arrays.asList; + /** * @since 3.3 */ @@ -57,8 +58,7 @@ public final class PropertyFieldDefinition { .indicativeSize(field.indicativeSize()) .type(field.type()) .options(field.options()) - .build() - ); + .build()); } return definitions; } @@ -141,18 +141,18 @@ public final class PropertyFieldDefinition { } public Builder options(String... options) { - this.options.addAll(ImmutableList.copyOf(options)); + this.options.addAll(asList(options)); return this; } public Builder options(List options) { - this.options.addAll(ImmutableList.copyOf(options)); + this.options.addAll(options); return this; } public PropertyFieldDefinition build() { - Preconditions.checkArgument(!Strings.isNullOrEmpty(key), "Key must be set"); - Preconditions.checkArgument(!Strings.isNullOrEmpty(name), "Name must be set"); + Preconditions.checkArgument(!StringUtils.isEmpty(key), "Key must be set"); + Preconditions.checkArgument(!StringUtils.isEmpty(name), "Name must be set"); return new PropertyFieldDefinition(this); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/Settings.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/Settings.java index 1cf9f489f1d..7e182dcd555 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/Settings.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/Settings.java @@ -19,9 +19,7 @@ */ package org.sonar.api.config; -import com.google.common.base.Joiner; import com.google.common.base.Splitter; -import com.google.common.base.Strings; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -342,8 +340,8 @@ public abstract class Settings { */ public String[] getStringLines(String key) { String value = getString(key); - if (Strings.isNullOrEmpty(value)) { - return ArrayUtils.EMPTY_STRING_ARRAY; + if (StringUtils.isEmpty(value)) { + return new String[0]; } return value.split("\r?\n|\r", -1); } @@ -392,7 +390,7 @@ public abstract class Settings { } } - String escapedValue = Joiner.on(',').join(escaped); + String escapedValue = escaped.stream().collect(Collectors.joining(",")); text = trim(escapedValue); } return setProperty(key, text); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/User.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/User.java index 7a14f1fcb58..63cd167693b 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/User.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/User.java @@ -19,8 +19,6 @@ */ package org.sonar.api.database.model; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; import org.sonar.api.database.BaseIdentifiable; /** @@ -78,6 +76,11 @@ public class User extends BaseIdentifiable { @Override public String toString() { - return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); + StringBuilder sb = new StringBuilder("User{"); + sb.append("login='").append(login).append('\''); + sb.append(", name='").append(name).append('\''); + sb.append(", email='").append(email).append('\''); + sb.append('}'); + return sb.toString(); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/design/Dependency.java b/sonar-plugin-api/src/main/java/org/sonar/api/design/Dependency.java index 0d95b7427d0..ab1a0314381 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/design/Dependency.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/design/Dependency.java @@ -19,9 +19,6 @@ */ package org.sonar.api.design; -import org.apache.commons.lang.builder.EqualsBuilder; -import org.apache.commons.lang.builder.HashCodeBuilder; -import org.apache.commons.lang.builder.ToStringBuilder; import org.sonar.api.resources.Resource; import org.sonar.graph.Edge; @@ -114,35 +111,37 @@ public class Dependency implements Edge { } @Override - public boolean equals(Object obj) { - if (!(obj instanceof Dependency)) { + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { return false; } - if (this == obj) { - return true; + Dependency that = (Dependency) o; + if (!from.equals(that.from)) { + return false; } - Dependency other = (Dependency) obj; - return new EqualsBuilder() - .append(from, other.from) - .append(to, other.to) - .isEquals(); + return to.equals(that.to); } @Override public int hashCode() { - return new HashCodeBuilder(17, 37) - .append(from) - .append(to) - .toHashCode(); + int result = from.hashCode(); + result = 31 * result + to.hashCode(); + return result; } @Override public String toString() { - return new ToStringBuilder(this) - .append("from", from) - .append("to", to) - .append("weight", weight) - .append("usage", usage) - .toString(); + StringBuilder sb = new StringBuilder("Dependency{"); + sb.append("from=").append(from); + sb.append(", to=").append(to); + sb.append(", usage='").append(usage).append('\''); + sb.append(", weight=").append(weight); + sb.append(", parent=").append(parent); + sb.append(", id=").append(id); + sb.append('}'); + return sb.toString(); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/DefaultTransitions.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/DefaultTransitions.java index 726f72dadd3..47aebc9e8b0 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/DefaultTransitions.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/DefaultTransitions.java @@ -19,10 +19,10 @@ */ package org.sonar.api.issue; -import com.google.common.collect.ImmutableList; - import java.util.List; +import static java.util.Arrays.asList; + /** * @since 3.6 */ @@ -43,5 +43,5 @@ public interface DefaultTransitions { /** * @since 4.4 */ - List ALL = ImmutableList.of(CONFIRM, UNCONFIRM, REOPEN, RESOLVE, FALSE_POSITIVE, WONT_FIX, CLOSE); + List ALL = asList(CONFIRM, UNCONFIRM, REOPEN, RESOLVE, FALSE_POSITIVE, WONT_FIX, CLOSE); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java index 001a08dd7f9..314d704cba2 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java @@ -19,7 +19,6 @@ */ package org.sonar.api.issue; -import com.google.common.collect.ImmutableList; import java.io.Serializable; import java.util.Collection; import java.util.Date; @@ -30,6 +29,8 @@ import org.sonar.api.batch.ScannerSide; import org.sonar.api.rule.RuleKey; import org.sonar.api.utils.Duration; +import static java.util.Arrays.asList; + /** * @since 3.6 */ @@ -67,14 +68,14 @@ public interface Issue extends Serializable { */ String RESOLUTION_WONT_FIX = "WONTFIX"; - List RESOLUTIONS = ImmutableList.of(RESOLUTION_FALSE_POSITIVE, RESOLUTION_WONT_FIX, RESOLUTION_FIXED, RESOLUTION_REMOVED); + List RESOLUTIONS = asList(RESOLUTION_FALSE_POSITIVE, RESOLUTION_WONT_FIX, RESOLUTION_FIXED, RESOLUTION_REMOVED); /** * Return all available statuses * * @since 4.4 */ - List STATUSES = ImmutableList.of(STATUS_OPEN, STATUS_CONFIRMED, STATUS_REOPENED, STATUS_RESOLVED, STATUS_CLOSED); + List STATUSES = asList(STATUS_OPEN, STATUS_CONFIRMED, STATUS_REOPENED, STATUS_RESOLVED, STATUS_CLOSED); /** * Unique generated key. It looks like "d2de809c-1512-4ae2-9f34-f5345c9f1a13". diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/NoSonarFilter.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/NoSonarFilter.java index 02020400c94..d5b3a59a33a 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/NoSonarFilter.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/NoSonarFilter.java @@ -19,19 +19,17 @@ */ package org.sonar.api.issue; -import org.sonar.api.scan.issue.filter.FilterableIssue; - -import org.sonar.api.scan.issue.filter.IssueFilter; -import com.google.common.collect.Maps; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; import org.apache.commons.lang.StringUtils; import org.sonar.api.batch.ScannerSide; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultInputFile; +import org.sonar.api.scan.issue.filter.FilterableIssue; +import org.sonar.api.scan.issue.filter.IssueFilter; import org.sonar.api.scan.issue.filter.IssueFilterChain; -import java.util.Map; -import java.util.Set; - /** * Issue filter used to ignore issues created on lines commented with the tag "NOSONAR". *
@@ -43,7 +41,7 @@ import java.util.Set; */ public class NoSonarFilter implements IssueFilter { - private final Map> noSonarLinesByResource = Maps.newHashMap(); + private final Map> noSonarLinesByResource = new HashMap<>(); /** * @deprecated since 5.0 use {@link #noSonarInFile(InputFile, Set)} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/Condition.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/Condition.java index 41c865c11a8..6de331f3026 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/Condition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/Condition.java @@ -19,13 +19,11 @@ */ package org.sonar.api.issue.condition; -import com.google.common.annotations.Beta; import org.sonar.api.issue.Issue; /** * @since 3.6 */ -@Beta public interface Condition { boolean matches(Issue issue); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/HasIssuePropertyCondition.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/HasIssuePropertyCondition.java index 34512521417..e84980371e0 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/HasIssuePropertyCondition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/HasIssuePropertyCondition.java @@ -19,21 +19,21 @@ */ package org.sonar.api.issue.condition; -import com.google.common.annotations.Beta; import com.google.common.base.Preconditions; -import com.google.common.base.Strings; +import org.apache.commons.lang.StringUtils; import org.sonar.api.issue.Issue; +import static org.apache.commons.lang.StringUtils.isEmpty; + /** * @since 3.6 */ -@Beta public final class HasIssuePropertyCondition implements Condition { private final String propertyKey; public HasIssuePropertyCondition(String propertyKey) { - Preconditions.checkArgument(!Strings.isNullOrEmpty(propertyKey)); + Preconditions.checkArgument(!isEmpty(propertyKey)); this.propertyKey = propertyKey; } @@ -43,6 +43,6 @@ public final class HasIssuePropertyCondition implements Condition { @Override public boolean matches(Issue issue) { - return !Strings.isNullOrEmpty(issue.attribute(propertyKey)); + return !StringUtils.isEmpty(issue.attribute(propertyKey)); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/HasResolution.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/HasResolution.java index faf9461b7c9..8ccd0ff91b3 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/HasResolution.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/HasResolution.java @@ -19,22 +19,23 @@ */ package org.sonar.api.issue.condition; -import com.google.common.annotations.Beta; -import com.google.common.collect.ImmutableSet; +import java.util.HashSet; +import java.util.Set; import org.sonar.api.issue.Issue; -import java.util.Set; +import static java.util.Arrays.asList; /** * @since 3.6 */ -@Beta public class HasResolution implements Condition { private final Set resolutions; public HasResolution(String first, String... others) { - this.resolutions = ImmutableSet.builder().add(first).add(others).build(); + this.resolutions = new HashSet<>(); + this.resolutions.add(first); + this.resolutions.addAll(asList(others)); } @Override diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/HasStatus.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/HasStatus.java index 7ac7436d66e..bf24ff96782 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/HasStatus.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/HasStatus.java @@ -19,26 +19,27 @@ */ package org.sonar.api.issue.condition; -import com.google.common.annotations.Beta; -import com.google.common.collect.ImmutableSet; +import java.util.HashSet; +import java.util.Set; import org.sonar.api.issue.Issue; -import java.util.Set; +import static java.util.Arrays.asList; /** * @since 3.6 */ -@Beta public class HasStatus implements Condition { - private final Set status; + private final Set statuses; public HasStatus(String first, String... others) { - this.status = ImmutableSet.builder().add(first).add(others).build(); + this.statuses = new HashSet<>(); + this.statuses.add(first); + this.statuses.addAll(asList(others)); } @Override public boolean matches(Issue issue) { - return issue.status() != null && status.contains(issue.status()); + return issue.status() != null && statuses.contains(issue.status()); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/IsUnResolved.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/IsUnResolved.java index 4ff29ac17dc..063a32e8476 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/IsUnResolved.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/IsUnResolved.java @@ -19,13 +19,11 @@ */ package org.sonar.api.issue.condition; -import com.google.common.annotations.Beta; import org.sonar.api.issue.Issue; /** * @since 3.6 */ -@Beta public class IsUnResolved implements Condition { @Override diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/NotCondition.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/NotCondition.java index 65bee54da3f..15cc2b6aa35 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/NotCondition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/NotCondition.java @@ -19,13 +19,11 @@ */ package org.sonar.api.issue.condition; -import com.google.common.annotations.Beta; import org.sonar.api.issue.Issue; /** * @since 3.6 */ -@Beta public class NotCondition implements Condition { private final Condition condition; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoverageMeasuresBuilder.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoverageMeasuresBuilder.java index 4a94a89890c..484055b570b 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoverageMeasuresBuilder.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoverageMeasuresBuilder.java @@ -19,13 +19,13 @@ */ package org.sonar.api.measures; -import com.google.common.collect.Maps; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.SortedMap; +import java.util.TreeMap; import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.utils.KeyValueFormat; @@ -47,9 +47,9 @@ public final class CoverageMeasuresBuilder { private int totalCoveredLines = 0; private int totalConditions = 0; private int totalCoveredConditions = 0; - private SortedMap hitsByLine = Maps.newTreeMap(); - private SortedMap conditionsByLine = Maps.newTreeMap(); - private SortedMap coveredConditionsByLine = Maps.newTreeMap(); + private SortedMap hitsByLine = new TreeMap<>(); + private SortedMap conditionsByLine = new TreeMap<>(); + private SortedMap coveredConditionsByLine = new TreeMap<>(); private CoverageMeasuresBuilder() { // use the factory diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java index cb33540a68f..58dec513e16 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java @@ -19,7 +19,6 @@ */ package org.sonar.api.measures; -import com.google.common.annotations.Beta; import java.io.Serializable; import java.util.Date; import javax.annotation.CheckForNull; @@ -612,7 +611,6 @@ public class Measure implements Serializable { * @since 2.14 */ @CheckForNull - @Beta public Integer getPersonId() { return personId; } @@ -620,7 +618,6 @@ public class Measure implements Serializable { /** * @since 2.14 */ - @Beta public Measure setPersonId(@Nullable Integer i) { this.personId = i; return this; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/RangeDistributionBuilder.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/RangeDistributionBuilder.java index 44f44912bd1..eb15f033dd6 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/RangeDistributionBuilder.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/RangeDistributionBuilder.java @@ -19,13 +19,13 @@ */ package org.sonar.api.measures; -import com.google.common.base.Function; import com.google.common.collect.SortedMultiset; import com.google.common.collect.TreeMultiset; import java.util.Arrays; import java.util.Collections; import java.util.Map; import java.util.Set; +import java.util.function.Function; import javax.annotation.Nullable; import org.apache.commons.lang.NumberUtils; import org.sonar.api.utils.KeyValueFormat; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/notifications/Notification.java b/sonar-plugin-api/src/main/java/org/sonar/api/notifications/Notification.java index 91f48b5a936..a68a307b002 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/notifications/Notification.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/notifications/Notification.java @@ -19,13 +19,11 @@ */ package org.sonar.api.notifications; -import com.google.common.collect.Maps; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - import java.io.Serializable; +import java.util.HashMap; import java.util.Map; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; /** * This class represents a notification that will be delivered to users. This is a general concept and it has no @@ -43,7 +41,7 @@ public class Notification implements Serializable { private static final String DEFAULT_MESSAGE_KEY = "default_message"; private final String type; - private final Map fields = Maps.newHashMap(); + private final Map fields = new HashMap<>(); /** *

diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/platform/NewUserHandler.java b/sonar-plugin-api/src/main/java/org/sonar/api/platform/NewUserHandler.java index aa39e70881f..3bbea912c46 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/platform/NewUserHandler.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/platform/NewUserHandler.java @@ -19,11 +19,11 @@ */ package org.sonar.api.platform; -import com.google.common.base.Preconditions; +import javax.annotation.Nullable; import org.sonar.api.ExtensionPoint; import org.sonar.api.server.ServerSide; -import javax.annotation.Nullable; +import static java.util.Objects.requireNonNull; /** * @since 3.2 @@ -38,8 +38,8 @@ public interface NewUserHandler { private String email; private Context(String login, String name, @Nullable String email) { - Preconditions.checkNotNull(login); - Preconditions.checkNotNull(name); + requireNonNull(login); + requireNonNull(name); this.login = login; this.name = name; this.email = email; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java index 36e058071dd..fa85ab21af4 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java @@ -19,12 +19,10 @@ */ package org.sonar.api.profiles; -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; import java.util.ArrayList; import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Collectors; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; @@ -306,7 +304,7 @@ public class RulesProfile implements Cloneable { * @param optionalSeverity if null, then the default rule severity is used */ public ActiveRule activateRule(final Rule rule, @Nullable RulePriority optionalSeverity) { - if (Iterables.any(activeRules, new MatchRule(rule))) { + if (activeRules.stream().anyMatch(ar -> ar.getRule().equals(rule))) { throw MessageException.of(String.format( "The definition of the profile '%s' (language '%s') contains multiple occurrences of the '%s:%s' rule. The plugin which declares this profile should fix this.", getName(), getLanguage(), rule.getRepositoryKey(), rule.getKey())); @@ -341,7 +339,9 @@ public class RulesProfile implements Cloneable { RulesProfile clone = RulesProfile.create(getName(), getLanguage()); clone.setDefaultProfile(getDefaultProfile()); if (activeRules != null && !activeRules.isEmpty()) { - clone.setActiveRules(Lists.transform(activeRules, CloneFunction.INSTANCE)); + clone.setActiveRules(activeRules.stream() + .map(ar -> (ActiveRule) ar.clone()) + .collect(Collectors.toList())); } return clone; } @@ -367,16 +367,8 @@ public class RulesProfile implements Cloneable { } @Override - public boolean apply(ActiveRule input) { + public boolean test(ActiveRule input) { return input.getRule().equals(rule); } } - - private enum CloneFunction implements Function { - INSTANCE; - @Override - public ActiveRule apply(ActiveRule input) { - return (ActiveRule) input.clone(); - } - } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Languages.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Languages.java index 0cfc1d8d9b8..19d90b8ddef 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Languages.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Languages.java @@ -19,10 +19,10 @@ */ package org.sonar.api.resources; -import com.google.common.collect.Maps; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import org.apache.commons.lang.ArrayUtils; @@ -44,7 +44,7 @@ public class Languages { private static final Logger LOG = Loggers.get(Languages.class); - private final Map map = Maps.newLinkedHashMap(); + private final Map map = new LinkedHashMap<>(); /** * Creates a list of languages diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceType.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceType.java index 14c8cf10820..53c8bd40903 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceType.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceType.java @@ -20,12 +20,14 @@ package org.sonar.api.resources; import com.google.common.base.Preconditions; -import com.google.common.base.Strings; -import com.google.common.collect.Maps; +import java.util.HashMap; import java.util.Map; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import static java.util.Objects.requireNonNull; +import static org.apache.commons.lang.StringUtils.isEmpty; + /** *

Experimental extension to declare types of resources. *

@@ -60,7 +62,7 @@ public class ResourceType { this.qualifier = builder.qualifier; this.iconPath = builder.iconPath; this.hasSourceCode = builder.hasSourceCode; - this.properties = Maps.newHashMap(builder.properties); + this.properties = new HashMap<>(builder.properties); } /** @@ -91,7 +93,7 @@ public class ResourceType { } public boolean hasProperty(String key) { - Preconditions.checkNotNull(key); + requireNonNull(key); return properties.containsKey(key); } @@ -102,7 +104,7 @@ public class ResourceType { * @since 3.0 */ public String getStringProperty(String key) { - Preconditions.checkNotNull(key); + requireNonNull(key); return properties.get(key); } @@ -113,7 +115,7 @@ public class ResourceType { * @since 3.0 */ public boolean getBooleanProperty(String key) { - Preconditions.checkNotNull(key); + requireNonNull(key); String value = properties.get(key); return value != null && Boolean.parseBoolean(value); } @@ -145,7 +147,7 @@ public class ResourceType { * Creates a new {@link Builder} */ public static Builder builder(String qualifier) { - Preconditions.checkNotNull(qualifier); + requireNonNull(qualifier); Preconditions.checkArgument(qualifier.length() <= 10, "Qualifier is limited to 10 characters"); return new Builder(qualifier); } @@ -157,7 +159,7 @@ public class ResourceType { private String qualifier; private String iconPath; private boolean hasSourceCode = false; - private final Map properties = Maps.newHashMap(); + private final Map properties = new HashMap<>(); /** * Creates a new {@link Builder} @@ -198,8 +200,8 @@ public class ResourceType { * @since 3.0 */ public Builder setProperty(String key, String value) { - Preconditions.checkNotNull(key); - Preconditions.checkNotNull(value); + requireNonNull(key); + requireNonNull(value); properties.put(key, value); return this; } @@ -215,7 +217,7 @@ public class ResourceType { * Creates an instance of {@link ResourceType} based on all information given to the builder. */ public ResourceType build() { - if (Strings.isNullOrEmpty(iconPath)) { + if (isEmpty(iconPath)) { iconPath = "/images/q/" + qualifier + ".png"; } return new ResourceType(this); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceTypeTree.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceTypeTree.java index 2fbaf86d22f..11c689ea8d4 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceTypeTree.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceTypeTree.java @@ -19,21 +19,22 @@ */ package org.sonar.api.resources; -import com.google.common.base.Preconditions; -import com.google.common.base.Predicate; import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Collections2; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ListMultimap; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.stream.Collectors; import org.sonar.api.batch.ScannerSide; import org.sonar.api.ce.ComputeEngineSide; import org.sonar.api.server.ServerSide; +import static com.google.common.base.Preconditions.checkArgument; +import static java.util.Collections.unmodifiableList; +import static java.util.Objects.requireNonNull; + /** * @since 2.14 */ @@ -47,7 +48,7 @@ public class ResourceTypeTree { private final ResourceType root; private ResourceTypeTree(Builder builder) { - this.types = ImmutableList.copyOf(builder.types); + this.types = unmodifiableList(new ArrayList<>(builder.types)); this.relations = ImmutableListMultimap.copyOf(builder.relations); this.root = builder.root; } @@ -65,12 +66,10 @@ public class ResourceTypeTree { } public List getLeaves() { - return ImmutableList.copyOf(Collections2.filter(relations.values(), new Predicate() { - @Override - public boolean apply(String qualifier) { - return relations.get(qualifier).isEmpty(); - } - })); + return unmodifiableList(relations.values() + .stream() + .filter(qualifier -> relations.get(qualifier).isEmpty()) + .collect(Collectors.toList())); } @Override @@ -91,16 +90,16 @@ public class ResourceTypeTree { } public Builder addType(ResourceType type) { - Preconditions.checkNotNull(type); - Preconditions.checkArgument(!types.contains(type), String.format("%s is already registered", type.getQualifier())); + requireNonNull(type); + checkArgument(!types.contains(type), String.format("%s is already registered", type.getQualifier())); types.add(type); return this; } public Builder addRelations(String parentQualifier, String... childrenQualifiers) { - Preconditions.checkNotNull(parentQualifier); - Preconditions.checkNotNull(childrenQualifiers); - Preconditions.checkArgument(childrenQualifiers.length > 0, "childrenQualifiers can't be empty"); + requireNonNull(parentQualifier); + requireNonNull(childrenQualifiers); + checkArgument(childrenQualifiers.length > 0, "childrenQualifiers can't be empty"); relations.putAll(parentQualifier, Arrays.asList(childrenQualifiers)); return this; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceTypes.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceTypes.java index 10c15a14346..dcbfe98c801 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceTypes.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceTypes.java @@ -20,25 +20,24 @@ package org.sonar.api.resources; import com.google.common.annotations.Beta; -import com.google.common.base.Preconditions; -import com.google.common.base.Predicate; -import com.google.common.collect.Collections2; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Objects; -import javax.annotation.Nullable; +import java.util.function.Predicate; +import java.util.stream.Collectors; import org.sonar.api.ce.ComputeEngineSide; import org.sonar.api.server.ServerSide; +import static java.util.Collections.unmodifiableList; +import static java.util.Collections.unmodifiableMap; +import static java.util.Collections.unmodifiableSet; +import static java.util.Objects.requireNonNull; + /** * @since 2.14 */ @@ -59,11 +58,11 @@ public class ResourceTypes { } public ResourceTypes(ResourceTypeTree[] trees) { - Preconditions.checkNotNull(trees); + requireNonNull(trees); - Map treeMap = Maps.newHashMap(); - Map typeMap = Maps.newLinkedHashMap(); - Collection rootsSet = Sets.newHashSet(); + Map treeMap = new LinkedHashMap<>(); + Map typeMap = new LinkedHashMap<>(); + Collection rootsSet = new LinkedHashSet<>(); for (ResourceTypeTree tree : trees) { rootsSet.add(tree.getRootType()); @@ -75,9 +74,9 @@ public class ResourceTypes { typeMap.put(type.getQualifier(), type); } } - treeByQualifier = ImmutableMap.copyOf(treeMap); - typeByQualifier = ImmutableMap.copyOf(typeMap); - rootTypes = ImmutableList.copyOf(rootsSet); + treeByQualifier = unmodifiableMap(new LinkedHashMap<>(treeMap)); + typeByQualifier = unmodifiableMap(new LinkedHashMap<>(typeMap)); + rootTypes = unmodifiableList(new ArrayList<>(rootsSet)); List mutableOrderedTypes = new ArrayList<>(); ResourceType view = null; @@ -98,7 +97,7 @@ public class ResourceTypes { mutableOrderedTypes.add(0, view); } - orderedTypes = ImmutableSet.copyOf(mutableOrderedTypes); + orderedTypes = unmodifiableSet(new LinkedHashSet<>(mutableOrderedTypes)); } public ResourceType get(String qualifier) { @@ -119,62 +118,33 @@ public class ResourceTypes { } public Collection getAll(Predicate predicate) { - return Collections2.filter(typeByQualifier.values(), predicate); - } - - private static class PropertyKeyPredicate implements Predicate { - private final String propertyKey; - - public PropertyKeyPredicate(String propertyKey) { - this.propertyKey = propertyKey; - } - - @Override - public boolean apply(@Nullable ResourceType input) { - return input != null && input.hasProperty(propertyKey); - } + return typeByQualifier.values().stream() + .filter(predicate) + .collect(Collectors.toList()); } - public Collection getAllWithPropertyKey(final String propertyKey) { - return Collections2.filter(typeByQualifier.values(), new PropertyKeyPredicate(propertyKey)); + public Collection getAllWithPropertyKey(String propertyKey) { + return typeByQualifier.values() + .stream() + .filter(Objects::nonNull) + .filter(input -> input.hasProperty(propertyKey)) + .collect(Collectors.toList()); } - private static class StringPropertyValuePredicate implements Predicate { - private final String propertyValue; - private final String propertyKey; - - public StringPropertyValuePredicate(String propertyValue, String propertyKey) { - this.propertyValue = propertyValue; - this.propertyKey = propertyKey; - } - - @Override - public boolean apply(@Nullable ResourceType input) { - return input != null && Objects.equals(propertyValue, input.getStringProperty(propertyKey)); - } - } - - public Collection getAllWithPropertyValue(final String propertyKey, final String propertyValue) { - return Collections2.filter(typeByQualifier.values(), new StringPropertyValuePredicate(propertyValue, propertyKey)); - } - - private static class BooleanPropertyValuePredicate implements Predicate { - private final String propertyKey; - private final boolean propertyValue; - - public BooleanPropertyValuePredicate(String propertyKey, boolean propertyValue) { - this.propertyKey = propertyKey; - this.propertyValue = propertyValue; - } - - @Override - public boolean apply(@Nullable ResourceType input) { - return input != null && input.getBooleanProperty(propertyKey) == propertyValue; - } + public Collection getAllWithPropertyValue(String propertyKey, String propertyValue) { + return typeByQualifier.values() + .stream() + .filter(Objects::nonNull) + .filter(input -> Objects.equals(propertyValue, input.getStringProperty(propertyKey))) + .collect(Collectors.toList()); } - public Collection getAllWithPropertyValue(final String propertyKey, final boolean propertyValue) { - return Collections2.filter(typeByQualifier.values(), new BooleanPropertyValuePredicate(propertyKey, propertyValue)); + public Collection getAllWithPropertyValue(String propertyKey, boolean propertyValue) { + return typeByQualifier.values() + .stream() + .filter(Objects::nonNull) + .filter(input -> input.getBooleanProperty(propertyKey) == propertyValue) + .collect(Collectors.toList()); } public List getChildrenQualifiers(String qualifier) { @@ -186,7 +156,10 @@ public class ResourceTypes { } public List getChildren(String qualifier) { - return Lists.transform(getChildrenQualifiers(qualifier), typeByQualifier::get); + return getChildrenQualifiers(qualifier) + .stream() + .map(typeByQualifier::get) + .collect(Collectors.toList()); } public List getLeavesQualifiers(String qualifier) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleKey.java b/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleKey.java index 69f3cce12d2..04a78395077 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleKey.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleKey.java @@ -20,11 +20,12 @@ package org.sonar.api.rule; import com.google.common.base.Preconditions; -import com.google.common.base.Strings; import java.io.Serializable; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import static org.apache.commons.lang.StringUtils.isEmpty; + /** * Key of a rule. Unique among all the rule repositories. * @@ -51,8 +52,8 @@ public class RuleKey implements Serializable, Comparable { * Create a key. Parameters are NOT null. */ public static RuleKey of(String repository, String rule) { - Preconditions.checkArgument(!Strings.isNullOrEmpty(repository), "Repository must be set"); - Preconditions.checkArgument(!Strings.isNullOrEmpty(rule), "Rule must be set"); + Preconditions.checkArgument(!isEmpty(repository), "Repository must be set"); + Preconditions.checkArgument(!isEmpty(rule), "Rule must be set"); return new RuleKey(repository, rule); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rule/Severity.java b/sonar-plugin-api/src/main/java/org/sonar/api/rule/Severity.java index 9b43fb3fea4..385b3a2b32e 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rule/Severity.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rule/Severity.java @@ -19,10 +19,10 @@ */ package org.sonar.api.rule; -import com.google.common.collect.ImmutableList; - import java.util.List; +import static java.util.Arrays.asList; + /** * @since 3.6 */ @@ -37,7 +37,7 @@ public final class Severity { /** * All the supported severity values, ordered from {@link #INFO} to {@link #BLOCKER}. */ - public static final List ALL = ImmutableList.of(INFO, MINOR, MAJOR, CRITICAL, BLOCKER); + public static final List ALL = asList(INFO, MINOR, MAJOR, CRITICAL, BLOCKER); private Severity() { // utility diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java index fd79d081ca3..d4d73b831f0 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java @@ -19,10 +19,10 @@ */ package org.sonar.api.rules; -import com.google.common.collect.Lists; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.stream.Collectors; import javax.annotation.CheckForNull; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.ToStringBuilder; @@ -287,11 +287,14 @@ public class ActiveRule implements Cloneable { final ActiveRule clone = new ActiveRule(getRulesProfile(), getRule(), getSeverity()); clone.setInheritance(getInheritance()); if (activeRuleParams != null && !activeRuleParams.isEmpty()) { - clone.setActiveRuleParams(Lists.transform(activeRuleParams, input -> { - ActiveRuleParam activeRuleParamClone = (ActiveRuleParam) input.clone(); - activeRuleParamClone.setActiveRule(clone); - return activeRuleParamClone; - })); + clone.setActiveRuleParams(activeRuleParams + .stream() + .map(input -> { + ActiveRuleParam activeRuleParamClone = (ActiveRuleParam) input.clone(); + activeRuleParamClone.setActiveRule(clone); + return activeRuleParamClone; + }) + .collect(Collectors.toList())); } return clone; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java index 073b18bc5cc..edf566ad403 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java @@ -23,8 +23,8 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.base.Functions; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; import java.lang.reflect.Field; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.apache.commons.lang.StringUtils; @@ -49,7 +49,7 @@ public final class AnnotationRuleParser { private static final Logger LOG = Loggers.get(AnnotationRuleParser.class); public List parse(String repositoryKey, Collection annotatedClasses) { - List rules = Lists.newArrayList(); + List rules = new ArrayList<>(); for (Class annotatedClass : annotatedClasses) { rules.add(create(repositoryKey, annotatedClass)); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java index 0a5d9f589b1..f09f0d35c8c 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java @@ -20,9 +20,9 @@ package org.sonar.api.rules; import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableSet; import java.util.ArrayList; import java.util.Date; +import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import javax.annotation.CheckForNull; @@ -36,6 +36,9 @@ import org.sonar.api.rule.RuleKey; import org.sonar.api.utils.SonarException; import org.sonar.check.Cardinality; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableSet; + public class Rule { /** @@ -63,7 +66,7 @@ public class Rule { * * @since 3.6 */ - private static final Set STATUS_LIST = ImmutableSet.of(STATUS_READY, STATUS_BETA, STATUS_DEPRECATED, STATUS_REMOVED); + private static final Set STATUS_LIST = unmodifiableSet(new LinkedHashSet<>(asList(STATUS_READY, STATUS_BETA, STATUS_DEPRECATED, STATUS_REMOVED))); private Integer id; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleType.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleType.java index 4ecab3affd2..db40c28879d 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleType.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleType.java @@ -19,18 +19,20 @@ */ package org.sonar.api.rules; -import com.google.common.base.Function; -import java.util.Arrays; +import java.util.LinkedHashSet; import java.util.Set; -import javax.annotation.Nonnull; -import static com.google.common.collect.FluentIterable.from; import static java.lang.String.format; +import static java.util.Arrays.stream; +import static java.util.Collections.unmodifiableSet; +import static java.util.stream.Collectors.toList; public enum RuleType { CODE_SMELL(1), BUG(2), VULNERABILITY(3); - private static final Set ALL_NAMES = from(Arrays.asList(values())).transform(ToName.INSTANCE).toSet(); + private static final Set ALL_NAMES = unmodifiableSet(new LinkedHashSet<>(stream(values()) + .map(Enum::name) + .collect(toList()))); private final int dbConstant; @@ -59,13 +61,4 @@ public enum RuleType { throw new IllegalArgumentException(format("Unsupported type value : %d", dbConstant)); } - private enum ToName implements Function { - INSTANCE; - - @Override - public String apply(@Nonnull RuleType input) { - return input.name(); - } - } - } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java index 95c4b55ecdb..093e3db899f 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java @@ -21,21 +21,18 @@ package org.sonar.api.rules; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Strings; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.io.Closeables; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.CharEncoding; import org.apache.commons.lang.StringUtils; import org.codehaus.staxmate.SMInputFactory; import org.codehaus.staxmate.in.SMHierarchicCursor; @@ -46,6 +43,8 @@ import org.sonar.api.server.ServerSide; import org.sonar.api.utils.SonarException; import org.sonar.check.Cardinality; +import static java.nio.charset.StandardCharsets.UTF_8; + /** * @since 2.3 * @deprecated in 4.2. Replaced by org.sonar.api.server.rule.RulesDefinition and org.sonar.api.server.rule.RulesDefinitionXmlLoader @@ -57,16 +56,11 @@ public final class XMLRuleParser { private static final Map TYPE_MAP = typeMapWithDeprecatedValues(); public List parse(File file) { - Reader reader = null; - try { - reader = new InputStreamReader(FileUtils.openInputStream(file), CharEncoding.UTF_8); + try (Reader reader = new InputStreamReader(FileUtils.openInputStream(file), UTF_8)) { return parse(reader); } catch (IOException e) { throw new SonarException("Fail to load the file: " + file, e); - - } finally { - Closeables.closeQuietly(reader); } } @@ -74,16 +68,11 @@ public final class XMLRuleParser { * Warning : the input stream is closed in this method */ public List parse(InputStream input) { - Reader reader = null; - try { - reader = new InputStreamReader(input, CharEncoding.UTF_8); + try (Reader reader = new InputStreamReader(input, UTF_8)) { return parse(reader); } catch (IOException e) { throw new SonarException("Fail to load the xml stream", e); - - } finally { - Closeables.closeQuietly(reader); } } @@ -128,7 +117,7 @@ public final class XMLRuleParser { rule.setSeverity(RulePriority.valueOf(StringUtils.trim(priorityAttribute))); } - List tags = Lists.newArrayList(); + List tags = new ArrayList<>(); SMInputCursor cursor = ruleC.childElementCursor(); while (cursor.getNext() != null) { @@ -200,13 +189,13 @@ public final class XMLRuleParser { param.setDefaultValue(propText); } } - if (Strings.isNullOrEmpty(param.getKey())) { + if (StringUtils.isEmpty(param.getKey())) { throw new SonarException("Node is missing in "); } } private static Map typeMapWithDeprecatedValues() { - Map map = Maps.newHashMap(); + Map map = new HashMap<>(); map.put("i", PropertyType.INTEGER.name()); map.put("s", PropertyType.STRING.name()); map.put("b", PropertyType.BOOLEAN.name()); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileExclusions.java b/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileExclusions.java index e0788edf563..1a071e62758 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileExclusions.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileExclusions.java @@ -19,15 +19,13 @@ */ package org.sonar.api.scan.filesystem; -import com.google.common.collect.ObjectArrays; +import java.util.Arrays; +import java.util.stream.Stream; import org.apache.commons.lang.StringUtils; -import org.sonar.api.batch.ScannerSide; import org.sonar.api.CoreProperties; +import org.sonar.api.batch.ScannerSide; import org.sonar.api.config.Settings; -import java.util.ArrayList; -import java.util.List; - /** * Configuration of file inclusions and exclusions. *

Plugins must not extend nor instantiate this class. An instance is injected at @@ -52,14 +50,11 @@ public class FileExclusions { } private String[] inclusions(String propertyKey) { - String[] patterns = sanitize(settings.getStringArray(propertyKey)); - List list = new ArrayList<>(); - for (String pattern : patterns) { - if (!"**/*".equals(pattern) && !"file:**/*".equals(pattern)) { - list.add(pattern); - } - } - return list.toArray(new String[list.size()]); + return Arrays.stream(settings.getStringArray(propertyKey)) + .map(StringUtils::trim) + .filter(s -> !"**/*".equals(s)) + .filter(s -> !"file:**/*".equals(s)) + .toArray(String[]::new); } public String[] sourceExclusions() { @@ -73,13 +68,8 @@ public class FileExclusions { private String[] exclusions(String globalExclusionsProperty, String exclusionsProperty) { String[] globalExclusions = settings.getStringArray(globalExclusionsProperty); String[] exclusions = settings.getStringArray(exclusionsProperty); - return sanitize(ObjectArrays.concat(globalExclusions, exclusions, String.class)); - } - - private static String[] sanitize(String[] patterns) { - for (int i = 0; i < patterns.length; i++) { - patterns[i] = StringUtils.trim(patterns[i]); - } - return patterns; + return Stream.concat(Arrays.stream(globalExclusions), Arrays.stream(exclusions)) + .map(StringUtils::trim) + .toArray(String[]::new); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/PathResolver.java b/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/PathResolver.java index 65d565f6f25..fdc1dd19afd 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/PathResolver.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/PathResolver.java @@ -19,7 +19,6 @@ */ package org.sonar.api.scan.filesystem; -import com.google.common.base.Joiner; import java.io.File; import java.nio.file.Path; import java.util.ArrayList; @@ -30,6 +29,8 @@ import org.apache.commons.io.FilenameUtils; import org.sonar.api.batch.ScannerSide; import org.sonar.api.utils.PathUtils; +import static java.util.stream.Collectors.joining; + /** * @since 3.5 */ @@ -59,7 +60,7 @@ public class PathResolver { while (cursor != null) { File parentDir = parentDir(dirs, cursor); if (parentDir != null) { - return new RelativePath(parentDir, Joiner.on("/").join(stack)); + return new RelativePath(parentDir, stack.stream().collect(joining("/"))); } stack.add(0, cursor.getName()); cursor = cursor.getParentFile(); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/security/Authenticator.java b/sonar-plugin-api/src/main/java/org/sonar/api/security/Authenticator.java index 879d840887d..cd1b37f1bf4 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/security/Authenticator.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/security/Authenticator.java @@ -19,12 +19,12 @@ */ package org.sonar.api.security; -import com.google.common.base.Preconditions; +import javax.annotation.Nullable; +import javax.servlet.http.HttpServletRequest; import org.sonar.api.ExtensionPoint; import org.sonar.api.server.ServerSide; -import javax.annotation.Nullable; -import javax.servlet.http.HttpServletRequest; +import static java.util.Objects.requireNonNull; /** * @see SecurityRealm @@ -46,7 +46,7 @@ public abstract class Authenticator { private HttpServletRequest request; public Context(@Nullable String username, @Nullable String password, HttpServletRequest request) { - Preconditions.checkNotNull(request); + requireNonNull(request); this.request = request; this.username = username; this.password = password; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/authentication/UserIdentity.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/authentication/UserIdentity.java index f26c4491b78..e491d3c5861 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/authentication/UserIdentity.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/authentication/UserIdentity.java @@ -19,19 +19,16 @@ */ package org.sonar.api.server.authentication; -import com.google.common.base.Predicate; import java.util.HashSet; import java.util.Set; import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.sonar.api.user.UserGroupValidation; import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.FluentIterable.from; +import static java.util.Objects.requireNonNull; import static org.apache.commons.lang.StringUtils.isNotBlank; -import static org.sonar.api.user.UserGroupValidation.validateGroupName; /** * User information provided by the Identity Provider to be register into the platform. @@ -170,8 +167,8 @@ public final class UserIdentity { * @since 5.5 */ public Builder setGroups(Set groups) { - checkNotNull(groups, "Groups cannot be null, please don't use this method if groups should not be synchronized."); - from(groups).filter(ValidateGroupName.INSTANCE).toList(); + requireNonNull(groups, "Groups cannot be null, please don't use this method if groups should not be synchronized."); + groups.forEach(UserGroupValidation::validateGroupName); this.groupsProvided = true; this.groups = groups; return this; @@ -204,14 +201,4 @@ public final class UserIdentity { checkArgument(email == null || email.length() <= 100, "User email size is too big (100 characters max)"); } } - - private enum ValidateGroupName implements Predicate { - INSTANCE; - - @Override - public boolean apply(@Nonnull String input) { - validateGroupName(input); - return true; - } - } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/debt/internal/DefaultDebtRemediationFunction.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/debt/internal/DefaultDebtRemediationFunction.java index b975510a8f5..b999d9b5265 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/debt/internal/DefaultDebtRemediationFunction.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/debt/internal/DefaultDebtRemediationFunction.java @@ -136,6 +136,7 @@ public class DefaultDebtRemediationFunction implements DebtRemediationFunction { return result; } + @Override public String toString() { return MoreObjects.toStringHelper(DebtRemediationFunction.class) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleParamType.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleParamType.java index 40cdb3545d5..fb729ced339 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleParamType.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleParamType.java @@ -24,7 +24,8 @@ import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.StringUtils; import org.sonar.api.PropertyType; -import static com.google.common.collect.Lists.newArrayList; +import static java.util.Arrays.asList; + /** * @since 4.2 @@ -57,7 +58,7 @@ public final class RuleParamType { private RuleParamType(String type, boolean multiple, String... values) { this.type = type; - this.values = newArrayList(values); + this.values = asList(values); StringBuilder sb = new StringBuilder(); sb.append(type); if (multiple) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java index cf8e80236ce..ce2c76818bc 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java @@ -20,16 +20,13 @@ package org.sonar.api.server.rule; import com.google.common.base.MoreObjects; -import com.google.common.base.Strings; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSortedSet; -import com.google.common.collect.Maps; import com.google.common.collect.Sets; import java.io.IOException; import java.net.URL; +import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -53,6 +50,11 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; import static java.lang.String.format; import static java.nio.charset.StandardCharsets.UTF_8; +import static java.util.Collections.emptyList; +import static java.util.Collections.unmodifiableList; +import static java.util.Collections.unmodifiableMap; +import static org.apache.commons.lang.StringUtils.defaultIfEmpty; +import static org.apache.commons.lang.StringUtils.isEmpty; import static org.apache.commons.lang.StringUtils.trimToNull; /** @@ -381,7 +383,7 @@ public interface RulesDefinition { * Instantiated by core but not by plugins, except for their tests. */ class Context { - private final Map repositoriesByKey = Maps.newHashMap(); + private final Map repositoriesByKey = new HashMap<>(); /** * New builder for {@link org.sonar.api.server.rule.RulesDefinition.Repository}. @@ -408,7 +410,7 @@ public interface RulesDefinition { } public List repositories() { - return ImmutableList.copyOf(repositoriesByKey.values()); + return unmodifiableList(new ArrayList<>(repositoriesByKey.values())); } /** @@ -417,7 +419,7 @@ public interface RulesDefinition { */ @Deprecated public List extendedRepositories(String repositoryKey) { - return Collections.emptyList(); + return emptyList(); } /** @@ -426,7 +428,7 @@ public interface RulesDefinition { */ @Deprecated public List extendedRepositories() { - return Collections.emptyList(); + return emptyList(); } private void registerRepository(NewRepositoryImpl newRepository) { @@ -468,7 +470,7 @@ public interface RulesDefinition { private final String key; private String language; private String name; - private final Map newRules = Maps.newHashMap(); + private final Map newRules = new HashMap<>(); private NewRepositoryImpl(Context context, String key, String language) { this.context = context; @@ -570,7 +572,7 @@ public interface RulesDefinition { newRule.validate(); ruleBuilder.put(newRule.key, new Rule(this, newRule)); } - this.rulesByKey = ImmutableMap.copyOf(ruleBuilder); + this.rulesByKey = unmodifiableMap(ruleBuilder); } @Override @@ -596,7 +598,7 @@ public interface RulesDefinition { @Override public List rules() { - return ImmutableList.copyOf(rulesByKey.values()); + return unmodifiableList(new ArrayList<>(rulesByKey.values())); } @Override @@ -674,7 +676,7 @@ public interface RulesDefinition { private DebtRemediationFunction debtRemediationFunction; private String gapDescription; private final Set tags = Sets.newTreeSet(); - private final Map paramsByKey = Maps.newHashMap(); + private final Map paramsByKey = new HashMap<>(); private final DebtRemediationFunctions functions; private boolean activatedByDefault; @@ -898,10 +900,10 @@ public interface RulesDefinition { } private void validate() { - if (Strings.isNullOrEmpty(name)) { + if (isEmpty(name)) { throw new IllegalStateException(format("Name of rule %s is empty", this)); } - if (Strings.isNullOrEmpty(htmlDescription) && Strings.isNullOrEmpty(markdownDescription)) { + if (isEmpty(htmlDescription) && isEmpty(markdownDescription)) { throw new IllegalStateException(format("One of HTML description or Markdown description must be defined for rule %s", this)); } } @@ -1040,7 +1042,7 @@ public interface RulesDefinition { } public List params() { - return ImmutableList.copyOf(params.values()); + return unmodifiableList(new ArrayList<>(params.values())); } public Set tags() { @@ -1118,7 +1120,7 @@ public interface RulesDefinition { * Empty default value will be converted to null. Max length is 4000 characters. */ public NewParam setDefaultValue(@Nullable String s) { - this.defaultValue = Strings.emptyToNull(s); + this.defaultValue = defaultIfEmpty(s, null); return this; } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java index bcf44b3dcb9..c958463ee22 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java @@ -22,15 +22,14 @@ package org.sonar.api.server.ws; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; import com.google.common.collect.Sets; import java.io.IOException; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -52,6 +51,7 @@ import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Strings.isNullOrEmpty; import static java.lang.String.format; import static java.util.Arrays.asList; +import static java.util.Arrays.stream; import static java.util.Objects.requireNonNull; /** @@ -100,7 +100,7 @@ import static java.util.Objects.requireNonNull; public interface WebService extends Definable { class Context { - private final Map controllers = Maps.newHashMap(); + private final Map controllers = new HashMap<>(); /** * Create a new controller. @@ -139,7 +139,7 @@ public interface WebService extends Definable { private final String path; private String description; private String since; - private final Map actions = Maps.newHashMap(); + private final Map actions = new HashMap<>(); private NewController(Context context, String path) { if (StringUtils.isBlank(path)) { @@ -254,7 +254,7 @@ public interface WebService extends Definable { private boolean post = false; private boolean isInternal = false; private RequestHandler handler; - private Map newParams = Maps.newHashMap(); + private Map newParams = new HashMap<>(); private URL responseExample = null; private List changelog = new ArrayList<>(); @@ -337,7 +337,7 @@ public interface WebService extends Definable { * @since 6.4 */ public NewAction setChangelog(Change... changes) { - this.changelog = Arrays.stream(requireNonNull(changes)) + this.changelog = stream(requireNonNull(changes)) .filter(Objects::nonNull) .collect(Collectors.toList()); @@ -776,7 +776,8 @@ public interface WebService extends Definable { private final String paramValue; - private static final Map BY_VALUE = Maps.uniqueIndex(asList(values()), input -> input.paramValue); + private static final Map BY_VALUE = stream(values()) + .collect(Collectors.toMap(v -> v.paramValue, v -> v)); SelectionMode(String paramValue) { this.paramValue = paramValue; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/internal/SimpleGetRequest.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/internal/SimpleGetRequest.java index ac3b607fe31..ce65867be76 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/internal/SimpleGetRequest.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/internal/SimpleGetRequest.java @@ -20,9 +20,8 @@ package org.sonar.api.server.ws.internal; import com.google.common.base.Splitter; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import java.io.InputStream; +import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.CheckForNull; @@ -31,10 +30,10 @@ import org.apache.commons.io.IOUtils; import org.sonar.api.server.ws.LocalConnector; import org.sonar.api.server.ws.Request; -import static com.google.common.base.Preconditions.checkNotNull; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; +import static java.util.Objects.requireNonNull; /** * Fake implementation of {@link org.sonar.api.server.ws.Request} used @@ -43,8 +42,8 @@ import static java.util.Collections.singletonList; */ public class SimpleGetRequest extends Request { - private final Map params = Maps.newHashMap(); - private final Map parts = Maps.newHashMap(); + private final Map params = new HashMap<>(); + private final Map parts = new HashMap<>(); private String mediaType = "application/json"; private String path; @@ -59,7 +58,7 @@ public class SimpleGetRequest extends Request { } public SimpleGetRequest setMediaType(String mediaType) { - checkNotNull(mediaType); + requireNonNull(mediaType); this.mediaType = mediaType; return this; } @@ -87,7 +86,7 @@ public class SimpleGetRequest extends Request { if (value == null) { return null; } - return Lists.newArrayList(Splitter.on(',').omitEmptyStrings().trimResults().split(value)); + return Splitter.on(',').omitEmptyStrings().trimResults().splitToList(value); } @Override diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/internal/ValidatingRequest.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/internal/ValidatingRequest.java index 440bf232ca2..79e76d50182 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/internal/ValidatingRequest.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/internal/ValidatingRequest.java @@ -32,9 +32,9 @@ import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.WebService; import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; +import static java.util.Objects.requireNonNull; import static org.apache.commons.lang.StringUtils.defaultString; /** @@ -56,7 +56,7 @@ public abstract class ValidatingRequest extends Request { @Override public LocalConnector localConnector() { - checkNotNull(localConnector, "Local connector has not been set"); + requireNonNull(localConnector, "Local connector has not been set"); return localConnector; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/FieldUtils2.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/FieldUtils2.java index 825e7371975..23018c5a19e 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/FieldUtils2.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/FieldUtils2.java @@ -28,20 +28,21 @@ import java.util.Collections; import java.util.List; /** - * Add features missing in org.apache.commons.lang.reflect.FieldUtils + * Add features missing in {@code org.apache.commons.lang.reflect.FieldUtils}. * * @since 2.14 */ public final class FieldUtils2 { private FieldUtils2() { + // only statics } /** - * Get accessible Field breaking scope if requested. Superclasses/interfaces are considered. + * Get accessible {@code Field} breaking scope if requested. Superclasses/interfaces are considered. * * @param clazz the class to reflect, must not be null - * @param forceAccess whether to break scope restrictions using the setAccessible method. - * False only matches public fields. + * @param forceAccess whether to break scope restrictions using the {@code setAccessible} method. + * {@code False} only matches public fields. */ public static List getFields(Class clazz, boolean forceAccess) { List result = new ArrayList<>(); @@ -50,7 +51,7 @@ public final class FieldUtils2 { for (Field declaredField : c.getDeclaredFields()) { if (!Modifier.isPublic(declaredField.getModifiers())) { if (forceAccess) { - declaredField.setAccessible(true);// NOSONAR only works from sufficiently privileged code + declaredField.setAccessible(true); } else { continue; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/LocalizedMessages.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/LocalizedMessages.java index 0ee2a85e669..6f0a1c9e59c 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/LocalizedMessages.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/LocalizedMessages.java @@ -19,11 +19,6 @@ */ package org.sonar.api.utils; -import com.google.common.collect.Iterators; -import com.google.common.collect.Lists; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; - import java.util.ArrayList; import java.util.Enumeration; import java.util.HashSet; @@ -33,6 +28,8 @@ import java.util.Locale; import java.util.MissingResourceException; import java.util.ResourceBundle; import java.util.Set; +import org.sonar.api.utils.log.Logger; +import org.sonar.api.utils.log.Loggers; public class LocalizedMessages extends ResourceBundle { @@ -91,17 +88,17 @@ public class LocalizedMessages extends ResourceBundle { } /* - * (non-Javadoc) - * - * @see java.util.ResourceBundle#handleGetObject(java.lang.String) - */ + * (non-Javadoc) + * + * @see java.util.ResourceBundle#handleGetObject(java.lang.String) + */ @Override protected Object handleGetObject(String key) { for (ResourceBundle b : bundles) { try { return b.getObject(key); } catch (MissingResourceException mre) { - // iterate + // iterate } } throw new MissingResourceException(null, null, key); @@ -116,7 +113,10 @@ public class LocalizedMessages extends ResourceBundle { // Constructor { for (ResourceBundle b : bundles) { - keys.addAll(Lists.newArrayList(Iterators.forEnumeration(b.getKeys()))); + Enumeration bundleKeys = b.getKeys(); + while (bundleKeys.hasMoreElements()) { + keys.add(bundleKeys.nextElement()); + } } i = keys.iterator(); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/MessageException.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/MessageException.java index 584dc596252..c853494e2dc 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/MessageException.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/MessageException.java @@ -19,13 +19,12 @@ */ package org.sonar.api.utils; +import java.util.Collection; import javax.annotation.CheckForNull; import javax.annotation.Nullable; -import java.util.Collection; -import java.util.Collections; - -import static com.google.common.collect.Lists.newArrayList; +import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; /** * Runtime exception for "functional" error. It aims to be displayed to end-users, without any technical information @@ -57,13 +56,13 @@ public class MessageException extends RuntimeException { private MessageException(@Nullable String message, @Nullable String l10nKey, @Nullable Object[] l10nParams) { super(message); this.l10nKey = l10nKey; - this.l10nParams = l10nParams == null ? Collections.emptyList() : Collections.unmodifiableCollection(newArrayList(l10nParams)); + this.l10nParams = l10nParams == null ? emptyList() : asList(l10nParams); } private MessageException(String message, Throwable cause) { super(message, cause); l10nKey = null; - l10nParams = Collections.emptyList(); + l10nParams = emptyList(); } public static MessageException of(String message, Throwable cause) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/UriReader.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/UriReader.java index 7a5aca0d435..b62ea204118 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/UriReader.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/UriReader.java @@ -23,12 +23,12 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.base.Throwables; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import com.google.common.io.Files; import java.io.File; import java.io.IOException; import java.net.URI; import java.nio.charset.Charset; +import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; @@ -46,7 +46,7 @@ import org.sonar.api.server.ServerSide; @ComputeEngineSide public class UriReader { - private final Map processorsByScheme = Maps.newHashMap(); + private final Map processorsByScheme = new HashMap<>(); public UriReader(SchemeProcessor[] processors) { List allProcessors = Lists.asList(new FileProcessor(), processors); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/command/Command.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/command/Command.java index 8e472823ee0..9584b3faa95 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/command/Command.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/command/Command.java @@ -21,17 +21,17 @@ package org.sonar.api.utils.command; import com.google.common.base.Joiner; import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.utils.System2; - import java.io.File; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.commons.lang.StringUtils; +import org.sonar.api.utils.System2; + +import static java.util.Collections.unmodifiableList; +import static java.util.Collections.unmodifiableMap; /** * @since 2.7 @@ -48,7 +48,7 @@ public class Command { Command(String executable, System2 system) { Preconditions.checkArgument(!StringUtils.isBlank(executable), "Command executable can not be blank"); this.executable = executable; - this.env = Maps.newHashMap(system.envVariables()); + this.env = new HashMap<>(system.envVariables()); this.system = system; } @@ -66,7 +66,7 @@ public class Command { } public List getArguments() { - return ImmutableList.copyOf(arguments); + return unmodifiableList(arguments); } public Command addArgument(String arg) { @@ -122,7 +122,7 @@ public class Command { * @since 3.2 */ public Map getEnvironmentVariables() { - return ImmutableMap.copyOf(env); + return unmodifiableMap(env); } /** @@ -150,17 +150,19 @@ public class Command { } List toStrings(boolean forLogs) { - ImmutableList.Builder command = ImmutableList.builder(); + List command = new ArrayList<>(); if (newShell) { if (system.isOsWindows()) { - command.add("cmd", "/C", "call"); + command.add("cmd"); + command.add("/C"); + command.add("call"); } else { command.add("sh"); } } command.add(executable); command.addAll(forLogs ? argumentsForLogs : arguments); - return command.build(); + return unmodifiableList(command); } public String toCommandLine() { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/Dashboard.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/Dashboard.java index d969085e1c6..55e6d782056 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/web/Dashboard.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/web/Dashboard.java @@ -21,8 +21,8 @@ package org.sonar.api.web; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ListMultimap; -import com.google.common.collect.Maps; import java.util.Collection; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -171,7 +171,7 @@ public final class Dashboard { Widget(String id) { this.id = id; - this.properties = Maps.newHashMap(); + this.properties = new HashMap<>(); } public Widget setProperty(String key, String value) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/ServletFilter.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/ServletFilter.java index c71ec53ee43..da8f4dfe0fc 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/web/ServletFilter.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/web/ServletFilter.java @@ -20,6 +20,7 @@ package org.sonar.api.web; import com.google.common.collect.ImmutableList; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; @@ -34,6 +35,7 @@ import org.sonar.api.server.ServerSide; import static com.google.common.base.Preconditions.checkArgument; import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; /** * @since 3.1 @@ -59,8 +61,8 @@ public abstract class ServletFilter implements Filter { private final Predicate[] exclusionPredicates; private UrlPattern(Builder builder) { - this.inclusions = ImmutableList.copyOf(builder.inclusions); - this.exclusions = ImmutableList.copyOf(builder.exclusions); + this.inclusions = unmodifiableList(new ArrayList<>(builder.inclusions)); + this.exclusions = unmodifiableList(new ArrayList<>(builder.exclusions)); if (builder.inclusionPredicates.isEmpty()) { // because Stream#anyMatch() returns false if stream is empty this.inclusionPredicates = new Predicate[] {s -> true}; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/page/Page.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/page/Page.java index 5e6391c2405..785f7c29b5d 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/web/page/Page.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/web/page/Page.java @@ -20,13 +20,13 @@ package org.sonar.api.web.page; import java.util.Arrays; +import java.util.LinkedHashSet; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; import javax.annotation.CheckForNull; import static java.lang.String.format; -import static java.util.Collections.unmodifiableSet; import static java.util.Objects.requireNonNull; import static org.sonar.api.web.page.Page.Scope.COMPONENT; import static org.sonar.api.web.page.Page.Scope.GLOBAL; @@ -45,7 +45,7 @@ public final class Page { private Page(Builder builder) { this.key = builder.key; this.name = builder.name; - this.qualifiers = unmodifiableSet(Stream.of(builder.qualifiers).sorted().collect(Collectors.toSet())); + this.qualifiers = Stream.of(builder.qualifiers).sorted().collect(Collectors.toCollection(LinkedHashSet::new)); this.isAdmin = builder.isAdmin; this.scope = builder.scope; } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/debt/DebtRemediationFunctionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/debt/DebtRemediationFunctionTest.java index 6176136db39..fa276281650 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/debt/DebtRemediationFunctionTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/debt/DebtRemediationFunctionTest.java @@ -71,6 +71,7 @@ public class DebtRemediationFunctionTest { @Test public void test_to_string() throws Exception { - assertThat(DebtRemediationFunction.createLinearWithOffset(Duration.create(10), Duration.create(5)).toString()).isNotNull(); + assertThat(DebtRemediationFunction.createLinearWithOffset(Duration.create(10), Duration.create(5)).toString()) + .isEqualTo("DebtRemediationFunction{type=LINEAR_OFFSET, coefficient=Duration[durationInMinutes=10], offset=Duration[durationInMinutes=5]}"); } } -- 2.39.5