All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.gerrit.acceptance.ExtensionRegistry Maven / Gradle / Ivy

There is a newer version: 3.11.0
Show newest version
// Copyright (C) 2019 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.gerrit.acceptance;

import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.gerrit.entities.SubmitRequirement;
import com.google.gerrit.extensions.api.changes.ActionVisitor;
import com.google.gerrit.extensions.config.CapabilityDefinition;
import com.google.gerrit.extensions.config.DownloadScheme;
import com.google.gerrit.extensions.config.PluginProjectPermissionDefinition;
import com.google.gerrit.extensions.events.AccountActivationListener;
import com.google.gerrit.extensions.events.AccountIndexedListener;
import com.google.gerrit.extensions.events.AttentionSetListener;
import com.google.gerrit.extensions.events.ChangeIndexedListener;
import com.google.gerrit.extensions.events.CommentAddedListener;
import com.google.gerrit.extensions.events.GitBatchRefUpdateListener;
import com.google.gerrit.extensions.events.GitReferenceUpdatedListener;
import com.google.gerrit.extensions.events.GroupIndexedListener;
import com.google.gerrit.extensions.events.ProjectIndexedListener;
import com.google.gerrit.extensions.events.ReviewerAddedListener;
import com.google.gerrit.extensions.events.ReviewerDeletedListener;
import com.google.gerrit.extensions.events.RevisionCreatedListener;
import com.google.gerrit.extensions.events.TopicEditedListener;
import com.google.gerrit.extensions.events.WorkInProgressStateChangedListener;
import com.google.gerrit.extensions.registration.DynamicMap;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.extensions.registration.PrivateInternals_DynamicMapImpl;
import com.google.gerrit.extensions.registration.RegistrationHandle;
import com.google.gerrit.extensions.webui.EditWebLink;
import com.google.gerrit.extensions.webui.FileHistoryWebLink;
import com.google.gerrit.extensions.webui.FileWebLink;
import com.google.gerrit.extensions.webui.PatchSetWebLink;
import com.google.gerrit.extensions.webui.ResolveConflictsWebLink;
import com.google.gerrit.server.ExceptionHook;
import com.google.gerrit.server.ServerStateProvider;
import com.google.gerrit.server.account.AccountStateProvider;
import com.google.gerrit.server.account.GroupBackend;
import com.google.gerrit.server.change.FilterIncludedIn;
import com.google.gerrit.server.change.ReviewerSuggestion;
import com.google.gerrit.server.config.ProjectConfigEntry;
import com.google.gerrit.server.git.ChangeMessageModifier;
import com.google.gerrit.server.git.receive.PluginPushOption;
import com.google.gerrit.server.git.validators.CommitValidationListener;
import com.google.gerrit.server.git.validators.OnSubmitValidationListener;
import com.google.gerrit.server.git.validators.RefOperationValidationListener;
import com.google.gerrit.server.logging.PerformanceLogger;
import com.google.gerrit.server.query.change.ChangeQueryBuilder.ChangeHasOperandFactory;
import com.google.gerrit.server.query.change.ChangeQueryBuilder.ChangeIsOperandFactory;
import com.google.gerrit.server.restapi.change.OnPostReview;
import com.google.gerrit.server.rules.SubmitRule;
import com.google.gerrit.server.validators.AccountActivationValidationListener;
import com.google.gerrit.server.validators.ProjectCreationValidationListener;
import com.google.inject.Inject;
import com.google.inject.util.Providers;
import java.util.ArrayList;
import java.util.List;

public class ExtensionRegistry {
  public static final String PLUGIN_NAME = "myPlugin";

  private final DynamicSet accountIndexedListeners;
  private final DynamicSet changeIndexedListeners;
  private final DynamicSet groupIndexedListeners;
  private final DynamicSet projectIndexedListeners;
  private final DynamicSet commitValidationListeners;
  private final DynamicSet topicEditedListeners;
  private final DynamicSet exceptionHooks;
  private final DynamicSet performanceLoggers;
  private final DynamicSet projectCreationValidationListeners;
  private final DynamicSet submitRules;
  private final DynamicSet submitRequirements;
  private final DynamicSet changeMessageModifiers;
  private final DynamicSet actionVisitors;
  private final DynamicMap downloadSchemes;
  private final DynamicSet refOperationValidationListeners;
  private final DynamicSet commentAddedListeners;
  private final DynamicSet refUpdatedListeners;
  private final DynamicSet batchRefUpdateListeners;
  private final DynamicSet fileHistoryWebLinks;
  private final DynamicSet filterIncludedIns;
  private final DynamicSet patchSetWebLinks;
  private final DynamicSet resolveConflictsWebLinks;
  private final DynamicSet editWebLinks;
  private final DynamicSet fileWebLinks;
  private final DynamicSet revisionCreatedListeners;
  private final DynamicSet groupBackends;
  private final DynamicSet
      accountActivationValidationListeners;
  private final DynamicSet accountActivationListeners;
  private final DynamicSet onSubmitValidationListeners;
  private final DynamicSet workInProgressStateChangedListeners;
  private final DynamicMap capabilityDefinitions;
  private final DynamicMap pluginProjectPermissionDefinitions;
  private final DynamicMap pluginConfigEntries;
  private final DynamicSet pluginPushOptions;
  private final DynamicSet onPostReviews;
  private final DynamicSet reviewerAddedListeners;
  private final DynamicSet reviewerDeletedListeners;
  private final DynamicSet serverStateProviders;
  private final DynamicSet accountStateProviders;
  private final DynamicSet attentionSetListeners;

