File parentFolder = ( baseDir.getParentFile() != null ) ? baseDir.getParentFile() : baseDir;
// First execute the status command to get the list of changed files.
JazzStatusCommand statusCmd = new JazzStatusCommand();
statusCmd.setLogger( getLogger() );
StatusScmResult statusCmdResult = statusCmd.executeStatusCommand( repo, fileSet );
List<ScmFile> statusScmFiles = statusCmdResult.getChangedFiles();
// In this case, we also use it across multiple calls to "scm diff" so that we
// sum all output into on.
JazzScmCommand diffCmd = null;
StringBuilder patch = new StringBuilder();
Map<String, CharSequence> differences = new HashMap<String, CharSequence>();
// Now lets iterate through them
for ( Iterator<ScmFile> it = statusScmFiles.iterator(); it.hasNext(); )
{
ScmFile file = (ScmFile) it.next();
if ( file.getStatus() == ScmFileStatus.MODIFIED )
{
// The "scm status" command returns files relative to the sandbox root.
// Whereas the "scm diff" command needs them relative to the working directory.
File fullPath = new File( parentFolder, file.getPath() );
String relativePath = fullPath.toString().substring( baseDir.toString().length() );
getLogger().debug( "Full Path : '" + fullPath + "'" );
getLogger().debug( "Relative Path : '" + relativePath + "'" );
// Now call "scm diff on it"
// In this case, we use the DebugLoggerConsumer's ability to store captured output
DebugLoggerConsumer diffConsumer = new DebugLoggerConsumer( getLogger() );
ErrorConsumer errConsumer = new ErrorConsumer( getLogger() );
diffCmd = createDiffCommand( repo, fileSet, relativePath );
int status = diffCmd.execute( diffConsumer, errConsumer );
if ( status != 0 || errConsumer.hasBeenFed() )
{
// Return a false result (not the usual SCMResult)
return new DiffScmResult( diffCmd.toString(), "The scm diff command failed.",
errConsumer.getOutput(), false );
}
// Append to patch (all combined)
patch.append( diffConsumer.getOutput() );
// Set the differences map <File, <CharSequence>
differences.put( relativePath, diffConsumer.getOutput() );
}
}
return new DiffScmResult( diffCmd.toString(), statusCmdResult.getChangedFiles(), differences,
patch.toString() );
}