private ReleaseResult performCheckout( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment,
List<MavenProject> reactorProjects )
throws ReleaseExecutionException, ReleaseFailureException, ScmException
{
ReleaseResult result = new ReleaseResult();
logInfo( result, "Checking out the project to perform the release ..." );
ScmRepository repository;
ScmProvider provider;
try
{
repository = scmRepositoryConfigurator.getConfiguredRepository( releaseDescriptor,
releaseEnvironment.getSettings() );
provider = scmRepositoryConfigurator.getRepositoryProvider( repository );
}
catch ( ScmRepositoryException e )
{
result.setResultCode( ReleaseResult.ERROR );
logError( result, e.getMessage() );
throw new ReleaseScmRepositoryException( e.getMessage(), e.getValidationMessages() );
}
catch ( NoSuchScmProviderException e )
{
result.setResultCode( ReleaseResult.ERROR );
logError( result, e.getMessage() );
throw new ReleaseExecutionException( "Unable to configure SCM repository: " + e.getMessage(), e );
}
MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects );
// TODO: sanity check that it is not . or .. or lower
File checkoutDirectory;
if ( StringUtils.isEmpty( releaseDescriptor.getCheckoutDirectory() ) )
{
checkoutDirectory = new File( rootProject.getFile().getParentFile(), "target/checkout" );
releaseDescriptor.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() );
}
else
{
checkoutDirectory = new File( releaseDescriptor.getCheckoutDirectory() );
}
if ( checkoutDirectory.exists() )
{
try
{
FileUtils.deleteDirectory( checkoutDirectory );
}
catch ( IOException e )
{
result.setResultCode( ReleaseResult.ERROR );
logError( result, e.getMessage() );
throw new ReleaseExecutionException( "Unable to remove old checkout directory: " + e.getMessage(), e );
}
}
checkoutDirectory.mkdirs();
CheckOutScmResult scmResult;
scmResult = provider.checkOut( repository, new ScmFileSet( checkoutDirectory ),
new ScmTag( releaseDescriptor.getScmReleaseLabel() ) );
if ( releaseDescriptor.isLocalCheckout() && !scmResult.isSuccess() )
{
// this is not beautiful but needed to indicate that the execute() method
// should continue in the parent directory
return null;
}
String scmRelativePathProjectDirectory = scmResult.getRelativePathProjectDirectory();
if ( StringUtils.isEmpty( scmRelativePathProjectDirectory ) )
{
String basedir;
try
{
basedir = ReleaseUtil.getCommonBasedir( reactorProjects );
}
catch ( IOException e )
{
throw new ReleaseExecutionException( "Exception occurred while calculating common basedir: "
+ e.getMessage(), e );
}
String rootProjectBasedir = rootProject.getBasedir().getAbsolutePath();
try
{
if ( ReleaseUtil.isSymlink( rootProject.getBasedir() ) )
{
rootProjectBasedir = rootProject.getBasedir().getCanonicalPath();
}
}
catch ( IOException e )
{
throw new ReleaseExecutionException( e.getMessage(), e );
}
if ( rootProjectBasedir.length() > basedir.length() )
{
scmRelativePathProjectDirectory = rootProjectBasedir.substring( basedir.length() + 1 );
}
}
releaseDescriptor.setScmRelativePathProjectDirectory( scmRelativePathProjectDirectory );
if ( !scmResult.isSuccess() )
{
result.setResultCode( ReleaseResult.ERROR );
logError( result, scmResult.getProviderMessage() );
throw new ReleaseScmCommandException( "Unable to checkout from SCM", scmResult );
}
result.setResultCode( ReleaseResult.SUCCESS );
return result;
}