  private final DynamicMap hasOperands;
  private final DynamicMap isOperands;
  private final DynamicMap reviewerSuggestions;

  @Inject
  ExtensionRegistry(
      DynamicSet accountIndexedListeners,
      DynamicSet changeIndexedListeners,
      DynamicSet groupIndexedListeners,
      DynamicSet projectIndexedListeners,
      DynamicSet commitValidationListeners,
      DynamicSet topicEditedListeners,
      DynamicSet exceptionHooks,
      DynamicSet performanceLoggers,
      DynamicSet projectCreationValidationListeners,
      DynamicSet submitRules,
      DynamicSet submitRequirements,
      DynamicSet changeMessageModifiers,
      DynamicSet actionVisitors,
      DynamicMap downloadSchemes,
      DynamicSet refOperationValidationListeners,
      DynamicSet commentAddedListeners,
      DynamicSet refUpdatedListeners,
      DynamicSet batchRefUpdateListeners,
      DynamicSet fileHistoryWebLinks,
      DynamicSet filterIncludedIns,
      DynamicSet patchSetWebLinks,
      DynamicSet resolveConflictsWebLinks,
      DynamicSet editWebLinks,
      DynamicSet fileWebLinks,
      DynamicSet revisionCreatedListeners,
      DynamicSet groupBackends,
      DynamicSet accountActivationValidationListeners,
      DynamicSet accountActivationListeners,
      DynamicSet onSubmitValidationListeners,
      DynamicSet workInProgressStateChangedListeners,
      DynamicMap capabilityDefinitions,
      DynamicMap pluginProjectPermissionDefinitions,
      DynamicMap pluginConfigEntries,
      DynamicSet pluginPushOption,
      DynamicSet onPostReviews,
      DynamicSet reviewerAddedListeners,
      DynamicSet reviewerDeletedListeners,
      DynamicMap hasOperands,
      DynamicMap isOperands,
      DynamicSet serverStateProviders,
      DynamicSet accountStateProviders,
      DynamicSet attentionSetListeners,
      DynamicMap reviewerSuggestions) {
    this.accountIndexedListeners = accountIndexedListeners;
    this.changeIndexedListeners = changeIndexedListeners;
    this.groupIndexedListeners = groupIndexedListeners;
    this.projectIndexedListeners = projectIndexedListeners;
    this.commitValidationListeners = commitValidationListeners;
    this.topicEditedListeners = topicEditedListeners;
    this.exceptionHooks = exceptionHooks;
    this.performanceLoggers = performanceLoggers;
    this.projectCreationValidationListeners = projectCreationValidationListeners;
    this.submitRules = submitRules;
    this.submitRequirements = submitRequirements;
    this.changeMessageModifiers = changeMessageModifiers;
    this.actionVisitors = actionVisitors;
    this.downloadSchemes = downloadSchemes;
    this.refOperationValidationListeners = refOperationValidationListeners;
    this.commentAddedListeners = commentAddedListeners;
    this.refUpdatedListeners = refUpdatedListeners;
    this.batchRefUpdateListeners = batchRefUpdateListeners;
    this.fileHistoryWebLinks = fileHistoryWebLinks;
    this.filterIncludedIns = filterIncludedIns;
    this.patchSetWebLinks = patchSetWebLinks;
    this.editWebLinks = editWebLinks;
    this.fileWebLinks = fileWebLinks;
    this.resolveConflictsWebLinks = resolveConflictsWebLinks;
    this.revisionCreatedListeners = revisionCreatedListeners;
    this.groupBackends = groupBackends;
    this.accountActivationValidationListeners = accountActivationValidationListeners;
    this.accountActivationListeners = accountActivationListeners;
    this.onSubmitValidationListeners = onSubmitValidationListeners;
    this.workInProgressStateChangedListeners = workInProgressStateChangedListeners;
    this.capabilityDefinitions = capabilityDefinitions;
    this.pluginProjectPermissionDefinitions = pluginProjectPermissionDefinitions;
    this.pluginConfigEntries = pluginConfigEntries;
    this.pluginPushOptions = pluginPushOption;
    this.onPostReviews = onPostReviews;
    this.reviewerAddedListeners = reviewerAddedListeners;
    this.reviewerDeletedListeners = reviewerDeletedListeners;
    this.hasOperands = hasOperands;
    this.isOperands = isOperands;
    this.serverStateProviders = serverStateProviders;
    this.accountStateProviders = accountStateProviders;
    this.attentionSetListeners = attentionSetListeners;
    this.reviewerSuggestions = reviewerSuggestions;
  }

