Merge "Revert "example-denyUpload""
diff --git a/BUILD b/BUILD
index 340fecd..8268bbb 100644
--- a/BUILD
+++ b/BUILD
@@ -2,7 +2,6 @@
name = "all",
srcs = [
"//example-adminSshCommand",
- "//example-assigneeValidator",
"//example-changeOperator",
"//example-commitValidator",
"//example-deployedOnIncludedInExtension",
@@ -12,6 +11,13 @@
"//example-simpleSshCommand",
"//example-sshCommandAlias",
"//example-topMenu",
+ "//example-validationListenerAssignee",
+ "//example-validationListenerCommit",
+ "//example-validationListenerHashtag",
+ "//example-validationListenerMerge",
+ "//example-validationListenerNewProjectCreated",
+ "//example-validationListenerRefOperation",
+ "//example-validationListenerUpload",
"//example-webLinkBranch",
"//example-webLinkFileHistory",
"//example-webLinkPatchSet",
diff --git a/example-assigneeValidator/BUCK b/example-assigneeValidator/BUCK
deleted file mode 100644
index 2eeaf10..0000000
--- a/example-assigneeValidator/BUCK
+++ /dev/null
@@ -1,18 +0,0 @@
-include_defs('//bucklets/gerrit_plugin.bucklet')
-
-gerrit_plugin(
- name = 'example-assigneeValidator',
- srcs = glob(['src/main/java/**/*.java']),
- resources = glob(['src/main/**/*']),
- manifest_entries = [
- 'Gerrit-PluginName: example-assigneeValidator',
- 'Gerrit-Module: com.googlesource.gerrit.plugins.examples.assigneevalidator.Module',
- 'Implementation-Title: Example Assignee Validator',
- 'Implementation-URL: https://gerrit-review.googlesource.com/#/admin/projects/plugins/examples',
- ],
-)
-
-java_library(
- name = 'classpath',
- deps = [':example-assigneevalidator__plugin'],
-)
diff --git a/example-assigneeValidator/BUILD b/example-assigneeValidator/BUILD
deleted file mode 100644
index 44a3877..0000000
--- a/example-assigneeValidator/BUILD
+++ /dev/null
@@ -1,12 +0,0 @@
-load("//tools/bzl:plugin.bzl", "gerrit_plugin")
-
-gerrit_plugin(
- name = "example-assigneeValidator",
- srcs = glob(["src/main/java/**/*.java"]),
- manifest_entries = [
- "Gerrit-PluginName: example-assigneeValidator",
- "Gerrit-Module: com.googlesource.gerrit.plugins.examples.assigneevalidator.Module",
- "Implementation-Title: Example Assignee Validator",
- ],
- resources = glob(["src/main/resources/**/*"]),
-)
diff --git a/example-assigneeValidator/bazel-example-assigneeValidator b/example-assigneeValidator/bazel-example-assigneeValidator
deleted file mode 120000
index 94bcb8f..0000000
--- a/example-assigneeValidator/bazel-example-assigneeValidator
+++ /dev/null
@@ -1 +0,0 @@
-/private/var/tmp/_bazel_jmelvin/ff3134ee89b7c76ee4c5952fa27dd382/execroot/assigneeValidator
\ No newline at end of file
diff --git a/example-assigneeValidator/src/main/resources/Documentation/about.md b/example-assigneeValidator/src/main/resources/Documentation/about.md
deleted file mode 100644
index 7b3bd87..0000000
--- a/example-assigneeValidator/src/main/resources/Documentation/about.md
+++ /dev/null
@@ -1 +0,0 @@
-Sample plugin to demonstrate the Assignee Validator feature of Gerrit's plugin API.
diff --git a/example-assigneeValidator/.buckconfig b/example-validationListenerAssignee/.buckconfig
similarity index 76%
copy from example-assigneeValidator/.buckconfig
copy to example-validationListenerAssignee/.buckconfig
index 00c5e8e..a597fac 100644
--- a/example-assigneeValidator/.buckconfig
+++ b/example-validationListenerAssignee/.buckconfig
@@ -1,5 +1,5 @@
[alias]
- plugin = //:example-assigneeValidator
+ plugin = //:example-validationListenerAssignee
[java]
src_roots = java, resources
diff --git a/example-validationListenerAssignee/.gitignore b/example-validationListenerAssignee/.gitignore
new file mode 100644
index 0000000..db1c934
--- /dev/null
+++ b/example-validationListenerAssignee/.gitignore
@@ -0,0 +1,8 @@
+/target
+/.classpath
+/.settings
+/.project
+/.buckd
+/buck-cache
+/buck-out
+*.iml
diff --git a/example-validationListenerAssignee/BUCK b/example-validationListenerAssignee/BUCK
new file mode 100644
index 0000000..625090c
--- /dev/null
+++ b/example-validationListenerAssignee/BUCK
@@ -0,0 +1,18 @@
+include_defs('//bucklets/gerrit_plugin.bucklet')
+
+gerrit_plugin(
+ name = 'example-validationListenerAssignee',
+ srcs = glob(['src/main/java/**/*.java']),
+ resources = glob(['src/main/**/*']),
+ manifest_entries = [
+ 'Gerrit-PluginName: example-validationListenerAssignee',
+ 'Gerrit-Module: com.googlesource.gerrit.plugins.examples.validationlistenerassignee.Module',
+ 'Implementation-Title: Example Validation Listener Assignee',
+ 'Implementation-URL: https://gerrit-review.googlesource.com/#/admin/projects/plugins/examples',
+ ],
+)
+
+java_library(
+ name = 'classpath',
+ deps = [':example-validationListenerAssignee__plugin'],
+)
diff --git a/example-validationListenerAssignee/BUILD b/example-validationListenerAssignee/BUILD
new file mode 100644
index 0000000..586f28a
--- /dev/null
+++ b/example-validationListenerAssignee/BUILD
@@ -0,0 +1,12 @@
+load("//tools/bzl:plugin.bzl", "gerrit_plugin")
+
+gerrit_plugin(
+ name = "example-validationListenerAssignee",
+ srcs = glob(["src/main/java/**/*.java"]),
+ manifest_entries = [
+ "Gerrit-PluginName: example-validationListenerAssignee",
+ "Gerrit-Module: com.googlesource.gerrit.plugins.examples.validationlistenerassignee.Module",
+ "Implementation-Title: Example Validation Listener Assignee",
+ ],
+ resources = glob(["src/main/resources/**/*"]),
+)
diff --git a/example-assigneeValidator/LICENSE b/example-validationListenerAssignee/LICENSE
similarity index 100%
copy from example-assigneeValidator/LICENSE
copy to example-validationListenerAssignee/LICENSE
diff --git a/example-assigneeValidator/WORKSPACE b/example-validationListenerAssignee/WORKSPACE
similarity index 91%
copy from example-assigneeValidator/WORKSPACE
copy to example-validationListenerAssignee/WORKSPACE
index 27f10b7..f8d65c3 100644
--- a/example-assigneeValidator/WORKSPACE
+++ b/example-validationListenerAssignee/WORKSPACE
@@ -1,4 +1,4 @@
-workspace(name = "assigneeValidator")
+workspace(name = "validationListenerAssignee")
load("//:bazlets.bzl", "load_bazlets")
diff --git a/example-assigneeValidator/bazlets.bzl b/example-validationListenerAssignee/bazlets.bzl
similarity index 100%
copy from example-assigneeValidator/bazlets.bzl
copy to example-validationListenerAssignee/bazlets.bzl
diff --git a/example-assigneeValidator/lib/gerrit/BUCK b/example-validationListenerAssignee/lib/gerrit/BUCK
similarity index 100%
copy from example-assigneeValidator/lib/gerrit/BUCK
copy to example-validationListenerAssignee/lib/gerrit/BUCK
diff --git a/example-assigneeValidator/pom.xml b/example-validationListenerAssignee/pom.xml
similarity index 89%
copy from example-assigneeValidator/pom.xml
copy to example-validationListenerAssignee/pom.xml
index 8491811..ec718bb 100644
--- a/example-assigneeValidator/pom.xml
+++ b/example-validationListenerAssignee/pom.xml
@@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlesource.gerrit.plugins</groupId>
- <artifactId>example-assigneeValidator</artifactId>
+ <artifactId>example-validationListenerAssignee</artifactId>
<packaging>jar</packaging>
<version>2.14-SNAPSHOT</version>
<properties>
@@ -37,13 +37,13 @@
<configuration>
<archive>
<manifestEntries>
- <Gerrit-PluginName>example-assigneeValidator</Gerrit-PluginName>
- <Gerrit-Module>com.googlesource.gerrit.plugins.examples.assigneevalidator.Module</Gerrit-Module>
+ <Gerrit-PluginName>example-validationListenerAssignee</Gerrit-PluginName>
+ <Gerrit-Module>com.googlesource.gerrit.plugins.examples.validationlistenerassignee.Module</Gerrit-Module>
<Implementation-Vendor>Gerrit Code Review</Implementation-Vendor>
<Implementation-URL>https://gerrit-review.googlesource.com/#/admin/projects/plugins/examples</Implementation-URL>
- <Implementation-Title>Example Assignee Validator</Implementation-Title>
+ <Implementation-Title>Example Validation Listener Assignee</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
<Gerrit-ApiType>${Gerrit-ApiType}</Gerrit-ApiType>
diff --git a/example-assigneeValidator/src/main/java/com/googlesource/gerrit/plugins/examples/assigneevalidator/AssigneeValidator.java b/example-validationListenerAssignee/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerassignee/AssigneeValidator.java
similarity index 68%
rename from example-assigneeValidator/src/main/java/com/googlesource/gerrit/plugins/examples/assigneevalidator/AssigneeValidator.java
rename to example-validationListenerAssignee/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerassignee/AssigneeValidator.java
index 0da6acd..63359ca 100644
--- a/example-assigneeValidator/src/main/java/com/googlesource/gerrit/plugins/examples/assigneevalidator/AssigneeValidator.java
+++ b/example-validationListenerAssignee/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerassignee/AssigneeValidator.java
@@ -1,4 +1,4 @@
-// Copyright (C) 2017 The Android Open Source Project
+// Copyright (C) 2014 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.
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package com.googlesource.gerrit.plugins.examples.assigneevalidator;
+package com.googlesource.gerrit.plugins.examples.validationlistenerassignee;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
@@ -23,28 +23,31 @@
import com.google.gerrit.server.validators.ValidationException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AssigneeValidator implements AssigneeValidationListener {
- private static final Logger log = LoggerFactory.getLogger(AssigneeValidationListener.class);
+ private static final Logger log =
+ LoggerFactory.getLogger(AssigneeValidationListener.class);
private static int MAX_ASSIGNED_CHANGES = 5;
- @Inject ChangeQueryBuilder queryBuilder;
+ @Inject
+ ChangeQueryBuilder queryBuilder;
- @Inject ChangeQueryProcessor queryProcessor;
+ @Inject
+ ChangeQueryProcessor queryProcessor;
@Override
- public void validateAssignee(Change change, Account assignee) throws ValidationException {
+ public void validateAssignee(Change change, Account assignee)
+ throws ValidationException {
try {
if (queryProcessor
- .query(queryBuilder.assignee(assignee.getPreferredEmail()))
- .entities()
- .size()
- > MAX_ASSIGNED_CHANGES) {
- throw new ValidationException(
- "Cannot assign user to more than " + MAX_ASSIGNED_CHANGES + " changes");
+ .query(queryBuilder.assignee(assignee.getPreferredEmail())).entities()
+ .size() > MAX_ASSIGNED_CHANGES) {
+ throw new ValidationException("Cannot assign user to more than "
+ + MAX_ASSIGNED_CHANGES + " changes");
}
} catch (OrmException | QueryParseException e) {
log.error("Failed to validate assignee for change " + change.getId(), e);
diff --git a/example-assigneeValidator/src/main/java/com/googlesource/gerrit/plugins/examples/assigneevalidator/Module.java b/example-validationListenerAssignee/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerassignee/Module.java
similarity index 77%
rename from example-assigneeValidator/src/main/java/com/googlesource/gerrit/plugins/examples/assigneevalidator/Module.java
rename to example-validationListenerAssignee/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerassignee/Module.java
index ceb85d5..05ff04d 100644
--- a/example-assigneeValidator/src/main/java/com/googlesource/gerrit/plugins/examples/assigneevalidator/Module.java
+++ b/example-validationListenerAssignee/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerassignee/Module.java
@@ -1,4 +1,4 @@
-// Copyright (C) 2017 The Android Open Source Project
+// Copyright (C) 2013 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.
@@ -12,16 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package com.googlesource.gerrit.plugins.examples.assigneevalidator;
+package com.googlesource.gerrit.plugins.examples.validationlistenerassignee;
-import com.google.inject.AbstractModule;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.server.validators.AssigneeValidationListener;
+import com.google.inject.AbstractModule;
public class Module extends AbstractModule {
@Override
protected void configure() {
- DynamicSet.bind(binder(),
- AssigneeValidationListener.class).to(AssigneeValidator.class);
+ DynamicSet.bind(binder(), AssigneeValidationListener.class)
+ .to(AssigneeValidator.class);
}
}
diff --git a/example-validationListenerAssignee/src/main/resources/Documentation/about.md b/example-validationListenerAssignee/src/main/resources/Documentation/about.md
new file mode 100644
index 0000000..05719a1
--- /dev/null
+++ b/example-validationListenerAssignee/src/main/resources/Documentation/about.md
@@ -0,0 +1 @@
+Sample plugin to demonstrate the validationListenerAssignee feature of Gerrit's plugin API.
diff --git a/example-assigneeValidator/tools/bazel.rc b/example-validationListenerAssignee/tools/bazel.rc
similarity index 100%
rename from example-assigneeValidator/tools/bazel.rc
rename to example-validationListenerAssignee/tools/bazel.rc
diff --git a/example-assigneeValidator/tools/bzl/BUILD b/example-validationListenerAssignee/tools/bzl/BUILD
similarity index 100%
copy from example-assigneeValidator/tools/bzl/BUILD
copy to example-validationListenerAssignee/tools/bzl/BUILD
diff --git a/example-assigneeValidator/tools/bzl/plugin.bzl b/example-validationListenerAssignee/tools/bzl/plugin.bzl
similarity index 100%
copy from example-assigneeValidator/tools/bzl/plugin.bzl
copy to example-validationListenerAssignee/tools/bzl/plugin.bzl
diff --git a/example-assigneeValidator/tools/workspace-status.sh b/example-validationListenerAssignee/tools/workspace-status.sh
similarity index 85%
copy from example-assigneeValidator/tools/workspace-status.sh
copy to example-validationListenerAssignee/tools/workspace-status.sh
index 0322307..95c851e 100755
--- a/example-assigneeValidator/tools/workspace-status.sh
+++ b/example-validationListenerAssignee/tools/workspace-status.sh
@@ -14,4 +14,4 @@
git describe --always --match "v[0-9].*" --dirty
}
-echo STABLE_BUILD_EXAMPLE-ASSIGNEEVALIDATOR_LABEL $(rev)
+echo STABLE_BUILD_EXAMPLE-VALIDATIONLISTENERASSIGNEE_LABEL $(rev)
diff --git a/example-assigneeValidator/.buckconfig b/example-validationListenerCommit/.buckconfig
similarity index 76%
copy from example-assigneeValidator/.buckconfig
copy to example-validationListenerCommit/.buckconfig
index 00c5e8e..c3ce4c8 100644
--- a/example-assigneeValidator/.buckconfig
+++ b/example-validationListenerCommit/.buckconfig
@@ -1,5 +1,5 @@
[alias]
- plugin = //:example-assigneeValidator
+ plugin = //:example-validationListenerCommit
[java]
src_roots = java, resources
diff --git a/example-validationListenerCommit/.gitignore b/example-validationListenerCommit/.gitignore
new file mode 100644
index 0000000..db1c934
--- /dev/null
+++ b/example-validationListenerCommit/.gitignore
@@ -0,0 +1,8 @@
+/target
+/.classpath
+/.settings
+/.project
+/.buckd
+/buck-cache
+/buck-out
+*.iml
diff --git a/example-validationListenerCommit/BUCK b/example-validationListenerCommit/BUCK
new file mode 100644
index 0000000..e61c849
--- /dev/null
+++ b/example-validationListenerCommit/BUCK
@@ -0,0 +1,18 @@
+include_defs('//bucklets/gerrit_plugin.bucklet')
+
+gerrit_plugin(
+ name = 'example-validationListenerCommit',
+ srcs = glob(['src/main/java/**/*.java']),
+ resources = glob(['src/main/**/*']),
+ manifest_entries = [
+ 'Gerrit-PluginName: example-validationListenerCommit',
+ 'Gerrit-Module: com.googlesource.gerrit.plugins.examples.validationlistenercommit.Module',
+ 'Implementation-Title: Example Validation Listener Commit',
+ 'Implementation-URL: https://gerrit-review.googlesource.com/#/admin/projects/plugins/examples',
+ ],
+)
+
+java_library(
+ name = 'classpath',
+ deps = [':example-validationListenerCommit__plugin'],
+)
diff --git a/example-validationListenerCommit/BUILD b/example-validationListenerCommit/BUILD
new file mode 100644
index 0000000..9763959
--- /dev/null
+++ b/example-validationListenerCommit/BUILD
@@ -0,0 +1,12 @@
+load("//tools/bzl:plugin.bzl", "gerrit_plugin")
+
+gerrit_plugin(
+ name = "example-validationListenerCommit",
+ srcs = glob(["src/main/java/**/*.java"]),
+ manifest_entries = [
+ "Gerrit-PluginName: example-validationListenerCommit",
+ "Gerrit-Module: com.googlesource.gerrit.plugins.examples.validationlistenercommit.Module",
+ "Implementation-Title: Example Validation Listener Commit",
+ ],
+ resources = glob(["src/main/resources/**/*"]),
+)
diff --git a/example-assigneeValidator/LICENSE b/example-validationListenerCommit/LICENSE
similarity index 100%
copy from example-assigneeValidator/LICENSE
copy to example-validationListenerCommit/LICENSE
diff --git a/example-assigneeValidator/WORKSPACE b/example-validationListenerCommit/WORKSPACE
similarity index 91%
copy from example-assigneeValidator/WORKSPACE
copy to example-validationListenerCommit/WORKSPACE
index 27f10b7..819a4ac 100644
--- a/example-assigneeValidator/WORKSPACE
+++ b/example-validationListenerCommit/WORKSPACE
@@ -1,4 +1,4 @@
-workspace(name = "assigneeValidator")
+workspace(name = "validationListenerCommit")
load("//:bazlets.bzl", "load_bazlets")
diff --git a/example-assigneeValidator/bazlets.bzl b/example-validationListenerCommit/bazlets.bzl
similarity index 100%
copy from example-assigneeValidator/bazlets.bzl
copy to example-validationListenerCommit/bazlets.bzl
diff --git a/example-assigneeValidator/lib/gerrit/BUCK b/example-validationListenerCommit/lib/gerrit/BUCK
similarity index 100%
rename from example-assigneeValidator/lib/gerrit/BUCK
rename to example-validationListenerCommit/lib/gerrit/BUCK
diff --git a/example-assigneeValidator/pom.xml b/example-validationListenerCommit/pom.xml
similarity index 89%
copy from example-assigneeValidator/pom.xml
copy to example-validationListenerCommit/pom.xml
index 8491811..1d0785e 100644
--- a/example-assigneeValidator/pom.xml
+++ b/example-validationListenerCommit/pom.xml
@@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlesource.gerrit.plugins</groupId>
- <artifactId>example-assigneeValidator</artifactId>
+ <artifactId>example-validationListenerCommit</artifactId>
<packaging>jar</packaging>
<version>2.14-SNAPSHOT</version>
<properties>
@@ -37,13 +37,13 @@
<configuration>
<archive>
<manifestEntries>
- <Gerrit-PluginName>example-assigneeValidator</Gerrit-PluginName>
- <Gerrit-Module>com.googlesource.gerrit.plugins.examples.assigneevalidator.Module</Gerrit-Module>
+ <Gerrit-PluginName>example-validationListenerCommit</Gerrit-PluginName>
+ <Gerrit-Module>com.googlesource.gerrit.plugins.examples.validationlistenercommit.Module</Gerrit-Module>
<Implementation-Vendor>Gerrit Code Review</Implementation-Vendor>
<Implementation-URL>https://gerrit-review.googlesource.com/#/admin/projects/plugins/examples</Implementation-URL>
- <Implementation-Title>Example Assignee Validator</Implementation-Title>
+ <Implementation-Title>Example Validation Listener Commit</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
<Gerrit-ApiType>${Gerrit-ApiType}</Gerrit-ApiType>
diff --git a/example-validationListenerCommit/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenercommit/CommitValidator.java b/example-validationListenerCommit/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenercommit/CommitValidator.java
new file mode 100644
index 0000000..70bca21
--- /dev/null
+++ b/example-validationListenerCommit/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenercommit/CommitValidator.java
@@ -0,0 +1,38 @@
+// Copyright (C) 2015 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.googlesource.gerrit.plugins.examples.validationlistenercommit;
+
+import com.google.common.collect.ImmutableList;
+import com.google.gerrit.server.events.CommitReceivedEvent;
+import com.google.gerrit.server.git.validators.CommitValidationException;
+import com.google.gerrit.server.git.validators.CommitValidationListener;
+import com.google.gerrit.server.git.validators.CommitValidationMessage;
+
+import java.util.List;
+
+public class CommitValidator implements CommitValidationListener {
+ @Override
+ public List<CommitValidationMessage> onCommitReceived(
+ CommitReceivedEvent receiveEvent) throws CommitValidationException {
+ if ("plugins/example-validationListenerCommit".equals(receiveEvent.project.getName()) &&
+ !receiveEvent.commit.getShortMessage().startsWith("Cookbook: ")) {
+ CommitValidationMessage m = new CommitValidationMessage(
+ "Subject should begin with 'Cookbook: '", true);
+ throw new CommitValidationException(
+ "Invalid commit message", ImmutableList.of(m));
+ }
+ return ImmutableList.of();
+ }
+}
diff --git a/example-assigneeValidator/src/main/java/com/googlesource/gerrit/plugins/examples/assigneevalidator/Module.java b/example-validationListenerCommit/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenercommit/Module.java
similarity index 71%
copy from example-assigneeValidator/src/main/java/com/googlesource/gerrit/plugins/examples/assigneevalidator/Module.java
copy to example-validationListenerCommit/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenercommit/Module.java
index ceb85d5..db39957 100644
--- a/example-assigneeValidator/src/main/java/com/googlesource/gerrit/plugins/examples/assigneevalidator/Module.java
+++ b/example-validationListenerCommit/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenercommit/Module.java
@@ -1,4 +1,4 @@
-// Copyright (C) 2017 The Android Open Source Project
+// Copyright (C) 2013 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.
@@ -12,16 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package com.googlesource.gerrit.plugins.examples.assigneevalidator;
+package com.googlesource.gerrit.plugins.examples.validationlistenercommit;
-import com.google.inject.AbstractModule;
import com.google.gerrit.extensions.registration.DynamicSet;
-import com.google.gerrit.server.validators.AssigneeValidationListener;
+import com.google.gerrit.server.git.validators.CommitValidationListener;
+import com.google.inject.AbstractModule;
public class Module extends AbstractModule {
@Override
protected void configure() {
- DynamicSet.bind(binder(),
- AssigneeValidationListener.class).to(AssigneeValidator.class);
+ DynamicSet.bind(binder(), CommitValidationListener.class)
+ .to(CommitValidator.class);
}
}
diff --git a/example-validationListenerCommit/src/main/resources/Documentation/about.md b/example-validationListenerCommit/src/main/resources/Documentation/about.md
new file mode 100644
index 0000000..f0fcc33
--- /dev/null
+++ b/example-validationListenerCommit/src/main/resources/Documentation/about.md
@@ -0,0 +1 @@
+Sample plugin to demonstrate the validationListenerCommit feature of Gerrit's plugin API.
diff --git a/example-assigneeValidator/tools/bazel.rc b/example-validationListenerCommit/tools/bazel.rc
similarity index 100%
copy from example-assigneeValidator/tools/bazel.rc
copy to example-validationListenerCommit/tools/bazel.rc
diff --git a/example-assigneeValidator/tools/bzl/BUILD b/example-validationListenerCommit/tools/bzl/BUILD
similarity index 100%
copy from example-assigneeValidator/tools/bzl/BUILD
copy to example-validationListenerCommit/tools/bzl/BUILD
diff --git a/example-assigneeValidator/tools/bzl/plugin.bzl b/example-validationListenerCommit/tools/bzl/plugin.bzl
similarity index 100%
copy from example-assigneeValidator/tools/bzl/plugin.bzl
copy to example-validationListenerCommit/tools/bzl/plugin.bzl
diff --git a/example-assigneeValidator/tools/workspace-status.sh b/example-validationListenerCommit/tools/workspace-status.sh
similarity index 85%
copy from example-assigneeValidator/tools/workspace-status.sh
copy to example-validationListenerCommit/tools/workspace-status.sh
index 0322307..5488fc6 100755
--- a/example-assigneeValidator/tools/workspace-status.sh
+++ b/example-validationListenerCommit/tools/workspace-status.sh
@@ -14,4 +14,4 @@
git describe --always --match "v[0-9].*" --dirty
}
-echo STABLE_BUILD_EXAMPLE-ASSIGNEEVALIDATOR_LABEL $(rev)
+echo STABLE_BUILD_EXAMPLE-VALIDATIONLISTENERCOMMIT_LABEL $(rev)
diff --git a/example-assigneeValidator/.buckconfig b/example-validationListenerHashtag/.buckconfig
similarity index 76%
copy from example-assigneeValidator/.buckconfig
copy to example-validationListenerHashtag/.buckconfig
index 00c5e8e..4ef2069 100644
--- a/example-assigneeValidator/.buckconfig
+++ b/example-validationListenerHashtag/.buckconfig
@@ -1,5 +1,5 @@
[alias]
- plugin = //:example-assigneeValidator
+ plugin = //:example-validationListenerHashtag
[java]
src_roots = java, resources
diff --git a/example-validationListenerHashtag/.gitignore b/example-validationListenerHashtag/.gitignore
new file mode 100644
index 0000000..db1c934
--- /dev/null
+++ b/example-validationListenerHashtag/.gitignore
@@ -0,0 +1,8 @@
+/target
+/.classpath
+/.settings
+/.project
+/.buckd
+/buck-cache
+/buck-out
+*.iml
diff --git a/example-validationListenerHashtag/BUCK b/example-validationListenerHashtag/BUCK
new file mode 100644
index 0000000..0c76c5a
--- /dev/null
+++ b/example-validationListenerHashtag/BUCK
@@ -0,0 +1,18 @@
+include_defs('//bucklets/gerrit_plugin.bucklet')
+
+gerrit_plugin(
+ name = 'example-validationListenerHashtag',
+ srcs = glob(['src/main/java/**/*.java']),
+ resources = glob(['src/main/**/*']),
+ manifest_entries = [
+ 'Gerrit-PluginName: example-validationListenerHashtag',
+ 'Gerrit-Module: com.googlesource.gerrit.plugins.examples.validationlistenerhashtag.Module',
+ 'Implementation-Title: Example Validation Listener Hashtag',
+ 'Implementation-URL: https://gerrit-review.googlesource.com/#/admin/projects/plugins/examples',
+ ],
+)
+
+java_library(
+ name = 'classpath',
+ deps = [':example-validationListenerHashtag__plugin'],
+)
diff --git a/example-validationListenerHashtag/BUILD b/example-validationListenerHashtag/BUILD
new file mode 100644
index 0000000..3000268
--- /dev/null
+++ b/example-validationListenerHashtag/BUILD
@@ -0,0 +1,12 @@
+load("//tools/bzl:plugin.bzl", "gerrit_plugin")
+
+gerrit_plugin(
+ name = "example-validationListenerHashtag",
+ srcs = glob(["src/main/java/**/*.java"]),
+ manifest_entries = [
+ "Gerrit-PluginName: example-validationListenerHashtag",
+ "Gerrit-Module: com.googlesource.gerrit.plugins.examples.validationlistenerhashtag.Module",
+ "Implementation-Title: Example Validation Listener Hashtag",
+ ],
+ resources = glob(["src/main/resources/**/*"]),
+)
diff --git a/example-assigneeValidator/LICENSE b/example-validationListenerHashtag/LICENSE
similarity index 100%
copy from example-assigneeValidator/LICENSE
copy to example-validationListenerHashtag/LICENSE
diff --git a/example-assigneeValidator/WORKSPACE b/example-validationListenerHashtag/WORKSPACE
similarity index 91%
copy from example-assigneeValidator/WORKSPACE
copy to example-validationListenerHashtag/WORKSPACE
index 27f10b7..8a5d367 100644
--- a/example-assigneeValidator/WORKSPACE
+++ b/example-validationListenerHashtag/WORKSPACE
@@ -1,4 +1,4 @@
-workspace(name = "assigneeValidator")
+workspace(name = "validationListenerHashtag")
load("//:bazlets.bzl", "load_bazlets")
diff --git a/example-assigneeValidator/bazlets.bzl b/example-validationListenerHashtag/bazlets.bzl
similarity index 100%
copy from example-assigneeValidator/bazlets.bzl
copy to example-validationListenerHashtag/bazlets.bzl
diff --git a/example-assigneeValidator/lib/gerrit/BUCK b/example-validationListenerHashtag/lib/gerrit/BUCK
similarity index 100%
copy from example-assigneeValidator/lib/gerrit/BUCK
copy to example-validationListenerHashtag/lib/gerrit/BUCK
diff --git a/example-assigneeValidator/pom.xml b/example-validationListenerHashtag/pom.xml
similarity index 89%
copy from example-assigneeValidator/pom.xml
copy to example-validationListenerHashtag/pom.xml
index 8491811..7965f8d 100644
--- a/example-assigneeValidator/pom.xml
+++ b/example-validationListenerHashtag/pom.xml
@@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlesource.gerrit.plugins</groupId>
- <artifactId>example-assigneeValidator</artifactId>
+ <artifactId>example-validationListenerHashtag</artifactId>
<packaging>jar</packaging>
<version>2.14-SNAPSHOT</version>
<properties>
@@ -37,13 +37,13 @@
<configuration>
<archive>
<manifestEntries>
- <Gerrit-PluginName>example-assigneeValidator</Gerrit-PluginName>
- <Gerrit-Module>com.googlesource.gerrit.plugins.examples.assigneevalidator.Module</Gerrit-Module>
+ <Gerrit-PluginName>example-validationListenerHashtag</Gerrit-PluginName>
+ <Gerrit-Module>com.googlesource.gerrit.plugins.examples.validationlistenerhashtag.Module</Gerrit-Module>
<Implementation-Vendor>Gerrit Code Review</Implementation-Vendor>
<Implementation-URL>https://gerrit-review.googlesource.com/#/admin/projects/plugins/examples</Implementation-URL>
- <Implementation-Title>Example Assignee Validator</Implementation-Title>
+ <Implementation-Title>Example Validation Listener Hashtag</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
<Gerrit-ApiType>${Gerrit-ApiType}</Gerrit-ApiType>
diff --git a/example-validationListenerHashtag/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerhashtag/HashtagValidator.java b/example-validationListenerHashtag/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerhashtag/HashtagValidator.java
new file mode 100644
index 0000000..02e149e
--- /dev/null
+++ b/example-validationListenerHashtag/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerhashtag/HashtagValidator.java
@@ -0,0 +1,42 @@
+// Copyright (C) 2014 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.googlesource.gerrit.plugins.examples.validationlistenerhashtag;
+
+import com.google.gerrit.reviewdb.client.Change;
+import com.google.gerrit.server.validators.HashtagValidationListener;
+import com.google.gerrit.server.validators.ValidationException;
+
+import java.util.Set;
+
+public class HashtagValidator implements HashtagValidationListener {
+
+ @Override
+ public void validateHashtags(Change change, Set<String> toAdd, Set<String> toRemove)
+ throws ValidationException {
+ if (change.getProject().get().equals("plugins/example-validationListenerHashtag")) {
+ if (toAdd.size() > 0) {
+ for (String hashtag : toAdd) {
+ if (!hashtag.startsWith("example-validationListenerHashtag-")) {
+ throw new ValidationException("Invalid example-validationListenerHashtag hashtag: " + hashtag);
+ }
+ }
+ }
+
+ if (toRemove.size() > 0) {
+ throw new ValidationException("Cannot remove example-validationListenerHashtag hashtags");
+ }
+ }
+ }
+}
diff --git a/example-assigneeValidator/src/main/java/com/googlesource/gerrit/plugins/examples/assigneevalidator/Module.java b/example-validationListenerHashtag/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerhashtag/Module.java
similarity index 71%
copy from example-assigneeValidator/src/main/java/com/googlesource/gerrit/plugins/examples/assigneevalidator/Module.java
copy to example-validationListenerHashtag/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerhashtag/Module.java
index ceb85d5..43c4426 100644
--- a/example-assigneeValidator/src/main/java/com/googlesource/gerrit/plugins/examples/assigneevalidator/Module.java
+++ b/example-validationListenerHashtag/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerhashtag/Module.java
@@ -1,4 +1,4 @@
-// Copyright (C) 2017 The Android Open Source Project
+// Copyright (C) 2013 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.
@@ -12,16 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package com.googlesource.gerrit.plugins.examples.assigneevalidator;
+package com.googlesource.gerrit.plugins.examples.validationlistenerhashtag;
-import com.google.inject.AbstractModule;
import com.google.gerrit.extensions.registration.DynamicSet;
-import com.google.gerrit.server.validators.AssigneeValidationListener;
+import com.google.gerrit.server.validators.HashtagValidationListener;
+import com.google.inject.AbstractModule;
public class Module extends AbstractModule {
@Override
protected void configure() {
- DynamicSet.bind(binder(),
- AssigneeValidationListener.class).to(AssigneeValidator.class);
+ DynamicSet.bind(binder(), HashtagValidationListener.class)
+ .to(HashtagValidator.class);
}
}
diff --git a/example-validationListenerHashtag/src/main/resources/Documentation/about.md b/example-validationListenerHashtag/src/main/resources/Documentation/about.md
new file mode 100644
index 0000000..f5c1bef
--- /dev/null
+++ b/example-validationListenerHashtag/src/main/resources/Documentation/about.md
@@ -0,0 +1 @@
+Sample plugin to demonstrate the validationListenerHashtag feature of Gerrit's plugin API.
diff --git a/example-assigneeValidator/tools/bazel.rc b/example-validationListenerHashtag/tools/bazel.rc
similarity index 100%
copy from example-assigneeValidator/tools/bazel.rc
copy to example-validationListenerHashtag/tools/bazel.rc
diff --git a/example-assigneeValidator/tools/bzl/BUILD b/example-validationListenerHashtag/tools/bzl/BUILD
similarity index 100%
copy from example-assigneeValidator/tools/bzl/BUILD
copy to example-validationListenerHashtag/tools/bzl/BUILD
diff --git a/example-assigneeValidator/tools/bzl/plugin.bzl b/example-validationListenerHashtag/tools/bzl/plugin.bzl
similarity index 100%
copy from example-assigneeValidator/tools/bzl/plugin.bzl
copy to example-validationListenerHashtag/tools/bzl/plugin.bzl
diff --git a/example-assigneeValidator/tools/workspace-status.sh b/example-validationListenerHashtag/tools/workspace-status.sh
similarity index 85%
copy from example-assigneeValidator/tools/workspace-status.sh
copy to example-validationListenerHashtag/tools/workspace-status.sh
index 0322307..0f2d3fe 100755
--- a/example-assigneeValidator/tools/workspace-status.sh
+++ b/example-validationListenerHashtag/tools/workspace-status.sh
@@ -14,4 +14,4 @@
git describe --always --match "v[0-9].*" --dirty
}
-echo STABLE_BUILD_EXAMPLE-ASSIGNEEVALIDATOR_LABEL $(rev)
+echo STABLE_BUILD_EXAMPLE-VALIDATIONLISTENERHASHTAG_LABEL $(rev)
diff --git a/example-assigneeValidator/.buckconfig b/example-validationListenerMerge/.buckconfig
similarity index 77%
rename from example-assigneeValidator/.buckconfig
rename to example-validationListenerMerge/.buckconfig
index 00c5e8e..22eee3f 100644
--- a/example-assigneeValidator/.buckconfig
+++ b/example-validationListenerMerge/.buckconfig
@@ -1,5 +1,5 @@
[alias]
- plugin = //:example-assigneeValidator
+ plugin = //:example-validationListenerMerge
[java]
src_roots = java, resources
diff --git a/example-validationListenerMerge/.gitignore b/example-validationListenerMerge/.gitignore
new file mode 100644
index 0000000..db1c934
--- /dev/null
+++ b/example-validationListenerMerge/.gitignore
@@ -0,0 +1,8 @@
+/target
+/.classpath
+/.settings
+/.project
+/.buckd
+/buck-cache
+/buck-out
+*.iml
diff --git a/example-validationListenerMerge/BUCK b/example-validationListenerMerge/BUCK
new file mode 100644
index 0000000..49d3948
--- /dev/null
+++ b/example-validationListenerMerge/BUCK
@@ -0,0 +1,18 @@
+include_defs('//bucklets/gerrit_plugin.bucklet')
+
+gerrit_plugin(
+ name = 'example-validationListenerMerge',
+ srcs = glob(['src/main/java/**/*.java']),
+ resources = glob(['src/main/**/*']),
+ manifest_entries = [
+ 'Gerrit-PluginName: example-validationListenerMerge',
+ 'Gerrit-Module: com.googlesource.gerrit.plugins.examples.validationlistenermerge.Module',
+ 'Implementation-Title: Example Validation Listener Merge',
+ 'Implementation-URL: https://gerrit-review.googlesource.com/#/admin/projects/plugins/examples',
+ ],
+)
+
+java_library(
+ name = 'classpath',
+ deps = [':example-validationListenerMerge__plugin'],
+)
diff --git a/example-validationListenerMerge/BUILD b/example-validationListenerMerge/BUILD
new file mode 100644
index 0000000..edf26e9
--- /dev/null
+++ b/example-validationListenerMerge/BUILD
@@ -0,0 +1,12 @@
+load("//tools/bzl:plugin.bzl", "gerrit_plugin")
+
+gerrit_plugin(
+ name = "example-validationListenerMerge",
+ srcs = glob(["src/main/java/**/*.java"]),
+ manifest_entries = [
+ "Gerrit-PluginName: example-validationListenerMerge",
+ "Gerrit-Module: com.googlesource.gerrit.plugins.examples.validationlistenermerge.Module",
+ "Implementation-Title: Example Validation Listener Merge",
+ ],
+ resources = glob(["src/main/resources/**/*"]),
+)
diff --git a/example-assigneeValidator/LICENSE b/example-validationListenerMerge/LICENSE
similarity index 100%
rename from example-assigneeValidator/LICENSE
rename to example-validationListenerMerge/LICENSE
diff --git a/example-assigneeValidator/WORKSPACE b/example-validationListenerMerge/WORKSPACE
similarity index 91%
copy from example-assigneeValidator/WORKSPACE
copy to example-validationListenerMerge/WORKSPACE
index 27f10b7..27f6664 100644
--- a/example-assigneeValidator/WORKSPACE
+++ b/example-validationListenerMerge/WORKSPACE
@@ -1,4 +1,4 @@
-workspace(name = "assigneeValidator")
+workspace(name = "validationListenerMerge")
load("//:bazlets.bzl", "load_bazlets")
diff --git a/example-assigneeValidator/bazlets.bzl b/example-validationListenerMerge/bazlets.bzl
similarity index 100%
rename from example-assigneeValidator/bazlets.bzl
rename to example-validationListenerMerge/bazlets.bzl
diff --git a/example-assigneeValidator/lib/gerrit/BUCK b/example-validationListenerMerge/lib/gerrit/BUCK
similarity index 100%
copy from example-assigneeValidator/lib/gerrit/BUCK
copy to example-validationListenerMerge/lib/gerrit/BUCK
diff --git a/example-assigneeValidator/pom.xml b/example-validationListenerMerge/pom.xml
similarity index 90%
rename from example-assigneeValidator/pom.xml
rename to example-validationListenerMerge/pom.xml
index 8491811..fce9a56 100644
--- a/example-assigneeValidator/pom.xml
+++ b/example-validationListenerMerge/pom.xml
@@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlesource.gerrit.plugins</groupId>
- <artifactId>example-assigneeValidator</artifactId>
+ <artifactId>example-validationListenerMerge</artifactId>
<packaging>jar</packaging>
<version>2.14-SNAPSHOT</version>
<properties>
@@ -37,13 +37,13 @@
<configuration>
<archive>
<manifestEntries>
- <Gerrit-PluginName>example-assigneeValidator</Gerrit-PluginName>
- <Gerrit-Module>com.googlesource.gerrit.plugins.examples.assigneevalidator.Module</Gerrit-Module>
+ <Gerrit-PluginName>example-validationListenerMerge</Gerrit-PluginName>
+ <Gerrit-Module>com.googlesource.gerrit.plugins.examples.validationlistenermerge.Module</Gerrit-Module>
<Implementation-Vendor>Gerrit Code Review</Implementation-Vendor>
<Implementation-URL>https://gerrit-review.googlesource.com/#/admin/projects/plugins/examples</Implementation-URL>
- <Implementation-Title>Example Assignee Validator</Implementation-Title>
+ <Implementation-Title>Example Validation Listener Merge</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
<Gerrit-ApiType>${Gerrit-ApiType}</Gerrit-ApiType>
diff --git a/example-validationListenerMerge/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenermerge/MergeUserValidator.java b/example-validationListenerMerge/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenermerge/MergeUserValidator.java
new file mode 100644
index 0000000..d8cbf98
--- /dev/null
+++ b/example-validationListenerMerge/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenermerge/MergeUserValidator.java
@@ -0,0 +1,49 @@
+// Copyright (C) 2014 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.googlesource.gerrit.plugins.examples.validationlistenermerge;
+
+import com.google.gerrit.reviewdb.client.Branch;
+import com.google.gerrit.reviewdb.client.PatchSet;
+import com.google.gerrit.server.IdentifiedUser;
+import com.google.gerrit.server.git.CodeReviewCommit;
+import com.google.gerrit.server.git.validators.MergeValidationException;
+import com.google.gerrit.server.git.validators.MergeValidationListener;
+import com.google.gerrit.server.project.ProjectState;
+import com.google.inject.Singleton;
+
+import org.eclipse.jgit.lib.Repository;
+
+// Because we have a dedicated Module, we need to bind to the set
+// there, however, if you are using this as a base for your own
+// plugin, you can simply comment out the 'Listen' annotation and
+// it will work as expected.
+//@Listen
+@Singleton
+public class MergeUserValidator implements MergeValidationListener {
+
+ /**
+ * Reject all merges if the submitter is not an administrator
+ */
+ @Override
+ public void onPreMerge(Repository repo, CodeReviewCommit commit,
+ ProjectState destProject, Branch.NameKey destBranch,
+ PatchSet.Id patchSetId, IdentifiedUser caller)
+ throws MergeValidationException {
+ if (!caller.getCapabilities().canAdministrateServer()) {
+ throw new MergeValidationException("Submitter " + caller.getNameEmail()
+ + " is not a site administrator");
+ }
+ }
+}
diff --git a/example-assigneeValidator/src/main/java/com/googlesource/gerrit/plugins/examples/assigneevalidator/Module.java b/example-validationListenerMerge/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenermerge/Module.java
similarity index 71%
copy from example-assigneeValidator/src/main/java/com/googlesource/gerrit/plugins/examples/assigneevalidator/Module.java
copy to example-validationListenerMerge/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenermerge/Module.java
index ceb85d5..dde757c 100644
--- a/example-assigneeValidator/src/main/java/com/googlesource/gerrit/plugins/examples/assigneevalidator/Module.java
+++ b/example-validationListenerMerge/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenermerge/Module.java
@@ -1,4 +1,4 @@
-// Copyright (C) 2017 The Android Open Source Project
+// Copyright (C) 2013 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.
@@ -12,16 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package com.googlesource.gerrit.plugins.examples.assigneevalidator;
+package com.googlesource.gerrit.plugins.examples.validationlistenermerge;
-import com.google.inject.AbstractModule;
import com.google.gerrit.extensions.registration.DynamicSet;
-import com.google.gerrit.server.validators.AssigneeValidationListener;
+import com.google.gerrit.server.git.validators.MergeValidationListener;
+import com.google.inject.AbstractModule;
public class Module extends AbstractModule {
@Override
protected void configure() {
- DynamicSet.bind(binder(),
- AssigneeValidationListener.class).to(AssigneeValidator.class);
+ DynamicSet.bind(binder(), MergeValidationListener.class)
+ .to(MergeUserValidator.class);
}
}
diff --git a/example-validationListenerMerge/src/main/resources/Documentation/about.md b/example-validationListenerMerge/src/main/resources/Documentation/about.md
new file mode 100644
index 0000000..7e66f71
--- /dev/null
+++ b/example-validationListenerMerge/src/main/resources/Documentation/about.md
@@ -0,0 +1 @@
+Sample plugin to demonstrate the validationListenerMerge feature of Gerrit's plugin API.
diff --git a/example-assigneeValidator/tools/bazel.rc b/example-validationListenerMerge/tools/bazel.rc
similarity index 100%
copy from example-assigneeValidator/tools/bazel.rc
copy to example-validationListenerMerge/tools/bazel.rc
diff --git a/example-assigneeValidator/tools/bzl/BUILD b/example-validationListenerMerge/tools/bzl/BUILD
similarity index 100%
rename from example-assigneeValidator/tools/bzl/BUILD
rename to example-validationListenerMerge/tools/bzl/BUILD
diff --git a/example-assigneeValidator/tools/bzl/plugin.bzl b/example-validationListenerMerge/tools/bzl/plugin.bzl
similarity index 100%
rename from example-assigneeValidator/tools/bzl/plugin.bzl
rename to example-validationListenerMerge/tools/bzl/plugin.bzl
diff --git a/example-assigneeValidator/tools/workspace-status.sh b/example-validationListenerMerge/tools/workspace-status.sh
similarity index 86%
rename from example-assigneeValidator/tools/workspace-status.sh
rename to example-validationListenerMerge/tools/workspace-status.sh
index 0322307..6928ad0 100755
--- a/example-assigneeValidator/tools/workspace-status.sh
+++ b/example-validationListenerMerge/tools/workspace-status.sh
@@ -14,4 +14,4 @@
git describe --always --match "v[0-9].*" --dirty
}
-echo STABLE_BUILD_EXAMPLE-ASSIGNEEVALIDATOR_LABEL $(rev)
+echo STABLE_BUILD_EXAMPLE-VALIDATIONLISTENERMERGE_LABEL $(rev)
diff --git a/example-assigneeValidator/.buckconfig b/example-validationListenerNewProjectCreated/.buckconfig
similarity index 72%
copy from example-assigneeValidator/.buckconfig
copy to example-validationListenerNewProjectCreated/.buckconfig
index 00c5e8e..0df5541 100644
--- a/example-assigneeValidator/.buckconfig
+++ b/example-validationListenerNewProjectCreated/.buckconfig
@@ -1,5 +1,5 @@
[alias]
- plugin = //:example-assigneeValidator
+ plugin = //:example-validationListenerNewProjectCreated
[java]
src_roots = java, resources
diff --git a/example-validationListenerNewProjectCreated/.gitignore b/example-validationListenerNewProjectCreated/.gitignore
new file mode 100644
index 0000000..db1c934
--- /dev/null
+++ b/example-validationListenerNewProjectCreated/.gitignore
@@ -0,0 +1,8 @@
+/target
+/.classpath
+/.settings
+/.project
+/.buckd
+/buck-cache
+/buck-out
+*.iml
diff --git a/example-validationListenerNewProjectCreated/BUCK b/example-validationListenerNewProjectCreated/BUCK
new file mode 100644
index 0000000..54a2277
--- /dev/null
+++ b/example-validationListenerNewProjectCreated/BUCK
@@ -0,0 +1,18 @@
+include_defs('//bucklets/gerrit_plugin.bucklet')
+
+gerrit_plugin(
+ name = 'example-validationListenerNewProjectCreated',
+ srcs = glob(['src/main/java/**/*.java']),
+ resources = glob(['src/main/**/*']),
+ manifest_entries = [
+ 'Gerrit-PluginName: example-validationListenerNewProjectCreated',
+ 'Gerrit-Module: com.googlesource.gerrit.plugins.examples.validationlistenernewprojectcreated.Module',
+ 'Implementation-Title: Example Validation Listener NewProjectCreated',
+ 'Implementation-URL: https://gerrit-review.googlesource.com/#/admin/projects/plugins/examples',
+ ],
+)
+
+java_library(
+ name = 'classpath',
+ deps = [':example-validationListenerNewProjectCreated__plugin'],
+)
diff --git a/example-validationListenerNewProjectCreated/BUILD b/example-validationListenerNewProjectCreated/BUILD
new file mode 100644
index 0000000..25d09c1
--- /dev/null
+++ b/example-validationListenerNewProjectCreated/BUILD
@@ -0,0 +1,12 @@
+load("//tools/bzl:plugin.bzl", "gerrit_plugin")
+
+gerrit_plugin(
+ name = "example-validationListenerNewProjectCreated",
+ srcs = glob(["src/main/java/**/*.java"]),
+ manifest_entries = [
+ "Gerrit-PluginName: example-validationListenerNewProjectCreated",
+ "Gerrit-Module: com.googlesource.gerrit.plugins.examples.validationlistenernewprojectcreated.Module",
+ "Implementation-Title: Example Validation Listener New Project Created",
+ ],
+ resources = glob(["src/main/resources/**/*"]),
+)
diff --git a/example-assigneeValidator/LICENSE b/example-validationListenerNewProjectCreated/LICENSE
similarity index 100%
copy from example-assigneeValidator/LICENSE
copy to example-validationListenerNewProjectCreated/LICENSE
diff --git a/example-assigneeValidator/WORKSPACE b/example-validationListenerNewProjectCreated/WORKSPACE
similarity index 89%
copy from example-assigneeValidator/WORKSPACE
copy to example-validationListenerNewProjectCreated/WORKSPACE
index 27f10b7..16abbe5 100644
--- a/example-assigneeValidator/WORKSPACE
+++ b/example-validationListenerNewProjectCreated/WORKSPACE
@@ -1,4 +1,4 @@
-workspace(name = "assigneeValidator")
+workspace(name = "validationListenerNewProjectCreated")
load("//:bazlets.bzl", "load_bazlets")
diff --git a/example-assigneeValidator/bazlets.bzl b/example-validationListenerNewProjectCreated/bazlets.bzl
similarity index 100%
copy from example-assigneeValidator/bazlets.bzl
copy to example-validationListenerNewProjectCreated/bazlets.bzl
diff --git a/example-assigneeValidator/lib/gerrit/BUCK b/example-validationListenerNewProjectCreated/lib/gerrit/BUCK
similarity index 100%
copy from example-assigneeValidator/lib/gerrit/BUCK
copy to example-validationListenerNewProjectCreated/lib/gerrit/BUCK
diff --git a/example-assigneeValidator/pom.xml b/example-validationListenerNewProjectCreated/pom.xml
similarity index 88%
copy from example-assigneeValidator/pom.xml
copy to example-validationListenerNewProjectCreated/pom.xml
index 8491811..f858854 100644
--- a/example-assigneeValidator/pom.xml
+++ b/example-validationListenerNewProjectCreated/pom.xml
@@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlesource.gerrit.plugins</groupId>
- <artifactId>example-assigneeValidator</artifactId>
+ <artifactId>example-validationListenerNewProjectCreated</artifactId>
<packaging>jar</packaging>
<version>2.14-SNAPSHOT</version>
<properties>
@@ -37,13 +37,13 @@
<configuration>
<archive>
<manifestEntries>
- <Gerrit-PluginName>example-assigneeValidator</Gerrit-PluginName>
- <Gerrit-Module>com.googlesource.gerrit.plugins.examples.assigneevalidator.Module</Gerrit-Module>
+ <Gerrit-PluginName>example-validationListenerNewProjectCreated</Gerrit-PluginName>
+ <Gerrit-Module>com.googlesource.gerrit.plugins.examples.validationlistenernewprojectcreated.Module</Gerrit-Module>
<Implementation-Vendor>Gerrit Code Review</Implementation-Vendor>
<Implementation-URL>https://gerrit-review.googlesource.com/#/admin/projects/plugins/examples</Implementation-URL>
- <Implementation-Title>Example Assignee Validator</Implementation-Title>
+ <Implementation-Title>Example Validation Listener NewProjectCreated</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
<Gerrit-ApiType>${Gerrit-ApiType}</Gerrit-ApiType>
diff --git a/example-assigneeValidator/src/main/java/com/googlesource/gerrit/plugins/examples/assigneevalidator/Module.java b/example-validationListenerNewProjectCreated/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenernewprojectcreated/Module.java
similarity index 70%
copy from example-assigneeValidator/src/main/java/com/googlesource/gerrit/plugins/examples/assigneevalidator/Module.java
copy to example-validationListenerNewProjectCreated/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenernewprojectcreated/Module.java
index ceb85d5..650febf 100644
--- a/example-assigneeValidator/src/main/java/com/googlesource/gerrit/plugins/examples/assigneevalidator/Module.java
+++ b/example-validationListenerNewProjectCreated/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenernewprojectcreated/Module.java
@@ -1,4 +1,4 @@
-// Copyright (C) 2017 The Android Open Source Project
+// Copyright (C) 2013 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.
@@ -12,16 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package com.googlesource.gerrit.plugins.examples.assigneevalidator;
+package com.googlesource.gerrit.plugins.examples.validationlistenernewprojectcreated;
-import com.google.inject.AbstractModule;
+import com.google.gerrit.extensions.events.NewProjectCreatedListener;
import com.google.gerrit.extensions.registration.DynamicSet;
-import com.google.gerrit.server.validators.AssigneeValidationListener;
+import com.google.inject.AbstractModule;
public class Module extends AbstractModule {
@Override
protected void configure() {
- DynamicSet.bind(binder(),
- AssigneeValidationListener.class).to(AssigneeValidator.class);
+ DynamicSet.bind(binder(), NewProjectCreatedListener.class)
+ .to(ProjectCreatedListener.class);
}
}
diff --git a/example-validationListenerNewProjectCreated/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenernewprojectcreated/ProjectCreatedListener.java b/example-validationListenerNewProjectCreated/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenernewprojectcreated/ProjectCreatedListener.java
new file mode 100644
index 0000000..33c4cc7
--- /dev/null
+++ b/example-validationListenerNewProjectCreated/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenernewprojectcreated/ProjectCreatedListener.java
@@ -0,0 +1,45 @@
+// Copyright (C) 2015 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.googlesource.gerrit.plugins.examples.validationlistenernewprojectcreated;
+
+import com.google.gerrit.extensions.api.GerritApi;
+import com.google.gerrit.extensions.api.projects.ProjectApi;
+import com.google.gerrit.extensions.events.NewProjectCreatedListener;
+import com.google.gerrit.extensions.restapi.RestApiException;
+import com.google.inject.Inject;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ProjectCreatedListener implements NewProjectCreatedListener {
+ private static final Logger log =
+ LoggerFactory.getLogger(ProjectCreatedListener.class);
+
+ @Inject
+ protected GerritApi gApi;
+
+ @Override
+ public void onNewProjectCreated(Event event) {
+ String name = event.getProjectName();
+ try {
+ ProjectApi api = gApi.projects().name(name);
+ log.info(String.format(
+ "New project: '%s', Parent: '%s'", name, api.get().parent));
+ } catch (RestApiException e) {
+ log.error(String.format(
+ "Failed to get info for new project %s", name), e);
+ }
+ }
+}
diff --git a/example-validationListenerNewProjectCreated/src/main/resources/Documentation/about.md b/example-validationListenerNewProjectCreated/src/main/resources/Documentation/about.md
new file mode 100644
index 0000000..18bf070
--- /dev/null
+++ b/example-validationListenerNewProjectCreated/src/main/resources/Documentation/about.md
@@ -0,0 +1 @@
+Sample plugin to demonstrate the validationListenerNewProjectCreated feature of Gerrit's plugin API.
diff --git a/example-assigneeValidator/tools/bazel.rc b/example-validationListenerNewProjectCreated/tools/bazel.rc
similarity index 100%
copy from example-assigneeValidator/tools/bazel.rc
copy to example-validationListenerNewProjectCreated/tools/bazel.rc
diff --git a/example-assigneeValidator/tools/bzl/BUILD b/example-validationListenerNewProjectCreated/tools/bzl/BUILD
similarity index 100%
copy from example-assigneeValidator/tools/bzl/BUILD
copy to example-validationListenerNewProjectCreated/tools/bzl/BUILD
diff --git a/example-assigneeValidator/tools/bzl/plugin.bzl b/example-validationListenerNewProjectCreated/tools/bzl/plugin.bzl
similarity index 100%
copy from example-assigneeValidator/tools/bzl/plugin.bzl
copy to example-validationListenerNewProjectCreated/tools/bzl/plugin.bzl
diff --git a/example-assigneeValidator/tools/workspace-status.sh b/example-validationListenerNewProjectCreated/tools/workspace-status.sh
similarity index 83%
copy from example-assigneeValidator/tools/workspace-status.sh
copy to example-validationListenerNewProjectCreated/tools/workspace-status.sh
index 0322307..6ab0b46 100755
--- a/example-assigneeValidator/tools/workspace-status.sh
+++ b/example-validationListenerNewProjectCreated/tools/workspace-status.sh
@@ -14,4 +14,4 @@
git describe --always --match "v[0-9].*" --dirty
}
-echo STABLE_BUILD_EXAMPLE-ASSIGNEEVALIDATOR_LABEL $(rev)
+echo STABLE_BUILD_EXAMPLE-VALIDATIONLISTENERNEWPROJECTCREATED_LABEL $(rev)
diff --git a/example-assigneeValidator/.buckconfig b/example-validationListenerRefOperation/.buckconfig
similarity index 74%
copy from example-assigneeValidator/.buckconfig
copy to example-validationListenerRefOperation/.buckconfig
index 00c5e8e..81a8e40 100644
--- a/example-assigneeValidator/.buckconfig
+++ b/example-validationListenerRefOperation/.buckconfig
@@ -1,5 +1,5 @@
[alias]
- plugin = //:example-assigneeValidator
+ plugin = //:example-validationListenerRefOperation
[java]
src_roots = java, resources
diff --git a/example-validationListenerRefOperation/.gitignore b/example-validationListenerRefOperation/.gitignore
new file mode 100644
index 0000000..db1c934
--- /dev/null
+++ b/example-validationListenerRefOperation/.gitignore
@@ -0,0 +1,8 @@
+/target
+/.classpath
+/.settings
+/.project
+/.buckd
+/buck-cache
+/buck-out
+*.iml
diff --git a/example-validationListenerRefOperation/BUCK b/example-validationListenerRefOperation/BUCK
new file mode 100644
index 0000000..35d515f
--- /dev/null
+++ b/example-validationListenerRefOperation/BUCK
@@ -0,0 +1,18 @@
+include_defs('//bucklets/gerrit_plugin.bucklet')
+
+gerrit_plugin(
+ name = 'example-validationListenerRefOperation',
+ srcs = glob(['src/main/java/**/*.java']),
+ resources = glob(['src/main/**/*']),
+ manifest_entries = [
+ 'Gerrit-PluginName: example-validationListenerRefOperation',
+ 'Gerrit-Module: com.googlesource.gerrit.plugins.examples.validationlistenerrefoperation.Module',
+ 'Implementation-Title: Example Validation Listener RefOperation',
+ 'Implementation-URL: https://gerrit-review.googlesource.com/#/admin/projects/plugins/examples',
+ ],
+)
+
+java_library(
+ name = 'classpath',
+ deps = [':example-validationListenerRefOperation__plugin'],
+)
diff --git a/example-validationListenerRefOperation/BUILD b/example-validationListenerRefOperation/BUILD
new file mode 100644
index 0000000..ba73ae4
--- /dev/null
+++ b/example-validationListenerRefOperation/BUILD
@@ -0,0 +1,12 @@
+load("//tools/bzl:plugin.bzl", "gerrit_plugin")
+
+gerrit_plugin(
+ name = "example-validationListenerRefOperation",
+ srcs = glob(["src/main/java/**/*.java"]),
+ manifest_entries = [
+ "Gerrit-PluginName: example-validationListenerRefOperation",
+ "Gerrit-Module: com.googlesource.gerrit.plugins.examples.validationlistenerrefoperation.Module",
+ "Implementation-Title: Example Validation Listener Ref Operation",
+ ],
+ resources = glob(["src/main/resources/**/*"]),
+)
diff --git a/example-assigneeValidator/LICENSE b/example-validationListenerRefOperation/LICENSE
similarity index 100%
copy from example-assigneeValidator/LICENSE
copy to example-validationListenerRefOperation/LICENSE
diff --git a/example-assigneeValidator/WORKSPACE b/example-validationListenerRefOperation/WORKSPACE
similarity index 90%
copy from example-assigneeValidator/WORKSPACE
copy to example-validationListenerRefOperation/WORKSPACE
index 27f10b7..fbf02d6 100644
--- a/example-assigneeValidator/WORKSPACE
+++ b/example-validationListenerRefOperation/WORKSPACE
@@ -1,4 +1,4 @@
-workspace(name = "assigneeValidator")
+workspace(name = "validationListenerRefOperation")
load("//:bazlets.bzl", "load_bazlets")
diff --git a/example-assigneeValidator/bazlets.bzl b/example-validationListenerRefOperation/bazlets.bzl
similarity index 100%
copy from example-assigneeValidator/bazlets.bzl
copy to example-validationListenerRefOperation/bazlets.bzl
diff --git a/example-assigneeValidator/lib/gerrit/BUCK b/example-validationListenerRefOperation/lib/gerrit/BUCK
similarity index 100%
copy from example-assigneeValidator/lib/gerrit/BUCK
copy to example-validationListenerRefOperation/lib/gerrit/BUCK
diff --git a/example-assigneeValidator/pom.xml b/example-validationListenerRefOperation/pom.xml
similarity index 89%
copy from example-assigneeValidator/pom.xml
copy to example-validationListenerRefOperation/pom.xml
index 8491811..9e92835 100644
--- a/example-assigneeValidator/pom.xml
+++ b/example-validationListenerRefOperation/pom.xml
@@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlesource.gerrit.plugins</groupId>
- <artifactId>example-assigneeValidator</artifactId>
+ <artifactId>example-validationListenerRefOperation</artifactId>
<packaging>jar</packaging>
<version>2.14-SNAPSHOT</version>
<properties>
@@ -37,13 +37,13 @@
<configuration>
<archive>
<manifestEntries>
- <Gerrit-PluginName>example-assigneeValidator</Gerrit-PluginName>
- <Gerrit-Module>com.googlesource.gerrit.plugins.examples.assigneevalidator.Module</Gerrit-Module>
+ <Gerrit-PluginName>example-validationListenerRefOperation</Gerrit-PluginName>
+ <Gerrit-Module>com.googlesource.gerrit.plugins.examples.validationlistenerrefoperation.Module</Gerrit-Module>
<Implementation-Vendor>Gerrit Code Review</Implementation-Vendor>
<Implementation-URL>https://gerrit-review.googlesource.com/#/admin/projects/plugins/examples</Implementation-URL>
- <Implementation-Title>Example Assignee Validator</Implementation-Title>
+ <Implementation-Title>Example Validation Listener RefOperation</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
<Gerrit-ApiType>${Gerrit-ApiType}</Gerrit-ApiType>
diff --git a/example-assigneeValidator/src/main/java/com/googlesource/gerrit/plugins/examples/assigneevalidator/Module.java b/example-validationListenerRefOperation/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerrefoperation/Module.java
similarity index 69%
copy from example-assigneeValidator/src/main/java/com/googlesource/gerrit/plugins/examples/assigneevalidator/Module.java
copy to example-validationListenerRefOperation/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerrefoperation/Module.java
index ceb85d5..b80fcff 100644
--- a/example-assigneeValidator/src/main/java/com/googlesource/gerrit/plugins/examples/assigneevalidator/Module.java
+++ b/example-validationListenerRefOperation/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerrefoperation/Module.java
@@ -1,4 +1,4 @@
-// Copyright (C) 2017 The Android Open Source Project
+// Copyright (C) 2013 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.
@@ -12,16 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package com.googlesource.gerrit.plugins.examples.assigneevalidator;
+package com.googlesource.gerrit.plugins.examples.validationlistenerrefoperation;
-import com.google.inject.AbstractModule;
import com.google.gerrit.extensions.registration.DynamicSet;
-import com.google.gerrit.server.validators.AssigneeValidationListener;
+import com.google.gerrit.server.git.validators.RefOperationValidationListener;
+import com.google.inject.AbstractModule;
public class Module extends AbstractModule {
@Override
protected void configure() {
- DynamicSet.bind(binder(),
- AssigneeValidationListener.class).to(AssigneeValidator.class);
+ DynamicSet.bind(binder(), RefOperationValidationListener.class)
+ .to(RefOperationValidationExample.class);
}
}
diff --git a/example-validationListenerRefOperation/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerrefoperation/RefOperationValidationExample.java b/example-validationListenerRefOperation/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerrefoperation/RefOperationValidationExample.java
new file mode 100644
index 0000000..4cabd36
--- /dev/null
+++ b/example-validationListenerRefOperation/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerrefoperation/RefOperationValidationExample.java
@@ -0,0 +1,45 @@
+// Copyright (C) 2015 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.googlesource.gerrit.plugins.examples.validationlistenerrefoperation;
+
+import com.google.common.collect.Lists;
+import com.google.gerrit.reviewdb.client.RefNames;
+import com.google.gerrit.server.events.RefReceivedEvent;
+import com.google.gerrit.server.git.validators.RefOperationValidationListener;
+import com.google.gerrit.server.git.validators.ValidationMessage;
+import com.google.gerrit.server.validators.ValidationException;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class RefOperationValidationExample implements
+ RefOperationValidationListener {
+
+ @Override
+ public List<ValidationMessage> onRefOperation(RefReceivedEvent event)
+ throws ValidationException {
+ ArrayList<ValidationMessage> messages = Lists.newArrayList();
+ if (event.command.getRefName()
+ .startsWith(RefNames.REFS_HEADS + "protected-")
+ && !event.user.getCapabilities().canAdministrateServer()) {
+ throw new ValidationException(String.format(
+ "Operation %s on %s branch in project %s is not valid!",
+ event.command.getType(),
+ event.command.getRefName(),
+ event.project.getName()));
+ }
+ return messages;
+ }
+}
diff --git a/example-validationListenerRefOperation/src/main/resources/Documentation/about.md b/example-validationListenerRefOperation/src/main/resources/Documentation/about.md
new file mode 100644
index 0000000..e5c078d
--- /dev/null
+++ b/example-validationListenerRefOperation/src/main/resources/Documentation/about.md
@@ -0,0 +1 @@
+Sample plugin to demonstrate the validationListenerRefOperation feature of Gerrit's plugin API.
diff --git a/example-assigneeValidator/tools/bazel.rc b/example-validationListenerRefOperation/tools/bazel.rc
similarity index 100%
copy from example-assigneeValidator/tools/bazel.rc
copy to example-validationListenerRefOperation/tools/bazel.rc
diff --git a/example-assigneeValidator/tools/bzl/BUILD b/example-validationListenerRefOperation/tools/bzl/BUILD
similarity index 100%
copy from example-assigneeValidator/tools/bzl/BUILD
copy to example-validationListenerRefOperation/tools/bzl/BUILD
diff --git a/example-assigneeValidator/tools/bzl/plugin.bzl b/example-validationListenerRefOperation/tools/bzl/plugin.bzl
similarity index 100%
copy from example-assigneeValidator/tools/bzl/plugin.bzl
copy to example-validationListenerRefOperation/tools/bzl/plugin.bzl
diff --git a/example-assigneeValidator/tools/workspace-status.sh b/example-validationListenerRefOperation/tools/workspace-status.sh
similarity index 84%
copy from example-assigneeValidator/tools/workspace-status.sh
copy to example-validationListenerRefOperation/tools/workspace-status.sh
index 0322307..a157618 100755
--- a/example-assigneeValidator/tools/workspace-status.sh
+++ b/example-validationListenerRefOperation/tools/workspace-status.sh
@@ -14,4 +14,4 @@
git describe --always --match "v[0-9].*" --dirty
}
-echo STABLE_BUILD_EXAMPLE-ASSIGNEEVALIDATOR_LABEL $(rev)
+echo STABLE_BUILD_EXAMPLE-VALIDATIONLISTENERREFOPERATION_LABEL $(rev)
diff --git a/example-assigneeValidator/.buckconfig b/example-validationListenerUpload/.buckconfig
similarity index 76%
copy from example-assigneeValidator/.buckconfig
copy to example-validationListenerUpload/.buckconfig
index 00c5e8e..277e01e 100644
--- a/example-assigneeValidator/.buckconfig
+++ b/example-validationListenerUpload/.buckconfig
@@ -1,5 +1,5 @@
[alias]
- plugin = //:example-assigneeValidator
+ plugin = //:example-validationListenerUpload
[java]
src_roots = java, resources
diff --git a/example-validationListenerUpload/.gitignore b/example-validationListenerUpload/.gitignore
new file mode 100644
index 0000000..db1c934
--- /dev/null
+++ b/example-validationListenerUpload/.gitignore
@@ -0,0 +1,8 @@
+/target
+/.classpath
+/.settings
+/.project
+/.buckd
+/buck-cache
+/buck-out
+*.iml
diff --git a/example-validationListenerUpload/BUCK b/example-validationListenerUpload/BUCK
new file mode 100644
index 0000000..07b9292
--- /dev/null
+++ b/example-validationListenerUpload/BUCK
@@ -0,0 +1,18 @@
+include_defs('//bucklets/gerrit_plugin.bucklet')
+
+gerrit_plugin(
+ name = 'example-validationListenerUpload',
+ srcs = glob(['src/main/java/**/*.java']),
+ resources = glob(['src/main/**/*']),
+ manifest_entries = [
+ 'Gerrit-PluginName: example-validationListenerUpload',
+ 'Gerrit-Module: com.googlesource.gerrit.plugins.examples.validationlistenerupload.Module',
+ 'Implementation-Title: Example Validation Listener Upload',
+ 'Implementation-URL: https://gerrit-review.googlesource.com/#/admin/projects/plugins/examples',
+ ],
+)
+
+java_library(
+ name = 'classpath',
+ deps = [':example-validationListenerUpload__plugin'],
+)
diff --git a/example-validationListenerUpload/BUILD b/example-validationListenerUpload/BUILD
new file mode 100644
index 0000000..472b79b
--- /dev/null
+++ b/example-validationListenerUpload/BUILD
@@ -0,0 +1,12 @@
+load("//tools/bzl:plugin.bzl", "gerrit_plugin")
+
+gerrit_plugin(
+ name = "example-validationListenerUpload",
+ srcs = glob(["src/main/java/**/*.java"]),
+ manifest_entries = [
+ "Gerrit-PluginName: example-validationListenerUpload",
+ "Gerrit-Module: com.googlesource.gerrit.plugins.examples.validationlistenerupload.Module",
+ "Implementation-Title: Example Validation Listener Upload",
+ ],
+ resources = glob(["src/main/resources/**/*"]),
+)
diff --git a/example-assigneeValidator/LICENSE b/example-validationListenerUpload/LICENSE
similarity index 100%
copy from example-assigneeValidator/LICENSE
copy to example-validationListenerUpload/LICENSE
diff --git a/example-assigneeValidator/WORKSPACE b/example-validationListenerUpload/WORKSPACE
similarity index 91%
rename from example-assigneeValidator/WORKSPACE
rename to example-validationListenerUpload/WORKSPACE
index 27f10b7..71770df 100644
--- a/example-assigneeValidator/WORKSPACE
+++ b/example-validationListenerUpload/WORKSPACE
@@ -1,4 +1,4 @@
-workspace(name = "assigneeValidator")
+workspace(name = "validationListenerUpload")
load("//:bazlets.bzl", "load_bazlets")
diff --git a/example-assigneeValidator/bazlets.bzl b/example-validationListenerUpload/bazlets.bzl
similarity index 100%
copy from example-assigneeValidator/bazlets.bzl
copy to example-validationListenerUpload/bazlets.bzl
diff --git a/example-assigneeValidator/lib/gerrit/BUCK b/example-validationListenerUpload/lib/gerrit/BUCK
similarity index 100%
copy from example-assigneeValidator/lib/gerrit/BUCK
copy to example-validationListenerUpload/lib/gerrit/BUCK
diff --git a/example-assigneeValidator/pom.xml b/example-validationListenerUpload/pom.xml
similarity index 89%
copy from example-assigneeValidator/pom.xml
copy to example-validationListenerUpload/pom.xml
index 8491811..289db64 100644
--- a/example-assigneeValidator/pom.xml
+++ b/example-validationListenerUpload/pom.xml
@@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlesource.gerrit.plugins</groupId>
- <artifactId>example-assigneeValidator</artifactId>
+ <artifactId>example-validationListenerUpload</artifactId>
<packaging>jar</packaging>
<version>2.14-SNAPSHOT</version>
<properties>
@@ -37,13 +37,13 @@
<configuration>
<archive>
<manifestEntries>
- <Gerrit-PluginName>example-assigneeValidator</Gerrit-PluginName>
- <Gerrit-Module>com.googlesource.gerrit.plugins.examples.assigneevalidator.Module</Gerrit-Module>
+ <Gerrit-PluginName>example-validationListenerUpload</Gerrit-PluginName>
+ <Gerrit-Module>com.googlesource.gerrit.plugins.examples.validationlistenerupload.Module</Gerrit-Module>
<Implementation-Vendor>Gerrit Code Review</Implementation-Vendor>
<Implementation-URL>https://gerrit-review.googlesource.com/#/admin/projects/plugins/examples</Implementation-URL>
- <Implementation-Title>Example Assignee Validator</Implementation-Title>
+ <Implementation-Title>Example Validation Listener Upload</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
<Gerrit-ApiType>${Gerrit-ApiType}</Gerrit-ApiType>
diff --git a/example-validationListenerUpload/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerupload/DenyUploadExample.java b/example-validationListenerUpload/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerupload/DenyUploadExample.java
new file mode 100644
index 0000000..7d85dce
--- /dev/null
+++ b/example-validationListenerUpload/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerupload/DenyUploadExample.java
@@ -0,0 +1,44 @@
+// Copyright (C) 2014 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.googlesource.gerrit.plugins.examples.validationlistenerupload;
+
+import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.server.CurrentUser;
+import com.google.gerrit.server.git.validators.UploadValidationListener;
+import com.google.gerrit.server.validators.ValidationException;
+import com.google.inject.Inject;
+
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.transport.UploadPack;
+
+import java.util.Collection;
+
+public class DenyUploadExample implements UploadValidationListener {
+ @Inject
+ private CurrentUser user;
+
+ @Override
+ public void onPreUpload(Repository repository, Project project,
+ String remoteHost, UploadPack up, Collection<? extends ObjectId> wants,
+ Collection<? extends ObjectId> haves) throws ValidationException {
+ up.sendMessage("Validating project name for " + user.getUserName() + "\n");
+ up.sendMessage(" from host: " + remoteHost + "\n");
+ if (project.getName().equals("deny-upload-project")) {
+ throw new ValidationException(
+ "This error message was sent from example-validationListenerUpload plugin DenyUploadExample.");
+ }
+ }
+}
diff --git a/example-assigneeValidator/src/main/java/com/googlesource/gerrit/plugins/examples/assigneevalidator/Module.java b/example-validationListenerUpload/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerupload/Module.java
similarity index 71%
copy from example-assigneeValidator/src/main/java/com/googlesource/gerrit/plugins/examples/assigneevalidator/Module.java
copy to example-validationListenerUpload/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerupload/Module.java
index ceb85d5..8bb84a3 100644
--- a/example-assigneeValidator/src/main/java/com/googlesource/gerrit/plugins/examples/assigneevalidator/Module.java
+++ b/example-validationListenerUpload/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerupload/Module.java
@@ -1,4 +1,4 @@
-// Copyright (C) 2017 The Android Open Source Project
+// Copyright (C) 2013 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.
@@ -12,16 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package com.googlesource.gerrit.plugins.examples.assigneevalidator;
+package com.googlesource.gerrit.plugins.examples.validationlistenerupload;
-import com.google.inject.AbstractModule;
import com.google.gerrit.extensions.registration.DynamicSet;
-import com.google.gerrit.server.validators.AssigneeValidationListener;
+import com.google.gerrit.server.git.validators.UploadValidationListener;
+import com.google.inject.AbstractModule;
public class Module extends AbstractModule {
@Override
protected void configure() {
- DynamicSet.bind(binder(),
- AssigneeValidationListener.class).to(AssigneeValidator.class);
+ DynamicSet.bind(binder(), UploadValidationListener.class)
+ .to(DenyUploadExample.class);
}
}
diff --git a/example-validationListenerUpload/src/main/resources/Documentation/about.md b/example-validationListenerUpload/src/main/resources/Documentation/about.md
new file mode 100644
index 0000000..61e7384
--- /dev/null
+++ b/example-validationListenerUpload/src/main/resources/Documentation/about.md
@@ -0,0 +1 @@
+Sample plugin to demonstrate the validationListenerUpload feature of Gerrit's plugin API.
diff --git a/example-assigneeValidator/tools/bazel.rc b/example-validationListenerUpload/tools/bazel.rc
similarity index 100%
copy from example-assigneeValidator/tools/bazel.rc
copy to example-validationListenerUpload/tools/bazel.rc
diff --git a/example-assigneeValidator/tools/bzl/BUILD b/example-validationListenerUpload/tools/bzl/BUILD
similarity index 100%
copy from example-assigneeValidator/tools/bzl/BUILD
copy to example-validationListenerUpload/tools/bzl/BUILD
diff --git a/example-assigneeValidator/tools/bzl/plugin.bzl b/example-validationListenerUpload/tools/bzl/plugin.bzl
similarity index 100%
copy from example-assigneeValidator/tools/bzl/plugin.bzl
copy to example-validationListenerUpload/tools/bzl/plugin.bzl
diff --git a/example-assigneeValidator/tools/workspace-status.sh b/example-validationListenerUpload/tools/workspace-status.sh
similarity index 85%
copy from example-assigneeValidator/tools/workspace-status.sh
copy to example-validationListenerUpload/tools/workspace-status.sh
index 0322307..9248805 100755
--- a/example-assigneeValidator/tools/workspace-status.sh
+++ b/example-validationListenerUpload/tools/workspace-status.sh
@@ -14,4 +14,4 @@
git describe --always --match "v[0-9].*" --dirty
}
-echo STABLE_BUILD_EXAMPLE-ASSIGNEEVALIDATOR_LABEL $(rev)
+echo STABLE_BUILD_EXAMPLE-VALIDATIONLISTENERUPLOAD_LABEL $(rev)