diff options
Diffstat (limited to 'org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit')
10 files changed, 353 insertions, 6 deletions
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/GerritUtil.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/GerritUtil.java index 296de8550..828b52282 100644 --- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/GerritUtil.java +++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/GerritUtil.java @@ -20,7 +20,9 @@ import java.util.Set; import org.apache.commons.lang.StringUtils; import org.eclipse.core.runtime.Assert; import org.eclipse.mylyn.internal.gerrit.core.client.GerritConfiguration; +import org.eclipse.mylyn.internal.gerrit.core.client.compat.DownloadSchemeX; import org.eclipse.mylyn.internal.gerrit.core.client.compat.ProjectDetailX; +import org.eclipse.mylyn.internal.gerrit.core.client.compat.SchemeInfo; import org.eclipse.mylyn.tasks.core.TaskRepository; import org.eclipse.osgi.util.NLS; @@ -89,6 +91,11 @@ public class GerritUtil { public static String getSshCloneUri(TaskRepository repository, GerritConfiguration config, Project project) throws URISyntaxException { + + if (supportsDownloadScheme(config, DownloadSchemeX.SSH)) { + return getSchemeUri(config, DownloadSchemeX.SSH, project); + } + Set<DownloadScheme> supportedDownloadSchemes = config.getGerritConfig().getDownloadSchemes(); if (supportedDownloadSchemes.contains(DownloadScheme.SSH) || supportedDownloadSchemes.contains(DownloadScheme.DEFAULT_DOWNLOADS)) { @@ -120,6 +127,10 @@ public class GerritUtil { } public static String getHttpCloneUri(TaskRepository repository, GerritConfiguration config, Project project) { + if (supportsDownloadScheme(config, DownloadSchemeX.HTTP)) { + return getSchemeUri(config, DownloadSchemeX.HTTP, project); + } + Set<DownloadScheme> supportedDownloadSchemes = config.getGerritConfig().getDownloadSchemes(); if (supportedDownloadSchemes.contains(DownloadScheme.HTTP) || supportedDownloadSchemes.contains(DownloadScheme.DEFAULT_DOWNLOADS)) { @@ -153,6 +164,10 @@ public class GerritUtil { } public static String getAnonHttpCloneUri(TaskRepository repository, GerritConfiguration config, Project project) { + if (supportsDownloadScheme(config, DownloadSchemeX.ANON_HTTP)) { + return getSchemeUri(config, DownloadSchemeX.ANON_HTTP, project); + } + Set<DownloadScheme> supportedDownloadSchemes = config.getGerritConfig().getDownloadSchemes(); if (supportedDownloadSchemes.contains(DownloadScheme.ANON_HTTP) || supportedDownloadSchemes.contains(DownloadScheme.DEFAULT_DOWNLOADS)) { @@ -176,10 +191,14 @@ public class GerritUtil { } public static String getAnonGitCloneUri(TaskRepository repository, GerritConfiguration config, Project project) { + if (supportsDownloadScheme(config, DownloadSchemeX.GIT)) { + return getSchemeUri(config, DownloadSchemeX.GIT, project); + } + Set<DownloadScheme> supportedDownloadSchemes = config.getGerritConfig().getDownloadSchemes(); String gitAddress = config.getGerritConfig().getGitDaemonUrl(); - if (gitAddress != null - && (supportedDownloadSchemes.contains(DownloadScheme.ANON_GIT) || supportedDownloadSchemes.contains(DownloadScheme.DEFAULT_DOWNLOADS))) { + if (gitAddress != null && (supportedDownloadSchemes.contains(DownloadScheme.ANON_GIT) + || supportedDownloadSchemes.contains(DownloadScheme.DEFAULT_DOWNLOADS))) { final StringBuilder sb = new StringBuilder(); sb.append(gitAddress); if (!gitAddress.endsWith("/")) { //$NON-NLS-1$ @@ -213,4 +232,17 @@ public class GerritUtil { return id; } + private static boolean supportsDownloadScheme(GerritConfiguration config, DownloadSchemeX scheme) { + return config.getGerritConfig().getSchemes() != null + && config.getGerritConfig().getSchemes().containsKey(scheme); + } + + private static String getSchemeUri(GerritConfiguration config, DownloadSchemeX scheme, Project project) { + SchemeInfo info = config.getGerritConfig().getSchemes().get(scheme); + return info != null ? forProject(info.getUrl(), project) : null; + } + + public static String forProject(String url, Project project) { + return url.replaceAll("\\$\\{project\\}", project.getName()); //$NON-NLS-1$ + } } diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java index 84311fe0b..cfb3c17f1 100644 --- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java +++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java @@ -187,14 +187,14 @@ public abstract class GerritClient extends ReviewsClient { GerritConfiguration config, GerritAuthenticationState authState, String xsrfKey, GerritClientStateListener stateListener) { Version version = Version.emptyVersion; - GerritClient versionDiscoveryClient = new GerritClient29(repository, version); + GerritClient versionDiscoveryClient = new GerritClient212(repository, version); versionDiscoveryClient.initialize(location, config, authState, xsrfKey, stateListener); try { version = versionDiscoveryClient.getVersion(new NullProgressMonitor()); } catch (GerritException e) { //Ignore, we'll just use the base client. } - GerritClient client = new GerritClient29(repository, version); + GerritClient client = new GerritClient212(repository, version); client.initialize(location, config, authState, xsrfKey, stateListener); return client; } @@ -226,7 +226,7 @@ public abstract class GerritClient extends ReviewsClient { } this.serviceByClass = new HashMap<Class<? extends RemoteJsonService>, RemoteJsonService>(); this.config = config; - this.restClient = new GerritRestClient(this.client); + this.restClient = new GerritRestClient(client); } public GerritSystemInfo getInfo(IProgressMonitor monitor) throws GerritException { @@ -298,7 +298,7 @@ public abstract class GerritClient extends ReviewsClient { if (gerritConfig == null) { if (GerritVersion.isVersion2120OrLater(version)) { - gerritConfig = new GerritConfigX(); + gerritConfig = getGerritConfigFromServerInfo(monitor); } else { throw new GerritException("Failed to obtain Gerrit configuration"); //$NON-NLS-1$ } @@ -315,6 +315,10 @@ public abstract class GerritClient extends ReviewsClient { } } + protected GerritConfigX getGerritConfigFromServerInfo(IProgressMonitor monitor) throws GerritException { + return new GerritConfigX(); + } + public GerritConfiguration refreshConfig(IProgressMonitor monitor) throws GerritException { refreshAllCachedProjectBranches(monitor); configRefreshed = true; diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient212.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient212.java new file mode 100644 index 000000000..233a4592d --- /dev/null +++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient212.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2018 Tasktop Technologies and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.gerrit.core.client; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.mylyn.internal.gerrit.core.client.compat.DownloadSchemeX; +import org.eclipse.mylyn.internal.gerrit.core.client.compat.GerritConfigX; +import org.eclipse.mylyn.internal.gerrit.core.client.compat.SchemeInfo; +import org.eclipse.mylyn.internal.gerrit.core.client.rest.DownloadSchemeInfo; +import org.eclipse.mylyn.internal.gerrit.core.client.rest.ServerInfo; +import org.eclipse.mylyn.tasks.core.TaskRepository; +import org.osgi.framework.Version; + +import com.google.gerrit.reviewdb.Project.NameKey; + +public class GerritClient212 extends GerritClient29 { + + protected GerritClient212(TaskRepository repository, Version version) { + super(repository, version); + } + + @Override + protected GerritConfigX getGerritConfigFromServerInfo(IProgressMonitor monitor) throws GerritException { + String query = "/config/server/info"; //$NON-NLS-1$/ + org.eclipse.mylyn.internal.gerrit.core.client.rest.ServerInfo serverInfo = getRestClient() + .executeGetRestRequest(query, org.eclipse.mylyn.internal.gerrit.core.client.rest.ServerInfo.class, + monitor); + + return convertServerInfoToGerritConfig(serverInfo); + } + + private GerritConfigX convertServerInfoToGerritConfig(ServerInfo serverInfo) { + GerritConfigX config = new GerritConfigX(); + + // gerrit/all_projects + user -> wildproject + config.setWildProject(new NameKey(serverInfo.getGerrit().getRootProject())); + + // download/schemes -> getGerritConfig().getDownloadSchemes + Map<DownloadSchemeX, SchemeInfo> schemes = new HashMap<>(); + + serverInfo.getDownload().getSchemes().entrySet().forEach(entry -> { + DownloadSchemeX scheme = DownloadSchemeX.fromString(entry.getKey()); + if (scheme != null) { + DownloadSchemeInfo info = entry.getValue(); + SchemeInfo schemeInfo = new SchemeInfo(info.getUrl(), info.isAuthRequired(), info.isAuthSupported(), + info.getCommands(), info.getCloneCommands()); + + schemes.put(scheme, schemeInfo); + } + }); + + config.setSchemes(schemes); + + return config; + } +} diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/compat/DownloadSchemeX.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/compat/DownloadSchemeX.java new file mode 100644 index 000000000..153ab508e --- /dev/null +++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/compat/DownloadSchemeX.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2018 Tasktop Technologies and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.gerrit.core.client.compat; + +public enum DownloadSchemeX { + ANON_HTTP("anonymous http"), HTTP("http"), GIT("git"), SSH("ssh"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + private String scheme; + + private DownloadSchemeX(String scheme) { + this.scheme = scheme; + } + + @Override + public String toString() { + return scheme; + } + + public static DownloadSchemeX fromString(String scheme) { + for (DownloadSchemeX value : values()) { + if (value.toString().equals(scheme)) { + return value; + } + } + return null; + } +} diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/compat/GerritConfigX.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/compat/GerritConfigX.java index d6346f99e..dd06d1604 100644 --- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/compat/GerritConfigX.java +++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/compat/GerritConfigX.java @@ -12,7 +12,9 @@ package org.eclipse.mylyn.internal.gerrit.core.client.compat; +import java.util.Collections; import java.util.List; +import java.util.Map; import com.google.gerrit.common.data.GerritConfig; @@ -26,6 +28,16 @@ public class GerritConfigX extends GerritConfig { private String gitHttpUrl; + private Map<DownloadSchemeX, SchemeInfo> schemes; + + public Map<DownloadSchemeX, SchemeInfo> getSchemes() { + return schemes; + } + + public void setSchemes(Map<DownloadSchemeX, SchemeInfo> schemes) { + this.schemes = Collections.unmodifiableMap(schemes); + } + public List<CommentLink> getCommentLinks2() { return commentLinks; } diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/compat/SchemeInfo.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/compat/SchemeInfo.java new file mode 100644 index 000000000..af62fbed7 --- /dev/null +++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/compat/SchemeInfo.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2018 Tasktop Technologies and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.gerrit.core.client.compat; + +import java.util.Collections; +import java.util.Map; + +public class SchemeInfo { + private final String url; + + private final boolean authRequired; + + private final boolean authSupported; + + private final Map<String, String> commands; + + private final Map<String, String> cloneCommands; + + public SchemeInfo(String url, boolean authRequired, boolean authSupported, Map<String, String> commands, + Map<String, String> cloneCommands) { + this.url = url; + this.authRequired = authRequired; + this.authSupported = authSupported; + this.commands = Collections.unmodifiableMap(commands); + this.cloneCommands = Collections.unmodifiableMap(cloneCommands); + } + + public String getUrl() { + return url; + } + + public boolean isAuthRequired() { + return authRequired; + } + + public boolean isAuthSupported() { + return authSupported; + } + + public Map<String, String> getCommands() { + return commands; + } + + public Map<String, String> getCloneCommands() { + return cloneCommands; + } +} diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/DownloadInfo.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/DownloadInfo.java new file mode 100644 index 000000000..5bab7e8ce --- /dev/null +++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/DownloadInfo.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2018 Tasktop Technologies and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.gerrit.core.client.rest; + +import java.util.Map; + +/** + * Data model object for + * <a href="https://gerrit-review.googlesource.com/Documentation/rest-api-config.html#download-info">DownloadInfo</a>. + * + * @since 2.12 + */ +public class DownloadInfo { + Map<String, DownloadSchemeInfo> schemes; + + public Map<String, DownloadSchemeInfo> getSchemes() { + return schemes; + } +} diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/DownloadSchemeInfo.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/DownloadSchemeInfo.java new file mode 100644 index 000000000..1f3ff685f --- /dev/null +++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/DownloadSchemeInfo.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2018 Tasktop Technologies and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.gerrit.core.client.rest; + +import java.util.Map; + +/** + * Data model object for <a href= + * "https://gerrit-review.googlesource.com/Documentation/rest-api-config.html#download-scheme-info">DownloadSchemeInfo</a>. + * + * @since 2.12 + */ +public class DownloadSchemeInfo { + private String url; + + private boolean is_auth_required; + + private boolean is_auth_supported; + + private Map<String, String> commands; + + private Map<String, String> clone_commands; + + public String getUrl() { + return url; + } + + public boolean isAuthRequired() { + return is_auth_required; + } + + public boolean isAuthSupported() { + return is_auth_supported; + } + + public Map<String, String> getCommands() { + return commands; + } + + public Map<String, String> getCloneCommands() { + return clone_commands; + } +} diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/GerritInfo.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/GerritInfo.java new file mode 100644 index 000000000..6c0170658 --- /dev/null +++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/GerritInfo.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2018 Tasktop Technologies and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.gerrit.core.client.rest; + +/** + * Data model object for + * <a href="https://gerrit-review.googlesource.com/Documentation/rest-api-config.html#gerrit-info">GerritInfo</a>. + * + * @since 2.12 + */ +public class GerritInfo { + private String all_projects_name; + + private String all_projects; + + public String getRootProject() { + return all_projects == null ? all_projects_name : all_projects; + } +} diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ServerInfo.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ServerInfo.java new file mode 100644 index 000000000..ae27692e9 --- /dev/null +++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ServerInfo.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2018 Tasktop Technologies and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.internal.gerrit.core.client.rest; + +/** + * Data model object for + * <a href="https://gerrit-review.googlesource.com/Documentation/rest-api-config.html#server-info">ServerInfo</a>. + * + * @since 2.12 + */ +public class ServerInfo { + private GerritInfo gerrit; + + private DownloadInfo download; + + public GerritInfo getGerrit() { + return gerrit; + } + + public DownloadInfo getDownload() { + return download; + } +} |