  public Registration newRegistration() {
    return new Registration();
  }

  @SuppressWarnings("FunctionalInterfaceClash")
  public class Registration implements AutoCloseable {
    private final List registrationHandles = new ArrayList<>();

    @CanIgnoreReturnValue
    public Registration add(AccountIndexedListener accountIndexedListener) {
      return add(accountIndexedListeners, accountIndexedListener);
    }

    @CanIgnoreReturnValue
    public Registration add(ChangeIndexedListener changeIndexedListener) {
      return add(changeIndexedListeners, changeIndexedListener);
    }

    @CanIgnoreReturnValue
    public Registration add(GroupIndexedListener groupIndexedListener) {
      return add(groupIndexedListeners, groupIndexedListener);
    }

    @CanIgnoreReturnValue
    public Registration add(ProjectIndexedListener projectIndexedListener) {
      return add(projectIndexedListeners, projectIndexedListener);
    }

    @CanIgnoreReturnValue
    public Registration add(CommitValidationListener commitValidationListener) {
      return add(commitValidationListeners, commitValidationListener);
    }

    @CanIgnoreReturnValue
    public Registration add(TopicEditedListener topicEditedListener) {
      return add(topicEditedListeners, topicEditedListener);
    }

    @CanIgnoreReturnValue
    public Registration add(ExceptionHook exceptionHook) {
      return add(exceptionHooks, exceptionHook);
    }

    @CanIgnoreReturnValue
    public Registration add(PerformanceLogger performanceLogger) {
      return add(performanceLoggers, performanceLogger);
    }

    @CanIgnoreReturnValue
    public Registration add(ProjectCreationValidationListener projectCreationListener) {
      return add(projectCreationValidationListeners, projectCreationListener);
    }

    @CanIgnoreReturnValue
    public Registration add(SubmitRule submitRule) {
      return add(submitRules, submitRule);
    }

    @CanIgnoreReturnValue
    public Registration add(SubmitRequirement submitRequirement) {
      return add(submitRequirements, submitRequirement);
    }

    @CanIgnoreReturnValue
    public Registration add(ChangeHasOperandFactory hasOperand, String exportName) {
      return add(hasOperands, hasOperand, exportName);
    }

    @CanIgnoreReturnValue
    public Registration add(ChangeIsOperandFactory isOperand, String exportName) {
      return add(isOperands, isOperand, exportName);
    }

    @CanIgnoreReturnValue
    public Registration add(ChangeMessageModifier changeMessageModifier) {
      return add(changeMessageModifiers, changeMessageModifier);
    }

    @CanIgnoreReturnValue
    public Registration add(ChangeMessageModifier changeMessageModifier, String exportName) {
      return add(changeMessageModifiers, changeMessageModifier, exportName);
    }

    @CanIgnoreReturnValue
    public Registration add(ActionVisitor actionVisitor) {
      return add(actionVisitors, actionVisitor);
    }

    @CanIgnoreReturnValue
    public Registration add(DownloadScheme downloadScheme, String exportName) {
      return add(downloadSchemes, downloadScheme, exportName);
    }

    @CanIgnoreReturnValue
    public Registration add(RefOperationValidationListener refOperationValidationListener) {
      return add(refOperationValidationListeners, refOperationValidationListener);
    }

    @CanIgnoreReturnValue
    public Registration add(CommentAddedListener commentAddedListener) {
      return add(commentAddedListeners, commentAddedListener);
    }

    @CanIgnoreReturnValue
    public Registration add(GitReferenceUpdatedListener refUpdatedListener) {
      return add(refUpdatedListeners, refUpdatedListener);
    }

    @CanIgnoreReturnValue
    public Registration add(GitBatchRefUpdateListener batchRefUpdateListener) {
      return add(batchRefUpdateListeners, batchRefUpdateListener);
    }

    @CanIgnoreReturnValue
    public Registration add(FileHistoryWebLink fileHistoryWebLink) {
      return add(fileHistoryWebLinks, fileHistoryWebLink);
    }

