LCOV - code coverage report
Current view: top level - acceptance - ExtensionRegistry.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 93 96 96.9 %
Date: 2022-11-19 15:00:39 Functions: 46 49 93.9 %

          Line data    Source code
       1             : // Copyright (C) 2019 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.acceptance;
      16             : 
      17             : import com.google.gerrit.entities.SubmitRequirement;
      18             : import com.google.gerrit.extensions.api.changes.ActionVisitor;
      19             : import com.google.gerrit.extensions.config.CapabilityDefinition;
      20             : import com.google.gerrit.extensions.config.DownloadScheme;
      21             : import com.google.gerrit.extensions.config.PluginProjectPermissionDefinition;
      22             : import com.google.gerrit.extensions.events.AccountActivationListener;
      23             : import com.google.gerrit.extensions.events.AccountIndexedListener;
      24             : import com.google.gerrit.extensions.events.AttentionSetListener;
      25             : import com.google.gerrit.extensions.events.ChangeIndexedListener;
      26             : import com.google.gerrit.extensions.events.CommentAddedListener;
      27             : import com.google.gerrit.extensions.events.GitBatchRefUpdateListener;
      28             : import com.google.gerrit.extensions.events.GitReferenceUpdatedListener;
      29             : import com.google.gerrit.extensions.events.GroupIndexedListener;
      30             : import com.google.gerrit.extensions.events.ProjectIndexedListener;
      31             : import com.google.gerrit.extensions.events.ReviewerAddedListener;
      32             : import com.google.gerrit.extensions.events.ReviewerDeletedListener;
      33             : import com.google.gerrit.extensions.events.RevisionCreatedListener;
      34             : import com.google.gerrit.extensions.events.TopicEditedListener;
      35             : import com.google.gerrit.extensions.events.WorkInProgressStateChangedListener;
      36             : import com.google.gerrit.extensions.registration.DynamicMap;
      37             : import com.google.gerrit.extensions.registration.DynamicSet;
      38             : import com.google.gerrit.extensions.registration.PrivateInternals_DynamicMapImpl;
      39             : import com.google.gerrit.extensions.registration.RegistrationHandle;
      40             : import com.google.gerrit.extensions.webui.EditWebLink;
      41             : import com.google.gerrit.extensions.webui.FileHistoryWebLink;
      42             : import com.google.gerrit.extensions.webui.FileWebLink;
      43             : import com.google.gerrit.extensions.webui.PatchSetWebLink;
      44             : import com.google.gerrit.extensions.webui.ResolveConflictsWebLink;
      45             : import com.google.gerrit.server.ExceptionHook;
      46             : import com.google.gerrit.server.account.GroupBackend;
      47             : import com.google.gerrit.server.change.ChangeETagComputation;
      48             : import com.google.gerrit.server.config.ProjectConfigEntry;
      49             : import com.google.gerrit.server.git.ChangeMessageModifier;
      50             : import com.google.gerrit.server.git.receive.PluginPushOption;
      51             : import com.google.gerrit.server.git.validators.CommitValidationListener;
      52             : import com.google.gerrit.server.git.validators.OnSubmitValidationListener;
      53             : import com.google.gerrit.server.git.validators.RefOperationValidationListener;
      54             : import com.google.gerrit.server.logging.PerformanceLogger;
      55             : import com.google.gerrit.server.query.change.ChangeQueryBuilder.ChangeHasOperandFactory;
      56             : import com.google.gerrit.server.query.change.ChangeQueryBuilder.ChangeIsOperandFactory;
      57             : import com.google.gerrit.server.restapi.change.OnPostReview;
      58             : import com.google.gerrit.server.rules.SubmitRule;
      59             : import com.google.gerrit.server.validators.AccountActivationValidationListener;
      60             : import com.google.gerrit.server.validators.ProjectCreationValidationListener;
      61             : import com.google.inject.Inject;
      62             : import com.google.inject.util.Providers;
      63             : import java.util.ArrayList;
      64             : import java.util.List;
      65             : 
      66             : public class ExtensionRegistry {
      67             :   public static final String PLUGIN_NAME = "myPlugin";
      68             : 
      69             :   private final DynamicSet<AccountIndexedListener> accountIndexedListeners;
      70             :   private final DynamicSet<ChangeIndexedListener> changeIndexedListeners;
      71             :   private final DynamicSet<GroupIndexedListener> groupIndexedListeners;
      72             :   private final DynamicSet<ProjectIndexedListener> projectIndexedListeners;
      73             :   private final DynamicSet<CommitValidationListener> commitValidationListeners;
      74             :   private final DynamicSet<TopicEditedListener> topicEditedListeners;
      75             :   private final DynamicSet<ExceptionHook> exceptionHooks;
      76             :   private final DynamicSet<PerformanceLogger> performanceLoggers;
      77             :   private final DynamicSet<ProjectCreationValidationListener> projectCreationValidationListeners;
      78             :   private final DynamicSet<SubmitRule> submitRules;
      79             :   private final DynamicSet<SubmitRequirement> submitRequirements;
      80             :   private final DynamicSet<ChangeMessageModifier> changeMessageModifiers;
      81             :   private final DynamicSet<ChangeETagComputation> changeETagComputations;
      82             :   private final DynamicSet<ActionVisitor> actionVisitors;
      83             :   private final DynamicMap<DownloadScheme> downloadSchemes;
      84             :   private final DynamicSet<RefOperationValidationListener> refOperationValidationListeners;
      85             :   private final DynamicSet<CommentAddedListener> commentAddedListeners;
      86             :   private final DynamicSet<GitReferenceUpdatedListener> refUpdatedListeners;
      87             :   private final DynamicSet<GitBatchRefUpdateListener> batchRefUpdateListeners;
      88             :   private final DynamicSet<FileHistoryWebLink> fileHistoryWebLinks;
      89             :   private final DynamicSet<PatchSetWebLink> patchSetWebLinks;
      90             :   private final DynamicSet<ResolveConflictsWebLink> resolveConflictsWebLinks;
      91             :   private final DynamicSet<EditWebLink> editWebLinks;
      92             :   private final DynamicSet<FileWebLink> fileWebLinks;
      93             :   private final DynamicSet<RevisionCreatedListener> revisionCreatedListeners;
      94             :   private final DynamicSet<GroupBackend> groupBackends;
      95             :   private final DynamicSet<AccountActivationValidationListener>
      96             :       accountActivationValidationListeners;
      97             :   private final DynamicSet<AccountActivationListener> accountActivationListeners;
      98             :   private final DynamicSet<OnSubmitValidationListener> onSubmitValidationListeners;
      99             :   private final DynamicSet<WorkInProgressStateChangedListener> workInProgressStateChangedListeners;
     100             :   private final DynamicMap<CapabilityDefinition> capabilityDefinitions;
     101             :   private final DynamicMap<PluginProjectPermissionDefinition> pluginProjectPermissionDefinitions;
     102             :   private final DynamicMap<ProjectConfigEntry> pluginConfigEntries;
     103             :   private final DynamicSet<PluginPushOption> pluginPushOptions;
     104             :   private final DynamicSet<OnPostReview> onPostReviews;
     105             :   private final DynamicSet<ReviewerAddedListener> reviewerAddedListeners;
     106             :   private final DynamicSet<ReviewerDeletedListener> reviewerDeletedListeners;
     107             :   private final DynamicSet<AttentionSetListener> attentionSetListeners;
     108             : 
     109             :   private final DynamicMap<ChangeHasOperandFactory> hasOperands;
     110             :   private final DynamicMap<ChangeIsOperandFactory> isOperands;
     111             : 
     112             :   @Inject
     113             :   ExtensionRegistry(
     114             :       DynamicSet<AccountIndexedListener> accountIndexedListeners,
     115             :       DynamicSet<ChangeIndexedListener> changeIndexedListeners,
     116             :       DynamicSet<GroupIndexedListener> groupIndexedListeners,
     117             :       DynamicSet<ProjectIndexedListener> projectIndexedListeners,
     118             :       DynamicSet<CommitValidationListener> commitValidationListeners,
     119             :       DynamicSet<TopicEditedListener> topicEditedListeners,
     120             :       DynamicSet<ExceptionHook> exceptionHooks,
     121             :       DynamicSet<PerformanceLogger> performanceLoggers,
     122             :       DynamicSet<ProjectCreationValidationListener> projectCreationValidationListeners,
     123             :       DynamicSet<SubmitRule> submitRules,
     124             :       DynamicSet<SubmitRequirement> submitRequirements,
     125             :       DynamicSet<ChangeMessageModifier> changeMessageModifiers,
     126             :       DynamicSet<ChangeETagComputation> changeETagComputations,
     127             :       DynamicSet<ActionVisitor> actionVisitors,
     128             :       DynamicMap<DownloadScheme> downloadSchemes,
     129             :       DynamicSet<RefOperationValidationListener> refOperationValidationListeners,
     130             :       DynamicSet<CommentAddedListener> commentAddedListeners,
     131             :       DynamicSet<GitReferenceUpdatedListener> refUpdatedListeners,
     132             :       DynamicSet<GitBatchRefUpdateListener> batchRefUpdateListeners,
     133             :       DynamicSet<FileHistoryWebLink> fileHistoryWebLinks,
     134             :       DynamicSet<PatchSetWebLink> patchSetWebLinks,
     135             :       DynamicSet<ResolveConflictsWebLink> resolveConflictsWebLinks,
     136             :       DynamicSet<EditWebLink> editWebLinks,
     137             :       DynamicSet<FileWebLink> fileWebLinks,
     138             :       DynamicSet<RevisionCreatedListener> revisionCreatedListeners,
     139             :       DynamicSet<GroupBackend> groupBackends,
     140             :       DynamicSet<AccountActivationValidationListener> accountActivationValidationListeners,
     141             :       DynamicSet<AccountActivationListener> accountActivationListeners,
     142             :       DynamicSet<OnSubmitValidationListener> onSubmitValidationListeners,
     143             :       DynamicSet<WorkInProgressStateChangedListener> workInProgressStateChangedListeners,
     144             :       DynamicMap<CapabilityDefinition> capabilityDefinitions,
     145             :       DynamicMap<PluginProjectPermissionDefinition> pluginProjectPermissionDefinitions,
     146             :       DynamicMap<ProjectConfigEntry> pluginConfigEntries,
     147             :       DynamicSet<PluginPushOption> pluginPushOption,
     148             :       DynamicSet<OnPostReview> onPostReviews,
     149             :       DynamicSet<ReviewerAddedListener> reviewerAddedListeners,
     150             :       DynamicSet<ReviewerDeletedListener> reviewerDeletedListeners,
     151             :       DynamicMap<ChangeHasOperandFactory> hasOperands,
     152             :       DynamicMap<ChangeIsOperandFactory> isOperands,
     153          36 :       DynamicSet<AttentionSetListener> attentionSetListeners) {
     154          36 :     this.accountIndexedListeners = accountIndexedListeners;
     155          36 :     this.changeIndexedListeners = changeIndexedListeners;
     156          36 :     this.groupIndexedListeners = groupIndexedListeners;
     157          36 :     this.projectIndexedListeners = projectIndexedListeners;
     158          36 :     this.commitValidationListeners = commitValidationListeners;
     159          36 :     this.topicEditedListeners = topicEditedListeners;
     160          36 :     this.exceptionHooks = exceptionHooks;
     161          36 :     this.performanceLoggers = performanceLoggers;
     162          36 :     this.projectCreationValidationListeners = projectCreationValidationListeners;
     163          36 :     this.submitRules = submitRules;
     164          36 :     this.submitRequirements = submitRequirements;
     165          36 :     this.changeMessageModifiers = changeMessageModifiers;
     166          36 :     this.changeETagComputations = changeETagComputations;
     167          36 :     this.actionVisitors = actionVisitors;
     168          36 :     this.downloadSchemes = downloadSchemes;
     169          36 :     this.refOperationValidationListeners = refOperationValidationListeners;
     170          36 :     this.commentAddedListeners = commentAddedListeners;
     171          36 :     this.refUpdatedListeners = refUpdatedListeners;
     172          36 :     this.batchRefUpdateListeners = batchRefUpdateListeners;
     173          36 :     this.fileHistoryWebLinks = fileHistoryWebLinks;
     174          36 :     this.patchSetWebLinks = patchSetWebLinks;
     175          36 :     this.editWebLinks = editWebLinks;
     176          36 :     this.fileWebLinks = fileWebLinks;
     177          36 :     this.resolveConflictsWebLinks = resolveConflictsWebLinks;
     178          36 :     this.revisionCreatedListeners = revisionCreatedListeners;
     179          36 :     this.groupBackends = groupBackends;
     180          36 :     this.accountActivationValidationListeners = accountActivationValidationListeners;
     181          36 :     this.accountActivationListeners = accountActivationListeners;
     182          36 :     this.onSubmitValidationListeners = onSubmitValidationListeners;
     183          36 :     this.workInProgressStateChangedListeners = workInProgressStateChangedListeners;
     184          36 :     this.capabilityDefinitions = capabilityDefinitions;
     185          36 :     this.pluginProjectPermissionDefinitions = pluginProjectPermissionDefinitions;
     186          36 :     this.pluginConfigEntries = pluginConfigEntries;
     187          36 :     this.pluginPushOptions = pluginPushOption;
     188          36 :     this.onPostReviews = onPostReviews;
     189          36 :     this.reviewerAddedListeners = reviewerAddedListeners;
     190          36 :     this.reviewerDeletedListeners = reviewerDeletedListeners;
     191          36 :     this.hasOperands = hasOperands;
     192          36 :     this.isOperands = isOperands;
     193          36 :     this.attentionSetListeners = attentionSetListeners;
     194          36 :   }
     195             : 
     196             :   public Registration newRegistration() {
     197          36 :     return new Registration();
     198             :   }
     199             : 
     200             :   @SuppressWarnings("FunctionalInterfaceClash")
     201          36 :   public class Registration implements AutoCloseable {
     202          36 :     private final List<RegistrationHandle> registrationHandles = new ArrayList<>();
     203             : 
     204             :     public Registration add(AccountIndexedListener accountIndexedListener) {
     205           2 :       return add(accountIndexedListeners, accountIndexedListener);
     206             :     }
     207             : 
     208             :     public Registration add(ChangeIndexedListener changeIndexedListener) {
     209          12 :       return add(changeIndexedListeners, changeIndexedListener);
     210             :     }
     211             : 
     212             :     public Registration add(GroupIndexedListener groupIndexedListener) {
     213           1 :       return add(groupIndexedListeners, groupIndexedListener);
     214             :     }
     215             : 
     216             :     public Registration add(ProjectIndexedListener projectIndexedListener) {
     217           1 :       return add(projectIndexedListeners, projectIndexedListener);
     218             :     }
     219             : 
     220             :     public Registration add(CommitValidationListener commitValidationListener) {
     221           8 :       return add(commitValidationListeners, commitValidationListener);
     222             :     }
     223             : 
     224             :     public Registration add(TopicEditedListener topicEditedListener) {
     225           3 :       return add(topicEditedListeners, topicEditedListener);
     226             :     }
     227             : 
     228             :     public Registration add(ExceptionHook exceptionHook) {
     229           0 :       return add(exceptionHooks, exceptionHook);
     230             :     }
     231             : 
     232             :     public Registration add(PerformanceLogger performanceLogger) {
     233           2 :       return add(performanceLoggers, performanceLogger);
     234             :     }
     235             : 
     236             :     public Registration add(ProjectCreationValidationListener projectCreationListener) {
     237           2 :       return add(projectCreationValidationListeners, projectCreationListener);
     238             :     }
     239             : 
     240             :     public Registration add(SubmitRule submitRule) {
     241           8 :       return add(submitRules, submitRule);
     242             :     }
     243             : 
     244             :     public Registration add(SubmitRequirement submitRequirement) {
     245           2 :       return add(submitRequirements, submitRequirement);
     246             :     }
     247             : 
     248             :     public Registration add(ChangeHasOperandFactory hasOperand, String exportName) {
     249           0 :       return add(hasOperands, hasOperand, exportName);
     250             :     }
     251             : 
     252             :     public Registration add(ChangeIsOperandFactory isOperand, String exportName) {
     253           1 :       return add(isOperands, isOperand, exportName);
     254             :     }
     255             : 
     256             :     public Registration add(ChangeMessageModifier changeMessageModifier) {
     257           3 :       return add(changeMessageModifiers, changeMessageModifier);
     258             :     }
     259             : 
     260             :     public Registration add(ChangeMessageModifier changeMessageModifier, String exportName) {
     261           1 :       return add(changeMessageModifiers, changeMessageModifier, exportName);
     262             :     }
     263             : 
     264             :     public Registration add(ChangeETagComputation changeETagComputation) {
     265           1 :       return add(changeETagComputations, changeETagComputation);
     266             :     }
     267             : 
     268             :     public Registration add(ActionVisitor actionVisitor) {
     269           1 :       return add(actionVisitors, actionVisitor);
     270             :     }
     271             : 
     272             :     public Registration add(DownloadScheme downloadScheme, String exportName) {
     273           1 :       return add(downloadSchemes, downloadScheme, exportName);
     274             :     }
     275             : 
     276             :     public Registration add(RefOperationValidationListener refOperationValidationListener) {
     277           2 :       return add(refOperationValidationListeners, refOperationValidationListener);
     278             :     }
     279             : 
     280             :     public Registration add(CommentAddedListener commentAddedListener) {
     281           3 :       return add(commentAddedListeners, commentAddedListener);
     282             :     }
     283             : 
     284             :     public Registration add(GitReferenceUpdatedListener refUpdatedListener) {
     285           1 :       return add(refUpdatedListeners, refUpdatedListener);
     286             :     }
     287             : 
     288             :     public Registration add(GitBatchRefUpdateListener batchRefUpdateListener) {
     289           0 :       return add(batchRefUpdateListeners, batchRefUpdateListener);
     290             :     }
     291             : 
     292             :     public Registration add(FileHistoryWebLink fileHistoryWebLink) {
     293           1 :       return add(fileHistoryWebLinks, fileHistoryWebLink);
     294             :     }
     295             : 
     296             :     public Registration add(PatchSetWebLink patchSetWebLink) {
     297           1 :       return add(patchSetWebLinks, patchSetWebLink);
     298             :     }
     299             : 
     300             :     public Registration add(ResolveConflictsWebLink resolveConflictsWebLink) {
     301           1 :       return add(resolveConflictsWebLinks, resolveConflictsWebLink);
     302             :     }
     303             : 
     304             :     public Registration add(EditWebLink editWebLink) {
     305           2 :       return add(editWebLinks, editWebLink);
     306             :     }
     307             : 
     308             :     public Registration add(FileWebLink fileWebLink) {
     309           2 :       return add(fileWebLinks, fileWebLink);
     310             :     }
     311             : 
     312             :     public Registration add(RevisionCreatedListener revisionCreatedListener) {
     313           1 :       return add(revisionCreatedListeners, revisionCreatedListener);
     314             :     }
     315             : 
     316             :     public Registration add(GroupBackend groupBackend) {
     317           4 :       return add(groupBackends, groupBackend);
     318             :     }
     319             : 
     320             :     public Registration add(
     321             :         AccountActivationValidationListener accountActivationValidationListener) {
     322           1 :       return add(accountActivationValidationListeners, accountActivationValidationListener);
     323             :     }
     324             : 
     325             :     public Registration add(AccountActivationListener accountDeactivatedListener) {
     326           1 :       return add(accountActivationListeners, accountDeactivatedListener);
     327             :     }
     328             : 
     329             :     public Registration add(OnSubmitValidationListener onSubmitValidationListener) {
     330           6 :       return add(onSubmitValidationListeners, onSubmitValidationListener);
     331             :     }
     332             : 
     333             :     public Registration add(WorkInProgressStateChangedListener workInProgressStateChangedListener) {
     334           2 :       return add(workInProgressStateChangedListeners, workInProgressStateChangedListener);
     335             :     }
     336             : 
     337             :     public Registration add(AttentionSetListener attentionSetListener) {
     338           1 :       return add(attentionSetListeners, attentionSetListener);
     339             :     }
     340             : 
     341             :     public Registration add(CapabilityDefinition capabilityDefinition, String exportName) {
     342           1 :       return add(capabilityDefinitions, capabilityDefinition, exportName);
     343             :     }
     344             : 
     345             :     public Registration add(
     346             :         PluginProjectPermissionDefinition pluginProjectPermissionDefinition, String exportName) {
     347           1 :       return add(pluginProjectPermissionDefinitions, pluginProjectPermissionDefinition, exportName);
     348             :     }
     349             : 
     350             :     public Registration add(ProjectConfigEntry pluginConfigEntry, String exportName) {
     351           1 :       return add(pluginConfigEntries, pluginConfigEntry, exportName);
     352             :     }
     353             : 
     354             :     public Registration add(PluginPushOption pluginPushOption) {
     355           3 :       return add(pluginPushOptions, pluginPushOption);
     356             :     }
     357             : 
     358             :     public Registration add(OnPostReview onPostReview) {
     359           1 :       return add(onPostReviews, onPostReview);
     360             :     }
     361             : 
     362             :     public Registration add(ReviewerAddedListener reviewerAddedListener) {
     363           1 :       return add(reviewerAddedListeners, reviewerAddedListener);
     364             :     }
     365             : 
     366             :     public Registration add(ReviewerDeletedListener reviewerDeletedListener) {
     367           1 :       return add(reviewerDeletedListeners, reviewerDeletedListener);
     368             :     }
     369             : 
     370             :     private <T> Registration add(DynamicSet<T> dynamicSet, T extension) {
     371          36 :       return add(dynamicSet, extension, "gerrit");
     372             :     }
     373             : 
     374             :     private <T> Registration add(DynamicSet<T> dynamicSet, T extension, String exportname) {
     375          36 :       RegistrationHandle registrationHandle = dynamicSet.add(exportname, extension);
     376          36 :       registrationHandles.add(registrationHandle);
     377          36 :       return this;
     378             :     }
     379             : 
     380             :     private <T> Registration add(DynamicMap<T> dynamicMap, T extension, String exportName) {
     381           3 :       RegistrationHandle registrationHandle =
     382             :           ((PrivateInternals_DynamicMapImpl<T>) dynamicMap)
     383           3 :               .put(PLUGIN_NAME, exportName, Providers.of(extension));
     384           3 :       registrationHandles.add(registrationHandle);
     385           3 :       return this;
     386             :     }
     387             : 
     388             :     @Override
     389             :     public void close() {
     390          36 :       registrationHandles.forEach(h -> h.remove());
     391          36 :     }
     392             :   }
     393             : }

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