|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2007 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2010 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 16-21
Link Here
|
| 16 |
|
16 |
|
| 17 |
import org.eclipse.core.runtime.*; |
17 |
import org.eclipse.core.runtime.*; |
| 18 |
import org.eclipse.osgi.util.NLS; |
18 |
import org.eclipse.osgi.util.NLS; |
|
|
19 |
import org.eclipse.team.core.ProjectSetCapability; |
| 19 |
import org.eclipse.team.internal.ccvs.core.*; |
20 |
import org.eclipse.team.internal.ccvs.core.*; |
| 20 |
import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation; |
21 |
import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation; |
| 21 |
import org.eclipse.team.internal.ccvs.core.resources.RemoteFile; |
22 |
import org.eclipse.team.internal.ccvs.core.resources.RemoteFile; |
|
Lines 24-58
Link Here
|
| 24 |
|
25 |
|
| 25 |
public class CVSURI { |
26 |
public class CVSURI { |
| 26 |
|
27 |
|
| 27 |
private static final String SCHEME = "cvs"; //$NON-NLS-1$ |
28 |
private static final String SCHEME_CVS = "cvs"; //$NON-NLS-1$ |
| 28 |
private final ICVSRepositoryLocation repository; |
29 |
private final ICVSRepositoryLocation repository; |
| 29 |
private final IPath path; |
30 |
private final IPath path; |
| 30 |
private final CVSTag tag; |
31 |
private final CVSTag tag; |
| 31 |
private final String revision; |
32 |
private final String revision; |
|
|
33 |
private final String projectName; |
| 32 |
|
34 |
|
| 33 |
/** |
35 |
/** |
| 34 |
* Convert the given URI to a CVSURI. There are two supported formats: the |
36 |
* Convert the given URI to a CVSURI. There are three supported formats: the |
| 35 |
* original opaque format and a newer hierarchical format. |
37 |
* original opaque format, a newer hierarchical format and a CVS SCM URL |
|
|
38 |
* format. |
| 39 |
* |
| 40 |
* In the last format, as delimiter you can use either colon ':' or, if you |
| 41 |
* use a colon for one of the variables (e.g. a windows path), a pipe '|'. |
| 42 |
* For more information visit http://maven.apache.org/scm/cvs.html. |
| 43 |
* |
| 36 |
* <ul> |
44 |
* <ul> |
| 37 |
* <li>cvs://[:]method:user[:password]@host:[port]/root/path#project/path[,tagName]</li> |
45 |
* <li>cvs://[:]method:user[:password]@host:[port]/root/path#project/path[,tagName]</li> |
| 38 |
* <li>cvs://_method_user[_password]~host_[port]!root!path/project/path[?<version,branch,date,revision>=tagName]</li> |
46 |
* <li>cvs://_method_user[_password]~host_[port]!root!path/project/path[?<version,branch,date,revision>=tagName]</li> |
|
|
47 |
* <li>scm:cvs<delimiter>method<delimiter>[user[<delimiter>password]@]host[<delimiter>port]<delimiter>/root/path<delimiter>project/path[;project="projectName"][;tag=tagName]</li> |
| 39 |
* </ul> |
48 |
* </ul> |
| 40 |
* @param uri the URI |
49 |
* @param uri the URI |
| 41 |
* @return a CVS URI |
50 |
* @return a CVS URI |
| 42 |
*/ |
51 |
*/ |
| 43 |
public static CVSURI fromUri(URI uri) { |
52 |
public static CVSURI fromUri(URI uri) { |
| 44 |
try { |
53 |
try { |
|
|
54 |
if (ProjectSetCapability.SCHEME_SCM.equals(uri.getScheme())) { |
| 55 |
uri = convert(uri); |
| 56 |
} |
| 45 |
ICVSRepositoryLocation repository = getRepository(uri); |
57 |
ICVSRepositoryLocation repository = getRepository(uri); |
| 46 |
if (repository != null) { |
58 |
if (repository != null) { |
| 47 |
IPath path = new Path(null, uri.getPath()); |
59 |
IPath path = new Path(null, uri.getPath()); |
| 48 |
CVSTag tag = getTag(uri); |
60 |
CVSTag tag = getTag(uri); |
| 49 |
String revision = getRevision(uri); |
61 |
String revision = getRevision(uri); |
| 50 |
return new CVSURI(repository, path, tag, revision); |
62 |
String projectName = getProjectName(uri); |
|
|
63 |
return new CVSURI(repository, path, tag, revision, projectName); |
| 51 |
} else { |
64 |
} else { |
| 52 |
repository = getOldRepository(uri); |
65 |
repository = getOldRepository(uri); |
| 53 |
IPath path = getOldPath(uri); |
66 |
IPath path = getOldPath(uri); |
| 54 |
CVSTag tag = getOldTag(uri); |
67 |
CVSTag tag = getOldTag(uri); |
| 55 |
return new CVSURI(repository, path, tag); |
68 |
String projectName = getProjectName(uri); |
|
|
69 |
return new CVSURI(repository, path, tag, null, projectName); |
| 56 |
} |
70 |
} |
| 57 |
} catch (CVSException e) { |
71 |
} catch (CVSException e) { |
| 58 |
CVSProviderPlugin.log(e); |
72 |
CVSProviderPlugin.log(e); |
|
Lines 60-70
Link Here
|
| 60 |
} |
74 |
} |
| 61 |
} |
75 |
} |
| 62 |
|
76 |
|
|
|
77 |
private static URI convert(URI uri) { |
| 78 |
StringBuffer sb = new StringBuffer(); |
| 79 |
String ssp = uri.getSchemeSpecificPart(); |
| 80 |
int i = ssp.lastIndexOf(':'); |
| 81 |
sb.append(ssp.substring(0, i)).append('#'); |
| 82 |
int j = ssp.indexOf(';'); |
| 83 |
if (j != -1) { |
| 84 |
sb.append(ssp.substring(i + 1, j)); |
| 85 |
String[] params = ssp.substring(j).split(";"); //$NON-NLS-1$ |
| 86 |
String projectName = ""; //$NON-NLS-1$ |
| 87 |
for (int k = 0; k < params.length; k++) { |
| 88 |
// PDE way of providing tags |
| 89 |
if (params[k].startsWith("tag=")) { //$NON-NLS-1$ |
| 90 |
sb.append(",version="); //$NON-NLS-1$ |
| 91 |
sb.append(params[k].substring(params[k].indexOf('=') + 1)); |
| 92 |
} else if (params[k].startsWith("version=")) { //$NON-NLS-1$ |
| 93 |
sb.append(',').append(params[k]); |
| 94 |
} else if (params[k].startsWith("project=")) { //$NON-NLS-1$ |
| 95 |
projectName = params[k].substring(params[k].indexOf('=') + 1); |
| 96 |
} |
| 97 |
} |
| 98 |
sb.append(',').append(projectName); // can be "" |
| 99 |
} else { |
| 100 |
sb.append(ssp.substring(i + 1)); |
| 101 |
} |
| 102 |
return URI.create(sb.toString()); |
| 103 |
} |
| 104 |
|
| 63 |
private static CVSTag getTag(URI uri) { |
105 |
private static CVSTag getTag(URI uri) { |
| 64 |
String query = uri.getQuery(); |
106 |
String query = uri.getQuery(); |
| 65 |
if (query == null) |
107 |
if (query == null) |
| 66 |
return null; |
108 |
return null; |
| 67 |
StringTokenizer tokens = new StringTokenizer(query, ","); //$NON-NLS-1$ |
109 |
return getTag(query); |
|
|
110 |
} |
| 111 |
|
| 112 |
private static CVSTag getTag(String s) { |
| 113 |
StringTokenizer tokens = new StringTokenizer(s, ","); //$NON-NLS-1$ |
| 68 |
while (tokens.hasMoreTokens()) { |
114 |
while (tokens.hasMoreTokens()) { |
| 69 |
String token = tokens.nextToken(); |
115 |
String token = tokens.nextToken(); |
| 70 |
int index = token.indexOf('='); |
116 |
int index = token.indexOf('='); |
|
Lines 116-121
Link Here
|
| 116 |
|
162 |
|
| 117 |
private static ICVSRepositoryLocation getRepository(URI uri) throws CVSException { |
163 |
private static ICVSRepositoryLocation getRepository(URI uri) throws CVSException { |
| 118 |
String authority = uri.getAuthority(); |
164 |
String authority = uri.getAuthority(); |
|
|
165 |
if (authority == null) |
| 166 |
return null; |
| 119 |
if (authority.indexOf('/') != -1) |
167 |
if (authority.indexOf('/') != -1) |
| 120 |
return null; |
168 |
return null; |
| 121 |
if (authority.indexOf('!') == -1) |
169 |
if (authority.indexOf('!') == -1) |
|
Lines 123-128
Link Here
|
| 123 |
authority = decodeAuthority(authority); |
171 |
authority = decodeAuthority(authority); |
| 124 |
return CVSRepositoryLocation.fromString(authority); |
172 |
return CVSRepositoryLocation.fromString(authority); |
| 125 |
} |
173 |
} |
|
|
174 |
|
| 175 |
private static String getProjectName(URI uri) { |
| 176 |
String f = uri.getFragment(); |
| 177 |
if (f != null) { |
| 178 |
int i = f.lastIndexOf(','); |
| 179 |
if (i != -1) { |
| 180 |
String s = f.substring(i + 1); |
| 181 |
if (!s.equals("")) //$NON-NLS-1$ |
| 182 |
return s; |
| 183 |
} |
| 184 |
} |
| 185 |
return null; |
| 186 |
} |
| 126 |
|
187 |
|
| 127 |
private static CVSTag getOldTag(URI uri) { |
188 |
private static CVSTag getOldTag(URI uri) { |
| 128 |
String f = uri.getFragment(); |
189 |
String f = uri.getFragment(); |
|
Lines 130-135
Link Here
|
| 130 |
if (i == -1) { |
191 |
if (i == -1) { |
| 131 |
return CVSTag.DEFAULT; |
192 |
return CVSTag.DEFAULT; |
| 132 |
} |
193 |
} |
|
|
194 |
CVSTag tag = getTag(f.substring(i + 1)); |
| 195 |
if (tag != null) |
| 196 |
return tag; |
| 133 |
|
197 |
|
| 134 |
return CVSTag.DEFAULT;//just use HEAD for now (name, CVSTag.BRANCH); |
198 |
return CVSTag.DEFAULT;//just use HEAD for now (name, CVSTag.BRANCH); |
| 135 |
} |
199 |
} |
|
Lines 152-161
Link Here
|
| 152 |
} |
216 |
} |
| 153 |
|
217 |
|
| 154 |
public CVSURI(ICVSRepositoryLocation repository, IPath path, CVSTag tag) { |
218 |
public CVSURI(ICVSRepositoryLocation repository, IPath path, CVSTag tag) { |
| 155 |
this(repository, path, tag, null); |
219 |
this(repository, path, tag, null, null); |
| 156 |
} |
220 |
} |
| 157 |
|
221 |
|
| 158 |
public CVSURI(ICVSRepositoryLocation repository, IPath path, CVSTag tag, String revision) { |
222 |
public CVSURI(ICVSRepositoryLocation repository, IPath path, CVSTag tag, String revision) { |
|
|
223 |
this(repository, path, tag, revision, null); |
| 224 |
} |
| 225 |
|
| 226 |
public CVSURI(ICVSRepositoryLocation repository, IPath path, CVSTag tag, String revision, String projectName) { |
| 159 |
this.repository = repository; |
227 |
this.repository = repository; |
| 160 |
this.path = path; |
228 |
this.path = path; |
| 161 |
this.tag = tag; |
229 |
this.tag = tag; |
|
Lines 163-170
Link Here
|
| 163 |
this.revision = revision; |
231 |
this.revision = revision; |
| 164 |
else |
232 |
else |
| 165 |
this.revision = null; |
233 |
this.revision = null; |
|
|
234 |
this.projectName = projectName; |
| 166 |
} |
235 |
} |
| 167 |
|
236 |
|
| 168 |
public CVSURI append(String name) { |
237 |
public CVSURI append(String name) { |
| 169 |
return new CVSURI(repository, path.append(name), tag); |
238 |
return new CVSURI(repository, path.append(name), tag); |
| 170 |
} |
239 |
} |
|
Lines 197-203
Link Here
|
| 197 |
query = query + "," + string; //$NON-NLS-1$ |
266 |
query = query + "," + string; //$NON-NLS-1$ |
| 198 |
} |
267 |
} |
| 199 |
} |
268 |
} |
| 200 |
return new URI(SCHEME, authority, pathString, query, null); |
269 |
if (projectName != null) { |
|
|
270 |
String string = "project=" + projectName; //$NON-NLS-1$ |
| 271 |
if (query == null) { |
| 272 |
query = string; |
| 273 |
} else { |
| 274 |
query = query + "," + string; //$NON-NLS-1$ |
| 275 |
} |
| 276 |
} |
| 277 |
return new URI(SCHEME_CVS, authority, pathString, query, null); |
| 201 |
} catch (URISyntaxException e) { |
278 |
} catch (URISyntaxException e) { |
| 202 |
CVSProviderPlugin.log(IStatus.ERROR, NLS.bind("An error occurred while creating a URI for {0} {1}", repository, path), e); //$NON-NLS-1$ |
279 |
CVSProviderPlugin.log(IStatus.ERROR, NLS.bind("An error occurred while creating a URI for {0} {1}", repository, path), e); //$NON-NLS-1$ |
| 203 |
throw new IllegalStateException(e.getMessage()); |
280 |
throw new IllegalStateException(e.getMessage()); |
|
Lines 305-308
Link Here
|
| 305 |
public String getRevision() { |
382 |
public String getRevision() { |
| 306 |
return revision; |
383 |
return revision; |
| 307 |
} |
384 |
} |
|
|
385 |
|
| 386 |
public String getProjectName() { |
| 387 |
return projectName; |
| 388 |
} |
| 308 |
} |
389 |
} |