PR: MPXDOC-130
CVS usage page is blank when using Subversion. git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@376558 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
1 parent
91b0e4e0ef
commit
a8a119ccc3
15 files changed
+615
-279
No files matched your search
@@ -33,33 +33,33 @@ import org.apache.maven.util.EnhancedStringTokenizer;
|
||||
*/
|
||||
public final class ScmUtil
|
||||
{
|
||||
|
||||
/**
|
||||
* Get the SCM type.
|
||||
*
|
||||
*
|
||||
* @param scmConnection the scm connection to analyse.
|
||||
* @return the scm type : cvs, svn , ...
|
||||
*/
|
||||
public String getScmType(final String scmConnection)
|
||||
public String getScmType( final String scmConnection )
|
||||
{
|
||||
if (isValid(scmConnection))
|
||||
if ( isValid( scmConnection ) )
|
||||
{
|
||||
return splitSCMConnection(scmConnection)[1];
|
||||
return splitSCMConnection( scmConnection )[1];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cvs root.
|
||||
*
|
||||
*
|
||||
* @param scmConnection the scm connection to analyse.
|
||||
* @return CVS root.
|
||||
*/
|
||||
public String getCvsRoot(String scmConnection)
|
||||
public String getCvsRoot( String scmConnection )
|
||||
{
|
||||
if (isValid(scmConnection))
|
||||
if ( isValid( scmConnection ) )
|
||||
{
|
||||
return getCvsRoot(scmConnection, "");
|
||||
return getCvsRoot( scmConnection, "" );
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -68,21 +68,22 @@ public final class ScmUtil
|
||||
/**
|
||||
* Get cvs server. Used in
|
||||
* xdocs/src/plugin-resources/templates/cvs-usage.xml.
|
||||
*
|
||||
*
|
||||
* @param conn six token connection string
|
||||
* @return CVS module.
|
||||
*/
|
||||
public String getCvsServer(String conn)
|
||||
public String getCvsServer( String conn )
|
||||
{
|
||||
String[] tokens = splitSCMConnection(conn);
|
||||
if (!tokens[1].equals("cvs"))
|
||||
String[] tokens = splitSCMConnection( conn );
|
||||
|
||||
if ( !tokens[1].equals( "cvs" ) )
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
if (tokens[3].indexOf('@') >= 0)
|
||||
if ( tokens[3].indexOf( '@' ) >= 0 )
|
||||
{
|
||||
return tokens[3].substring(tokens[3].indexOf('@') + 1);
|
||||
return tokens[3].substring( tokens[3].indexOf( '@' ) + 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -92,29 +93,34 @@ public final class ScmUtil
|
||||
|
||||
/**
|
||||
* Get cvs root. Used in xdocs/src/plugin-resources/templates/cvs-usage.xml.
|
||||
*
|
||||
*
|
||||
* @param conn six token connection string
|
||||
* @param username username override if non-empty.
|
||||
* @return CVS root.
|
||||
*/
|
||||
public String getCvsRoot(String conn, String username)
|
||||
public String getCvsRoot( String conn, String username )
|
||||
{
|
||||
String[] tokens = splitSCMConnection(conn);
|
||||
String[] tokens = splitSCMConnection( conn );
|
||||
|
||||
if (!tokens[1].equals("cvs"))
|
||||
if ( !tokens[1].equals( "cvs" ) )
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
if (tokens[3].indexOf('@') >= 0)
|
||||
if ( tokens[3].indexOf( '@' ) >= 0 )
|
||||
{
|
||||
if (username.length() == 0)
|
||||
if ( username.length() == 0 )
|
||||
{
|
||||
username = tokens[3].substring(0, tokens[3].indexOf('@'));
|
||||
username = tokens[3].substring( 0, tokens[3].indexOf( '@' ) );
|
||||
}
|
||||
tokens[3] = username + "@" + tokens[3].substring(tokens[3].indexOf('@') + 1);
|
||||
|
||||
tokens[3] =
|
||||
username + "@"
|
||||
+ tokens[3].substring( tokens[3].indexOf( '@' ) + 1 );
|
||||
}
|
||||
|
||||
String result = ":" + tokens[2] + ":" + tokens[3] + ":" + tokens[4];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -125,38 +131,42 @@ public final class ScmUtil
|
||||
* inserts a separator (':' or '|') between the username and '@' to indicate
|
||||
* that there is a password and that it is empty.
|
||||
* If username != "" it replaces username in conn.
|
||||
*
|
||||
*
|
||||
* @param conn six token connection string
|
||||
* @param username username override if non-empty.
|
||||
* @return CVS root.
|
||||
*/
|
||||
public String getCvsConnection(String conn, String username)
|
||||
public String getCvsConnection( String conn, String username )
|
||||
{
|
||||
String[] tokens = splitSCMConnection(conn);
|
||||
String[] tokens = splitSCMConnection( conn );
|
||||
|
||||
if (!tokens[1].equals("cvs"))
|
||||
if ( !tokens[1].equals( "cvs" ) )
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
// The length of conn has already been checked in the call to
|
||||
// splitSCMConnection(conn) above, so it's OK to just extract the char.
|
||||
String separator = "" + conn.charAt(3);
|
||||
String separator = "" + conn.charAt( 3 );
|
||||
|
||||
if (tokens[3].indexOf('@') >= 0)
|
||||
if ( tokens[3].indexOf( '@' ) >= 0 )
|
||||
{
|
||||
if (username.length() == 0)
|
||||
if ( username.length() == 0 )
|
||||
{
|
||||
username = tokens[3].substring(0, tokens[3].indexOf('@'))
|
||||
username =
|
||||
tokens[3].substring( 0, tokens[3].indexOf( '@' ) )
|
||||
+ separator;
|
||||
}
|
||||
tokens[3] = username + "@"
|
||||
+ tokens[3].substring(tokens[3].indexOf('@') + 1);
|
||||
|
||||
tokens[3] =
|
||||
username + "@"
|
||||
+ tokens[3].substring( tokens[3].indexOf( '@' ) + 1 );
|
||||
}
|
||||
|
||||
String result = tokens[0] + separator + tokens[1] + separator
|
||||
+ tokens[2] + separator + tokens[3] + separator + tokens[4]
|
||||
+ separator + tokens[5];
|
||||
String result =
|
||||
tokens[0] + separator + tokens[1] + separator + tokens[2]
|
||||
+ separator + tokens[3] + separator + tokens[4] + separator
|
||||
+ tokens[5];
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -164,20 +174,21 @@ public final class ScmUtil
|
||||
/**
|
||||
* Get cvs module. Used in
|
||||
* xdocs/src/plugin-resources/templates/cvs-usage.xml.
|
||||
*
|
||||
*
|
||||
* @param conn six token connection string
|
||||
* @return CVS module.
|
||||
*/
|
||||
public String getCvsModule(String conn)
|
||||
public String getCvsModule( String conn )
|
||||
{
|
||||
if (isValid(conn))
|
||||
if ( isValid( conn ) )
|
||||
{
|
||||
String[] tokens = splitSCMConnection( conn );
|
||||
|
||||
String[] tokens = splitSCMConnection(conn);
|
||||
if (!tokens[1].equals("cvs"))
|
||||
if ( !tokens[1].equals( "cvs" ) )
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
return tokens[5];
|
||||
}
|
||||
|
||||
@@ -186,73 +197,137 @@ public final class ScmUtil
|
||||
|
||||
/**
|
||||
* Splits an SCM string into parts.
|
||||
*
|
||||
*
|
||||
* @param connection
|
||||
* @return A string array of SCM parts
|
||||
*/
|
||||
public String[] splitSCMConnection(String connection)
|
||||
public String[] splitSCMConnection( String connection )
|
||||
{
|
||||
if (connection == null)
|
||||
if ( connection == null )
|
||||
{
|
||||
throw new NullPointerException("repository connection is null");
|
||||
throw new NullPointerException( "repository connection is null" );
|
||||
}
|
||||
|
||||
if (connection.length() < 4)
|
||||
if ( connection.length() < 5 )
|
||||
{
|
||||
throw new IllegalArgumentException("repository connection is too short");
|
||||
throw new IllegalArgumentException(
|
||||
"repository connection is too short" );
|
||||
}
|
||||
|
||||
if (!connection.startsWith("scm"))
|
||||
if ( !connection.startsWith( "scm:" ) )
|
||||
{
|
||||
throw new IllegalArgumentException("repository connection must start with scm[delim]");
|
||||
throw new IllegalArgumentException(
|
||||
"repository connection must start with scm:" );
|
||||
}
|
||||
|
||||
String delimiter = "" + connection.charAt(3);
|
||||
String delimiter = getSCMConnectionSeparator( connection );
|
||||
|
||||
EnhancedStringTokenizer tok = new EnhancedStringTokenizer(connection, delimiter);
|
||||
// If the tokenizer is going to work correctly then the character
|
||||
// following "scm" must be the same as the delimiter, which is not
|
||||
// always the case. Therefor we give it a modified connection.
|
||||
String modifiedConnection =
|
||||
"scm" + delimiter + connection.substring( 4 );
|
||||
|
||||
String[] tokens = tokenizerToArray(tok);
|
||||
EnhancedStringTokenizer tok =
|
||||
new EnhancedStringTokenizer( modifiedConnection, delimiter );
|
||||
|
||||
String[] tokens = tokenizerToArray( tok );
|
||||
|
||||
// for a valid repository, it should be scm:<provider> at least
|
||||
if (tokens.length >= 1 && tokens[1].equals("cvs"))
|
||||
if ( ( tokens.length >= 1 ) && tokens[1].equals( "cvs" ) )
|
||||
{
|
||||
if (tokens.length != 6)
|
||||
if ( ( tokens.length >= 2 ) && tokens[2].equals( "local" ) )
|
||||
{
|
||||
if ( tokens.length == 6 )
|
||||
{
|
||||
if ( ( tokens[3].length() > 0 )
|
||||
&& !tokens[3].equals( "local" ) )
|
||||
{
|
||||
throw new IllegalArgumentException(
|
||||
"cvs local repository connection string must specify 5 tokens, or an empty 3rd token if 6" );
|
||||
}
|
||||
}
|
||||
else if ( tokens.length == 5 )
|
||||
{
|
||||
String[] newTokens = new String[6];
|
||||
|
||||
newTokens[0] = tokens[0];
|
||||
newTokens[1] = tokens[1];
|
||||
newTokens[2] = tokens[2];
|
||||
newTokens[3] = "";
|
||||
newTokens[4] = tokens[3];
|
||||
newTokens[5] = tokens[4];
|
||||
tokens = newTokens;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException(
|
||||
"cvs local repository connection string doesn't contain five tokens" );
|
||||
}
|
||||
}
|
||||
|
||||
if ( tokens.length != 6 )
|
||||
{
|
||||
throw new IllegalArgumentException(
|
||||
"cvs repository connection string doesn't contain six tokens");
|
||||
"cvs repository connection string doesn't contain six tokens" );
|
||||
}
|
||||
}
|
||||
|
||||
return tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the separator used in an SCM string
|
||||
* @param connection
|
||||
* @return String that can be either ":" or "|"
|
||||
*/
|
||||
public String getSCMConnectionSeparator( String connection )
|
||||
{
|
||||
if ( connection == null )
|
||||
{
|
||||
throw new NullPointerException( "repository connection is null" );
|
||||
}
|
||||
|
||||
if ( connection.indexOf( "|" ) != -1 )
|
||||
{
|
||||
return "|";
|
||||
}
|
||||
else
|
||||
{
|
||||
return ":";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a tokenizer to an array of strings FIXME: This should be in a
|
||||
* string util class.
|
||||
*
|
||||
*
|
||||
* @param tok
|
||||
* @return String[]
|
||||
*/
|
||||
public String[] tokenizerToArray(EnhancedStringTokenizer tok)
|
||||
public String[] tokenizerToArray( EnhancedStringTokenizer tok )
|
||||
{
|
||||
List l = new ArrayList();
|
||||
while (tok.hasMoreTokens())
|
||||
|
||||
while ( tok.hasMoreTokens() )
|
||||
{
|
||||
l.add(tok.nextToken());
|
||||
l.add( tok.nextToken() );
|
||||
}
|
||||
return (String[]) l.toArray(new String[l.size()]);
|
||||
|
||||
return (String[]) l.toArray( new String[l.size()] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple check for a value in the POM. Due to the Jelly swizzling fields that aren't set come
|
||||
* out as empty strings. This will not be required when the new lazy evaluation mechanism is put
|
||||
* in place.
|
||||
*
|
||||
*
|
||||
* @param value POM value to test.
|
||||
* @return Is the value valid.
|
||||
*/
|
||||
protected boolean isValid(String value)
|
||||
protected boolean isValid( String value )
|
||||
{
|
||||
if (value != null && !value.trim().equals(""))
|
||||
if ( ( value != null ) && !value.trim().equals( "" ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user