@@ -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<String> paths = Lists.newArrayList(); | |||
Collection<String> 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<JarEntry> entries = jar.entries(); | |||
while (entries.hasMoreElements()) { | |||
String name = entries.nextElement().getName(); |
@@ -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(); | |||
} | |||
} |
@@ -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<InputFile> filter(Iterable<InputFile> target) { | |||
return Iterables.filter(target, this::apply); | |||
return () -> StreamSupport.stream(target.spliterator(), false) | |||
.filter(this::apply) | |||
.iterator(); | |||
} | |||
@Override |
@@ -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<OptimizedFilePredicate> predicates() { | |||
return predicates; | |||
} |
@@ -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<File> files(FilePredicate predicate) { | |||
doPreloadFiles(); | |||
return Iterables.transform(inputFiles(predicate), InputFile::file); | |||
return () -> StreamSupport.stream(inputFiles(predicate).spliterator(), false) | |||
.map(InputFile::file) | |||
.iterator(); | |||
} | |||
@Override |
@@ -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(); |
@@ -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, |
@@ -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; | |||
} |
@@ -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<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 |
@@ -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<Metric> allMetrics() { |
@@ -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<TokensLine> result = ImmutableList.builder(); | |||
private final ArrayList<TokensLine> 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<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); | |||
@@ -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"); | |||
} | |||
} |
@@ -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; |
@@ -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<String, String> getContextProperties() { | |||
return ImmutableMap.copyOf(sensorStorage.contextProperties); | |||
return unmodifiableMap(sensorStorage.contextProperties); | |||
} | |||
@Override |
@@ -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<Flow> flows() { | |||
return this.flows.stream() | |||
.<Flow>map(l -> () -> ImmutableList.copyOf(l)) | |||
.<Flow>map(l -> () -> unmodifiableList(new ArrayList<>(l))) | |||
.collect(toList()); | |||
} | |||
@@ -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<G extends Serializable> extends DefaultStorable implements Measure<G>, NewMeasure<G> { | |||
private InputComponent component; | |||
@@ -57,7 +59,7 @@ public class DefaultMeasure<G extends Serializable> extends DefaultStorable impl | |||
@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; | |||
} | |||
@@ -65,7 +67,7 @@ public class DefaultMeasure<G extends Serializable> extends DefaultStorable impl | |||
@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; | |||
} | |||
@@ -87,8 +89,8 @@ public class DefaultMeasure<G extends Serializable> 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); | |||
} |
@@ -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<TextRange, Set<TextRange>> 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; |
@@ -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; | |||
} | |||
@@ -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<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 |
@@ -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<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.") |
@@ -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) { |
@@ -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<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, ":"); | |||
@@ -144,9 +140,6 @@ public final class License { | |||
} catch (IOException e) { | |||
// silently ignore | |||
} finally { | |||
IOUtils.closeQuietly(reader); | |||
} | |||
return new License(props); | |||
} |
@@ -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 | |||
* <b>only for unit tests</b>. This is not the implementation | |||
@@ -61,7 +62,7 @@ public class MapSettings extends Settings { | |||
@Override | |||
public Map<String, String> getProperties() { | |||
return ImmutableMap.copyOf(props); | |||
return unmodifiableMap(props); | |||
} | |||
/** |
@@ -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<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; | |||
@@ -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<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) { | |||
@@ -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<String> 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<PropertyFieldDefinition> 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"); |
@@ -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()); | |||
} | |||
} |
@@ -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<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); | |||
} | |||
} |
@@ -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); |
@@ -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(); | |||
} | |||
} |
@@ -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<Resource> { | |||
} | |||
@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(); | |||
} | |||
} |
@@ -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<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); | |||
} |
@@ -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<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". |
@@ -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". | |||
* <br> | |||
@@ -43,7 +41,7 @@ import java.util.Set; | |||
*/ | |||
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)} |
@@ -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); |
@@ -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)); | |||
} | |||
} |
@@ -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<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 |
@@ -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<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()); | |||
} | |||
} |
@@ -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 |
@@ -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; | |||
@@ -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<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 |
@@ -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<G extends Serializable> implements Serializable { | |||
* @since 2.14 | |||
*/ | |||
@CheckForNull | |||
@Beta | |||
public Integer getPersonId() { | |||
return personId; | |||
} | |||
@@ -620,7 +618,6 @@ public class Measure<G extends Serializable> implements Serializable { | |||
/** | |||
* @since 2.14 | |||
*/ | |||
@Beta | |||
public Measure<G> setPersonId(@Nullable Integer i) { | |||
this.personId = i; | |||
return this; |
@@ -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; |
@@ -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<String, String> fields = Maps.newHashMap(); | |||
private final Map<String, String> fields = new HashMap<>(); | |||
/** | |||
* <p> |
@@ -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; |
@@ -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<ActiveRule, ActiveRule> { | |||
INSTANCE; | |||
@Override | |||
public ActiveRule apply(ActiveRule input) { | |||
return (ActiveRule) input.clone(); | |||
} | |||
} | |||
} |
@@ -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<String, Language> map = Maps.newLinkedHashMap(); | |||
private final Map<String, Language> map = new LinkedHashMap<>(); | |||
/** | |||
* Creates a list of languages |
@@ -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; | |||
/** | |||
* <p>Experimental extension to declare types of resources. | |||
* <p> | |||
@@ -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<String, String> properties = Maps.newHashMap(); | |||
private final Map<String, String> 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); |
@@ -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<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 | |||
@@ -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; | |||
} |
@@ -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<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()); | |||
@@ -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<ResourceType> 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<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) { | |||
@@ -186,7 +156,10 @@ public class ResourceTypes { | |||
} | |||
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) { |
@@ -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<RuleKey> { | |||
* 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); | |||
} | |||
@@ -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<String> ALL = ImmutableList.of(INFO, MINOR, MAJOR, CRITICAL, BLOCKER); | |||
public static final List<String> ALL = asList(INFO, MINOR, MAJOR, CRITICAL, BLOCKER); | |||
private Severity() { | |||
// utility |
@@ -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; | |||
} |
@@ -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<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)); | |||
} |
@@ -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<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; | |||
@@ -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<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; | |||
@@ -59,13 +61,4 @@ public enum RuleType { | |||
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(); | |||
} | |||
} | |||
} |
@@ -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<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); | |||
} | |||
} | |||
@@ -74,16 +68,11 @@ public final class XMLRuleParser { | |||
* 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); | |||
} | |||
} | |||
@@ -128,7 +117,7 @@ public final class XMLRuleParser { | |||
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) { | |||
@@ -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 <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()); |
@@ -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. | |||
* <p>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<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() { | |||
@@ -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); | |||
} | |||
} |
@@ -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(); |
@@ -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; |
@@ -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<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; | |||
@@ -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<String> { | |||
INSTANCE; | |||
@Override | |||
public boolean apply(@Nonnull String input) { | |||
validateGroupName(input); | |||
return true; | |||
} | |||
} | |||
} |
@@ -136,6 +136,7 @@ public class DefaultDebtRemediationFunction implements DebtRemediationFunction { | |||
return result; | |||
} | |||
@Override | |||
public String toString() { | |||
return MoreObjects.toStringHelper(DebtRemediationFunction.class) |
@@ -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) { |
@@ -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<String, Repository> repositoriesByKey = Maps.newHashMap(); | |||
private final Map<String, Repository> repositoriesByKey = new HashMap<>(); | |||
/** | |||
* New builder for {@link org.sonar.api.server.rule.RulesDefinition.Repository}. | |||
@@ -408,7 +410,7 @@ public interface RulesDefinition { | |||
} | |||
public List<Repository> repositories() { | |||
return ImmutableList.copyOf(repositoriesByKey.values()); | |||
return unmodifiableList(new ArrayList<>(repositoriesByKey.values())); | |||
} | |||
/** | |||
@@ -417,7 +419,7 @@ public interface RulesDefinition { | |||
*/ | |||
@Deprecated | |||
public List<ExtendedRepository> extendedRepositories(String repositoryKey) { | |||
return Collections.emptyList(); | |||
return emptyList(); | |||
} | |||
/** | |||
@@ -426,7 +428,7 @@ public interface RulesDefinition { | |||
*/ | |||
@Deprecated | |||
public List<ExtendedRepository> 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<String, NewRule> newRules = Maps.newHashMap(); | |||
private final Map<String, NewRule> 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<Rule> 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<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; | |||
@@ -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<Param> params() { | |||
return ImmutableList.copyOf(params.values()); | |||
return unmodifiableList(new ArrayList<>(params.values())); | |||
} | |||
public Set<String> 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; | |||
} | |||
} |
@@ -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<WebService.Context> { | |||
class Context { | |||
private final Map<String, Controller> controllers = Maps.newHashMap(); | |||
private final Map<String, Controller> controllers = new HashMap<>(); | |||
/** | |||
* Create a new controller. | |||
@@ -139,7 +139,7 @@ public interface WebService extends Definable<WebService.Context> { | |||
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)) { | |||
@@ -254,7 +254,7 @@ public interface WebService extends Definable<WebService.Context> { | |||
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<>(); | |||
@@ -337,7 +337,7 @@ public interface WebService extends Definable<WebService.Context> { | |||
* @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<WebService.Context> { | |||
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; |
@@ -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<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; | |||
@@ -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 |
@@ -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; | |||
} | |||
@@ -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 <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<>(); | |||
@@ -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; | |||
} |
@@ -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<String> bundleKeys = b.getKeys(); | |||
while (bundleKeys.hasMoreElements()) { | |||
keys.add(bundleKeys.nextElement()); | |||
} | |||
} | |||
i = keys.iterator(); | |||
} |
@@ -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) { |
@@ -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<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); |
@@ -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<String> 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<String, String> getEnvironmentVariables() { | |||
return ImmutableMap.copyOf(env); | |||
return unmodifiableMap(env); | |||
} | |||
/** | |||
@@ -150,17 +150,19 @@ public class Command { | |||
} | |||
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() { |
@@ -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) { |
@@ -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<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}; |
@@ -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; | |||
} |
@@ -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]}"); | |||
} | |||
} |