From: Simon Brandhof Date: Wed, 19 Jul 2017 19:48:19 +0000 (+0200) Subject: Decrease coupling with Guava X-Git-Tag: 6.6-RC1~821 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=710daeb6ef71ae21bd55a83f863907e14aa458a6;p=sonarqube.git Decrease coupling with Guava --- diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java index b954a67e27f..c001028bcf6 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java @@ -23,8 +23,8 @@ import com.google.common.annotations.VisibleForTesting; 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; @@ -132,7 +132,7 @@ public class ComponentKeyUpdaterDao implements Dao { private static Set collectAllModules(String projectUuid, String stringToReplace, ComponentKeyUpdaterMapper mapper) { ResourceDto project = mapper.selectProject(projectUuid); - Set modules = Sets.newHashSet(); + Set modules = new HashSet<>(); if (project.getKey().contains(stringToReplace)) { modules.add(project); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java index aa67d804a53..96d358fa201 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/TreeAction.java @@ -25,6 +25,7 @@ import com.google.common.collect.ImmutableSortedSet; 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; @@ -54,7 +55,6 @@ import org.sonarqube.ws.WsComponents.TreeWsResponse; 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; @@ -65,8 +65,8 @@ import static org.sonar.db.component.ComponentTreeQuery.Strategy.LEAVES; 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; @@ -261,7 +261,7 @@ public class TreeAction implements ComponentsWsAction { return requestQualifiers; } - Sets.SetView qualifiersIntersection = Sets.intersection(newHashSet(childrenQualifiers), newHashSet(requestQualifiers)); + Sets.SetView qualifiersIntersection = Sets.intersection(new HashSet<>(childrenQualifiers), new HashSet<>(requestQualifiers)); return new ArrayList<>(qualifiersIntersection); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/ComponentsWithUnprocessedIssues.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/ComponentsWithUnprocessedIssues.java index 3541851b4d0..43fafd7dfe3 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/ComponentsWithUnprocessedIssues.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/ComponentsWithUnprocessedIssues.java @@ -19,11 +19,11 @@ */ 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 { @@ -34,7 +34,7 @@ public class ComponentsWithUnprocessedIssues { public void setUuids(Set 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) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistProjectLinksStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistProjectLinksStep.java index 0734c07c9fb..91b8f31da9b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistProjectLinksStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistProjectLinksStep.java @@ -20,6 +20,7 @@ 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; @@ -39,7 +40,6 @@ import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolde 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; /** @@ -105,7 +105,7 @@ public class PersistProjectLinksStep implements ComputationStep { } private void mergeLinks(DbSession session, String componentUuid, List links, List previousLinks) { - Set linkType = newHashSet(); + Set linkType = new HashSet<>(); for (final ScannerReport.ComponentLink link : links) { String type = convertType(link.getType()); if (!linkType.contains(type)) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/AbstractChangeTagsAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/AbstractChangeTagsAction.java index 24bcaefca2b..78cc97af888 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/AbstractChangeTagsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/AbstractChangeTagsAction.java @@ -21,8 +21,8 @@ package org.sonar.server.issue; 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; @@ -55,13 +55,13 @@ public abstract class AbstractChangeTagsAction extends Action { @Override public boolean execute(Map properties, Context context) { Collection 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 getTagsToSet(Context context, Collection tagsFromParams); private Set parseTags(Map properties) { - Set result = Sets.newHashSet(); + Set result = new HashSet<>(); String tagsString = (String) properties.get(TAGS_PARAMETER); if (!Strings.isNullOrEmpty(tagsString)) { for (String tag : TAGS_SPLITTER.split(tagsString)) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/AddTagsAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/AddTagsAction.java index be36724b96a..4a0b98f46f5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/AddTagsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/AddTagsAction.java @@ -19,8 +19,8 @@ */ 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; @@ -35,7 +35,7 @@ public class AddTagsAction extends AbstractChangeTagsAction { @Override protected Collection getTagsToSet(Context context, Collection tagsFromParams) { - Set allTags = Sets.newHashSet(context.issue().tags()); + Set allTags = new HashSet<>(context.issue().tags()); allTags.addAll(tagsFromParams); return allTags; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java index 725d93d036a..a1de892c458 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueFieldsSetter.java @@ -20,10 +20,10 @@ 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; @@ -318,7 +318,7 @@ public class IssueFieldsSetter { .map(tag -> RuleTagFormat.validate(tag.toLowerCase(Locale.ENGLISH))) .collect(MoreCollectors.toSet()); - Set oldTags = Sets.newHashSet(issue.tags()); + Set oldTags = new HashSet<>(issue.tags()); if (!oldTags.equals(newTags)) { issue.setFieldChange(context, TAGS, oldTags.isEmpty() ? null : CHANGELOG_TAG_JOINER.join(oldTags), diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryFactory.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryFactory.java index 43f8cbedae0..6c95b348096 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryFactory.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryFactory.java @@ -25,11 +25,11 @@ import com.google.common.base.Splitter; 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; @@ -110,7 +110,7 @@ public class IssueQueryFactory { .facetMode(request.getFacetMode()) .organizationUuid(convertOrganizationKeyToUuid(dbSession, request.getOrganization())); - Set allComponentUuids = Sets.newHashSet(); + Set allComponentUuids = new HashSet<>(); boolean effectiveOnComponentOnly = mergeDeprecatedComponentParameters(dbSession, request.getOnComponentOnly(), request.getComponents(), @@ -203,12 +203,12 @@ public class IssueQueryFactory { } private boolean mergeDeprecatedComponentParameters(DbSession session, @Nullable Boolean onComponentOnly, - @Nullable Collection components, - @Nullable Collection componentUuids, - @Nullable Collection componentKeys, - @Nullable Collection componentRootUuids, - @Nullable Collection componentRoots, - Set allComponentUuids) { + @Nullable Collection components, + @Nullable Collection componentUuids, + @Nullable Collection componentKeys, + @Nullable Collection componentRootUuids, + @Nullable Collection componentRoots, + Set allComponentUuids) { boolean effectiveOnComponentOnly = false; checkArgument(atMostOneNonNullElement(components, componentUuids, componentKeys, componentRootUuids, componentRoots), @@ -241,13 +241,13 @@ public class IssueQueryFactory { } private void addComponentParameters(IssueQuery.Builder builder, DbSession session, - boolean onComponentOnly, - Collection componentUuids, - @Nullable Collection projectUuids, @Nullable Collection projectKeys, - @Nullable Collection moduleUuids, - @Nullable Collection directories, - @Nullable Collection fileUuids, - @Nullable Collection authors) { + boolean onComponentOnly, + Collection componentUuids, + @Nullable Collection projectUuids, @Nullable Collection projectKeys, + @Nullable Collection moduleUuids, + @Nullable Collection directories, + @Nullable Collection fileUuids, + @Nullable Collection authors) { builder.onComponentOnly(onComponentOnly); if (onComponentOnly) { @@ -326,8 +326,8 @@ public class IssueQueryFactory { } private static void addDirectories(IssueQuery.Builder builder, List directories) { - Collection directoryModuleUuids = Sets.newHashSet(); - Collection directoryPaths = Sets.newHashSet(); + Collection directoryModuleUuids = new HashSet<>(); + Collection directoryPaths = new HashSet<>(); for (ComponentDto directory : directories) { directoryModuleUuids.add(directory.moduleUuid()); directoryPaths.add(directory.path()); diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/RemoveTagsAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/RemoveTagsAction.java index e561332537d..3abfe5c10e1 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/RemoveTagsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/RemoveTagsAction.java @@ -19,8 +19,8 @@ */ 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; @@ -35,7 +35,7 @@ public class RemoveTagsAction extends AbstractChangeTagsAction { @Override protected Collection getTagsToSet(Context context, Collection tagsFromParams) { - Set newTags = Sets.newHashSet(context.issue().tags()); + Set newTags = new HashSet<>(context.issue().tags()); newTags.removeAll(tagsFromParams); return newTags; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/workflow/StateMachine.java b/server/sonar-server/src/main/java/org/sonar/server/issue/workflow/StateMachine.java index 8e8a508f4ca..b84106f0e7f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/workflow/StateMachine.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/workflow/StateMachine.java @@ -24,8 +24,8 @@ import com.google.common.collect.ArrayListMultimap; 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; @@ -61,7 +61,7 @@ public class StateMachine { } public static class Builder { - private final Set states = Sets.newLinkedHashSet(); + private final Set states = new LinkedHashSet<>(); // transitions per originating state private final ListMultimap outTransitions = ArrayListMultimap.create(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/TagsAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/TagsAction.java index 8bcb6e79ad0..fd97bac9dd8 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/TagsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/TagsAction.java @@ -19,13 +19,13 @@ */ 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; @@ -97,10 +97,10 @@ public class TagsAction implements IssuesWsAction { Collection issueTags = issueIndex.listTags(organization, textQuery, pageSize); Collection ruleTags = ruleIndex.listTags(organization, textQuery, pageSize); - SortedSet result = Sets.newTreeSet(); + SortedSet result = new TreeSet<>(); result.addAll(issueTags); result.addAll(ruleTags); - List resultAsList = Lists.newArrayList(result); + List resultAsList = new ArrayList<>(result); return resultAsList.size() > pageSize && pageSize > 0 ? resultAsList.subList(0, pageSize) : resultAsList; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java index b8173696254..1536fcce774 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java @@ -21,11 +21,12 @@ package org.sonar.server.qualityprofile; 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; @@ -171,15 +172,15 @@ public class QProfileBackuperImpl implements QProfileBackuper { } private static List parseRuleActivations(SMInputCursor rulesCursor) throws XMLStreamException { - List activations = Lists.newArrayList(); - Set activatedKeys = Sets.newHashSet(); - List duplicatedKeys = Lists.newArrayList(); + List activations = new ArrayList<>(); + Set activatedKeys = new HashSet<>(); + List duplicatedKeys = new ArrayList<>(); while (rulesCursor.getNext() != null) { SMInputCursor ruleCursor = rulesCursor.childElementCursor(); String repositoryKey = null; String key = null; String severity = null; - Map parameters = Maps.newHashMap(); + Map parameters = new HashMap<>(); while (ruleCursor.getNext() != null) { String nodeName = ruleCursor.getLocalName(); if (StringUtils.equals(ATTRIBUTE_REPOSITORY_KEY, nodeName)) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileComparison.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileComparison.java index e027f864414..68514b92836 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileComparison.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileComparison.java @@ -22,9 +22,9 @@ package org.sonar.server.qualityprofile; 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; @@ -53,7 +53,7 @@ public class QProfileComparison { Map leftActiveRulesByRuleKey = loadActiveRules(dbSession, left); Map rightActiveRulesByRuleKey = loadActiveRules(dbSession, right); - Set allRules = Sets.newHashSet(); + Set allRules = new HashSet<>(); allRules.addAll(leftActiveRulesByRuleKey.keySet()); allRules.addAll(rightActiveRulesByRuleKey.keySet()); @@ -130,7 +130,7 @@ public class QProfileComparison { } public Collection collectRuleKeys() { - Set keys = Sets.newHashSet(); + Set keys = new HashSet<>(); keys.addAll(inLeft.keySet()); keys.addAll(inRight.keySet()); keys.addAll(modified.keySet()); diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResetImpl.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResetImpl.java index 2d7e13bda02..1ec211badc9 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResetImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResetImpl.java @@ -19,9 +19,9 @@ */ 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; @@ -54,7 +54,7 @@ public class QProfileResetImpl implements QProfileReset { 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 ruleToBeDeactivated = Sets.newHashSet(); + Set 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) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java index fb5a05efabc..5a69d2110a6 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java @@ -25,10 +25,10 @@ import com.google.common.collect.ListMultimap; 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; @@ -407,7 +407,7 @@ public class SearchAction implements RulesWsAction { facet.clear().setProperty(facetName); Map facets = results.facets.get(facetName); if (facets != null) { - Set itemsFromFacets = Sets.newHashSet(); + Set itemsFromFacets = new HashSet<>(); for (Map.Entry facetValue : facets.entrySet()) { itemsFromFacets.add(facetValue.getKey()); facet.addValues(value diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/UpdateAction.java b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/UpdateAction.java index 52a04e17496..599ba81c97e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/UpdateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/UpdateAction.java @@ -20,7 +20,6 @@ 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; @@ -48,6 +47,7 @@ import org.sonar.server.user.UserSession; 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; @@ -241,7 +241,7 @@ public class UpdateAction implements RulesWsAction { 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 diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/ws/DeactivateAction.java b/server/sonar-server/src/main/java/org/sonar/server/user/ws/DeactivateAction.java index a3f702db63f..d85c4f86198 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/user/ws/DeactivateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/user/ws/DeactivateAction.java @@ -19,8 +19,8 @@ */ 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; @@ -118,7 +118,7 @@ public class DeactivateAction implements UsersWsAction { try (JsonWriter json = response.newJsonWriter()) { json.beginObject(); json.name("user"); - Set groups = Sets.newHashSet(); + Set groups = new HashSet<>(); groups.addAll(dbClient.groupMembershipDao().selectGroupsByLogins(dbSession, singletonList(login)).get(login)); userWriter.write(json, user, groups, UserJsonWriter.FIELDS); json.endObject(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/ws/UpdateAction.java b/server/sonar-server/src/main/java/org/sonar/server/user/ws/UpdateAction.java index 7b9a1da6394..cd89f46d5dd 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/user/ws/UpdateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/user/ws/UpdateAction.java @@ -19,8 +19,8 @@ */ 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; @@ -125,7 +125,7 @@ public class UpdateAction implements UsersWsAction { try (JsonWriter json = response.newJsonWriter()) { json.beginObject(); json.name("user"); - Set groups = Sets.newHashSet(); + Set 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); diff --git a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/SearchAction.java index cb0d1120da7..13632c5bc24 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/SearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/SearchAction.java @@ -19,8 +19,8 @@ */ 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; @@ -115,7 +115,7 @@ public class SearchAction implements UserGroupsWsAction { } private static Set neededFields(Request request) { - Set fields = Sets.newHashSet(); + Set fields = new HashSet<>(); List fieldsFromRequest = request.paramAsStrings(Param.FIELDS); if (fieldsFromRequest == null || fieldsFromRequest.isEmpty()) { fields.addAll(ALL_FIELDS); diff --git a/sonar-core/src/test/java/org/sonar/core/util/UuidsTest.java b/sonar-core/src/test/java/org/sonar/core/util/UuidsTest.java index c00a49c2c8f..9c5f12be1ec 100644 --- a/sonar-core/src/test/java/org/sonar/core/util/UuidsTest.java +++ b/sonar-core/src/test/java/org/sonar/core/util/UuidsTest.java @@ -19,19 +19,18 @@ */ 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 all = Sets.newHashSet(); + Set all = new HashSet<>(); for (int i = 0; i < 50; i++) { String uuid = Uuids.create(); assertThat(uuid).isNotEmpty(); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/OrPredicate.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/OrPredicate.java index 5f98bd9346a..b711b7c87ef 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/OrPredicate.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/OrPredicate.java @@ -19,7 +19,6 @@ */ package org.sonar.api.batch.fs.internal; -import com.google.common.annotations.VisibleForTesting; import org.sonar.api.batch.fs.FilePredicate; import org.sonar.api.batch.fs.InputFile; @@ -65,7 +64,6 @@ class OrPredicate extends AbstractFilePredicate { return false; } - @VisibleForTesting Collection predicates() { return predicates; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/AesCipher.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/AesCipher.java index c5afc2a36b1..049c138dd00 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/AesCipher.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/AesCipher.java @@ -19,23 +19,19 @@ */ 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; @@ -60,8 +56,10 @@ final class AesCipher implements Cipher { 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); } } @@ -72,8 +70,10 @@ final class AesCipher implements Cipher { 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); } } @@ -94,7 +94,6 @@ final class AesCipher implements Cipher { 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); @@ -122,7 +121,6 @@ final class AesCipher implements Cipher { } } - @VisibleForTesting String getPathToSecretKey() { if (StringUtils.isBlank(pathToSecretKey)) { pathToSecretKey = new File(FileUtils.getUserDirectoryPath(), ".sonar/sonar-secret.txt").getPath(); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/License.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/License.java index 6b3facf42bd..435fc8dd6f4 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/License.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/License.java @@ -19,7 +19,6 @@ */ package org.sonar.api.config; -import com.google.common.annotations.VisibleForTesting; import java.io.IOException; import java.io.StringReader; import java.nio.charset.StandardCharsets; @@ -97,7 +96,6 @@ public final class License { return isExpired(new Date()); } - @VisibleForTesting boolean isExpired(Date now) { Date date = getExpirationDate(); if (date == null) { @@ -125,7 +123,6 @@ public final class License { return readPlainText(new String(Base64.decodeBase64(base64.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8)); } - @VisibleForTesting static License readPlainText(String data) { Map props = new HashMap<>(); try { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java index d15b7c1a65b..510a9013d35 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java @@ -19,7 +19,6 @@ */ package org.sonar.api.config; -import com.google.common.collect.ImmutableMap; import java.util.ArrayList; import java.util.EnumMap; import java.util.LinkedHashSet; @@ -177,15 +176,15 @@ public final class PropertyDefinition { } private static EnumMap> createValidations(List options) { - return new EnumMap<>(ImmutableMap.>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> 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 validateBoolean() { @@ -438,7 +437,7 @@ public final class PropertyDefinition { * 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); @@ -457,7 +456,7 @@ public final class PropertyDefinition { * 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 qualifiers) { addQualifiers(this.onQualifiers, qualifiers); @@ -476,7 +475,7 @@ public final class PropertyDefinition { * 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); @@ -495,7 +494,7 @@ public final class PropertyDefinition { * 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 qualifiers) { addQualifiers(this.onlyOnQualifiers, qualifiers); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java index edf566ad403..10f0ca044cd 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java @@ -19,7 +19,6 @@ */ 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; @@ -113,7 +112,6 @@ public final class AnnotationRuleParser { .build(), PropertyType.STRING); - @VisibleForTesting static PropertyType guessType(Class type) { return TYPE_FOR_CLASS.apply(type); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java index 093e3db899f..65ec0eb82cc 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java @@ -19,7 +19,6 @@ */ 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; @@ -208,7 +207,6 @@ public final class XMLRuleParser { return map; } - @VisibleForTesting static String type(String type) { String validType = TYPE_MAP.get(type); if (null != validType) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleTagsToTypeConverter.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleTagsToTypeConverter.java index 1248a83b310..1d05f3bf293 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleTagsToTypeConverter.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RuleTagsToTypeConverter.java @@ -19,11 +19,14 @@ */ 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 @@ -32,7 +35,7 @@ class RuleTagsToTypeConverter { public static final String TAG_BUG = "bug"; public static final String TAG_SECURITY = "security"; - static final Set RESERVED_TAGS = ImmutableSet.of(TAG_BUG, TAG_SECURITY); + static final Set RESERVED_TAGS = unmodifiableSet(new HashSet<>(asList(TAG_BUG, TAG_SECURITY))); private RuleTagsToTypeConverter() { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java index ce2c76818bc..0e9b90fbc3c 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java @@ -19,18 +19,18 @@ */ 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; @@ -159,8 +159,9 @@ public interface RulesDefinition { /** * 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 { @@ -447,6 +448,7 @@ public interface RulesDefinition { /** * 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); @@ -520,10 +522,11 @@ public interface RulesDefinition { @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(); } } @@ -620,10 +623,11 @@ public interface RulesDefinition { @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(); } } @@ -634,6 +638,7 @@ public interface RulesDefinition { /** * 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 */ @@ -641,14 +646,16 @@ public interface RulesDefinition { /** * 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 */ @@ -657,6 +664,7 @@ public interface RulesDefinition { /** * 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); @@ -675,7 +683,7 @@ public interface RulesDefinition { private RuleStatus status = RuleStatus.defaultStatus(); private DebtRemediationFunction debtRemediationFunction; private String gapDescription; - private final Set tags = Sets.newTreeSet(); + private final Set tags = new TreeSet<>(); private final Map paramsByKey = new HashMap<>(); private final DebtRemediationFunctions functions; private boolean activatedByDefault; @@ -705,6 +713,7 @@ public interface RulesDefinition { /** * Should this rule be enabled by default. For example in SonarLint standalone. + * * @since 6.0 */ public NewRule setActivatedByDefault(boolean activatedByDefault) { @@ -731,6 +740,7 @@ public interface RulesDefinition { * * 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) { @@ -805,9 +815,9 @@ public interface RulesDefinition { * 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; @@ -948,11 +958,11 @@ public interface RulesDefinition { 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 paramsBuilder = ImmutableMap.builder(); + Map 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; } @@ -969,8 +979,8 @@ public interface RulesDefinition { } /** - * @since 5.5 * @see NewRule#setType(RuleType) + * @since 5.5 */ public RuleType type() { return type; @@ -996,6 +1006,7 @@ public interface RulesDefinition { /** * Should this rule be enabled by default. For example in SonarLint standalone. + * * @since 6.0 */ public boolean activatedByDefault() { @@ -1007,9 +1018,9 @@ public interface RulesDefinition { } /** + * @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 diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionAnnotationLoader.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionAnnotationLoader.java index 576c80d107c..95858cfe18b 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionAnnotationLoader.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionAnnotationLoader.java @@ -19,12 +19,11 @@ */ 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; @@ -45,16 +44,18 @@ public class RulesDefinitionAnnotationLoader { private static final Logger LOG = Loggers.get(RulesDefinitionAnnotationLoader.class); - private static final Function, RuleParamType> TYPE_FOR_CLASS = Functions.forMap( - ImmutableMap., 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, RuleParamType> TYPE_FOR_CLASS; + + static { + Map, 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) { @@ -113,8 +114,8 @@ public class RulesDefinitionAnnotationLoader { } } - @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; } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/LocalConnector.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/LocalConnector.java index 6dea7ce323b..a6cdc79c098 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/LocalConnector.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/LocalConnector.java @@ -19,7 +19,6 @@ */ package org.sonar.api.server.ws; -import com.google.common.annotations.Beta; import java.util.Collection; import java.util.List; import javax.annotation.CheckForNull; @@ -42,7 +41,7 @@ import javax.annotation.CheckForNull; * } * } * - * + *

* It requires to use the sonar-ws library which Maven ids are: *

  *   <dependency>
@@ -50,10 +49,9 @@ import javax.annotation.CheckForNull;
  *     <artifactId>sonar-ws</artifactId>
  *   </dependency>
  * 
- * + * * @since 5.5 */ -@Beta public interface LocalConnector { LocalResponse call(LocalRequest request); @@ -61,6 +59,7 @@ public interface LocalConnector { 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 */ @@ -73,6 +72,7 @@ public interface LocalConnector { /** * HTTP method. Possible values are "GET" and "POST" + * * @see Request#method() */ String getMethod(); @@ -112,6 +112,7 @@ public interface LocalConnector { /** * HTTP headers + * * @see Response#setHeader(String, String) */ Collection getHeaderNames(); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/Request.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/Request.java index d8a6b9ce39c..2428fc441f5 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/Request.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/Request.java @@ -19,7 +19,6 @@ */ 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; @@ -277,7 +276,6 @@ public abstract class Request { } } - @Beta public Param getParam(String key, BiFunction retrieveAndValidate) { String param = this.param(key); if (param != null) { @@ -286,7 +284,6 @@ public abstract class Request { return AbsentParam.absent(); } - @Beta public StringParam getParam(String key, Consumer validate) { String value = this.param(key); if (value != null) { @@ -296,7 +293,6 @@ public abstract class Request { return AbsentStringParam.absent(); } - @Beta public StringParam getParam(String key) { String value = this.param(key); if (value != null) { @@ -310,7 +306,6 @@ public abstract class Request { * @see LocalConnector * @since 5.5 */ - @Beta public abstract LocalConnector localConnector(); /** @@ -332,7 +327,6 @@ public abstract class Request { * 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 { boolean isPresent(); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java index 84cb57735c6..aaa7b86b910 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java @@ -20,9 +20,6 @@ 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; @@ -30,6 +27,7 @@ import java.util.ArrayList; 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; @@ -89,7 +87,7 @@ import static java.util.Objects.requireNonNull; * } * } * - * + *

* 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)}. * @@ -130,7 +128,7 @@ public interface WebService extends Definable { } public List controllers() { - return ImmutableList.copyOf(controllers.values()); + return Collections.unmodifiableList(new ArrayList<>(controllers.values())); } } @@ -199,11 +197,11 @@ public interface WebService extends Definable { this.path = newController.path; this.description = newController.description; this.since = newController.since; - ImmutableMap.Builder mapBuilder = ImmutableMap.builder(); + Map 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() { @@ -411,7 +409,6 @@ public interface WebService extends Definable { } /** - * * 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. *

@@ -424,7 +421,6 @@ public interface WebService extends Definable { } /** - * * 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. *

@@ -511,11 +507,11 @@ public interface WebService extends Definable { 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 paramsBuilder = ImmutableMap.builder(); + Map 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) { @@ -661,9 +657,9 @@ public interface WebService extends Definable { } /** + * @see #setDeprecatedKey(String, String) * @since 5.0 * @deprecated since 6.4 - * @see #setDeprecatedKey(String, String) */ @Deprecated public NewParam setDeprecatedKey(@Nullable String s) { @@ -672,7 +668,6 @@ public interface WebService extends Definable { } /** - * * @param deprecatedSince Version when the old key was replaced/deprecated. Ex: 5.6 * @since 6.4 */ @@ -752,7 +747,7 @@ public interface WebService extends Definable { 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()); } @@ -909,8 +904,8 @@ public interface WebService extends Definable { /** * Is the parameter internal ? * - * @since 6.2 * @see NewParam#setInternal(boolean) + * @since 6.2 */ public boolean isInternal() { return internal; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/task/TaskDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/task/TaskDefinition.java index c34ff5250b4..9b08b95cfe4 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/task/TaskDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/task/TaskDefinition.java @@ -20,11 +20,11 @@ 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}. @@ -115,9 +115,9 @@ public class TaskDefinition implements Comparable { } 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); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/user/UserGroupValidation.java b/sonar-plugin-api/src/main/java/org/sonar/api/user/UserGroupValidation.java index 31958e6a2c9..0eddb443a77 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/user/UserGroupValidation.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/user/UserGroupValidation.java @@ -19,10 +19,10 @@ */ 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 { @@ -33,7 +33,7 @@ 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"); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/UriReader.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/UriReader.java index b62ea204118..61a548d0403 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/UriReader.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/UriReader.java @@ -19,19 +19,18 @@ */ 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; @@ -49,12 +48,11 @@ public class UriReader { private final Map processorsByScheme = new HashMap<>(); public UriReader(SchemeProcessor[] processors) { - List 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); } - } + }); } /** @@ -82,7 +80,6 @@ public class UriReader { 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()); @@ -106,7 +103,7 @@ public class UriReader { @Override public String[] getSupportedSchemes() { - return new String[] {"file"}; + return new String[]{"file"}; } @Override diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/internal/WorkDuration.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/internal/WorkDuration.java index 2ac02200643..b7625873fd9 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/internal/WorkDuration.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/internal/WorkDuration.java @@ -19,7 +19,6 @@ */ 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; @@ -165,7 +164,6 @@ public class WorkDuration implements Serializable { return minutes; } - @VisibleForTesting int hoursInDay() { return hoursInDay; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/ServletFilter.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/ServletFilter.java index da8f4dfe0fc..ab129155de8 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/web/ServletFilter.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/web/ServletFilter.java @@ -19,7 +19,6 @@ */ package org.sonar.api.web; -import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -141,8 +140,8 @@ public abstract class ServletFilter implements Filter { */ public static class Builder { private static final String WILDCARD_CHAR = "*"; - private static final Collection STATIC_RESOURCES = ImmutableList.of("/css/*", "/fonts/*", "/images/*", "/js/*", "/static/*", - "/robots.txt", "/favicon.ico", "/apple-touch-icon*", "/mstile*"); + private static final Collection STATIC_RESOURCES = unmodifiableList(asList("/css/*", "/fonts/*", "/images/*", "/js/*", "/static/*", + "/robots.txt", "/favicon.ico", "/apple-touch-icon*", "/mstile*")); private final Set inclusions = new LinkedHashSet<>(); private final Set exclusions = new LinkedHashSet<>(); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginPredicate.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginPredicate.java index befc42c1ea0..dc39f5c0ced 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginPredicate.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginPredicate.java @@ -22,6 +22,7 @@ package org.sonar.scanner.bootstrap; 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; @@ -33,8 +34,6 @@ import org.sonar.api.config.Configuration; 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 */ @@ -46,8 +45,8 @@ public class ScannerPluginPredicate implements Predicate { private static final String BUILDBREAKER_PLUGIN_KEY = "buildbreaker"; private static final Joiner COMMA_JOINER = Joiner.on(", "); - private final Set whites = newHashSet(); - private final Set blacks = newHashSet(); + private final Set whites = new HashSet<>(); + private final Set blacks = new HashSet<>(); private final GlobalMode mode; public ScannerPluginPredicate(Configuration settings, GlobalMode mode) { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/IssuePattern.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/IssuePattern.java index 689d4158d8d..a6c50cd4715 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/IssuePattern.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/ignore/pattern/IssuePattern.java @@ -19,13 +19,11 @@ */ 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; @@ -76,7 +74,7 @@ public class IssuePattern { } Set getAllLines() { - Set allLines = Sets.newLinkedHashSet(lines); + Set allLines = new LinkedHashSet<>(lines); for (LineRange lineRange : lineRanges) { allLines.addAll(lineRange.toLines()); }