Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2010-12-01 09:33:05 -0500
committerTomasz Zarna2010-12-01 09:33:05 -0500
commit1e19b795333d46f027ecbc1d6af24bf77e4a1706 (patch)
tree9c31ce71569ad9c220908ffe2e3a2f00e757a461
parentf93a2c679e74e704ddebb968cb65f99193bddcc6 (diff)
downloadeclipse.platform.team-1e19b795333d46f027ecbc1d6af24bf77e4a1706.tar.gz
eclipse.platform.team-1e19b795333d46f027ecbc1d6af24bf77e4a1706.tar.xz
eclipse.platform.team-1e19b795333d46f027ecbc1d6af24bf77e4a1706.zip
bug 326926: API to configure and import SCM URLs
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/core/ProjectSetCapability.java34
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProjectSetCapability.java7
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/filesystem/CVSURI.java97
-rw-r--r--tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/cvsresources/CVSURITest.java136
4 files changed, 260 insertions, 14 deletions
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/ProjectSetCapability.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/ProjectSetCapability.java
index 307094c69..6dcb40f9e 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/ProjectSetCapability.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/ProjectSetCapability.java
@@ -34,6 +34,13 @@ import org.eclipse.team.internal.core.Messages;
public abstract class ProjectSetCapability {
/**
+ * Scheme constant (value "scm") indicating the SCM URI.
+ *
+ * @since 3.7
+ */
+ public static final String SCHEME_SCM = "scm"; //$NON-NLS-1$
+
+ /**
* Ensure that the provider type is backwards compatible by
* passing the project set serializer to the type if a serializer
* is registered. This is required for repository providers
@@ -303,13 +310,30 @@ public abstract class ProjectSetCapability {
/**
* Convert the given URI and projectName to a reference string that can be
- * passed to the {@link #addToWorkspace(String[], ProjectSetSerializationContext, IProgressMonitor)}
+ * passed to the
+ * {@link #addToWorkspace(String[], ProjectSetSerializationContext, IProgressMonitor)}
* method. The scheme of the provided URI must match the scheme of the
* repository provider type from which this capability was obtained.
- * @param uri the uri that identifies the location of the project in the repository.
- * @param projectName the name of the project.
- * @return the reference string representing a project that can be loaded into the workspace
- * or <code>null</code> if the URI and name cannot be translated into a reference string
+ * <p>
+ * Since 3.7 SCM URIs are also accepted.
+ * </p>
+ * <p>
+ * The default implementation returns <code>null</code>. Subclasses may
+ * override.
+ * </p>
+ *
+ * @see #SCHEME_SCM
+ * @param uri
+ * the URI that identifies the location of the project in the
+ * repository.
+ * @param projectName
+ * the name of the project to use. If <code>null</code>, use the
+ * project name from the provided SCM URI. If the URI is not an
+ * SCM URI or does not contain project name, <code>null</code> is
+ * returned.
+ * @return the reference string representing a project that can be loaded
+ * into the workspace or <code>null</code>, if the URI and name
+ * cannot be translated into a reference string
* @since 3.2
*/
public String asReference(URI uri, String projectName) {
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProjectSetCapability.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProjectSetCapability.java
index 66026942f..01e3e74ee 100644
--- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProjectSetCapability.java
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProjectSetCapability.java
@@ -629,6 +629,13 @@ public class CVSProjectSetCapability extends ProjectSetCapability {
CVSURI cvsURI = CVSURI.fromUri(uri);
ICVSRepositoryLocation location = cvsURI.getRepository();
ICVSFolder folder = cvsURI.toFolder();
+ if (projectName == null) {
+ if (cvsURI.getProjectName() != null) {
+ projectName = cvsURI.getProjectName();
+ } else {
+ return null;
+ }
+ }
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
return asReference((CVSRepositoryLocation)location, folder, project);
} catch (TeamException e) {
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/filesystem/CVSURI.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/filesystem/CVSURI.java
index 5a54ed54f..7f92030d6 100644
--- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/filesystem/CVSURI.java
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/filesystem/CVSURI.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation 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
@@ -16,6 +16,7 @@ import java.util.StringTokenizer;
import org.eclipse.core.runtime.*;
import org.eclipse.osgi.util.NLS;
+import org.eclipse.team.core.ProjectSetCapability;
import org.eclipse.team.internal.ccvs.core.*;
import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation;
import org.eclipse.team.internal.ccvs.core.resources.RemoteFile;
@@ -24,24 +25,36 @@ import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo;
public class CVSURI {
- private static final String SCHEME = "cvs"; //$NON-NLS-1$
+ private static final String SCHEME_CVS = "cvs"; //$NON-NLS-1$
private final ICVSRepositoryLocation repository;
private final IPath path;
private final CVSTag tag;
private final String revision;
+ private final String projectName;
/**
- * Convert the given URI to a CVSURI. There are two supported formats: the
- * original opaque format and a newer hierarchical format.
+ * Convert the given URI to a CVSURI. There are three supported formats: the
+ * original opaque format, a newer hierarchical format and a CVS SCM URL
+ * format.
+ *
+ * In the last format, as delimiter you can use either colon ':' or, if you
+ * use a colon for one of the variables (e.g. a windows path), a pipe '|'.
+ * For more information visit http://maven.apache.org/scm/cvs.html. Please
+ * note, that URIs with the pipe separator are currently not supported.
+ *
* <ul>
* <li>cvs://[:]method:user[:password]@host:[port]/root/path#project/path[,tagName]</li>
* <li>cvs://_method_user[_password]~host_[port]!root!path/project/path[?<version,branch,date,revision>=tagName]</li>
+ * <li>scm:cvs<delimiter>method<delimiter>[user[<delimiter>password]@]host[<delimiter>port]<delimiter>/root/path<delimiter>project/path[;project="projectName"][;tag=tagName]</li>
* </ul>
* @param uri the URI
* @return a CVS URI
*/
public static CVSURI fromUri(URI uri) {
try {
+ if (ProjectSetCapability.SCHEME_SCM.equals(uri.getScheme())) {
+ uri = convert(uri);
+ }
ICVSRepositoryLocation repository = getRepository(uri);
if (repository != null) {
IPath path = new Path(null, uri.getPath());
@@ -52,7 +65,8 @@ public class CVSURI {
repository = getOldRepository(uri);
IPath path = getOldPath(uri);
CVSTag tag = getOldTag(uri);
- return new CVSURI(repository, path, tag);
+ String projectName = getProjectName(uri);
+ return new CVSURI(repository, path, tag, null, projectName);
}
} catch (CVSException e) {
CVSProviderPlugin.log(e);
@@ -60,11 +74,43 @@ public class CVSURI {
}
}
+ private static URI convert(URI uri) {
+ StringBuffer sb = new StringBuffer();
+ String ssp = uri.getSchemeSpecificPart();
+ int i = ssp.lastIndexOf(':');
+ sb.append(ssp.substring(0, i)).append('#');
+ int j = ssp.indexOf(';');
+ if (j != -1) {
+ sb.append(ssp.substring(i + 1, j));
+ String[] params = ssp.substring(j).split(";"); //$NON-NLS-1$
+ String projectName = ""; //$NON-NLS-1$
+ for (int k = 0; k < params.length; k++) {
+ // PDE way of providing tags
+ if (params[k].startsWith("tag=")) { //$NON-NLS-1$
+ sb.append(",version="); //$NON-NLS-1$
+ sb.append(params[k].substring(params[k].indexOf('=') + 1));
+ } else if (params[k].startsWith("version=")) { //$NON-NLS-1$
+ sb.append(',').append(params[k]);
+ } else if (params[k].startsWith("project=")) { //$NON-NLS-1$
+ projectName = params[k].substring(params[k].indexOf('=') + 1);
+ }
+ }
+ sb.append(',').append(projectName); // can be ""
+ } else {
+ sb.append(ssp.substring(i + 1));
+ }
+ return URI.create(sb.toString());
+ }
+
private static CVSTag getTag(URI uri) {
String query = uri.getQuery();
if (query == null)
return null;
- StringTokenizer tokens = new StringTokenizer(query, ","); //$NON-NLS-1$
+ return getTag(query);
+ }
+
+ private static CVSTag getTag(String s) {
+ StringTokenizer tokens = new StringTokenizer(s, ","); //$NON-NLS-1$
while (tokens.hasMoreTokens()) {
String token = tokens.nextToken();
int index = token.indexOf('=');
@@ -116,6 +162,8 @@ public class CVSURI {
private static ICVSRepositoryLocation getRepository(URI uri) throws CVSException {
String authority = uri.getAuthority();
+ if (authority == null)
+ return null;
if (authority.indexOf('/') != -1)
return null;
if (authority.indexOf('!') == -1)
@@ -123,6 +171,19 @@ public class CVSURI {
authority = decodeAuthority(authority);
return CVSRepositoryLocation.fromString(authority);
}
+
+ private static String getProjectName(URI uri) {
+ String f = uri.getFragment();
+ if (f != null) {
+ int i = f.lastIndexOf(',');
+ if (i != -1) {
+ String s = f.substring(i + 1);
+ if (!s.equals("")) //$NON-NLS-1$
+ return s;
+ }
+ }
+ return null;
+ }
private static CVSTag getOldTag(URI uri) {
String f = uri.getFragment();
@@ -130,6 +191,9 @@ public class CVSURI {
if (i == -1) {
return CVSTag.DEFAULT;
}
+ CVSTag tag = getTag(f.substring(i + 1));
+ if (tag != null)
+ return tag;
return CVSTag.DEFAULT;//just use HEAD for now (name, CVSTag.BRANCH);
}
@@ -152,10 +216,14 @@ public class CVSURI {
}
public CVSURI(ICVSRepositoryLocation repository, IPath path, CVSTag tag) {
- this(repository, path, tag, null);
+ this(repository, path, tag, null, null);
}
public CVSURI(ICVSRepositoryLocation repository, IPath path, CVSTag tag, String revision) {
+ this(repository, path, tag, revision, null);
+ }
+
+ public CVSURI(ICVSRepositoryLocation repository, IPath path, CVSTag tag, String revision, String projectName) {
this.repository = repository;
this.path = path;
this.tag = tag;
@@ -163,6 +231,7 @@ public class CVSURI {
this.revision = revision;
else
this.revision = null;
+ this.projectName = projectName;
}
public CVSURI append(String name) {
@@ -197,7 +266,15 @@ public class CVSURI {
query = query + "," + string; //$NON-NLS-1$
}
}
- return new URI(SCHEME, authority, pathString, query, null);
+ if (projectName != null) {
+ String string = "project=" + projectName; //$NON-NLS-1$
+ if (query == null) {
+ query = string;
+ } else {
+ query = query + "," + string; //$NON-NLS-1$
+ }
+ }
+ return new URI(SCHEME_CVS, authority, pathString, query, null);
} catch (URISyntaxException e) {
CVSProviderPlugin.log(IStatus.ERROR, NLS.bind("An error occurred while creating a URI for {0} {1}", repository, path), e); //$NON-NLS-1$
throw new IllegalStateException(e.getMessage());
@@ -305,4 +382,8 @@ public class CVSURI {
public String getRevision() {
return revision;
}
+
+ public String getProjectName() {
+ return projectName;
+ }
}
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/cvsresources/CVSURITest.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/cvsresources/CVSURITest.java
index c7334d577..c8a02a222 100644
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/cvsresources/CVSURITest.java
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/cvsresources/CVSURITest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 IBM Corporation and others.
+ * Copyright (c) 2006, 2010 IBM Corporation 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
@@ -17,6 +17,7 @@ import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.CVSProjectSetCapability;
import org.eclipse.team.internal.ccvs.core.CVSTag;
import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation;
@@ -115,5 +116,138 @@ public class CVSURITest extends EclipseTest {
assertEquals(null, cvsUri.getTag());
assertEquals(cvsUri.toURI(), uri);
}
+
+ // CVS SCM URL tests, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=326926
+ public void testScmUri1() throws CVSException {
+ URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:module;tag=tag");
+ CVSURI cvsUri = CVSURI.fromUri(uri);
+ assertEquals("module", cvsUri.getPath().toString());
+ CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path");
+ assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
+ assertEquals(cvsUri.getTag(), new CVSTag("tag", CVSTag.VERSION));
+
+ String refString = new CVSProjectSetCapability().asReference(uri, "project");
+ assertEquals("1.0,:pserver:host.com:/cvsroot/path,module,project,tag", refString);
+ }
+
+ public void testScmUri2() throws CVSException {
+ URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:module;version=version");
+ CVSURI cvsUri = CVSURI.fromUri(uri);
+ assertEquals("module", cvsUri.getPath().toString());
+ CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path");
+ assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
+ assertEquals(cvsUri.getTag(), new CVSTag("version", CVSTag.VERSION));
+
+ String refString = new CVSProjectSetCapability().asReference(uri, "project");
+ assertEquals("1.0,:pserver:host.com:/cvsroot/path,module,project,version", refString);
+ }
+
+ public void testScmUri3() throws CVSException {
+ URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:path/to/module;version=version;project=project1");
+ CVSURI cvsUri = CVSURI.fromUri(uri);
+ assertEquals("path/to/module", cvsUri.getPath().toString());
+ CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path");
+ assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
+ assertEquals(cvsUri.getTag(), new CVSTag("version", CVSTag.VERSION));
+
+ String refString = new CVSProjectSetCapability().asReference(uri, "project2");
+ assertEquals("1.0,:pserver:host.com:/cvsroot/path,path/to/module,project2,version", refString);
+ }
+
+ public void testScmUri4() throws CVSException {
+ URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:path/to/module;version=version;project=project1");
+ CVSURI cvsUri = CVSURI.fromUri(uri);
+ assertEquals("path/to/module", cvsUri.getPath().toString());
+ CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path");
+ assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
+ assertEquals(cvsUri.getTag(), new CVSTag("version", CVSTag.VERSION));
+
+ String refString = new CVSProjectSetCapability().asReference(uri, null);
+ assertEquals("1.0,:pserver:host.com:/cvsroot/path,path/to/module,project1,version", refString);
+ }
+
+ public void testScmUri5() throws CVSException {
+ URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:path/to/module;project=project1;version=version");
+ CVSURI cvsUri = CVSURI.fromUri(uri);
+ assertEquals("path/to/module", cvsUri.getPath().toString());
+ CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path");
+ assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
+ assertEquals(cvsUri.getTag(), new CVSTag("version", CVSTag.VERSION));
+
+ String refString = new CVSProjectSetCapability().asReference(uri, null);
+ assertEquals("1.0,:pserver:host.com:/cvsroot/path,path/to/module,project1,version", refString);
+ }
+
+ public void testScmUri6() throws CVSException {
+ URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:path/to/module;tag=tag");
+ CVSURI cvsUri = CVSURI.fromUri(uri);
+ assertEquals("path/to/module", cvsUri.getPath().toString());
+ CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path");
+ assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
+ assertEquals(cvsUri.getTag(), new CVSTag("tag", CVSTag.VERSION));
+
+ String refString = new CVSProjectSetCapability().asReference(uri, null);
+ assertNull(refString);
+ }
+
+ public void testScmUri7() throws CVSException {
+ URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:path/to/module;version=version");
+ CVSURI cvsUri = CVSURI.fromUri(uri);
+ assertEquals("path/to/module", cvsUri.getPath().toString());
+ CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path");
+ assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
+ assertEquals(cvsUri.getTag(), new CVSTag("version", CVSTag.VERSION));
+
+ String refString = new CVSProjectSetCapability().asReference(uri, null);
+ assertNull(refString);
+ }
+ public void testScmUri8() throws CVSException {
+ URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:path/to/module;project=");
+ CVSURI cvsUri = CVSURI.fromUri(uri);
+ assertEquals("path/to/module", cvsUri.getPath().toString());
+ CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path");
+ assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
+ assertEquals(cvsUri.getTag(), CVSTag.DEFAULT);
+
+ String refString = new CVSProjectSetCapability().asReference(uri, null);
+ assertNull(refString);
+ }
+
+ public void testScmUri9() throws CVSException {
+ URI uri = URI.create("scm:cvs:pserver:host.com:/cvsroot/path:path/to/module");
+ CVSURI cvsUri = CVSURI.fromUri(uri);
+ assertEquals("path/to/module", cvsUri.getPath().toString());
+ CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:host.com:/cvsroot/path");
+ assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
+ assertEquals(cvsUri.getTag(), CVSTag.DEFAULT);
+
+ String refString = new CVSProjectSetCapability().asReference(uri, "project");
+ assertEquals("1.0,:pserver:host.com:/cvsroot/path,path/to/module,project", refString);
+ }
+
+ public void testScmUri10() throws URISyntaxException, CVSException {
+ URI uri = new URI("scm:cvs:pserver:anonymous:@host.com:/cvsroot/path:module");
+ CVSURI cvsUri = CVSURI.fromUri(uri);
+ assertEquals("module", cvsUri.getPath().toString());
+ CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:anonymous:@host.com:/cvsroot/path");
+ assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
+ assertEquals(cvsUri.getTag(), CVSTag.DEFAULT);
+
+ String refString = new CVSProjectSetCapability().asReference(uri, "project");
+ assertEquals("1.0,:pserver:anonymous:@host.com:/cvsroot/path,module,project", refString);
+ }
+
+ public void testScmUri11() throws URISyntaxException, CVSException {
+ URI uri = new URI("scm:cvs:pserver:username@host.com:/cvsroot/path:module");
+ CVSURI cvsUri = CVSURI.fromUri(uri);
+ assertEquals("module", cvsUri.getPath().toString());
+ CVSRepositoryLocation location = CVSRepositoryLocation.fromString(":pserver:username@host.com:/cvsroot/path");
+ assertEquals(cvsUri.getRepository().getLocation(false), location.getLocation(false));
+ assertEquals(cvsUri.getTag(), CVSTag.DEFAULT);
+
+ String refString = new CVSProjectSetCapability().asReference(uri, "project");
+ assertEquals("1.0,:pserver:username@host.com:/cvsroot/path,module,project", refString);
+ }
+
}

Back to the top