public ScmResult executeBranchCommand( ScmProviderRepository repo, ScmFileSet fileSet, String branch, ScmBranchParameters scmBranchParameters )
throws ScmException
{
if ( branch == null || StringUtils.isEmpty( branch.trim() ) )
{
throw new ScmException( "branch name must be specified" );
}
if ( !fileSet.getFileList().isEmpty() )
{
throw new ScmException( "This provider doesn't support branching subsets of a directory" );
}
SvnScmProviderRepository repository = (SvnScmProviderRepository) repo;
File messageFile = FileUtils.createTempFile( "maven-scm-", ".commit", null );
try
{
FileUtils.fileWrite( messageFile.getAbsolutePath(), scmBranchParameters.getMessage() );
}
catch ( IOException ex )
{
return new BranchScmResult( null, "Error while making a temporary file for the commit message: "
+ ex.getMessage(), null, false );
}
Commandline cl = createCommandLine( repository, fileSet.getBasedir(), branch, messageFile, scmBranchParameters );
CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
if ( getLogger().isInfoEnabled() )
{
getLogger().info( "Executing: " + SvnCommandLineUtils.cryptPassword( cl ) );
getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() );
}
int exitCode;
try
{
exitCode = SvnCommandLineUtils.execute( cl, stdout, stderr, getLogger() );
}
catch ( CommandLineException ex )
{
throw new ScmException( "Error while executing command.", ex );
}
finally
{
try
{
FileUtils.forceDelete( messageFile );
}
catch ( IOException ex )
{
// ignore
}
}
if ( exitCode != 0 )
{
return new BranchScmResult( cl.toString(), "The svn branch command failed.", stderr.getOutput(), false );
}
List<ScmFile> fileList = new ArrayList<ScmFile>();
List<File> files = null;
try
{
@SuppressWarnings( "unchecked" )
List<File> listFiles = FileUtils.getFiles( fileSet.getBasedir(), "**", "**/.svn/**", false );
files = listFiles;
}
catch ( IOException e )
{
throw new ScmException( "Error while executing command.", e );
}
for ( File f : files )
{
fileList.add( new ScmFile( f.getPath(), ScmFileStatus.TAGGED ) );