diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2017-04-11 00:54:06 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2017-04-11 00:54:16 +0200 |
commit | cc0dbbae435d4101a9253e2fc527fb2909278f17 (patch) | |
tree | 3964cfffc4c582d792576a0b19f96ebd3fb9e7d0 /org.eclipse.jgit | |
parent | fc24c5e18d654164f1616bb5a30cffd146b9e8b4 (diff) | |
parent | f17ec3928c45d7f5170e92b4e0e1f7390de5fff2 (diff) | |
download | jgit-cc0dbbae435d4101a9253e2fc527fb2909278f17.tar.gz jgit-cc0dbbae435d4101a9253e2fc527fb2909278f17.zip |
Merge branch 'stable-4.7'
* stable-4.7:
Cleanup and test trailing slash handling in ManifestParser
ManifestParser: Throw exception if remote does not have fetch attribute
Change-Id: Ia9dc3110bcbdae05175851ce647ffd11c542f4c0
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit')
3 files changed, 31 insertions, 13 deletions
diff --git a/org.eclipse.jgit/resources/org/eclipse/jgit/gitrepo/internal/RepoText.properties b/org.eclipse.jgit/resources/org/eclipse/jgit/gitrepo/internal/RepoText.properties index 7443ad32f0..e942038a3d 100644 --- a/org.eclipse.jgit/resources/org/eclipse/jgit/gitrepo/internal/RepoText.properties +++ b/org.eclipse.jgit/resources/org/eclipse/jgit/gitrepo/internal/RepoText.properties @@ -3,6 +3,7 @@ errorIncludeFile=Error: unable to read include file {0} errorIncludeNotImplemented=Error: <include> tag not supported as no callback defined. errorNoDefault=Error: no default remote in manifest file. errorNoDefaultFilename=Error: no default remote in manifest file {0}. +errorNoFetch=Error: remote {0} is missing fetch attribute. errorParsingManifestFile=Error occurred during parsing manifest file. errorRemoteUnavailable=Error remote {0} is unavailable. invalidManifest=Invalid manifest. diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java index 26210ecbb9..94c8e437c3 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java @@ -46,6 +46,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.net.URISyntaxException; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collections; @@ -124,12 +125,7 @@ public class ManifestParser extends DefaultHandler { this.filename = filename; this.defaultBranch = defaultBranch; this.rootRepo = rootRepo; - - // Strip trailing '/' to match repo behavior. - while (baseUrl.endsWith("/")) { //$NON-NLS-1$ - baseUrl = baseUrl.substring(0, baseUrl.length()-1); - } - this.baseUrl = URI.create(baseUrl); + this.baseUrl = normalizeEmptyPath(URI.create(baseUrl)); plusGroups = new HashSet<>(); minusGroups = new HashSet<>(); @@ -257,7 +253,7 @@ public class ManifestParser extends DefaultHandler { return; // Only do the following after we finished reading everything. - Map<String, String> remoteUrls = new HashMap<>(); + Map<String, URI> remoteUrls = new HashMap<>(); if (defaultRevision == null && defaultRemote != null) { Remote remote = remotes.get(defaultRemote); if (remote != null) { @@ -287,15 +283,18 @@ public class ManifestParser extends DefaultHandler { revision = r.revision; } } - String remoteUrl = remoteUrls.get(remote); + URI remoteUrl = remoteUrls.get(remote); if (remoteUrl == null) { - remoteUrl = baseUrl.resolve(remotes.get(remote).fetch).toString(); - if (!remoteUrl.endsWith("/")) //$NON-NLS-1$ - remoteUrl = remoteUrl + "/"; //$NON-NLS-1$ + String fetch = remotes.get(remote).fetch; + if (fetch == null) { + throw new SAXException(MessageFormat + .format(RepoText.get().errorNoFetch, remote)); + } + remoteUrl = normalizeEmptyPath(baseUrl.resolve(fetch)); remoteUrls.put(remote, remoteUrl); } - proj.setUrl(remoteUrl + proj.getName()) - .setDefaultRevision(revision); + proj.setUrl(remoteUrl.resolve(proj.getName()).toString()) + .setDefaultRevision(revision); } filteredProjects.addAll(projects); @@ -303,6 +302,23 @@ public class ManifestParser extends DefaultHandler { removeOverlaps(); } + static URI normalizeEmptyPath(URI u) { + // URI.create("scheme://host").resolve("a/b") => "scheme://hosta/b" + // That seems like bug https://bugs.openjdk.java.net/browse/JDK-4666701. + // We workaround this by special casing the empty path case. + if (u.getHost() != null && !u.getHost().isEmpty() && + (u.getPath() == null || u.getPath().isEmpty())) { + try { + return new URI(u.getScheme(), + u.getUserInfo(), u.getHost(), u.getPort(), + "/", u.getQuery(), u.getFragment()); //$NON-NLS-1$ + } catch (URISyntaxException x) { + throw new IllegalArgumentException(x.getMessage(), x); + } + } + return u; + } + /** * Getter for projects. * diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/internal/RepoText.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/internal/RepoText.java index 36b6e3aac4..02a2565bdd 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/internal/RepoText.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/internal/RepoText.java @@ -64,6 +64,7 @@ public class RepoText extends TranslationBundle { /***/ public String errorIncludeNotImplemented; /***/ public String errorNoDefault; /***/ public String errorNoDefaultFilename; + /***/ public String errorNoFetch; /***/ public String errorParsingManifestFile; /***/ public String errorRemoteUnavailable; /***/ public String invalidManifest; |