use of org.tigris.subversion.subclipse.core.client.OperationProgressNotifyListener in project subclipse by subclipse.
the class CheckinResourcesCommand method run.
/* (non-Javadoc)
* @see org.tigris.subversion.subclipse.core.commands.ISVNCommand#run(org.eclipse.core.runtime.IProgressMonitor)
*/
public void run(IProgressMonitor monitor) throws SVNException {
commitError = false;
postCommitError = null;
final ISVNClientAdapter svnClient = root.getRepository().getSVNClient();
OperationManager.getInstance().beginOperation(svnClient, new OperationProgressNotifyListener(monitor, svnClient));
try {
// Prepare the parents list
// we will Auto-commit parents if they are not already commited
List<IContainer> parentsList = new ArrayList<IContainer>();
List<IProject> projectList = new ArrayList<IProject>();
for (IResource currentResource : resources) {
IProject project = currentResource.getProject();
if (!projectList.contains(project)) {
projectList.add(project);
}
IContainer parent = currentResource.getParent();
ISVNLocalResource svnParentResource = SVNWorkspaceRoot.getSVNResourceFor(parent);
while (parent.getType() != IResource.ROOT && parent.getType() != IResource.PROJECT && !svnParentResource.hasRemote()) {
if (!inCommitList(parent))
parentsList.add(parent);
parent = parent.getParent();
svnParentResource = svnParentResource.getParent();
}
}
// convert parents and resources to an array of File
int parents = parentsList.size();
// change commit to non-recursive!!
if (parents > 0)
depth = IResource.DEPTH_ZERO;
final File[] resourceFiles = new File[parents + resources.length];
for (int i = 0; i < parents; i++) {
resourceFiles[i] = ((IResource) parentsList.get(i)).getLocation().toFile();
}
for (int i = 0, j = parents; i < resources.length; i++, j++) {
resourceFiles[j] = resources[i].getLocation().toFile();
}
IProject[] projects = new IProject[projectList.size()];
projectList.toArray(projects);
ISchedulingRule rule = MultiRule.combine(projects);
SVNProviderPlugin.run(new ISVNRunnable() {
public void run(final IProgressMonitor pm) throws SVNException {
try {
notifyListener = new ISVNNotifyListener() {
public void logCommandLine(String commandLine) {
}
public void logCompleted(String message) {
}
public void logError(String message) {
}
public void logMessage(String message) {
if (message.startsWith("Transmitting file data"))
pm.subTask(message);
}
public void logRevision(long revision, String path) {
}
public void onNotify(File path, SVNNodeKind kind) {
}
public void setCommand(int command) {
}
};
pm.beginTask(null, resourceFiles.length);
pm.setTaskName("Checking in...");
svnClient.addNotifyListener(operationResourceCollector);
svnClient.addNotifyListener(notifyListener);
// then the resources the user has requested to commit
if (svnClient.canCommitAcrossWC())
svnClient.commitAcrossWC(resourceFiles, message, depth == IResource.DEPTH_INFINITE, keepLocks, true);
else
svnClient.commit(resourceFiles, message, depth == IResource.DEPTH_INFINITE, keepLocks);
postCommitError = svnClient.getPostCommitError();
} catch (SVNClientException e) {
commitError = true;
throw SVNException.wrapException(e);
} finally {
pm.done();
if (svnClient != null) {
svnClient.removeNotifyListener(operationResourceCollector);
svnClient.removeNotifyListener(notifyListener);
root.getRepository().returnSVNClient(svnClient);
}
}
}
}, rule, Policy.monitorFor(monitor));
} finally {
OperationManager.getInstance().endOperation(true, operationResourceCollector.getOperationResources(), !commitError);
}
}
use of org.tigris.subversion.subclipse.core.client.OperationProgressNotifyListener in project subclipse by subclipse.
the class CheckoutCommand method basicRun.
protected void basicRun(final IProject project, ISVNRemoteFolder resource, final IProgressMonitor pm) throws SVNException {
ISVNClientAdapter svnClient = null;
if (pm != null) {
pm.beginTask(null, 1000);
}
try {
// Perform the checkout
boolean createProject = false;
svnClient = resource.getRepository().getSVNClient();
OperationManager.getInstance().beginOperation(svnClient, new OperationProgressNotifyListener(pm, svnClient));
// Prepare the target projects to receive resources
scrubProject(resource, project, (pm != null) ? Policy.subMonitorFor(pm, 100) : null);
File destPath;
if (project.getLocation() == null) {
// not exist in the workspace
if (projectRoot == null) {
ISVNLocalFolder root = SVNWorkspaceRoot.getSVNFolderFor(ResourcesPlugin.getWorkspace().getRoot());
destPath = new File(root.getIResource().getLocation().toFile(), project.getName());
} else {
destPath = new File(projectRoot.toFile(), project.getName());
}
if (!destPath.exists()) {
destPath.mkdirs();
}
createProject = true;
} else {
if (projectRoot != null) {
try {
destPath = new File(projectRoot.toFile(), project.getName());
setProjectToRoot(project, destPath);
} catch (CoreException e) {
throw new SVNException("Cannot create project to checkout to", e);
}
} else {
destPath = project.getLocation().toFile();
}
}
if (createProject) {
createProjectList.add(project);
}
checkoutProject(pm, resource, svnClient, destPath);
SVNWorkspaceRoot.setManagedBySubclipse(project);
if (refreshProjects) {
try {
project.create(null);
project.open(null);
} catch (CoreException e1) {
throw new SVNException("Cannot create project to checkout to", e1);
}
refreshProject(project, (pm != null) ? Policy.subMonitorFor(pm, 100) : null);
} else {
manageProjectList.add(project);
}
} finally {
resource.getRepository().returnSVNClient(svnClient);
if (pm != null) {
pm.done();
}
}
}
use of org.tigris.subversion.subclipse.core.client.OperationProgressNotifyListener in project subclipse by subclipse.
the class AddResourcesCommand method run.
/* (non-Javadoc)
* @see org.tigris.subversion.subclipse.core.commands.ISVNCommand#run(org.eclipse.core.runtime.IProgressMonitor)
*/
public void run(IProgressMonitor monitor) throws SVNException {
monitor = Policy.monitorFor(monitor);
// Visit the children of the resources using the depth in order to
// determine which folders, text files and binary files need to be added
// A TreeSet is needed for the folders so they are in the right order (i.e. parents created
// before children)
final SortedSet<ISVNLocalResource> folders = new TreeSet<ISVNLocalResource>();
// Sets are required for the files to ensure that files will not appear twice if there parent
// was added as well
// and the depth isn't zero
final HashSet<ISVNLocalResource> files = new HashSet<ISVNLocalResource>();
for (int i = 0; i < resources.length; i++) {
final IResource currentResource = resources[i];
try {
// Auto-add parents if they are not already managed
IContainer parent = currentResource.getParent();
ISVNLocalResource svnParentResource = SVNWorkspaceRoot.getSVNResourceFor(parent);
while (parent.getType() != IResource.ROOT && parent.getType() != IResource.PROJECT && !svnParentResource.isManaged()) {
folders.add(svnParentResource);
parent = parent.getParent();
svnParentResource = svnParentResource.getParent();
}
// Auto-add children accordingly to depth
final SVNException[] exception = new SVNException[] { null };
currentResource.accept(new IResourceVisitor() {
public boolean visit(IResource resource) {
try {
ISVNLocalResource mResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
// added explicitly (is equal currentResource) or is not ignored
if ((!mResource.isManaged()) && (currentResource.equals(resource) || !mResource.isIgnored())) {
if (resource.getType() == IResource.FILE) {
files.add(mResource);
} else {
folders.add(mResource);
}
}
// Always return true and let the depth determine if children are visited
return true;
} catch (SVNException e) {
exception[0] = e;
return false;
}
}
}, depth, false);
if (exception[0] != null) {
throw exception[0];
}
} catch (CoreException e) {
throw new SVNException(new Status(IStatus.ERROR, SVNProviderPlugin.ID, TeamException.UNABLE, Policy.bind("SVNTeamProvider.visitError", new Object[] { resources[i].getFullPath() }), // $NON-NLS-1$
e));
}
}
// for
// If an exception occured during the visit, throw it here
// Add the folders, followed by files!
ISVNClientAdapter svnClient = root.getRepository().getSVNClient();
monitor.beginTask(null, files.size() + folders.size());
monitor.setTaskName("Adding...");
svnClient.addNotifyListener(operationResourceCollector);
OperationManager.getInstance().beginOperation(svnClient, new OperationProgressNotifyListener(monitor, svnClient));
try {
for (ISVNLocalResource localResource : folders) {
try {
svnClient.addDirectory(localResource.getIResource().getLocation().toFile(), false);
localResource.refreshStatus();
} catch (SVNClientException e) {
throw SVNException.wrapException(e);
}
}
for (ISVNLocalResource localResource : files) {
try {
svnClient.addFile(localResource.getIResource().getLocation().toFile());
// If file has read-only attribute set, remove it
ResourceAttributes attrs = localResource.getIResource().getResourceAttributes();
if (localResource.getIResource().getType() == IResource.FILE && attrs.isReadOnly()) {
attrs.setReadOnly(false);
try {
localResource.getIResource().setResourceAttributes(attrs);
} catch (CoreException swallow) {
}
}
} catch (SVNClientException e) {
throw SVNException.wrapException(e);
}
}
} finally {
Set<IResource> operationResources = operationResourceCollector.getOperationResources();
OperationManager.getInstance().endOperation(true, operationResources);
monitor.done();
if (svnClient != null) {
svnClient.removeNotifyListener(operationResourceCollector);
root.getRepository().returnSVNClient(svnClient);
}
}
}
use of org.tigris.subversion.subclipse.core.client.OperationProgressNotifyListener in project subclipse by subclipse.
the class ImportCommand method run.
/* (non-Javadoc)
* @see org.tigris.subversion.subclipse.core.commands.ISVNCommand#run(org.eclipse.core.runtime.IProgressMonitor)
*/
public void run(IProgressMonitor monitor) throws SVNException {
final IProgressMonitor subPm = Policy.infiniteSubMonitorFor(monitor, 100);
ISVNClientAdapter svnClient = null;
try {
subPm.beginTask(null, Policy.INFINITE_PM_GUESS_FOR_SWITCH);
svnClient = folder.getRepository().getSVNClient();
OperationManager.getInstance().beginOperation(svnClient, new OperationProgressNotifyListener(subPm, svnClient));
svnClient.doImport(dir, folder.getUrl(), comment, recurse);
} catch (SVNClientException e) {
throw SVNException.wrapException(e);
} finally {
folder.getRepository().returnSVNClient(svnClient);
OperationManager.getInstance().endOperation();
subPm.done();
}
}
use of org.tigris.subversion.subclipse.core.client.OperationProgressNotifyListener in project subclipse by subclipse.
the class MergeCommand method run.
public void run(IProgressMonitor monitor) throws SVNException {
ISVNClientAdapter svnClient = null;
try {
monitor.beginTask(null, 100);
svnClient = root.getRepository().getSVNClient();
OperationManager.getInstance().beginOperation(svnClient, new OperationProgressNotifyListener(monitor, svnClient));
monitor.subTask(resource.getName());
File file = resource.getLocation().toFile();
svnClient.merge(svnUrl1, svnRevision1, svnUrl2, svnRevision2, file, force, recurse, false, ignoreAncestry);
try {
// Refresh the resource after merge
resource.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
} catch (CoreException e1) {
}
monitor.worked(100);
} catch (SVNClientException e) {
throw SVNException.wrapException(e);
} finally {
root.getRepository().returnSVNClient(svnClient);
OperationManager.getInstance().endOperation();
monitor.done();
}
}
Aggregations