LCOV - code coverage report
Current view: top level - server/config - GroupSetProvider.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 9 14 64.3 %
Date: 2022-11-19 15:00:39 Functions: 3 3 100.0 %

          Line data    Source code
       1             : // Copyright (C) 2010 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // You may obtain a copy of the License at
       6             : //
       7             : // http://www.apache.org/licenses/LICENSE-2.0
       8             : //
       9             : // Unless required by applicable law or agreed to in writing, software
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : 
      15             : package com.google.gerrit.server.config;
      16             : 
      17             : import com.google.common.collect.ImmutableSet;
      18             : import com.google.common.flogger.FluentLogger;
      19             : import com.google.gerrit.entities.AccountGroup;
      20             : import com.google.gerrit.entities.GroupReference;
      21             : import com.google.gerrit.server.account.GroupBackend;
      22             : import com.google.gerrit.server.account.GroupBackends;
      23             : import com.google.gerrit.server.util.RequestContext;
      24             : import com.google.gerrit.server.util.ServerRequestContext;
      25             : import com.google.gerrit.server.util.ThreadLocalRequestContext;
      26             : import com.google.inject.Provider;
      27             : import java.util.List;
      28             : import java.util.Set;
      29             : 
      30             : /** Parses groups referenced in the {@code gerrit.config} file. */
      31             : public abstract class GroupSetProvider implements Provider<Set<AccountGroup.UUID>> {
      32         148 :   private static final FluentLogger logger = FluentLogger.forEnclosingClass();
      33             : 
      34             :   protected Set<AccountGroup.UUID> groupIds;
      35             : 
      36             :   protected GroupSetProvider(
      37             :       GroupBackend groupBackend,
      38             :       ThreadLocalRequestContext threadContext,
      39             :       ServerRequestContext serverCtx,
      40         148 :       List<String> groupNames) {
      41         148 :     RequestContext ctx = threadContext.setContext(serverCtx);
      42             :     try {
      43         148 :       ImmutableSet.Builder<AccountGroup.UUID> builder = ImmutableSet.builder();
      44         148 :       for (String n : groupNames) {
      45           0 :         GroupReference g = GroupBackends.findBestSuggestion(groupBackend, n);
      46           0 :         if (g != null) {
      47           0 :           builder.add(g.getUUID());
      48             :         } else {
      49           0 :           logger.atWarning().log("Group \"%s\" not available, skipping.", n);
      50             :         }
      51           0 :       }
      52         148 :       groupIds = builder.build();
      53             :     } finally {
      54         148 :       threadContext.setContext(ctx);
      55             :     }
      56         148 :   }
      57             : 
      58             :   @Override
      59             :   public Set<AccountGroup.UUID> get() {
      60         148 :     return groupIds;
      61             :   }
      62             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750