Browse Source

Noop changes to ManifestParser

* Parse the base URL in ManifestParser construction.  This will signal
  errors earlier.

* Simplify stripping of trailing slashes.

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Change-Id: I4a86f68c9d7737f71cf20352cfe26288fbd2b463
stable-4.7
Han-Wen Nienhuys 8 years ago
parent
commit
6e652846f6
  1. 21
      org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java

21
org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java

@ -78,7 +78,7 @@ import org.xml.sax.helpers.XMLReaderFactory;
*/ */
public class ManifestParser extends DefaultHandler { public class ManifestParser extends DefaultHandler {
private final String filename; private final String filename;
private final String baseUrl; private final URI baseUrl;
private final String defaultBranch; private final String defaultBranch;
private final Repository rootRepo; private final Repository rootRepo;
private final Map<String, Remote> remotes; private final Map<String, Remote> remotes;
@ -126,11 +126,11 @@ public class ManifestParser extends DefaultHandler {
this.defaultBranch = defaultBranch; this.defaultBranch = defaultBranch;
this.rootRepo = rootRepo; this.rootRepo = rootRepo;
// Strip trailing /s to match repo behavior. // Strip trailing '/' to match repo behavior.
int lastIndex = baseUrl.length() - 1; while (baseUrl.endsWith("/")) { //$NON-NLS-1$
while (lastIndex >= 0 && baseUrl.charAt(lastIndex) == '/') baseUrl = baseUrl.substring(0, baseUrl.length()-1);
lastIndex--; }
this.baseUrl = baseUrl.substring(0, lastIndex + 1); this.baseUrl = URI.create(baseUrl);
plusGroups = new HashSet<>(); plusGroups = new HashSet<>();
minusGroups = new HashSet<>(); minusGroups = new HashSet<>();
@ -259,12 +259,6 @@ public class ManifestParser extends DefaultHandler {
// Only do the following after we finished reading everything. // Only do the following after we finished reading everything.
Map<String, String> remoteUrls = new HashMap<>(); Map<String, String> remoteUrls = new HashMap<>();
URI baseUri;
try {
baseUri = new URI(baseUrl);
} catch (URISyntaxException e) {
throw new SAXException(e);
}
if (defaultRevision == null && defaultRemote != null) { if (defaultRevision == null && defaultRemote != null) {
Remote remote = remotes.get(defaultRemote); Remote remote = remotes.get(defaultRemote);
if (remote != null) { if (remote != null) {
@ -296,8 +290,7 @@ public class ManifestParser extends DefaultHandler {
} }
String remoteUrl = remoteUrls.get(remote); String remoteUrl = remoteUrls.get(remote);
if (remoteUrl == null) { if (remoteUrl == null) {
remoteUrl = remoteUrl = baseUrl.resolve(remotes.get(remote).fetch).toString();
baseUri.resolve(remotes.get(remote).fetch).toString();
if (!remoteUrl.endsWith("/")) //$NON-NLS-1$ if (!remoteUrl.endsWith("/")) //$NON-NLS-1$
remoteUrl = remoteUrl + "/"; //$NON-NLS-1$ remoteUrl = remoteUrl + "/"; //$NON-NLS-1$
remoteUrls.put(remote, remoteUrl); remoteUrls.put(remote, remoteUrl);

Loading…
Cancel
Save