package bluej.groupwork.svn;
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.tigris.subversion.javahl.ClientException;
import org.tigris.subversion.javahl.Depth;
import org.tigris.subversion.javahl.Revision;
import org.tigris.subversion.javahl.SVNClientInterface;
import bluej.groupwork.TeamUtils;
import bluej.groupwork.TeamworkCommandAborted;
import bluej.groupwork.TeamworkCommandError;
import bluej.groupwork.TeamworkCommandResult;
import bluej.utility.Debug;
| Implementation of Subversion commit command, handling forced commits.
|
| @author Davin McCall
|
public class SvnCommitCommand
extends SvnCommitAllCommand{
private Set<File> forceFiles;
private long revision;
public SvnCommitCommand(SvnRepository repository, Set<File> newFiles,
Set<File> binaryNewFiles, Set<File> deletedFiles, Set<File> files,
Set<File> forceFiles, long revision, String commitComment)
{
super(repository, newFiles, binaryNewFiles, deletedFiles, files, commitComment);
this.forceFiles = forceFiles;
this.revision = revision;
}
@Override
protected TeamworkCommandResult doCommand()
{
SVNClientInterface client = getClient();
Set<File> backupSet = new HashSet<File>();
Set<File> deleteMeSet = new HashSet<File>();
Map<File,File> bmap = null;
for (Iterator<File> i = forceFiles.iterator(); i.hasNext(); ) {
File file = i.next();
if (file.exists() && ! deletedFiles.contains(file)) {
backupSet.add(file);
}
else {
deleteMeSet.add(file);
}
}
try {
bmap = TeamUtils.backupFiles(backupSet);
String [] paths = new String[forceFiles.size()];
int j = 0;
for (Iterator<File> i = forceFiles.iterator(); i.hasNext(); ) {
File file = i.next();
paths[j++] = file.getAbsolutePath();
file.delete();
}
client.update(paths, Revision.getInstance(revision), Depth.infinity, false, false, false);
TeamworkCommandResult result = super.doCommand();
return result;
}
catch (IOException ioe) {
return new TeamworkCommandError(ioe.getMessage(), "File I/O error: " + ioe.getLocalizedMessage());
}
catch (ClientException ce) {
if (! isCancelled()) {
return new TeamworkCommandError(ce.getMessage(), ce.getLocalizedMessage());
}
else {
return new TeamworkCommandAborted();
}
}
finally {
if (bmap != null) {
try {
TeamUtils.restoreBackups(bmap);
for (Iterator<File> i = deleteMeSet.iterator(); i.hasNext(); ) {
i.next().delete();
}
}
catch (IOException ioe) {
Debug.message("Failed to restore file after forced commit: " + ioe.getLocalizedMessage());
}
}
}
}
}
top,
use,
map,
class SvnCommitCommand
. SvnCommitCommand
. doCommand
139 neLoCode
+ 2 LoComm