Define gerrit-extension-api module

This module will hold a set of thin interfaces that extensions can
build against. Extensions are more lightweight than plugins and have
a smaller surface of the Gerrit server available to them.

Change-Id: I4213004f1ba5c034cf8fc7fbb9f6dd53f3ec8a96
This commit is contained in:
Shawn O. Pearce
2012-05-10 15:31:48 -07:00
parent 450f0cc262
commit 1650acea38
19 changed files with 611 additions and 42 deletions

View File

@@ -0,0 +1,52 @@
// Copyright (C) 2012 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.extensions.annotations;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import com.google.inject.BindingAnnotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
/**
* Annotation applied to auto-registered, exported types.
* <p>
* Plugins or extensions using auto-registration should apply this annotation to
* any non-abstract class they want exported for access.
* <p>
* For SSH commands the @Export annotation names the subcommand:
*
* <pre>
* @Export("print")
* class MyCommand extends SshCommand {
* </pre>
*
* For HTTP servlets, the @Export annotation names the URL the servlet is bound
* to, relative to the plugin or extension's namespace within the Gerrit
* container.
*
* <pre>
* @Export("/index.html")
* class ShowIndexHtml extends HttpServlet {
* </pre>
*/
@Target({ElementType.TYPE})
@Retention(RUNTIME)
@BindingAnnotation
public @interface Export {
String value();
}

View File

@@ -0,0 +1,52 @@
// Copyright (C) 2012 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.extensions.annotations;
import java.io.Serializable;
import java.lang.annotation.Annotation;
final class ExportImpl implements Export, Serializable {
private static final long serialVersionUID = 0;
private final String value;
ExportImpl(String value) {
this.value = value;
}
@Override
public Class<? extends Annotation> annotationType() {
return Export.class;
}
@Override
public String value() {
return value;
}
@Override
public int hashCode() {
return (127 * "value".hashCode()) ^ value.hashCode();
}
@Override
public boolean equals(Object o) {
return o instanceof Export && value.equals(((Export) o).value());
}
@Override
public String toString() {
return "@" + Export.class.getName() + "(value=" + value + ")";
}
}

View File

@@ -0,0 +1,26 @@
// Copyright (C) 2012 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.extensions.annotations;
/** Static constructors for {@link Export} annotations. */
public final class Exports {
/** Create an annotation to export under a specific name. */
public static Export named(String name) {
return new ExportImpl(name);
}
private Exports() {
}
}

View File

@@ -0,0 +1,42 @@
// Copyright (C) 2012 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.extensions.annotations;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import com.google.inject.BindingAnnotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
/**
* Annotation applied to a String containing the plugin or extension name.
* <p>
* A plugin or extension may receive this string by Guice injection to discover
* the name that an administrator has installed the plugin or extension under:
*
* <pre>
* @Inject
* MyType(@PluginName String myName) {
* ...
* }
* </pre>
*/
@Target({ElementType.PARAMETER, ElementType.FIELD})
@Retention(RUNTIME)
@BindingAnnotation
public @interface PluginName {
}