From 6b0bbd4c60fe0b3021e4df093750685110f604c6 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Thu, 10 Sep 2015 10:30:38 -0400 Subject: [PATCH] Remove use of com.google.common.collect.Sets Remove use of com.google.common.collect.Sets. This commit removes all uses of com.google.common.collect.Sets. This is one of many steps in the eventual removal of Guava as a dependency. Relates elastic/elasticsearchelastic/elasticsearch#13224 Original commit: elastic/x-pack-elasticsearch@5276ed9723e56bdeb6a150072df5b6b296385b19 --- .../elasticsearch/shield/audit/AuditTrailModule.java | 2 +- .../java/org/elasticsearch/shield/authc/Realms.java | 3 +-- .../shield/authc/esusers/tool/ESUsersTool.java | 6 ++++-- .../shield/authz/InternalAuthorizationService.java | 8 ++------ .../org/elasticsearch/shield/authz/Privilege.java | 2 +- .../DefaultIndicesAndAliasesResolver.java | 4 ++-- .../shield/crypto/tool/SystemKeyTool.java | 2 +- .../authz/accesscontrol/IndicesPermissionTests.java | 2 +- .../shield/support/ShieldFilesTests.java | 12 +++--------- 9 files changed, 16 insertions(+), 25 deletions(-) diff --git a/shield/src/main/java/org/elasticsearch/shield/audit/AuditTrailModule.java b/shield/src/main/java/org/elasticsearch/shield/audit/AuditTrailModule.java index 3fd2ace69a1..cedfb0fec4d 100644 --- a/shield/src/main/java/org/elasticsearch/shield/audit/AuditTrailModule.java +++ b/shield/src/main/java/org/elasticsearch/shield/audit/AuditTrailModule.java @@ -5,10 +5,10 @@ */ package org.elasticsearch.shield.audit; -import com.google.common.collect.Sets; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.inject.multibindings.Multibinder; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.shield.ShieldLifecycleService; import org.elasticsearch.shield.audit.index.IndexAuditTrail; import org.elasticsearch.shield.audit.index.IndexAuditUserHolder; diff --git a/shield/src/main/java/org/elasticsearch/shield/authc/Realms.java b/shield/src/main/java/org/elasticsearch/shield/authc/Realms.java index 0a6433f2067..fb6f3ad2308 100644 --- a/shield/src/main/java/org/elasticsearch/shield/authc/Realms.java +++ b/shield/src/main/java/org/elasticsearch/shield/authc/Realms.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.shield.authc; -import com.google.common.collect.Sets; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.inject.Inject; @@ -67,7 +66,7 @@ public class Realms extends AbstractLifecycleComponent implements Iterab protected List initRealms() { Settings realmsSettings = settings.getAsSettings("shield.authc.realms"); - Set internalTypes = Sets.newHashSet(); + Set internalTypes = new HashSet<>(); List realms = new ArrayList<>(); for (String name : realmsSettings.names()) { Settings realmSettings = realmsSettings.getAsSettings(name); diff --git a/shield/src/main/java/org/elasticsearch/shield/authc/esusers/tool/ESUsersTool.java b/shield/src/main/java/org/elasticsearch/shield/authc/esusers/tool/ESUsersTool.java index b2e13a99729..5a25eff29ea 100644 --- a/shield/src/main/java/org/elasticsearch/shield/authc/esusers/tool/ESUsersTool.java +++ b/shield/src/main/java/org/elasticsearch/shield/authc/esusers/tool/ESUsersTool.java @@ -6,7 +6,8 @@ package org.elasticsearch.shield.authc.esusers.tool; import com.google.common.base.Joiner; -import com.google.common.collect.*; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ObjectArrays; import org.apache.commons.cli.CommandLine; import org.elasticsearch.common.Strings; import org.elasticsearch.common.cli.CheckFileCommand; @@ -14,6 +15,7 @@ import org.elasticsearch.common.cli.CliTool; import org.elasticsearch.common.cli.CliToolConfig; import org.elasticsearch.common.cli.Terminal; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.env.Environment; import org.elasticsearch.shield.authc.Realms; import org.elasticsearch.shield.authc.esusers.ESUsersRealm; @@ -394,7 +396,7 @@ public class ESUsersTool extends CliTool { if (roles.size() == 0) { userRolesToWrite.remove(username); } else { - userRolesToWrite.put(username, Sets.newLinkedHashSet(roles).toArray(new String[]{})); + userRolesToWrite.put(username, new LinkedHashSet<>(roles).toArray(new String[]{})); } FileUserRolesStore.writeFile(userRolesToWrite, file); diff --git a/shield/src/main/java/org/elasticsearch/shield/authz/InternalAuthorizationService.java b/shield/src/main/java/org/elasticsearch/shield/authz/InternalAuthorizationService.java index 10f00898705..1c04db45c6c 100644 --- a/shield/src/main/java/org/elasticsearch/shield/authz/InternalAuthorizationService.java +++ b/shield/src/main/java/org/elasticsearch/shield/authz/InternalAuthorizationService.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.shield.authz; -import com.google.common.collect.Sets; import org.elasticsearch.ElasticsearchSecurityException; import org.elasticsearch.action.CompositeIndicesRequest; import org.elasticsearch.action.IndicesRequest; @@ -20,6 +19,7 @@ import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.search.action.SearchServiceTransportAction; import org.elasticsearch.shield.User; import org.elasticsearch.shield.audit.AuditTrail; @@ -31,11 +31,7 @@ import org.elasticsearch.shield.authz.indicesresolver.IndicesAndAliasesResolver; import org.elasticsearch.shield.authz.store.RolesStore; import org.elasticsearch.transport.TransportRequest; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.function.Predicate; import static org.elasticsearch.shield.support.Exceptions.authorizationError; diff --git a/shield/src/main/java/org/elasticsearch/shield/authz/Privilege.java b/shield/src/main/java/org/elasticsearch/shield/authz/Privilege.java index f0c5b480dbd..e7e3144c3d9 100644 --- a/shield/src/main/java/org/elasticsearch/shield/authz/Privilege.java +++ b/shield/src/main/java/org/elasticsearch/shield/authz/Privilege.java @@ -9,7 +9,6 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; import com.google.common.util.concurrent.UncheckedExecutionException; import dk.brics.automaton.Automaton; import dk.brics.automaton.BasicAutomata; @@ -21,6 +20,7 @@ import org.elasticsearch.action.search.MultiSearchAction; import org.elasticsearch.action.search.SearchAction; import org.elasticsearch.action.suggest.SuggestAction; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.shield.support.AutomatonPredicate; import org.elasticsearch.shield.support.Automatons; diff --git a/shield/src/main/java/org/elasticsearch/shield/authz/indicesresolver/DefaultIndicesAndAliasesResolver.java b/shield/src/main/java/org/elasticsearch/shield/authz/indicesresolver/DefaultIndicesAndAliasesResolver.java index 4f75273f456..dddd2b3fe29 100644 --- a/shield/src/main/java/org/elasticsearch/shield/authz/indicesresolver/DefaultIndicesAndAliasesResolver.java +++ b/shield/src/main/java/org/elasticsearch/shield/authz/indicesresolver/DefaultIndicesAndAliasesResolver.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.shield.authz.indicesresolver; -import com.google.common.collect.Sets; import org.elasticsearch.action.AliasesRequest; import org.elasticsearch.action.CompositeIndicesRequest; import org.elasticsearch.action.IndicesRequest; @@ -15,6 +14,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.regex.Regex; +import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.shield.User; @@ -51,7 +51,7 @@ public class DefaultIndicesAndAliasesResolver implements IndicesAndAliasesResolv } if (request instanceof CompositeIndicesRequest) { - Set indices = Sets.newHashSet(); + Set indices = new HashSet<>(); CompositeIndicesRequest compositeIndicesRequest = (CompositeIndicesRequest) request; for (IndicesRequest indicesRequest : compositeIndicesRequest.subRequests()) { indices.addAll(resolveIndicesAndAliases(user, action, indicesRequest, metaData)); diff --git a/shield/src/main/java/org/elasticsearch/shield/crypto/tool/SystemKeyTool.java b/shield/src/main/java/org/elasticsearch/shield/crypto/tool/SystemKeyTool.java index 57973b9acb9..384c5f10bd9 100644 --- a/shield/src/main/java/org/elasticsearch/shield/crypto/tool/SystemKeyTool.java +++ b/shield/src/main/java/org/elasticsearch/shield/crypto/tool/SystemKeyTool.java @@ -5,13 +5,13 @@ */ package org.elasticsearch.shield.crypto.tool; -import com.google.common.collect.Sets; import org.apache.commons.cli.CommandLine; import org.elasticsearch.common.cli.CheckFileCommand; import org.elasticsearch.common.cli.CliTool; import org.elasticsearch.common.cli.CliToolConfig; import org.elasticsearch.common.cli.Terminal; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.env.Environment; import org.elasticsearch.shield.crypto.InternalCryptoService; diff --git a/shield/src/test/java/org/elasticsearch/shield/authz/accesscontrol/IndicesPermissionTests.java b/shield/src/test/java/org/elasticsearch/shield/authz/accesscontrol/IndicesPermissionTests.java index 1fa81913b34..eac8e55d29a 100644 --- a/shield/src/test/java/org/elasticsearch/shield/authz/accesscontrol/IndicesPermissionTests.java +++ b/shield/src/test/java/org/elasticsearch/shield/authz/accesscontrol/IndicesPermissionTests.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.shield.authz.accesscontrol; -import com.google.common.collect.Sets; import org.elasticsearch.Version; import org.elasticsearch.action.search.SearchAction; import org.elasticsearch.cluster.metadata.AliasMetaData; @@ -14,6 +13,7 @@ import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.shield.authz.Permission; import org.elasticsearch.shield.authz.Privilege; import org.elasticsearch.test.ESTestCase; diff --git a/shield/src/test/java/org/elasticsearch/shield/support/ShieldFilesTests.java b/shield/src/test/java/org/elasticsearch/shield/support/ShieldFilesTests.java index a8667a81fca..938704f79fa 100644 --- a/shield/src/test/java/org/elasticsearch/shield/support/ShieldFilesTests.java +++ b/shield/src/test/java/org/elasticsearch/shield/support/ShieldFilesTests.java @@ -6,9 +6,9 @@ package org.elasticsearch.shield.support; import com.google.common.base.Charsets; -import com.google.common.collect.Sets; import com.google.common.jimfs.Configuration; import com.google.common.jimfs.Jimfs; +import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.env.Environment; import org.elasticsearch.test.ESTestCase; import org.junit.Test; @@ -22,15 +22,9 @@ import java.nio.file.attribute.PosixFilePermission; import java.util.Locale; import java.util.Set; -import static java.nio.file.attribute.PosixFilePermission.GROUP_EXECUTE; -import static java.nio.file.attribute.PosixFilePermission.OTHERS_EXECUTE; -import static java.nio.file.attribute.PosixFilePermission.OWNER_EXECUTE; -import static java.nio.file.attribute.PosixFilePermission.OWNER_READ; -import static java.nio.file.attribute.PosixFilePermission.OWNER_WRITE; +import static java.nio.file.attribute.PosixFilePermission.*; import static org.elasticsearch.shield.support.ShieldFiles.openAtomicMoveWriter; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.*; public class ShieldFilesTests extends ESTestCase {