summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorTomasz Zarna2011-12-01 08:47:52 (EST)
committer Matthias Sohn2011-12-01 08:47:52 (EST)
commit199adc61d412c5eb13088b741a673de5debd2335 (patch)
tree1a0da02d0684aa596a1a33e42beb686b153b2370
parentabd4106f8de2f72d32c81d6e76355aa20ca4e175 (diff)
downloadegit-199adc61d412c5eb13088b741a673de5debd2335.zip
egit-199adc61d412c5eb13088b741a673de5debd2335.tar.gz
egit-199adc61d412c5eb13088b741a673de5debd2335.tar.bz2
Allow GitProjectSetCapability to accept SCM URIs refs/changes/18/4618/5
Bug: 356448 Change-Id: I04bcf212469f4a9422fd7eb839f874f55cf3f92c Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitURITest.java108
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/CoreText.java6
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/GitProjectSetCapability.java14
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/coretext.properties3
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/internal/GitURI.java121
5 files changed, 252 insertions, 0 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitURITest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitURITest.java
new file mode 100644
index 0000000..df1ff3b
--- /dev/null
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitURITest.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (c) 2011, IBM Corporation
+ *
+ * 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:
+ * Tomasz Zarna (IBM) - initial implementation
+ *******************************************************************************/
+package org.eclipse.egit.core.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.net.URI;
+
+import org.eclipse.egit.core.GitProjectSetCapability;
+import org.eclipse.egit.core.internal.GitURI;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.transport.URIish;
+import org.eclipse.team.core.ScmUrlImportDescription;
+import org.junit.Before;
+import org.junit.Test;
+
+public class GitURITest {
+
+ private GitProjectSetCapability capability;
+
+ @Before
+ public void setUp() {
+ capability = new GitProjectSetCapability();
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInvalidScmUriWithQuotationMarks() throws Exception {
+ URI.create("scm:git:git://git.eclipse.org/gitroot/platform/eclipse.platform.team.git;path=\"bundles/org.eclipse.team.core\"");
+ // expected IAE, " are not allowed in a URI reference
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInvalidScmUriForCVS() throws Exception {
+ new GitURI(URI.create("scm:cvs:pserver:dev.eclipse.org:/cvsroot/eclipse:org.eclipse.compare"));
+ // expected IAE, it's a CVS SCM URL
+ }
+
+ // ScmUrlImportDescription can handle " in Strings expected to be URI refs
+ @Test
+ public void testScmUriWithPath() throws Exception {
+ ScmUrlImportDescription description = new ScmUrlImportDescription(
+ "scm:git:git://git.eclipse.org/gitroot/platform/eclipse.platform.team.git;path=\"bundles/org.eclipse.team.core\"",
+ null);
+ URI uri = description.getUri();
+ GitURI gitUri = new GitURI(uri);
+ assertEquals("bundles/org.eclipse.team.core", gitUri.getPath()
+ .toString());
+ URIish uriish = new URIish(
+ "git://git.eclipse.org/gitroot/platform/eclipse.platform.team.git");
+ assertEquals(uriish, gitUri.getRepository());
+ assertEquals(Constants.MASTER, gitUri.getTag());
+
+ String refString = capability.asReference(uri, "org.eclipse.team.core");
+ assertEquals(
+ "1.0,git://git.eclipse.org/gitroot/platform/eclipse.platform.team.git,master,bundles/org.eclipse.team.core",
+ refString);
+ }
+
+ @Test
+ public void testScmUriWithPathAndTag() throws Exception {
+ ScmUrlImportDescription description = new ScmUrlImportDescription(
+ "scm:git:git://git.eclipse.org/gitroot/platform/eclipse.platform.ui.git;path=\"bundles/org.eclipse.jface\";tag=v20111107-2125",
+ null);
+ URI uri = description.getUri();
+ GitURI gitUri = new GitURI(uri);
+ assertEquals("bundles/org.eclipse.jface", gitUri.getPath().toString());
+ URIish uriish = new URIish(
+ "git://git.eclipse.org/gitroot/platform/eclipse.platform.ui.git");
+ assertEquals(uriish, gitUri.getRepository());
+ assertEquals("v20111107-2125", gitUri.getTag());
+
+ String refString = capability.asReference(uri, "org.eclipse.jface");
+ assertEquals(
+ "1.0,git://git.eclipse.org/gitroot/platform/eclipse.platform.ui.git,v20111107-2125,bundles/org.eclipse.jface",
+ refString);
+ }
+
+ @Test
+ public void testScmUriWithPathProjectAndTag() throws Exception {
+ ScmUrlImportDescription description = new ScmUrlImportDescription(
+ "scm:git:git://git.eclipse.org/gitroot/equinox/rt.equinox.bundles.git;path=\"bundles/org.eclipse.equinox.http.jetty6\";project=\"org.eclipse.equinox.http.jetty\";tag=v20111010-1614",
+ null);
+ URI uri = description.getUri();
+ GitURI gitUri = new GitURI(uri);
+ assertEquals("bundles/org.eclipse.equinox.http.jetty6", gitUri
+ .getPath().toString());
+ URIish uriish = new URIish(
+ "git://git.eclipse.org/gitroot/equinox/rt.equinox.bundles.git");
+ assertEquals(uriish, gitUri.getRepository());
+ assertEquals("v20111010-1614", gitUri.getTag());
+ assertEquals("org.eclipse.equinox.http.jetty", gitUri.getProjectName());
+
+ String refString = capability.asReference(uri,
+ "org.eclipse.equinox.http.jetty");
+ assertEquals(
+ "1.0,git://git.eclipse.org/gitroot/equinox/rt.equinox.bundles.git,v20111010-1614,bundles/org.eclipse.equinox.http.jetty6",
+ refString);
+ }
+}
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/CoreText.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/CoreText.java
index 67ffe52..87ed6b7 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/CoreText.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/CoreText.java
@@ -350,6 +350,12 @@ public class CoreText extends NLS {
/** */
public static String GitRemoteFolder_fetchingMembers;
+ /** */
+ public static String GitURI_InvalidSCMURL;
+
+ /** */
+ public static String GitURI_InvalidURI;
+
static {
initializeMessages(BUNDLE_NAME, CoreText.class);
}
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/GitProjectSetCapability.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/GitProjectSetCapability.java
index c7300e0..7026335 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/GitProjectSetCapability.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/GitProjectSetCapability.java
@@ -9,12 +9,14 @@
*
* Contributors:
* Manuel Doninger <manuel.doninger@googlemail.com>
+ * Tomasz Zarna <Tomasz.Zarna@pl.ibm.com>
*******************************************************************************/
package org.eclipse.egit.core;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
+import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
@@ -24,6 +26,7 @@ import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;
+
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IWorkspace;
@@ -33,6 +36,7 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.egit.core.internal.GitURI;
import org.eclipse.egit.core.op.CloneOperation;
import org.eclipse.egit.core.op.ConnectProviderOperation;
import org.eclipse.egit.core.project.RepositoryMapping;
@@ -87,6 +91,10 @@ public final class GitProjectSetCapability extends ProjectSetCapability {
if (projectPath.equals("")) //$NON-NLS-1$
projectPath = "."; //$NON-NLS-1$
+ return asReference(url, branch, projectPath);
+ }
+
+ private String asReference(String url, String branch, String projectPath) {
StringBuilder sb = new StringBuilder();
sb.append(VERSION);
@@ -207,6 +215,12 @@ public final class GitProjectSetCapability extends ProjectSetCapability {
return result;
}
+ @Override
+ public String asReference(URI uri, String projectName) {
+ GitURI gitURI = new GitURI(uri);
+ return asReference(gitURI.getRepository().toString(), gitURI.getTag(), gitURI.getPath().toString());
+ }
+
private TeamException throwTeamException(Throwable th) throws TeamException{
Throwable current = th;
while(current.getCause()!=null){
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/coretext.properties b/org.eclipse.egit.core/src/org/eclipse/egit/core/coretext.properties
index 54c3b88..aac0e25 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/coretext.properties
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/coretext.properties
@@ -146,3 +146,6 @@ GitResourceVariantTreeSubscriber_fetchTaskName=Fetching data from git repositori
GitSyncObjectCache_noData=Cache doesn''t contain data for key: {0}
GitRemoteFolder_fetchingMembers=Fetching members of {0}
+
+GitURI_InvalidSCMURL=Invalid SCM URL {0}
+GitURI_InvalidURI=Invalid uri {0}: {1}
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/GitURI.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/GitURI.java
new file mode 100644
index 0000000..7459edb
--- /dev/null
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/GitURI.java
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * Copyright (c) 2011, IBM Corporation
+ *
+ * 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:
+ * Tomasz Zarna (IBM) - initial implementation
+ *******************************************************************************/
+package org.eclipse.egit.core.internal;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.egit.core.Activator;
+import org.eclipse.egit.core.CoreText;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.transport.URIish;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.team.core.ProjectSetCapability;
+
+/**
+ * This URI like construct used for a Git SCM URL. See
+ * http://maven.apache.org/scm/scm-url-format.html for the format description.
+ */
+public class GitURI {
+ private static final String SCHEME_GIT = "git"; //$NON-NLS-1$
+
+ private static final String KEY_PATH = "path"; //$NON-NLS-1$
+
+ private static final String KEY_PROJECT = "project"; //$NON-NLS-1$
+
+ private static final String KEY_TAG = "tag"; //$NON-NLS-1$
+
+ private final URIish repository;
+
+ private IPath path;
+
+ private String tag;
+
+ private String projectName;
+
+ /**
+ * Construct the {@link GitURI} for the given URI.
+ *
+ * @param uri
+ * the URI in the SCM URL format
+ */
+ public GitURI(URI uri) {
+ try {
+ if (ProjectSetCapability.SCHEME_SCM.equals(uri.getScheme())) {
+ final String ssp = uri.getSchemeSpecificPart();
+ if (ssp.startsWith(SCHEME_GIT)) {
+ int indexOfSemicolon = ssp.indexOf(';');
+ URIish r = new URIish(ssp.substring(
+ SCHEME_GIT.length() + 1, indexOfSemicolon));
+ IPath p = null;
+ String t = Constants.MASTER; // default
+ String pn = null;
+ String[] params = ssp.substring(indexOfSemicolon)
+ .split(";"); //$NON-NLS-1$
+ for (String param : params) {
+ if (param.startsWith(KEY_PATH + '=')) {
+ p = new Path(
+ param.substring(param.indexOf('=') + 1));
+ } else if (param.startsWith(KEY_TAG + '=')) {
+ t = param.substring(param.indexOf('=') + 1);
+ } else if (param.startsWith(KEY_PROJECT + '=')) {
+ pn = param.substring(param.indexOf('=') + 1);
+ }
+ }
+ this.repository = r;
+ this.path = p;
+ this.tag = t;
+ this.projectName = pn;
+ return;
+ }
+ }
+ throw new IllegalArgumentException(NLS.bind(
+ CoreText.GitURI_InvalidSCMURL,
+ new String[] { uri.toString() }));
+ } catch (URISyntaxException e) {
+ Activator.logError(e.getMessage(), e);
+ throw new IllegalArgumentException(NLS.bind(
+ CoreText.GitURI_InvalidURI, new String[] { uri.toString(),
+ e.getMessage() }));
+ }
+ }
+
+ /**
+ * @return path
+ */
+ public IPath getPath() {
+ return path;
+ }
+
+ /**
+ * @return repository
+ */
+ public URIish getRepository() {
+ return repository;
+ }
+
+ /**
+ * @return tag
+ */
+ public String getTag() {
+ return tag;
+ }
+
+ /**
+ * @return project name
+ */
+ public String getProjectName() {
+ return projectName;
+ }
+} \ No newline at end of file