Merge branch 'stable-2.6'
* stable-2.6: Fix NPE when abandoning change with invalid author Only show submit type in change view for open changes Allow seeing the submit type for patch sets which are not current Update plugin-gwt-archetype to match current implementation Update plugin-js-archetype to match current implementation Add ApiType.JS Do not call onModuleLoad() second time Register @Listen annotated classes in Http and Ssh modules
This commit is contained in:
commit
c9c0912827
@ -14,14 +14,20 @@
|
||||
|
||||
package com.google.gerrit.httpd.plugins;
|
||||
|
||||
import static com.google.gerrit.server.plugins.AutoRegisterUtil.calculateBindAnnotation;
|
||||
|
||||
import com.google.common.collect.LinkedListMultimap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.gerrit.extensions.annotations.Export;
|
||||
import com.google.gerrit.server.plugins.InvalidPluginException;
|
||||
import com.google.gerrit.server.plugins.ModuleGenerator;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Scopes;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServlet;
|
||||
@ -29,6 +35,7 @@ import javax.servlet.http.HttpServlet;
|
||||
class HttpAutoRegisterModuleGenerator extends ServletModule
|
||||
implements ModuleGenerator {
|
||||
private final Map<String, Class<HttpServlet>> serve = Maps.newHashMap();
|
||||
private final Multimap<TypeLiteral<?>, Class<?>> listeners = LinkedListMultimap.create();
|
||||
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
@ -36,6 +43,16 @@ class HttpAutoRegisterModuleGenerator extends ServletModule
|
||||
bind(e.getValue()).in(Scopes.SINGLETON);
|
||||
serve(e.getKey()).with(e.getValue());
|
||||
}
|
||||
for (Map.Entry<TypeLiteral<?>, Class<?>> e : listeners.entries()) {
|
||||
@SuppressWarnings("unchecked")
|
||||
TypeLiteral<Object> type = (TypeLiteral<Object>) e.getKey();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<Object> impl = (Class<Object>) e.getValue();
|
||||
|
||||
Annotation n = calculateBindAnnotation(impl);
|
||||
bind(type).annotatedWith(n).to(impl);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -62,6 +79,11 @@ class HttpAutoRegisterModuleGenerator extends ServletModule
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void listen(TypeLiteral<?> tl, Class<?> clazz) {
|
||||
listeners.put(tl, clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module create() throws InvalidPluginException {
|
||||
return this;
|
||||
|
@ -41,8 +41,6 @@ limitations under the License.
|
||||
</includes>
|
||||
<archive>
|
||||
<manifestEntries>
|
||||
<Gerrit-Module>${package}.Module</Gerrit-Module>
|
||||
|
||||
<Implementation-Vendor>${Implementation-Vendor}</Implementation-Vendor>
|
||||
<Implementation-URL>${Implementation-Url}</Implementation-URL>
|
||||
|
||||
|
@ -14,13 +14,12 @@
|
||||
|
||||
package ${package};
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.gerrit.extensions.webui.WebUiPlugin;
|
||||
import com.google.gerrit.extensions.webui.GwtPlugin;
|
||||
import com.google.gerrit.extensions.annotations.Listen;
|
||||
|
||||
class Module extends AbstractModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(WebUiPlugin.class).toInstance(new GwtPlugin("hello_gwt_plugins"));
|
||||
@Listen
|
||||
public class MyExtension extends GwtPlugin {
|
||||
public MyExtension() {
|
||||
super("hello_gwt_plugins");
|
||||
}
|
||||
}
|
@ -72,12 +72,6 @@ public class PluginGenerator extends Generator {
|
||||
|
||||
// We really use a SourceWriter since it's convenient
|
||||
SourceWriter sw = f.createSourceWriter(context, out);
|
||||
sw.println("public " + generatedSimpleSourceName + "() {");
|
||||
sw.indent();
|
||||
sw.println("onModuleLoad();");
|
||||
sw.outdent();
|
||||
sw.println("}");
|
||||
|
||||
sw.commit(logger);
|
||||
}
|
||||
|
||||
|
@ -42,8 +42,6 @@ limitations under the License.
|
||||
</includes>
|
||||
<archive>
|
||||
<manifestEntries>
|
||||
<Gerrit-Module>${package}.Module</Gerrit-Module>
|
||||
|
||||
<Implementation-Vendor>${Implementation-Vendor}</Implementation-Vendor>
|
||||
<Implementation-URL>${Implementation-Url}</Implementation-URL>
|
||||
|
||||
|
@ -14,13 +14,12 @@
|
||||
|
||||
package ${package};
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.gerrit.extensions.webui.WebUiPlugin;
|
||||
import com.google.gerrit.extensions.annotations.Listen;
|
||||
import com.google.gerrit.extensions.webui.JavaScriptPlugin;
|
||||
|
||||
class Module extends AbstractModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(WebUiPlugin.class).toInstance(new JavaScriptPlugin("hello-js-plugins.js"));
|
||||
@Listen
|
||||
public class MyJsExtension extends JavaScriptPlugin {
|
||||
public MyJsExtension() {
|
||||
super("hello-js-plugins.js");
|
||||
}
|
||||
}
|
@ -411,6 +411,9 @@ public class EventFactory {
|
||||
* @return object suitable for serialization to JSON
|
||||
*/
|
||||
public AccountAttribute asAccountAttribute(Account.Id id) {
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
return asAccountAttribute(accountCache.get(id).getAccount());
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.server.plugins;
|
||||
|
||||
import static com.google.gerrit.server.plugins.AutoRegisterUtil.calculateBindAnnotation;
|
||||
import static com.google.gerrit.server.plugins.PluginGuiceEnvironment.is;
|
||||
|
||||
import com.google.common.collect.LinkedListMultimap;
|
||||
@ -26,7 +27,6 @@ import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Scopes;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.google.inject.internal.UniqueAnnotations;
|
||||
|
||||
import org.eclipse.jgit.util.IO;
|
||||
import org.objectweb.asm.AnnotationVisitor;
|
||||
@ -116,16 +116,7 @@ class AutoRegisterModules {
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<Object> impl = (Class<Object>) e.getValue();
|
||||
|
||||
Annotation n = impl.getAnnotation(Export.class);
|
||||
if (n == null) {
|
||||
n = impl.getAnnotation(javax.inject.Named.class);
|
||||
}
|
||||
if (n == null) {
|
||||
n = impl.getAnnotation(com.google.inject.name.Named.class);
|
||||
}
|
||||
if (n == null) {
|
||||
n = UniqueAnnotations.create();
|
||||
}
|
||||
Annotation n = calculateBindAnnotation(impl);
|
||||
bind(type).annotatedWith(n).to(impl);
|
||||
}
|
||||
}
|
||||
@ -248,6 +239,8 @@ class AutoRegisterModules {
|
||||
if (env.hasDynamicSet(tl)) {
|
||||
sysSingletons.add(clazz);
|
||||
sysListen.put(tl, clazz);
|
||||
httpGen.listen(tl, clazz);
|
||||
sshGen.listen(tl, clazz);
|
||||
} else if (env.hasDynamicMap(tl)) {
|
||||
if (clazz.getAnnotation(Export.class) == null) {
|
||||
throw new InvalidPluginException(String.format(
|
||||
@ -256,6 +249,8 @@ class AutoRegisterModules {
|
||||
}
|
||||
sysSingletons.add(clazz);
|
||||
sysListen.put(tl, clazz);
|
||||
httpGen.listen(tl, clazz);
|
||||
sshGen.listen(tl, clazz);
|
||||
} else {
|
||||
throw new InvalidPluginException(String.format(
|
||||
"Cannot register %s, server does not accept %s",
|
||||
|
@ -0,0 +1,41 @@
|
||||
// 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.server.plugins;
|
||||
|
||||
import com.google.gerrit.extensions.annotations.Export;
|
||||
import com.google.inject.internal.UniqueAnnotations;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
public final class AutoRegisterUtil {
|
||||
|
||||
public static Annotation calculateBindAnnotation(Class<Object> impl) {
|
||||
Annotation n = impl.getAnnotation(Export.class);
|
||||
if (n == null) {
|
||||
n = impl.getAnnotation(javax.inject.Named.class);
|
||||
}
|
||||
if (n == null) {
|
||||
n = impl.getAnnotation(com.google.inject.name.Named.class);
|
||||
}
|
||||
if (n == null) {
|
||||
n = UniqueAnnotations.create();
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
private AutoRegisterUtil() {
|
||||
// hide default constructor
|
||||
}
|
||||
}
|
@ -16,11 +16,14 @@ package com.google.gerrit.server.plugins;
|
||||
|
||||
import com.google.gerrit.extensions.annotations.Export;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
public interface ModuleGenerator {
|
||||
void setPluginName(String name);
|
||||
|
||||
void export(Export export, Class<?> type) throws InvalidPluginException;
|
||||
|
||||
void listen(TypeLiteral<?> tl, Class<?> clazz);
|
||||
|
||||
Module create() throws InvalidPluginException;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ import javax.annotation.Nullable;
|
||||
|
||||
public class Plugin {
|
||||
public static enum ApiType {
|
||||
EXTENSION, PLUGIN;
|
||||
EXTENSION, PLUGIN, JS;
|
||||
}
|
||||
|
||||
/** Unique key that changes whenever a plugin reloads. */
|
||||
@ -74,6 +74,8 @@ public class Plugin {
|
||||
return ApiType.EXTENSION;
|
||||
} else if (ApiType.PLUGIN.name().equalsIgnoreCase(v)) {
|
||||
return ApiType.PLUGIN;
|
||||
} else if (ApiType.JS.name().equalsIgnoreCase(v)) {
|
||||
return ApiType.JS;
|
||||
} else {
|
||||
throw new InvalidPluginException("Invalid Gerrit-ApiType: " + v);
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import com.google.common.collect.Sets;
|
||||
import com.google.gerrit.extensions.annotations.PluginName;
|
||||
import com.google.gerrit.extensions.events.LifecycleListener;
|
||||
import com.google.gerrit.extensions.systemstatus.ServerInformation;
|
||||
import com.google.gerrit.extensions.webui.JavaScriptPlugin;
|
||||
import com.google.gerrit.server.config.ConfigUtil;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.config.SitePaths;
|
||||
@ -473,6 +474,8 @@ public class PluginLoader implements LifecycleListener {
|
||||
return PluginName.class.getClassLoader();
|
||||
case PLUGIN:
|
||||
return PluginLoader.class.getClassLoader();
|
||||
case JS:
|
||||
return JavaScriptPlugin.class.getClassLoader();
|
||||
default:
|
||||
throw new InvalidPluginException("Unsupported ApiType " + type);
|
||||
}
|
||||
|
@ -456,11 +456,6 @@ public class ChangeControl {
|
||||
@SuppressWarnings("unchecked")
|
||||
public SubmitTypeRecord getSubmitTypeRecord(ReviewDb db, PatchSet patchSet,
|
||||
@Nullable ChangeData cd) {
|
||||
if (!patchSet.getId().equals(change.currentPatchSetId())) {
|
||||
return typeRuleError("Patch set " + patchSet.getPatchSetId()
|
||||
+ " is not current");
|
||||
}
|
||||
|
||||
try {
|
||||
if (change.getStatus() == Change.Status.DRAFT && !isDraftVisible(db, cd)) {
|
||||
return typeRuleError("Patch set " + patchSet.getPatchSetId()
|
||||
|
@ -14,22 +14,29 @@
|
||||
|
||||
package com.google.gerrit.sshd;
|
||||
|
||||
import static com.google.gerrit.server.plugins.AutoRegisterUtil.calculateBindAnnotation;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.LinkedListMultimap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.gerrit.extensions.annotations.Export;
|
||||
import com.google.gerrit.server.plugins.InvalidPluginException;
|
||||
import com.google.gerrit.server.plugins.ModuleGenerator;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
import org.apache.sshd.server.Command;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Map;
|
||||
|
||||
class SshAutoRegisterModuleGenerator
|
||||
extends AbstractModule
|
||||
implements ModuleGenerator {
|
||||
private final Map<String, Class<Command>> commands = Maps.newHashMap();
|
||||
private final Multimap<TypeLiteral<?>, Class<?>> listeners = LinkedListMultimap.create();
|
||||
private CommandName command;
|
||||
|
||||
@Override
|
||||
@ -39,6 +46,16 @@ class SshAutoRegisterModuleGenerator
|
||||
for (Map.Entry<String, Class<Command>> e : commands.entrySet()) {
|
||||
bind(Commands.key(command, e.getKey())).to(e.getValue());
|
||||
}
|
||||
for (Map.Entry<TypeLiteral<?>, Class<?>> e : listeners.entries()) {
|
||||
@SuppressWarnings("unchecked")
|
||||
TypeLiteral<Object> type = (TypeLiteral<Object>) e.getKey();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<Object> impl = (Class<Object>) e.getValue();
|
||||
|
||||
Annotation n = calculateBindAnnotation(impl);
|
||||
bind(type).annotatedWith(n).to(impl);
|
||||
}
|
||||
}
|
||||
|
||||
public void setPluginName(String name) {
|
||||
@ -66,6 +83,12 @@ class SshAutoRegisterModuleGenerator
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void listen(TypeLiteral<?> tl, Class<?> clazz) {
|
||||
listeners.put(tl, clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module create() throws InvalidPluginException {
|
||||
Preconditions.checkState(command != null, "pluginName must be provided");
|
||||
|
Loading…
Reference in New Issue
Block a user