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

          Line data    Source code
       1             : // Copyright (C) 2020 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.submit;
      16             : 
      17             : import com.google.common.collect.ImmutableSet;
      18             : import com.google.common.flogger.FluentLogger;
      19             : import com.google.gerrit.entities.BranchNameKey;
      20             : import com.google.gerrit.server.config.GerritServerConfig;
      21             : import com.google.inject.Inject;
      22             : import java.util.Set;
      23             : import org.eclipse.jgit.lib.Config;
      24             : 
      25             : /**
      26             :  * Wrap a {@link SubscriptionGraph.Factory} to honor the gerrit configuration.
      27             :  *
      28             :  * <p>If superproject subscriptions are disabled in the conf, return an empty graph.
      29             :  */
      30             : public class ConfiguredSubscriptionGraphFactory implements SubscriptionGraph.Factory {
      31         142 :   private static final FluentLogger logger = FluentLogger.forEnclosingClass();
      32             : 
      33             :   private final SubscriptionGraph.Factory subscriptionGraphFactory;
      34             :   private final Config cfg;
      35             : 
      36             :   @Inject
      37             :   ConfiguredSubscriptionGraphFactory(
      38             :       @VanillaSubscriptionGraph SubscriptionGraph.Factory subscriptionGraphFactory,
      39         142 :       @GerritServerConfig Config cfg) {
      40         142 :     this.subscriptionGraphFactory = subscriptionGraphFactory;
      41         142 :     this.cfg = cfg;
      42         142 :   }
      43             : 
      44             :   @Override
      45             :   public SubscriptionGraph compute(Set<BranchNameKey> updatedBranches, MergeOpRepoManager orm)
      46             :       throws SubmoduleConflictException {
      47          68 :     if (cfg.getBoolean("submodule", "enableSuperProjectSubscriptions", true)) {
      48          68 :       return subscriptionGraphFactory.compute(updatedBranches, orm);
      49             :     }
      50           1 :     logger.atFine().log("Updating superprojects disabled");
      51           1 :     return SubscriptionGraph.createEmptyGraph(ImmutableSet.copyOf(updatedBranches));
      52             :   }
      53             : }

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