example-validationListener* Change-Id: I016396287b6fd62f83fdd1b1bb577d191b266516
diff --git a/BUILD b/BUILD index 8455063..6c6b149 100644 --- a/BUILD +++ b/BUILD
@@ -13,6 +13,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-validationListenerAssignee/.buckconfig b/example-validationListenerAssignee/.buckconfig new file mode 100644 index 0000000..a597fac --- /dev/null +++ b/example-validationListenerAssignee/.buckconfig
@@ -0,0 +1,15 @@ +[alias] + plugin = //:example-validationListenerAssignee + +[java] + src_roots = java, resources + source_level = 8 + target_level = 8 + +[project] + ignore = .git + +[cache] + mode = dir + dir = buck-out/cache +
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-validationListenerAssignee/LICENSE b/example-validationListenerAssignee/LICENSE new file mode 100644 index 0000000..11069ed --- /dev/null +++ b/example-validationListenerAssignee/LICENSE
@@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +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.
diff --git a/example-validationListenerAssignee/WORKSPACE b/example-validationListenerAssignee/WORKSPACE new file mode 100644 index 0000000..f8d65c3 --- /dev/null +++ b/example-validationListenerAssignee/WORKSPACE
@@ -0,0 +1,26 @@ +workspace(name = "validationListenerAssignee") + +load("//:bazlets.bzl", "load_bazlets") + +load_bazlets( + commit = "0f87babe07a555425d829c6e7951e296e9e24579", + # local_path = "/home/<user>/projects/bazlets", +) + +# Release Plugin API +load( + "@com_googlesource_gerrit_bazlets//:gerrit_api.bzl", + "gerrit_api", +) + +# Snapshot Plugin API +#load( +# "@com_googlesource_gerrit_bazlets//:gerrit_api_maven_local.bzl", +# "gerrit_api_maven_local", +#) + +# Load release Plugin API +gerrit_api() + +# Load snapshot Plugin API +#gerrit_api_maven_local()
diff --git a/example-validationListenerAssignee/bazlets.bzl b/example-validationListenerAssignee/bazlets.bzl new file mode 100644 index 0000000..e14e488 --- /dev/null +++ b/example-validationListenerAssignee/bazlets.bzl
@@ -0,0 +1,17 @@ +NAME = "com_googlesource_gerrit_bazlets" + +def load_bazlets( + commit, + local_path = None + ): + if not local_path: + native.git_repository( + name = NAME, + remote = "https://gerrit.googlesource.com/bazlets", + commit = commit, + ) + else: + native.local_repository( + name = NAME, + path = local_path, + )
diff --git a/example-validationListenerAssignee/lib/gerrit/BUCK b/example-validationListenerAssignee/lib/gerrit/BUCK new file mode 100644 index 0000000..8d5f0e9 --- /dev/null +++ b/example-validationListenerAssignee/lib/gerrit/BUCK
@@ -0,0 +1,20 @@ +include_defs('//bucklets/maven_jar.bucklet') + +VER = '2.14-SNAPSHOT' +REPO = MAVEN_LOCAL + +maven_jar( + name = 'acceptance-framework', + id = 'com.google.gerrit:gerrit-acceptance-framework:' + VER, + license = 'Apache2.0', + attach_source = False, + repository = REPO, +) + +maven_jar( + name = 'plugin-api', + id = 'com.google.gerrit:gerrit-plugin-api:' + VER, + license = 'Apache2.0', + attach_source = False, + repository = REPO, +)
diff --git a/example-validationListenerAssignee/pom.xml b/example-validationListenerAssignee/pom.xml new file mode 100644 index 0000000..ec718bb --- /dev/null +++ b/example-validationListenerAssignee/pom.xml
@@ -0,0 +1,85 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>com.googlesource.gerrit.plugins</groupId> + <artifactId>example-validationListenerAssignee</artifactId> + <packaging>jar</packaging> + <version>2.14-SNAPSHOT</version> + <properties> + <Gerrit-ApiType>plugin</Gerrit-ApiType> + <Gerrit-ApiVersion>${project.version}</Gerrit-ApiVersion> + </properties> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>2.4</version> + <configuration> + <archive> + <manifestEntries> + <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 Validation Listener Assignee</Implementation-Title> + <Implementation-Version>${project.version}</Implementation-Version> + + <Gerrit-ApiType>${Gerrit-ApiType}</Gerrit-ApiType> + <Gerrit-ApiVersion>${Gerrit-ApiVersion}</Gerrit-ApiVersion> + </manifestEntries> + </archive> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.3.2</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + <encoding>UTF-8</encoding> + </configuration> + </plugin> + </plugins> + + </build> + + <dependencies> + <dependency> + <groupId>com.google.gerrit</groupId> + <artifactId>gerrit-${Gerrit-ApiType}-api</artifactId> + <version>${Gerrit-ApiVersion}</version> + <scope>provided</scope> + </dependency> + </dependencies> + + <repositories> + <repository> + <id>maven.org</id> + <url>http://repo1.maven.org/maven2</url> + </repository> + </repositories> +</project>
diff --git a/example-validationListenerAssignee/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerassignee/AssigneeValidator.java b/example-validationListenerAssignee/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerassignee/AssigneeValidator.java new file mode 100644 index 0000000..63359ca --- /dev/null +++ b/example-validationListenerAssignee/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerassignee/AssigneeValidator.java
@@ -0,0 +1,57 @@ +// 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.validationlistenerassignee; + +import com.google.gerrit.reviewdb.client.Account; +import com.google.gerrit.reviewdb.client.Change; +import com.google.gerrit.server.query.QueryParseException; +import com.google.gerrit.server.query.change.ChangeQueryBuilder; +import com.google.gerrit.server.query.change.ChangeQueryProcessor; +import com.google.gerrit.server.validators.AssigneeValidationListener; +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 int MAX_ASSIGNED_CHANGES = 5; + + @Inject + ChangeQueryBuilder queryBuilder; + + @Inject + ChangeQueryProcessor queryProcessor; + + @Override + 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"); + } + } catch (OrmException | QueryParseException e) { + log.error("Failed to validate assignee for change " + change.getId(), e); + // Allow assignee. + } + } +}
diff --git a/example-validationListenerAssignee/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerassignee/Module.java b/example-validationListenerAssignee/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerassignee/Module.java new file mode 100644 index 0000000..05ff04d --- /dev/null +++ b/example-validationListenerAssignee/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerassignee/Module.java
@@ -0,0 +1,27 @@ +// 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. +// 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.validationlistenerassignee; + +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); + } +}
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-validationListenerAssignee/tools/bazel.rc b/example-validationListenerAssignee/tools/bazel.rc new file mode 100644 index 0000000..4ed16cf --- /dev/null +++ b/example-validationListenerAssignee/tools/bazel.rc
@@ -0,0 +1,2 @@ +build --workspace_status_command=./tools/workspace-status.sh +test --build_tests_only
diff --git a/example-validationListenerAssignee/tools/bzl/BUILD b/example-validationListenerAssignee/tools/bzl/BUILD new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/example-validationListenerAssignee/tools/bzl/BUILD
diff --git a/example-validationListenerAssignee/tools/bzl/plugin.bzl b/example-validationListenerAssignee/tools/bzl/plugin.bzl new file mode 100644 index 0000000..2b1df8c --- /dev/null +++ b/example-validationListenerAssignee/tools/bzl/plugin.bzl
@@ -0,0 +1,4 @@ +load( + "@com_googlesource_gerrit_bazlets//:gerrit_plugin.bzl", + "gerrit_plugin", +)
diff --git a/example-validationListenerAssignee/tools/workspace-status.sh b/example-validationListenerAssignee/tools/workspace-status.sh new file mode 100755 index 0000000..95c851e --- /dev/null +++ b/example-validationListenerAssignee/tools/workspace-status.sh
@@ -0,0 +1,17 @@ +#!/bin/bash + +# This script will be run by bazel when the build process starts to +# generate key-value information that represents the status of the +# workspace. The output should be like +# +# KEY1 VALUE1 +# KEY2 VALUE2 +# +# If the script exits with non-zero code, it's considered as a failure +# and the output will be discarded. + +function rev() { + git describe --always --match "v[0-9].*" --dirty +} + +echo STABLE_BUILD_EXAMPLE-VALIDATIONLISTENERASSIGNEE_LABEL $(rev)
diff --git a/example-validationListenerCommit/.buckconfig b/example-validationListenerCommit/.buckconfig new file mode 100644 index 0000000..c3ce4c8 --- /dev/null +++ b/example-validationListenerCommit/.buckconfig
@@ -0,0 +1,15 @@ +[alias] + plugin = //:example-validationListenerCommit + +[java] + src_roots = java, resources + source_level = 8 + target_level = 8 + +[project] + ignore = .git + +[cache] + mode = dir + dir = buck-out/cache +
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-validationListenerCommit/LICENSE b/example-validationListenerCommit/LICENSE new file mode 100644 index 0000000..11069ed --- /dev/null +++ b/example-validationListenerCommit/LICENSE
@@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +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.
diff --git a/example-validationListenerCommit/WORKSPACE b/example-validationListenerCommit/WORKSPACE new file mode 100644 index 0000000..819a4ac --- /dev/null +++ b/example-validationListenerCommit/WORKSPACE
@@ -0,0 +1,26 @@ +workspace(name = "validationListenerCommit") + +load("//:bazlets.bzl", "load_bazlets") + +load_bazlets( + commit = "0f87babe07a555425d829c6e7951e296e9e24579", + # local_path = "/home/<user>/projects/bazlets", +) + +# Release Plugin API +load( + "@com_googlesource_gerrit_bazlets//:gerrit_api.bzl", + "gerrit_api", +) + +# Snapshot Plugin API +#load( +# "@com_googlesource_gerrit_bazlets//:gerrit_api_maven_local.bzl", +# "gerrit_api_maven_local", +#) + +# Load release Plugin API +gerrit_api() + +# Load snapshot Plugin API +#gerrit_api_maven_local()
diff --git a/example-validationListenerCommit/bazlets.bzl b/example-validationListenerCommit/bazlets.bzl new file mode 100644 index 0000000..e14e488 --- /dev/null +++ b/example-validationListenerCommit/bazlets.bzl
@@ -0,0 +1,17 @@ +NAME = "com_googlesource_gerrit_bazlets" + +def load_bazlets( + commit, + local_path = None + ): + if not local_path: + native.git_repository( + name = NAME, + remote = "https://gerrit.googlesource.com/bazlets", + commit = commit, + ) + else: + native.local_repository( + name = NAME, + path = local_path, + )
diff --git a/example-validationListenerCommit/lib/gerrit/BUCK b/example-validationListenerCommit/lib/gerrit/BUCK new file mode 100644 index 0000000..8d5f0e9 --- /dev/null +++ b/example-validationListenerCommit/lib/gerrit/BUCK
@@ -0,0 +1,20 @@ +include_defs('//bucklets/maven_jar.bucklet') + +VER = '2.14-SNAPSHOT' +REPO = MAVEN_LOCAL + +maven_jar( + name = 'acceptance-framework', + id = 'com.google.gerrit:gerrit-acceptance-framework:' + VER, + license = 'Apache2.0', + attach_source = False, + repository = REPO, +) + +maven_jar( + name = 'plugin-api', + id = 'com.google.gerrit:gerrit-plugin-api:' + VER, + license = 'Apache2.0', + attach_source = False, + repository = REPO, +)
diff --git a/example-validationListenerCommit/pom.xml b/example-validationListenerCommit/pom.xml new file mode 100644 index 0000000..1d0785e --- /dev/null +++ b/example-validationListenerCommit/pom.xml
@@ -0,0 +1,85 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>com.googlesource.gerrit.plugins</groupId> + <artifactId>example-validationListenerCommit</artifactId> + <packaging>jar</packaging> + <version>2.14-SNAPSHOT</version> + <properties> + <Gerrit-ApiType>plugin</Gerrit-ApiType> + <Gerrit-ApiVersion>${project.version}</Gerrit-ApiVersion> + </properties> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>2.4</version> + <configuration> + <archive> + <manifestEntries> + <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 Validation Listener Commit</Implementation-Title> + <Implementation-Version>${project.version}</Implementation-Version> + + <Gerrit-ApiType>${Gerrit-ApiType}</Gerrit-ApiType> + <Gerrit-ApiVersion>${Gerrit-ApiVersion}</Gerrit-ApiVersion> + </manifestEntries> + </archive> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.3.2</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + <encoding>UTF-8</encoding> + </configuration> + </plugin> + </plugins> + + </build> + + <dependencies> + <dependency> + <groupId>com.google.gerrit</groupId> + <artifactId>gerrit-${Gerrit-ApiType}-api</artifactId> + <version>${Gerrit-ApiVersion}</version> + <scope>provided</scope> + </dependency> + </dependencies> + + <repositories> + <repository> + <id>maven.org</id> + <url>http://repo1.maven.org/maven2</url> + </repository> + </repositories> +</project>
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-validationListenerCommit/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenercommit/Module.java b/example-validationListenerCommit/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenercommit/Module.java new file mode 100644 index 0000000..db39957 --- /dev/null +++ b/example-validationListenerCommit/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenercommit/Module.java
@@ -0,0 +1,27 @@ +// 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. +// 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.gerrit.extensions.registration.DynamicSet; +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(), 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-validationListenerCommit/tools/bazel.rc b/example-validationListenerCommit/tools/bazel.rc new file mode 100644 index 0000000..4ed16cf --- /dev/null +++ b/example-validationListenerCommit/tools/bazel.rc
@@ -0,0 +1,2 @@ +build --workspace_status_command=./tools/workspace-status.sh +test --build_tests_only
diff --git a/example-validationListenerCommit/tools/bzl/BUILD b/example-validationListenerCommit/tools/bzl/BUILD new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/example-validationListenerCommit/tools/bzl/BUILD
diff --git a/example-validationListenerCommit/tools/bzl/plugin.bzl b/example-validationListenerCommit/tools/bzl/plugin.bzl new file mode 100644 index 0000000..2b1df8c --- /dev/null +++ b/example-validationListenerCommit/tools/bzl/plugin.bzl
@@ -0,0 +1,4 @@ +load( + "@com_googlesource_gerrit_bazlets//:gerrit_plugin.bzl", + "gerrit_plugin", +)
diff --git a/example-validationListenerCommit/tools/workspace-status.sh b/example-validationListenerCommit/tools/workspace-status.sh new file mode 100755 index 0000000..5488fc6 --- /dev/null +++ b/example-validationListenerCommit/tools/workspace-status.sh
@@ -0,0 +1,17 @@ +#!/bin/bash + +# This script will be run by bazel when the build process starts to +# generate key-value information that represents the status of the +# workspace. The output should be like +# +# KEY1 VALUE1 +# KEY2 VALUE2 +# +# If the script exits with non-zero code, it's considered as a failure +# and the output will be discarded. + +function rev() { + git describe --always --match "v[0-9].*" --dirty +} + +echo STABLE_BUILD_EXAMPLE-VALIDATIONLISTENERCOMMIT_LABEL $(rev)
diff --git a/example-validationListenerHashtag/.buckconfig b/example-validationListenerHashtag/.buckconfig new file mode 100644 index 0000000..4ef2069 --- /dev/null +++ b/example-validationListenerHashtag/.buckconfig
@@ -0,0 +1,15 @@ +[alias] + plugin = //:example-validationListenerHashtag + +[java] + src_roots = java, resources + source_level = 8 + target_level = 8 + +[project] + ignore = .git + +[cache] + mode = dir + dir = buck-out/cache +
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-validationListenerHashtag/LICENSE b/example-validationListenerHashtag/LICENSE new file mode 100644 index 0000000..11069ed --- /dev/null +++ b/example-validationListenerHashtag/LICENSE
@@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +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.
diff --git a/example-validationListenerHashtag/WORKSPACE b/example-validationListenerHashtag/WORKSPACE new file mode 100644 index 0000000..8a5d367 --- /dev/null +++ b/example-validationListenerHashtag/WORKSPACE
@@ -0,0 +1,26 @@ +workspace(name = "validationListenerHashtag") + +load("//:bazlets.bzl", "load_bazlets") + +load_bazlets( + commit = "0f87babe07a555425d829c6e7951e296e9e24579", + # local_path = "/home/<user>/projects/bazlets", +) + +# Release Plugin API +load( + "@com_googlesource_gerrit_bazlets//:gerrit_api.bzl", + "gerrit_api", +) + +# Snapshot Plugin API +#load( +# "@com_googlesource_gerrit_bazlets//:gerrit_api_maven_local.bzl", +# "gerrit_api_maven_local", +#) + +# Load release Plugin API +gerrit_api() + +# Load snapshot Plugin API +#gerrit_api_maven_local()
diff --git a/example-validationListenerHashtag/bazlets.bzl b/example-validationListenerHashtag/bazlets.bzl new file mode 100644 index 0000000..e14e488 --- /dev/null +++ b/example-validationListenerHashtag/bazlets.bzl
@@ -0,0 +1,17 @@ +NAME = "com_googlesource_gerrit_bazlets" + +def load_bazlets( + commit, + local_path = None + ): + if not local_path: + native.git_repository( + name = NAME, + remote = "https://gerrit.googlesource.com/bazlets", + commit = commit, + ) + else: + native.local_repository( + name = NAME, + path = local_path, + )
diff --git a/example-validationListenerHashtag/lib/gerrit/BUCK b/example-validationListenerHashtag/lib/gerrit/BUCK new file mode 100644 index 0000000..8d5f0e9 --- /dev/null +++ b/example-validationListenerHashtag/lib/gerrit/BUCK
@@ -0,0 +1,20 @@ +include_defs('//bucklets/maven_jar.bucklet') + +VER = '2.14-SNAPSHOT' +REPO = MAVEN_LOCAL + +maven_jar( + name = 'acceptance-framework', + id = 'com.google.gerrit:gerrit-acceptance-framework:' + VER, + license = 'Apache2.0', + attach_source = False, + repository = REPO, +) + +maven_jar( + name = 'plugin-api', + id = 'com.google.gerrit:gerrit-plugin-api:' + VER, + license = 'Apache2.0', + attach_source = False, + repository = REPO, +)
diff --git a/example-validationListenerHashtag/pom.xml b/example-validationListenerHashtag/pom.xml new file mode 100644 index 0000000..7965f8d --- /dev/null +++ b/example-validationListenerHashtag/pom.xml
@@ -0,0 +1,85 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>com.googlesource.gerrit.plugins</groupId> + <artifactId>example-validationListenerHashtag</artifactId> + <packaging>jar</packaging> + <version>2.14-SNAPSHOT</version> + <properties> + <Gerrit-ApiType>plugin</Gerrit-ApiType> + <Gerrit-ApiVersion>${project.version}</Gerrit-ApiVersion> + </properties> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>2.4</version> + <configuration> + <archive> + <manifestEntries> + <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 Validation Listener Hashtag</Implementation-Title> + <Implementation-Version>${project.version}</Implementation-Version> + + <Gerrit-ApiType>${Gerrit-ApiType}</Gerrit-ApiType> + <Gerrit-ApiVersion>${Gerrit-ApiVersion}</Gerrit-ApiVersion> + </manifestEntries> + </archive> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.3.2</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + <encoding>UTF-8</encoding> + </configuration> + </plugin> + </plugins> + + </build> + + <dependencies> + <dependency> + <groupId>com.google.gerrit</groupId> + <artifactId>gerrit-${Gerrit-ApiType}-api</artifactId> + <version>${Gerrit-ApiVersion}</version> + <scope>provided</scope> + </dependency> + </dependencies> + + <repositories> + <repository> + <id>maven.org</id> + <url>http://repo1.maven.org/maven2</url> + </repository> + </repositories> +</project>
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-validationListenerHashtag/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerhashtag/Module.java b/example-validationListenerHashtag/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerhashtag/Module.java new file mode 100644 index 0000000..43c4426 --- /dev/null +++ b/example-validationListenerHashtag/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerhashtag/Module.java
@@ -0,0 +1,27 @@ +// 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. +// 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.extensions.registration.DynamicSet; +import com.google.gerrit.server.validators.HashtagValidationListener; +import com.google.inject.AbstractModule; + +public class Module extends AbstractModule { + @Override + protected void configure() { + 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-validationListenerHashtag/tools/bazel.rc b/example-validationListenerHashtag/tools/bazel.rc new file mode 100644 index 0000000..4ed16cf --- /dev/null +++ b/example-validationListenerHashtag/tools/bazel.rc
@@ -0,0 +1,2 @@ +build --workspace_status_command=./tools/workspace-status.sh +test --build_tests_only
diff --git a/example-validationListenerHashtag/tools/bzl/BUILD b/example-validationListenerHashtag/tools/bzl/BUILD new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/example-validationListenerHashtag/tools/bzl/BUILD
diff --git a/example-validationListenerHashtag/tools/bzl/plugin.bzl b/example-validationListenerHashtag/tools/bzl/plugin.bzl new file mode 100644 index 0000000..2b1df8c --- /dev/null +++ b/example-validationListenerHashtag/tools/bzl/plugin.bzl
@@ -0,0 +1,4 @@ +load( + "@com_googlesource_gerrit_bazlets//:gerrit_plugin.bzl", + "gerrit_plugin", +)
diff --git a/example-validationListenerHashtag/tools/workspace-status.sh b/example-validationListenerHashtag/tools/workspace-status.sh new file mode 100755 index 0000000..0f2d3fe --- /dev/null +++ b/example-validationListenerHashtag/tools/workspace-status.sh
@@ -0,0 +1,17 @@ +#!/bin/bash + +# This script will be run by bazel when the build process starts to +# generate key-value information that represents the status of the +# workspace. The output should be like +# +# KEY1 VALUE1 +# KEY2 VALUE2 +# +# If the script exits with non-zero code, it's considered as a failure +# and the output will be discarded. + +function rev() { + git describe --always --match "v[0-9].*" --dirty +} + +echo STABLE_BUILD_EXAMPLE-VALIDATIONLISTENERHASHTAG_LABEL $(rev)
diff --git a/example-validationListenerMerge/.buckconfig b/example-validationListenerMerge/.buckconfig new file mode 100644 index 0000000..22eee3f --- /dev/null +++ b/example-validationListenerMerge/.buckconfig
@@ -0,0 +1,15 @@ +[alias] + plugin = //:example-validationListenerMerge + +[java] + src_roots = java, resources + source_level = 8 + target_level = 8 + +[project] + ignore = .git + +[cache] + mode = dir + dir = buck-out/cache +
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-validationListenerMerge/LICENSE b/example-validationListenerMerge/LICENSE new file mode 100644 index 0000000..11069ed --- /dev/null +++ b/example-validationListenerMerge/LICENSE
@@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +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.
diff --git a/example-validationListenerMerge/WORKSPACE b/example-validationListenerMerge/WORKSPACE new file mode 100644 index 0000000..27f6664 --- /dev/null +++ b/example-validationListenerMerge/WORKSPACE
@@ -0,0 +1,26 @@ +workspace(name = "validationListenerMerge") + +load("//:bazlets.bzl", "load_bazlets") + +load_bazlets( + commit = "0f87babe07a555425d829c6e7951e296e9e24579", + # local_path = "/home/<user>/projects/bazlets", +) + +# Release Plugin API +load( + "@com_googlesource_gerrit_bazlets//:gerrit_api.bzl", + "gerrit_api", +) + +# Snapshot Plugin API +#load( +# "@com_googlesource_gerrit_bazlets//:gerrit_api_maven_local.bzl", +# "gerrit_api_maven_local", +#) + +# Load release Plugin API +gerrit_api() + +# Load snapshot Plugin API +#gerrit_api_maven_local()
diff --git a/example-validationListenerMerge/bazlets.bzl b/example-validationListenerMerge/bazlets.bzl new file mode 100644 index 0000000..e14e488 --- /dev/null +++ b/example-validationListenerMerge/bazlets.bzl
@@ -0,0 +1,17 @@ +NAME = "com_googlesource_gerrit_bazlets" + +def load_bazlets( + commit, + local_path = None + ): + if not local_path: + native.git_repository( + name = NAME, + remote = "https://gerrit.googlesource.com/bazlets", + commit = commit, + ) + else: + native.local_repository( + name = NAME, + path = local_path, + )
diff --git a/example-validationListenerMerge/lib/gerrit/BUCK b/example-validationListenerMerge/lib/gerrit/BUCK new file mode 100644 index 0000000..8d5f0e9 --- /dev/null +++ b/example-validationListenerMerge/lib/gerrit/BUCK
@@ -0,0 +1,20 @@ +include_defs('//bucklets/maven_jar.bucklet') + +VER = '2.14-SNAPSHOT' +REPO = MAVEN_LOCAL + +maven_jar( + name = 'acceptance-framework', + id = 'com.google.gerrit:gerrit-acceptance-framework:' + VER, + license = 'Apache2.0', + attach_source = False, + repository = REPO, +) + +maven_jar( + name = 'plugin-api', + id = 'com.google.gerrit:gerrit-plugin-api:' + VER, + license = 'Apache2.0', + attach_source = False, + repository = REPO, +)
diff --git a/example-validationListenerMerge/pom.xml b/example-validationListenerMerge/pom.xml new file mode 100644 index 0000000..fce9a56 --- /dev/null +++ b/example-validationListenerMerge/pom.xml
@@ -0,0 +1,85 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>com.googlesource.gerrit.plugins</groupId> + <artifactId>example-validationListenerMerge</artifactId> + <packaging>jar</packaging> + <version>2.14-SNAPSHOT</version> + <properties> + <Gerrit-ApiType>plugin</Gerrit-ApiType> + <Gerrit-ApiVersion>${project.version}</Gerrit-ApiVersion> + </properties> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>2.4</version> + <configuration> + <archive> + <manifestEntries> + <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 Validation Listener Merge</Implementation-Title> + <Implementation-Version>${project.version}</Implementation-Version> + + <Gerrit-ApiType>${Gerrit-ApiType}</Gerrit-ApiType> + <Gerrit-ApiVersion>${Gerrit-ApiVersion}</Gerrit-ApiVersion> + </manifestEntries> + </archive> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.3.2</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + <encoding>UTF-8</encoding> + </configuration> + </plugin> + </plugins> + + </build> + + <dependencies> + <dependency> + <groupId>com.google.gerrit</groupId> + <artifactId>gerrit-${Gerrit-ApiType}-api</artifactId> + <version>${Gerrit-ApiVersion}</version> + <scope>provided</scope> + </dependency> + </dependencies> + + <repositories> + <repository> + <id>maven.org</id> + <url>http://repo1.maven.org/maven2</url> + </repository> + </repositories> +</project>
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-validationListenerMerge/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenermerge/Module.java b/example-validationListenerMerge/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenermerge/Module.java new file mode 100644 index 0000000..dde757c --- /dev/null +++ b/example-validationListenerMerge/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenermerge/Module.java
@@ -0,0 +1,27 @@ +// 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. +// 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.extensions.registration.DynamicSet; +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(), 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-validationListenerMerge/tools/bazel.rc b/example-validationListenerMerge/tools/bazel.rc new file mode 100644 index 0000000..4ed16cf --- /dev/null +++ b/example-validationListenerMerge/tools/bazel.rc
@@ -0,0 +1,2 @@ +build --workspace_status_command=./tools/workspace-status.sh +test --build_tests_only
diff --git a/example-validationListenerMerge/tools/bzl/BUILD b/example-validationListenerMerge/tools/bzl/BUILD new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/example-validationListenerMerge/tools/bzl/BUILD
diff --git a/example-validationListenerMerge/tools/bzl/plugin.bzl b/example-validationListenerMerge/tools/bzl/plugin.bzl new file mode 100644 index 0000000..2b1df8c --- /dev/null +++ b/example-validationListenerMerge/tools/bzl/plugin.bzl
@@ -0,0 +1,4 @@ +load( + "@com_googlesource_gerrit_bazlets//:gerrit_plugin.bzl", + "gerrit_plugin", +)
diff --git a/example-validationListenerMerge/tools/workspace-status.sh b/example-validationListenerMerge/tools/workspace-status.sh new file mode 100755 index 0000000..6928ad0 --- /dev/null +++ b/example-validationListenerMerge/tools/workspace-status.sh
@@ -0,0 +1,17 @@ +#!/bin/bash + +# This script will be run by bazel when the build process starts to +# generate key-value information that represents the status of the +# workspace. The output should be like +# +# KEY1 VALUE1 +# KEY2 VALUE2 +# +# If the script exits with non-zero code, it's considered as a failure +# and the output will be discarded. + +function rev() { + git describe --always --match "v[0-9].*" --dirty +} + +echo STABLE_BUILD_EXAMPLE-VALIDATIONLISTENERMERGE_LABEL $(rev)
diff --git a/example-validationListenerNewProjectCreated/.buckconfig b/example-validationListenerNewProjectCreated/.buckconfig new file mode 100644 index 0000000..0df5541 --- /dev/null +++ b/example-validationListenerNewProjectCreated/.buckconfig
@@ -0,0 +1,15 @@ +[alias] + plugin = //:example-validationListenerNewProjectCreated + +[java] + src_roots = java, resources + source_level = 8 + target_level = 8 + +[project] + ignore = .git + +[cache] + mode = dir + dir = buck-out/cache +
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-validationListenerNewProjectCreated/LICENSE b/example-validationListenerNewProjectCreated/LICENSE new file mode 100644 index 0000000..11069ed --- /dev/null +++ b/example-validationListenerNewProjectCreated/LICENSE
@@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +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.
diff --git a/example-validationListenerNewProjectCreated/WORKSPACE b/example-validationListenerNewProjectCreated/WORKSPACE new file mode 100644 index 0000000..16abbe5 --- /dev/null +++ b/example-validationListenerNewProjectCreated/WORKSPACE
@@ -0,0 +1,26 @@ +workspace(name = "validationListenerNewProjectCreated") + +load("//:bazlets.bzl", "load_bazlets") + +load_bazlets( + commit = "0f87babe07a555425d829c6e7951e296e9e24579", + # local_path = "/home/<user>/projects/bazlets", +) + +# Release Plugin API +load( + "@com_googlesource_gerrit_bazlets//:gerrit_api.bzl", + "gerrit_api", +) + +# Snapshot Plugin API +#load( +# "@com_googlesource_gerrit_bazlets//:gerrit_api_maven_local.bzl", +# "gerrit_api_maven_local", +#) + +# Load release Plugin API +gerrit_api() + +# Load snapshot Plugin API +#gerrit_api_maven_local()
diff --git a/example-validationListenerNewProjectCreated/bazlets.bzl b/example-validationListenerNewProjectCreated/bazlets.bzl new file mode 100644 index 0000000..e14e488 --- /dev/null +++ b/example-validationListenerNewProjectCreated/bazlets.bzl
@@ -0,0 +1,17 @@ +NAME = "com_googlesource_gerrit_bazlets" + +def load_bazlets( + commit, + local_path = None + ): + if not local_path: + native.git_repository( + name = NAME, + remote = "https://gerrit.googlesource.com/bazlets", + commit = commit, + ) + else: + native.local_repository( + name = NAME, + path = local_path, + )
diff --git a/example-validationListenerNewProjectCreated/lib/gerrit/BUCK b/example-validationListenerNewProjectCreated/lib/gerrit/BUCK new file mode 100644 index 0000000..8d5f0e9 --- /dev/null +++ b/example-validationListenerNewProjectCreated/lib/gerrit/BUCK
@@ -0,0 +1,20 @@ +include_defs('//bucklets/maven_jar.bucklet') + +VER = '2.14-SNAPSHOT' +REPO = MAVEN_LOCAL + +maven_jar( + name = 'acceptance-framework', + id = 'com.google.gerrit:gerrit-acceptance-framework:' + VER, + license = 'Apache2.0', + attach_source = False, + repository = REPO, +) + +maven_jar( + name = 'plugin-api', + id = 'com.google.gerrit:gerrit-plugin-api:' + VER, + license = 'Apache2.0', + attach_source = False, + repository = REPO, +)
diff --git a/example-validationListenerNewProjectCreated/pom.xml b/example-validationListenerNewProjectCreated/pom.xml new file mode 100644 index 0000000..f858854 --- /dev/null +++ b/example-validationListenerNewProjectCreated/pom.xml
@@ -0,0 +1,85 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>com.googlesource.gerrit.plugins</groupId> + <artifactId>example-validationListenerNewProjectCreated</artifactId> + <packaging>jar</packaging> + <version>2.14-SNAPSHOT</version> + <properties> + <Gerrit-ApiType>plugin</Gerrit-ApiType> + <Gerrit-ApiVersion>${project.version}</Gerrit-ApiVersion> + </properties> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>2.4</version> + <configuration> + <archive> + <manifestEntries> + <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 Validation Listener NewProjectCreated</Implementation-Title> + <Implementation-Version>${project.version}</Implementation-Version> + + <Gerrit-ApiType>${Gerrit-ApiType}</Gerrit-ApiType> + <Gerrit-ApiVersion>${Gerrit-ApiVersion}</Gerrit-ApiVersion> + </manifestEntries> + </archive> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.3.2</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + <encoding>UTF-8</encoding> + </configuration> + </plugin> + </plugins> + + </build> + + <dependencies> + <dependency> + <groupId>com.google.gerrit</groupId> + <artifactId>gerrit-${Gerrit-ApiType}-api</artifactId> + <version>${Gerrit-ApiVersion}</version> + <scope>provided</scope> + </dependency> + </dependencies> + + <repositories> + <repository> + <id>maven.org</id> + <url>http://repo1.maven.org/maven2</url> + </repository> + </repositories> +</project>
diff --git a/example-validationListenerNewProjectCreated/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenernewprojectcreated/Module.java b/example-validationListenerNewProjectCreated/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenernewprojectcreated/Module.java new file mode 100644 index 0000000..650febf --- /dev/null +++ b/example-validationListenerNewProjectCreated/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenernewprojectcreated/Module.java
@@ -0,0 +1,27 @@ +// 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. +// 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.events.NewProjectCreatedListener; +import com.google.gerrit.extensions.registration.DynamicSet; +import com.google.inject.AbstractModule; + +public class Module extends AbstractModule { + @Override + protected void configure() { + 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-validationListenerNewProjectCreated/tools/bazel.rc b/example-validationListenerNewProjectCreated/tools/bazel.rc new file mode 100644 index 0000000..4ed16cf --- /dev/null +++ b/example-validationListenerNewProjectCreated/tools/bazel.rc
@@ -0,0 +1,2 @@ +build --workspace_status_command=./tools/workspace-status.sh +test --build_tests_only
diff --git a/example-validationListenerNewProjectCreated/tools/bzl/BUILD b/example-validationListenerNewProjectCreated/tools/bzl/BUILD new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/example-validationListenerNewProjectCreated/tools/bzl/BUILD
diff --git a/example-validationListenerNewProjectCreated/tools/bzl/plugin.bzl b/example-validationListenerNewProjectCreated/tools/bzl/plugin.bzl new file mode 100644 index 0000000..2b1df8c --- /dev/null +++ b/example-validationListenerNewProjectCreated/tools/bzl/plugin.bzl
@@ -0,0 +1,4 @@ +load( + "@com_googlesource_gerrit_bazlets//:gerrit_plugin.bzl", + "gerrit_plugin", +)
diff --git a/example-validationListenerNewProjectCreated/tools/workspace-status.sh b/example-validationListenerNewProjectCreated/tools/workspace-status.sh new file mode 100755 index 0000000..6ab0b46 --- /dev/null +++ b/example-validationListenerNewProjectCreated/tools/workspace-status.sh
@@ -0,0 +1,17 @@ +#!/bin/bash + +# This script will be run by bazel when the build process starts to +# generate key-value information that represents the status of the +# workspace. The output should be like +# +# KEY1 VALUE1 +# KEY2 VALUE2 +# +# If the script exits with non-zero code, it's considered as a failure +# and the output will be discarded. + +function rev() { + git describe --always --match "v[0-9].*" --dirty +} + +echo STABLE_BUILD_EXAMPLE-VALIDATIONLISTENERNEWPROJECTCREATED_LABEL $(rev)
diff --git a/example-validationListenerRefOperation/.buckconfig b/example-validationListenerRefOperation/.buckconfig new file mode 100644 index 0000000..81a8e40 --- /dev/null +++ b/example-validationListenerRefOperation/.buckconfig
@@ -0,0 +1,15 @@ +[alias] + plugin = //:example-validationListenerRefOperation + +[java] + src_roots = java, resources + source_level = 8 + target_level = 8 + +[project] + ignore = .git + +[cache] + mode = dir + dir = buck-out/cache +
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-validationListenerRefOperation/LICENSE b/example-validationListenerRefOperation/LICENSE new file mode 100644 index 0000000..11069ed --- /dev/null +++ b/example-validationListenerRefOperation/LICENSE
@@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +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.
diff --git a/example-validationListenerRefOperation/WORKSPACE b/example-validationListenerRefOperation/WORKSPACE new file mode 100644 index 0000000..fbf02d6 --- /dev/null +++ b/example-validationListenerRefOperation/WORKSPACE
@@ -0,0 +1,26 @@ +workspace(name = "validationListenerRefOperation") + +load("//:bazlets.bzl", "load_bazlets") + +load_bazlets( + commit = "0f87babe07a555425d829c6e7951e296e9e24579", + # local_path = "/home/<user>/projects/bazlets", +) + +# Release Plugin API +load( + "@com_googlesource_gerrit_bazlets//:gerrit_api.bzl", + "gerrit_api", +) + +# Snapshot Plugin API +#load( +# "@com_googlesource_gerrit_bazlets//:gerrit_api_maven_local.bzl", +# "gerrit_api_maven_local", +#) + +# Load release Plugin API +gerrit_api() + +# Load snapshot Plugin API +#gerrit_api_maven_local()
diff --git a/example-validationListenerRefOperation/bazlets.bzl b/example-validationListenerRefOperation/bazlets.bzl new file mode 100644 index 0000000..e14e488 --- /dev/null +++ b/example-validationListenerRefOperation/bazlets.bzl
@@ -0,0 +1,17 @@ +NAME = "com_googlesource_gerrit_bazlets" + +def load_bazlets( + commit, + local_path = None + ): + if not local_path: + native.git_repository( + name = NAME, + remote = "https://gerrit.googlesource.com/bazlets", + commit = commit, + ) + else: + native.local_repository( + name = NAME, + path = local_path, + )
diff --git a/example-validationListenerRefOperation/lib/gerrit/BUCK b/example-validationListenerRefOperation/lib/gerrit/BUCK new file mode 100644 index 0000000..8d5f0e9 --- /dev/null +++ b/example-validationListenerRefOperation/lib/gerrit/BUCK
@@ -0,0 +1,20 @@ +include_defs('//bucklets/maven_jar.bucklet') + +VER = '2.14-SNAPSHOT' +REPO = MAVEN_LOCAL + +maven_jar( + name = 'acceptance-framework', + id = 'com.google.gerrit:gerrit-acceptance-framework:' + VER, + license = 'Apache2.0', + attach_source = False, + repository = REPO, +) + +maven_jar( + name = 'plugin-api', + id = 'com.google.gerrit:gerrit-plugin-api:' + VER, + license = 'Apache2.0', + attach_source = False, + repository = REPO, +)
diff --git a/example-validationListenerRefOperation/pom.xml b/example-validationListenerRefOperation/pom.xml new file mode 100644 index 0000000..9e92835 --- /dev/null +++ b/example-validationListenerRefOperation/pom.xml
@@ -0,0 +1,85 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>com.googlesource.gerrit.plugins</groupId> + <artifactId>example-validationListenerRefOperation</artifactId> + <packaging>jar</packaging> + <version>2.14-SNAPSHOT</version> + <properties> + <Gerrit-ApiType>plugin</Gerrit-ApiType> + <Gerrit-ApiVersion>${project.version}</Gerrit-ApiVersion> + </properties> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>2.4</version> + <configuration> + <archive> + <manifestEntries> + <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 Validation Listener RefOperation</Implementation-Title> + <Implementation-Version>${project.version}</Implementation-Version> + + <Gerrit-ApiType>${Gerrit-ApiType}</Gerrit-ApiType> + <Gerrit-ApiVersion>${Gerrit-ApiVersion}</Gerrit-ApiVersion> + </manifestEntries> + </archive> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.3.2</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + <encoding>UTF-8</encoding> + </configuration> + </plugin> + </plugins> + + </build> + + <dependencies> + <dependency> + <groupId>com.google.gerrit</groupId> + <artifactId>gerrit-${Gerrit-ApiType}-api</artifactId> + <version>${Gerrit-ApiVersion}</version> + <scope>provided</scope> + </dependency> + </dependencies> + + <repositories> + <repository> + <id>maven.org</id> + <url>http://repo1.maven.org/maven2</url> + </repository> + </repositories> +</project>
diff --git a/example-validationListenerRefOperation/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerrefoperation/Module.java b/example-validationListenerRefOperation/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerrefoperation/Module.java new file mode 100644 index 0000000..b80fcff --- /dev/null +++ b/example-validationListenerRefOperation/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerrefoperation/Module.java
@@ -0,0 +1,27 @@ +// 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. +// 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.gerrit.extensions.registration.DynamicSet; +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(), 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-validationListenerRefOperation/tools/bazel.rc b/example-validationListenerRefOperation/tools/bazel.rc new file mode 100644 index 0000000..4ed16cf --- /dev/null +++ b/example-validationListenerRefOperation/tools/bazel.rc
@@ -0,0 +1,2 @@ +build --workspace_status_command=./tools/workspace-status.sh +test --build_tests_only
diff --git a/example-validationListenerRefOperation/tools/bzl/BUILD b/example-validationListenerRefOperation/tools/bzl/BUILD new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/example-validationListenerRefOperation/tools/bzl/BUILD
diff --git a/example-validationListenerRefOperation/tools/bzl/plugin.bzl b/example-validationListenerRefOperation/tools/bzl/plugin.bzl new file mode 100644 index 0000000..2b1df8c --- /dev/null +++ b/example-validationListenerRefOperation/tools/bzl/plugin.bzl
@@ -0,0 +1,4 @@ +load( + "@com_googlesource_gerrit_bazlets//:gerrit_plugin.bzl", + "gerrit_plugin", +)
diff --git a/example-validationListenerRefOperation/tools/workspace-status.sh b/example-validationListenerRefOperation/tools/workspace-status.sh new file mode 100755 index 0000000..a157618 --- /dev/null +++ b/example-validationListenerRefOperation/tools/workspace-status.sh
@@ -0,0 +1,17 @@ +#!/bin/bash + +# This script will be run by bazel when the build process starts to +# generate key-value information that represents the status of the +# workspace. The output should be like +# +# KEY1 VALUE1 +# KEY2 VALUE2 +# +# If the script exits with non-zero code, it's considered as a failure +# and the output will be discarded. + +function rev() { + git describe --always --match "v[0-9].*" --dirty +} + +echo STABLE_BUILD_EXAMPLE-VALIDATIONLISTENERREFOPERATION_LABEL $(rev)
diff --git a/example-validationListenerUpload/.buckconfig b/example-validationListenerUpload/.buckconfig new file mode 100644 index 0000000..277e01e --- /dev/null +++ b/example-validationListenerUpload/.buckconfig
@@ -0,0 +1,15 @@ +[alias] + plugin = //:example-validationListenerUpload + +[java] + src_roots = java, resources + source_level = 8 + target_level = 8 + +[project] + ignore = .git + +[cache] + mode = dir + dir = buck-out/cache +
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-validationListenerUpload/LICENSE b/example-validationListenerUpload/LICENSE new file mode 100644 index 0000000..11069ed --- /dev/null +++ b/example-validationListenerUpload/LICENSE
@@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +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.
diff --git a/example-validationListenerUpload/WORKSPACE b/example-validationListenerUpload/WORKSPACE new file mode 100644 index 0000000..71770df --- /dev/null +++ b/example-validationListenerUpload/WORKSPACE
@@ -0,0 +1,26 @@ +workspace(name = "validationListenerUpload") + +load("//:bazlets.bzl", "load_bazlets") + +load_bazlets( + commit = "0f87babe07a555425d829c6e7951e296e9e24579", + # local_path = "/home/<user>/projects/bazlets", +) + +# Release Plugin API +load( + "@com_googlesource_gerrit_bazlets//:gerrit_api.bzl", + "gerrit_api", +) + +# Snapshot Plugin API +#load( +# "@com_googlesource_gerrit_bazlets//:gerrit_api_maven_local.bzl", +# "gerrit_api_maven_local", +#) + +# Load release Plugin API +gerrit_api() + +# Load snapshot Plugin API +#gerrit_api_maven_local()
diff --git a/example-validationListenerUpload/bazlets.bzl b/example-validationListenerUpload/bazlets.bzl new file mode 100644 index 0000000..e14e488 --- /dev/null +++ b/example-validationListenerUpload/bazlets.bzl
@@ -0,0 +1,17 @@ +NAME = "com_googlesource_gerrit_bazlets" + +def load_bazlets( + commit, + local_path = None + ): + if not local_path: + native.git_repository( + name = NAME, + remote = "https://gerrit.googlesource.com/bazlets", + commit = commit, + ) + else: + native.local_repository( + name = NAME, + path = local_path, + )
diff --git a/example-validationListenerUpload/lib/gerrit/BUCK b/example-validationListenerUpload/lib/gerrit/BUCK new file mode 100644 index 0000000..8d5f0e9 --- /dev/null +++ b/example-validationListenerUpload/lib/gerrit/BUCK
@@ -0,0 +1,20 @@ +include_defs('//bucklets/maven_jar.bucklet') + +VER = '2.14-SNAPSHOT' +REPO = MAVEN_LOCAL + +maven_jar( + name = 'acceptance-framework', + id = 'com.google.gerrit:gerrit-acceptance-framework:' + VER, + license = 'Apache2.0', + attach_source = False, + repository = REPO, +) + +maven_jar( + name = 'plugin-api', + id = 'com.google.gerrit:gerrit-plugin-api:' + VER, + license = 'Apache2.0', + attach_source = False, + repository = REPO, +)
diff --git a/example-validationListenerUpload/pom.xml b/example-validationListenerUpload/pom.xml new file mode 100644 index 0000000..289db64 --- /dev/null +++ b/example-validationListenerUpload/pom.xml
@@ -0,0 +1,85 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>com.googlesource.gerrit.plugins</groupId> + <artifactId>example-validationListenerUpload</artifactId> + <packaging>jar</packaging> + <version>2.14-SNAPSHOT</version> + <properties> + <Gerrit-ApiType>plugin</Gerrit-ApiType> + <Gerrit-ApiVersion>${project.version}</Gerrit-ApiVersion> + </properties> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>2.4</version> + <configuration> + <archive> + <manifestEntries> + <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 Validation Listener Upload</Implementation-Title> + <Implementation-Version>${project.version}</Implementation-Version> + + <Gerrit-ApiType>${Gerrit-ApiType}</Gerrit-ApiType> + <Gerrit-ApiVersion>${Gerrit-ApiVersion}</Gerrit-ApiVersion> + </manifestEntries> + </archive> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.3.2</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + <encoding>UTF-8</encoding> + </configuration> + </plugin> + </plugins> + + </build> + + <dependencies> + <dependency> + <groupId>com.google.gerrit</groupId> + <artifactId>gerrit-${Gerrit-ApiType}-api</artifactId> + <version>${Gerrit-ApiVersion}</version> + <scope>provided</scope> + </dependency> + </dependencies> + + <repositories> + <repository> + <id>maven.org</id> + <url>http://repo1.maven.org/maven2</url> + </repository> + </repositories> +</project>
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-validationListenerUpload/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerupload/Module.java b/example-validationListenerUpload/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerupload/Module.java new file mode 100644 index 0000000..8bb84a3 --- /dev/null +++ b/example-validationListenerUpload/src/main/java/com/googlesource/gerrit/plugins/examples/validationlistenerupload/Module.java
@@ -0,0 +1,27 @@ +// 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. +// 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.extensions.registration.DynamicSet; +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(), 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-validationListenerUpload/tools/bazel.rc b/example-validationListenerUpload/tools/bazel.rc new file mode 100644 index 0000000..4ed16cf --- /dev/null +++ b/example-validationListenerUpload/tools/bazel.rc
@@ -0,0 +1,2 @@ +build --workspace_status_command=./tools/workspace-status.sh +test --build_tests_only
diff --git a/example-validationListenerUpload/tools/bzl/BUILD b/example-validationListenerUpload/tools/bzl/BUILD new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/example-validationListenerUpload/tools/bzl/BUILD
diff --git a/example-validationListenerUpload/tools/bzl/plugin.bzl b/example-validationListenerUpload/tools/bzl/plugin.bzl new file mode 100644 index 0000000..2b1df8c --- /dev/null +++ b/example-validationListenerUpload/tools/bzl/plugin.bzl
@@ -0,0 +1,4 @@ +load( + "@com_googlesource_gerrit_bazlets//:gerrit_plugin.bzl", + "gerrit_plugin", +)
diff --git a/example-validationListenerUpload/tools/workspace-status.sh b/example-validationListenerUpload/tools/workspace-status.sh new file mode 100755 index 0000000..9248805 --- /dev/null +++ b/example-validationListenerUpload/tools/workspace-status.sh
@@ -0,0 +1,17 @@ +#!/bin/bash + +# This script will be run by bazel when the build process starts to +# generate key-value information that represents the status of the +# workspace. The output should be like +# +# KEY1 VALUE1 +# KEY2 VALUE2 +# +# If the script exits with non-zero code, it's considered as a failure +# and the output will be discarded. + +function rev() { + git describe --always --match "v[0-9].*" --dirty +} + +echo STABLE_BUILD_EXAMPLE-VALIDATIONLISTENERUPLOAD_LABEL $(rev)