aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@sap.com>2010-10-06 14:02:05 +0200
committerChristian Halstrick <christian.halstrick@sap.com>2010-10-08 06:44:16 +0200
commita1b0ca1807c78d1b715bb68f8f8fa08b797bd4a5 (patch)
treea43d77ab25a69b5ebb2130841744ece523b60114 /org.eclipse.jgit/src/org/eclipse
parent784d388c497efcb4a9b004cf9c97efed14719dd7 (diff)
downloadjgit-a1b0ca1807c78d1b715bb68f8f8fa08b797bd4a5.tar.gz
jgit-a1b0ca1807c78d1b715bb68f8f8fa08b797bd4a5.zip
Introduce commented constants for the segments of an URI regex
The regular expressions used to parse URI's are constructed by concatenating different segments to a big String. Introduce String constants for these segements and document them. Change-Id: If8b9dbaaf57ca333ac0b6c9610c3d3a515c540f9 Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java57
1 files changed, 51 insertions, 6 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java
index 206cc823a4..44ba632d12 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java
@@ -61,19 +61,64 @@ import org.eclipse.jgit.lib.Constants;
* any special character is written as-is.
*/
public class URIish implements Serializable {
+ /**
+ * Part of a pattern which matches the scheme part (git, http, ...) of an
+ * URI. Defines one capturing group containing the scheme without the
+ * trailing colon and slashes
+ */
+ private static final String SCHEME_P = "([a-z][a-z0-9+-]+)://";
+
+ /**
+ * Part of a pattern which matches the optional user/password part (e.g.
+ * root:pwd@ in git://root:pwd@host.xyz/a.git) of URIs. Defines two
+ * capturing groups: the first containing the user and the second containing
+ * the password
+ */
+ private static final String OPT_USER_PWD_P = "(?:([^/]+?)(?::([^/]+?))?@)?";
+
+ /**
+ * Part of a pattern which matches the optional host part of URIs. Defines
+ * one capturing group containing the host name.
+ */
+ private static final String OPT_HOST_P = "(?:([^/]+?))?";
+
+ /**
+ * Part of a pattern which matches the optional port part of URIs. Defines
+ * one capturing group containing the port without the preceding colon.
+ */
+ private static final String OPT_PORT_P = "(?::(\\d+))?";
+
+ /**
+ * Part of a pattern which matches the optional drive letter in paths (e.g.
+ * D: in file:///D:/a.txt). Defines no capturing group.
+ */
+ private static final String OPT_DRIVE_LETTER_P = "(?:[A-Za-z]:)?";
+
+ /**
+ * Part of a pattern which matches a relative path. Relative paths don't
+ * start with slash or drive letters. Defines no capturing group.
+ */
+ private static final String OPT_RELATIVE_PATH_P = "(?:\\.\\.)?";
+
private static final long serialVersionUID = 1L;
+ /**
+ * A pattern matching standard URI: </br>
+ * <code>scheme "://" user_password? hostname? portnumber? path</code>
+ */
private static final Pattern FULL_URI = Pattern.compile("^" //
+ "(?:" //
- + "([a-z][a-z0-9+-]+)://" // optional http://
- + "(?:([^/]+?)(?::([^/]+?))?@)?" // optional user:password@
- + "(?:([^/]+?))?(?::(\\d+))?" // optional example.com:1337
+ + SCHEME_P //
+ + OPT_USER_PWD_P //
+ + OPT_HOST_P //
+ + OPT_PORT_P //
+ ")?" //
- + "(" + "(?:[A-Za-z]:)?" // optional drive-letter:
- + "(?:\\.\\.)?" // optionally a relative path
- + "/.+" //
+ + "(" + OPT_DRIVE_LETTER_P + OPT_RELATIVE_PATH_P + "/.+" //
+ ")$"); // /anything
+ /**
+ * A pattern matching SCP URI's of the form user@host:path/to/repo.git
+ */
private static final Pattern SCP_URI = Pattern.compile("^" //
+ "(?:([^@]+?)@)?" //
+ "([^:]+?)" //