Merge branch 'stable-3.9'
* stable-3.9:
GitHubOAuthConfigTest: Reformat the code using google-java-format
Build github plugin against the v3.8.0-rc5 Gerrit API
PullRequestCreateChange: Remove unused import
Fix velocity deprecated configuration keys
Set plugin version to 3.4.7
Fire git ref update events for all imported refs
PluginVelocityRuntimeProvider: Fix warning flagged by error prone
Fix default scopes resolution
Change-Id: I3f3f559c70378003766916bbf70e8173c3c89109
diff --git a/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/GitHubOAuthConfig.java b/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/GitHubOAuthConfig.java
index 16fcb28..300a945 100644
--- a/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/GitHubOAuthConfig.java
+++ b/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/GitHubOAuthConfig.java
@@ -56,6 +56,7 @@
public static final String GERRIT_LOGIN = "/login";
public static final String GERRIT_LOGOUT = "/logout";
public static final String GITHUB_PLUGIN_OAUTH_SCOPE = "/plugins/github-plugin/static/scope.html";
+ public static final ScopeKey GITHUB_DEFAULT_SCOPES_KEY = new ScopeKey("scopes", null, 0);
public final String gitHubUrl;
public final String gitHubApiUrl;
@@ -186,10 +187,10 @@
}
public Scope[] getDefaultScopes() {
- if (scopes == null || scopes.get("scopes") == null) {
+ if (scopes == null || scopes.get(GITHUB_DEFAULT_SCOPES_KEY) == null) {
return new Scope[0];
}
- return scopes.get("scopes").toArray(new Scope[0]);
+ return scopes.get(GITHUB_DEFAULT_SCOPES_KEY).toArray(new Scope[0]);
}
public KeyConfig getCurrentKeyConfig() {
diff --git a/github-oauth/src/test/java/com/googlesource/gerrit/plugins/github/oauth/GitHubOAuthConfigTest.java b/github-oauth/src/test/java/com/googlesource/gerrit/plugins/github/oauth/GitHubOAuthConfigTest.java
index 7808ff4..7a11427 100644
--- a/github-oauth/src/test/java/com/googlesource/gerrit/plugins/github/oauth/GitHubOAuthConfigTest.java
+++ b/github-oauth/src/test/java/com/googlesource/gerrit/plugins/github/oauth/GitHubOAuthConfigTest.java
@@ -61,7 +61,8 @@
assertEquals(githubOAuthConfig().getCurrentKeyConfig().isCurrent(), true);
assertEquals(githubOAuthConfig().getCurrentKeyConfig().getCipherAlgorithm(), cipherAlgorithm);
- assertEquals(githubOAuthConfig().getCurrentKeyConfig().getSecretKeyAlgorithm(), secretKeyAlgorithm);
+ assertEquals(
+ githubOAuthConfig().getCurrentKeyConfig().getSecretKeyAlgorithm(), secretKeyAlgorithm);
assertEquals(githubOAuthConfig().getCurrentKeyConfig().getKeyId(), keySubsection);
}
@@ -91,7 +92,8 @@
CONF_KEY_SECTION, someOtherKeyConfig, PASSWORD_DEVICE_CONFIG_LABEL, testPasswordDevice);
assertEquals(githubOAuthConfig().getKeyConfig(currentKeyConfig).getKeyId(), currentKeyConfig);
- assertEquals(githubOAuthConfig().getKeyConfig(someOtherKeyConfig).getKeyId(), someOtherKeyConfig);
+ assertEquals(
+ githubOAuthConfig().getKeyConfig(someOtherKeyConfig).getKeyId(), someOtherKeyConfig);
}
@Test
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/GitCloneStep.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/GitCloneStep.java
index 503712c..9d09f51 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/GitCloneStep.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/GitCloneStep.java
@@ -23,11 +23,15 @@
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.RestApiException;
+import com.google.gerrit.server.IdentifiedUser;
+import com.google.gerrit.server.account.AccountState;
+import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.util.ManualRequestContext;
import com.google.gerrit.server.util.OneOffRequestContext;
import com.google.inject.Inject;
+import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted;
import com.googlesource.gerrit.plugins.github.GitHubConfig;
import java.io.File;
@@ -37,7 +41,9 @@
import org.eclipse.jgit.api.FetchCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
+import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ProgressMonitor;
+import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryCache;
import org.slf4j.Logger;
@@ -54,6 +60,8 @@
private final ProjectCache projectCache;
private final GitRepositoryManager repoManager;
private final String projectName;
+ private final GitReferenceUpdated referenceUpdated;
+ private final Provider<IdentifiedUser> identifiedUser;
public interface Factory {
GitCloneStep create(
@@ -69,6 +77,8 @@
DynamicSet<ProjectDeletedListener> deletedListeners,
ProjectCache projectCache,
GitRepositoryManager repoManager,
+ GitReferenceUpdated referenceUpdated,
+ Provider<IdentifiedUser> identifiedUser,
@Assisted("organisation") String organisation,
@Assisted("name") String repository)
throws GitException {
@@ -83,6 +93,8 @@
this.deletedListeners = deletedListeners;
this.projectCache = projectCache;
this.repoManager = repoManager;
+ this.referenceUpdated = referenceUpdated;
+ this.identifiedUser = identifiedUser;
}
private static File prepareTargetGitDirectory(File gitDir, String projectName)
@@ -112,6 +124,7 @@
@Override
public void doImport(ProgressMonitor progress) throws GitException {
createNewProject();
+ Project.NameKey key = Project.nameKey(projectName);
String sourceUri = getSourceUri();
try (Git git = Git.open(destinationDirectory)) {
FetchCommand fetch =
@@ -122,6 +135,11 @@
}
LOG.info(sourceUri + "| Clone into " + destinationDirectory);
fetch.call();
+ AccountState accountState = identifiedUser.get().state();
+ for (Ref ref : git.getRepository().getRefDatabase().getRefs()) {
+ referenceUpdated.fire(
+ key, ref.getName(), ObjectId.zeroId(), ref.getObjectId(), accountState);
+ }
} catch (IOException | GitAPIException e) {
LOG.error("Unable to fetch from {} into {}", sourceUri, destinationDirectory, e);
throw new GitCloneFailedException(sourceUri, e);
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/velocity/PluginVelocityRuntimeProvider.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/velocity/PluginVelocityRuntimeProvider.java
index e1b4d9b..735ac4d 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/velocity/PluginVelocityRuntimeProvider.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/velocity/PluginVelocityRuntimeProvider.java
@@ -21,6 +21,7 @@
import com.google.inject.Singleton;
import java.net.URL;
import java.net.URLClassLoader;
+import java.util.Arrays;
import java.util.Properties;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.RuntimeInstance;
@@ -29,12 +30,12 @@
@Singleton
public class PluginVelocityRuntimeProvider implements Provider<RuntimeInstance> {
- private static final String VELOCITY_FILE_RESOURCE_LOADER_PATH = "file.resource.loader.path";
- private static final String VELOCITY_FILE_RESOURCE_LOADER_CLASS = "file.resource.loader.class";
- private static final String VELOCITY_CLASS_RESOURCE_LOADER_CLASS = "class.resource.loader.class";
- private static final String VELOCITY_JAR_RESOURCE_LOADER_CLASS = "jar.resource.loader.class";
- private static final String VELOCITY_JAR_RESOURCE_LOADER_PATH = "jar.resource.loader.path";
- private static final String VELOCITY_RESOURCE_LOADER = "resource.loader";
+ private static final String VELOCITY_FILE_RESOURCE_LOADER_PATH = "resource.loader.file.path";
+ private static final String VELOCITY_FILE_RESOURCE_LOADER_CLASS = "resource.loader.jar.path";
+ private static final String VELOCITY_CLASS_RESOURCE_LOADER_CLASS = "resource.loader.class.class";
+ private static final String VELOCITY_JAR_RESOURCE_LOADER_CLASS = "resource.loader.jar.class";
+ private static final String VELOCITY_JAR_RESOURCE_LOADER_PATH = "resource.loader.jar.path";
+ private static final String VELOCITY_RESOURCE_LOADER = "resource.loaders";
private final SitePaths site;
private String pluginName;
@@ -90,7 +91,7 @@
"Cannot find any Jar file in "
+ pluginName
+ " plugin class loader URLs "
- + jarUrls
+ + Arrays.toString(jarUrls)
+ ": unable to initialize Velocity resource loading.");
}
}