From cef0d98c87d5551cc7b3827d106eba2c8eb8fbb5 Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Sat, 14 Sep 2024 14:21:44 +0100 Subject: [PATCH 01/19] OAK-11100: remove use of Guava transform/filter - oak-auth-external --- .../external/impl/DynamicSyncContext.java | 4 +- .../external/impl/jmx/Delegatee.java | 40 ++++++++++--------- .../ExternalGroupPrincipalProvider.java | 11 ++--- .../principal/SyncHandlerMappingTracker.java | 7 ++-- .../external/AbstractExternalAuthTest.java | 5 +-- .../external/impl/AbstractDynamicTest.java | 13 +++--- .../principal/AutoMembershipProviderTest.java | 7 +++- .../principal/ExternalGroupPrincipalTest.java | 9 +++-- 8 files changed, 55 insertions(+), 41 deletions(-) diff --git a/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/DynamicSyncContext.java b/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/DynamicSyncContext.java index 36068ceab6a..b545e71ced2 100644 --- a/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/DynamicSyncContext.java +++ b/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/DynamicSyncContext.java @@ -20,6 +20,7 @@ import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.Group; import org.apache.jackrabbit.api.security.user.UserManager; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityException; @@ -234,7 +235,8 @@ private Map collectSyncEntries(@NotNull Iterable */ private void collectSyncEntries(@NotNull Iterable declaredGroupRefs, long depth, @NotNull Map map) throws ExternalIdentityException, RepositoryException { boolean shortcut = shortcut(depth); - for (ExternalIdentityRef ref : Iterables.filter(declaredGroupRefs, this::isSameIDP)) { + Iterable filtered = () -> CollectionUtils.toStream(declaredGroupRefs).filter(this::isSameIDP).iterator(); + for (ExternalIdentityRef ref : filtered) { String principalName = null; Authorizable a = null; ExternalGroup externalGroup = null; diff --git a/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/jmx/Delegatee.java b/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/jmx/Delegatee.java index cf8157a3bec..b8dad0c7678 100644 --- a/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/jmx/Delegatee.java +++ b/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/jmx/Delegatee.java @@ -23,6 +23,7 @@ import org.apache.jackrabbit.oak.api.ContentRepository; import org.apache.jackrabbit.oak.api.ContentSession; import org.apache.jackrabbit.oak.api.Root; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.plugins.value.jcr.ValueFactoryImpl; import org.apache.jackrabbit.oak.spi.security.SecurityProvider; @@ -54,6 +55,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.Objects; import static java.util.Objects.requireNonNull; @@ -354,25 +356,27 @@ private List commit(@NotNull ResultMessages messages, @NotNull List< @NotNull private Iterator internalListOrphanedIdentities() { - try { - Iterator it = handler.listIdentities(userMgr); - return Iterators.filter(Iterators.transform(it, syncedIdentity -> { - if (syncedIdentity != null && isMyIDP(syncedIdentity)) { - try { - // nonNull-ExternalIdRef has already been asserted by 'isMyIDP' - ExternalIdentity extId = idp.getIdentity(requireNonNull(syncedIdentity.getExternalIdRef())); - if (extId == null) { - return syncedIdentity.getId(); - } - } catch (ExternalIdentityException e) { - log.error("Error while fetching external identity {}", syncedIdentity, e); + Iterable it = () -> { + try { + return handler.listIdentities(userMgr); + } catch (RepositoryException e) { + log.error("Error while listing orphaned users", e); + return Collections.emptyIterator(); + } + }; + return CollectionUtils.toStream(it).map(syncedIdentity -> { + if (syncedIdentity != null && isMyIDP(syncedIdentity)) { + try { + // nonNull-ExternalIdRef has already been asserted by 'isMyIDP' + ExternalIdentity extId = idp.getIdentity(requireNonNull(syncedIdentity.getExternalIdRef())); + if (extId == null) { + return syncedIdentity.getId(); } + } catch (ExternalIdentityException e) { + log.error("Error while fetching external identity {}", syncedIdentity, e); } - return null; - }), x -> x != null); - } catch (RepositoryException e) { - log.error("Error while listing orphaned users", e); - return Collections.emptyIterator(); - } + } + return null; + }).filter(Objects::nonNull).iterator(); } } diff --git a/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalGroupPrincipalProvider.java b/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalGroupPrincipalProvider.java index d232ea89a29..7c98b4bb34a 100644 --- a/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalGroupPrincipalProvider.java +++ b/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalGroupPrincipalProvider.java @@ -19,7 +19,6 @@ import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Iterators; -import org.apache.jackrabbit.guava.common.collect.Sets; import org.apache.jackrabbit.api.security.principal.GroupPrincipal; import org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal; import org.apache.jackrabbit.api.security.principal.PrincipalManager; @@ -35,6 +34,7 @@ import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.api.Type; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.plugins.memory.PropertyValues; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef; @@ -213,7 +213,7 @@ public Iterator findPrincipals(@Nullable String nameHint, i // search for external group principals that have not been synchronzied into the repository Result result = findPrincipals(Objects.toString(nameHint, ""), false); if (result != null) { - return Iterators.filter(new GroupPrincipalIterator(nameHint, result), Objects::nonNull); + return CollectionUtils.toStream(new GroupPrincipalIterator(nameHint, result)).filter(Objects::nonNull).iterator(); } else { return Collections.emptyIterator(); } @@ -305,7 +305,7 @@ public boolean isMember(@NotNull Group group, @NotNull Authorizable authorizable } Set valueSet = ImmutableSet.copyOf(vs); - Iterator declared = Iterators.filter(Iterators.transform(valueSet.iterator(), value -> { + Iterator declared = valueSet.stream().map(value -> { try { String groupPrincipalName = value.getString(); Authorizable gr = userManager.getAuthorizable(new PrincipalImpl(groupPrincipalName)); @@ -313,7 +313,7 @@ public boolean isMember(@NotNull Group group, @NotNull Authorizable authorizable } catch (RepositoryException e) { return null; } - }), Objects::nonNull); + }).filter(Objects::nonNull).iterator(); if (includeInherited) { // retrieve groups inherited from dynamic groups through cross-IDP membership return new InheritedMembershipIterator(declared); @@ -640,7 +640,8 @@ private GroupPrincipalIterator(@Nullable String queryString, @NotNull Result que if (!propValues.hasNext()) { if (rows.hasNext()) { ResultRow row = rows.next(); - propValues = Iterators.filter(row.getValue(REP_EXTERNAL_PRINCIPAL_NAMES).getValue(Type.STRINGS).iterator(), Objects::nonNull); + propValues = CollectionUtils.toStream(row.getValue(REP_EXTERNAL_PRINCIPAL_NAMES).getValue(Type.STRINGS)) + .filter(Objects::nonNull).iterator(); idpName = getIdpName(row); } else { propValues = Collections.emptyIterator(); diff --git a/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SyncHandlerMappingTracker.java b/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SyncHandlerMappingTracker.java index 664a6dff6d9..91acb416d84 100644 --- a/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SyncHandlerMappingTracker.java +++ b/oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/SyncHandlerMappingTracker.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.oak.commons.PropertiesUtil; import org.apache.jackrabbit.oak.spi.security.authentication.external.SyncHandler; import org.apache.jackrabbit.oak.spi.security.authentication.external.impl.SyncHandlerMapping; @@ -29,6 +28,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.Objects; import static org.apache.jackrabbit.oak.spi.security.authentication.external.impl.SyncHandlerMapping.PARAM_IDP_NAME; import static org.apache.jackrabbit.oak.spi.security.authentication.external.impl.SyncHandlerMapping.PARAM_SYNC_HANDLER_NAME; @@ -77,14 +77,13 @@ private void addMapping(ServiceReference reference) { } Iterable getIdpNames(@NotNull final String syncHandlerName) { - return Iterables.filter(Iterables.transform(referenceMap.values(), mapping -> { + return () -> referenceMap.values().stream().map(mapping -> { if (syncHandlerName.equals(mapping.syncHandlerName)) { return mapping.idpName; } else { // different synchandler name return null; - } - }), x -> x != null); + }}).filter(Objects::nonNull).iterator(); } private static final class Mapping { diff --git a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/AbstractExternalAuthTest.java b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/AbstractExternalAuthTest.java index f697f4a17ab..a47df089422 100644 --- a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/AbstractExternalAuthTest.java +++ b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/AbstractExternalAuthTest.java @@ -17,7 +17,6 @@ package org.apache.jackrabbit.oak.spi.security.authentication.external; import org.apache.jackrabbit.guava.common.collect.ImmutableMap; -import org.apache.jackrabbit.guava.common.collect.Iterators; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.User; import org.apache.jackrabbit.api.security.user.UserManager; @@ -136,7 +135,7 @@ protected static void assertException(@NotNull CommitFailedException e, @NotNull @NotNull private static Iterator getAllAuthorizableIds(@NotNull UserManager userManager) throws Exception { Iterator iter = userManager.findAuthorizables("jcr:primaryType", null); - return Iterators.filter(Iterators.transform(iter, input -> { + return CollectionUtils.toStream(iter).map(input -> { try { if (input != null) { return input.getID(); @@ -145,7 +144,7 @@ private static Iterator getAllAuthorizableIds(@NotNull UserManager userM // failed to retrieve ID } return null; - }), Objects::nonNull); + }).filter(Objects::nonNull).iterator(); } @Override diff --git a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/AbstractDynamicTest.java b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/AbstractDynamicTest.java index 41909166559..192efd65350 100644 --- a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/AbstractDynamicTest.java +++ b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/AbstractDynamicTest.java @@ -16,12 +16,11 @@ */ package org.apache.jackrabbit.oak.spi.security.authentication.external.impl; -import org.apache.jackrabbit.guava.common.collect.ImmutableList; import org.apache.jackrabbit.guava.common.collect.Iterables; -import org.apache.jackrabbit.guava.common.collect.Iterators; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.UserManager; import org.apache.jackrabbit.oak.api.Root; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser; @@ -34,8 +33,10 @@ import javax.jcr.RepositoryException; import javax.jcr.ValueFactory; import java.security.Principal; +import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.stream.Collectors; import static org.junit.Assert.assertSame; @@ -116,17 +117,19 @@ protected void sync(@NotNull ExternalIdentity externalIdentity, @NotNull SyncRes @NotNull static List getIds(@NotNull Iterator authorizables) { - return ImmutableList.copyOf(Iterators.transform(authorizables, authorizable -> { + return Collections.unmodifiableList( + CollectionUtils.toStream(authorizables).map(authorizable -> { try { return authorizable.getID(); } catch (RepositoryException repositoryException) { throw new RuntimeException(); } - })); + }).collect(Collectors.toList())); } @NotNull static List getPrincipalNames(@NotNull Iterator groupPrincipals) { - return ImmutableList.copyOf(Iterators.transform(groupPrincipals, Principal::getName)); + return Collections + .unmodifiableList(CollectionUtils.toStream(groupPrincipals).map(Principal::getName).collect(Collectors.toList())); } } \ No newline at end of file diff --git a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/AutoMembershipProviderTest.java b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/AutoMembershipProviderTest.java index 2590fbb4f80..2382c503b79 100644 --- a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/AutoMembershipProviderTest.java +++ b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/AutoMembershipProviderTest.java @@ -26,6 +26,7 @@ import org.apache.jackrabbit.api.security.user.UserManager; import org.apache.jackrabbit.oak.api.QueryEngine; import org.apache.jackrabbit.oak.api.Root; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef; import org.apache.jackrabbit.oak.spi.security.authentication.external.basic.DefaultSyncConfig; import org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal; @@ -38,9 +39,11 @@ import javax.jcr.RepositoryException; import java.text.ParseException; import java.util.Collection; +import java.util.Collections; import java.util.Iterator; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import static org.apache.jackrabbit.oak.spi.security.authentication.external.impl.ExternalIdentityConstants.REP_EXTERNAL_ID; import static org.junit.Assert.assertEquals; @@ -108,13 +111,13 @@ private AutoMembershipProvider createAutoMembershipProvider(@NotNull Root root, } private static void assertMatchingEntries(@NotNull Iterator it, @NotNull String... expectedIds) { - Set ids = ImmutableSet.copyOf(Iterators.transform(it, authorizable -> { + Set ids = Collections.unmodifiableSet(CollectionUtils.toStream(it).map(authorizable -> { try { return authorizable.getID(); } catch (RepositoryException repositoryException) { return ""; } - })); + }).collect(Collectors.toSet())); assertEquals(ImmutableSet.copyOf(expectedIds), ids); } diff --git a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalGroupPrincipalTest.java b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalGroupPrincipalTest.java index e9571c7efaf..7bc106c7419 100644 --- a/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalGroupPrincipalTest.java +++ b/oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/principal/ExternalGroupPrincipalTest.java @@ -17,8 +17,6 @@ package org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableMap; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.api.security.principal.GroupPrincipal; import org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal; import org.apache.jackrabbit.api.security.user.Authorizable; @@ -27,6 +25,8 @@ import org.apache.jackrabbit.oak.api.QueryEngine; import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.api.Type; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; +import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser; @@ -40,6 +40,7 @@ import java.text.ParseException; import java.util.Enumeration; import java.util.Map; +import java.util.stream.Stream; import static org.apache.jackrabbit.oak.spi.security.authentication.external.TestIdentityProvider.ID_SECOND_USER; import static org.apache.jackrabbit.oak.spi.security.authentication.external.impl.ExternalIdentityConstants.REP_EXTERNAL_PRINCIPAL_NAMES; @@ -81,7 +82,9 @@ public void testNotIsMember() throws Exception { public void testIsMemberExternalGroup() throws Exception { GroupPrincipal principal = getGroupPrincipal(); - Iterable exGroupPrincNames = Iterables.transform(ImmutableList.copyOf(idp.listGroups()), ExternalIdentity::getPrincipalName); + Stream s = CollectionUtils.toStream(idp.listGroups()); + Iterable exGroupPrincNames = () -> s.map(ExternalIdentity::getPrincipalName).iterator(); + for (String principalName : exGroupPrincNames) { assertFalse(principal.isMember(new PrincipalImpl(principalName))); } From 4a0c445426deb036bc8dab83df5c20d7dec7725c Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Sat, 14 Sep 2024 15:59:50 +0100 Subject: [PATCH 02/19] OAK-11100: remove use of Guava transform/filter - oak-auth-ldap --- .../ldap/impl/LdapIdentityProviderTest.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapIdentityProviderTest.java b/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapIdentityProviderTest.java index 749de755083..f0cecde4f6e 100644 --- a/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapIdentityProviderTest.java +++ b/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/impl/LdapIdentityProviderTest.java @@ -14,13 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.jackrabbit.oak.security.authentication.ldap.impl; import org.apache.jackrabbit.guava.common.collect.ImmutableSet; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Iterators; import org.apache.directory.api.util.Strings; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityException; @@ -200,7 +199,8 @@ public void testGetDeclaredMembersByRef() throws Exception { public void testGetDeclaredMembers() throws Exception { ExternalGroup gr = idp.getGroup(TEST_GROUP1_NAME); Iterable memberrefs = gr.getDeclaredMembers(); - Iterable memberIds = Iterables.transform(memberrefs, externalIdentityRef -> externalIdentityRef.getId()); + Iterable memberIds = () -> CollectionUtils.toStream(memberrefs) + .map(externalIdentityRef -> externalIdentityRef.getId()).iterator(); Set expected = ImmutableSet.copyOf(TEST_GROUP1_MEMBERS); assertEquals(expected, ImmutableSet.copyOf(memberIds)); @@ -212,7 +212,7 @@ public void testGetDeclaredMembersInvalidMemberAttribute() throws Exception { ExternalGroup gr = idp.getGroup(TEST_GROUP1_NAME); Iterable memberrefs = gr.getDeclaredMembers(); - assertTrue(Iterables.isEmpty(memberrefs)); + assertTrue(!memberrefs.iterator().hasNext()); } @Test @@ -237,7 +237,8 @@ public void testGetDeclaredGroupMissingIdAttribute() throws Exception { ExternalUser user = idp.getUser(TEST_USER1_UID); Iterable groupRefs = user.getDeclaredGroups(); - Iterable groupIds = Iterables.transform(groupRefs, externalIdentityRef -> externalIdentityRef.getId()); + Iterable groupIds = () -> CollectionUtils.toStream(groupRefs) + .map(externalIdentityRef -> externalIdentityRef.getId()).iterator(); assertEquals(ImmutableSet.copyOf(TEST_USER1_GROUPS), ImmutableSet.copyOf(groupIds)); } From 340990f881800cc5e3df3c04c6afb09972c77611 Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Sat, 14 Sep 2024 17:29:07 +0100 Subject: [PATCH 03/19] OAK-11100: remove use of Guava transform/filter - oak-authorization-cug --- .../cug/impl/CugAccessControlManager.java | 2 +- .../authorization/cug/impl/CugImportBaseTest.java | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/oak-authorization-cug/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugAccessControlManager.java b/oak-authorization-cug/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugAccessControlManager.java index 0fd6220e027..45ffbce30e3 100644 --- a/oak-authorization-cug/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugAccessControlManager.java +++ b/oak-authorization-cug/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugAccessControlManager.java @@ -229,7 +229,7 @@ public AccessControlPolicy[] getEffectivePolicies(@NotNull Set princi return new AccessControlPolicy[0]; } Root r = getLatestRoot(); - Set candidates = collectEffectiveCandidates(r, Iterables.transform(principals, Principal::getName)); + Set candidates = collectEffectiveCandidates(r, () -> principals.stream().map(Principal::getName).iterator()); if (candidates.isEmpty()) { return new AccessControlPolicy[0]; } else { diff --git a/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugImportBaseTest.java b/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugImportBaseTest.java index 0c217d95387..445ff53043f 100644 --- a/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugImportBaseTest.java +++ b/oak-authorization-cug/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/cug/impl/CugImportBaseTest.java @@ -18,7 +18,11 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; +import java.util.Arrays; +import java.util.Collections; import java.util.Set; +import java.util.stream.Collectors; + import javax.jcr.ImportUUIDBehavior; import javax.jcr.Node; import javax.jcr.Property; @@ -31,8 +35,6 @@ import javax.jcr.nodetype.ConstraintViolationException; import javax.jcr.security.AccessControlException; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.api.JackrabbitRepository; import org.apache.jackrabbit.api.JackrabbitSession; import org.apache.jackrabbit.api.security.user.Group; @@ -191,13 +193,13 @@ private void doImport(Session importSession, String parentPath, String xml) thro static void assertPrincipalNames(@NotNull Set expectedPrincipalNames, @NotNull Value[] principalNames) { assertEquals(expectedPrincipalNames.size(), principalNames.length); - Set result = ImmutableSet.copyOf(Iterables.transform(ImmutableSet.copyOf(principalNames), principalName -> { + Set result = Collections.unmodifiableSet(Arrays.asList(principalNames).stream().map(principalName -> { try { return principalName.getString(); } catch (RepositoryException e) { throw new IllegalStateException(e); } - })); + }).collect(Collectors.toSet())); assertEquals(expectedPrincipalNames, result); } From 38aaec27a74b2c4252d3cf5388c2335285b5fec2 Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Sat, 14 Sep 2024 19:34:17 +0100 Subject: [PATCH 04/19] OAK-11100: remove use of Guava transform/filter - oak-authorization-principalbased --- .../impl/PrincipalBasedAccessControlManager.java | 7 ++++++- .../PrincipalBasedAuthorizationConfiguration.java | 3 +-- .../impl/PrincipalPolicyImporter.java | 2 +- .../impl/AbstractPrincipalBasedTest.java | 8 +++----- .../principalbased/impl/EffectivePolicyTest.java | 13 +++++++------ .../impl/PrincipalPolicyImplTest.java | 3 +-- .../impl/ReadablePathsAccessControlTest.java | 6 +++--- .../impl/ReadablePathsPermissionTest.java | 5 ++--- 8 files changed, 24 insertions(+), 23 deletions(-) diff --git a/oak-authorization-principalbased/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalBasedAccessControlManager.java b/oak-authorization-principalbased/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalBasedAccessControlManager.java index cf08d170278..d5f8d8d65cb 100644 --- a/oak-authorization-principalbased/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalBasedAccessControlManager.java +++ b/oak-authorization-principalbased/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalBasedAccessControlManager.java @@ -231,7 +231,12 @@ public AccessControlPolicy[] getEffectivePolicies(String absPath) throws Reposit entries.add(entry); } } - Iterable acls = Iterables.transform(m.entrySet(), entry -> new ImmutablePrincipalPolicy(entry.getKey(), filter.getOakPath(entry.getKey()), entry.getValue(), mgrProvider.getRestrictionProvider(), getNamePathMapper())); + + Iterable acls = () -> m.entrySet().stream() + .map(entry -> (PrincipalAccessControlList) new ImmutablePrincipalPolicy(entry.getKey(), + filter.getOakPath(entry.getKey()), entry.getValue(), mgrProvider.getRestrictionProvider(), + getNamePathMapper())) + .iterator(); if (ReadPolicy.hasEffectiveReadPolicy(readPaths, oakPath)) { Iterable iterable = Iterables.concat(acls, Collections.singleton(ReadPolicy.INSTANCE)); diff --git a/oak-authorization-principalbased/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalBasedAuthorizationConfiguration.java b/oak-authorization-principalbased/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalBasedAuthorizationConfiguration.java index a9b24c3472b..a0cb21fd393 100644 --- a/oak-authorization-principalbased/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalBasedAuthorizationConfiguration.java +++ b/oak-authorization-principalbased/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalBasedAuthorizationConfiguration.java @@ -17,7 +17,6 @@ package org.apache.jackrabbit.oak.spi.security.authorization.principalbased.impl; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.namepath.NamePathMapper; @@ -129,7 +128,7 @@ public PermissionProvider getPermissionProvider(@NotNull Root root, @NotNull Str if (!f.canHandle(principals)) { return EmptyPermissionProvider.getInstance(); } else { - Iterable principalPaths = Iterables.transform(principals, f::getOakPath); + Iterable principalPaths = () -> principals.stream().map(f::getOakPath).iterator(); return new PrincipalBasedPermissionProvider(root, workspaceName, principalPaths, this); } } diff --git a/oak-authorization-principalbased/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalPolicyImporter.java b/oak-authorization-principalbased/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalPolicyImporter.java index 952d5848e66..33b806a6ecd 100644 --- a/oak-authorization-principalbased/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalPolicyImporter.java +++ b/oak-authorization-principalbased/src/main/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalPolicyImporter.java @@ -249,7 +249,7 @@ private Entry(@NotNull List propInfos) throws RepositoryException { if (REP_EFFECTIVE_PATH.equals(oakName) && PropertyType.PATH == prop.getType()) { effectivePath = extractEffectivePath(prop); } else if (REP_PRIVILEGES.equals(oakName) && PropertyType.NAME == prop.getType()) { - privs = getPrivileges(Iterables.transform(prop.getTextValues(), TextValue::getString)); + privs = getPrivileges(() -> prop.getTextValues().stream().map(TextValue::getString).iterator()); } else { throw new ConstraintViolationException("Unsupported property '"+oakName+"' with type "+prop.getType()+" within policy entry of type rep:PrincipalEntry"); } diff --git a/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/AbstractPrincipalBasedTest.java b/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/AbstractPrincipalBasedTest.java index 0dfd0ba5ed8..ad52aeabbde 100644 --- a/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/AbstractPrincipalBasedTest.java +++ b/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/AbstractPrincipalBasedTest.java @@ -18,7 +18,6 @@ import org.apache.jackrabbit.guava.common.collect.ImmutableMap; import org.apache.jackrabbit.guava.common.collect.ImmutableSet; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.ObjectArrays; import org.apache.jackrabbit.api.security.JackrabbitAccessControlList; import org.apache.jackrabbit.api.security.JackrabbitAccessControlManager; @@ -50,7 +49,7 @@ import javax.jcr.security.AccessControlPolicy; import javax.jcr.security.Privilege; import java.security.Principal; -import java.util.Collections; +import java.util.Arrays; import java.util.Map; import java.util.UUID; @@ -58,8 +57,6 @@ import static org.apache.jackrabbit.oak.spi.nodetype.NodeTypeConstants.NT_OAK_UNSTRUCTURED; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; public abstract class AbstractPrincipalBasedTest extends AbstractSecurityTest { @@ -115,7 +112,8 @@ protected SecurityProvider initSecurityProvider() { @Override @NotNull protected Privilege[] privilegesFromNames(@NotNull String... privilegeNames) throws RepositoryException { - Iterable pn = Iterables.transform(ImmutableSet.copyOf(privilegeNames), privName -> getNamePathMapper().getJcrName(privName)); + Iterable pn = () -> Arrays.asList(privilegeNames).stream().map(privName -> getNamePathMapper().getJcrName(privName)) + .iterator(); return super.privilegesFromNames(pn); } diff --git a/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/EffectivePolicyTest.java b/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/EffectivePolicyTest.java index d59cbd70332..95330f1512b 100644 --- a/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/EffectivePolicyTest.java +++ b/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/EffectivePolicyTest.java @@ -17,8 +17,6 @@ package org.apache.jackrabbit.oak.spi.security.authorization.principalbased.impl; import org.apache.jackrabbit.guava.common.collect.ImmutableMap; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry; import org.apache.jackrabbit.api.security.authorization.PrincipalAccessControlList; @@ -34,9 +32,11 @@ import javax.jcr.Value; import javax.jcr.security.AccessControlPolicy; import java.security.Principal; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import static org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.AccessControlConstants.REP_GLOB; import static org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.AccessControlConstants.REP_NT_NAMES; @@ -139,10 +139,11 @@ public void testEffectivePolicyByPath() throws Exception { // filter expected entries: only entries that take effect at the target path should be taken into consideration ImmutablePrincipalPolicy byPrincipal = (ImmutablePrincipalPolicy) acMgr.getEffectivePolicies(Set.of(effectivePolicy.getPrincipal()))[0]; - Set expected = ImmutableSet.copyOf(Iterables.filter(byPrincipal.getEntries(), entry -> { - String effectivePath = ((PrincipalAccessControlList.Entry) entry).getEffectivePath(); - return effectivePath != null && Text.isDescendantOrEqual(effectivePath, path); - })); + Set expected = Collections + .unmodifiableSet(byPrincipal.getEntries().stream().filter(entry -> { + String effectivePath = ((PrincipalAccessControlList.Entry) entry).getEffectivePath(); + return effectivePath != null && Text.isDescendantOrEqual(effectivePath, path); + }).collect(Collectors.toSet())); assertEquals(expected.size(), effectivePolicy.size()); List entries = effectivePolicy.getEntries(); diff --git a/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalPolicyImplTest.java b/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalPolicyImplTest.java index 1b4cf080e6a..7fcd36511f3 100644 --- a/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalPolicyImplTest.java +++ b/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/PrincipalPolicyImplTest.java @@ -18,7 +18,6 @@ import org.apache.jackrabbit.guava.common.collect.ImmutableList; import org.apache.jackrabbit.guava.common.collect.ImmutableMap; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.api.security.authorization.PrincipalAccessControlList; import org.apache.jackrabbit.api.security.authorization.PrivilegeCollection; import org.apache.jackrabbit.api.security.authorization.PrivilegeManager; @@ -122,7 +121,7 @@ private Tree createEntryTree(@NotNull PrincipalPolicyImpl.EntryImpl entry) { PropertyState privs = PropertyStates.createProperty(REP_PRIVILEGES, privilegeBitsProvider.getPrivilegeNames(entry.getPrivilegeBits()), Type.NAMES); when(t.getProperty(REP_PRIVILEGES)).thenReturn(privs); - Iterable props = Iterables.transform(entry.getRestrictions(), Restriction::getProperty); + Iterable props = () -> entry.getRestrictions().stream().map(Restriction::getProperty).iterator(); Tree rTree = mock(Tree.class); if (props.iterator().hasNext()) { when(rTree.exists()).thenReturn(true); diff --git a/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/ReadablePathsAccessControlTest.java b/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/ReadablePathsAccessControlTest.java index 68b68cd4728..6fbbf13af39 100644 --- a/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/ReadablePathsAccessControlTest.java +++ b/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/ReadablePathsAccessControlTest.java @@ -17,7 +17,6 @@ package org.apache.jackrabbit.oak.spi.security.authorization.principalbased.impl; import org.apache.jackrabbit.guava.common.collect.ImmutableSet; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Iterators; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.api.security.JackrabbitAccessControlManager; @@ -42,6 +41,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; +import java.util.stream.Collectors; import static org.apache.jackrabbit.oak.commons.PathUtils.ROOT_PATH; import static org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants.JCR_READ; @@ -70,10 +70,10 @@ public void before() throws Exception { Set paths = getConfig(AuthorizationConfiguration.class).getParameters().getConfigValue(PermissionConstants.PARAM_READ_PATHS, PermissionConstants.DEFAULT_READ_PATHS); assertFalse(paths.isEmpty()); - readablePaths = Iterators.cycle(Iterables.transform(paths, f -> getNamePathMapper().getJcrPath(f))); + readablePaths = Iterators.cycle(paths.stream().map(f -> getNamePathMapper().getJcrPath(f)).collect(Collectors.toList())); Set childPaths = new HashSet<>(); for (String path : paths) { - Iterables.addAll(childPaths, Iterables.transform(root.getTree(path).getChildren(), tree -> getNamePathMapper().getJcrPath(tree.getPath()))); + CollectionUtils.toStream(root.getTree(path).getChildren()).map(tree -> getNamePathMapper().getJcrPath(tree.getPath())).forEach(childPaths::add); } readableChildPaths = Iterators.cycle(childPaths); } diff --git a/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/ReadablePathsPermissionTest.java b/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/ReadablePathsPermissionTest.java index 0eb7cb3a1b5..c4236e0a5f0 100644 --- a/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/ReadablePathsPermissionTest.java +++ b/oak-authorization-principalbased/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/principalbased/impl/ReadablePathsPermissionTest.java @@ -16,11 +16,10 @@ */ package org.apache.jackrabbit.oak.spi.security.authorization.principalbased.impl; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Iterators; -import org.apache.jackrabbit.guava.common.collect.Sets; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.tree.TreeLocation; import org.apache.jackrabbit.oak.spi.namespace.NamespaceConstants; import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters; @@ -65,7 +64,7 @@ public void before() throws Exception { readablePaths = Iterators.cycle(paths); Set childPaths = new HashSet<>(); for (String path : paths) { - Iterables.addAll(childPaths, Iterables.transform(root.getTree(path).getChildren(), Tree::getPath)); + CollectionUtils.toStream(root.getTree(path).getChildren()).map(Tree::getPath).forEach(childPaths::add); } readableChildPaths = Iterators.cycle(childPaths); From e6a9e623891554fe89dc1ea4d40152fd15f3fbf6 Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Sun, 15 Sep 2024 12:54:58 +0100 Subject: [PATCH 05/19] OAK-11100: remove use of Guava transform/filter - oak-blob-cloud --- .../org/apache/jackrabbit/oak/blob/cloud/s3/S3Backend.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/oak-blob-cloud/src/main/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3Backend.java b/oak-blob-cloud/src/main/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3Backend.java index 2f34b5ea5cf..d697a3fe982 100644 --- a/oak-blob-cloud/src/main/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3Backend.java +++ b/oak-blob-cloud/src/main/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3Backend.java @@ -38,6 +38,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.function.Function; +import java.util.stream.Collectors; import com.amazonaws.services.s3.model.GetObjectMetadataRequest; import com.amazonaws.services.s3.model.GetObjectRequest; @@ -98,7 +99,6 @@ import org.apache.jackrabbit.guava.common.collect.Maps; import static org.apache.jackrabbit.guava.common.base.Preconditions.checkArgument; -import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; import static java.lang.Thread.currentThread; /** @@ -1098,9 +1098,8 @@ private boolean loadBatch() { return false; } - List listing = Lists.newArrayList( - filter(prevObjectListing.getObjectSummaries(), - input -> !input.getKey().startsWith(META_KEY_PREFIX))); + List listing = prevObjectListing.getObjectSummaries().stream() + .filter(input -> !input.getKey().startsWith(META_KEY_PREFIX)).collect(Collectors.toList()); // After filtering no elements if (listing.isEmpty()) { From f0dfd55672bf215e7b987af1f7c6ea8fdfc7c9b7 Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Mon, 16 Sep 2024 08:10:49 +0100 Subject: [PATCH 06/19] OAK-11100: remove use of Guava transform/filter - oak-blob-plugins --- .../oak/plugins/blob/datastore/BlobIdTracker.java | 9 ++++----- .../oak/plugins/blob/SharedDataStoreUtilsTest.java | 10 +++++----- .../plugins/blob/datastore/DataStoreBlobStoreTest.java | 7 ++----- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/oak-blob-plugins/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/BlobIdTracker.java b/oak-blob-plugins/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/BlobIdTracker.java index bba731b6abe..557eca8f6af 100644 --- a/oak-blob-plugins/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/BlobIdTracker.java +++ b/oak-blob-plugins/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/BlobIdTracker.java @@ -30,6 +30,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; import java.util.function.Predicate; +import java.util.stream.Collectors; import org.apache.jackrabbit.guava.common.base.Stopwatch; import org.apache.jackrabbit.guava.common.collect.Lists; @@ -45,8 +46,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; -import static org.apache.jackrabbit.guava.common.collect.Lists.newArrayList; import static org.apache.jackrabbit.guava.common.io.Files.move; import static org.apache.jackrabbit.guava.common.io.Files.newWriter; import static java.io.File.createTempFile; @@ -264,10 +263,10 @@ private void globalMerge() throws IOException { Stopwatch watch = Stopwatch.createStarted(); LOG.trace("Retrieving all blob id files available form the DataStore"); // Download all the blob reference records from the data store - Iterable refRecords = datastore.getAllMetadataRecords(fileNamePrefix); + List refRecords = datastore.getAllMetadataRecords(fileNamePrefix); // Download all the corresponding files for the records - List refFiles = newArrayList(transform(refRecords, input -> { + List refFiles = refRecords.stream().map(input -> { InputStream inputStream = null; try { inputStream = input.getStream(); @@ -278,7 +277,7 @@ private void globalMerge() throws IOException { closeQuietly(inputStream); } return null; - })); + }).collect(Collectors.toList()); LOG.info("Retrieved all blob id files in [{}]", watch.elapsed(TimeUnit.MILLISECONDS)); // Merge all the downloaded files in to the local store diff --git a/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/SharedDataStoreUtilsTest.java b/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/SharedDataStoreUtilsTest.java index 91d24963295..d014b39e366 100644 --- a/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/SharedDataStoreUtilsTest.java +++ b/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/SharedDataStoreUtilsTest.java @@ -31,8 +31,8 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Lists; import org.apache.jackrabbit.guava.common.collect.Maps; import org.apache.commons.io.FileUtils; @@ -473,8 +473,8 @@ public void testGetAllRecords() throws Exception { added.add(rec); } - Set retrieved = CollectionUtils.toSet(Iterables.transform(CollectionUtils.toSet(dataStore.getAllRecords()), - input -> input.getIdentifier().toString())); + Set retrieved = CollectionUtils.toStream(dataStore.getAllRecords()).map(input -> input.getIdentifier().toString()) + .collect(Collectors.toSet()); assertEquals(added, retrieved); } @@ -504,8 +504,8 @@ public void testGetAllRecordsWithMeta() throws Exception { added.add(rec); } - Set retrieved = CollectionUtils.toSet(Iterables.transform(CollectionUtils.toSet(dataStore.getAllRecords()), - input -> input.getIdentifier().toString())); + Set retrieved = CollectionUtils.toStream(dataStore.getAllRecords()).map(input -> input.getIdentifier().toString()) + .collect(Collectors.toSet()); assertEquals(added, retrieved); } diff --git a/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreBlobStoreTest.java b/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreBlobStoreTest.java index 258f85a0898..ada9a4540db 100644 --- a/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreBlobStoreTest.java +++ b/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreBlobStoreTest.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.jackrabbit.oak.plugins.blob.datastore; import java.io.ByteArrayInputStream; @@ -28,10 +27,9 @@ import java.util.Random; import java.util.Set; import java.util.UUID; +import java.util.stream.Collectors; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.Iterables; -import org.apache.jackrabbit.guava.common.collect.Lists; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.jackrabbit.core.data.DataIdentifier; @@ -171,8 +169,7 @@ public void testGetAllChunks() throws Exception{ DataIdentifier d20 = new DataIdentifier("d-20"); DataIdentifier d30 = new DataIdentifier("d-30"); List dis = ImmutableList.of(d10, d20, d30); - List recs = Lists.newArrayList( - Iterables.transform(dis, input -> new TimeDataRecord(input))); + List recs = dis.stream().map(input -> new TimeDataRecord(input)).collect(Collectors.toList()); OakFileDataStore mockedDS = mock(OakFileDataStore.class); when(mockedDS.getAllRecords()).thenReturn(recs.iterator()); when(mockedDS.getRecord(new DataIdentifier("d-10"))).thenReturn(new TimeDataRecord(d10)); From c78df7d5f1c4c472b28224e8c59cb8e2b4db318b Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Mon, 16 Sep 2024 10:14:41 +0100 Subject: [PATCH 07/19] OAK-11100: remove use of Guava transform/filter - oak-commons --- .../apache/jackrabbit/oak/commons/sort/ExternalSortTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/sort/ExternalSortTest.java b/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/sort/ExternalSortTest.java index 47530a471bb..97b06ddeaa4 100644 --- a/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/sort/ExternalSortTest.java +++ b/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/sort/ExternalSortTest.java @@ -18,7 +18,6 @@ import net.jpountz.lz4.LZ4FrameInputStream; import net.jpountz.lz4.LZ4FrameOutputStream; -import org.apache.jackrabbit.guava.common.base.Joiner; import org.apache.jackrabbit.guava.common.io.Files; import org.apache.jackrabbit.guava.common.primitives.Ints; import org.apache.jackrabbit.oak.commons.Compression; @@ -49,8 +48,8 @@ import java.util.List; import java.util.function.Function; import java.util.function.Predicate; +import java.util.stream.Collectors; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -488,7 +487,7 @@ public void customType() throws Exception { Function stringToType = line -> line != null ? new TestLine(line) : null; Function typeToString = tl -> tl != null ? tl.line : null; - String testData = Joiner.on('\n').join(transform(testLines, tl -> tl.line)); + String testData = testLines.stream().map(tl -> tl.line).collect(Collectors.joining("\n")); File testFile = folder.newFile(); try (BufferedWriter bufferedWriter = Files.newWriter(testFile, charset)) { bufferedWriter.write(testData); From b512c559010d673f9cf56bb443b5b89a0db492b3 Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Mon, 16 Sep 2024 14:30:51 +0100 Subject: [PATCH 08/19] OAK-11100: remove use of Guava transform/filter - oak-core-spi --- .../java/org/apache/jackrabbit/oak/spi/mount/MountInfo.java | 5 +++-- .../jackrabbit/oak/spi/whiteboard/WhiteboardUtils.java | 5 ++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/mount/MountInfo.java b/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/mount/MountInfo.java index 6f8af9d0c87..477935e341b 100644 --- a/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/mount/MountInfo.java +++ b/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/mount/MountInfo.java @@ -27,11 +27,12 @@ import java.util.Set; import java.util.TreeSet; import java.util.function.Function; +import java.util.stream.Collectors; import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import static java.util.Objects.requireNonNull; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; + import static org.apache.jackrabbit.guava.common.collect.Sets.newTreeSet; import static org.apache.jackrabbit.oak.commons.PathUtils.getParentPath; import static org.apache.jackrabbit.oak.commons.PathUtils.isAncestor; @@ -140,7 +141,7 @@ public String getPathFragmentName() { private static TreeSet cleanCopy(Collection includedPaths) { // ensure that paths don't have trailing slashes - this triggers an assertion in PathUtils isAncestor - return newTreeSet(transform(includedPaths, SANITIZE_PATH::apply)); + return newTreeSet(includedPaths.stream().map(SANITIZE_PATH).collect(Collectors.toList())); } public Set getPathsSupportingFragments() { diff --git a/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/whiteboard/WhiteboardUtils.java b/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/whiteboard/WhiteboardUtils.java index 1e8b8bb3c4e..5b49d7ec34e 100644 --- a/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/whiteboard/WhiteboardUtils.java +++ b/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/whiteboard/WhiteboardUtils.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; import java.util.function.Predicate; +import java.util.stream.Collectors; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; @@ -29,9 +30,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.apache.jackrabbit.guava.common.collect.ImmutableList; import org.apache.jackrabbit.guava.common.collect.ImmutableMap; -import org.apache.jackrabbit.guava.common.collect.Iterables; import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.ScheduleExecutionInstanceTypes.DEFAULT; import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.ScheduleExecutionInstanceTypes.RUN_ON_LEADER; @@ -162,7 +161,7 @@ public static List getServices(@NotNull Whiteboard wb, @NotNull Class if (predicate == null) { return tracker.getServices(); } else { - return ImmutableList.copyOf(Iterables.filter(tracker.getServices(), (input) -> predicate.test(input))); + return Collections.unmodifiableList(tracker.getServices().stream().filter(predicate).collect(Collectors.toList())); } } finally { tracker.stop(); From 5853b9c6d9a4d8646af2d73115c4abc20db190dc Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Mon, 16 Sep 2024 16:38:20 +0100 Subject: [PATCH 09/19] OAK-11100: remove use of Guava transform/filter - oak-core --- .../java/org/apache/jackrabbit/oak/Oak.java | 6 +++--- .../oak/core/SecureNodeBuilder.java | 16 ++++++-------- .../jackrabbit/oak/core/SecureNodeState.java | 18 ++++++---------- .../plugins/identifier/IdentifierManager.java | 7 +++---- .../plugins/index/IndexInfoServiceImpl.java | 8 ++++--- .../plugins/index/IndexPathServiceImpl.java | 14 ++++++------- .../index/reference/ReferenceIndex.java | 9 ++++---- .../migration/AbstractDecoratedNodeState.java | 20 ++++++++++-------- .../nodetype/EffectiveNodeTypeImpl.java | 14 +++++++------ .../oak/plugins/nodetype/NodeTypeImpl.java | 13 +++++++----- .../nodetype/write/NodeTypeTemplateImpl.java | 9 +++++--- .../oak/plugins/tree/impl/AbstractTree.java | 21 +++++++++---------- .../oak/query/ast/LowerCaseImpl.java | 5 ++--- .../authorization/accesscontrol/ACL.java | 11 +++++----- .../AccessControlManagerImpl.java | 2 +- .../SecurityProviderRegistration.java | 5 ++++- .../user/CachedPrincipalMembershipReader.java | 6 +++--- .../oak/security/user/UserManagerImpl.java | 7 ++++--- .../plugins/tree/impl/ImmutableTreeTest.java | 5 +++-- .../oak/query/AbstractQueryTest.java | 1 - ...uthorizationConfigurationImplOSGiTest.java | 11 +++++++--- .../AccessControlManagerImplTest.java | 3 +-- .../evaluation/AbstractQueryTest.java | 8 +++++-- .../evaluation/ChildOrderPropertyTest.java | 3 ++- .../permission/PermissionHookTest.java | 4 +++- .../SecurityProviderRegistrationTest.java | 7 +++++-- .../oak/security/privilege/JcrAllTest.java | 12 ++++++----- .../security/privilege/PrivilegeImplTest.java | 7 ++++--- .../user/CachedGroupPrincipalTest.java | 17 +++++++++------ 29 files changed, 146 insertions(+), 123 deletions(-) diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java index 6ceebaf14e1..7347fe9d034 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java @@ -51,7 +51,6 @@ import javax.security.auth.login.LoginException; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Lists; import org.apache.jackrabbit.guava.common.io.Closer; @@ -63,6 +62,7 @@ import org.apache.jackrabbit.oak.api.jmx.QueryEngineSettingsMBean; import org.apache.jackrabbit.oak.api.jmx.RepositoryManagementMBean; import org.apache.jackrabbit.oak.commons.IOUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser; import org.apache.jackrabbit.oak.commons.jmx.AnnotatedStandardMBean; import org.apache.jackrabbit.oak.core.ContentRepositoryImpl; @@ -703,14 +703,14 @@ private void initialContent(IndexEditorProvider indexEditors, QueryIndexProvider // FIXME: OAK-810 move to proper workspace initialization // initialize default workspace - Iterable workspaceInitializers = Iterables.transform(securityProvider.getConfigurations(), + Iterable workspaceInitializers = () -> CollectionUtils.toStream(securityProvider.getConfigurations()).map( sc -> { WorkspaceInitializer wi = sc.getWorkspaceInitializer(); if (wi instanceof QueryIndexProviderAware) { ((QueryIndexProviderAware) wi).setQueryIndexProvider(indexProvider); } return wi; - }); + }).iterator(); OakInitializer.initialize(workspaceInitializers, store, defaultWorkspaceName, initHook); } diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeBuilder.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeBuilder.java index ce14ebd2f75..bbbdf812dfe 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeBuilder.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeBuilder.java @@ -25,6 +25,7 @@ import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.api.Type; import org.apache.jackrabbit.oak.commons.LazyValue; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.tree.factories.TreeFactory; import org.apache.jackrabbit.oak.spi.security.authorization.permission.PermissionProvider; import org.apache.jackrabbit.oak.spi.security.authorization.permission.TreePermission; @@ -36,7 +37,6 @@ import static java.util.Objects.requireNonNull; import static org.apache.jackrabbit.guava.common.base.Preconditions.checkState; -import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; import static org.apache.jackrabbit.guava.common.collect.Iterables.size; import static java.util.Collections.emptyList; import static org.apache.jackrabbit.oak.api.Type.BOOLEAN; @@ -194,9 +194,7 @@ public synchronized long getPropertyCount() { if (getTreePermission().canReadProperties() || isNew()) { return builder.getPropertyCount(); } else { - return size(filter( - builder.getProperties(), - new ReadablePropertyPredicate()::test)); + return CollectionUtils.toStream(builder.getProperties()).filter(new ReadablePropertyPredicate()).count(); } } @@ -206,9 +204,8 @@ public Iterable getProperties() { if (getTreePermission().canReadProperties() || isNew()) { return builder.getProperties(); } else { - return filter( - builder.getProperties(), - new ReadablePropertyPredicate()::test); + return CollectionUtils.toIterable( + CollectionUtils.toStream(builder.getProperties()).filter(new ReadablePropertyPredicate()).iterator()); } } @@ -285,9 +282,8 @@ public NodeBuilder removeProperty(String name) { @NotNull @Override public Iterable getChildNodeNames() { - return filter( - builder.getChildNodeNames(), - input -> input != null && getChildNode(input).exists()); + return () -> CollectionUtils.toStream(builder.getChildNodeNames()) + .filter(input -> input != null && getChildNode(input).exists()).iterator(); } @Override diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeState.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeState.java index 7e6f7ff502f..81b6b7e93ba 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeState.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeState.java @@ -17,6 +17,7 @@ package org.apache.jackrabbit.oak.core; import org.apache.jackrabbit.oak.api.PropertyState; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.memory.MemoryChildNodeEntry; import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder; import org.apache.jackrabbit.oak.spi.security.authorization.permission.TreePermission; @@ -28,8 +29,6 @@ import org.jetbrains.annotations.Nullable; import static java.util.Objects.requireNonNull; -import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; import java.util.function.Function; import java.util.function.Predicate; @@ -78,9 +77,7 @@ public synchronized long getPropertyCount() { if (treePermission.canReadProperties()) { propertyCount = state.getPropertyCount(); } else { - propertyCount = count(filter( - state.getProperties(), - new ReadablePropertyPredicate()::test)); + propertyCount = CollectionUtils.toStream(state.getProperties()).filter(new ReadablePropertyPredicate()).count(); } } return propertyCount; @@ -91,9 +88,8 @@ public Iterable getProperties() { if (treePermission.canReadProperties()) { return state.getProperties(); } else { - return filter( - state.getProperties(), - new ReadablePropertyPredicate()::test); + return CollectionUtils + .toIterable(CollectionUtils.toStream(state.getProperties()).filter(new ReadablePropertyPredicate()).iterator()); } } @@ -144,10 +140,8 @@ public Iterable getChildNodeEntries() { // everything is readable including ac-content -> no secure wrapper needed return state.getChildNodeEntries(); } else if (treePermission.canRead()) { - Iterable readable = transform( - state.getChildNodeEntries(), - new WrapChildEntryFunction()::apply); - return filter(readable, new IterableNodePredicate()::test); + return () -> CollectionUtils.toStream(state.getChildNodeEntries()).map(new WrapChildEntryFunction()) + .filter(new IterableNodePredicate()).iterator(); } else { return emptyList(); } diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java index 50abff87a04..31bc598a7ef 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java @@ -25,7 +25,6 @@ import javax.jcr.PropertyType; import javax.jcr.query.Query; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Iterators; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.oak.api.PropertyState; @@ -39,6 +38,7 @@ import org.apache.jackrabbit.oak.commons.PathUtils; import org.apache.jackrabbit.oak.commons.QueryUtils; import org.apache.jackrabbit.oak.commons.UUIDUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.plugins.memory.PropertyValues; import org.apache.jackrabbit.oak.plugins.memory.StringPropertyState; @@ -318,9 +318,8 @@ public Iterable getReferences(@NotNull Tree tree, @NotNull final String pr QueryEngine.INTERNAL_SQL2_QUERY, Query.JCR_SQL2, bindings, NO_MAPPINGS); - Iterable resultTrees = Iterables.transform(result.getRows(), row -> row.getTree(null)); - return Iterables.filter(resultTrees, tree1 -> !tree1.getPath().startsWith(VersionConstants.VERSION_STORE_PATH) - ); + return () -> CollectionUtils.toStream(result.getRows()).map(row -> row.getTree(null)) + .filter(tree1 -> !tree1.getPath().startsWith(VersionConstants.VERSION_STORE_PATH)).iterator(); } catch (ParseException e) { log.error("query failed", e); return Collections.emptySet(); diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexInfoServiceImpl.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexInfoServiceImpl.java index 9e53c910595..ec1774b3fa8 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexInfoServiceImpl.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexInfoServiceImpl.java @@ -21,9 +21,11 @@ import java.io.IOException; import java.util.HashSet; import java.util.Map; +import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; -import org.apache.jackrabbit.guava.common.collect.Iterables; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.state.NodeState; import org.apache.jackrabbit.oak.spi.state.NodeStateUtils; import org.apache.jackrabbit.oak.spi.state.NodeStore; @@ -68,7 +70,7 @@ public Iterable getAllIndexInfo() { } else { activeIndexes.addAll(allIndexes); } - return Iterables.filter(Iterables.transform(indexPathService.getIndexPaths(), indexPath -> { + return CollectionUtils.toStream(indexPathService.getIndexPaths()).map(indexPath -> { try { IndexInfo info = getInfo(indexPath); if (info != null) { @@ -79,7 +81,7 @@ public Iterable getAllIndexInfo() { log.warn("Error occurred while capturing IndexInfo for path {}", indexPath, e); return null; } - }), x -> x != null); + }).filter(Objects::nonNull).collect(Collectors.toList()); } @Override diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexPathServiceImpl.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexPathServiceImpl.java index 9b9dd6314cb..9763dc3eb23 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexPathServiceImpl.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexPathServiceImpl.java @@ -16,13 +16,13 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.jackrabbit.oak.plugins.index; import java.util.Iterator; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.index.nodetype.NodeTypeIndexProvider; import org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider; import org.apache.jackrabbit.oak.query.QueryEngineSettings; @@ -43,9 +43,7 @@ import org.slf4j.LoggerFactory; import static org.apache.jackrabbit.guava.common.base.Preconditions.checkState; -import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; -import static org.apache.jackrabbit.guava.common.collect.Iterators.transform; + import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE; import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.DECLARING_NODE_TYPES; import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NODE_TYPE; @@ -91,14 +89,14 @@ public Iterable getIndexPaths() { log.warn("{} is not found to be indexed as part of nodetype index. Non root indexes would " + "not be listed", INDEX_DEFINITIONS_NODE_TYPE); NodeState oakIndex = nodeStore.getRoot().getChildNode("oak:index"); - return transform(filter(oakIndex.getChildNodeEntries(), - cne -> INDEX_DEFINITIONS_NODE_TYPE.equals(cne.getNodeState().getName(JCR_PRIMARYTYPE))), - cne -> PathUtils.concat("/oak:index", cne.getName())); + return () -> CollectionUtils.toStream(oakIndex.getChildNodeEntries()) + .filter(cne -> INDEX_DEFINITIONS_NODE_TYPE.equals(cne.getNodeState().getName(JCR_PRIMARYTYPE))) + .map(cne -> PathUtils.concat("/oak:index", cne.getName())).iterator(); } return () -> { Iterator itr = getIndex().query(createFilter(INDEX_DEFINITIONS_NODE_TYPE), nodeStore.getRoot()); - return transform(itr, input -> input.getPath()); + return CollectionUtils.toStream(itr).map(IndexRow::getPath).iterator(); }; } diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/reference/ReferenceIndex.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/reference/ReferenceIndex.java index 2ac090852ed..d9ddfbd737d 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/reference/ReferenceIndex.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/reference/ReferenceIndex.java @@ -16,8 +16,6 @@ */ package org.apache.jackrabbit.oak.plugins.index.reference; -import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; import static java.lang.Double.POSITIVE_INFINITY; import static javax.jcr.PropertyType.REFERENCE; import static javax.jcr.PropertyType.WEAKREFERENCE; @@ -33,7 +31,9 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.index.property.Multiplexers; import org.apache.jackrabbit.oak.plugins.index.property.strategy.IndexStoreStrategy; import org.apache.jackrabbit.oak.query.SQL2Parser; @@ -45,7 +45,6 @@ import org.apache.jackrabbit.oak.spi.query.QueryIndex; import org.apache.jackrabbit.oak.spi.state.NodeState; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Lists; @@ -138,9 +137,9 @@ private Cursor lookup(NodeState root, String uuid, Iterable paths = Iterables.concat(iterables); if (!"*".equals(name)) { - paths = filter(paths, path -> name.equals(getName(path))); + paths = CollectionUtils.toStream(paths).filter(path -> name.equals(getName(path))).collect(Collectors.toList()); } - paths = transform(paths, path -> getParentPath(path)); + paths = CollectionUtils.toStream(paths).map(path -> getParentPath(path)).collect(Collectors.toList()); return newPathCursor(paths, filter.getQueryLimits()); } diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/migration/AbstractDecoratedNodeState.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/migration/AbstractDecoratedNodeState.java index a5a5798261d..4c80a451147 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/migration/AbstractDecoratedNodeState.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/migration/AbstractDecoratedNodeState.java @@ -19,6 +19,7 @@ import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Type; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState; import org.apache.jackrabbit.oak.plugins.memory.MemoryChildNodeEntry; import org.apache.jackrabbit.oak.plugins.memory.PropertyStates; @@ -35,7 +36,9 @@ import java.util.Collection; import java.util.Collections; import java.util.HashSet; +import java.util.Objects; import java.util.Set; +import java.util.stream.Collectors; import static org.apache.jackrabbit.oak.plugins.tree.TreeConstants.OAK_CHILD_ORDER; @@ -97,8 +100,8 @@ protected static PropertyState fixChildOrderPropertyState(NodeState nodeState, P if (propertyState != null && OAK_CHILD_ORDER.equals(propertyState.getName())) { final Collection childNodeNames = new ArrayList(); Iterables.addAll(childNodeNames, nodeState.getChildNodeNames()); - final Iterable values = Iterables.filter( - propertyState.getValue(Type.NAMES), x -> childNodeNames.contains(x)); + final Iterable values = () -> CollectionUtils.toStream(propertyState.getValue(Type.NAMES)) + .filter(childNodeNames::contains).iterator(); return PropertyStates.createProperty(OAK_CHILD_ORDER, values, Type.NAMES); } return propertyState; @@ -137,7 +140,7 @@ public NodeState getChildNode(@NotNull final String name) throws IllegalArgument @Override @NotNull public Iterable getChildNodeEntries() { - final Iterable transformed = Iterables.transform(delegate.getChildNodeEntries(), childNodeEntry -> { + return CollectionUtils.toStream(delegate.getChildNodeEntries()).map(childNodeEntry -> { if (childNodeEntry != null) { final String name = childNodeEntry.getName(); final NodeState nodeState = decorate(name, childNodeEntry.getNodeState()); @@ -146,8 +149,7 @@ public Iterable getChildNodeEntries() { } } return null; - }); - return Iterables.filter(transformed, x -> x != null); + }).filter(Objects::nonNull).collect(Collectors.toList()); } @Override @@ -168,10 +170,10 @@ public PropertyState getProperty(@NotNull String name) { @Override @NotNull public Iterable getProperties() { - final Iterable propertyStates = Iterables.transform( - delegate.getProperties(), - propertyState -> decorate(propertyState)); - return Iterables.filter(Iterables.concat(propertyStates, getNewPropertyStates()), x -> x != null); + final Iterable propertyStates = () -> CollectionUtils.toStream(delegate.getProperties()) + .map(propertyState -> decorate(propertyState)).iterator(); + return () -> CollectionUtils.toStream(Iterables.concat(propertyStates, getNewPropertyStates())).filter(Objects::nonNull) + .iterator(); } /** diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeTypeImpl.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeTypeImpl.java index 56cc48ae533..7d298e5dc95 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeTypeImpl.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/EffectiveNodeTypeImpl.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import javax.jcr.PropertyType; import javax.jcr.RepositoryException; @@ -37,6 +38,7 @@ import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Tree; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.value.jcr.PartialValueFactory; import org.apache.jackrabbit.oak.spi.nodetype.EffectiveNodeType; import org.jetbrains.annotations.NotNull; @@ -175,25 +177,25 @@ public Iterable getPropertyDefinitions() { @NotNull @Override public Iterable getAutoCreateNodeDefinitions() { - return Iterables.filter(getNodeDefinitions(), nodeDefinition -> nodeDefinition.isAutoCreated()); + return () -> CollectionUtils.toStream(getNodeDefinitions()).filter(NodeDefinition::isAutoCreated).iterator(); } @NotNull @Override public Iterable getAutoCreatePropertyDefinitions() { - return Iterables.filter(getPropertyDefinitions(), propertyDefinition -> propertyDefinition.isAutoCreated()); + return () -> CollectionUtils.toStream(getPropertyDefinitions()).filter(PropertyDefinition::isAutoCreated).iterator(); } @NotNull @Override public Iterable getMandatoryNodeDefinitions() { - return Iterables.filter(getNodeDefinitions(), nodeDefinition -> nodeDefinition.isMandatory()); + return () -> CollectionUtils.toStream(getNodeDefinitions()).filter(NodeDefinition::isMandatory).iterator(); } @NotNull @Override public Iterable getMandatoryPropertyDefinitions() { - return Iterables.filter(getPropertyDefinitions(), propertyDefinition -> propertyDefinition.isMandatory()); + return () -> CollectionUtils.toStream(getPropertyDefinitions()).filter(PropertyDefinition::isMandatory).iterator(); } /** @@ -205,8 +207,8 @@ public Iterable getMandatoryPropertyDefinitions() { @NotNull @Override public Iterable getNamedNodeDefinitions(@NotNull final String oakName) { - return Iterables.concat(Iterables.transform(nodeTypes.values(), - input -> input.getDeclaredNamedNodeDefinitions(oakName))); + return Iterables.concat(nodeTypes.values().stream().map(input -> input.getDeclaredNamedNodeDefinitions(oakName)) + .collect(Collectors.toList())); } /** diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeImpl.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeImpl.java index 9fb4222b9bf..b2cdcb3612c 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeImpl.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeImpl.java @@ -66,7 +66,6 @@ import javax.jcr.nodetype.NodeTypeIterator; import javax.jcr.nodetype.PropertyDefinition; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Lists; import org.apache.jackrabbit.guava.common.collect.Maps; import org.apache.jackrabbit.commons.cnd.CompactNodeTypeDefWriter; @@ -187,8 +186,10 @@ public String getPrimaryItemName() { @Override @NotNull public PropertyDefinition[] getDeclaredPropertyDefinitions() { Map definitions = newTreeMap(); - for (Tree child : Iterables.filter(definition.getChildren(), PrimaryTypePredicate.PROPERTY_DEF_PREDICATE::test)) { - definitions.put(getIndex(child), new PropertyDefinitionImpl(child, this, mapper)); + for (Tree child : definition.getChildren()) { + if (PrimaryTypePredicate.PROPERTY_DEF_PREDICATE.test(child)) { + definitions.put(getIndex(child), new PropertyDefinitionImpl(child, this, mapper)); + } } return definitions.values().toArray(NO_PROPERTY_DEFINITIONS); } @@ -201,8 +202,10 @@ public PropertyDefinition[] getDeclaredPropertyDefinitions() { @Override @NotNull public NodeDefinition[] getDeclaredChildNodeDefinitions() { Map definitions = newTreeMap(); - for (Tree child : Iterables.filter(definition.getChildren(), PrimaryTypePredicate.CHILDNODE_DEF_PREDICATE::test)) { - definitions.put(getIndex(child), new NodeDefinitionImpl(child, this, mapper)); + for (Tree child : definition.getChildren()) { + if (PrimaryTypePredicate.CHILDNODE_DEF_PREDICATE.test(child)) { + definitions.put(getIndex(child), new NodeDefinitionImpl(child, this, mapper)); + } } return definitions.values().toArray(NO_NODE_DEFINITIONS); } diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/NodeTypeTemplateImpl.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/NodeTypeTemplateImpl.java index a78ff511ced..0e35101502f 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/NodeTypeTemplateImpl.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/NodeTypeTemplateImpl.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.plugins.nodetype.write; -import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; import static org.apache.jackrabbit.JcrConstants.JCR_CHILDNODEDEFINITION; import static org.apache.jackrabbit.JcrConstants.JCR_HASORDERABLECHILDNODES; import static org.apache.jackrabbit.JcrConstants.JCR_ISMIXIN; @@ -180,9 +179,13 @@ Tree writeTo(@NotNull Tree parent, boolean allowUpdate) throws RepositoryExcepti private static void writeItemDefinitions(@NotNull Tree nodeTypeTree, @Nullable List itemDefTemplates, @NotNull String nodeName, @NotNull String primaryTypeName) throws RepositoryException { // first remove existing - for (Tree t : filter(nodeTypeTree.getChildren(), new SameNamePredicate(nodeName)::test)) { - t.remove(); + SameNamePredicate p = new SameNamePredicate(nodeName); + for (Tree t : nodeTypeTree.getChildren()) { + if (p.test(t)) { + t.remove(); + } } + // now write definitions int index = 1; if (itemDefTemplates != null) { diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/tree/impl/AbstractTree.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/tree/impl/AbstractTree.java index 2f5773e5005..bd985a57ffc 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/tree/impl/AbstractTree.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/tree/impl/AbstractTree.java @@ -20,9 +20,6 @@ import static org.apache.jackrabbit.guava.common.base.Preconditions.checkState; -import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; -import static org.apache.jackrabbit.guava.common.collect.Iterables.size; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; import static org.apache.jackrabbit.guava.common.collect.Sets.newLinkedHashSet; import static org.apache.jackrabbit.oak.api.Tree.Status.MODIFIED; import static org.apache.jackrabbit.oak.api.Tree.Status.NEW; @@ -33,11 +30,14 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Objects; import java.util.Set; +import java.util.stream.Collectors; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.index.IndexConstants; import org.apache.jackrabbit.oak.plugins.index.reference.NodeReferenceConstants; import org.apache.jackrabbit.oak.plugins.tree.TreeConstants; @@ -255,7 +255,7 @@ public boolean hasProperty(@NotNull String name) { @Override public long getPropertyCount() { - return size(getProperties()); + return CollectionUtils.toStream(getProperties()).count(); } @Override @@ -276,7 +276,8 @@ public Status getPropertyStatus(@NotNull String name) { @Override @NotNull public Iterable getProperties() { - return filter(getNodeBuilder().getProperties(), propertyState -> !isHidden(propertyState.getName())); + return CollectionUtils.toIterable(CollectionUtils.toStream(getNodeBuilder().getProperties()) + .filter(propertyState -> !isHidden(propertyState.getName())).iterator()); } @Override @@ -310,11 +311,9 @@ public long getChildrenCount(long max) { @Override @NotNull public Iterable getChildren() { - Iterable children = transform(getChildNames(), - name -> { - AbstractTree child = createChild(name); - return child.exists() ? child : null; - }); - return filter(children, x -> x != null); + return CollectionUtils.toStream(getChildNames()).map(name -> { + AbstractTree child = createChild(name); + return child.exists() ? child : null; + }).filter(Objects::nonNull).collect(Collectors.toList()); } } diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/LowerCaseImpl.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/LowerCaseImpl.java index df46dd82735..cadde6c2564 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/LowerCaseImpl.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/LowerCaseImpl.java @@ -25,12 +25,12 @@ import org.apache.jackrabbit.oak.api.PropertyValue; import org.apache.jackrabbit.oak.api.Type; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.query.index.FilterImpl; import org.apache.jackrabbit.oak.plugins.memory.PropertyValues; import org.apache.jackrabbit.oak.spi.query.QueryConstants; import org.apache.jackrabbit.oak.spi.query.QueryIndex.OrderEntry; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; import static org.apache.jackrabbit.oak.api.Type.STRING; import static org.apache.jackrabbit.oak.api.Type.STRINGS; @@ -77,8 +77,7 @@ public PropertyValue currentProperty() { } // TODO toLowerCase(): document the Turkish locale problem if (p.getType().isArray()) { - Iterable lowerCase = transform(p.getValue(STRINGS), - input -> input.toLowerCase()); + Iterable lowerCase = () -> CollectionUtils.toStream(p.getValue(STRINGS)).map(String::toLowerCase).iterator(); return PropertyValues.newString(lowerCase); } else { String value = p.getValue(STRING); diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/ACL.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/ACL.java index 026fa5eb68d..0011e7c58bc 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/ACL.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/ACL.java @@ -23,14 +23,14 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; + import javax.jcr.RepositoryException; import javax.jcr.Value; import javax.jcr.security.AccessControlEntry; import javax.jcr.security.AccessControlException; import javax.jcr.security.Privilege; -import org.apache.jackrabbit.guava.common.collect.Iterables; -import org.apache.jackrabbit.guava.common.collect.Lists; import org.apache.jackrabbit.api.security.authorization.PrivilegeManager; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.ACE; @@ -164,8 +164,8 @@ private static ACE checkACE(AccessControlEntry entry) throws AccessControlExcept private boolean internalAddEntry(@NotNull ACE entry) throws RepositoryException { final String principalName = entry.getPrincipal().getName(); final Set restrictions = entry.getRestrictions(); - List subList = Lists.newArrayList(Iterables.filter(entries, ace -> - principalName.equals(requireNonNull(ace).getPrincipal().getName()) && restrictions.equals(ace.getRestrictions()))); + List subList = entries.stream().filter(ace -> principalName.equals(requireNonNull(ace).getPrincipal().getName()) + && restrictions.equals(ace.getRestrictions())).collect(Collectors.toList()); boolean addEntry = true; for (ACE existing : subList) { @@ -211,7 +211,8 @@ private ACE createACE(@NotNull ACE existing, @NotNull PrivilegeBits newPrivilege @NotNull private Set validateRestrictions(@NotNull Map restrictions, @NotNull Map mvRestrictions) throws RepositoryException { - Iterable mandatoryDefs = Iterables.filter(getRestrictionProvider().getSupportedRestrictions(getOakPath()), RestrictionDefinition::isMandatory); + Iterable mandatoryDefs = () -> getRestrictionProvider().getSupportedRestrictions(getOakPath()).stream() + .filter(RestrictionDefinition::isMandatory).iterator(); for (RestrictionDefinition def : mandatoryDefs) { String jcrName = getNamePathMapper().getJcrName(def.getName()); boolean mandatoryPresent; diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImpl.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImpl.java index 720f0abd342..0818342164a 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImpl.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImpl.java @@ -845,7 +845,7 @@ private final class PrincipalPredicate implements Predicate { private PrincipalPredicate(@Nullable String accessControlledPath, @NotNull Set principals, @NotNull Collection oakPaths) { this.accessControlledPath = accessControlledPath; - principalNames = Iterables.transform(principals, Principal::getName); + principalNames = () -> principals.stream().map(Principal::getName).iterator(); this.oakPaths = oakPaths; } diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/internal/SecurityProviderRegistration.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/internal/SecurityProviderRegistration.java index 5bddaf2dd4e..abfc87365a0 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/internal/SecurityProviderRegistration.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/internal/SecurityProviderRegistration.java @@ -20,6 +20,7 @@ import org.apache.jackrabbit.guava.common.io.Closer; import org.apache.jackrabbit.api.security.JackrabbitAccessControlManager; import org.apache.jackrabbit.oak.commons.PropertiesUtil; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.osgi.OsgiWhiteboard; import org.apache.jackrabbit.oak.plugins.tree.RootProvider; import org.apache.jackrabbit.oak.plugins.tree.TreeProvider; @@ -85,6 +86,7 @@ import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; +import java.util.stream.Collectors; import static org.apache.jackrabbit.guava.common.collect.Lists.newArrayList; import static org.apache.jackrabbit.oak.commons.IOUtils.closeQuietly; @@ -527,7 +529,8 @@ private void maybeRegister() { } closer = Closer.create(); - Iterable>> monitors = Iterables.transform(securityProvider.getConfigurations(), sc -> sc.getMonitors(statisticsProvider)); + Iterable>> monitors = () -> CollectionUtils.toStream(securityProvider.getConfigurations()) + .map(sc -> sc.getMonitors(statisticsProvider)).iterator(); for (Monitor monitor : Iterables.concat(monitors)) { Registration reg = whiteboard.register(monitor.getMonitorClass(), monitor, monitor.getMonitorProperties()); closer.register(reg::unregister); diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/CachedPrincipalMembershipReader.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/CachedPrincipalMembershipReader.java index 9bf016ee5f7..35abb19ed13 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/CachedPrincipalMembershipReader.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/CachedPrincipalMembershipReader.java @@ -16,9 +16,7 @@ */ package org.apache.jackrabbit.oak.security.user; -import org.apache.jackrabbit.guava.common.base.Joiner; import org.apache.jackrabbit.guava.common.base.Strings; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.api.Tree; @@ -39,6 +37,7 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.function.BiConsumer; +import java.util.stream.Collectors; import static org.apache.jackrabbit.oak.security.user.CacheConstants.REP_GROUP_PRINCIPAL_NAMES; import static org.apache.jackrabbit.oak.security.user.UserPrincipalProvider.EXPIRATION_NO_CACHE; @@ -216,7 +215,8 @@ private void cacheGroups(@NotNull Tree authorizableTree, } cache.setProperty(CacheConstants.REP_EXPIRATION, LongUtils.calculateExpirationTime(expiration)); - String value = (groupPrincipals.isEmpty()) ? "" : Joiner.on(",").join(Iterables.transform(groupPrincipals, input -> Text.escape(input.getName()))); + String value = (groupPrincipals.isEmpty()) ? "" + : groupPrincipals.stream().map(input -> Text.escape(input.getName())).collect(Collectors.joining(",")); cache.setProperty(REP_GROUP_PRINCIPAL_NAMES, value); root.commit(CacheValidatorProvider.asCommitAttributes()); diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserManagerImpl.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserManagerImpl.java index f78e6b083d3..b49dce68d01 100644 --- a/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserManagerImpl.java +++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserManagerImpl.java @@ -17,7 +17,6 @@ package org.apache.jackrabbit.oak.security.user; import org.apache.jackrabbit.guava.common.base.Strings; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.api.security.principal.PrincipalManager; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.AuthorizableExistsException; @@ -558,13 +557,15 @@ private UserQueryManager getQueryManager() { * * @return A {@code List} of {@code GroupAction}s. List may be empty. */ + @SuppressWarnings("unchecked") @NotNull private Iterable filterGroupActions() { - return Iterables.filter(actionProvider.getAuthorizableActions(securityProvider), GroupAction.class); + return () -> (Iterator) actionProvider.getAuthorizableActions(securityProvider).stream().filter(GroupAction.class::isInstance).iterator(); } + @SuppressWarnings("unchecked") @NotNull private Iterable filterUserActions() { - return Iterables.filter(actionProvider.getAuthorizableActions(securityProvider), UserAction.class); + return () -> (Iterator) actionProvider.getAuthorizableActions(securityProvider).stream().filter(UserAction.class::isInstance).iterator(); } } diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/tree/impl/ImmutableTreeTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/tree/impl/ImmutableTreeTest.java index 2ff4ce0ffbe..716931b3a0e 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/tree/impl/ImmutableTreeTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/tree/impl/ImmutableTreeTest.java @@ -19,13 +19,14 @@ package org.apache.jackrabbit.oak.plugins.tree.impl; import java.util.List; +import java.util.stream.Collectors; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Lists; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.oak.AbstractSecurityTest; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Tree; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.tree.TreeConstants; import org.apache.jackrabbit.oak.plugins.tree.TreeType; import org.apache.jackrabbit.oak.plugins.tree.TreeTypeProvider; @@ -263,7 +264,7 @@ private static ImmutableTree getHiddenTree(@NotNull ImmutableTree immutable) { } private static void assertSequence(Iterable trees, String... names) { - List actual = Lists.newArrayList(Iterables.transform(trees, input -> input.getName())); + List actual = CollectionUtils.toStream(trees).map(Tree::getName).collect(Collectors.toList()); assertEquals(Lists.newArrayList(names), actual); } diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java index cb09b688d3e..55c05aecbcd 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java @@ -29,7 +29,6 @@ import java.text.ParseException; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/AuthorizationConfigurationImplOSGiTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/AuthorizationConfigurationImplOSGiTest.java index 2b21d021ea3..d51163ee2bf 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/AuthorizationConfigurationImplOSGiTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/AuthorizationConfigurationImplOSGiTest.java @@ -44,6 +44,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import static org.apache.jackrabbit.oak.spi.security.authorization.permission.PermissionConstants.PARAM_ADMINISTRATIVE_PRINCIPALS; import static org.apache.jackrabbit.oak.spi.security.authorization.permission.PermissionConstants.PARAM_READ_PATHS; @@ -103,13 +104,17 @@ public void testGetWorkspaceInitializer() { @Test public void testGetCommitHooks() { List expected = ImmutableList.of(VersionablePathHook.class, PermissionHook.class); - assertTrue(Iterables.elementsEqual(expected, Iterables.transform(authorizationConfiguration.getCommitHooks(adminSession.getWorkspaceName()), commitHook -> commitHook.getClass()))); + assertTrue(Iterables.elementsEqual(expected, authorizationConfiguration.getCommitHooks(adminSession.getWorkspaceName()) + .stream().map(commitHook -> commitHook.getClass()).collect(Collectors.toList()))); } @Test public void testGetValidators() { - List expected = ImmutableList.of(PermissionStoreValidatorProvider.class, PermissionValidatorProvider.class, AccessControlValidatorProvider.class); - assertTrue(Iterables.elementsEqual(expected, Iterables.transform(authorizationConfiguration.getValidators(adminSession.getWorkspaceName(), Set.of(), new MoveTracker()), commitHook -> commitHook.getClass()))); + List expected = ImmutableList.of(PermissionStoreValidatorProvider.class, PermissionValidatorProvider.class, + AccessControlValidatorProvider.class); + assertTrue(Iterables.elementsEqual(expected, + authorizationConfiguration.getValidators(adminSession.getWorkspaceName(), Set.of(), new MoveTracker()).stream() + .map(commitHook -> commitHook.getClass()).collect(Collectors.toList()))); } @Test diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImplTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImplTest.java index 4de904920a9..c23ebebc47b 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImplTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImplTest.java @@ -19,7 +19,6 @@ import org.apache.jackrabbit.guava.common.collect.ImmutableList; import org.apache.jackrabbit.guava.common.collect.ImmutableMap; import org.apache.jackrabbit.guava.common.collect.ImmutableSet; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Lists; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry; @@ -1360,7 +1359,7 @@ public void testSetPolicyCreatesIndexedAceNodeNames() throws Exception { assertEquals(4, acl.getAccessControlEntries().length); Iterable aceTrees = root.getTree(testPath).getChild(REP_POLICY).getChildren(); - String[] aceNodeNames = Iterables.toArray(Iterables.transform(aceTrees, Tree::getName), String.class); + String[] aceNodeNames = CollectionUtils.toStream(aceTrees).map(Tree::getName).toArray(String[]::new); assertArrayEquals(new String[]{"allow", "allow1", "deny2", "deny3"}, aceNodeNames); } diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/evaluation/AbstractQueryTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/evaluation/AbstractQueryTest.java index 86f60eabe5c..18eb35216c0 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/evaluation/AbstractQueryTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/evaluation/AbstractQueryTest.java @@ -24,6 +24,7 @@ import org.apache.jackrabbit.oak.api.Result; import org.apache.jackrabbit.oak.api.ResultRow; import org.apache.jackrabbit.oak.api.Tree; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.tree.TreeUtil; import org.apache.jackrabbit.oak.spi.nodetype.NodeTypeConstants; import org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration; @@ -44,6 +45,7 @@ import java.util.Collections; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -98,7 +100,8 @@ public void testQueryWithEmptyGlobRestriction() throws Exception { Result result = getTestRoot().getQueryEngine().executeQuery(getStatement(), Query.JCR_SQL2, Collections.emptyMap(), Collections.emptyMap()); Iterable expected = Set.of(node.getPath()); - assertTrue(Iterables.elementsEqual(expected, Iterables.transform(result.getRows(), ResultRow::getPath))); + assertTrue(Iterables.elementsEqual(expected, + CollectionUtils.toStream(result.getRows()).map(ResultRow::getPath).collect(Collectors.toList()))); } @Test @@ -125,7 +128,8 @@ public void testQueryWithEmptyGlobRestrictionAndPropertyRead() throws Exception Result result = getTestRoot().getQueryEngine().executeQuery(getStatement(), Query.JCR_SQL2, Collections.emptyMap(), Collections.emptyMap()); Iterable expected = Set.of(node.getPath()); - assertTrue(Iterables.elementsEqual(expected, Iterables.transform(result.getRows(), row -> row.getPath()))); + assertTrue(Iterables.elementsEqual(expected, + CollectionUtils.toStream(result.getRows()).map(row -> row.getPath()).collect(Collectors.toList()))); } @Test diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/evaluation/ChildOrderPropertyTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/evaluation/ChildOrderPropertyTest.java index f017dcf4d04..b0036f96b3f 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/evaluation/ChildOrderPropertyTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/evaluation/ChildOrderPropertyTest.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import org.apache.jackrabbit.guava.common.collect.ImmutableList; import org.apache.jackrabbit.guava.common.collect.Iterables; @@ -99,7 +100,7 @@ public void testChildOrderWithoutPropertyReadAccess() throws Exception { assertFalse(aTree.hasProperty(JcrConstants.JCR_PRIMARYTYPE)); List expected = ImmutableList.of("/a/bb", "/a/b"); - Iterable childPaths = Iterables.transform(aTree.getChildren(), input -> input.getPath()); + List childPaths = CollectionUtils.toStream(aTree.getChildren()).map(Tree::getPath).collect(Collectors.toList()); assertTrue(childPaths.toString(), Iterables.elementsEqual(expected, childPaths)); } } diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionHookTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionHookTest.java index 516c946db52..95b4d5c72a0 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionHookTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authorization/permission/PermissionHookTest.java @@ -68,6 +68,7 @@ import java.util.Iterator; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES; import static org.junit.Assert.assertEquals; @@ -796,7 +797,8 @@ public void testInvalidPolicyNodeBecomesTypeRepACL() throws Exception { principalPermissionStore = root.getTree(PermissionConstants.PERMISSIONS_STORE_PATH).getChild(adminSession.getWorkspaceName()).getChild(testPrincipal.getName()); assertEquals(2, principalPermissionStore.getChildrenCount(10)); - Iterable paths = Iterables.transform(principalPermissionStore.getChildren(), tree -> tree.getProperty(REP_ACCESS_CONTROLLED_PATH).getValue(Type.STRING)); + Set paths = CollectionUtils.toStream(principalPermissionStore.getChildren()) + .map(tree -> tree.getProperty(REP_ACCESS_CONTROLLED_PATH).getValue(Type.STRING)).collect(Collectors.toSet()); assertEquals(Set.of(testPath, t.getPath()), ImmutableSet.copyOf(paths)); } diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/internal/SecurityProviderRegistrationTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/internal/SecurityProviderRegistrationTest.java index 9ebb4fc7c62..12cebf6a561 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/internal/SecurityProviderRegistrationTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/internal/SecurityProviderRegistrationTest.java @@ -18,13 +18,13 @@ import org.apache.jackrabbit.guava.common.collect.ImmutableList; import org.apache.jackrabbit.guava.common.collect.ImmutableMap; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.api.security.JackrabbitAccessControlManager; import org.apache.jackrabbit.oak.AbstractSecurityTest; import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.plugins.memory.PropertyStates; import org.apache.jackrabbit.oak.plugins.tree.RootProvider; @@ -88,8 +88,10 @@ import java.util.Hashtable; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.SortedMap; +import java.util.stream.Collectors; import static org.apache.jackrabbit.oak.spi.security.RegistrationConstants.OAK_SECURITY_NAME; import static org.hamcrest.Matchers.notNullValue; @@ -213,7 +215,8 @@ public void testActivateWithoutPreconditions() { SecurityProvider service = context.getService(SecurityProvider.class); assertNotNull(service); - assertEquals(6, Iterables.size(Iterables.filter(service.getConfigurations(), x -> x != null))); + assertEquals(6, Iterables + .size(CollectionUtils.toStream(service.getConfigurations()).filter(Objects::nonNull).collect(Collectors.toList()))); } diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/JcrAllTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/JcrAllTest.java index d40d7c90548..3d56b8abba7 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/JcrAllTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/JcrAllTest.java @@ -18,11 +18,14 @@ import java.util.Arrays; import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + import javax.jcr.security.Privilege; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.api.security.authorization.PrivilegeManager; import org.apache.jackrabbit.oak.AbstractSecurityTest; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.spi.security.authorization.permission.Permissions; import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBits; @@ -66,10 +69,9 @@ public void testAllAggregation() throws Exception { PrivilegeBits all = bitsProvider.getBits(JCR_ALL); PrivilegeManager pMgr = getSecurityProvider().getConfiguration(PrivilegeConfiguration.class).getPrivilegeManager(root, NamePathMapper.DEFAULT); - Iterable declaredAggr = Arrays.asList(pMgr.getPrivilege(JCR_ALL).getDeclaredAggregatePrivileges()); - String[] allAggregates = Iterables.toArray(Iterables.transform( - declaredAggr, - privilege -> requireNonNull(privilege).getName()), String.class); + List declaredAggr = Arrays.asList(pMgr.getPrivilege(JCR_ALL).getDeclaredAggregatePrivileges()); + String[] allAggregates = declaredAggr.stream().map(privilege -> requireNonNull(privilege).getName()) + .collect(Collectors.toList()).toArray(new String[0]); PrivilegeBits all2 = bitsProvider.getBits(allAggregates); assertEquals(all, all2); diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeImplTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeImplTest.java index ddae8eba7b9..1284c60211c 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeImplTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeImplTest.java @@ -16,12 +16,13 @@ */ package org.apache.jackrabbit.oak.security.privilege; +import java.util.Arrays; import java.util.Set; +import java.util.stream.Collectors; + import javax.jcr.security.Privilege; import org.apache.jackrabbit.guava.common.collect.ImmutableList; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.api.security.authorization.PrivilegeManager; import org.apache.jackrabbit.oak.AbstractSecurityTest; import org.apache.jackrabbit.oak.api.Tree; @@ -67,7 +68,7 @@ private static void assertAggregation(@NotNull Privilege[] aggr, @NotNull String assertEquals(expectedNames.length, aggr.length); Set expected = CollectionUtils.toSet(expectedNames); - Set result = CollectionUtils.toSet(Iterables.transform(ImmutableSet.copyOf(aggr), Privilege::getName)); + Set result = Arrays.stream(aggr).map(Privilege::getName).collect(Collectors.toSet()); assertEquals(expected, result); } diff --git a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/CachedGroupPrincipalTest.java b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/CachedGroupPrincipalTest.java index a0b6ad0a94f..180463e9621 100644 --- a/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/CachedGroupPrincipalTest.java +++ b/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/CachedGroupPrincipalTest.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.security.user; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.api.security.principal.GroupPrincipal; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.Group; @@ -24,6 +23,7 @@ import org.apache.jackrabbit.oak.AbstractSecurityTest; import org.apache.jackrabbit.oak.api.ContentSession; import org.apache.jackrabbit.oak.api.Root; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.namepath.NamePathMapper; import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters; import org.apache.jackrabbit.oak.spi.security.authentication.SystemSubject; @@ -77,7 +77,8 @@ public void before() throws Exception { // a) force the cache to be created pp = new UserPrincipalProvider(systemRoot, getUserConfiguration(), namePathMapper); - Iterable principals = Iterables.filter(pp.getPrincipals(userId), new GroupPredicate()::test); + Iterable principals = CollectionUtils + .toIterable(pp.getPrincipals(userId).stream().filter(new GroupPredicate()).iterator()); for (Principal p : principals) { String className = p.getClass().getName(); assertEquals("org.apache.jackrabbit.oak.security.user.UserPrincipalProvider$GroupPrincipalImpl", className); @@ -122,7 +123,8 @@ public void testGroupPrincipals() throws Exception { // b) retrieve principals again (this time from the cache) // -> verify that they are a different implementation - Iterable principalsAgain = Iterables.filter(pp.getPrincipals(userId), new GroupPredicate()::test); + Iterable principalsAgain = CollectionUtils + .toIterable(pp.getPrincipals(userId).stream().filter(new GroupPredicate()).iterator()); for (Principal p : principalsAgain) { String className = p.getClass().getName(); assertEquals("org.apache.jackrabbit.oak.security.user.UserPrincipalProvider$CachedGroupPrincipal", className); @@ -151,7 +153,8 @@ public void testCachedPrincipalsGroupRemoved() throws Exception { // b) retrieve principals again (this time from the cache) // principal for 'testGroup' is no longer backed by an user mgt group // verify that this doesn't lead to runtime exceptions - Iterable principalsAgain = Iterables.filter(pp.getPrincipals(userId), new GroupPredicate()::test); + Iterable principalsAgain = CollectionUtils + .toIterable(pp.getPrincipals(userId).stream().filter(new GroupPredicate()).iterator()); for (Principal p : principalsAgain) { String className = p.getClass().getName(); assertEquals("org.apache.jackrabbit.oak.security.user.UserPrincipalProvider$CachedGroupPrincipal", className); @@ -185,7 +188,8 @@ public void testCachedPrincipalsGroupReplacedByUser() throws Exception { // b) retrieve principals again (this time from the cache) // principal for 'testGroup' is no longer backed by an user mgt group // verify that this doesn't lead to runtime exceptions - Iterable principalsAgain = Iterables.filter(pp.getPrincipals(userId), new GroupPredicate()::test); + Iterable principalsAgain = CollectionUtils + .toIterable(pp.getPrincipals(userId).stream().filter(new GroupPredicate()).iterator()); for (Principal p : principalsAgain) { String className = p.getClass().getName(); assertEquals("org.apache.jackrabbit.oak.security.user.UserPrincipalProvider$CachedGroupPrincipal", className); @@ -214,7 +218,8 @@ public String getOakPath(String jcrPath) { // b) retrieve principals again (this time from the cache) // principal for 'testGroup' is no longer backed by an user mgt group // verify that this doesn't lead to runtime exceptions - Iterable principalsAgain = Iterables.filter(provider.getPrincipals(userId), new GroupPredicate()::test); + Iterable principalsAgain = CollectionUtils + .toIterable(provider.getPrincipals(userId).stream().filter(new GroupPredicate()).iterator()); for (Principal p : principalsAgain) { String className = p.getClass().getName(); assertEquals("org.apache.jackrabbit.oak.security.user.UserPrincipalProvider$CachedGroupPrincipal", className); From 804e154d60c5cc95a3487611fd250c794394d3be Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Mon, 16 Sep 2024 18:12:23 +0100 Subject: [PATCH 10/19] OAK-11100: remove use of Guava transform/filter - oak-exercise --- .../external/CustomExternalIdentityProvider.java | 7 +++---- .../simplifiedroles/ThreeRolesPermissionProvider.java | 4 ++-- .../advanced/L5_CustomPermissionEvaluationTest.java | 3 +-- .../security/privilege/L4_CustomPrivilegeTest.java | 6 ++---- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/oak-exercise/src/main/java/org/apache/jackrabbit/oak/exercise/security/authentication/external/CustomExternalIdentityProvider.java b/oak-exercise/src/main/java/org/apache/jackrabbit/oak/exercise/security/authentication/external/CustomExternalIdentityProvider.java index 80506118915..81d48b22e8a 100644 --- a/oak-exercise/src/main/java/org/apache/jackrabbit/oak/exercise/security/authentication/external/CustomExternalIdentityProvider.java +++ b/oak-exercise/src/main/java/org/apache/jackrabbit/oak/exercise/security/authentication/external/CustomExternalIdentityProvider.java @@ -17,8 +17,6 @@ package org.apache.jackrabbit.oak.exercise.security.authentication.external; import org.apache.jackrabbit.guava.common.collect.ImmutableMap; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalGroup; import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentity; @@ -46,6 +44,7 @@ import java.util.Iterator; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; @Component(service = ExternalIdentityProvider.class, immediate = true, configurationPolicy = ConfigurationPolicy.REQUIRE) @Designate(ocd = CustomExternalIdentityProvider.Configuration.class) @@ -153,8 +152,8 @@ public Iterable getDeclaredGroups() { if (groupIds == null || groupIds.isEmpty()) { return Set.of(); } else { - return Iterables.transform(groupIds, - input -> new ExternalIdentityRef(input, getName())); + return groupIds.stream().map(input -> new ExternalIdentityRef(input, getName())) + .collect(Collectors.toUnmodifiableSet()); } } diff --git a/oak-exercise/src/main/java/org/apache/jackrabbit/oak/exercise/security/authorization/models/simplifiedroles/ThreeRolesPermissionProvider.java b/oak-exercise/src/main/java/org/apache/jackrabbit/oak/exercise/security/authorization/models/simplifiedroles/ThreeRolesPermissionProvider.java index b62101bb2f1..4e91d2960d6 100644 --- a/oak-exercise/src/main/java/org/apache/jackrabbit/oak/exercise/security/authorization/models/simplifiedroles/ThreeRolesPermissionProvider.java +++ b/oak-exercise/src/main/java/org/apache/jackrabbit/oak/exercise/security/authorization/models/simplifiedroles/ThreeRolesPermissionProvider.java @@ -17,7 +17,6 @@ package org.apache.jackrabbit.oak.exercise.security.authorization.models.simplifiedroles; import org.apache.jackrabbit.guava.common.collect.ImmutableSet; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.api.Tree; @@ -39,6 +38,7 @@ import java.security.Principal; import java.util.Set; +import java.util.stream.Collectors; class ThreeRolesPermissionProvider implements AggregatedPermissionProvider, ThreeRolesConstants { @@ -61,7 +61,7 @@ class ThreeRolesPermissionProvider implements AggregatedPermissionProvider, Thre @NotNull String supportedPath, @NotNull Context ctx, @NotNull RootProvider rootProvider) { this.root = root; - this.principalNames = ImmutableSet.copyOf(Iterables.transform(principals, Principal::getName)); + this.principalNames = principals.stream().map(Principal::getName).collect(Collectors.toUnmodifiableSet()); this.supportedPath = supportedPath; this.ctx = ctx; this.rootProvider = rootProvider; diff --git a/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/authorization/advanced/L5_CustomPermissionEvaluationTest.java b/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/authorization/advanced/L5_CustomPermissionEvaluationTest.java index 35c9d8076ac..f272d65bea3 100644 --- a/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/authorization/advanced/L5_CustomPermissionEvaluationTest.java +++ b/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/authorization/advanced/L5_CustomPermissionEvaluationTest.java @@ -25,7 +25,6 @@ import org.apache.jackrabbit.guava.common.collect.ImmutableList; import org.apache.jackrabbit.guava.common.collect.ImmutableSet; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.api.JackrabbitSession; import org.apache.jackrabbit.api.security.authorization.PrivilegeManager; import org.apache.jackrabbit.oak.AbstractSecurityTest; @@ -212,7 +211,7 @@ private PermissionProvider getPermissionProvider(@NotNull Set princip } private Iterable getTreePaths() { - return Iterables.transform(trees, Tree::getPath); + return () -> trees.stream().map(Tree::getPath).iterator(); } private Set getGuestPrincipals() throws Exception { diff --git a/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/privilege/L4_CustomPrivilegeTest.java b/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/privilege/L4_CustomPrivilegeTest.java index 65506fe24fa..d8a42c25c9a 100644 --- a/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/privilege/L4_CustomPrivilegeTest.java +++ b/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/privilege/L4_CustomPrivilegeTest.java @@ -17,15 +17,14 @@ package org.apache.jackrabbit.oak.exercise.security.privilege; import java.security.Principal; +import java.util.Arrays; import java.util.Set; import java.util.UUID; import javax.jcr.security.Privilege; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.api.security.authorization.PrivilegeManager; import org.apache.jackrabbit.oak.AbstractSecurityTest; -import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal; import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants; import org.junit.Test; @@ -116,8 +115,7 @@ private static void assertEqualPrivileges(Set expectedNames, Privilege[] fail(); } - Iterable resultNames = Iterables.transform(CollectionUtils.toSet(result), - Object::toString); + Iterable resultNames = () -> Arrays.asList(result).stream().map(Object::toString).iterator(); Iterables.removeAll(resultNames, expectedNames); assertFalse(resultNames.iterator().hasNext()); From 76cc28b204310f70b1ef93036d05bdec071fd493 Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Mon, 16 Sep 2024 19:38:12 +0100 Subject: [PATCH 11/19] OAK-11100: remove use of Guava transform/filter - oak-it --- .../oak/composite/CompositeNodeStoreTest.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/oak-it/src/test/java/org/apache/jackrabbit/oak/composite/CompositeNodeStoreTest.java b/oak-it/src/test/java/org/apache/jackrabbit/oak/composite/CompositeNodeStoreTest.java index ca16ca15f9c..778ca7fce41 100644 --- a/oak-it/src/test/java/org/apache/jackrabbit/oak/composite/CompositeNodeStoreTest.java +++ b/oak-it/src/test/java/org/apache/jackrabbit/oak/composite/CompositeNodeStoreTest.java @@ -18,7 +18,6 @@ */ package org.apache.jackrabbit.oak.composite; -import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; import static org.apache.jackrabbit.guava.common.collect.Lists.newArrayList; import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME; import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.createIndexDefinition; @@ -43,6 +42,7 @@ import java.util.Objects; import java.util.Set; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; import javax.sql.DataSource; @@ -52,6 +52,7 @@ import org.apache.jackrabbit.oak.api.Blob; import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.api.Type; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore; import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreBuilder; import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDataSourceFactory; @@ -650,14 +651,14 @@ public void duplicatedChildren() throws CommitFailedException { deepMountBuilder.child("new").setProperty("store", "deepMounted", Type.STRING); deepMountedStore.merge(deepMountBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY); - List children = newArrayList(filter(store.getRoot().getChildNodeEntries(), - x -> Objects.equals(x == null ? null : x.getName(), "new"))); + List children = CollectionUtils.toStream(store.getRoot().getChildNodeEntries()) + .filter(x -> Objects.equals(x == null ? null : x.getName(), "new")).collect(Collectors.toList()); assertEquals(1, children.size()); assertEquals("global", children.get(0).getNodeState().getString("store")); NodeBuilder rootBuilder = store.getRoot().builder(); - List childNames = newArrayList(filter(rootBuilder.getChildNodeNames(), - x -> Objects.equals(x, "new"))); + List childNames = CollectionUtils.toStream(rootBuilder.getChildNodeNames()).filter("new"::equals) + .collect(Collectors.toList()); assertEquals(1, childNames.size()); assertEquals("global", rootBuilder.getChildNode("new").getString("store")); } From ad6ed68baf0533c5e4936aaaea68d153e23e0c31 Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Mon, 16 Sep 2024 21:37:21 +0100 Subject: [PATCH 12/19] OAK-11100: remove use of Guava transform/filter - oak-jcr --- .../jackrabbit/oak/jcr/session/NodeImpl.java | 30 ++++++++----------- .../jackrabbit/oak/jcr/xml/ImporterImpl.java | 11 +++---- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java index fc8423f2f8e..10b485e9901 100644 --- a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java +++ b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java @@ -20,7 +20,6 @@ import static java.util.Arrays.asList; import static java.util.Collections.singleton; import static java.util.Objects.requireNonNull; -import static org.apache.jackrabbit.guava.common.collect.Iterators.transform; import static org.apache.jackrabbit.guava.common.collect.Sets.newLinkedHashSet; import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES; import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE; @@ -67,7 +66,6 @@ import javax.jcr.version.VersionException; import javax.jcr.version.VersionHistory; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Iterators; import org.apache.jackrabbit.guava.common.collect.Lists; import org.apache.jackrabbit.JcrConstants; @@ -81,6 +79,7 @@ import org.apache.jackrabbit.oak.api.Type; import org.apache.jackrabbit.oak.commons.LazyValue; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate; import org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate; import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate; @@ -804,15 +803,12 @@ public PropertyIterator perform() throws InvalidItemStateException { IdentifierManager idManager = sessionDelegate.getIdManager(); Iterable propertyOakPaths = idManager.getReferences(weak, node.getTree(), name); // TODO: oak name? - Iterable properties = Iterables.transform( - propertyOakPaths, - oakPath -> { - PropertyDelegate pd = sessionDelegate.getProperty(oakPath); - return pd == null ? null : new PropertyImpl(pd, sessionContext); - } - ); + Iterator properties = CollectionUtils.toStream(propertyOakPaths).map(oakPath -> { + PropertyDelegate pd = sessionDelegate.getProperty(oakPath); + return pd == null ? null : new PropertyImpl(pd, sessionContext); + }).iterator(); - return new PropertyIteratorAdapter(sessionDelegate.sync(properties.iterator())); + return new PropertyIteratorAdapter(sessionDelegate.sync(properties)); } }); } @@ -1351,16 +1347,14 @@ private EffectiveNodeType getEffectiveNodeType() throws RepositoryException { return getNodeTypeManager().getEffectiveNodeType(dlg.getTree()); } - private Iterator nodeIterator(Iterator childNodes) { - return sessionDelegate.sync(transform( - childNodes, - nodeDelegate -> new NodeImpl(nodeDelegate, sessionContext))); + private Iterator nodeIterator(Iterator childNodes) { + return sessionDelegate.sync(CollectionUtils.toStream(childNodes) + .map(nodeDelegate -> new NodeImpl(nodeDelegate, sessionContext)).iterator()); } - private Iterator propertyIterator(Iterator properties) { - return sessionDelegate.sync(transform( - properties, - propertyDelegate -> new PropertyImpl(propertyDelegate, sessionContext))); + private Iterator propertyIterator(Iterator properties) { + return sessionDelegate.sync(CollectionUtils.toStream(properties) + .map(propertyDelegate -> new PropertyImpl(propertyDelegate, sessionContext)).iterator()); } private void checkValidWorkspace(String workspaceName) diff --git a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java index b74de0f0c34..6aa68b1ba86 100644 --- a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java +++ b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java @@ -20,9 +20,11 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Objects; import java.util.Set; import java.util.Stack; import java.util.UUID; +import java.util.stream.Collectors; import javax.jcr.ImportUUIDBehavior; import javax.jcr.ItemExistsException; @@ -36,7 +38,6 @@ import javax.jcr.nodetype.PropertyDefinition; import javax.jcr.version.VersionException; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Lists; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.oak.api.ContentSession; @@ -297,23 +298,23 @@ private void importProperties(@NotNull Tree tree, } private Iterable getPropertyImporters() { - return Iterables.filter(Iterables.transform(pItemImporters, importer -> { + return pItemImporters.stream().map(importer -> { if (importer instanceof ProtectedPropertyImporter) { return (ProtectedPropertyImporter) importer; } else { return null; } - }), x -> x != null); + }).filter(Objects::nonNull).collect(Collectors.toList()); } private Iterable getNodeImporters() { - return Iterables.filter(Iterables.transform(pItemImporters, importer -> { + return pItemImporters.stream().map(importer -> { if (importer instanceof ProtectedNodeImporter) { return (ProtectedNodeImporter) importer; } else { return null; } - }), x -> x != null); + }).filter(Objects::nonNull).collect(Collectors.toList()); } //-----------------------------------------------------------< Importer >--- From c9849584df03c166716123436733e9d02ac3da9e Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Tue, 17 Sep 2024 07:22:50 +0100 Subject: [PATCH 13/19] OAK-11100: remove use of Guava transform/filter - oak-lucene --- .../lucene/ActiveDeletedBlobCollectorMBeanImpl.java | 8 ++++---- .../oak/plugins/index/lucene/IndexCopier.java | 10 +++------- .../index/lucene/hybrid/LuceneDocumentHolder.java | 5 +++-- .../plugins/index/lucene/property/BucketSwitcher.java | 9 +++++---- .../lucene/property/HybridPropertyIndexInfo.java | 5 ++--- .../lucene/property/HybridPropertyIndexLookup.java | 11 ++++++----- .../index/lucene/property/RecursiveDeleteTest.java | 8 +++++--- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/ActiveDeletedBlobCollectorMBeanImpl.java b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/ActiveDeletedBlobCollectorMBeanImpl.java index 2e882601142..e12a7fa62ad 100644 --- a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/ActiveDeletedBlobCollectorMBeanImpl.java +++ b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/ActiveDeletedBlobCollectorMBeanImpl.java @@ -24,6 +24,7 @@ import org.apache.jackrabbit.oak.api.jmx.CheckpointMBean; import org.apache.jackrabbit.oak.api.jmx.IndexStatsMBean; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.commons.jmx.ManagementOperation; import org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfoService; import org.apache.jackrabbit.oak.plugins.index.IndexPathService; @@ -48,10 +49,9 @@ import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; -import java.util.stream.StreamSupport; import static java.util.Objects.requireNonNull; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; + import static org.apache.jackrabbit.oak.api.Type.STRING; import static org.apache.jackrabbit.oak.api.jmx.IndexStatsMBean.STATUS_RUNNING; import static org.apache.jackrabbit.oak.commons.jmx.ManagementOperation.Status.failed; @@ -213,7 +213,7 @@ public void flagActiveDeletionSafe() { */ private boolean waitForRunningIndexCycles() { Map origIndexLaneToExecutinoCountMap = Maps.asMap( - new HashSet<>(StreamSupport.stream(asyncIndexInfoService.getAsyncLanes().spliterator(), false) + new HashSet<>(CollectionUtils.toStream(asyncIndexInfoService.getAsyncLanes()) .map(lane -> asyncIndexInfoService.getInfo(lane).getStatsMBean()) .filter(bean -> { String beanStatus; @@ -234,7 +234,7 @@ private boolean waitForRunningIndexCycles() { if (!origIndexLaneToExecutinoCountMap.isEmpty()) { LOG.info("Found running index lanes ({}). Sleep a bit before continuing.", - transform(origIndexLaneToExecutinoCountMap.keySet(), IndexStatsMBean::getName)); + origIndexLaneToExecutinoCountMap.keySet().stream().map(IndexStatsMBean::getName).collect(Collectors.toList())); try { clock.waitUntil(clock.getTime() + TimeUnit.SECONDS.toMillis(1)); } catch (InterruptedException e) { diff --git a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexCopier.java b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexCopier.java index 4d0d874ce81..7278a0d4cc2 100644 --- a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexCopier.java +++ b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexCopier.java @@ -40,7 +40,6 @@ import javax.management.openmbean.TabularDataSupport; import javax.management.openmbean.TabularType; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.guava.common.collect.Sets; import org.apache.jackrabbit.guava.common.util.concurrent.Monitor; import org.apache.commons.io.FileUtils; @@ -61,8 +60,7 @@ import org.slf4j.LoggerFactory; import static org.apache.jackrabbit.guava.common.base.Preconditions.checkState; -import static org.apache.jackrabbit.guava.common.collect.Iterables.toArray; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; + import static org.apache.jackrabbit.guava.common.collect.Maps.newConcurrentMap; import static org.apache.jackrabbit.oak.commons.IOUtils.humanReadableByteCount; @@ -609,8 +607,7 @@ public long getLocalIndexDirSize() { @Override public String[] getGarbageDetails() { - return toArray(transform(failedToDeleteFiles.values(), - input -> input.deleteLog()), String.class); + return failedToDeleteFiles.values().stream().map(input -> input.deleteLog()).toArray(String[]::new); } @Override @@ -653,8 +650,7 @@ public String getSkippedFromUploadSize() { @Override public String[] getCopyInProgressDetails() { - return toArray(transform(copyInProgressFiles, - input -> input.copyLog()), String.class); + return copyInProgressFiles.stream().map(input -> input.copyLog()).toArray(String[]::new); } @Override diff --git a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/LuceneDocumentHolder.java b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/LuceneDocumentHolder.java index d436833d6d9..ac67300007c 100644 --- a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/LuceneDocumentHolder.java +++ b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/hybrid/LuceneDocumentHolder.java @@ -20,6 +20,7 @@ import java.util.Collection; import java.util.Map; +import java.util.stream.Collectors; import org.apache.jackrabbit.guava.common.collect.ArrayListMultimap; import org.apache.jackrabbit.guava.common.collect.Iterables; @@ -115,7 +116,7 @@ private boolean queueSizeWithinLimits(){ } private static Iterable asLuceneDocInfo(ListMultimap docs) { - return Iterables.transform(docs.entries(), input -> { + return docs.entries().stream().map(input -> { return new LuceneDocInfo() { @Override public String getIndexPath() { @@ -127,6 +128,6 @@ public String getDocPath() { return input.getValue(); } }; - }); + }).collect(Collectors.toList()); } } diff --git a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/BucketSwitcher.java b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/BucketSwitcher.java index ea11e914a31..5c53793534e 100644 --- a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/BucketSwitcher.java +++ b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/BucketSwitcher.java @@ -20,10 +20,11 @@ package org.apache.jackrabbit.oak.plugins.index.lucene.property; import java.util.Objects; +import java.util.stream.Collectors; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Type; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.state.NodeBuilder; import static org.apache.jackrabbit.oak.plugins.index.lucene.property.HybridPropertyIndexUtil.PROP_ASYNC_INDEXED_TO_TIME_AT_SWITCH; @@ -97,9 +98,9 @@ public boolean switchBucket(long lastIndexedTo) { public Iterable getOldBuckets() { String head = builder.getString(PROP_HEAD_BUCKET); String previous = builder.getString(PROP_PREVIOUS_BUCKET); - return Iterables.filter(builder.getChildNodeNames(), - name -> !Objects.equals(name, head) && !Objects.equals(name, previous) - ); + return CollectionUtils.toStream(builder.getChildNodeNames()) + .filter(name -> !Objects.equals(name, head) && !Objects.equals(name, previous)).collect(Collectors.toList()); + } private boolean asyncIndexedToTimeSameAsPrevious(long lastIndexedTo) { diff --git a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/HybridPropertyIndexInfo.java b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/HybridPropertyIndexInfo.java index bf81faced52..bcb5f7b9443 100644 --- a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/HybridPropertyIndexInfo.java +++ b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/HybridPropertyIndexInfo.java @@ -16,14 +16,13 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.jackrabbit.oak.plugins.index.lucene.property; import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.TreeTraverser; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.commons.json.JsopBuilder; import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry; import org.apache.jackrabbit.oak.spi.state.NodeState; @@ -91,7 +90,7 @@ private void collectCounts(NodeState bucket) { TreeTraverser t = new TreeTraverser() { @Override public Iterable children(NodeState root) { - return Iterables.transform(root.getChildNodeEntries(), ChildNodeEntry::getNodeState); + return () -> CollectionUtils.toStream(root.getChildNodeEntries()).map(ChildNodeEntry::getNodeState).iterator(); } }; AtomicInteger matches = new AtomicInteger(); diff --git a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/HybridPropertyIndexLookup.java b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/HybridPropertyIndexLookup.java index d6cd834c55a..b80a74b3aa3 100644 --- a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/HybridPropertyIndexLookup.java +++ b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/HybridPropertyIndexLookup.java @@ -16,11 +16,11 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.jackrabbit.oak.plugins.index.lucene.property; import java.util.Collections; import java.util.Set; +import java.util.stream.Collectors; import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.oak.api.PropertyValue; @@ -35,7 +35,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; + import static org.apache.jackrabbit.oak.commons.PathUtils.isAbsolute; import static org.apache.jackrabbit.oak.plugins.index.lucene.property.HybridPropertyIndexUtil.PROPERTY_INDEX; import static org.apache.jackrabbit.oak.plugins.index.lucene.property.HybridPropertyIndexUtil.PROP_HEAD_BUCKET; @@ -102,13 +102,14 @@ private Iterable query(Filter filter, String propertyName, Set e result = querySimple(filter, indexName, propIndexNode, encodedValues); } - Iterable paths = transform(result, path -> isAbsolute(path) ? path : "/" + path); + Iterable paths = CollectionUtils.toStream(result).map(path -> isAbsolute(path) ? path : "/" + path) + .collect(Collectors.toList()); if (log.isTraceEnabled()) { - paths = transform(paths, path -> { + paths = CollectionUtils.toStream(paths).map(path -> { log.trace("[{}] {} = {} -> {}", indexPath, propertyName, encodedValues, path); return path; - }); + }).collect(Collectors.toList()); } return paths; } diff --git a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/RecursiveDeleteTest.java b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/RecursiveDeleteTest.java index 34c604c258a..c153a0ca1fb 100644 --- a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/RecursiveDeleteTest.java +++ b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/property/RecursiveDeleteTest.java @@ -25,9 +25,9 @@ import java.util.Random; import java.util.concurrent.atomic.AtomicInteger; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.TreeTraverser; import org.apache.jackrabbit.oak.api.CommitFailedException; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.fixture.DocumentMemoryFixture; import org.apache.jackrabbit.oak.fixture.MemoryFixture; import org.apache.jackrabbit.oak.fixture.NodeStoreFixture; @@ -46,7 +46,9 @@ import static java.util.Arrays.asList; import static org.apache.jackrabbit.oak.spi.state.NodeStateUtils.getNode; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; @RunWith(Parameterized.class) public class RecursiveDeleteTest { @@ -152,7 +154,7 @@ private int getSubtreeCount(NodeState state){ TreeTraverser t = new TreeTraverser() { @Override public Iterable children(NodeState root) { - return Iterables.transform(root.getChildNodeEntries(), ChildNodeEntry::getNodeState); + return () -> CollectionUtils.toStream(root.getChildNodeEntries()).map(ChildNodeEntry::getNodeState).iterator(); } }; return t.preOrderTraversal(state).size(); From f07a446ad1d13f249c60ad90496ec91cbe2802d1 Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Tue, 17 Sep 2024 09:07:43 +0100 Subject: [PATCH 14/19] OAK-11100: remove use of Guava transform/filter - oak-run-commons --- .../document/NodeStateEntryTraverser.java | 23 ++++++++----------- .../document/DocumentNodeStoreHelper.java | 6 ++--- .../indexer/document/flatfile/TestUtils.java | 4 +--- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/NodeStateEntryTraverser.java b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/NodeStateEntryTraverser.java index 65bf0a678f1..5e76d1e8167 100644 --- a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/NodeStateEntryTraverser.java +++ b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/NodeStateEntryTraverser.java @@ -16,11 +16,11 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.jackrabbit.oak.index.indexer.document; import org.apache.jackrabbit.guava.common.collect.FluentIterable; import org.apache.jackrabbit.guava.common.io.Closer; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.document.Collection; import org.apache.jackrabbit.oak.plugins.document.DocumentNodeState; import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore; @@ -41,7 +41,6 @@ import static java.util.Collections.emptyList; import static java.util.Collections.singleton; import static org.apache.jackrabbit.guava.common.collect.Iterables.concat; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; public class NodeStateEntryTraverser implements Iterable, Closeable { private final Closer closer = Closer.create(); @@ -123,18 +122,14 @@ private Iterable getEntries(NodeDocument doc) { return emptyList(); } - return transform( - concat(singleton(nodeState), - nodeState.getAllBundledNodesStates()), - dns -> { - NodeStateEntry.NodeStateEntryBuilder builder = new NodeStateEntry.NodeStateEntryBuilder(dns, dns.getPath().toString()); - if (doc.getModified() != null) { - builder.withLastModified(doc.getModified()); - } - builder.withID(doc.getId()); - return builder.build(); - } - ); + return () -> CollectionUtils.toStream(concat(singleton(nodeState), nodeState.getAllBundledNodesStates())).map(dns -> { + NodeStateEntry.NodeStateEntryBuilder builder = new NodeStateEntry.NodeStateEntryBuilder(dns, dns.getPath().toString()); + if (doc.getModified() != null) { + builder.withLastModified(doc.getModified()); + } + builder.withID(doc.getId()); + return builder.build(); + }).iterator(); } private Iterable getDocsFilteredByPath() { diff --git a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreHelper.java b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreHelper.java index 448a0d644dc..f97ae9d899e 100644 --- a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreHelper.java +++ b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreHelper.java @@ -29,6 +29,7 @@ import org.apache.jackrabbit.oak.api.Blob; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Type; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.commons.json.JsopReader; import org.apache.jackrabbit.oak.commons.json.JsopTokenizer; import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore; @@ -37,7 +38,6 @@ import org.bson.conversions.Bson; import org.apache.jackrabbit.guava.common.base.Stopwatch; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Lists; import org.apache.jackrabbit.guava.common.primitives.Longs; import com.mongodb.BasicDBObject; @@ -153,8 +153,8 @@ private static Iterable getDocuments(DocumentStore store) { mds, Collection.NODES); Bson query = Filters.eq(NodeDocument.HAS_BINARY_FLAG, NodeDocument.HAS_BINARY_VAL); FindIterable cursor = dbCol.find(query); - return Iterables.transform(cursor, - input -> MongoDocumentStoreHelper.convertFromDBObject(mds, Collection.NODES, input)); + return () -> CollectionUtils.toStream(cursor) + .map(input -> MongoDocumentStoreHelper.convertFromDBObject(mds, Collection.NODES, input)).iterator(); } else { return Utils.getSelectedDocuments(store, NodeDocument.HAS_BINARY_FLAG, NodeDocument.HAS_BINARY_VAL); diff --git a/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/TestUtils.java b/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/TestUtils.java index 9373ab4333c..a55242a97fc 100644 --- a/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/TestUtils.java +++ b/oak-run-commons/src/test/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/TestUtils.java @@ -16,11 +16,9 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.jackrabbit.oak.index.indexer.document.flatfile; import org.apache.jackrabbit.guava.common.base.Joiner; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.oak.index.indexer.document.NodeStateEntry; import org.apache.jackrabbit.oak.index.indexer.document.NodeStateEntry.NodeStateEntryBuilder; import org.apache.jackrabbit.oak.spi.state.NodeBuilder; @@ -65,7 +63,7 @@ static CountingIterable createList(Set preferred, List createEntries(List paths) { - return Iterables.transform(paths, p -> new NodeStateEntryBuilder(createNodeState(p), p).withID(getID(p)).build()); + return () -> paths.stream().map(p -> new NodeStateEntryBuilder(createNodeState(p), p).withID(getID(p)).build()).iterator(); } static String getID(String path) { From 582caf47962281379a33e8d75ac94779ecf38ebf Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Tue, 17 Sep 2024 10:44:38 +0100 Subject: [PATCH 15/19] OAK-11100: remove use of Guava transform/filter - oak-run --- .../mongo/MongoDocumentStoreCheckHelper.java | 14 +++++++------- .../apache/jackrabbit/oak/run/PrintingDiff.java | 5 +++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreCheckHelper.java b/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreCheckHelper.java index 4944e72764b..d2839aa0a38 100644 --- a/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreCheckHelper.java +++ b/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStoreCheckHelper.java @@ -18,13 +18,14 @@ import com.mongodb.DBObject; +import java.util.stream.Collectors; + +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.document.Collection; import org.apache.jackrabbit.oak.plugins.document.NodeDocument; import org.bson.BsonDocument; import org.bson.BsonInt32; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; - /** * MongoDocumentStoreCheckHelper... */ @@ -35,10 +36,9 @@ public static long getEstimatedDocumentCount(MongoDocumentStore store) { } public static Iterable getAllNodeDocuments(MongoDocumentStore store) { - return transform(store.getDBCollection(Collection.NODES) - .find(DBObject.class) - .sort(new BsonDocument("$natural", new BsonInt32(1))), - input -> store.convertFromDBObject(Collection.NODES, input) - ); + return CollectionUtils.toStream( + store.getDBCollection(Collection.NODES).find(DBObject.class).sort(new BsonDocument("$natural", new BsonInt32(1))) + .map(input -> store.convertFromDBObject(Collection.NODES, input))) + .collect(Collectors.toList()); } } diff --git a/oak-run/src/main/java/org/apache/jackrabbit/oak/run/PrintingDiff.java b/oak-run/src/main/java/org/apache/jackrabbit/oak/run/PrintingDiff.java index 1bda8da88e1..e5c46f93360 100644 --- a/oak-run/src/main/java/org/apache/jackrabbit/oak/run/PrintingDiff.java +++ b/oak-run/src/main/java/org/apache/jackrabbit/oak/run/PrintingDiff.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.run; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; import static org.apache.commons.io.FileUtils.byteCountToDisplaySize; import static org.apache.jackrabbit.oak.api.Type.BINARIES; import static org.apache.jackrabbit.oak.api.Type.BINARY; @@ -28,9 +27,11 @@ import java.io.PrintWriter; import java.util.function.Function; +import java.util.stream.Collectors; import org.apache.jackrabbit.oak.api.Blob; import org.apache.jackrabbit.oak.api.PropertyState; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.state.NodeState; import org.apache.jackrabbit.oak.spi.state.NodeStateDiff; @@ -126,7 +127,7 @@ private static String toString(PropertyState ps) { String v = BLOB_LENGTH.apply(ps.getValue(BINARY)); val.append(" = {").append(v).append("}"); } else if (ps.getType() == BINARIES) { - String v = transform(ps.getValue(BINARIES), BLOB_LENGTH::apply).toString(); + String v = CollectionUtils.toStream(ps.getValue(BINARIES)).map(BLOB_LENGTH).collect(Collectors.toList()).toString(); val.append("[").append(ps.count()).append("] = ").append(v); } else if (ps.isArray()) { val.append("[").append(ps.count()).append("] = ").append(ps.getValue(STRINGS)); From f1412940881318aa82974833752a63a1d58c86de Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Fri, 20 Sep 2024 08:32:45 +0100 Subject: [PATCH 16/19] OAK-11100: remove use of Guava transform/filter - oak-search --- .../oak/plugins/index/search/AggregateTest.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/search/AggregateTest.java b/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/search/AggregateTest.java index 38ac728f152..8d0a2ef8575 100644 --- a/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/search/AggregateTest.java +++ b/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/search/AggregateTest.java @@ -29,11 +29,11 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.jackrabbit.guava.common.collect.ArrayListMultimap; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.ListMultimap; import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.oak.api.Type; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.index.search.Aggregate.NodeInclude; import org.apache.jackrabbit.oak.plugins.index.search.Aggregate.NodeIncludeResult; import org.apache.jackrabbit.oak.plugins.index.search.Aggregate.PropertyIncludeResult; @@ -104,11 +104,12 @@ public void noOfChildNodeRead() { NodeState state = nb.getNodeState(); final AtomicInteger counter = new AtomicInteger(); - Iterable countingIterator = Iterables.transform(state.getChildNodeEntries(), - input -> { + Iterable countingIterator = CollectionUtils + .toIterable(CollectionUtils.toStream(state.getChildNodeEntries()).map(input -> { counter.incrementAndGet(); + System.out.println(input); return input; - }); + }).iterator()); NodeState mocked = spy(state); doReturn(countingIterator).when(mocked).getChildNodeEntries(); ag.collectAggregates(mocked, col); From 68000c1faba7071eca362a112bb6851ea26d1bbb Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Fri, 20 Sep 2024 17:33:44 +0100 Subject: [PATCH 17/19] OAK-11100: remove use of Guava transform/filter - oak-segment-tar --- .../jackrabbit/oak/segment/tool/PrintingDiff.java | 6 +++--- .../jackrabbit/oak/segment/upgrade/UpgradeIT.java | 11 ++++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/PrintingDiff.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/PrintingDiff.java index 3cea0f777d8..f70521073ec 100644 --- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/PrintingDiff.java +++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/tool/PrintingDiff.java @@ -14,10 +14,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.jackrabbit.oak.segment.tool; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; import static org.apache.commons.io.FileUtils.byteCountToDisplaySize; import static org.apache.jackrabbit.oak.api.Type.BINARIES; import static org.apache.jackrabbit.oak.api.Type.BINARY; @@ -29,9 +27,11 @@ import java.io.PrintWriter; import java.util.function.Function; +import java.util.stream.Collectors; import org.apache.jackrabbit.oak.api.Blob; import org.apache.jackrabbit.oak.api.PropertyState; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.spi.state.NodeState; import org.apache.jackrabbit.oak.spi.state.NodeStateDiff; @@ -112,7 +112,7 @@ private static String toString(PropertyState ps) { String v = BLOB_LENGTH.apply(ps.getValue(BINARY)); val.append(" = {").append(v).append("}"); } else if (ps.getType() == BINARIES) { - String v = transform(ps.getValue(BINARIES), BLOB_LENGTH::apply).toString(); + String v = CollectionUtils.toStream(ps.getValue(BINARIES)).map(BLOB_LENGTH).collect(Collectors.toList()).toString(); val.append("[").append(ps.count()).append("] = ").append(v); } else if (ps.isArray()) { val.append("[").append(ps.count()).append("] = ").append(ps.getValue(STRINGS)); diff --git a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java index ca99eff4f3e..e337e64c9b2 100644 --- a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java +++ b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/upgrade/UpgradeIT.java @@ -15,10 +15,8 @@ * limitations under the License. * */ - package org.apache.jackrabbit.oak.segment.upgrade; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; import static java.lang.String.format; import static java.util.concurrent.TimeUnit.MINUTES; import static org.apache.jackrabbit.oak.segment.SegmentVersion.V_12; @@ -36,6 +34,7 @@ import org.apache.commons.lang3.JavaVersion; import org.apache.commons.lang3.SystemUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.segment.SegmentVersion; import org.apache.jackrabbit.oak.segment.data.SegmentData; import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException; @@ -151,10 +150,8 @@ private void checkSegmentVersion(@NotNull SegmentVersion version) throws IOExcep } private static Iterable getSegments(@NotNull TarFiles tarFiles) { - return transform( - tarFiles.getSegmentIds(), - uuid -> newSegmentData(tarFiles.readSegment( - uuid.getMostSignificantBits(), - uuid.getLeastSignificantBits()))); + return () -> CollectionUtils.toStream(tarFiles.getSegmentIds()) + .map(uuid -> newSegmentData(tarFiles.readSegment(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits()))) + .iterator(); } } From 3edf33b3c3d248a42a5c6ece297f1014310193c3 Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Sat, 21 Sep 2024 15:22:37 +0100 Subject: [PATCH 18/19] OAK-11100: remove use of Guava transform/filter - oak-store-composite --- .../oak/composite/CompositeNodeStore.java | 6 ++---- .../oak/composite/CompositeChildrenCountTest.java | 14 +++++++------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CompositeNodeStore.java b/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CompositeNodeStore.java index 60949fe351a..b62e6028532 100644 --- a/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CompositeNodeStore.java +++ b/oak-store-composite/src/main/java/org/apache/jackrabbit/oak/composite/CompositeNodeStore.java @@ -57,8 +57,6 @@ import static org.apache.jackrabbit.guava.common.base.Preconditions.checkArgument; import static java.util.Objects.requireNonNull; import static org.apache.jackrabbit.guava.common.collect.ImmutableMap.copyOf; - -import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; import static org.apache.jackrabbit.guava.common.collect.Maps.filterKeys; import static java.lang.System.currentTimeMillis; @@ -208,8 +206,8 @@ public Blob getBlob(String reference) { public Iterable checkpoints() { final NodeStore globalNodeStore = ctx.getGlobalStore().getNodeStore(); - return filter(globalNodeStore.checkpoints(), - checkpoint -> isCompositeCheckpoint(checkpoint)); + return () -> CollectionUtils.toStream(globalNodeStore.checkpoints()).filter(checkpoint -> isCompositeCheckpoint(checkpoint)) + .iterator(); } private boolean isCompositeCheckpoint(String checkpoint) { diff --git a/oak-store-composite/src/test/java/org/apache/jackrabbit/oak/composite/CompositeChildrenCountTest.java b/oak-store-composite/src/test/java/org/apache/jackrabbit/oak/composite/CompositeChildrenCountTest.java index 416a773221e..2fa319ece89 100644 --- a/oak-store-composite/src/test/java/org/apache/jackrabbit/oak/composite/CompositeChildrenCountTest.java +++ b/oak-store-composite/src/test/java/org/apache/jackrabbit/oak/composite/CompositeChildrenCountTest.java @@ -18,10 +18,10 @@ */ package org.apache.jackrabbit.oak.composite; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Lists; import org.apache.jackrabbit.oak.api.PropertyState; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState; import org.apache.jackrabbit.oak.plugins.memory.MemoryChildNodeEntry; import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder; @@ -42,7 +42,6 @@ import static org.apache.jackrabbit.guava.common.collect.Iterables.cycle; import static org.apache.jackrabbit.guava.common.collect.Iterables.limit; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; import static java.lang.Long.MAX_VALUE; import static java.util.Arrays.asList; @@ -223,7 +222,8 @@ public Iterable getChildNodeEntries() { Iterable childrenIterable = cycle(new MemoryChildNodeEntry("child", EMPTY_NODE)); return asCountingIterable(limit(childrenIterable, childrenCount == MAX_VALUE ? 1000 : (int) childrenCount)); } else { - return asCountingIterable(transform(asList(children), input -> new MemoryChildNodeEntry(input, EMPTY_NODE))); + return asCountingIterable( + () -> asList(children).stream().map(input -> new MemoryChildNodeEntry(input, EMPTY_NODE)).iterator()); } } @@ -239,10 +239,10 @@ public NodeBuilder builder() { } private Iterable asCountingIterable(Iterable input) { - return Iterables.transform(input, inp -> { - fetchedChildren++; - return inp; - }); + return () -> CollectionUtils.toStream(input).map(inp -> { + fetchedChildren++; + return inp; + }).iterator(); } } } From e74d23e99100e7f66abeef1b352457171d5609c2 Mon Sep 17 00:00:00 2001 From: Julian Reschke Date: Tue, 24 Sep 2024 14:14:40 +0100 Subject: [PATCH 19/19] OAK-11100: remove use of Guava transform/filter - oak-store-document (wip) --- .../oak/plugins/document/Branch.java | 18 +++------- .../oak/plugins/document/Commit.java | 7 ++-- .../plugins/document/DocumentNodeState.java | 35 +++++++++++-------- .../plugins/document/DocumentNodeStore.java | 14 ++++---- .../document/DocumentNodeStoreBranch.java | 3 +- .../document/DocumentNodeStoreMBeanImpl.java | 19 ++++------ .../document/LastRevRecoveryAgent.java | 13 ++++--- .../plugins/document/MissingBcSweeper2.java | 7 ++-- .../document/MissingLastRevSeeker.java | 14 ++++---- .../oak/plugins/document/NodeDocument.java | 23 ++++++------ .../plugins/document/NodeDocumentSweeper.java | 14 ++++---- .../oak/plugins/document/PropertyHistory.java | 30 ++++++++-------- .../document/UnsavedModifications.java | 5 ++- .../plugins/document/VersionGCSupport.java | 18 +++++----- .../document/mongo/MongoDocumentStore.java | 13 ++++--- .../mongo/MongoMissingLastRevSeeker.java | 8 ++--- .../document/mongo/MongoVersionGCSupport.java | 17 +++++---- .../document/persistentCache/NodeCache.java | 6 ++-- .../document/rdb/RDBDocumentStoreJDBC.java | 5 ++- .../document/rdb/RDBVersionGCSupport.java | 11 +++--- .../DelegatingDocumentNodeState.java | 11 ++++-- .../oak/plugins/document/util/Utils.java | 8 ++--- ...goVersionGCSupportDefaultNoBranchTest.java | 6 ++-- .../document/VersionGarbageCollectorIT.java | 31 ++++++++-------- 24 files changed, 162 insertions(+), 174 deletions(-) diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Branch.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Branch.java index a57436e3c26..af389d685d4 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Branch.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Branch.java @@ -18,8 +18,6 @@ import static org.apache.jackrabbit.guava.common.base.Preconditions.checkArgument; import static java.util.Objects.requireNonNull; -import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; @@ -31,7 +29,6 @@ import java.util.SortedSet; import java.util.TreeMap; import java.util.concurrent.ConcurrentSkipListMap; -import java.util.function.Predicate; import org.apache.jackrabbit.guava.common.collect.Iterables; @@ -271,14 +268,9 @@ Iterable getModifiedPathsUntil(@NotNull final Revision r) { if (!commits.containsKey(r)) { return Collections.emptyList(); } - Iterable> paths = transform(filter(commits.entrySet(), - new Predicate>() { - @Override - public boolean test(Map.Entry input) { - return !input.getValue().isRebase() - && input.getKey().compareRevisionTime(r) <= 0; - } - }::test), input -> input.getValue().getModifiedPaths()); + Iterable> paths = () -> commits.entrySet().stream() + .filter(input -> !input.getValue().isRebase() && input.getKey().compareRevisionTime(r) <= 0) + .map(input -> input.getValue().getModifiedPaths()).iterator(); return Iterables.concat(paths); } @@ -405,8 +397,8 @@ protected boolean isRebase() { @Override Iterable getModifiedPaths() { - Iterable> paths = transform(previous.values(), - branchCommit -> branchCommit.getModifiedPaths()); + Iterable> paths = () -> previous.values().stream().map(branchCommit -> branchCommit.getModifiedPaths()) + .iterator(); return Iterables.concat(paths); } diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java index 8ff6f8fc08a..c01559c7db6 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java @@ -31,7 +31,6 @@ import java.util.concurrent.TimeUnit; import org.apache.jackrabbit.guava.common.collect.Iterables; -import org.apache.jackrabbit.guava.common.collect.Sets; import org.apache.jackrabbit.oak.commons.json.JsopStream; import org.apache.jackrabbit.oak.commons.json.JsopWriter; import org.apache.jackrabbit.oak.plugins.document.UpdateOp.Key; @@ -43,8 +42,7 @@ import org.slf4j.LoggerFactory; import static java.util.Objects.requireNonNull; -import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; + import static org.apache.jackrabbit.guava.common.collect.Lists.partition; import static java.util.Collections.singletonList; import static org.apache.jackrabbit.oak.plugins.document.Collection.JOURNAL; @@ -891,7 +889,6 @@ private boolean isBundled(Path path) { } private static boolean hasContentChanges(UpdateOp op) { - return filter(transform(op.getChanges().keySet(), - input -> input.getName()), Utils.PROPERTY_OR_DELETED::test).iterator().hasNext(); + return op.getChanges().keySet().stream().map(Key::getName).filter(Utils.PROPERTY_OR_DELETED).iterator().hasNext(); } } diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java index 647ef9fe0d5..bb0a840c8f3 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java @@ -23,11 +23,13 @@ import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; +import java.util.function.Function; import org.apache.jackrabbit.guava.common.collect.ImmutableMap; import org.apache.jackrabbit.guava.common.collect.TreeTraverser; import org.apache.jackrabbit.oak.api.Type; import org.apache.jackrabbit.oak.cache.CacheValue; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.commons.json.JsopBuilder; import org.apache.jackrabbit.oak.commons.json.JsopReader; import org.apache.jackrabbit.oak.commons.json.JsopTokenizer; @@ -253,7 +255,7 @@ public Iterable getProperties() { //Filter out the meta properties related to bundling from //generic listing of props if (bundlingContext.isBundled()){ - return Iterables.filter(properties.values(), BundlorUtils.NOT_BUNDLOR_PROPS::test); + return () -> properties.values().stream().filter(BundlorUtils.NOT_BUNDLOR_PROPS).iterator(); } return properties.values(); } @@ -501,7 +503,8 @@ public Iterable getAllBundledNodesStates() { return new TreeTraverser(){ @Override public Iterable children(DocumentNodeState root) { - return Iterables.transform(() -> root.getBundledChildren(), ce -> (DocumentNodeState)ce.getNodeState()); + return () -> CollectionUtils.toStream(root.getBundledChildren()).map(ce -> (DocumentNodeState) ce.getNodeState()) + .iterator(); } }.preOrderTraversal(this) .filter(dns -> !dns.getPath().equals(this.getPath()) ); //Exclude this @@ -571,20 +574,22 @@ private AbstractDocumentNodeState getSecondaryNodeState(){ @NotNull private Iterable getChildNodeEntries(@NotNull String name, int limit) { - Iterable children = store.getChildNodes(this, name, limit); - return Iterables.transform(children, input -> { - return new AbstractChildNodeEntry() { - @Override - public String getName() { - return input.getPath().getName(); - } + Iterable children = store.getChildNodes(this, name, limit); + Function transformer = input -> { + return new AbstractChildNodeEntry() { + @Override + public String getName() { + return input.getPath().getName(); + } - @Override - public NodeState getNodeState() { - return input; - } - }; - }); + @Override + public NodeState getNodeState() { + return input; + } + }; + }; + + return () -> CollectionUtils.toStream(children).map(transformer).iterator(); } private static Map asMap(Iterable props){ diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java index b91681e67cb..9fc7bfa6b89 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java @@ -20,7 +20,7 @@ import static java.util.Objects.requireNonNull; import static org.apache.jackrabbit.guava.common.base.Preconditions.checkState; import static org.apache.jackrabbit.guava.common.collect.Iterables.partition; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; + import static org.apache.jackrabbit.guava.common.collect.Lists.newArrayList; import static org.apache.jackrabbit.guava.common.collect.Lists.reverse; import static java.util.Collections.singletonList; @@ -70,7 +70,6 @@ import java.util.function.Function; import java.util.function.Predicate; import java.util.function.Supplier; -import java.util.stream.StreamSupport; import javax.jcr.PropertyType; @@ -137,7 +136,6 @@ import org.apache.jackrabbit.guava.common.base.Suppliers; import org.apache.jackrabbit.guava.common.collect.ImmutableList; import org.apache.jackrabbit.guava.common.collect.ImmutableMap; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Lists; import org.apache.jackrabbit.guava.common.collect.Maps; import org.apache.jackrabbit.guava.common.collect.Sets; @@ -1576,7 +1574,8 @@ Iterable getChildNodes(@NotNull final DocumentNodeState paren } final RevisionVector readRevision = parent.getLastRevision(); - return transform(getChildren(parent, name, limit).children, new Function() { + return () -> getChildren(parent, name, limit).children.stream().map( + new Function() { @Override public DocumentNodeState apply(String input) { Path p = new Path(parent.getPath(), input); @@ -1619,7 +1618,7 @@ private String docAsString(String id, boolean cached) { return e.toString(); } } - }::apply); + }).iterator(); } @Nullable @@ -2213,9 +2212,8 @@ public Map checkpointInfo(@NotNull String checkpoint) { public Iterable checkpoints() { checkOpen(); final long now = clock.getTime(); - return Iterables.transform(Iterables.filter(checkpoints.getCheckpoints().entrySet(), - cp -> cp.getValue().getExpiryTime() > now), - cp -> cp.getKey().toString()); + return () -> checkpoints.getCheckpoints().entrySet().stream().filter(cp -> cp.getValue().getExpiryTime() > now) + .map(cp -> cp.getKey().toString()).iterator(); } @Nullable diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBranch.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBranch.java index 99fb15cf0a7..2d376c12d18 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBranch.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBranch.java @@ -31,7 +31,6 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReadWriteLock; -import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.guava.common.collect.Sets; import org.apache.jackrabbit.oak.api.CommitFailedException; @@ -751,7 +750,7 @@ private void checkForConflicts() throws CommitFailedException { NodeDocument doc = Utils.getRootDocument(store.getDocumentStore()); Set collisions = new HashSet<>(doc.getLocalMap(COLLISIONS).keySet()); Set commits = new HashSet<>(); - Iterables.transform(b.getCommits(), Revision::asTrunkRevision).forEach(commits::add); + b.getCommits().stream().map(Revision::asTrunkRevision).forEach(commits::add); Set conflicts = Sets.intersection(collisions, commits); if (!conflicts.isEmpty()) { throw new CommitFailedException(STATE, 2, diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBeanImpl.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBeanImpl.java index f3ade339c1b..b1bc2217d26 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBeanImpl.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreMBeanImpl.java @@ -27,6 +27,7 @@ import org.apache.jackrabbit.api.stats.RepositoryStatistics; import org.apache.jackrabbit.api.stats.TimeSeries; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.commons.jmx.AnnotatedStandardMBean; import org.apache.jackrabbit.oak.plugins.document.util.Utils; import org.apache.jackrabbit.stats.TimeSeriesStatsUtil; @@ -35,9 +36,6 @@ import static org.apache.jackrabbit.guava.common.base.Preconditions.checkArgument; import static java.util.Objects.requireNonNull; -import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; -import static org.apache.jackrabbit.guava.common.collect.Iterables.toArray; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; /** * Implementation of a DocumentNodeStoreMBean. @@ -87,23 +85,20 @@ public int getUnmergedBranchCount() { @Override public String[] getInactiveClusterNodes() { - return toArray(transform(filter(clusterNodes, - input -> !input.isActive()), - input -> input.getClusterId() + "=" + input.getCreated()), String.class); + return CollectionUtils.toStream(clusterNodes).filter(input -> !input.isActive()) + .map(input -> input.getClusterId() + "=" + input.getCreated()).toArray(String[]::new); } @Override public String[] getActiveClusterNodes() { - return toArray(transform(filter(clusterNodes, - input -> input.isActive()), - input -> input.getClusterId() + "=" + input.getLeaseEndTime()), String.class); + return CollectionUtils.toStream(clusterNodes).filter(input -> input.isActive()) + .map(input -> input.getClusterId() + "=" + input.getLeaseEndTime()).toArray(String[]::new); } @Override public String[] getLastKnownRevisions() { - return toArray(transform(filter(nodeStore.getHeadRevision(), - input -> input.getClusterId() != getClusterId()), - input -> input.getClusterId() + "=" + input.toString()), String.class); + return CollectionUtils.toStream(nodeStore.getHeadRevision()).filter(input -> input.getClusterId() != getClusterId()) + .map(input -> input.getClusterId() + "=" + input.toString()).toArray(String[]::new); } @Override diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgent.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgent.java index 0417435e60b..3a834a1c3a9 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgent.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/LastRevRecoveryAgent.java @@ -18,8 +18,6 @@ */ package org.apache.jackrabbit.oak.plugins.document; -import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; import static org.apache.jackrabbit.guava.common.collect.Lists.newArrayList; import static org.apache.jackrabbit.guava.common.collect.Maps.filterKeys; import static java.util.Collections.singletonList; @@ -45,6 +43,7 @@ import org.apache.jackrabbit.guava.common.collect.Sets; import org.apache.jackrabbit.oak.commons.TimeDurationFormatter; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.document.bundlor.DocumentBundlor; import org.apache.jackrabbit.oak.plugins.document.cache.CacheInvalidationStats; import org.apache.jackrabbit.oak.plugins.document.util.MapFactory; @@ -286,7 +285,7 @@ public int recover(final Iterable suspects, // invalidate all suspects (OAK-9908) log.info("Starting cache invalidation before sweep..."); CacheInvalidationStats stats = store.invalidateCache( - transform(suspects, Document::getId)); + () -> CollectionUtils.toStream(suspects).map(Document::getId).iterator()); log.info("Invalidation stats: {}", stats); sweeper.sweep(suspects, new NodeDocumentSweepListener() { @Override @@ -761,10 +760,10 @@ public void performRecoveryIfNeeded() { * @return the recovery candidate nodes. */ public Iterable getRecoveryCandidateNodes() { - return Iterables.transform(filter(missingLastRevUtil.getAllClusters(), - input ->revisionContext.getClusterId() != input.getClusterId() - && input.isRecoveryNeeded(revisionContext.getClock().getTime())), - ClusterNodeInfoDocument::getClusterId); + return () -> CollectionUtils.toStream(missingLastRevUtil.getAllClusters()) + .filter(input -> revisionContext.getClusterId() != input.getClusterId() + && input.isRecoveryNeeded(revisionContext.getClock().getTime())) + .map(ClusterNodeInfoDocument::getClusterId).iterator(); } private static class ClusterPredicate implements Predicate { diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/MissingBcSweeper2.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/MissingBcSweeper2.java index 2e02023f125..5f4f27d20a3 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/MissingBcSweeper2.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/MissingBcSweeper2.java @@ -19,7 +19,6 @@ import static java.util.Objects.requireNonNull; import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; import static org.apache.jackrabbit.guava.common.collect.Iterables.partition; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; import static org.apache.jackrabbit.guava.common.collect.Maps.immutableEntry; import static org.apache.jackrabbit.oak.plugins.document.util.Utils.COMMITROOT_OR_REVISIONS; @@ -34,6 +33,7 @@ import java.util.function.Function; import org.apache.jackrabbit.oak.commons.TimeDurationFormatter; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.document.util.Utils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -136,8 +136,7 @@ private void performSweep2(Iterable documents, private Iterable> sweepOperations( final Iterable docs) { - return filter(transform(docs, - new Function>() { + return () -> CollectionUtils.toStream(docs).map(new Function>() { int yieldCnt = 0; long lastYield = context.getClock().getTime(); @@ -160,7 +159,7 @@ public Map.Entry apply(NodeDocument doc) { } return immutableEntry(doc.getPath(), sweepOne(doc)); } - }::apply), input -> input.getValue() != null); + }).filter(input -> input.getValue() != null).iterator(); } private UpdateOp sweepOne(NodeDocument doc) throws DocumentStoreException { diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/MissingLastRevSeeker.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/MissingLastRevSeeker.java index fc9b38326e8..4d7c02658c6 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/MissingLastRevSeeker.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/MissingLastRevSeeker.java @@ -16,18 +16,16 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.jackrabbit.oak.plugins.document; import java.util.stream.StreamSupport; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.document.util.Utils; import org.apache.jackrabbit.oak.stats.Clock; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.apache.jackrabbit.guava.common.collect.Iterables; - import static org.apache.jackrabbit.oak.plugins.document.Collection.CLUSTER_NODES; import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.MODIFIED_IN_SECS; import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.SD_TYPE; @@ -82,11 +80,11 @@ public Iterable getCandidates(final long startTime) { // Fetch all documents where lastmod >= startTime Iterable nodes = getSelectedDocuments(store, MODIFIED_IN_SECS, getModifiedInSecs(startTime)); - return Iterables.filter(nodes, input -> { - Long modified = (Long) input.get(MODIFIED_IN_SECS); - Long sdType = (Long) input.get(SD_TYPE); - return (modified != null && (modified >= getModifiedInSecs(startTime)) && sdType == null); - }); + return () -> CollectionUtils.toStream(nodes).filter(input -> { + Long modified = (Long) input.get(MODIFIED_IN_SECS); + Long sdType = (Long) input.get(SD_TYPE); + return (modified != null && (modified >= getModifiedInSecs(startTime)) && sdType == null); + }).iterator(); } /** diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java index bca44bf938c..05ff9c49543 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java @@ -20,7 +20,6 @@ import static java.util.stream.Collectors.toSet; import static org.apache.jackrabbit.guava.common.base.Preconditions.checkArgument; import static org.apache.jackrabbit.guava.common.collect.ImmutableList.copyOf; -import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; import static org.apache.jackrabbit.guava.common.collect.Iterables.mergeSorted; import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES; @@ -61,6 +60,7 @@ import org.apache.jackrabbit.guava.common.collect.Sets; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.commons.json.JsopBuilder; import org.apache.jackrabbit.oak.commons.json.JsopReader; import org.apache.jackrabbit.oak.commons.json.JsopTokenizer; @@ -1353,12 +1353,12 @@ Iterable getPreviousDocs(@NotNull final String property, } // didn't find entry -> scan through remaining head ranges - return filter(transform(getPreviousRanges().headMap(revision).entrySet(), input -> { - if (input.getValue().includes(revision)) { - return getPreviousDoc(input.getKey(), input.getValue()); - } - return null; - }), input ->input != null && input.getValueMap(property).containsKey(revision)); + return () -> getPreviousRanges().headMap(revision).entrySet().stream().map(input -> { + if (input.getValue().includes(revision)) { + return getPreviousDoc(input.getKey(), input.getValue()); + } + return null; + }).filter(input -> input != null && input.getValueMap(property).containsKey(revision)).iterator(); } } @@ -1559,8 +1559,9 @@ Iterable> getVisibleChanges(@NotNull final String pr Predicate> p = input -> !readRevision.isRevisionNewer(input.getKey()); List>> changes = Lists.newArrayList(); Map localChanges = getLocalMap(property); + if (!localChanges.isEmpty()) { - changes.add(filter(localChanges.entrySet(), p::test)); + changes.add(() -> localChanges.entrySet().stream().filter(p).iterator()); } for (Revision r : readRevision) { @@ -1664,7 +1665,7 @@ public Iterator> iterator() { } else { changes = Iterables.concat(transform(copyOf(ranges), rangeToChanges::apply)); } - return filter(changes, input -> !readRev.isRevisionNewer(input.getKey())); + return () -> CollectionUtils.toStream(changes).filter(input -> !readRev.isRevisionNewer(input.getKey())).iterator(); } /** @@ -1760,8 +1761,8 @@ String resolveCommitValue(Revision revision) { */ @NotNull RevisionVector getSweepRevisions() { - return new RevisionVector(transform(getLocalMap(SWEEP_REV).values(), - s -> Revision.fromString(s))); + return new RevisionVector( + getLocalMap(SWEEP_REV).values().stream().map(s -> Revision.fromString(s)).toArray(Revision[]::new)); } //-------------------------< UpdateOp modifiers >--------------------------- diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentSweeper.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentSweeper.java index 970c2815789..ba61ec59a23 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentSweeper.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentSweeper.java @@ -23,6 +23,7 @@ import java.util.function.Predicate; import org.apache.jackrabbit.oak.commons.TimeDurationFormatter; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.document.util.Utils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -30,9 +31,8 @@ import org.slf4j.LoggerFactory; import static java.util.Objects.requireNonNull; -import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; + import static org.apache.jackrabbit.guava.common.collect.Iterables.partition; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; import static org.apache.jackrabbit.guava.common.collect.Maps.immutableEntry; import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.isDeletedEntry; @@ -162,10 +162,9 @@ private Revision performSweep(Iterable documents, return head; } - private Iterable> sweepOperations( - final Iterable docs) { - return filter(transform(docs, doc -> immutableEntry(doc.getPath(), sweepOne(doc))), - input -> input.getValue() != null); + private Iterable> sweepOperations(final Iterable docs) { + return () -> CollectionUtils.toStream(docs).map(doc -> immutableEntry(doc.getPath(), sweepOne(doc))) + .filter(input -> input.getValue() != null).iterator(); } private UpdateOp sweepOne(NodeDocument doc) throws DocumentStoreException { @@ -175,7 +174,8 @@ private UpdateOp sweepOne(NodeDocument doc) throws DocumentStoreException { // - DELETED : for new node (this) // - COMMITROOT : for new child (parent) // - REVISIONS : for commit roots (root for branch commits) - for (String property : filter(doc.keySet(), SWEEP_ONE_PREDICATE::test)) { + Iterable keys = () -> doc.keySet().stream().filter(SWEEP_ONE_PREDICATE).iterator(); + for (String property : keys) { Map valueMap = doc.getLocalMap(property); for (Map.Entry entry : valueMap.entrySet()) { Revision rev = entry.getKey(); diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/PropertyHistory.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/PropertyHistory.java index 967a1b3d6d0..89640c6b7fa 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/PropertyHistory.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/PropertyHistory.java @@ -17,13 +17,13 @@ package org.apache.jackrabbit.oak.plugins.document; import static java.util.Objects.requireNonNull; -import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; -import static java.util.AbstractMap.SimpleImmutableEntry; +import java.util.AbstractMap.SimpleImmutableEntry; import java.util.Iterator; import java.util.Map; +import java.util.Objects; import java.util.TreeMap; +import java.util.function.Function; import org.apache.jackrabbit.guava.common.collect.AbstractIterator; import org.apache.jackrabbit.guava.common.collect.Iterators; @@ -55,17 +55,19 @@ public PropertyHistory(@NotNull NodeDocument doc, @Override public Iterator iterator() { - return ensureOrder(filter(transform(doc.getPreviousRanges().entrySet(), input -> { - Revision r = input.getKey(); - int h = input.getValue().height; - String prevId = Utils.getPreviousIdFor(mainPath, r, h); - NodeDocument prev = doc.getPreviousDocument(prevId); - if (prev == null) { - LOG.debug("Document with previous revisions not found: " + prevId); - return null; - } - return new SimpleImmutableEntry(r, prev); - }), x -> x != null)); + Function, Map.Entry> transformer = input -> { + Revision r = input.getKey(); + int h = input.getValue().height; + String prevId = Utils.getPreviousIdFor(mainPath, r, h); + NodeDocument prev = doc.getPreviousDocument(prevId); + if (prev == null) { + LOG.debug("Document with previous revisions not found: " + prevId); + return null; + } + return new SimpleImmutableEntry(r, prev); + }; + + return ensureOrder(() -> doc.getPreviousRanges().entrySet().stream().map(transformer).filter(Objects::nonNull).iterator()); } /** diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/UnsavedModifications.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/UnsavedModifications.java index ae8f8fe6232..0907b006955 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/UnsavedModifications.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/UnsavedModifications.java @@ -113,9 +113,8 @@ public Iterable getPaths(@NotNull final Revision start) { if (map.isEmpty()) { return Collections.emptyList(); } else { - return Iterables.transform(Iterables.filter(map.entrySet(), - input ->start.compareRevisionTime(input.getValue()) < 1), - input -> input.getKey()); + return () -> map.entrySet().stream().filter(input -> start.compareRevisionTime(input.getValue()) < 1) + .map(Map.Entry::getKey).iterator(); } } diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGCSupport.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGCSupport.java index a713901102b..d96288b1e09 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGCSupport.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/VersionGCSupport.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.jackrabbit.oak.plugins.document; import static java.util.Comparator.comparing; @@ -24,7 +23,6 @@ import static java.util.Optional.of; import static java.util.Optional.ofNullable; import static java.util.stream.Stream.concat; -import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; import static java.util.stream.Collectors.toList; import static org.apache.jackrabbit.oak.plugins.document.Document.ID; import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.MIN_ID_VALUE; @@ -42,6 +40,7 @@ import java.util.stream.Stream; import java.util.stream.StreamSupport; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.document.NodeDocument.SplitDocType; import org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats; import org.apache.jackrabbit.oak.plugins.document.util.Utils; @@ -75,9 +74,10 @@ public VersionGCSupport(DocumentStore store) { * @return matching documents. */ public Iterable getPossiblyDeletedDocs(final long fromModified, final long toModified) { - return StreamSupport.stream(getSelectedDocuments(store, NodeDocument.DELETED_ONCE, 1).spliterator(), false) - .filter(input -> input.wasDeletedOnce() && modifiedGreaterThanEquals(input, fromModified) && modifiedLessThan(input, toModified)) - .collect(toList()); + return () -> CollectionUtils.toStream(getSelectedDocuments(store, NodeDocument.DELETED_ONCE, 1)) + .filter(input -> input.wasDeletedOnce() && modifiedGreaterThanEquals(input, fromModified) + && modifiedLessThan(input, toModified)) + .iterator(); } /** @@ -174,10 +174,10 @@ protected SplitDocumentCleanUp createCleanUp(Set gcTypes, protected Iterable identifyGarbage(final Set gcTypes, final RevisionVector sweepRevs, final long oldestRevTimeStamp) { - return filter(getAllDocuments(store), - doc -> gcTypes.contains(doc.getSplitDocType()) - && doc.hasAllRevisionLessThan(oldestRevTimeStamp) - && !isDefaultNoBranchSplitNewerThan(doc, sweepRevs)); + return () -> CollectionUtils + .toStream(getAllDocuments(store)).filter(doc -> gcTypes.contains(doc.getSplitDocType()) + && doc.hasAllRevisionLessThan(oldestRevTimeStamp) && !isDefaultNoBranchSplitNewerThan(doc, sweepRevs)) + .iterator(); } /** diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java index baaaf8b9aef..235f9c92ccd 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java @@ -37,6 +37,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.locks.Lock; +import java.util.stream.Collectors; import java.util.stream.StreamSupport; import org.apache.jackrabbit.guava.common.base.Stopwatch; @@ -118,8 +119,6 @@ import static java.util.Objects.isNull; import static java.util.concurrent.TimeUnit.NANOSECONDS; -import static java.util.stream.Collectors.toList; -import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; import static org.apache.jackrabbit.guava.common.collect.Maps.filterKeys; import static org.apache.jackrabbit.guava.common.collect.Sets.difference; import static com.mongodb.client.model.Projections.include; @@ -528,7 +527,8 @@ public CacheInvalidationStats invalidateCache(Iterable keys) { result.queryCount++; int invalidated = nodesCache.invalidateOutdated(modStamps); - for (String id : filter(ids, x -> !modStamps.keySet().contains(x))) { + Iterable filteredIds = () -> ids.stream().filter(x -> !modStamps.keySet().contains(x)).iterator(); + for (String id : filteredIds) { nodesCache.invalidate(id); invalidated++; } @@ -1262,9 +1262,9 @@ public List findAndUpdate(final @NotNull Collection c results.put(op, findAndUpdate(collection, op)); } } catch (MongoException e) { - throw handleException(e, collection, Iterables.transform(updateOps, UpdateOp::getId)); + throw handleException(e, collection, () -> updateOps.stream().map(UpdateOp::getId).iterator()); } finally { - stats.doneFindAndModify(watch.elapsed(NANOSECONDS), collection, updateOps.stream().map(UpdateOp::getId).collect(toList()), + stats.doneFindAndModify(watch.elapsed(NANOSECONDS), collection, updateOps.stream().map(UpdateOp::getId).collect(Collectors.toList()), true, retryCount); } final List resultList = new ArrayList<>(results.values()); @@ -1363,8 +1363,7 @@ public List createOrUpdate(Collection collection, } } } catch (MongoException e) { - throw handleException(e, collection, Iterables.transform(updateOps, - input -> input.getId())); + throw handleException(e, collection, () -> updateOps.stream().map(UpdateOp::getId).iterator()); } finally { stats.doneCreateOrUpdate(watch.elapsed(TimeUnit.NANOSECONDS), collection, Lists.transform(updateOps, input -> input.getId())); diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoMissingLastRevSeeker.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoMissingLastRevSeeker.java index d904cc16505..42505430f67 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoMissingLastRevSeeker.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoMissingLastRevSeeker.java @@ -16,13 +16,13 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.jackrabbit.oak.plugins.document.mongo; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; import static org.apache.jackrabbit.oak.plugins.document.Collection.CLUSTER_NODES; import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; + import com.mongodb.BasicDBObject; import com.mongodb.ReadPreference; import com.mongodb.client.FindIterable; @@ -61,8 +61,8 @@ public CloseableIterable getCandidates(final long startTime) { FindIterable cursor = getNodeCollection() .find(query).sort(sortFields); - return CloseableIterable.wrap(transform(cursor, - input -> store.convertFromDBObject(NODES, input))); + return CloseableIterable + .wrap(() -> CollectionUtils.toStream(cursor).map(input -> store.convertFromDBObject(NODES, input)).iterator()); } @Override diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoVersionGCSupport.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoVersionGCSupport.java index e72991ff34f..b6c7c1802da 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoVersionGCSupport.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoVersionGCSupport.java @@ -26,8 +26,7 @@ import static java.util.Optional.empty; import static java.util.Optional.ofNullable; import static org.apache.jackrabbit.guava.common.collect.Iterables.concat; -import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; + import static com.mongodb.client.model.Filters.and; import static com.mongodb.client.model.Filters.lt; import static java.util.Collections.emptyList; @@ -53,6 +52,7 @@ import com.mongodb.client.MongoCursor; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.commons.json.JsopBuilder; import org.apache.jackrabbit.oak.plugins.document.Document; import org.apache.jackrabbit.oak.plugins.document.NodeDocument; @@ -143,8 +143,7 @@ public CloseableIterable getPossiblyDeletedDocs(final long fromMod FindIterable cursor = getNodeCollection() .find(query).batchSize(batchSize); - return CloseableIterable.wrap(transform(cursor, - input -> store.convertFromDBObject(NODES, input))); + return wrap(() -> CollectionUtils.toStream(cursor).map(input -> store.convertFromDBObject(NODES, input)).iterator()); } /** @@ -267,7 +266,7 @@ public Iterable getModifiedDocs(final long fromModified, final lon .hint(modifiedIdHint) .sort(sort) .limit(limit); - return wrap(transform(cursor, input -> store.convertFromDBObject(NODES, input))); + return wrap(() -> CollectionUtils.toStream(cursor).map(input -> store.convertFromDBObject(NODES, input)).iterator()); } /** @@ -331,10 +330,10 @@ protected Iterable identifyGarbage(final Set gcTypes // of the query as part of OAK-8351 does), it nevertheless // makes any future similar problem more visible than long running // queries alone (15min is still long). - Iterable iterable = filter(transform(getNodeCollection().find(query) - .maxTime(15, TimeUnit.MINUTES).hint(hint), - input -> store.convertFromDBObject(NODES, input)), - input -> !isDefaultNoBranchSplitNewerThan(input, sweepRevs)); + Iterable iterable = () -> + CollectionUtils.toStream(getNodeCollection().find(query).maxTime(15, TimeUnit.MINUTES).hint(hint)) + .map(input -> store.convertFromDBObject(NODES, input)) + .filter(input -> !isDefaultNoBranchSplitNewerThan(input, sweepRevs)).iterator(); allResults = concat(allResults, iterable); } return allResults; diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCache.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCache.java index 9d57be4c995..5969363d208 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCache.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCache.java @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.oak.plugins.document.persistentCache; -import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; import static java.util.Collections.singleton; import static org.apache.jackrabbit.guava.common.cache.RemovalCause.COLLECTED; import static org.apache.jackrabbit.guava.common.cache.RemovalCause.EXPIRED; @@ -35,8 +34,8 @@ import org.apache.jackrabbit.guava.common.cache.CacheStats; import org.apache.jackrabbit.guava.common.cache.RemovalCause; import org.apache.jackrabbit.guava.common.collect.ImmutableMap; -import org.apache.jackrabbit.guava.common.collect.ImmutableSet; import org.apache.jackrabbit.oak.cache.CacheValue; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore; import org.apache.jackrabbit.oak.plugins.document.DocumentStore; import org.apache.jackrabbit.oak.plugins.document.persistentCache.PersistentCache.GenerationCache; @@ -251,7 +250,8 @@ public ImmutableMap getAllPresent( Iterable typedKeys = (Iterable) keys; memCacheMetadata.incrementAll(keys); ImmutableMap result = memCache.getAllPresent(keys); - memCacheMetadata.removeAll(filter(typedKeys, x -> !result.keySet().contains(x))); + Iterable toRemove = () -> CollectionUtils.toStream(typedKeys).filter(x -> !result.keySet().contains(x)).iterator(); + memCacheMetadata.removeAll(toRemove); return result; } diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java index 3ee5e58f710..d8e7aec390f 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreJDBC.java @@ -16,7 +16,7 @@ */ package org.apache.jackrabbit.oak.plugins.document.rdb; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; + import static org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.CHAR2OCTETRATIO; import static org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.asBytes; import static org.apache.jackrabbit.oak.plugins.document.rdb.RDBJDBCTools.asDocumentStoreException; @@ -47,7 +47,6 @@ import java.util.Set; import org.apache.jackrabbit.oak.commons.PerfLogger; -import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.document.Document; import org.apache.jackrabbit.oak.plugins.document.DocumentStoreException; import org.apache.jackrabbit.oak.plugins.document.NodeDocument; @@ -430,7 +429,7 @@ public Set update(Connection connection, RDBTableMe } private static void assertNoDuplicatedIds(List documents) { - if (CollectionUtils.toSet(transform(documents, Document::getId)).size() < documents.size()) { + if (documents.stream().map(Document::getId).count() < documents.size()) { throw new IllegalArgumentException("There are duplicated ids in the document list"); } } diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBVersionGCSupport.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBVersionGCSupport.java index 588ece3821f..17921e2a423 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBVersionGCSupport.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBVersionGCSupport.java @@ -16,8 +16,6 @@ */ package org.apache.jackrabbit.oak.plugins.document.rdb; -import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; - import java.io.Closeable; import java.io.IOException; import java.util.ArrayList; @@ -29,6 +27,7 @@ import java.util.concurrent.TimeUnit; import java.util.function.Predicate; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.commons.properties.SystemPropertySupplier; import org.apache.jackrabbit.oak.plugins.document.Collection; import org.apache.jackrabbit.oak.plugins.document.DocumentStoreException; @@ -105,7 +104,8 @@ private Iterable getSplitDocuments() { private Iterable identifyGarbageMode1(final Set gcTypes, final RevisionVector sweepRevs, final long oldestRevTimeStamp) { - return filter(getSplitDocuments(), getGarbageCheckPredicate(gcTypes, sweepRevs, oldestRevTimeStamp)::test); + return () -> CollectionUtils.toStream(getSplitDocuments()) + .filter(getGarbageCheckPredicate(gcTypes, sweepRevs, oldestRevTimeStamp)).iterator(); } private Predicate getGarbageCheckPredicate(final Set gcTypes, final RevisionVector sweepRevs, @@ -161,7 +161,10 @@ private Iterable identifyGarbageMode2(final Set gcTy final CountingPredicate cp1 = new CountingPredicate(name1, pred); final CountingPredicate cp2 = new CountingPredicate(name2, pred); - return CloseableIterable.wrap(Iterables.concat(Iterables.filter(fit1, cp1::test), Iterables.filter(fit2, cp2::test)), + final Iterable iterable1 = () -> CollectionUtils.toStream(fit1).filter(cp1).iterator(); + final Iterable iterable2 = () -> CollectionUtils.toStream(fit2).filter(cp2).iterator(); + + return CloseableIterable.wrap(Iterables.concat(iterable1, iterable2), new Closeable() { @Override public void close() throws IOException { diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/DelegatingDocumentNodeState.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/DelegatingDocumentNodeState.java index 13727a9e79b..b26e219c2ec 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/DelegatingDocumentNodeState.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/secondary/DelegatingDocumentNodeState.java @@ -20,6 +20,7 @@ import org.apache.jackrabbit.guava.common.collect.Iterables; import org.apache.jackrabbit.oak.api.PropertyState; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState; import org.apache.jackrabbit.oak.plugins.document.NodeStateDiffer; import org.apache.jackrabbit.oak.plugins.document.Path; @@ -34,6 +35,8 @@ import static java.util.Objects.requireNonNull; import static org.apache.jackrabbit.guava.common.base.Preconditions.checkState; +import java.util.Iterator; +import java.util.function.Function; import java.util.function.Predicate; /** @@ -151,10 +154,11 @@ public boolean exists() { return true; } + @SuppressWarnings("unchecked") @NotNull @Override public Iterable getProperties() { - return Iterables.filter(delegate.getProperties(), NOT_META_PROPS::test); + return () -> (Iterator) CollectionUtils.toStream(delegate.getProperties()).filter(NOT_META_PROPS).iterator(); } @Override @@ -171,8 +175,9 @@ public NodeState getChildNode(@NotNull String name) throws IllegalArgumentExcept @NotNull @Override public Iterable getChildNodeEntries() { - return Iterables.transform(delegate.getChildNodeEntries(), - input -> new MemoryChildNodeEntry(input.getName(), decorate(input.getName(), input.getNodeState()))); + Function transform = input -> new MemoryChildNodeEntry(input.getName(), + decorate(input.getName(), input.getNodeState())); + return () -> CollectionUtils.toStream(delegate.getChildNodeEntries()).map(transform).iterator(); } @NotNull diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java index c04e8efea8e..fc924be6d5e 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/Utils.java @@ -39,11 +39,11 @@ import java.util.function.Predicate; import java.util.stream.Collectors; - import org.apache.jackrabbit.guava.common.collect.AbstractIterator; import org.apache.jackrabbit.oak.commons.OakVersion; import org.apache.jackrabbit.oak.commons.PathUtils; import org.apache.jackrabbit.oak.commons.StringUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.document.ClusterNodeInfo; import org.apache.jackrabbit.oak.plugins.document.ClusterNodeInfoDocument; import org.apache.jackrabbit.oak.plugins.document.Collection; @@ -64,7 +64,7 @@ import org.slf4j.LoggerFactory; import static java.util.Objects.requireNonNull; -import static org.apache.jackrabbit.guava.common.collect.Iterables.transform; + import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.MIN_ID_VALUE; import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.isDeletedEntry; import static org.apache.jackrabbit.oak.plugins.document.NodeDocument.isCommitRootEntry; @@ -969,14 +969,14 @@ public static boolean isHiddenPath(@NotNull String path) { */ public static Iterable asStringValueIterable( @NotNull Iterable values) { - return transform(values, input -> new StringValue(input)); + return () -> CollectionUtils.toStream(values).map(input -> new StringValue(input)).iterator(); } /** * Transforms the given paths into ids using {@link #getIdFromPath(String)}. */ public static Iterable pathToId(@NotNull Iterable paths) { - return transform(paths, input -> getIdFromPath(input)); + return () -> CollectionUtils.toStream(paths).map(input -> getIdFromPath(input)).iterator(); } /** diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoVersionGCSupportDefaultNoBranchTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoVersionGCSupportDefaultNoBranchTest.java index 7d8e750562f..5b7ba9b0140 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoVersionGCSupportDefaultNoBranchTest.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoVersionGCSupportDefaultNoBranchTest.java @@ -40,6 +40,7 @@ import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.commons.PathUtils; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder; import org.apache.jackrabbit.oak.plugins.document.DocumentStoreFixture.MongoFixture; import org.apache.jackrabbit.oak.plugins.document.NodeDocument.SplitDocType; @@ -54,7 +55,6 @@ import org.apache.jackrabbit.oak.spi.state.NodeBuilder; import org.apache.jackrabbit.oak.stats.Clock; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; @@ -283,8 +283,8 @@ public void doTestBothInstancesSplit(int numSplit1, int numSplit2) throws Except Iterable garbage = gcSupport1.identifyGarbage(GC_TYPES, sweepRevs, oldestRevTimeStamp); assertNotNull(garbage); assertEquals(totalSplits, Iterables.size(garbage)); - assertEquals(numSplit1, Iterables.size(Iterables.filter(garbage, splitDocsWithClusterId(1)::test))); - assertEquals(numSplit2, Iterables.size(Iterables.filter(garbage, splitDocsWithClusterId(2)::test))); + assertEquals(numSplit1, CollectionUtils.toStream(garbage).filter(splitDocsWithClusterId(1)).count()); + assertEquals(numSplit2, CollectionUtils.toStream(garbage).filter(splitDocsWithClusterId(2)).count()); Stats stats = deleteSplitDocuments(gcSupport1, sweepRevs, oldestRevTimeStamp); assertNotNull(stats); diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorIT.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorIT.java index 8d794747c42..1a72ffa577d 100644 --- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorIT.java +++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorIT.java @@ -52,7 +52,6 @@ import static org.apache.commons.lang3.reflect.FieldUtils.writeField; import static org.apache.commons.lang3.reflect.FieldUtils.writeStaticField; -import static org.apache.jackrabbit.guava.common.collect.Iterables.filter; import static org.apache.jackrabbit.guava.common.collect.Iterables.size; import static java.util.concurrent.TimeUnit.HOURS; import static java.util.concurrent.TimeUnit.MINUTES; @@ -110,6 +109,7 @@ import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Type; +import org.apache.jackrabbit.oak.commons.collections.CollectionUtils; import org.apache.jackrabbit.oak.plugins.document.DocumentStoreFixture.RDBFixture; import org.apache.jackrabbit.oak.plugins.document.FailingDocumentStore.FailedUpdateOpListener; import org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.FullGCMode; @@ -3434,15 +3434,14 @@ public void gcWithConcurrentModification() throws Exception { VersionGCSupport gcSupport = new VersionGCSupport(store1.getDocumentStore()) { @Override public Iterable getPossiblyDeletedDocs(long fromModified, long toModified) { - return filter(super.getPossiblyDeletedDocs(fromModified, toModified), - input -> { - try { - docs.put(input); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - return true; - }); + return () -> CollectionUtils.toStream(super.getPossiblyDeletedDocs(fromModified, toModified)).filter(input -> { + try { + docs.put(input); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + return true; + }).iterator(); } }; @@ -3667,12 +3666,12 @@ public void lowerBoundOfModifiedDocs() throws Exception { VersionGCSupport nonReportingGcSupport = new VersionGCSupport(store1.getDocumentStore()) { @Override public Iterable getPossiblyDeletedDocs(final long fromModified, long toModified) { - return filter(fixtureGCSupport.getPossiblyDeletedDocs(fromModified, toModified), - input -> { - docCounter.incrementAndGet(); - // don't report any doc to be GC'able - return false; - }); + return () -> CollectionUtils.toStream(fixtureGCSupport.getPossiblyDeletedDocs(fromModified, toModified)) + .filter(input -> { + docCounter.incrementAndGet(); + // don't report any doc to be GC'able + return false; + }).iterator(); } }; final VersionGarbageCollector gc = new VersionGarbageCollector(store1, nonReportingGcSupport, false, false, false);