diff options
author | Marcin Czech <maczech@gmail.com> | 2020-09-29 09:48:59 +0200 |
---|---|---|
committer | David Ostrovsky <david.ostrovsky@gmail.com> | 2022-07-18 11:56:42 +0000 |
commit | b0519a3d30c174112dd4f4579cdab5cd0e72652d (patch) | |
tree | e42a2d5fc3c3083d66d55bc6f758d22d01c54096 | |
parent | cf6ccb571f94c1d53a2ae721afcdd4b3def8ee5e (diff) |
Allow reuse of DelegateRepository functionality
By allowing plugins to reuse DelegateRepository functionality
multi-site and high-availability plugins can avoid code
duplication and significantly reduce the code complexity.
Also, make the annotation @UsedAt repeatable for associating
the DelegateRepository functionality with the usage from multiple
plugins.
Bug: Issue 13429
Release-Notes: skip
Change-Id: I2b5f5b215395fc1ef2a8008a71f5c09278d1278b
(cherry picked from commit ed54a267dafeed829722b340ccaee2bbbc7f94b3)
-rw-r--r-- | java/com/google/gerrit/common/UsedAt.java | 12 | ||||
-rw-r--r-- | java/com/google/gerrit/server/git/DelegateRepository.java | 9 |
2 files changed, 18 insertions, 3 deletions
diff --git a/java/com/google/gerrit/common/UsedAt.java b/java/com/google/gerrit/common/UsedAt.java index 9f8b2551bd..085a6010e7 100644 --- a/java/com/google/gerrit/common/UsedAt.java +++ b/java/com/google/gerrit/common/UsedAt.java @@ -19,6 +19,8 @@ import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; +import java.lang.annotation.ElementType; +import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.Target; @@ -28,6 +30,7 @@ import java.lang.annotation.Target; */ @Target({METHOD, TYPE, FIELD}) @Retention(RUNTIME) +@Repeatable(UsedAt.Uses.class) public @interface UsedAt { /** Enumeration of projects that call a method/type/field. */ enum Project { @@ -36,9 +39,18 @@ public @interface UsedAt { PLUGIN_CHECKS, PLUGIN_DELETE_PROJECT, PLUGIN_SERVICEUSER, + PLUGIN_HIGH_AVAILABILITY, + PLUGIN_MULTI_SITE, PLUGINS_ALL, // Use this project if a method/type is generally made available to all plugins. } /** Reference to the project that uses the method annotated with this annotation. */ Project value(); + + /** Allows to mark method/type/field with multiple UsedAt annotations. */ + @Retention(RUNTIME) + @Target(ElementType.TYPE) + @interface Uses { + UsedAt[] value(); + } } diff --git a/java/com/google/gerrit/server/git/DelegateRepository.java b/java/com/google/gerrit/server/git/DelegateRepository.java index b61488b657..9c860c49d5 100644 --- a/java/com/google/gerrit/server/git/DelegateRepository.java +++ b/java/com/google/gerrit/server/git/DelegateRepository.java @@ -14,6 +14,7 @@ package com.google.gerrit.server.git; +import com.google.gerrit.common.UsedAt; import java.io.IOException; import org.eclipse.jgit.attributes.AttributesNodeProvider; import org.eclipse.jgit.lib.BaseRepositoryBuilder; @@ -24,11 +25,13 @@ import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.StoredConfig; /** Wrapper around {@link Repository} that delegates all calls to the wrapped {@link Repository}. */ -class DelegateRepository extends Repository { +@UsedAt(UsedAt.Project.PLUGIN_HIGH_AVAILABILITY) +@UsedAt(UsedAt.Project.PLUGIN_MULTI_SITE) +public class DelegateRepository extends Repository { - private final Repository delegate; + protected final Repository delegate; - DelegateRepository(Repository delegate) { + protected DelegateRepository(Repository delegate) { super(toBuilder(delegate)); this.delegate = delegate; } |