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() {
String jarPath = null;
JarFile jar = null;
try {
- Collection<String> paths = Lists.newArrayList();
+ Collection<String> paths = new ArrayList<>();
URL root = classLoader.getResource(rootPath);
if (root != null) {
checkJarFile(root);
}
// 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<JarEntry> entries = jar.entries();
while (entries.hasMoreElements()) {
String name = entries.nextElement().getName();
*/
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
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();
}
}
*/
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;
@Override
public Iterable<InputFile> filter(Iterable<InputFile> target) {
- return Iterables.filter(target, this::apply);
+ return () -> StreamSupport.stream(target.spliterator(), false)
+ .filter(this::apply)
+ .iterator();
}
@Override
*/
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;
return result;
}
- @VisibleForTesting
Collection<OptimizedFilePredicate> predicates() {
return predicates;
}
*/
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;
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;
@Override
public Iterable<File> files(FilePredicate predicate) {
doPreloadFiles();
- return Iterables.transform(inputFiles(predicate), InputFile::file);
+ return () -> StreamSupport.stream(inputFiles(predicate).spliterator(), false)
+ .map(InputFile::file)
+ .iterator();
}
@Override
*/
package org.sonar.api.batch.rule;
-import com.google.common.annotations.Beta;
-
/**
* @since 4.2
*/
-@Beta
public interface RuleParam {
String key();
String description();
*/
package org.sonar.api.batch.rule;
-import com.google.common.annotations.Beta;
-
/**
* @since 5.2
*/
-@Beta
public enum Severity {
INFO,
MINOR,
*/
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;
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;
}
*/
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 {
this.internalKey = newRule.internalKey;
this.status = newRule.status;
- ImmutableMap.Builder<String, RuleParam> builder = ImmutableMap.builder();
+ Map<String, RuleParam> builder = new HashMap<>();
for (NewRuleParam newRuleParam : newRule.params.values()) {
builder.put(newRuleParam.key, new DefaultRuleParam(newRuleParam));
}
- params = builder.build();
+ params = Collections.unmodifiableMap(builder);
}
@Override
*/
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;
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<Metric> allMetrics() {
*/
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;
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<TokensLine> result = ImmutableList.builder();
+ private final ArrayList<TokensLine> result = new ArrayList<>();
private InputFile inputFile;
private int startLine = Integer.MIN_VALUE;
private int startIndex = 0;
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;
}
public List<TokensLine> getTokenLines() {
- return result.build();
+ return unmodifiableList(new ArrayList<>(result));
}
- private static void addNewTokensLine(ImmutableList.Builder<TokensLine> result, int startUnit, int endUnit, int startLine, StringBuilder sb) {
+ private static void addNewTokensLine(List<TokensLine> 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);
@Override
protected void doSave() {
- Preconditions.checkState(inputFile != null, "Call onFile() first");
+ checkState(inputFile != null, "Call onFile() first");
if (excluded) {
return;
}
}
private void checkInputFileNotNull() {
- Preconditions.checkState(inputFile != null, "Call onFile() first");
+ checkState(inputFile != null, "Call onFile() first");
}
}
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;
}
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;
*/
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;
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.
*
* @since 6.1
*/
public Map<String, String> getContextProperties() {
- return ImmutableMap.copyOf(sensorStorage.contextProperties);
+ return unmodifiableMap(sensorStorage.contextProperties);
}
@Override
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;
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;
@Override
public List<Flow> flows() {
return this.flows.stream()
- .<Flow>map(l -> () -> ImmutableList.copyOf(l))
+ .<Flow>map(l -> () -> unmodifiableList(new ArrayList<>(l)))
.collect(toList());
}
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<G extends Serializable> extends DefaultStorable implements Measure<G>, NewMeasure<G> {
private InputComponent component;
@Override
public DefaultMeasure<G> forMetric(Metric<G> 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;
}
@Override
public DefaultMeasure<G> 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;
}
@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);
}
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<TextRange, Set<TextRange>> referencesBySymbol;
@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;
}
@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;
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 {
}
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;
}
}
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;
}
*/
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;
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 {
private final Set<String> 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
*/
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;
}
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<PropertyDefinition> 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.")
*/
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
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) {
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;
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 -
@VisibleForTesting
static License readPlainText(String data) {
- Map<String, String> props = Maps.newHashMap();
- StringReader reader = new StringReader(data);
+ Map<String, String> props = new HashMap<>();
try {
- List<String> lines = IOUtils.readLines(reader);
+ List<String> lines = IOUtils.readLines(new StringReader(data));
for (String line : lines) {
if (StringUtils.isNotBlank(line) && line.indexOf(':') > 0) {
String key = StringUtils.substringBefore(line, ":");
} catch (IOException e) {
// silently ignore
-
- } finally {
- IOUtils.closeQuietly(reader);
}
return new License(props);
}
*/
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
* <b>only for unit tests</b>. This is not the implementation
@Override
public Map<String, String> getProperties() {
- return ImmutableMap.copyOf(props);
+ return unmodifiableMap(props);
}
/**
*/
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;
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;
@ExtensionPoint
public final class PropertyDefinition {
- private static final Set<String> SUPPORTED_QUALIFIERS = ImmutableSet.of(Qualifiers.PROJECT, Qualifiers.VIEW, Qualifiers.MODULE, Qualifiers.SUBVIEW);
+ private static final Set<String> SUPPORTED_QUALIFIERS = unmodifiableSet(new LinkedHashSet<>(asList(Qualifiers.PROJECT, Qualifiers.VIEW, Qualifiers.MODULE, Qualifiers.SUBVIEW)));
private String key;
private String defaultValue;
.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()))
@Override
public String toString() {
- if (StringUtils.isEmpty(propertySetKey)) {
+ if (isEmpty(propertySetKey)) {
return key;
}
return new StringBuilder().append(propertySetKey).append('|').append(key).toString();
}
private static void addQualifiers(List<String> 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<String> target, List<String> qualifiers) {
}
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<String> options) {
- this.options.addAll(ImmutableList.copyOf(options));
+ this.options.addAll(options);
return this;
}
}
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<PropertyFieldDefinition> fields) {
- this.fields.addAll(ImmutableList.copyOf(fields));
+ this.fields.addAll(fields);
return this;
}
}
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");
*/
package org.sonar.api.config;
-import com.google.common.base.Strings;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
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());
}
}
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
*/
.indicativeSize(field.indicativeSize())
.type(field.type())
.options(field.options())
- .build()
- );
+ .build());
}
return definitions;
}
}
public Builder options(String... options) {
- this.options.addAll(ImmutableList.copyOf(options));
+ this.options.addAll(asList(options));
return this;
}
public Builder options(List<String> 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);
}
}
*/
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;
*/
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);
}
}
}
- String escapedValue = Joiner.on(',').join(escaped);
+ String escapedValue = escaped.stream().collect(Collectors.joining(","));
text = trim(escapedValue);
}
return setProperty(key, text);
*/
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;
/**
@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();
}
}
*/
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;
}
@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();
}
}
*/
package org.sonar.api.issue;
-import com.google.common.collect.ImmutableList;
-
import java.util.List;
+import static java.util.Arrays.asList;
+
/**
* @since 3.6
*/
/**
* @since 4.4
*/
- List<String> ALL = ImmutableList.of(CONFIRM, UNCONFIRM, REOPEN, RESOLVE, FALSE_POSITIVE, WONT_FIX, CLOSE);
+ List<String> ALL = asList(CONFIRM, UNCONFIRM, REOPEN, RESOLVE, FALSE_POSITIVE, WONT_FIX, CLOSE);
}
*/
package org.sonar.api.issue;
-import com.google.common.collect.ImmutableList;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.Duration;
+import static java.util.Arrays.asList;
+
/**
* @since 3.6
*/
*/
String RESOLUTION_WONT_FIX = "WONTFIX";
- List<String> RESOLUTIONS = ImmutableList.of(RESOLUTION_FALSE_POSITIVE, RESOLUTION_WONT_FIX, RESOLUTION_FIXED, RESOLUTION_REMOVED);
+ List<String> RESOLUTIONS = asList(RESOLUTION_FALSE_POSITIVE, RESOLUTION_WONT_FIX, RESOLUTION_FIXED, RESOLUTION_REMOVED);
/**
* Return all available statuses
*
* @since 4.4
*/
- List<String> STATUSES = ImmutableList.of(STATUS_OPEN, STATUS_CONFIRMED, STATUS_REOPENED, STATUS_RESOLVED, STATUS_CLOSED);
+ List<String> STATUSES = asList(STATUS_OPEN, STATUS_CONFIRMED, STATUS_REOPENED, STATUS_RESOLVED, STATUS_CLOSED);
/**
* Unique generated key. It looks like "d2de809c-1512-4ae2-9f34-f5345c9f1a13".
*/
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".
* <br>
*/
public class NoSonarFilter implements IssueFilter {
- private final Map<String, Set<Integer>> noSonarLinesByResource = Maps.newHashMap();
+ private final Map<String, Set<Integer>> noSonarLinesByResource = new HashMap<>();
/**
* @deprecated since 5.0 use {@link #noSonarInFile(InputFile, Set)}
*/
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);
*/
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;
}
@Override
public boolean matches(Issue issue) {
- return !Strings.isNullOrEmpty(issue.attribute(propertyKey));
+ return !StringUtils.isEmpty(issue.attribute(propertyKey));
}
}
*/
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<String> resolutions;
public HasResolution(String first, String... others) {
- this.resolutions = ImmutableSet.<String>builder().add(first).add(others).build();
+ this.resolutions = new HashSet<>();
+ this.resolutions.add(first);
+ this.resolutions.addAll(asList(others));
}
@Override
*/
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<String> status;
+ private final Set<String> statuses;
public HasStatus(String first, String... others) {
- this.status = ImmutableSet.<String>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());
}
}
*/
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
*/
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;
*/
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;
private int totalCoveredLines = 0;
private int totalConditions = 0;
private int totalCoveredConditions = 0;
- private SortedMap<Integer, Integer> hitsByLine = Maps.newTreeMap();
- private SortedMap<Integer, Integer> conditionsByLine = Maps.newTreeMap();
- private SortedMap<Integer, Integer> coveredConditionsByLine = Maps.newTreeMap();
+ private SortedMap<Integer, Integer> hitsByLine = new TreeMap<>();
+ private SortedMap<Integer, Integer> conditionsByLine = new TreeMap<>();
+ private SortedMap<Integer, Integer> coveredConditionsByLine = new TreeMap<>();
private CoverageMeasuresBuilder() {
// use the factory
*/
package org.sonar.api.measures;
-import com.google.common.annotations.Beta;
import java.io.Serializable;
import java.util.Date;
import javax.annotation.CheckForNull;
* @since 2.14
*/
@CheckForNull
- @Beta
public Integer getPersonId() {
return personId;
}
/**
* @since 2.14
*/
- @Beta
public Measure<G> setPersonId(@Nullable Integer i) {
this.personId = i;
return this;
*/
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;
*/
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
private static final String DEFAULT_MESSAGE_KEY = "default_message";
private final String type;
- private final Map<String, String> fields = Maps.newHashMap();
+ private final Map<String, String> fields = new HashMap<>();
/**
* <p>
*/
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
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;
*/
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;
* @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()));
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;
}
}
@Override
- public boolean apply(ActiveRule input) {
+ public boolean test(ActiveRule input) {
return input.getRule().equals(rule);
}
}
-
- private enum CloneFunction implements Function<ActiveRule, ActiveRule> {
- INSTANCE;
- @Override
- public ActiveRule apply(ActiveRule input) {
- return (ActiveRule) input.clone();
- }
- }
}
*/
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;
private static final Logger LOG = Loggers.get(Languages.class);
- private final Map<String, Language> map = Maps.newLinkedHashMap();
+ private final Map<String, Language> map = new LinkedHashMap<>();
/**
* Creates a list of languages
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;
+
/**
* <p>Experimental extension to declare types of resources.
* <p>
this.qualifier = builder.qualifier;
this.iconPath = builder.iconPath;
this.hasSourceCode = builder.hasSourceCode;
- this.properties = Maps.newHashMap(builder.properties);
+ this.properties = new HashMap<>(builder.properties);
}
/**
}
public boolean hasProperty(String key) {
- Preconditions.checkNotNull(key);
+ requireNonNull(key);
return properties.containsKey(key);
}
* @since 3.0
*/
public String getStringProperty(String key) {
- Preconditions.checkNotNull(key);
+ requireNonNull(key);
return properties.get(key);
}
* @since 3.0
*/
public boolean getBooleanProperty(String key) {
- Preconditions.checkNotNull(key);
+ requireNonNull(key);
String value = properties.get(key);
return value != null && Boolean.parseBoolean(value);
}
* 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);
}
private String qualifier;
private String iconPath;
private boolean hasSourceCode = false;
- private final Map<String, String> properties = Maps.newHashMap();
+ private final Map<String, String> properties = new HashMap<>();
/**
* Creates a new {@link Builder}
* @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;
}
* 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);
*/
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
*/
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;
}
}
public List<String> getLeaves() {
- return ImmutableList.copyOf(Collections2.filter(relations.values(), new Predicate<String>() {
- @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
}
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;
}
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
*/
}
public ResourceTypes(ResourceTypeTree[] trees) {
- Preconditions.checkNotNull(trees);
+ requireNonNull(trees);
- Map<String, ResourceTypeTree> treeMap = Maps.newHashMap();
- Map<String, ResourceType> typeMap = Maps.newLinkedHashMap();
- Collection<ResourceType> rootsSet = Sets.newHashSet();
+ Map<String, ResourceTypeTree> treeMap = new LinkedHashMap<>();
+ Map<String, ResourceType> typeMap = new LinkedHashMap<>();
+ Collection<ResourceType> rootsSet = new LinkedHashSet<>();
for (ResourceTypeTree tree : trees) {
rootsSet.add(tree.getRootType());
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<ResourceType> mutableOrderedTypes = new ArrayList<>();
ResourceType view = null;
mutableOrderedTypes.add(0, view);
}
- orderedTypes = ImmutableSet.copyOf(mutableOrderedTypes);
+ orderedTypes = unmodifiableSet(new LinkedHashSet<>(mutableOrderedTypes));
}
public ResourceType get(String qualifier) {
}
public Collection<ResourceType> getAll(Predicate<ResourceType> predicate) {
- return Collections2.filter(typeByQualifier.values(), predicate);
- }
-
- private static class PropertyKeyPredicate implements Predicate<ResourceType> {
- 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<ResourceType> getAllWithPropertyKey(final String propertyKey) {
- return Collections2.filter(typeByQualifier.values(), new PropertyKeyPredicate(propertyKey));
+ public Collection<ResourceType> getAllWithPropertyKey(String propertyKey) {
+ return typeByQualifier.values()
+ .stream()
+ .filter(Objects::nonNull)
+ .filter(input -> input.hasProperty(propertyKey))
+ .collect(Collectors.toList());
}
- private static class StringPropertyValuePredicate implements Predicate<ResourceType> {
- 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<ResourceType> getAllWithPropertyValue(final String propertyKey, final String propertyValue) {
- return Collections2.filter(typeByQualifier.values(), new StringPropertyValuePredicate(propertyValue, propertyKey));
- }
-
- private static class BooleanPropertyValuePredicate implements Predicate<ResourceType> {
- 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<ResourceType> 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<ResourceType> getAllWithPropertyValue(final String propertyKey, final boolean propertyValue) {
- return Collections2.filter(typeByQualifier.values(), new BooleanPropertyValuePredicate(propertyKey, propertyValue));
+ public Collection<ResourceType> getAllWithPropertyValue(String propertyKey, boolean propertyValue) {
+ return typeByQualifier.values()
+ .stream()
+ .filter(Objects::nonNull)
+ .filter(input -> input.getBooleanProperty(propertyKey) == propertyValue)
+ .collect(Collectors.toList());
}
public List<String> getChildrenQualifiers(String qualifier) {
}
public List<ResourceType> getChildren(String qualifier) {
- return Lists.transform(getChildrenQualifiers(qualifier), typeByQualifier::get);
+ return getChildrenQualifiers(qualifier)
+ .stream()
+ .map(typeByQualifier::get)
+ .collect(Collectors.toList());
}
public List<String> getLeavesQualifiers(String qualifier) {
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.
*
* 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);
}
*/
package org.sonar.api.rule;
-import com.google.common.collect.ImmutableList;
-
import java.util.List;
+import static java.util.Arrays.asList;
+
/**
* @since 3.6
*/
/**
* All the supported severity values, ordered from {@link #INFO} to {@link #BLOCKER}.
*/
- public static final List<String> ALL = ImmutableList.of(INFO, MINOR, MAJOR, CRITICAL, BLOCKER);
+ public static final List<String> ALL = asList(INFO, MINOR, MAJOR, CRITICAL, BLOCKER);
private Severity() {
// utility
*/
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;
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;
}
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;
private static final Logger LOG = Loggers.get(AnnotationRuleParser.class);
public List<Rule> parse(String repositoryKey, Collection<Class> annotatedClasses) {
- List<Rule> rules = Lists.newArrayList();
+ List<Rule> rules = new ArrayList<>();
for (Class annotatedClass : annotatedClasses) {
rules.add(create(repositoryKey, annotatedClass));
}
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;
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 {
/**
*
* @since 3.6
*/
- private static final Set<String> STATUS_LIST = ImmutableSet.of(STATUS_READY, STATUS_BETA, STATUS_DEPRECATED, STATUS_REMOVED);
+ private static final Set<String> STATUS_LIST = unmodifiableSet(new LinkedHashSet<>(asList(STATUS_READY, STATUS_BETA, STATUS_DEPRECATED, STATUS_REMOVED)));
private Integer id;
*/
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<String> ALL_NAMES = from(Arrays.asList(values())).transform(ToName.INSTANCE).toSet();
+ private static final Set<String> ALL_NAMES = unmodifiableSet(new LinkedHashSet<>(stream(values())
+ .map(Enum::name)
+ .collect(toList())));
private final int dbConstant;
throw new IllegalArgumentException(format("Unsupported type value : %d", dbConstant));
}
- private enum ToName implements Function<RuleType, String> {
- INSTANCE;
-
- @Override
- public String apply(@Nonnull RuleType input) {
- return input.name();
- }
- }
-
}
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;
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
private static final Map<String, String> TYPE_MAP = typeMapWithDeprecatedValues();
public List<Rule> 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);
}
}
* Warning : the input stream is closed in this method
*/
public List<Rule> 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);
}
}
rule.setSeverity(RulePriority.valueOf(StringUtils.trim(priorityAttribute)));
}
- List<String> tags = Lists.newArrayList();
+ List<String> tags = new ArrayList<>();
SMInputCursor cursor = ruleC.childElementCursor();
while (cursor.getNext() != null) {
param.setDefaultValue(propText);
}
}
- if (Strings.isNullOrEmpty(param.getKey())) {
+ if (StringUtils.isEmpty(param.getKey())) {
throw new SonarException("Node <key> is missing in <param>");
}
}
private static Map<String, String> typeMapWithDeprecatedValues() {
- Map<String, String> map = Maps.newHashMap();
+ Map<String, String> map = new HashMap<>();
map.put("i", PropertyType.INTEGER.name());
map.put("s", PropertyType.STRING.name());
map.put("b", PropertyType.BOOLEAN.name());
*/
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.
* <p>Plugins must not extend nor instantiate this class. An instance is injected at
}
private String[] inclusions(String propertyKey) {
- String[] patterns = sanitize(settings.getStringArray(propertyKey));
- List<String> 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() {
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);
}
}
*/
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;
import org.sonar.api.batch.ScannerSide;
import org.sonar.api.utils.PathUtils;
+import static java.util.stream.Collectors.joining;
+
/**
* @since 3.5
*/
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();
*/
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
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;
*/
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.
* @since 5.5
*/
public Builder setGroups(Set<String> 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;
checkArgument(email == null || email.length() <= 100, "User email size is too big (100 characters max)");
}
}
-
- private enum ValidateGroupName implements Predicate<String> {
- INSTANCE;
-
- @Override
- public boolean apply(@Nonnull String input) {
- validateGroupName(input);
- return true;
- }
- }
}
return result;
}
+
@Override
public String toString() {
return MoreObjects.toStringHelper(DebtRemediationFunction.class)
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
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) {
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;
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;
/**
* Instantiated by core but not by plugins, except for their tests.
*/
class Context {
- private final Map<String, Repository> repositoriesByKey = Maps.newHashMap();
+ private final Map<String, Repository> repositoriesByKey = new HashMap<>();
/**
* New builder for {@link org.sonar.api.server.rule.RulesDefinition.Repository}.
}
public List<Repository> repositories() {
- return ImmutableList.copyOf(repositoriesByKey.values());
+ return unmodifiableList(new ArrayList<>(repositoriesByKey.values()));
}
/**
*/
@Deprecated
public List<ExtendedRepository> extendedRepositories(String repositoryKey) {
- return Collections.emptyList();
+ return emptyList();
}
/**
*/
@Deprecated
public List<ExtendedRepository> extendedRepositories() {
- return Collections.emptyList();
+ return emptyList();
}
private void registerRepository(NewRepositoryImpl newRepository) {
private final String key;
private String language;
private String name;
- private final Map<String, NewRule> newRules = Maps.newHashMap();
+ private final Map<String, NewRule> newRules = new HashMap<>();
private NewRepositoryImpl(Context context, String key, String language) {
this.context = context;
newRule.validate();
ruleBuilder.put(newRule.key, new Rule(this, newRule));
}
- this.rulesByKey = ImmutableMap.copyOf(ruleBuilder);
+ this.rulesByKey = unmodifiableMap(ruleBuilder);
}
@Override
@Override
public List<Rule> rules() {
- return ImmutableList.copyOf(rulesByKey.values());
+ return unmodifiableList(new ArrayList<>(rulesByKey.values()));
}
@Override
private DebtRemediationFunction debtRemediationFunction;
private String gapDescription;
private final Set<String> tags = Sets.newTreeSet();
- private final Map<String, NewParam> paramsByKey = Maps.newHashMap();
+ private final Map<String, NewParam> paramsByKey = new HashMap<>();
private final DebtRemediationFunctions functions;
private boolean activatedByDefault;
}
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));
}
}
}
public List<Param> params() {
- return ImmutableList.copyOf(params.values());
+ return unmodifiableList(new ArrayList<>(params.values()));
}
public Set<String> tags() {
* 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;
}
}
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;
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;
/**
public interface WebService extends Definable<WebService.Context> {
class Context {
- private final Map<String, Controller> controllers = Maps.newHashMap();
+ private final Map<String, Controller> controllers = new HashMap<>();
/**
* Create a new controller.
private final String path;
private String description;
private String since;
- private final Map<String, NewAction> actions = Maps.newHashMap();
+ private final Map<String, NewAction> actions = new HashMap<>();
private NewController(Context context, String path) {
if (StringUtils.isBlank(path)) {
private boolean post = false;
private boolean isInternal = false;
private RequestHandler handler;
- private Map<String, NewParam> newParams = Maps.newHashMap();
+ private Map<String, NewParam> newParams = new HashMap<>();
private URL responseExample = null;
private List<Change> changelog = new ArrayList<>();
* @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());
private final String paramValue;
- private static final Map<String, SelectionMode> BY_VALUE = Maps.uniqueIndex(asList(values()), input -> input.paramValue);
+ private static final Map<String, SelectionMode> BY_VALUE = stream(values())
+ .collect(Collectors.toMap(v -> v.paramValue, v -> v));
SelectionMode(String paramValue) {
this.paramValue = paramValue;
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;
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
*/
public class SimpleGetRequest extends Request {
- private final Map<String, String> params = Maps.newHashMap();
- private final Map<String, Part> parts = Maps.newHashMap();
+ private final Map<String, String> params = new HashMap<>();
+ private final Map<String, Part> parts = new HashMap<>();
private String mediaType = "application/json";
private String path;
}
public SimpleGetRequest setMediaType(String mediaType) {
- checkNotNull(mediaType);
+ requireNonNull(mediaType);
this.mediaType = mediaType;
return this;
}
if (value == null) {
return null;
}
- return Lists.newArrayList(Splitter.on(',').omitEmptyStrings().trimResults().split(value));
+ return Splitter.on(',').omitEmptyStrings().trimResults().splitToList(value);
}
@Override
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;
/**
@Override
public LocalConnector localConnector() {
- checkNotNull(localConnector, "Local connector has not been set");
+ requireNonNull(localConnector, "Local connector has not been set");
return localConnector;
}
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 <code>Field</code> 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 <code>setAccessible</code> method.
- * <code>False</code> 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<Field> getFields(Class clazz, boolean forceAccess) {
List<Field> result = new ArrayList<>();
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;
}
*/
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;
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 {
}
/*
- * (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);
// Constructor
{
for (ResourceBundle b : bundles) {
- keys.addAll(Lists.newArrayList(Iterators.forEnumeration(b.getKeys())));
+ Enumeration<String> bundleKeys = b.getKeys();
+ while (bundleKeys.hasMoreElements()) {
+ keys.add(bundleKeys.nextElement());
+ }
}
i = keys.iterator();
}
*/
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
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) {
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;
@ComputeEngineSide
public class UriReader {
- private final Map<String, SchemeProcessor> processorsByScheme = Maps.newHashMap();
+ private final Map<String, SchemeProcessor> processorsByScheme = new HashMap<>();
public UriReader(SchemeProcessor[] processors) {
List<SchemeProcessor> allProcessors = Lists.asList(new FileProcessor(), processors);
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
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;
}
}
public List<String> getArguments() {
- return ImmutableList.copyOf(arguments);
+ return unmodifiableList(arguments);
}
public Command addArgument(String arg) {
* @since 3.2
*/
public Map<String, String> getEnvironmentVariables() {
- return ImmutableMap.copyOf(env);
+ return unmodifiableMap(env);
}
/**
}
List<String> toStrings(boolean forLogs) {
- ImmutableList.Builder<String> command = ImmutableList.builder();
+ List<String> 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() {
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;
Widget(String id) {
this.id = id;
- this.properties = Maps.newHashMap();
+ this.properties = new HashMap<>();
}
public Widget setProperty(String key, String value) {
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;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Arrays.asList;
+import static java.util.Collections.unmodifiableList;
/**
* @since 3.1
private final Predicate<String>[] 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};
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;
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;
}
@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]}");
}
}