|
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 24-70
Link Here
|
| 24 |
|
24 |
|
| 25 |
public class CVSURI { |
25 |
public class CVSURI { |
| 26 |
|
26 |
|
| 27 |
private static final String SCHEME = "cvs"; //$NON-NLS-1$ |
27 |
private static final String SCHEME_CVS = "cvs"; //$NON-NLS-1$ |
|
|
28 |
private static final String SCHEME_SCM = "scm"; //$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 |
* |
|
|
50 |
* @param uri |
| 51 |
* the URI |
| 41 |
* @return a CVS URI |
52 |
* @return a CVS URI |
| 42 |
*/ |
53 |
*/ |
| 43 |
public static CVSURI fromUri(URI uri) { |
54 |
public static CVSURI fromUri(URI uri) { |
| 44 |
try { |
55 |
try { |
|
|
56 |
if (SCHEME_SCM.equals(uri.getScheme())) { |
| 57 |
uri = convert(uri); |
| 58 |
} |
| 59 |
|
| 45 |
ICVSRepositoryLocation repository = getRepository(uri); |
60 |
ICVSRepositoryLocation repository = getRepository(uri); |
| 46 |
if (repository != null) { |
61 |
if (repository != null) { |
| 47 |
IPath path = new Path(null, uri.getPath()); |
62 |
IPath path = new Path(null, uri.getPath()); |
| 48 |
CVSTag tag = getTag(uri); |
63 |
CVSTag tag = getTag(uri); |
| 49 |
String revision = getRevision(uri); |
64 |
String revision = getRevision(uri); |
| 50 |
return new CVSURI(repository, path, tag, revision); |
65 |
String projectName = getProjectName(uri); |
|
|
66 |
return new CVSURI(repository, path, tag, revision, projectName); |
| 51 |
} else { |
67 |
} else { |
| 52 |
repository = getOldRepository(uri); |
68 |
repository = getOldRepository(uri); |
| 53 |
IPath path = getOldPath(uri); |
69 |
IPath path = getOldPath(uri); |
| 54 |
CVSTag tag = getOldTag(uri); |
70 |
CVSTag tag = getOldTag(uri); |
| 55 |
return new CVSURI(repository, path, tag); |
71 |
String projectName = getProjectName(uri); |
|
|
72 |
return new CVSURI(repository, path, tag, projectName); |
| 56 |
} |
73 |
} |
| 57 |
} catch (CVSException e) { |
74 |
} catch (CVSException e) { |
| 58 |
CVSProviderPlugin.log(e); |
75 |
CVSProviderPlugin.log(e); |
| 59 |
throw new IllegalArgumentException(NLS.bind(CVSMessages.CVSURI_InvalidURI, new String[] {uri.toString(), e.getMessage()})); |
76 |
throw new IllegalArgumentException(NLS.bind(CVSMessages.CVSURI_InvalidURI, new String[] {uri.toString(), e.getMessage()})); |
|
|
77 |
} catch (URISyntaxException e) { |
| 78 |
throw new IllegalArgumentException(NLS.bind(CVSMessages.CVSURI_InvalidURI, new String[] {uri.toString(), e.getMessage()})); |
| 60 |
} |
79 |
} |
| 61 |
} |
80 |
} |
| 62 |
|
81 |
|
|
|
82 |
private static URI convert(URI uri) throws URISyntaxException { |
| 83 |
StringBuffer sb = new StringBuffer(); |
| 84 |
String ssp = uri.getSchemeSpecificPart(); |
| 85 |
if (ssp.startsWith(SCHEME_CVS + ":")) { |
| 86 |
// sb.append(SCHEME_CVS + "://"); |
| 87 |
// ssp = ssp.substring((SCHEME_CVS + ":").length()); |
| 88 |
} |
| 89 |
int i = ssp.lastIndexOf("|"); |
| 90 |
if (i != -1) { |
| 91 |
sb.append(ssp.substring(0, i)).append("#").append(ssp.substring(i + 1)); |
| 92 |
} else { |
| 93 |
i = ssp.lastIndexOf(":"); |
| 94 |
sb.append(ssp.substring(0, i)).append("#").append(ssp.substring(i + 1)); |
| 95 |
} |
| 96 |
|
| 97 |
i = sb.indexOf(";project="); |
| 98 |
if (i != -1) |
| 99 |
sb.replace(i, i + ";project=".length(), ","); |
| 100 |
// TODO: see https://bugs.eclipse.org/bugs/show_bug.cgi?id=326926#c2 |
| 101 |
i = sb.indexOf(";tag="); // PDE way of providing tags |
| 102 |
if (i != -1) |
| 103 |
sb.replace(i, i + ";tag=".length(), ",version="); |
| 104 |
return new URI(sb.toString()); |
| 105 |
} |
| 106 |
|
| 63 |
private static CVSTag getTag(URI uri) { |
107 |
private static CVSTag getTag(URI uri) { |
| 64 |
String query = uri.getQuery(); |
108 |
String query = uri.getQuery(); |
| 65 |
if (query == null) |
109 |
if (query == null) |
| 66 |
return null; |
110 |
return null; |
| 67 |
StringTokenizer tokens = new StringTokenizer(query, ","); //$NON-NLS-1$ |
111 |
return getTag(query); |
|
|
112 |
} |
| 113 |
|
| 114 |
private static CVSTag getTag(String s) { |
| 115 |
StringTokenizer tokens = new StringTokenizer(s, ","); //$NON-NLS-1$ |
| 68 |
while (tokens.hasMoreTokens()) { |
116 |
while (tokens.hasMoreTokens()) { |
| 69 |
String token = tokens.nextToken(); |
117 |
String token = tokens.nextToken(); |
| 70 |
int index = token.indexOf('='); |
118 |
int index = token.indexOf('='); |
|
Lines 116-121
Link Here
|
| 116 |
|
164 |
|
| 117 |
private static ICVSRepositoryLocation getRepository(URI uri) throws CVSException { |
165 |
private static ICVSRepositoryLocation getRepository(URI uri) throws CVSException { |
| 118 |
String authority = uri.getAuthority(); |
166 |
String authority = uri.getAuthority(); |
|
|
167 |
if (authority == null) |
| 168 |
return null; |
| 119 |
if (authority.indexOf('/') != -1) |
169 |
if (authority.indexOf('/') != -1) |
| 120 |
return null; |
170 |
return null; |
| 121 |
if (authority.indexOf('!') == -1) |
171 |
if (authority.indexOf('!') == -1) |
|
Lines 123-135
Link Here
|
| 123 |
authority = decodeAuthority(authority); |
173 |
authority = decodeAuthority(authority); |
| 124 |
return CVSRepositoryLocation.fromString(authority); |
174 |
return CVSRepositoryLocation.fromString(authority); |
| 125 |
} |
175 |
} |
| 126 |
|
176 |
|
|
|
177 |
private static String getProjectName(URI uri) { |
| 178 |
return null; |
| 179 |
} |
| 180 |
|
| 127 |
private static CVSTag getOldTag(URI uri) { |
181 |
private static CVSTag getOldTag(URI uri) { |
| 128 |
String f = uri.getFragment(); |
182 |
String f = uri.getFragment(); |
| 129 |
int i = f.indexOf(','); |
183 |
int i = f.indexOf(','); |
| 130 |
if (i == -1) { |
184 |
if (i == -1) { |
| 131 |
return CVSTag.DEFAULT; |
185 |
return CVSTag.DEFAULT; |
| 132 |
} |
186 |
} |
|
|
187 |
CVSTag tag = getTag(f.substring(i + 1)); |
| 188 |
if (tag != null) |
| 189 |
return tag; |
| 133 |
|
190 |
|
| 134 |
return CVSTag.DEFAULT;//just use HEAD for now (name, CVSTag.BRANCH); |
191 |
return CVSTag.DEFAULT;//just use HEAD for now (name, CVSTag.BRANCH); |
| 135 |
} |
192 |
} |
|
Lines 152-161
Link Here
|
| 152 |
} |
209 |
} |
| 153 |
|
210 |
|
| 154 |
public CVSURI(ICVSRepositoryLocation repository, IPath path, CVSTag tag) { |
211 |
public CVSURI(ICVSRepositoryLocation repository, IPath path, CVSTag tag) { |
| 155 |
this(repository, path, tag, null); |
212 |
this(repository, path, tag, null, null); |
| 156 |
} |
213 |
} |
| 157 |
|
214 |
|
| 158 |
public CVSURI(ICVSRepositoryLocation repository, IPath path, CVSTag tag, String revision) { |
215 |
public CVSURI(ICVSRepositoryLocation repository, IPath path, CVSTag tag, String revision) { |
|
|
216 |
this(repository, path, tag, revision, null); |
| 217 |
} |
| 218 |
|
| 219 |
public CVSURI(ICVSRepositoryLocation repository, IPath path, CVSTag tag, String revision, String projectName) { |
| 159 |
this.repository = repository; |
220 |
this.repository = repository; |
| 160 |
this.path = path; |
221 |
this.path = path; |
| 161 |
this.tag = tag; |
222 |
this.tag = tag; |
|
Lines 163-170
Link Here
|
| 163 |
this.revision = revision; |
224 |
this.revision = revision; |
| 164 |
else |
225 |
else |
| 165 |
this.revision = null; |
226 |
this.revision = null; |
|
|
227 |
this.projectName = projectName; |
| 166 |
} |
228 |
} |
| 167 |
|
229 |
|
| 168 |
public CVSURI append(String name) { |
230 |
public CVSURI append(String name) { |
| 169 |
return new CVSURI(repository, path.append(name), tag); |
231 |
return new CVSURI(repository, path.append(name), tag); |
| 170 |
} |
232 |
} |
|
Lines 197-203
Link Here
|
| 197 |
query = query + "," + string; //$NON-NLS-1$ |
259 |
query = query + "," + string; //$NON-NLS-1$ |
| 198 |
} |
260 |
} |
| 199 |
} |
261 |
} |
| 200 |
return new URI(SCHEME, authority, pathString, query, null); |
262 |
return new URI(SCHEME_CVS, authority, pathString, query, null); |
| 201 |
} catch (URISyntaxException e) { |
263 |
} 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$ |
264 |
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()); |
265 |
throw new IllegalStateException(e.getMessage()); |
|
Lines 305-308
Link Here
|
| 305 |
public String getRevision() { |
367 |
public String getRevision() { |
| 306 |
return revision; |
368 |
return revision; |
| 307 |
} |
369 |
} |
|
|
370 |
|
| 371 |
public String getProjectName() { |
| 372 |
return projectName; |
| 373 |
} |
| 308 |
} |
374 |
} |