Merge branch 'stable-3.2'
* stable-3.2:
Error Prone: Enable and fix ClassCanBeStatic
AutoRegisterModulesTest: Declare inner classes as static
Update git submodules
Fix issue with auto registering ssh commands
Convert plugin's name to lowercase when generate hook name
Update git submodules
Update git submodules
ErrorProne: Increase severity of FunctionalInterfaceClash to ERROR
Revert "LifecycleListener: Mark stop method as default to make it optional"
Update git submodules
LifecycleListener: Mark stop method as default to make it optional
Change-Id: Ie86ec489f985cf0c024d70e555c5f47d961a155d
diff --git a/java/com/google/gerrit/server/plugins/AutoRegisterModules.java b/java/com/google/gerrit/server/plugins/AutoRegisterModules.java
index fde61ff..9d93ed2 100644
--- a/java/com/google/gerrit/server/plugins/AutoRegisterModules.java
+++ b/java/com/google/gerrit/server/plugins/AutoRegisterModules.java
@@ -158,7 +158,7 @@
return;
}
- if (is("org.apache.sshd.server.Command", clazz)) {
+ if (is("org.apache.sshd.server.command.Command", clazz)) {
sshGen.export(export, clazz);
} else if (is("javax.servlet.http.HttpServlet", clazz)) {
httpGen.export(export, clazz);
diff --git a/java/com/google/gerrit/server/plugins/PluginGuiceEnvironment.java b/java/com/google/gerrit/server/plugins/PluginGuiceEnvironment.java
index c032c46..87e1ca9 100644
--- a/java/com/google/gerrit/server/plugins/PluginGuiceEnvironment.java
+++ b/java/com/google/gerrit/server/plugins/PluginGuiceEnvironment.java
@@ -589,7 +589,7 @@
return false;
}
- if (is("org.apache.sshd.server.Command", type)) {
+ if (is("org.apache.sshd.server.command.Command", type)) {
return false;
}
diff --git a/javatests/com/google/gerrit/server/BUILD b/javatests/com/google/gerrit/server/BUILD
index 60d9d69..248c7d1 100644
--- a/javatests/com/google/gerrit/server/BUILD
+++ b/javatests/com/google/gerrit/server/BUILD
@@ -63,6 +63,7 @@
"//java/com/google/gerrit/server/schema",
"//java/com/google/gerrit/server/schema/testing",
"//java/com/google/gerrit/server/util/time",
+ "//java/com/google/gerrit/sshd",
"//java/com/google/gerrit/testing:assertable-executor",
"//java/com/google/gerrit/testing:gerrit-test-util",
"//java/com/google/gerrit/truth",
diff --git a/javatests/com/google/gerrit/server/plugins/AutoRegisterModulesTest.java b/javatests/com/google/gerrit/server/plugins/AutoRegisterModulesTest.java
new file mode 100644
index 0000000..55c9bc3
--- /dev/null
+++ b/javatests/com/google/gerrit/server/plugins/AutoRegisterModulesTest.java
@@ -0,0 +1,101 @@
+// Copyright (C) 2020 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 static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.google.common.collect.Lists;
+import com.google.gerrit.extensions.annotations.Export;
+import com.google.gerrit.extensions.annotations.Listen;
+import com.google.gerrit.sshd.SshCommand;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.annotation.Annotation;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.jar.Manifest;
+import org.junit.Test;
+
+public class AutoRegisterModulesTest {
+
+ @Test
+ public void shouldRegisterSshCommand() throws InvalidPluginException {
+ ModuleGenerator sshModule = mock(ModuleGenerator.class);
+ PluginGuiceEnvironment env = mock(PluginGuiceEnvironment.class);
+
+ when(env.hasSshModule()).thenReturn(true);
+ when(env.newSshModuleGenerator()).thenReturn(sshModule);
+
+ PluginContentScanner scanner = new TestPluginContextScanner();
+ ClassLoader classLoader = this.getClass().getClassLoader();
+
+ AutoRegisterModules objectUnderTest =
+ new AutoRegisterModules("test_plugin_name", env, scanner, classLoader);
+ objectUnderTest.discover();
+
+ verify(sshModule).setPluginName("test_plugin_name");
+ verify(sshModule).export(any(Export.class), eq(TestSshCommand.class));
+ }
+
+ @Export(value = "test")
+ public static class TestSshCommand extends SshCommand {
+ @Override
+ protected void run() throws UnloggedFailure, Failure, Exception {}
+ }
+
+ private static class TestPluginContextScanner implements PluginContentScanner {
+
+ @Override
+ public Manifest getManifest() throws IOException {
+ return null;
+ }
+
+ @Override
+ public Map<Class<? extends Annotation>, Iterable<ExtensionMetaData>> scan(
+ String pluginName, Iterable<Class<? extends Annotation>> annotations)
+ throws InvalidPluginException {
+ Map<Class<? extends Annotation>, Iterable<ExtensionMetaData>> extensions = new HashMap<>();
+ extensions.put(
+ Export.class,
+ Lists.newArrayList(
+ new ExtensionMetaData(
+ "com.google.gerrit.server.plugins.AutoRegisterModulesTest$TestSshCommand",
+ "com.google.gerrit.extensions.annotations.Export")));
+ extensions.put(Listen.class, Lists.newArrayList());
+ return extensions;
+ }
+
+ @Override
+ public Optional<PluginEntry> getEntry(String resourcePath) throws IOException {
+ return null;
+ }
+
+ @Override
+ public InputStream getInputStream(PluginEntry entry) throws IOException {
+ return null;
+ }
+
+ @Override
+ public Enumeration<PluginEntry> entries() {
+ return null;
+ }
+ }
+}
diff --git a/polygerrit-ui/app/elements/plugins/gr-dom-hooks/gr-dom-hooks.js b/polygerrit-ui/app/elements/plugins/gr-dom-hooks/gr-dom-hooks.js
index 4822163..93cbcf5 100644
--- a/polygerrit-ui/app/elements/plugins/gr-dom-hooks/gr-dom-hooks.js
+++ b/polygerrit-ui/app/elements/plugins/gr-dom-hooks/gr-dom-hooks.js
@@ -27,7 +27,12 @@
if (opt_moduleName) {
return endpointName + ' ' + opt_moduleName;
} else {
- return this._plugin.getPluginName() + '-autogenerated-' + endpointName;
+ // lowercase in case plugin's name contains uppercase letters
+ // TODO: this still can not prevent if plugin has invalid char
+ // other than uppercase, but is the first step
+ // https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
+ const pluginName = this._plugin.getPluginName() || 'unknown_plugin';
+ return pluginName.toLowerCase() + '-autogenerated-' + endpointName;
}
};