Merge branch 'stable-2.11'
* stable-2.11
Do not overwrite HTTP auth configuration settings
NOTE: The change was already in master and cherry-picked to stable-2.11
Merging from stable-2.11 just to update the tracking on Git
Change-Id: Ie972904371e871005ec683ce40439ead673771ab
diff --git a/github-oauth/pom.xml b/github-oauth/pom.xml
index b4e9a2b..e758496 100644
--- a/github-oauth/pom.xml
+++ b/github-oauth/pom.xml
@@ -21,7 +21,7 @@
<parent>
<groupId>com.googlesource.gerrit.plugins.github</groupId>
<artifactId>github-parent</artifactId>
- <version>2.11</version>
+ <version>2.12-SNAPSHOT</version>
</parent>
<artifactId>github-oauth</artifactId>
<name>Gerrit Code Review - GitHub OAuth login</name>
@@ -107,7 +107,7 @@
<dependency>
<groupId>org.kohsuke</groupId>
<artifactId>github-api</artifactId>
- <version>1.62</version>
+ <version>1.68</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
diff --git a/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/GitHubLogin.java b/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/GitHubLogin.java
index 081d6c1..f9afeeb 100644
--- a/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/GitHubLogin.java
+++ b/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/GitHubLogin.java
@@ -136,7 +136,7 @@
}
public GitHub getHub() throws IOException {
- return GitHub.connectUsingOAuth(this.token.accessToken);
+ return GitHub.connectUsingOAuth(config.gitHubApiUrl, token.accessToken);
}
private String getScopesKey(HttpServletRequest request,
diff --git a/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/OAuthWebFilter.java b/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/OAuthWebFilter.java
index 6929d16..6291481 100644
--- a/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/OAuthWebFilter.java
+++ b/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/OAuthWebFilter.java
@@ -26,8 +26,8 @@
import org.slf4j.LoggerFactory;
import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
+import java.nio.file.Files;
+import java.nio.file.attribute.FileTime;
import java.util.Random;
import java.util.Set;
@@ -183,8 +183,8 @@
String user, String access_token) throws IOException,
ConfigInvalidException {
FileBasedConfig currentSecureConfig =
- new FileBasedConfig(sites.secure_config, FS.DETECTED);
- long currentSecureConfigUpdateTs = sites.secure_config.lastModified();
+ new FileBasedConfig(sites.secure_config.toFile(), FS.DETECTED);
+ FileTime currentSecureConfigUpdateTs = Files.getLastModifiedTime(sites.secure_config);
currentSecureConfig.load();
boolean configUpdate =
@@ -202,19 +202,17 @@
log.info("Updating " + sites.secure_config + " credentials for user "
+ user);
- if (sites.secure_config.lastModified() != currentSecureConfigUpdateTs) {
+ FileTime secureConfigCurrentModifiedTime =
+ Files.getLastModifiedTime(sites.secure_config);
+ if (!secureConfigCurrentModifiedTime.equals(currentSecureConfigUpdateTs)) {
throw new ConcurrentFileBasedConfigWriteException("File "
+ sites.secure_config + " was written at "
- + formatTS(sites.secure_config.lastModified())
+ + secureConfigCurrentModifiedTime
+ " while was trying to update security for user " + user);
}
currentSecureConfig.save();
}
- private String formatTS(long ts) {
- return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(ts));
- }
-
private boolean updateConfigSection(FileBasedConfig config, String section,
String user, String password) {
String configUser = config.getString("remote", section, "username");
diff --git a/github-plugin/pom.xml b/github-plugin/pom.xml
index e8a1daa..adb635b 100644
--- a/github-plugin/pom.xml
+++ b/github-plugin/pom.xml
@@ -20,7 +20,7 @@
<parent>
<artifactId>github-parent</artifactId>
<groupId>com.googlesource.gerrit.plugins.github</groupId>
- <version>2.11</version>
+ <version>2.12-SNAPSHOT</version>
</parent>
<artifactId>github-plugin</artifactId>
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/GitHubConfig.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/GitHubConfig.java
index 17c3b9e..44a4b4e 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/GitHubConfig.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/GitHubConfig.java
@@ -26,8 +26,8 @@
import org.eclipse.jgit.lib.Config;
-import java.io.File;
import java.net.MalformedURLException;
+import java.nio.file.Path;
import java.util.HashMap;
@Singleton
@@ -48,7 +48,7 @@
private static final String CONF_PUBLIC_BASE_PROJECT = "publicBaseProject";
private static final String CONF_PRIVATE_BASE_PROJECT = "privateBaseProject";
- public final File gitDir;
+ public final Path gitDir;
public final int jobPoolLimit;
public final int jobExecTimeout;
public final int pullRequestListLimit;
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/GuiceModule.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/GuiceModule.java
index 2b37e5e..0521cef 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/GuiceModule.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/GuiceModule.java
@@ -14,13 +14,17 @@
package com.googlesource.gerrit.plugins.github;
+import com.google.gerrit.common.EventListener;
import com.google.gerrit.extensions.registration.DynamicSet;
+import com.google.gerrit.extensions.restapi.RestApiModule;
import com.google.gerrit.extensions.webui.TopMenu;
import com.google.gerrit.server.account.GroupBackend;
+import com.google.gerrit.server.project.ProjectResource;
+import com.google.gson.Gson;
import com.google.inject.AbstractModule;
+import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
import com.google.inject.assistedinject.FactoryModuleBuilder;
-
import com.googlesource.gerrit.plugins.github.group.GitHubGroupBackend;
import com.googlesource.gerrit.plugins.github.group.GitHubGroupMembership;
import com.googlesource.gerrit.plugins.github.group.GitHubGroupsCache;
@@ -28,6 +32,11 @@
import com.googlesource.gerrit.plugins.github.oauth.GitHubLogin;
import com.googlesource.gerrit.plugins.github.oauth.IdentifiedUserGitHubLoginProvider;
import com.googlesource.gerrit.plugins.github.oauth.UserScopedProvider;
+import com.googlesource.gerrit.plugins.github.replication.GerritGsonProvider;
+import com.googlesource.gerrit.plugins.github.replication.ListProjectReplicationStatus;
+import com.googlesource.gerrit.plugins.github.replication.ReplicationStatusFlatFile;
+import com.googlesource.gerrit.plugins.github.replication.ReplicationStatusListener;
+import com.googlesource.gerrit.plugins.github.replication.ReplicationStatusStore;
public class GuiceModule extends AbstractModule {
@Override
@@ -39,10 +48,23 @@
DynamicSet.bind(binder(), TopMenu.class).to(GitHubTopMenu.class);
DynamicSet.bind(binder(), GroupBackend.class).to(GitHubGroupBackend.class);
+ DynamicSet.bind(binder(), EventListener.class).to(ReplicationStatusListener.class);
install(new FactoryModuleBuilder()
.build(GitHubOrganisationGroup.Factory.class));
install(new FactoryModuleBuilder()
.build(GitHubGroupMembership.Factory.class));
+
+ install(new RestApiModule() {
+ @Override
+ protected void configure() {
+ get(ProjectResource.PROJECT_KIND, "replication").to(
+ ListProjectReplicationStatus.class);
+ }
+ });
+
+ bind(ReplicationStatusStore.class).to(ReplicationStatusFlatFile.class)
+ .in(Scopes.SINGLETON);
+ bind(Gson.class).toProvider(GerritGsonProvider.class);
}
}
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 4b6cfb7..1ca982d 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
@@ -53,7 +53,7 @@
GitDestinationNotWritableException {
super(gitConfig.gitHubUrl, organisation, repository, gitHubRepoFactory);
LOG.debug("GitHub Clone " + organisation + "/" + repository);
- this.gitDir = gitConfig.gitDir;
+ this.gitDir = gitConfig.gitDir.toFile();
this.destinationDirectory =
getDestinationDirectory(organisation, repository);
}
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/PullRequestImportJob.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/PullRequestImportJob.java
index 174de06..9834c2c 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/PullRequestImportJob.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/PullRequestImportJob.java
@@ -177,18 +177,18 @@
walk.markUninteresting(walk.lookupCommit(baseObjectId));
walk.markStart(walk.lookupCommit(prHeadObjectId));
walk.sort(RevSort.REVERSE);
-
+
int patchNr = 1;
for (GHPullRequestCommitDetail ghCommitDetail : pr.listCommits()) {
status.update(Code.SYNC, "Patch #" + patchNr, "Patch#" + patchNr
+ ": Inserting PullRequest into Gerrit");
RevCommit revCommit =
walk.parseCommit(ObjectId.fromString(ghCommitDetail.getSha()));
-
+
GHUser prUser = pr.getUser();
GitUser commitAuthor = ghCommitDetail.getCommit().getAuthor();
GitHubUser gitHubUser = GitHubUser.from(prUser, commitAuthor);
-
+
Account.Id pullRequestOwner = getOrRegisterAccount(db, gitHubUser);
Id changeId =
createChange.addCommitToChange(db, project, gitRepo,
@@ -199,7 +199,7 @@
prChanges.add(changeId);
}
}
-
+
return prChanges;
}
}
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/ReplicationConfig.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/ReplicationConfig.java
index 1784e0e..60e8502 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/ReplicationConfig.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/ReplicationConfig.java
@@ -35,9 +35,9 @@
@Inject
public ReplicationConfig(final SitePaths site) {
replicationConf =
- new FileBasedConfig(new File(site.etc_dir, "replication.config"),
+ new FileBasedConfig(new File(site.etc_dir.toFile(), "replication.config"),
FS.DETECTED);
- secureConf = new FileBasedConfig(site.secure_config, FS.DETECTED);
+ secureConf = new FileBasedConfig(site.secure_config.toFile(), FS.DETECTED);
}
public synchronized void addSecureCredentials(String organisation,
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/GerritGsonProvider.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/GerritGsonProvider.java
new file mode 100644
index 0000000..c4334be
--- /dev/null
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/GerritGsonProvider.java
@@ -0,0 +1,30 @@
+// Copyright (C) 2013 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.googlesource.gerrit.plugins.github.replication;
+
+import com.google.gerrit.server.OutputFormat;
+import com.google.gson.Gson;
+import com.google.inject.Provider;
+import com.google.inject.Singleton;
+
+@Singleton
+public class GerritGsonProvider implements Provider<Gson> {
+ private final Gson gerritStyleGson = OutputFormat.JSON_COMPACT.newGson();
+
+ @Override
+ public Gson get() {
+ return gerritStyleGson;
+ }
+}
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/GitHubDestinations.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/GitHubDestinations.java
index e383fe1..ab8fa24 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/GitHubDestinations.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/GitHubDestinations.java
@@ -34,9 +34,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -79,7 +80,7 @@
replicationUserFactory = ruf;
gitRepositoryManager = grm;
groupBackend = gb;
- configs = getDestinations(new File(site.etc_dir, "replication.config"));
+ configs = getDestinations(site.etc_dir.resolve("replication.config"));
organisations = getOrganisations(configs);
}
@@ -94,13 +95,13 @@
return organisations;
}
- private List<Destination> getDestinations(File cfgPath)
+ private List<Destination> getDestinations(Path cfgPath)
throws ConfigInvalidException, IOException {
- FileBasedConfig cfg = new FileBasedConfig(cfgPath, FS.DETECTED);
- if (!cfg.getFile().exists() || cfg.getFile().length() == 0) {
+ if (!Files.exists(cfgPath) || Files.size(cfgPath) == 0) {
return Collections.emptyList();
- }
-
+ }
+
+ FileBasedConfig cfg = new FileBasedConfig(cfgPath.toFile(), FS.DETECTED);
try {
cfg.load();
} catch (ConfigInvalidException e) {
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/ListProjectReplicationStatus.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/ListProjectReplicationStatus.java
new file mode 100644
index 0000000..868ac5b
--- /dev/null
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/ListProjectReplicationStatus.java
@@ -0,0 +1,37 @@
+// Copyright (C) 2013 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.googlesource.gerrit.plugins.github.replication;
+
+import com.google.gerrit.extensions.restapi.AuthException;
+import com.google.gerrit.extensions.restapi.BadRequestException;
+import com.google.gerrit.extensions.restapi.ResourceConflictException;
+import com.google.gerrit.extensions.restapi.RestReadView;
+import com.google.gerrit.server.project.ProjectResource;
+import com.google.inject.Inject;
+
+public class ListProjectReplicationStatus implements RestReadView<ProjectResource> {
+ private final ReplicationStatusStore statusStore;
+
+ @Inject
+ public ListProjectReplicationStatus(ReplicationStatusStore statusStore) {
+ this.statusStore = statusStore;
+ }
+
+ @Override
+ public Object apply(ProjectResource resource) throws AuthException,
+ BadRequestException, ResourceConflictException, Exception {
+ return statusStore.list(resource.getNameKey());
+ }
+}
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/ReplicationStatusFlatFile.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/ReplicationStatusFlatFile.java
new file mode 100644
index 0000000..4d5a033
--- /dev/null
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/ReplicationStatusFlatFile.java
@@ -0,0 +1,91 @@
+// Copyright (C) 2015 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.googlesource.gerrit.plugins.github.replication;
+
+import static java.nio.file.StandardOpenOption.CREATE;
+import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
+import static java.nio.file.StandardOpenOption.WRITE;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.google.gerrit.extensions.annotations.PluginData;
+import com.google.gerrit.reviewdb.client.Project;
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+
+public class ReplicationStatusFlatFile implements ReplicationStatusStore {
+ private final Path pluginData;
+ private final Gson gson;
+
+ @Inject
+ public ReplicationStatusFlatFile(@PluginData Path pluginData,
+ Provider<Gson> gsonProvider) {
+ this.pluginData = pluginData;
+ this.gson = gsonProvider.get();
+ }
+
+ @Override
+ public void set(Project.NameKey projectKey, String refKey,
+ JsonObject statusEvent) throws IOException {
+ Path replicationStatusPath =
+ getReplicationStatusPath(projectKey.get() + "/" + refKey);
+ Files.write(replicationStatusPath, statusEvent.toString().getBytes(),
+ TRUNCATE_EXISTING, CREATE, WRITE);
+ }
+
+ private Path getReplicationStatusPath(String key) throws IOException {
+ Path projectPath =
+ pluginData.resolve(getSanitizedKey(key) + ".replication-error.json");
+ Files.createDirectories(projectPath.getParent());
+ return projectPath;
+ }
+
+ private String getSanitizedKey(String key) {
+ String sanitizedKey = key.replace(".", "_").replace(" ", "_");
+ return sanitizedKey;
+ }
+
+ @Override
+ public List<JsonObject> list(Project.NameKey parentKey) throws IOException {
+ Path projectPath = pluginData.resolve(getSanitizedKey(parentKey.get()));
+ final List<JsonObject> entries = new ArrayList<>();
+ Files.walkFileTree(projectPath, new SimpleFileVisitor<Path>() {
+
+ @Override
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
+ throws IOException {
+ try (Reader fileReader =
+ Files.newBufferedReader(file, StandardCharsets.UTF_8)) {
+ JsonObject json = gson.fromJson(fileReader, JsonObject.class);
+ entries.add(json);
+ }
+ return FileVisitResult.CONTINUE;
+ }
+ });
+ return entries;
+ }
+
+}
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/ReplicationStatusListener.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/ReplicationStatusListener.java
new file mode 100644
index 0000000..49358a9
--- /dev/null
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/ReplicationStatusListener.java
@@ -0,0 +1,65 @@
+// Copyright (C) 2015 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.googlesource.gerrit.plugins.github.replication;
+
+import java.io.IOException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gerrit.common.EventListener;
+import com.google.gerrit.reviewdb.client.Project.NameKey;
+import com.google.gerrit.server.events.Event;
+import com.google.gerrit.server.events.RefEvent;
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.google.inject.Singleton;
+
+@Singleton
+public class ReplicationStatusListener implements EventListener {
+ private static final String REF_REPLICATED_EVENT = "ref-replicated";
+ private static Logger log = LoggerFactory
+ .getLogger(ReplicationStatusListener.class);
+
+ private final ReplicationStatusStore statusStore;
+ private final Gson gson;
+
+ @Inject
+ public ReplicationStatusListener(ReplicationStatusStore statusStore,
+ Provider<Gson> gsonProvider) {
+ this.statusStore = statusStore;
+ this.gson = gsonProvider.get();
+ }
+
+ @Override
+ public void onEvent(Event event) {
+ if (RefEvent.class.isAssignableFrom(event.getClass())
+ && event.getType().equals(REF_REPLICATED_EVENT)) {
+ RefEvent refEvent = (RefEvent) event;
+ NameKey projectNameKey = refEvent.getProjectNameKey();
+ JsonObject eventJson = (JsonObject) gson.toJsonTree(event);
+ String refKey = eventJson.get("ref").getAsString();
+
+ try {
+ statusStore.set(projectNameKey, refKey, eventJson);
+ } catch (IOException e) {
+ log.error("Unable to update replication status for event " + eventJson
+ + " on project " + projectNameKey, e);
+ }
+ }
+ }
+}
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/ReplicationStatusStore.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/ReplicationStatusStore.java
new file mode 100644
index 0000000..75c1872
--- /dev/null
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/replication/ReplicationStatusStore.java
@@ -0,0 +1,29 @@
+// Copyright (C) 2015 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.googlesource.gerrit.plugins.github.replication;
+
+import java.io.IOException;
+import java.util.List;
+
+import com.google.gerrit.reviewdb.client.Project;
+import com.google.gson.JsonObject;
+
+public interface ReplicationStatusStore {
+
+ public void set(Project.NameKey projectKey, String refKey,
+ JsonObject statusEvent) throws IOException;
+
+ public List<JsonObject> list(Project.NameKey projectKey) throws IOException;
+}
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 57b4780..431a438 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
@@ -26,7 +26,6 @@
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
import org.apache.velocity.runtime.resource.loader.JarResourceLoader;
-import java.io.File;
import java.util.Properties;
@Singleton
@@ -65,13 +64,14 @@
p.setProperty(VELOCITY_FILE_RESOURCE_LOADER_CLASS, pkg
+ ".FileResourceLoader");
p.setProperty(VELOCITY_FILE_RESOURCE_LOADER_PATH,
- new File(site.static_dir.getAbsolutePath(), "..").getAbsolutePath());
+ site.static_dir.getParent().toAbsolutePath().toString());
p.setProperty(VELOCITY_CLASS_RESOURCE_LOADER_CLASS,
ClasspathResourceLoader.class.getName());
p.setProperty(VELOCITY_JAR_RESOURCE_LOADER_CLASS,
JarResourceLoader.class.getName());
p.setProperty(VELOCITY_JAR_RESOURCE_LOADER_PATH, "jar:file:"
- + new File(site.plugins_dir, pluginName + ".jar").getAbsolutePath());
+ + site.plugins_dir.resolve(pluginName + ".jar").toAbsolutePath()
+ .toString());
RuntimeInstance ri = new RuntimeInstance();
try {
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/velocity/VelocityViewServlet.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/velocity/VelocityViewServlet.java
index cd1a202..75e3c47 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/velocity/VelocityViewServlet.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/velocity/VelocityViewServlet.java
@@ -19,8 +19,6 @@
import com.google.inject.Provider;
import com.google.inject.Singleton;
import com.google.inject.name.Named;
-
-import com.googlesource.gerrit.plugins.github.GitHubConfig.NextPage;
import com.googlesource.gerrit.plugins.github.oauth.GitHubLogin;
import com.googlesource.gerrit.plugins.github.oauth.ScopedProvider;
@@ -47,7 +45,7 @@
public class VelocityViewServlet extends HttpServlet {
private static final Logger log = LoggerFactory
.getLogger(VelocityViewServlet.class);
- private static final String STATIC_PREFIX = "/static";
+ private static final String STATIC_PREFIX = "/static/";
private static final long serialVersionUID = 529071287765413268L;
private final RuntimeInstance velocityRuntime;
private final Provider<PluginVelocityModel> modelProvider;
@@ -73,16 +71,11 @@
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse resp = (HttpServletResponse) response;
- String servletPath = req.getPathInfo();
- NextPage nextPage = (NextPage) req.getAttribute("destUrl");
- String destUrl = null;
- if (nextPage != null && !nextPage.uri.startsWith("/")) {
- destUrl =
- servletPath.substring(0, servletPath.lastIndexOf("/")) + "/"
- + nextPage.uri;
- }
-
- String pathInfo = STATIC_PREFIX + MoreObjects.firstNonNull(destUrl, servletPath);
+ String pathInfo =
+ STATIC_PREFIX
+ + MoreObjects.firstNonNull(
+ (String) req.getAttribute("destUrl"),
+ req.getPathInfo());
try {
Template template = velocityRuntime.getTemplate(pathInfo, "UTF-8");
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/RepositoriesListController.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/RepositoriesListController.java
index 45198ab..87cc52e 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/RepositoriesListController.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/RepositoriesListController.java
@@ -30,6 +30,8 @@
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.PagedIterable;
import org.kohsuke.github.PagedIterator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.IOException;
@@ -39,6 +41,7 @@
@Singleton
public class RepositoriesListController implements VelocityController {
+ private static final Logger log = LoggerFactory.getLogger(RepositoriesListController.class);
private final ProjectCache projects;
private final GitHubConfig config;
@@ -63,18 +66,24 @@
while (repoIter.hasNext() && numRepos < config.repositoryListLimit) {
GHRepository ghRepository = repoIter.next();
- JsonObject repository = new JsonObject();
- String projectName = organisation + "/" + ghRepository.getName();
- if (projects.get(Project.NameKey.parse(projectName)) == null) {
- repository.add("name", new JsonPrimitive(ghRepository.getName()));
- repository.add("organisation", new JsonPrimitive(organisation));
- repository.add(
- "description",
- new JsonPrimitive(
- Strings.nullToEmpty(ghRepository.getDescription())));
- repository.add("private", new JsonPrimitive(ghRepository.isPrivate()));
- jsonRepos.add(repository);
- numRepos++;
+ if (ghRepository.hasPushAccess() && ghRepository.hasPullAccess()) {
+ JsonObject repository = new JsonObject();
+ String projectName = organisation + "/" + ghRepository.getName();
+ if (projects.get(Project.NameKey.parse(projectName)) == null) {
+ repository.add("name", new JsonPrimitive(ghRepository.getName()));
+ repository.add("organisation", new JsonPrimitive(organisation));
+ repository.add(
+ "description",
+ new JsonPrimitive(Strings.nullToEmpty(ghRepository
+ .getDescription())));
+ repository
+ .add("private", new JsonPrimitive(ghRepository.isPrivate()));
+ jsonRepos.add(repository);
+ numRepos++;
+ }
+ } else {
+ log.warn("Skipping repository {} because user {} has no push/pull access to it",
+ ghRepository.getName(), user.getUserName());
}
}
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/VelocityControllerServlet.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/VelocityControllerServlet.java
index 1d7b65e..561fbd0 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/VelocityControllerServlet.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/wizard/VelocityControllerServlet.java
@@ -122,7 +122,7 @@
private void redirectToNextStep(HttpServletRequest req,
HttpServletResponse resp) throws IOException, ServletException {
- String sourceUri = req.getRequestURI();
+ String sourceUri = req.getPathInfo();
int pathPos = sourceUri.lastIndexOf('/') + 1;
String sourcePage = sourceUri.substring(pathPos);
String sourcePath = sourceUri.substring(0, pathPos);
@@ -137,7 +137,7 @@
} else {
RequestDispatcher requestDispatcher =
req.getRequestDispatcher(nextPageURL(sourcePath, nextPage));
- req.setAttribute("destUrl", nextPage);
+ req.setAttribute("destUrl", nextPage.uri);
requestDispatcher.forward(req, resp);
}
}
diff --git a/pom.xml b/pom.xml
index 575be55..05bb64c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -18,7 +18,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlesource.gerrit.plugins.github</groupId>
<artifactId>github-parent</artifactId>
- <version>2.11</version>
+ <version>2.12-SNAPSHOT</version>
<name>Gerrit Code Review - GitHub integration</name>
<url>http://www.gerritforge.com</url>
<packaging>pom</packaging>
@@ -292,7 +292,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
- <version>1.14.0</version>
+ <version>1.16.2</version>
<scope>provided</scope>
</dependency>
</dependencies>