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.Collection;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
private static Set<ResourceDto> collectAllModules(String projectUuid, String stringToReplace, ComponentKeyUpdaterMapper mapper) {
ResourceDto project = mapper.selectProject(projectUuid);
- Set<ResourceDto> modules = Sets.newHashSet();
+ Set<ResourceDto> modules = new HashSet<>();
if (project.getKey().contains(stringToReplace)) {
modules.add(project);
}
import com.google.common.collect.Ordering;
import com.google.common.collect.Sets;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.sonarqube.ws.client.component.TreeWsRequest;
import static com.google.common.collect.FluentIterable.from;
-import static com.google.common.collect.Sets.newHashSet;
import static java.lang.String.CASE_INSENSITIVE_ORDER;
import static java.lang.String.format;
import static java.util.Collections.emptyMap;
import static org.sonar.server.component.ComponentFinder.ParamNames.COMPONENT_ID_AND_COMPONENT;
import static org.sonar.server.component.ws.ComponentDtoToWsComponent.componentDtoToWsComponent;
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
-import static org.sonar.server.ws.WsParameterBuilder.createQualifiersParameter;
import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext;
+import static org.sonar.server.ws.WsParameterBuilder.createQualifiersParameter;
import static org.sonar.server.ws.WsUtils.checkRequest;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_TREE;
return requestQualifiers;
}
- Sets.SetView<String> qualifiersIntersection = Sets.intersection(newHashSet(childrenQualifiers), newHashSet(requestQualifiers));
+ Sets.SetView<String> qualifiersIntersection = Sets.intersection(new HashSet<>(childrenQualifiers), new HashSet<>(requestQualifiers));
return new ArrayList<>(qualifiersIntersection);
}
*/
package org.sonar.server.computation.task.projectanalysis.issue;
+import java.util.HashSet;
import java.util.Set;
import javax.annotation.CheckForNull;
import static com.google.common.base.Preconditions.checkState;
-import static com.google.common.collect.Sets.newHashSet;
import static java.util.Objects.requireNonNull;
public class ComponentsWithUnprocessedIssues {
public void setUuids(Set<String> uuids) {
requireNonNull(uuids, "Uuids cannot be null");
checkState(this.uuids == null, "Uuids have already been initialized");
- this.uuids = newHashSet(uuids);
+ this.uuids = new HashSet<>(uuids);
}
public void remove(String uuid) {
package org.sonar.server.computation.task.projectanalysis.step;
import com.google.common.collect.ImmutableMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.sonar.server.computation.task.projectanalysis.component.TypeAwareVisitorAdapter;
import org.sonar.server.computation.task.step.ComputationStep;
-import static com.google.common.collect.Sets.newHashSet;
import static org.sonar.server.computation.task.projectanalysis.component.ComponentVisitor.Order.PRE_ORDER;
/**
}
private void mergeLinks(DbSession session, String componentUuid, List<ScannerReport.ComponentLink> links, List<ComponentLinkDto> previousLinks) {
- Set<String> linkType = newHashSet();
+ Set<String> linkType = new HashSet<>();
for (final ScannerReport.ComponentLink link : links) {
String type = convertType(link.getType());
if (!linkType.contains(type)) {
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
-import com.google.common.collect.Sets;
import java.util.Collection;
+import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.sonar.api.issue.condition.IsUnResolved;
@Override
public boolean execute(Map<String, Object> properties, Context context) {
Collection<String> tags = getTagsToSet(context, parseTags(properties));
- return issueUpdater.setTags((DefaultIssue) context.issue(), tags, context.issueChangeContext());
+ return issueUpdater.setTags(context.issue(), tags, context.issueChangeContext());
}
protected abstract Collection<String> getTagsToSet(Context context, Collection<String> tagsFromParams);
private Set<String> parseTags(Map<String, Object> properties) {
- Set<String> result = Sets.newHashSet();
+ Set<String> result = new HashSet<>();
String tagsString = (String) properties.get(TAGS_PARAMETER);
if (!Strings.isNullOrEmpty(tagsString)) {
for (String tag : TAGS_SPLITTER.split(tagsString)) {
*/
package org.sonar.server.issue;
-import com.google.common.collect.Sets;
import java.util.Collection;
+import java.util.HashSet;
import java.util.Set;
import org.sonar.api.server.ServerSide;
@Override
protected Collection<String> getTagsToSet(Context context, Collection<String> tagsFromParams) {
- Set<String> allTags = Sets.newHashSet(context.issue().tags());
+ Set<String> allTags = new HashSet<>(context.issue().tags());
allTags.addAll(tagsFromParams);
return allTags;
}
package org.sonar.server.issue;
import com.google.common.base.Joiner;
-import com.google.common.collect.Sets;
import java.time.temporal.ChronoUnit;
import java.util.Collection;
import java.util.Date;
+import java.util.HashSet;
import java.util.Locale;
import java.util.Objects;
import java.util.Set;
.map(tag -> RuleTagFormat.validate(tag.toLowerCase(Locale.ENGLISH)))
.collect(MoreCollectors.toSet());
- Set<String> oldTags = Sets.newHashSet(issue.tags());
+ Set<String> oldTags = new HashSet<>(issue.tags());
if (!oldTags.equals(newTags)) {
issue.setFieldChange(context, TAGS,
oldTags.isEmpty() ? null : CHANGELOG_TAG_JOINER.join(oldTags),
import com.google.common.base.Strings;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
+import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
.facetMode(request.getFacetMode())
.organizationUuid(convertOrganizationKeyToUuid(dbSession, request.getOrganization()));
- Set<String> allComponentUuids = Sets.newHashSet();
+ Set<String> allComponentUuids = new HashSet<>();
boolean effectiveOnComponentOnly = mergeDeprecatedComponentParameters(dbSession,
request.getOnComponentOnly(),
request.getComponents(),
}
private boolean mergeDeprecatedComponentParameters(DbSession session, @Nullable Boolean onComponentOnly,
- @Nullable Collection<String> components,
- @Nullable Collection<String> componentUuids,
- @Nullable Collection<String> componentKeys,
- @Nullable Collection<String> componentRootUuids,
- @Nullable Collection<String> componentRoots,
- Set<String> allComponentUuids) {
+ @Nullable Collection<String> components,
+ @Nullable Collection<String> componentUuids,
+ @Nullable Collection<String> componentKeys,
+ @Nullable Collection<String> componentRootUuids,
+ @Nullable Collection<String> componentRoots,
+ Set<String> allComponentUuids) {
boolean effectiveOnComponentOnly = false;
checkArgument(atMostOneNonNullElement(components, componentUuids, componentKeys, componentRootUuids, componentRoots),
}
private void addComponentParameters(IssueQuery.Builder builder, DbSession session,
- boolean onComponentOnly,
- Collection<String> componentUuids,
- @Nullable Collection<String> projectUuids, @Nullable Collection<String> projectKeys,
- @Nullable Collection<String> moduleUuids,
- @Nullable Collection<String> directories,
- @Nullable Collection<String> fileUuids,
- @Nullable Collection<String> authors) {
+ boolean onComponentOnly,
+ Collection<String> componentUuids,
+ @Nullable Collection<String> projectUuids, @Nullable Collection<String> projectKeys,
+ @Nullable Collection<String> moduleUuids,
+ @Nullable Collection<String> directories,
+ @Nullable Collection<String> fileUuids,
+ @Nullable Collection<String> authors) {
builder.onComponentOnly(onComponentOnly);
if (onComponentOnly) {
}
private static void addDirectories(IssueQuery.Builder builder, List<ComponentDto> directories) {
- Collection<String> directoryModuleUuids = Sets.newHashSet();
- Collection<String> directoryPaths = Sets.newHashSet();
+ Collection<String> directoryModuleUuids = new HashSet<>();
+ Collection<String> directoryPaths = new HashSet<>();
for (ComponentDto directory : directories) {
directoryModuleUuids.add(directory.moduleUuid());
directoryPaths.add(directory.path());
*/
package org.sonar.server.issue;
-import com.google.common.collect.Sets;
import java.util.Collection;
+import java.util.HashSet;
import java.util.Set;
import org.sonar.api.server.ServerSide;
@Override
protected Collection<String> getTagsToSet(Context context, Collection<String> tagsFromParams) {
- Set<String> newTags = Sets.newHashSet(context.issue().tags());
+ Set<String> newTags = new HashSet<>(context.issue().tags());
newTags.removeAll(tagsFromParams);
return newTags;
}
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ListMultimap;
-import com.google.common.collect.Sets;
import java.util.Arrays;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
}
public static class Builder {
- private final Set<String> states = Sets.newLinkedHashSet();
+ private final Set<String> states = new LinkedHashSet<>();
// transitions per originating state
private final ListMultimap<String, Transition> outTransitions = ArrayListMultimap.create();
*/
package org.sonar.server.issue.ws;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
import com.google.common.io.Resources;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.SortedSet;
+import java.util.TreeSet;
import javax.annotation.Nullable;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
Collection<String> issueTags = issueIndex.listTags(organization, textQuery, pageSize);
Collection<String> ruleTags = ruleIndex.listTags(organization, textQuery, pageSize);
- SortedSet<String> result = Sets.newTreeSet();
+ SortedSet<String> result = new TreeSet<>();
result.addAll(issueTags);
result.addAll(ruleTags);
- List<String> resultAsList = Lists.newArrayList(result);
+ List<String> resultAsList = new ArrayList<>(result);
return resultAsList.size() > pageSize && pageSize > 0 ? resultAsList.subList(0, pageSize) : resultAsList;
}
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
import java.io.Reader;
import java.io.Writer;
+import java.util.ArrayList;
import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
}
private static List<RuleActivation> parseRuleActivations(SMInputCursor rulesCursor) throws XMLStreamException {
- List<RuleActivation> activations = Lists.newArrayList();
- Set<RuleKey> activatedKeys = Sets.newHashSet();
- List<RuleKey> duplicatedKeys = Lists.newArrayList();
+ List<RuleActivation> activations = new ArrayList<>();
+ Set<RuleKey> activatedKeys = new HashSet<>();
+ List<RuleKey> duplicatedKeys = new ArrayList<>();
while (rulesCursor.getNext() != null) {
SMInputCursor ruleCursor = rulesCursor.childElementCursor();
String repositoryKey = null;
String key = null;
String severity = null;
- Map<String, String> parameters = Maps.newHashMap();
+ Map<String, String> parameters = new HashMap<>();
while (ruleCursor.getNext() != null) {
String nodeName = ruleCursor.getLocalName();
if (StringUtils.equals(ATTRIBUTE_REPOSITORY_KEY, nodeName)) {
import com.google.common.base.Function;
import com.google.common.collect.MapDifference;
import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Map<RuleKey, OrgActiveRuleDto> leftActiveRulesByRuleKey = loadActiveRules(dbSession, left);
Map<RuleKey, OrgActiveRuleDto> rightActiveRulesByRuleKey = loadActiveRules(dbSession, right);
- Set<RuleKey> allRules = Sets.newHashSet();
+ Set<RuleKey> allRules = new HashSet<>();
allRules.addAll(leftActiveRulesByRuleKey.keySet());
allRules.addAll(rightActiveRulesByRuleKey.keySet());
}
public Collection<RuleKey> collectRuleKeys() {
- Set<RuleKey> keys = Sets.newHashSet();
+ Set<RuleKey> keys = new HashSet<>();
keys.addAll(inLeft.keySet());
keys.addAll(inRight.keySet());
keys.addAll(modified.keySet());
*/
package org.sonar.server.qualityprofile;
-import com.google.common.collect.Sets;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.sonar.api.rule.RuleKey;
requireNonNull(profile.getId(), "Quality profile must be persisted");
checkArgument(!profile.isBuiltIn(), "Operation forbidden for built-in Quality Profile '%s'", profile.getKee());
BulkChangeResult result = new BulkChangeResult();
- Set<RuleKey> ruleToBeDeactivated = Sets.newHashSet();
+ Set<RuleKey> ruleToBeDeactivated = new HashSet<>();
// Keep reference to all the activated rules before backup restore
for (ActiveRuleDto activeRuleDto : db.activeRuleDao().selectByProfile(dbSession, profile)) {
if (activeRuleDto.getInheritance() == null) {
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Ordering;
-import com.google.common.collect.Sets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
facet.clear().setProperty(facetName);
Map<String, Long> facets = results.facets.get(facetName);
if (facets != null) {
- Set<String> itemsFromFacets = Sets.newHashSet();
+ Set<String> itemsFromFacets = new HashSet<>();
for (Map.Entry<String, Long> facetValue : facets.entrySet()) {
itemsFromFacets.add(facetValue.getKey());
facet.addValues(value
package org.sonar.server.rule.ws;
import com.google.common.base.Splitter;
-import com.google.common.collect.Sets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.sonar.server.ws.WsUtils;
import org.sonarqube.ws.Rules.UpdateResponse;
+import static com.google.common.collect.Sets.newHashSet;
import static java.lang.String.format;
import static java.util.Collections.singletonList;
import static java.util.Optional.ofNullable;
if (StringUtils.isBlank(value)) {
update.setTags(null);
} else {
- update.setTags(Sets.newHashSet(Splitter.on(',').omitEmptyStrings().trimResults().split(value)));
+ update.setTags(newHashSet(Splitter.on(',').omitEmptyStrings().trimResults().split(value)));
}
}
// else do not touch this field
*/
package org.sonar.server.user.ws;
-import com.google.common.collect.Sets;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
try (JsonWriter json = response.newJsonWriter()) {
json.beginObject();
json.name("user");
- Set<String> groups = Sets.newHashSet();
+ Set<String> groups = new HashSet<>();
groups.addAll(dbClient.groupMembershipDao().selectGroupsByLogins(dbSession, singletonList(login)).get(login));
userWriter.write(json, user, groups, UserJsonWriter.FIELDS);
json.endObject();
*/
package org.sonar.server.user.ws;
-import com.google.common.collect.Sets;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.sonar.api.server.ws.Change;
try (JsonWriter json = response.newJsonWriter()) {
json.beginObject();
json.name("user");
- Set<String> groups = Sets.newHashSet();
+ Set<String> groups = new HashSet<>();
UserDto user = checkFound(dbClient.userDao().selectByLogin(dbSession, login), "User '%s' doesn't exist", login);
groups.addAll(dbClient.groupMembershipDao().selectGroupsByLogins(dbSession, singletonList(login)).get(login));
userWriter.write(json, user, groups, UserJsonWriter.FIELDS);
*/
package org.sonar.server.usergroups.ws;
-import com.google.common.collect.Sets;
import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
}
private static Set<String> neededFields(Request request) {
- Set<String> fields = Sets.newHashSet();
+ Set<String> fields = new HashSet<>();
List<String> fieldsFromRequest = request.paramAsStrings(Param.FIELDS);
if (fieldsFromRequest == null || fieldsFromRequest.isEmpty()) {
fields.addAll(ALL_FIELDS);
*/
package org.sonar.core.util;
-import com.google.common.collect.Sets;
+import java.util.HashSet;
+import java.util.Set;
import org.junit.Test;
import org.sonar.test.TestUtils;
-import java.util.Set;
-
import static org.assertj.core.api.Assertions.assertThat;
public class UuidsTest {
@Test
public void create_unique() {
- Set<String> all = Sets.newHashSet();
+ Set<String> all = new HashSet<>();
for (int i = 0; i < 50; i++) {
String uuid = Uuids.create();
assertThat(uuid).isNotEmpty();
*/
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.InputFile;
return false;
}
- @VisibleForTesting
Collection<FilePredicate> predicates() {
return predicates;
}
*/
package org.sonar.api.config;
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Throwables;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.CoreProperties;
-
-import javax.annotation.Nullable;
-import javax.crypto.KeyGenerator;
-import javax.crypto.SecretKey;
-import javax.crypto.spec.SecretKeySpec;
-
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.Key;
import java.security.SecureRandom;
+import javax.annotation.Nullable;
+import javax.crypto.KeyGenerator;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.SecretKeySpec;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.StringUtils;
+import org.sonar.api.CoreProperties;
import static java.nio.charset.StandardCharsets.UTF_8;
javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance(CRYPTO_KEY);
cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, loadSecretFile());
return Base64.encodeBase64String(cipher.doFinal(clearText.getBytes(StandardCharsets.UTF_8.name())));
+ } catch (RuntimeException e) {
+ throw e;
} catch (Exception e) {
- throw Throwables.propagate(e);
+ throw new RuntimeException(e);
}
}
cipher.init(javax.crypto.Cipher.DECRYPT_MODE, loadSecretFile());
byte[] cipherData = cipher.doFinal(Base64.decodeBase64(StringUtils.trim(encryptedText)));
return new String(cipherData, StandardCharsets.UTF_8);
+ } catch (RuntimeException e) {
+ throw e;
} catch (Exception e) {
- throw Throwables.propagate(e);
+ throw new RuntimeException(e);
}
}
return loadSecretFileFromFile(path);
}
- @VisibleForTesting
Key loadSecretFileFromFile(@Nullable String path) throws IOException {
if (StringUtils.isBlank(path)) {
throw new IllegalStateException("Secret key not found. Please set the property " + CoreProperties.ENCRYPTION_SECRET_KEY_PATH);
}
}
- @VisibleForTesting
String getPathToSecretKey() {
if (StringUtils.isBlank(pathToSecretKey)) {
pathToSecretKey = new File(FileUtils.getUserDirectoryPath(), ".sonar/sonar-secret.txt").getPath();
*/
package org.sonar.api.config;
-import com.google.common.annotations.VisibleForTesting;
import java.io.IOException;
import java.io.StringReader;
import java.nio.charset.StandardCharsets;
return isExpired(new Date());
}
- @VisibleForTesting
boolean isExpired(Date now) {
Date date = getExpirationDate();
if (date == null) {
return readPlainText(new String(Base64.decodeBase64(base64.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8));
}
- @VisibleForTesting
static License readPlainText(String data) {
Map<String, String> props = new HashMap<>();
try {
*/
package org.sonar.api.config;
-import com.google.common.collect.ImmutableMap;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.LinkedHashSet;
}
private static EnumMap<PropertyType, Function<String, Result>> createValidations(List<String> options) {
- return new EnumMap<>(ImmutableMap.<PropertyType, Function<String, Result>>builder()
- .put(BOOLEAN, validateBoolean())
- .put(INTEGER, validateInteger())
- .put(LONG, validateInteger())
- .put(FLOAT, validateFloat())
- .put(REGULAR_EXPRESSION, validateRegexp())
- .put(SINGLE_SELECT_LIST,
- aValue -> options.contains(aValue) ? Result.SUCCESS : Result.newError("notInOptions"))
- .build());
+ EnumMap<PropertyType, Function<String, Result>> map = new EnumMap<>(PropertyType.class);
+ map.put(BOOLEAN, validateBoolean());
+ map.put(INTEGER, validateInteger());
+ map.put(LONG, validateInteger());
+ map.put(FLOAT, validateFloat());
+ map.put(REGULAR_EXPRESSION, validateRegexp());
+ map.put(SINGLE_SELECT_LIST,
+ aValue -> options.contains(aValue) ? Result.SUCCESS : Result.newError("notInOptions"));
+ return map;
}
private static Function<String, Result> validateBoolean() {
* only in General Settings.
*
* @throws IllegalArgumentException only qualifiers {@link Qualifiers#PROJECT PROJECT}, {@link Qualifiers#MODULE MODULE},
- * {@link Qualifiers#VIEW VIEW} and {@link Qualifiers#SUBVIEW SVW} are allowed.
+ * {@link Qualifiers#VIEW VIEW} and {@link Qualifiers#SUBVIEW SVW} are allowed.
*/
public Builder onQualifiers(String first, String... rest) {
addQualifiers(this.onQualifiers, first, rest);
* only in General Settings.
*
* @throws IllegalArgumentException only qualifiers {@link Qualifiers#PROJECT PROJECT}, {@link Qualifiers#MODULE MODULE},
- * {@link Qualifiers#VIEW VIEW} and {@link Qualifiers#SUBVIEW SVW} are allowed.
+ * {@link Qualifiers#VIEW VIEW} and {@link Qualifiers#SUBVIEW SVW} are allowed.
*/
public Builder onQualifiers(List<String> qualifiers) {
addQualifiers(this.onQualifiers, qualifiers);
* only in General Settings.
*
* @throws IllegalArgumentException only qualifiers {@link Qualifiers#PROJECT PROJECT}, {@link Qualifiers#MODULE MODULE},
- * {@link Qualifiers#VIEW VIEW} and {@link Qualifiers#SUBVIEW SVW} are allowed.
+ * {@link Qualifiers#VIEW VIEW} and {@link Qualifiers#SUBVIEW SVW} are allowed.
*/
public Builder onlyOnQualifiers(String first, String... rest) {
addQualifiers(this.onlyOnQualifiers, first, rest);
* only in General Settings.
*
* @throws IllegalArgumentException only qualifiers {@link Qualifiers#PROJECT PROJECT}, {@link Qualifiers#MODULE MODULE},
- * {@link Qualifiers#VIEW VIEW} and {@link Qualifiers#SUBVIEW SVW} are allowed.
+ * {@link Qualifiers#VIEW VIEW} and {@link Qualifiers#SUBVIEW SVW} are allowed.
*/
public Builder onlyOnQualifiers(List<String> qualifiers) {
addQualifiers(this.onlyOnQualifiers, qualifiers);
*/
package org.sonar.api.rules;
-import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.collect.ImmutableMap;
.build(),
PropertyType.STRING);
- @VisibleForTesting
static PropertyType guessType(Class<?> type) {
return TYPE_FOR_CLASS.apply(type);
}
*/
package org.sonar.api.rules;
-import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import java.io.File;
import java.io.IOException;
return map;
}
- @VisibleForTesting
static String type(String type) {
String validType = TYPE_MAP.get(type);
if (null != validType) {
*/
package org.sonar.api.server.rule;
-import com.google.common.collect.ImmutableSet;
import java.util.Collection;
+import java.util.HashSet;
import java.util.Set;
import org.sonar.api.rules.RuleType;
+import static java.util.Arrays.asList;
+import static java.util.Collections.unmodifiableSet;
+
/**
* @see org.sonar.api.server.rule.RulesDefinition.NewRule#setType(RuleType)
* @since 5.5
public static final String TAG_BUG = "bug";
public static final String TAG_SECURITY = "security";
- static final Set<String> RESERVED_TAGS = ImmutableSet.of(TAG_BUG, TAG_SECURITY);
+ static final Set<String> RESERVED_TAGS = unmodifiableSet(new HashSet<>(asList(TAG_BUG, TAG_SECURITY)));
private RuleTagsToTypeConverter() {
*/
package org.sonar.api.server.rule;
-import com.google.common.base.MoreObjects;
-import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Sets;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.TreeSet;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
/**
* Default sub-characteristics of technical debt model. See http://www.sqale.org
+ *
* @deprecated in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model.
- * See https://jira.sonarsource.com/browse/MMF-184
+ * See https://jira.sonarsource.com/browse/MMF-184
*/
@Deprecated
final class SubCharacteristics {
/**
* Create a rule with specified key. Max length of key is 200 characters. Key must be unique
* among the repository
+ *
* @throws IllegalArgumentException is key is not unique. Note a warning was logged up to version 5.4 (included)
*/
NewRule createRule(String ruleKey);
@Override
public String toString() {
- return MoreObjects.toStringHelper(this)
- .add("key", key)
- .add("language", language)
- .toString();
+ StringBuilder sb = new StringBuilder("NewRepository{");
+ sb.append("key='").append(key).append('\'');
+ sb.append(", language='").append(language).append('\'');
+ sb.append('}');
+ return sb.toString();
}
}
@Override
public String toString() {
- return MoreObjects.toStringHelper(this)
- .add("language", language)
- .add("key", key)
- .toString();
+ StringBuilder sb = new StringBuilder("Repository{");
+ sb.append("key='").append(key).append('\'');
+ sb.append(", language='").append(language).append('\'');
+ sb.append('}');
+ return sb.toString();
}
}
/**
* Shortcut for {@code create(Type.LINEAR, gap multiplier, null)}.
+ *
* @param gapMultiplier the duration to fix one issue. See {@link DebtRemediationFunction} for details about format.
* @see org.sonar.api.server.debt.DebtRemediationFunction.Type#LINEAR
*/
/**
* Shortcut for {@code create(Type.LINEAR_OFFSET, gap multiplier, base effort)}.
+ *
* @param gapMultiplier duration to fix one point of complexity. See {@link DebtRemediationFunction} for details and format.
- * @param baseEffort duration to make basic analysis. See {@link DebtRemediationFunction} for details and format.
+ * @param baseEffort duration to make basic analysis. See {@link DebtRemediationFunction} for details and format.
* @see org.sonar.api.server.debt.DebtRemediationFunction.Type#LINEAR_OFFSET
*/
DebtRemediationFunction linearWithOffset(String gapMultiplier, String baseEffort);
/**
* Shortcut for {@code create(Type.CONSTANT_ISSUE, null, base effort)}.
+ *
* @param baseEffort cost per issue. See {@link DebtRemediationFunction} for details and format.
* @see org.sonar.api.server.debt.DebtRemediationFunction.Type#CONSTANT_ISSUE
*/
/**
* Flexible way to create a {@link DebtRemediationFunction}. An unchecked exception is thrown if
* coefficient and/or offset are not valid according to the given @{code type}.
+ *
* @since 5.3
*/
DebtRemediationFunction create(DebtRemediationFunction.Type type, @Nullable String gapMultiplier, @Nullable String baseEffort);
private RuleStatus status = RuleStatus.defaultStatus();
private DebtRemediationFunction debtRemediationFunction;
private String gapDescription;
- private final Set<String> tags = Sets.newTreeSet();
+ private final Set<String> tags = new TreeSet<>();
private final Map<String, NewParam> paramsByKey = new HashMap<>();
private final DebtRemediationFunctions functions;
private boolean activatedByDefault;
/**
* Should this rule be enabled by default. For example in SonarLint standalone.
+ *
* @since 6.0
*/
public NewRule setActivatedByDefault(boolean activatedByDefault) {
* </ul>
* Finally the "bug" and "security" tags are considered as reserved. They
* are silently removed from the final state of definition.
+ *
* @since 5.5
*/
public NewRule setType(RuleType t) {
* SQALE sub-characteristic. See http://www.sqale.org
*
* @see org.sonar.api.server.rule.RulesDefinition.SubCharacteristics for constant values
- * @deprecated in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model. This method does nothing.
- * See https://jira.sonarsource.com/browse/MMF-184
* @see #setType(RuleType)
+ * @deprecated in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model. This method does nothing.
+ * See https://jira.sonarsource.com/browse/MMF-184
*/
public NewRule setDebtSubCharacteristic(@Nullable String s) {
return this;
this.gapDescription = newRule.gapDescription;
this.type = newRule.type == null ? RuleTagsToTypeConverter.convert(newRule.tags) : newRule.type;
this.tags = ImmutableSortedSet.copyOf(Sets.difference(newRule.tags, RuleTagsToTypeConverter.RESERVED_TAGS));
- ImmutableMap.Builder<String, Param> paramsBuilder = ImmutableMap.builder();
+ Map<String, Param> paramsBuilder = new HashMap<>();
for (NewParam newParam : newRule.paramsByKey.values()) {
paramsBuilder.put(newParam.key, new Param(newParam));
}
- this.params = paramsBuilder.build();
+ this.params = Collections.unmodifiableMap(paramsBuilder);
this.activatedByDefault = newRule.activatedByDefault;
}
}
/**
- * @since 5.5
* @see NewRule#setType(RuleType)
+ * @since 5.5
*/
public RuleType type() {
return type;
/**
* Should this rule be enabled by default. For example in SonarLint standalone.
+ *
* @since 6.0
*/
public boolean activatedByDefault() {
}
/**
+ * @see #type()
* @deprecated in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model. {@code null} is
* always returned. See https://jira.sonarsource.com/browse/MMF-184
- * @see #type()
*/
@CheckForNull
@Deprecated
*/
package org.sonar.api.server.rule;
-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 java.lang.reflect.Field;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import javax.annotation.CheckForNull;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.rule.RuleStatus;
private static final Logger LOG = Loggers.get(RulesDefinitionAnnotationLoader.class);
- private static final Function<Class<?>, RuleParamType> TYPE_FOR_CLASS = Functions.forMap(
- ImmutableMap.<Class<?>, RuleParamType>builder()
- .put(Integer.class, RuleParamType.INTEGER)
- .put(int.class, RuleParamType.INTEGER)
- .put(Float.class, RuleParamType.FLOAT)
- .put(float.class, RuleParamType.FLOAT)
- .put(Boolean.class, RuleParamType.BOOLEAN)
- .put(boolean.class, RuleParamType.BOOLEAN)
- .build(),
- RuleParamType.STRING);
+ private static final Map<Class<?>, RuleParamType> TYPE_FOR_CLASS;
+
+ static {
+ Map<Class<?>, RuleParamType> map = new HashMap<>();
+ map.put(Integer.class, RuleParamType.INTEGER);
+ map.put(int.class, RuleParamType.INTEGER);
+ map.put(Float.class, RuleParamType.FLOAT);
+ map.put(float.class, RuleParamType.FLOAT);
+ map.put(Boolean.class, RuleParamType.BOOLEAN);
+ map.put(boolean.class, RuleParamType.BOOLEAN);
+ TYPE_FOR_CLASS = Collections.unmodifiableMap(map);
+ }
public void load(RulesDefinition.NewExtendedRepository repo, Class... annotatedClasses) {
for (Class annotatedClass : annotatedClasses) {
}
}
- @VisibleForTesting
static RuleParamType guessType(Class<?> type) {
- return TYPE_FOR_CLASS.apply(type);
+ RuleParamType result = TYPE_FOR_CLASS.get(type);
+ return result != null ? result : RuleParamType.STRING;
}
}
*/
package org.sonar.api.server.ws;
-import com.google.common.annotations.Beta;
import java.util.Collection;
import java.util.List;
import javax.annotation.CheckForNull;
* }
* }
* </pre>
- *
+ * <p>
* It requires to use the sonar-ws library which Maven ids are:
* <pre>
* <dependency>
* <artifactId>sonar-ws</artifactId>
* </dependency>
* </pre>
- *
+ *
* @since 5.5
*/
-@Beta
public interface LocalConnector {
LocalResponse call(LocalRequest request);
interface LocalRequest {
/**
* URL path, which is the concatenation of controller path and action key, for example "api/issues/search"
+ *
* @see org.sonar.api.server.ws.WebService.Controller#path
* @see org.sonar.api.server.ws.WebService.Action#key
*/
/**
* HTTP method. Possible values are "GET" and "POST"
+ *
* @see Request#method()
*/
String getMethod();
/**
* HTTP headers
+ *
* @see Response#setHeader(String, String)
*/
Collection<String> getHeaderNames();
*/
package org.sonar.api.server.ws;
-import com.google.common.annotations.Beta;
import com.google.common.base.Splitter;
import java.io.InputStream;
import java.util.ArrayList;
}
}
- @Beta
public <T> Param<T> getParam(String key, BiFunction<Request, String, T> retrieveAndValidate) {
String param = this.param(key);
if (param != null) {
return AbsentParam.absent();
}
- @Beta
public StringParam getParam(String key, Consumer<String> validate) {
String value = this.param(key);
if (value != null) {
return AbsentStringParam.absent();
}
- @Beta
public StringParam getParam(String key) {
String value = this.param(key);
if (value != null) {
* @see LocalConnector
* @since 5.5
*/
- @Beta
public abstract LocalConnector localConnector();
/**
* Represents a Request parameter, provides information whether is was specified or not (check {@link #isPresent()})
* and utility method to nicely handles cases where the parameter is not present.
*/
- @Beta
public interface Param<T> {
boolean isPresent();
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.Sets;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
* }
* }
* </pre>
- *
+ * <p>
* Since version 5.5, a web service can call another web service to get some data. See {@link Request#localConnector()}
* provided by {@link RequestHandler#handle(Request, Response)}.
*
}
public List<Controller> controllers() {
- return ImmutableList.copyOf(controllers.values());
+ return Collections.unmodifiableList(new ArrayList<>(controllers.values()));
}
}
this.path = newController.path;
this.description = newController.description;
this.since = newController.since;
- ImmutableMap.Builder<String, Action> mapBuilder = ImmutableMap.builder();
+ Map<String, Action> mapBuilder = new HashMap<>();
for (NewAction newAction : newController.actions.values()) {
mapBuilder.put(newAction.key, new Action(this, newAction));
}
- this.actions = mapBuilder.build();
+ this.actions = Collections.unmodifiableMap(mapBuilder);
}
public String path() {
}
/**
- *
* Creates the parameter {@link org.sonar.api.server.ws.WebService.Param#TEXT_QUERY}, which is
* used to search for a subset of fields containing the supplied string.
* <p>
}
/**
- *
* Creates the parameter {@link org.sonar.api.server.ws.WebService.Param#TEXT_QUERY}, which is
* used to search for a subset of fields containing the supplied string.
* <p>
logWarningIf(isNullOrEmpty(this.since), "Since is not set on action " + path);
logWarningIf(!this.post && this.responseExample == null, "The response example is not set on action " + path);
- ImmutableMap.Builder<String, Param> paramsBuilder = ImmutableMap.builder();
+ Map<String, Param> paramsBuilder = new HashMap<>();
for (NewParam newParam : newAction.newParams.values()) {
paramsBuilder.put(newParam.key, new Param(this, newParam));
}
- this.params = paramsBuilder.build();
+ this.params = Collections.unmodifiableMap(paramsBuilder);
}
private static void logWarningIf(boolean condition, String message) {
}
/**
+ * @see #setDeprecatedKey(String, String)
* @since 5.0
* @deprecated since 6.4
- * @see #setDeprecatedKey(String, String)
*/
@Deprecated
public NewParam setDeprecatedKey(@Nullable String s) {
}
/**
- *
* @param deprecatedSince Version when the old key was replaced/deprecated. Ex: 5.6
* @since 6.4
*/
if (values == null || values.isEmpty()) {
this.possibleValues = null;
} else {
- this.possibleValues = Sets.newLinkedHashSet();
+ this.possibleValues = new LinkedHashSet<>();
for (Object value : values) {
this.possibleValues.add(value.toString());
}
/**
* Is the parameter internal ?
*
- * @since 6.2
* @see NewParam#setInternal(boolean)
+ * @since 6.2
*/
public boolean isInternal() {
return internal;
package org.sonar.api.task;
import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
import java.util.regex.Pattern;
+import org.apache.commons.lang.StringUtils;
import org.sonar.api.ExtensionPoint;
-import org.sonar.api.batch.ScannerSide;
import org.sonar.api.batch.InstantiationStrategy;
+import org.sonar.api.batch.ScannerSide;
/**
* Register and describe a {@link TaskExtension}.
}
public TaskDefinition build() {
- Preconditions.checkArgument(!Strings.isNullOrEmpty(key), "Task key must be set");
+ Preconditions.checkArgument(!StringUtils.isEmpty(key), "Task key must be set");
Preconditions.checkArgument(Pattern.matches(KEY_PATTERN, key), "Task key '" + key + "' must match " + KEY_PATTERN);
- Preconditions.checkArgument(!Strings.isNullOrEmpty(description), "Description must be set for task '" + key + "'");
+ Preconditions.checkArgument(!StringUtils.isEmpty(description), "Description must be set for task '" + key + "'");
Preconditions.checkArgument(taskClass != null, "Class must be set for task '" + key + "'");
return new TaskDefinition(this);
}
*/
package org.sonar.api.user;
+import org.apache.commons.lang.StringUtils;
import org.sonar.api.security.DefaultGroups;
import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Strings.isNullOrEmpty;
public class UserGroupValidation {
}
public static void validateGroupName(String groupName) {
- checkArgument(!isNullOrEmpty(groupName) && groupName.trim().length() > 0, "Group name cannot be empty");
+ checkArgument(!StringUtils.isEmpty(groupName) && groupName.trim().length() > 0, "Group name cannot be empty");
checkArgument(groupName.length() <= GROUP_NAME_MAX_LENGTH, "Group name cannot be longer than %s characters", GROUP_NAME_MAX_LENGTH);
checkArgument(!DefaultGroups.isAnyone(groupName), "Anyone group cannot be used");
}
*/
package org.sonar.api.utils;
-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.io.Files;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.nio.charset.Charset;
+import java.util.Arrays;
import java.util.HashMap;
-import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.stream.Stream;
import org.sonar.api.batch.ScannerSide;
import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.server.ServerSide;
private final Map<String, SchemeProcessor> processorsByScheme = new HashMap<>();
public UriReader(SchemeProcessor[] processors) {
- List<SchemeProcessor> allProcessors = Lists.asList(new FileProcessor(), processors);
- for (SchemeProcessor processor : allProcessors) {
+ Stream.concat(Stream.of(new FileProcessor()), Arrays.stream(processors)).forEach(processor -> {
for (String scheme : processor.getSupportedSchemes()) {
processorsByScheme.put(scheme.toLowerCase(Locale.ENGLISH), processor);
}
- }
+ });
}
/**
return reader.description(uri);
}
- @VisibleForTesting
SchemeProcessor searchForSupportedProcessor(URI uri) {
SchemeProcessor processor = processorsByScheme.get(uri.getScheme().toLowerCase(Locale.ENGLISH));
Preconditions.checkArgument(processor != null, "URI schema is not supported: " + uri.getScheme());
@Override
public String[] getSupportedSchemes() {
- return new String[] {"file"};
+ return new String[]{"file"};
}
@Override
*/
package org.sonar.api.utils.internal;
-import com.google.common.annotations.VisibleForTesting;
import java.io.Serializable;
import javax.annotation.Nullable;
import org.apache.commons.lang.builder.ToStringBuilder;
return minutes;
}
- @VisibleForTesting
int hoursInDay() {
return hoursInDay;
}
*/
package org.sonar.api.web;
-import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
*/
public static class Builder {
private static final String WILDCARD_CHAR = "*";
- private static final Collection<String> STATIC_RESOURCES = ImmutableList.of("/css/*", "/fonts/*", "/images/*", "/js/*", "/static/*",
- "/robots.txt", "/favicon.ico", "/apple-touch-icon*", "/mstile*");
+ private static final Collection<String> STATIC_RESOURCES = unmodifiableList(asList("/css/*", "/fonts/*", "/images/*", "/js/*", "/static/*",
+ "/robots.txt", "/favicon.ico", "/apple-touch-icon*", "/mstile*"));
private final Set<String> inclusions = new LinkedHashSet<>();
private final Set<String> exclusions = new LinkedHashSet<>();
import com.google.common.base.Joiner;
import com.google.common.base.Predicate;
import com.google.common.base.Splitter;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
-import static com.google.common.collect.Sets.newHashSet;
-
/**
* Filters the plugins to be enabled during analysis
*/
private static final String BUILDBREAKER_PLUGIN_KEY = "buildbreaker";
private static final Joiner COMMA_JOINER = Joiner.on(", ");
- private final Set<String> whites = newHashSet();
- private final Set<String> blacks = newHashSet();
+ private final Set<String> whites = new HashSet<>();
+ private final Set<String> blacks = new HashSet<>();
private final GlobalMode mode;
public ScannerPluginPredicate(Configuration settings, GlobalMode mode) {
*/
package org.sonar.scanner.issue.ignore.pattern;
-import com.google.common.collect.Sets;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
-
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.rule.RuleKey;
}
Set<Integer> getAllLines() {
- Set<Integer> allLines = Sets.newLinkedHashSet(lines);
+ Set<Integer> allLines = new LinkedHashSet<>(lines);
for (LineRange lineRange : lineRanges) {
allLines.addAll(lineRange.toLines());
}