Format all Java files with google-java-format Change-Id: I7d2fa9d81b17c4793cc6e1cea6c802fa0fedc48d
diff --git a/src/main/java/com/googlesource/gerrit/plugins/scripting/groovyprovider/GroovyPluginProvider.java b/src/main/java/com/googlesource/gerrit/plugins/scripting/groovyprovider/GroovyPluginProvider.java index 915805e..7c07387 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/scripting/groovyprovider/GroovyPluginProvider.java +++ b/src/main/java/com/googlesource/gerrit/plugins/scripting/groovyprovider/GroovyPluginProvider.java
@@ -23,35 +23,27 @@ import com.google.gerrit.server.plugins.ServerPluginProvider; import com.google.inject.Inject; import com.google.inject.Provider; - -import org.eclipse.jgit.internal.storage.file.FileSnapshot; - import java.nio.file.Path; import java.util.Set; +import org.eclipse.jgit.internal.storage.file.FileSnapshot; /** * Groovy scripting plugins. * - * Allows to define a Groovy class to implement any type of Gerrit plugin. + * <p>Allows to define a Groovy class to implement any type of Gerrit plugin. * - * Example of Groovy SSH Plugin (hello-1.0.groovy): - * ------------------------------------------------ import - * com.google.gerrit.sshd.SshCommand import - * com.google.gerrit.extensions.annotations.Export + * <p>Example of Groovy SSH Plugin (hello-1.0.groovy): + * ------------------------------------------------ import com.google.gerrit.sshd.SshCommand import + * com.google.gerrit.extensions.annotations.Export @Export("groovy") class GroovyCommand extends + * SshCommand { public void run() { stdout.println("Hello Gerrit from Groovy !") } * - * @Export("groovy") - * class GroovyCommand extends SshCommand { - * public void run() { - * stdout.println("Hello Gerrit from Groovy !") - * } - * - * The above example add a "hello groovy" command to Gerrit - * SSH interface that displays "Hello Gerrit from Groovy !". + * <p>The above example add a "hello groovy" command to Gerrit SSH interface that displays "Hello + * Gerrit from Groovy !". */ @Listen class GroovyPluginProvider implements ServerPluginProvider { - private static final Set<String> GROOVY_EXTENSIONS = Sets.newHashSet( - "groovy", "gvy", "gy", "gsh"); + private static final Set<String> GROOVY_EXTENSIONS = + Sets.newHashSet("groovy", "gvy", "gy", "gsh"); private final Provider<GroovyPluginScriptEngine> scriptEngineProvider; private final String providerPluginName; @@ -65,13 +57,18 @@ } @Override - public ServerPlugin get(Path srcFile, FileSnapshot snapshot, - PluginDescription description) throws InvalidPluginException { + public ServerPlugin get(Path srcFile, FileSnapshot snapshot, PluginDescription description) + throws InvalidPluginException { GroovyPluginScriptEngine scriptEngine = scriptEngineProvider.get(); - return new ServerPlugin(getPluginName(srcFile), description.canonicalUrl, - description.user, srcFile, snapshot, new GroovyPluginScanner( - getPluginName(srcFile), scriptEngine, srcFile), - description.dataDir, scriptEngine.getGroovyClassLoader()); + return new ServerPlugin( + getPluginName(srcFile), + description.canonicalUrl, + description.user, + srcFile, + snapshot, + new GroovyPluginScanner(getPluginName(srcFile), scriptEngine, srcFile), + description.dataDir, + scriptEngine.getGroovyClassLoader()); } @Override @@ -85,10 +82,9 @@ String srcFileName = srcFile.getFileName().toString(); int dashPos = srcFileName.lastIndexOf('-'); int dotPos = srcFileName.lastIndexOf('.'); - return srcFileName.substring(0, dashPos > 0 ? dashPos:dotPos); + return srcFileName.substring(0, dashPos > 0 ? dashPos : dotPos); } - @Override public String getProviderPluginName() { return providerPluginName;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/scripting/groovyprovider/GroovyPluginScanner.java b/src/main/java/com/googlesource/gerrit/plugins/scripting/groovyprovider/GroovyPluginScanner.java index f93f45e..435dd1c 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/scripting/groovyprovider/GroovyPluginScanner.java +++ b/src/main/java/com/googlesource/gerrit/plugins/scripting/groovyprovider/GroovyPluginScanner.java
@@ -13,20 +13,15 @@ // limitations under the License. package com.googlesource.gerrit.plugins.scripting.groovyprovider; -import java.util.Optional; import com.google.common.collect.Sets; import com.google.gerrit.server.plugins.AbstractPreloadedPluginScanner; import com.google.gerrit.server.plugins.InvalidPluginException; -import com.google.gerrit.server.plugins.PluginEntry; import com.google.gerrit.server.plugins.Plugin.ApiType; - +import com.google.gerrit.server.plugins.PluginEntry; import groovy.lang.Binding; import groovy.lang.Script; import groovy.util.ResourceException; import groovy.util.ScriptException; - -import org.codehaus.groovy.runtime.InvokerHelper; - import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; @@ -36,7 +31,9 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; +import java.util.Optional; import java.util.Set; +import org.codehaus.groovy.runtime.InvokerHelper; public class GroovyPluginScanner extends AbstractPreloadedPluginScanner { @@ -58,8 +55,7 @@ } @Override - public InputStream getInputStream(PluginEntry entry) - throws IOException { + public InputStream getInputStream(PluginEntry entry) throws IOException { throw new FileNotFoundException(); } @@ -68,12 +64,12 @@ return Collections.emptyEnumeration(); } - public static Set<Class<?>> load(GroovyPluginScriptEngine scriptEngine, Path srcFile) throws InvalidPluginException { + public static Set<Class<?>> load(GroovyPluginScriptEngine scriptEngine, Path srcFile) + throws InvalidPluginException { try { return scanGroovyScriptBindings(scriptEngine.loadScriptByName(srcFile.toString())); } catch (ResourceException | ScriptException e) { - throw new InvalidPluginException( - "Cannot compile and execute Groovy script " + srcFile, e); + throw new InvalidPluginException("Cannot compile and execute Groovy script " + srcFile, e); } } @@ -84,16 +80,15 @@ try { Method mainMethod = scriptClass.getMethod("main", String[].class); int modifiers = mainMethod.getModifiers(); - if (Modifier.isPublic(modifiers) - && Modifier.isStatic(modifiers)) { + if (Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers)) { classes.addAll(getMainBindings(scriptClass)); } } catch (NoSuchMethodException e) { classes.add(scriptClass); } catch (SecurityException e) { - throw new InvalidPluginException("Cannot access Groovy script class " - + scriptClass.getName(), e); + throw new InvalidPluginException( + "Cannot access Groovy script class " + scriptClass.getName(), e); } return classes; }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/scripting/groovyprovider/GroovyPluginScriptEngine.java b/src/main/java/com/googlesource/gerrit/plugins/scripting/groovyprovider/GroovyPluginScriptEngine.java index 1462bc4..e86a0af 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/scripting/groovyprovider/GroovyPluginScriptEngine.java +++ b/src/main/java/com/googlesource/gerrit/plugins/scripting/groovyprovider/GroovyPluginScriptEngine.java
@@ -15,17 +15,14 @@ import com.google.gerrit.server.config.SitePaths; import com.google.inject.Inject; - +import groovy.util.GroovyScriptEngine; import java.net.MalformedURLException; import java.net.URL; -import groovy.util.GroovyScriptEngine; - public class GroovyPluginScriptEngine extends GroovyScriptEngine { @Inject - public GroovyPluginScriptEngine(SitePaths sitePaths) - throws MalformedURLException { + public GroovyPluginScriptEngine(SitePaths sitePaths) throws MalformedURLException { super(new URL[] {sitePaths.plugins_dir.toUri().toURL()}); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/scripting/groovyprovider/Module.java b/src/main/java/com/googlesource/gerrit/plugins/scripting/groovyprovider/Module.java index 512c67f..15e444a 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/scripting/groovyprovider/Module.java +++ b/src/main/java/com/googlesource/gerrit/plugins/scripting/groovyprovider/Module.java
@@ -22,8 +22,7 @@ @Override protected void configure() { - DynamicSet.bind(binder(), ServerPluginProvider.class) - .to(GroovyPluginProvider.class); + DynamicSet.bind(binder(), ServerPluginProvider.class).to(GroovyPluginProvider.class); bind(GroovyPluginScriptEngine.class); } }