From 22f65786e27e44a9c272b7865af550232c6a306a Mon Sep 17 00:00:00 2001
From: ltheussl
Date: Thu, 6 Apr 2006 18:44:01 +0000
Subject: [PATCH] Code reformatting
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@392030 13f79535-47bb-0310-9956-ffa450edef68
---
.../org/apache/maven/xdoc/util/ScmUtil.java | 452 +++++++++++-------
1 file changed, 270 insertions(+), 182 deletions(-)
diff --git a/xdoc/src/main/org/apache/maven/xdoc/util/ScmUtil.java b/xdoc/src/main/org/apache/maven/xdoc/util/ScmUtil.java
index 5fdd23c4..318113e2 100644
--- a/xdoc/src/main/org/apache/maven/xdoc/util/ScmUtil.java
+++ b/xdoc/src/main/org/apache/maven/xdoc/util/ScmUtil.java
@@ -21,38 +21,41 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
-import org.apache.maven.scm.provider.cvslib.CvsScmProvider;
-import org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository;
-import org.apache.maven.scm.provider.svn.SvnScmProvider;
-import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
import org.apache.maven.scm.provider.clearcase.ClearCaseScmProvider;
import org.apache.maven.scm.provider.clearcase.repository.ClearCaseScmProviderRepository;
+import org.apache.maven.scm.provider.cvslib.CvsScmProvider;
+import org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository;
import org.apache.maven.scm.provider.perforce.PerforceScmProvider;
import org.apache.maven.scm.provider.perforce.repository.PerforceScmProviderRepository;
import org.apache.maven.scm.provider.starteam.StarteamScmProvider;
import org.apache.maven.scm.provider.starteam.repository.StarteamScmProviderRepository;
+import org.apache.maven.scm.provider.svn.SvnScmProvider;
+import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
import org.apache.maven.scm.repository.ScmRepositoryException;
import org.apache.maven.util.EnhancedStringTokenizer;
/**
* Utility class to manage SCM informations. NOTE: This is very CVS specific,
* but I would like to try additional SCM package like subversion ASAP.
- *
+ *
* @author Jason van Zyl
* @author Arnaud Heritier
* @version $Id$
*/
-public final class ScmUtil {
+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) {
- if (isValid(scmConnection)) {
- return splitSCMConnection(scmConnection)[1];
+ public String getScmType( final String scmConnection )
+ {
+ if ( isValid( scmConnection ) )
+ {
+ return splitSCMConnection( scmConnection )[1];
}
return null;
@@ -65,51 +68,60 @@ public final class ScmUtil {
* (':' 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) {
- String[] tokens = splitSCMConnection(conn);
+ public String getCvsConnection( String conn, String username )
+ {
+ String[] tokens = splitSCMConnection( conn );
- if (!tokens[1].equals("cvs")) {
+ if ( !tokens[1].equals( "cvs" ) )
+ {
return "";
}
- String separator = getSCMConnectionSeparator(conn);
+ String separator = getSCMConnectionSeparator( conn );
- if (tokens[3].indexOf('@') >= 0) {
- if (username.length() == 0) {
- username = tokens[3].substring(0, tokens[3].indexOf('@'))
- + separator;
+ if ( tokens[3].indexOf( '@' ) >= 0 )
+ {
+ if ( username.length() == 0 )
+ {
+ 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] + ":" + tokens[1] + separator + tokens[2]
- + separator + tokens[3] + separator + tokens[4] + separator
- + tokens[5];
+ String result =
+ tokens[0] + ":" + tokens[1] + separator + tokens[2] + separator
+ + tokens[3] + separator + tokens[4] + separator + tokens[5];
return result;
}
/**
* Get cvs module. Used in xdocs/src/plugin-resources/templates/scm/cvs.xml.
- *
+ *
* @param conn
* six token connection string
* @return CVS module.
*/
- public String getCvsModule(String conn) {
- if (isValid(conn)) {
- String[] tokens = splitSCMConnection(conn);
+ public String getCvsModule( String conn )
+ {
+ if ( isValid( conn ) )
+ {
+ String[] tokens = splitSCMConnection( conn );
- if (!tokens[1].equals("cvs")) {
+ if ( !tokens[1].equals( "cvs" ) )
+ {
return "";
}
@@ -123,19 +135,23 @@ public final class ScmUtil {
* Get svn connection string. Used in
* xdocs/src/plugin-resources/templates/scm/svn.xml. It removes the first
* two elements (scm:svn:)
- *
+ *
* @param conn
* the repository connection
* @return CVS root.
*/
- public String getSvnConnection(String conn) {
- if (conn != null && conn.length() > 8
- && "svn".equals(conn.substring(4, 7)))
- return conn.substring(8);
- else {
- System.err
- .println("Your subversion connection does not seem to be valid: "
- + conn);
+ public String getSvnConnection( String conn )
+ {
+ if ( ( conn != null ) && ( conn.length() > 8 )
+ && "svn".equals( conn.substring( 4, 7 ) ) )
+ {
+ return conn.substring( 8 );
+ }
+ else
+ {
+ System.err.println(
+ "Your subversion connection does not seem to be valid: " + conn );
+
return "";
}
}
@@ -151,25 +167,30 @@ public final class ScmUtil {
*/
public String anonymousAccessCVS( String connection )
{
-
- char delim = getSCMConnectionSeparator(connection).charAt(0);
+ char delim = getSCMConnectionSeparator( connection ).charAt( 0 );
CvsScmProvider cvsProvider = new CvsScmProvider();
CvsScmProviderRepository cvsRepo;
- String scmSpecificUrl = connection.substring(8);
+ String scmSpecificUrl = connection.substring( 8 );
+
+ try
+ {
+ cvsRepo =
+ (CvsScmProviderRepository) cvsProvider
+ .makeProviderScmRepository( scmSpecificUrl, delim );
+ }
+ catch ( ScmRepositoryException e )
+ {
+ System.err.println(
+ "Your developerConnection does not seem to be valid: "
+ + e.getMessage() );
- try {
- cvsRepo = (CvsScmProviderRepository) cvsProvider
- .makeProviderScmRepository(scmSpecificUrl, delim);
- } catch (ScmRepositoryException e) {
- System.err
- .println("Your developerConnection does not seem to be valid: "
- + e.getMessage());
return "";
}
StringBuffer command = new StringBuffer();
+
command.append( "cvs -d " ).append( cvsRepo.getCvsRoot() ).append( " login" );
command.append( "\n" );
command.append( "cvs -z3 -d " ).append( cvsRepo.getCvsRoot() );
@@ -189,32 +210,39 @@ public final class ScmUtil {
*/
public String developerAccessCVS( String devConnection )
{
-
- char delim = getSCMConnectionSeparator(devConnection).charAt(0);
+ char delim = getSCMConnectionSeparator( devConnection ).charAt( 0 );
CvsScmProvider cvsProvider = new CvsScmProvider();
CvsScmProviderRepository cvsRepo;
- String scmSpecificUrl = devConnection.substring(8);
+ String scmSpecificUrl = devConnection.substring( 8 );
+
+ try
+ {
+ cvsRepo =
+ (CvsScmProviderRepository) cvsProvider
+ .makeProviderScmRepository( scmSpecificUrl, delim );
+ }
+ catch ( ScmRepositoryException e )
+ {
+ System.err.println(
+ "Your developerConnection does not seem to be valid: "
+ + e.getMessage() );
- try {
- cvsRepo = (CvsScmProviderRepository) cvsProvider
- .makeProviderScmRepository(scmSpecificUrl, delim);
- } catch (ScmRepositoryException e) {
- System.err
- .println("Your developerConnection does not seem to be valid: "
- + e.getMessage());
return "";
}
-
// Safety: remove the username if present
- String cvsRoot = StringUtils.replace( cvsRepo.getCvsRoot(), cvsRepo.getUser(), "username" );
+ String cvsRoot =
+ StringUtils.replace( cvsRepo.getCvsRoot(), cvsRepo.getUser(),
+ "username" );
StringBuffer command = new StringBuffer();
+
command.append( "export CVS_RSH=ssh" );
command.append( "\n" );
- command.append( "cvs -z3 -d " ).append( cvsRoot ).append( " co " ).append( cvsRepo.getModule() );
+ command.append( "cvs -z3 -d " ).append( cvsRoot ).append( " co " )
+ .append( cvsRepo.getModule() );
return command.toString();
}
@@ -228,28 +256,35 @@ public final class ScmUtil {
* @param checkoutDirectoryName The checkout directory.
* @see http://svnbook.red-bean.com/
*/
- public String anonymousAccessSVN( String connection, String checkoutDirectoryName )
+ public String anonymousAccessSVN( String connection,
+ String checkoutDirectoryName )
{
-
- char delim = getSCMConnectionSeparator(connection).charAt(0);
+ char delim = getSCMConnectionSeparator( connection ).charAt( 0 );
SvnScmProvider svnProvider = new SvnScmProvider();
SvnScmProviderRepository svnRepo;
- String scmSpecificUrl = connection.substring(8);
+ String scmSpecificUrl = connection.substring( 8 );
+
+ try
+ {
+ svnRepo =
+ (SvnScmProviderRepository) svnProvider
+ .makeProviderScmRepository( scmSpecificUrl, delim );
+ }
+ catch ( ScmRepositoryException e )
+ {
+ System.err.println(
+ "Your developerConnection does not seem to be valid: "
+ + e.getMessage() );
- try {
- svnRepo = (SvnScmProviderRepository) svnProvider
- .makeProviderScmRepository(scmSpecificUrl, delim);
- } catch (ScmRepositoryException e) {
- System.err
- .println("Your developerConnection does not seem to be valid: "
- + e.getMessage());
return "";
}
StringBuffer command = new StringBuffer();
- command.append( "svn checkout " ).append( svnRepo.getUrl() ).append( " " ).append( checkoutDirectoryName );
+
+ command.append( "svn checkout " ).append( svnRepo.getUrl() )
+ .append( " " ).append( checkoutDirectoryName );
return command.toString();
}
@@ -264,34 +299,39 @@ public final class ScmUtil {
* @param checkoutDirectoryName The checkout directory.
* @see http://svnbook.red-bean.com/
*/
- public String developerAccessSVN( String devConnection, String checkoutDirectoryName )
+ public String developerAccessSVN( String devConnection,
+ String checkoutDirectoryName )
{
-
- char delim = getSCMConnectionSeparator(devConnection).charAt(0);
+ char delim = getSCMConnectionSeparator( devConnection ).charAt( 0 );
SvnScmProvider svnProvider = new SvnScmProvider();
SvnScmProviderRepository svnRepo;
- String scmSpecificUrl = devConnection.substring(8);
+ String scmSpecificUrl = devConnection.substring( 8 );
+
+ try
+ {
+ svnRepo =
+ (SvnScmProviderRepository) svnProvider
+ .makeProviderScmRepository( scmSpecificUrl, delim );
+ }
+ catch ( ScmRepositoryException e )
+ {
+ System.err.println(
+ "Your developerConnection does not seem to be valid: "
+ + e.getMessage() );
- try {
- svnRepo = (SvnScmProviderRepository) svnProvider
- .makeProviderScmRepository(scmSpecificUrl, delim);
- } catch (ScmRepositoryException e) {
- System.err
- .println("Your developerConnection does not seem to be valid: "
- + e.getMessage());
return "";
}
StringBuffer command = new StringBuffer();
- command.append( "svn checkout " ).append( svnRepo.getUrl() ).append( " " ).append( checkoutDirectoryName );
+ command.append( "svn checkout " ).append( svnRepo.getUrl() )
+ .append( " " ).append( checkoutDirectoryName );
return command.toString();
}
-
/**
* Create the documentation to provide an developer access with a
* Perforce SCM. For example, generate the following command
@@ -302,43 +342,54 @@ public final class ScmUtil {
*
* p4 -H hostname -p port -u username -P password path submit -c changement
*
- *
+ *
* @param devConnection
* @see http://www.perforce.com/perforce/doc.051/manuals/cmdref/index.html>
*/
- public String developerAccessPerforce(String devConnection) {
+ public String developerAccessPerforce( String devConnection )
+ {
StringBuffer command = new StringBuffer();
- char delim = getSCMConnectionSeparator(devConnection).charAt(0);
+ char delim = getSCMConnectionSeparator( devConnection ).charAt( 0 );
PerforceScmProvider perforceProvider = new PerforceScmProvider();
PerforceScmProviderRepository perforceRepo;
- String scmSpecificUrl = devConnection.substring(13);
+ String scmSpecificUrl = devConnection.substring( 13 );
+
+ try
+ {
+ perforceRepo =
+ (PerforceScmProviderRepository) perforceProvider
+ .makeProviderScmRepository( scmSpecificUrl, delim );
+ }
+ catch ( ScmRepositoryException e )
+ {
+ System.err.println(
+ "Your developerConnection does not seem to be valid: "
+ + e.getMessage() );
- try {
- perforceRepo = (PerforceScmProviderRepository) perforceProvider
- .makeProviderScmRepository(scmSpecificUrl, delim);
- } catch (ScmRepositoryException e) {
- System.err
- .println("Your developerConnection does not seem to be valid: "
- + e.getMessage());
return "";
}
- command.append("p4");
- if (!StringUtils.isEmpty(perforceRepo.getHost())) {
- command.append(" -H ").append(perforceRepo.getHost());
+ command.append( "p4" );
+
+ if ( !StringUtils.isEmpty( perforceRepo.getHost() ) )
+ {
+ command.append( " -H " ).append( perforceRepo.getHost() );
}
- if (perforceRepo.getPort() > 0) {
- command.append(" -p " + perforceRepo.getPort());
+
+ if ( perforceRepo.getPort() > 0 )
+ {
+ command.append( " -p " + perforceRepo.getPort() );
}
- command.append(" -u username");
- command.append(" -P password");
- command.append(" ");
- command.append(perforceRepo.getPath());
- command.append("\n");
- command.append("p4 submit -c \"A comment\"");
+
+ command.append( " -u username" );
+ command.append( " -P password" );
+ command.append( " " );
+ command.append( perforceRepo.getPath() );
+ command.append( "\n" );
+ command.append( "p4 submit -c \"A comment\"" );
return command.toString();
}
@@ -357,42 +408,50 @@ public final class ScmUtil {
* stcmd ci -x -nologo -stop -p myusername:mypassword@myhost:1234/projecturl
* -f NCI -is
*
- *
+ *
* @param devConnection
*/
- public String developerAccessStarteam(String devConnection) {
-
+ public String developerAccessStarteam( String devConnection )
+ {
StringBuffer command = new StringBuffer();
- char delim = getSCMConnectionSeparator(devConnection).charAt(0);
+ char delim = getSCMConnectionSeparator( devConnection ).charAt( 0 );
StarteamScmProvider starteamProvider = new StarteamScmProvider();
StarteamScmProviderRepository starteamRepo;
- String scmSpecificUrl = devConnection.substring(13);
+ String scmSpecificUrl = devConnection.substring( 13 );
+
+ try
+ {
+ starteamRepo =
+ (StarteamScmProviderRepository) starteamProvider
+ .makeProviderScmRepository( scmSpecificUrl, delim );
+ }
+ catch ( ScmRepositoryException e )
+ {
+ System.err.println(
+ "Your developerConnection does not seem to be valid: "
+ + e.getMessage() );
- try {
- starteamRepo = (StarteamScmProviderRepository) starteamProvider
- .makeProviderScmRepository(scmSpecificUrl, delim);
- } catch (ScmRepositoryException e) {
- System.err
- .println("Your developerConnection does not seem to be valid: "
- + e.getMessage());
return "";
}
// Safety: remove the username/password if present
- String fullUrl = StringUtils.replace(starteamRepo.getFullUrl(),
- starteamRepo.getUser(), "username");
- fullUrl = StringUtils.replace(fullUrl, starteamRepo.getPassword(),
- "password");
+ String fullUrl =
+ StringUtils.replace( starteamRepo.getFullUrl(),
+ starteamRepo.getUser(), "username" );
- command.append("stcmd co -x -nologo -stop -p ");
- command.append(fullUrl);
- command.append(" -is");
- command.append("\n");
- command.append("stcmd ci -x -nologo -stop -p ");
- command.append(fullUrl);
- command.append(" -f NCI -is");
+ fullUrl =
+ StringUtils.replace( fullUrl, starteamRepo.getPassword(),
+ "password" );
+
+ command.append( "stcmd co -x -nologo -stop -p " );
+ command.append( fullUrl );
+ command.append( " -is" );
+ command.append( "\n" );
+ command.append( "stcmd ci -x -nologo -stop -p " );
+ command.append( fullUrl );
+ command.append( " -f NCI -is" );
return command.toString();
}
@@ -404,77 +463,94 @@ public final class ScmUtil {
*
* cleartool checkout module
*
- *
+ *
* @param devConnection
*/
- public String developerAccessClearCase(String devConnection) {
-
+ public String developerAccessClearCase( String devConnection )
+ {
StringBuffer command = new StringBuffer();
- char delim = getSCMConnectionSeparator(devConnection).charAt(0);
+ char delim = getSCMConnectionSeparator( devConnection ).charAt( 0 );
ClearCaseScmProvider clearCaseProvider = new ClearCaseScmProvider();
ClearCaseScmProviderRepository clearCaseRepo;
- String scmSpecificUrl = devConnection.substring(14);
+ String scmSpecificUrl = devConnection.substring( 14 );
+
+ try
+ {
+ clearCaseRepo =
+ (ClearCaseScmProviderRepository) clearCaseProvider
+ .makeProviderScmRepository( scmSpecificUrl, delim );
+ }
+ catch ( ScmRepositoryException e )
+ {
+ System.err.println(
+ "Your developerConnection does not seem to be valid: "
+ + e.getMessage() );
- try {
- clearCaseRepo = (ClearCaseScmProviderRepository) clearCaseProvider
- .makeProviderScmRepository(scmSpecificUrl, delim);
- } catch (ScmRepositoryException e) {
- System.err
- .println("Your developerConnection does not seem to be valid: "
- + e.getMessage());
return "";
}
- command.append("cleartool checkout ").append(
- clearCaseRepo.getViewName("id"));
+ command.append( "cleartool checkout " ).append( clearCaseRepo
+ .getViewName( "id" ) );
return command.toString();
}
/**
* Splits an SCM string into parts.
- *
+ *
* @param connection
* @return A string array of SCM parts
*/
- public String[] splitSCMConnection(String connection) {
- if (connection == null) {
- throw new NullPointerException("repository connection is null");
+ public String[] splitSCMConnection( String connection )
+ {
+ if ( connection == null )
+ {
+ throw new NullPointerException( "repository connection is null" );
}
- if (connection.length() < 5) {
+ if ( connection.length() < 5 )
+ {
throw new IllegalArgumentException(
- "repository connection is too short");
+ "repository connection is too short" );
}
- if (!connection.startsWith("scm:")) {
+ if ( !connection.startsWith( "scm:" ) )
+ {
throw new IllegalArgumentException(
- "repository connection must start with scm:");
+ "repository connection must start with scm:" );
}
- String delimiter = getSCMConnectionSeparator(connection);
+ String delimiter = getSCMConnectionSeparator( connection );
// 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 modifiedConnection =
+ "scm" + delimiter + connection.substring( 4 );
- EnhancedStringTokenizer tok = new EnhancedStringTokenizer(
- modifiedConnection, delimiter);
+ EnhancedStringTokenizer tok =
+ new EnhancedStringTokenizer( modifiedConnection, delimiter );
- String[] tokens = tokenizerToArray(tok);
+ String[] tokens = tokenizerToArray( tok );
// for a valid repository, it should be scm: at least
- if ((tokens.length >= 1) && tokens[1].equals("cvs")) {
- if ((tokens.length >= 2) && tokens[2].equals("local")) {
- if (tokens.length == 6) {
- if ((tokens[3].length() > 0) && !tokens[3].equals("local")) {
+ if ( ( tokens.length >= 1 ) && tokens[1].equals( "cvs" ) )
+ {
+ 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");
+ "cvs local repository connection string must specify 5 tokens, or an empty 3rd token if 6" );
}
- } else if (tokens.length == 5) {
+ }
+ else if ( tokens.length == 5 )
+ {
String[] newTokens = new String[6];
newTokens[0] = tokens[0];
@@ -484,15 +560,18 @@ public final class ScmUtil {
newTokens[4] = tokens[3];
newTokens[5] = tokens[4];
tokens = newTokens;
- } else {
+ }
+ else
+ {
throw new IllegalArgumentException(
- "cvs local repository connection string doesn't contain five tokens");
+ "cvs local repository connection string doesn't contain five tokens" );
}
}
- if (tokens.length != 6) {
+ 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" );
}
}
@@ -501,18 +580,23 @@ public final class ScmUtil {
/**
* 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");
+ public String getSCMConnectionSeparator( String connection )
+ {
+ if ( connection == null )
+ {
+ throw new NullPointerException( "repository connection is null" );
}
- if (connection.indexOf("|") != -1) {
+ if ( connection.indexOf( "|" ) != -1 )
+ {
return "|";
- } else {
+ }
+ else
+ {
return ":";
}
}
@@ -520,31 +604,35 @@ public final class ScmUtil {
/**
* 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()) {
- l.add(tok.nextToken());
+ while ( tok.hasMoreTokens() )
+ {
+ 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) {
- if ((value != null) && !value.trim().equals("")) {
+ protected boolean isValid( String value )
+ {
+ if ( ( value != null ) && !value.trim().equals( "" ) )
+ {
return true;
}