    @CanIgnoreReturnValue
    public Registration add(FilterIncludedIn filterIncludedIn) {
      return add(filterIncludedIns, filterIncludedIn);
    }

    @CanIgnoreReturnValue
    public Registration add(PatchSetWebLink patchSetWebLink) {
      return add(patchSetWebLinks, patchSetWebLink);
    }

    @CanIgnoreReturnValue
    public Registration add(ResolveConflictsWebLink resolveConflictsWebLink) {
      return add(resolveConflictsWebLinks, resolveConflictsWebLink);
    }

    @CanIgnoreReturnValue
    public Registration add(EditWebLink editWebLink) {
      return add(editWebLinks, editWebLink);
    }

    @CanIgnoreReturnValue
    public Registration add(FileWebLink fileWebLink) {
      return add(fileWebLinks, fileWebLink);
    }

    @CanIgnoreReturnValue
    public Registration add(RevisionCreatedListener revisionCreatedListener) {
      return add(revisionCreatedListeners, revisionCreatedListener);
    }

    @CanIgnoreReturnValue
    public Registration add(GroupBackend groupBackend) {
      return add(groupBackends, groupBackend);
    }

    @CanIgnoreReturnValue
    public Registration add(
        AccountActivationValidationListener accountActivationValidationListener) {
      return add(accountActivationValidationListeners, accountActivationValidationListener);
    }

    @CanIgnoreReturnValue
    public Registration add(AccountActivationListener accountDeactivatedListener) {
      return add(accountActivationListeners, accountDeactivatedListener);
    }

    @CanIgnoreReturnValue
    public Registration add(OnSubmitValidationListener onSubmitValidationListener) {
      return add(onSubmitValidationListeners, onSubmitValidationListener);
    }

    @CanIgnoreReturnValue
    public Registration add(WorkInProgressStateChangedListener workInProgressStateChangedListener) {
      return add(workInProgressStateChangedListeners, workInProgressStateChangedListener);
    }

    @CanIgnoreReturnValue
    public Registration add(ServerStateProvider serverStateProvider) {
      return add(serverStateProviders, serverStateProvider);
    }

    @CanIgnoreReturnValue
    public Registration add(AccountStateProvider accountStateProvider) {
      return add(accountStateProviders, accountStateProvider);
    }

    @CanIgnoreReturnValue
    public Registration add(AttentionSetListener attentionSetListener) {
      return add(attentionSetListeners, attentionSetListener);
    }

    @CanIgnoreReturnValue
    public Registration add(CapabilityDefinition capabilityDefinition, String exportName) {
      return add(capabilityDefinitions, capabilityDefinition, exportName);
    }

    @CanIgnoreReturnValue
    public Registration add(
        PluginProjectPermissionDefinition pluginProjectPermissionDefinition, String exportName) {
      return add(pluginProjectPermissionDefinitions, pluginProjectPermissionDefinition, exportName);
    }

    @CanIgnoreReturnValue
    public Registration add(ProjectConfigEntry pluginConfigEntry, String exportName) {
      return add(pluginConfigEntries, pluginConfigEntry, exportName);
    }

    @CanIgnoreReturnValue
    public Registration add(PluginPushOption pluginPushOption) {
      return add(pluginPushOptions, pluginPushOption);
    }

    @CanIgnoreReturnValue
    public Registration add(OnPostReview onPostReview) {
      return add(onPostReviews, onPostReview);
    }

    @CanIgnoreReturnValue
    public Registration add(ReviewerAddedListener reviewerAddedListener) {
      return add(reviewerAddedListeners, reviewerAddedListener);
    }

    @CanIgnoreReturnValue
    public Registration add(ReviewerDeletedListener reviewerDeletedListener) {
      return add(reviewerDeletedListeners, reviewerDeletedListener);
    }

    @CanIgnoreReturnValue
    public Registration add(ReviewerSuggestion reviewerSuggestion, String exportName) {
      return add(reviewerSuggestions, reviewerSuggestion, exportName);
    }

    private  Registration add(DynamicSet dynamicSet, T extension) {
      return add(dynamicSet, extension, "gerrit");
    }

    private  Registration add(DynamicSet dynamicSet, T extension, String exportname) {
      RegistrationHandle registrationHandle = dynamicSet.add(exportname, extension);
      registrationHandles.add(registrationHandle);
      return this;
    }

    private  Registration add(DynamicMap dynamicMap, T extension, String exportName) {
      RegistrationHandle registrationHandle =
          ((PrivateInternals_DynamicMapImpl) dynamicMap)
              .put(PLUGIN_NAME, exportName, Providers.of(extension));
      registrationHandles.add(registrationHandle);
      return this;
    }

    @Override
    public void close() {
      registrationHandles.forEach(h -> h.remove());
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy