use of org.tigris.subversion.subclipse.core.ISVNRunnable 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.ISVNRunnable in project subclipse by subclipse.
the class ShareProjectCommand 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 {
// Determine if the repository is known
boolean alreadyExists = SVNProviderPlugin.getPlugin().getRepositories().isKnownRepository(location.getLocation(), false);
final ISVNClientAdapter svnClient = location.getSVNClient();
try {
// perform the workspace modifications in a runnable
SVNProviderPlugin.run(new ISVNRunnable() {
public void run(IProgressMonitor pm) throws SVNException {
String message;
if (comment == null)
// $NON-NLS-1$
message = Policy.bind("SVNProvider.initialImport");
else
message = comment;
try {
// create the remote dir
SVNUrl url = location.getUrl().appendPath(remoteDirName);
if (createDirectory)
svnClient.mkdir(url, true, message);
try {
OperationManager.getInstance().beginOperation(svnClient, new OperationProgressNotifyListener(pm, svnClient));
// checkout it so that we have .svn
// If directory already existed in repository, do recursive checkout.
svnClient.checkout(url, project.getLocation().toFile(), SVNRevision.HEAD, !createDirectory);
} finally {
OperationManager.getInstance().endOperation();
}
} catch (SVNClientException e) {
throw new SVNException("Error while creating module: " + e.getMessage(), e);
}
// SharingWizard.doesSVNDirectoryExist calls
// getStatus on the folder which populates the
// status cache
// Need to clear the cache so we can get the new
// hasRemote value
SVNProviderPlugin.getPlugin().getStatusCacheManager().refreshStatus(project, true);
try {
// Register it with Team.
RepositoryProvider.map(project, SVNProviderPlugin.getTypeId());
} catch (TeamException e) {
throw new SVNException("Cannot register project with svn provider", e);
}
}
}, monitor);
} catch (SVNException e) {
// its cache
if (!alreadyExists)
SVNProviderPlugin.getPlugin().getRepositories().disposeRepository(location);
throw e;
} finally {
location.returnSVNClient(svnClient);
}
// Add the repository if it didn't exist already
if (!alreadyExists)
SVNProviderPlugin.getPlugin().getRepositories().addOrUpdateRepository(location);
}
use of org.tigris.subversion.subclipse.core.ISVNRunnable in project subclipse by subclipse.
the class LocalFolder method getSVNFolders.
public IFolder[] getSVNFolders(IProgressMonitor monitor, final boolean unmanage) throws SVNException {
final ArrayList<IFolder> svnFolders = new ArrayList<IFolder>();
SVNProviderPlugin.run(new ISVNRunnable() {
public void run(IProgressMonitor pm) throws SVNException {
pm = Policy.monitorFor(pm);
pm.beginTask(null, 100);
ISVNResource[] members = members(Policy.subMonitorFor(pm, 20), FOLDER_MEMBERS | MANAGED_MEMBERS);
ArrayList<IContainer> dirs = new ArrayList<IContainer>();
for (ISVNResource member : members) {
dirs.add((IContainer) ((ISVNLocalResource) member).getIResource());
}
// we add the current folder to the
dirs.add((IContainer) getIResource());
// list : we want to add .svn dir
// for it too
IProgressMonitor monitorDel = Policy.subMonitorFor(pm, 80);
monitorDel.beginTask(null, dirs.size());
for (IContainer container : dirs) {
monitorDel.worked(1);
recursiveGetSVNFolders(container, monitorDel, unmanage);
}
monitorDel.done();
pm.done();
}
private void recursiveGetSVNFolders(IContainer container, IProgressMonitor pm, boolean unmanage) {
try {
// We must not add svn directories for linked resources.
if (container.isLinked())
return;
pm.beginTask(null, 10);
pm.subTask(container.getFullPath().toOSString());
IResource[] members = container.members(true);
for (IResource member : members) {
pm.worked(1);
if (member.getType() != IResource.FILE) {
recursiveGetSVNFolders((IContainer) member, pm, unmanage);
}
}
// Post order traversal
IFolder svnFolder = container.getFolder(new Path(SVNProviderPlugin.getPlugin().getAdminDirectoryName()));
if (svnFolder.exists()) {
svnFolders.add(svnFolder);
if (unmanage) {
try {
svnFolder.delete(true, null);
} catch (CoreException e) {
}
}
}
} catch (CoreException e) {
// Just ignore and continue
} finally {
pm.done();
}
}
}, Policy.subMonitorFor(monitor, 99));
IFolder[] folderArray = new IFolder[svnFolders.size()];
svnFolders.toArray(folderArray);
return folderArray;
}
use of org.tigris.subversion.subclipse.core.ISVNRunnable in project subclipse by subclipse.
the class CheckoutCommand 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 {
try {
for (int i = 0; i < resources.length; i++) {
final IProject project = projects[i];
final ISVNRemoteFolder resource = resources[i];
SVNProviderPlugin.run(new ISVNRunnable() {
public void run(IProgressMonitor pm) throws SVNException {
basicRun(project, resource, pm);
}
}, projects[i], Policy.monitorFor(monitor));
}
} finally {
OperationManager.getInstance().endOperation();
}
}
use of org.tigris.subversion.subclipse.core.ISVNRunnable in project subclipse by subclipse.
the class SwitchToUrlCommand method run.
/* (non-Javadoc)
* @see org.tigris.subversion.subclipse.core.commands.ISVNCommand#run(org.eclipse.core.runtime.IProgressMonitor)
*/
public void run(final IProgressMonitor monitor) throws SVNException {
final ISVNClientAdapter svnClient = root.getRepository().getSVNClient();
OperationManager.getInstance().beginOperation(svnClient, new OperationProgressNotifyListener(monitor, svnClient));
try {
SVNProviderPlugin.run(new ISVNRunnable() {
public void run(IProgressMonitor monitor) throws SVNException {
try {
monitor.beginTask(null, Policy.INFINITE_PM_GUESS_FOR_SWITCH);
if (conflictResolver != null) {
svnClient.addConflictResolutionCallback(conflictResolver);
}
svnClient.addNotifyListener(operationResourceCollector);
File file = resource.getLocation().toFile();
svnClient.switchToUrl(file, svnUrl, svnRevision, svnRevision, depth, setDepth, ignoreExternals, force, ignoreAncestry);
OperationManager.getInstance().onNotify(resource.getLocation().toFile(), SVNNodeKind.UNKNOWN);
} catch (SVNClientException e) {
throw SVNException.wrapException(e);
} finally {
if (svnClient != null) {
if (conflictResolver != null) {
svnClient.addConflictResolutionCallback(null);
}
root.getRepository().returnSVNClient(svnClient);
}
monitor.done();
}
}
}, resource.getProject(), Policy.monitorFor(monitor));
} finally {
Set<IResource> operationResources = operationResourceCollector.getOperationResources();
if (operationResources.size() == 0) {
IResource[] resources = SVNWorkspaceRoot.getResourcesFor(resource);
for (IResource refreshResource : resources) {
operationResources.add(refreshResource);
}
}
OperationManager.getInstance().endOperation(true, operationResources);
}
}
Aggregations