You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by bw...@apache.org on 2003/04/11 20:40:55 UTC
cvs commit: maven/src/java/org/apache/maven/project Repository.java
bwalding 2003/04/11 11:40:55
Modified: src/java/org/apache/maven/project Repository.java
Log:
Some utility functions for processing the connection string
Revision Changes Path
1.12 +64 -1 maven/src/java/org/apache/maven/project/Repository.java
Index: Repository.java
===================================================================
RCS file: /home/cvs/maven/src/java/org/apache/maven/project/Repository.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Repository.java 13 Jan 2003 05:33:10 -0000 1.11
+++ Repository.java 11 Apr 2003 18:40:55 -0000 1.12
@@ -1,5 +1,10 @@
package org.apache.maven.project;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.util.EnhancedStringTokenizer;
+
/* ====================================================================
* The Apache Software License, Version 1.1
*
@@ -145,4 +150,62 @@
return null;
}
+
+
+ /**
+ * Splits an SCM string into parts
+ * @param connection
+ * @return
+ */
+ public static String[] splitSCMConnection(String connection)
+ {
+ if (connection == null)
+ {
+ throw new NullPointerException("repository connection is null");
+ }
+
+ if (connection.length() < 4)
+ {
+ throw new IllegalArgumentException("repository connection is too short");
+ }
+
+ if (!connection.startsWith("scm"))
+ {
+ throw new IllegalArgumentException("repository connection must start with scm[delim]");
+ }
+
+ String delimiter = "" + connection.charAt(3);
+
+ EnhancedStringTokenizer tok = new EnhancedStringTokenizer(connection, delimiter);
+
+ String[] tokens = tokenizerToArray(tok);
+
+ if (tokens.length < 6)
+ {
+ throw new IllegalArgumentException("repository connection string contains less than six tokens");
+ }
+
+ if (tokens.length > 6)
+ {
+ throw new IllegalArgumentException("repository connection string contains more than six tokens");
+ }
+ return tokens;
+ }
+
+ /**
+ * Converts a tokenizer to an array of strings
+ * FIXME: This should be in a string util class
+ * @param tok
+ * @return String[]
+ */
+ public static String[] tokenizerToArray(EnhancedStringTokenizer tok)
+ {
+ List l = new ArrayList();
+ while (tok.hasMoreTokens())
+ {
+ l.add(tok.nextToken());
+ }
+ return (String[]) l.toArray(new String[l.size()]);
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org