use of org.tigris.subversion.subclipse.core.ISVNLocalResource in project subclipse by subclipse.
the class ResolveTreeConflictWizard method getStatuses.
private ISVNStatus[] getStatuses(boolean getAll) throws SVNException {
if (statuses == null) {
IProject project = treeConflict.getResource().getProject();
if (project == null)
return new ISVNStatus[0];
ISVNLocalResource svnProject = SVNWorkspaceRoot.getSVNResourceFor(project);
GetStatusCommand command = new GetStatusCommand(svnProject, true, getAll);
command.run(new NullProgressMonitor());
statuses = command.getStatuses();
}
return statuses;
}
use of org.tigris.subversion.subclipse.core.ISVNLocalResource in project subclipse by subclipse.
the class ResolveTreeConflictWizard method performFinish.
public boolean performFinish() {
if (mainPage.getReplace()) {
mergeException = null;
try {
BusyIndicator.showWhile(Display.getDefault(), new Runnable() {
public void run() {
try {
svnClient = svnResource.getRepository().getSVNClient();
File file = svnResource.getResource().getLocation().toFile();
svnClient.remove(new File[] { file }, true);
SVNUrl url = new SVNUrl(treeConflict.getConflictDescriptor().getSrcRightVersion().getReposURL() + "/" + treeConflict.getConflictDescriptor().getSrcRightVersion().getPathInRepos());
SVNRevision revision;
int index = treeConflict.getConflictDescriptor().getSrcRightVersion().toString().lastIndexOf(// $NON-NLS-1$
"@");
if (index == -1) {
revision = SVNRevision.HEAD;
} else {
long number = Long.parseLong(treeConflict.getConflictDescriptor().getSrcRightVersion().toString().substring(index + 1));
revision = new SVNRevision.Number(number);
}
svnClient.copy(url, file, revision);
} catch (Exception e) {
mergeException = e;
}
}
});
if (mergeException != null) {
SVNUIPlugin.log(IStatus.ERROR, mergeException.getMessage(), mergeException);
MessageDialog.openError(getShell(), Messages.ResolveTreeConflictWizard_2, mergeException.getMessage());
return false;
}
svnResource.getResource().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
} catch (Exception e) {
SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
MessageDialog.openError(getShell(), Messages.ResolveTreeConflictWizard_2, e.getMessage());
return false;
}
return true;
}
compare = mainPage.getCompare();
if (mainPage.getMergeFromRepository()) {
try {
final SVNUrl url = new SVNUrl(mainPage.getMergeFromUrl());
SVNRevision revision1;
if (treeConflict.getConflictDescriptor().getSrcLeftVersion().getPegRevision() == treeConflict.getConflictDescriptor().getSrcRightVersion().getPegRevision())
revision1 = new SVNRevision.Number(treeConflict.getConflictDescriptor().getSrcLeftVersion().getPegRevision() - 1);
else
revision1 = new SVNRevision.Number(treeConflict.getConflictDescriptor().getSrcLeftVersion().getPegRevision());
final SVNRevision revision2 = new SVNRevision.Number(treeConflict.getConflictDescriptor().getSrcRightVersion().getPegRevision());
if (treeConflict.getConflictDescriptor().getSrcLeftVersion().getPegRevision() == treeConflict.getConflictDescriptor().getSrcRightVersion().getPegRevision())
revision1 = new SVNRevision.Number(treeConflict.getConflictDescriptor().getSrcLeftVersion().getPegRevision() - 1);
final IResource mergeTarget = mainPage.getMergeTarget();
final SVNRevision rev1 = revision1;
svnClient = svnResource.getRepository().getSVNClient();
mergeException = null;
BusyIndicator.showWhile(Display.getDefault(), new Runnable() {
public void run() {
try {
mergePath = mergeTarget.getLocation().toFile();
svnClient.merge(url, rev1, url, revision2, mergePath, true, false, false, true);
try {
// Refresh the resource after merge
if (mergeTarget.getParent() != null)
mergeTarget.getParent().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
else
mergeTarget.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
} catch (CoreException e1) {
}
} catch (Exception e) {
mergeException = e;
}
}
});
if (mergeException != null) {
SVNUIPlugin.log(IStatus.ERROR, mergeException.getMessage(), mergeException);
MessageDialog.openError(getShell(), Messages.ResolveTreeConflictWizard_mergeError, mergeException.getMessage());
return false;
}
} catch (Exception e) {
SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
MessageDialog.openError(getShell(), Messages.ResolveTreeConflictWizard_mergeError, e.getMessage());
return false;
} finally {
svnResource.getRepository().returnSVNClient(svnClient);
}
}
if (mainPage.getCompare()) {
if (mainPage.getCompareResource2() == null) {
ISVNLocalResource svnCompareResource = mainPage.getSvnCompareResource();
if (svnCompareResource == null)
svnCompareResource = svnResource;
ISVNRemoteResource remoteResource = mainPage.getRemoteResource();
try {
// $NON-NLS-1$ //$NON-NLS-2$
File file = File.createTempFile("revision", ".diff");
file.deleteOnExit();
File path = new File(svnCompareResource.getResource().getLocation().toString());
SVNUrl toUrl = remoteResource.getUrl();
SVNRevision toRevision = remoteResource.getRevision();
ShowDifferencesAsUnifiedDiffOperationWC operation = new ShowDifferencesAsUnifiedDiffOperationWC(targetPart, path, toUrl, toRevision, file);
SVNLocalCompareInput compareInput = new SVNLocalCompareInput(svnCompareResource, remoteResource);
compareInput.setDiffOperation(operation);
CompareUI.openCompareEditorOnPage(compareInput, targetPart.getSite().getPage());
CompareCloseListener closeListener = new CompareCloseListener(Messages.ResolveTreeConflictWizard_compare + svnCompareResource.getName() + // $NON-NLS-1$
" <workspace>");
targetPart.getSite().getPage().addPartListener(closeListener);
} catch (Exception e) {
SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
MessageDialog.openError(getShell(), Messages.ResolveTreeConflictWizard_compareError, e.getMessage());
return false;
}
} else {
ISelection selection = new IStructuredSelection() {
public Object getFirstElement() {
return mainPage.getCompareResource1();
}
public Iterator iterator() {
return toList().iterator();
}
public int size() {
return 2;
}
public Object[] toArray() {
IResource[] compareResources = { mainPage.getCompareResource1(), mainPage.getCompareResource2() };
return compareResources;
}
public List toList() {
List compareList = new ArrayList();
compareList.add(mainPage.getCompareResource1());
compareList.add(mainPage.getCompareResource2());
return compareList;
}
public boolean isEmpty() {
return false;
}
};
CompareAction compareAction = new CompareAction();
compareAction.setActivePart(null, targetPart);
IAction action = new Action() {
};
compareAction.selectionChanged(action, selection);
compareAction.run(selection);
CompareCloseListener closeListener = new CompareCloseListener(Messages.ResolveTreeConflictWizard_compare2 + mainPage.getCompareResource1().getName() + "' - '" + mainPage.getCompareResource2().getName() + // $NON-NLS-1$ //$NON-NLS-2$
"')");
targetPart.getSite().getPage().addPartListener(closeListener);
}
}
if (mainPage.getRevertResource() != null) {
revertException = null;
BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {
public void run() {
try {
IResource[] revertResources = { mainPage.getRevertResource() };
RevertResourcesCommand revertCommand = new RevertResourcesCommand(svnResource.getWorkspaceRoot(), revertResources);
revertCommand.run(new NullProgressMonitor());
} catch (Exception e) {
revertException = e;
}
}
});
if (revertException != null) {
SVNUIPlugin.log(IStatus.ERROR, revertException.getMessage(), revertException);
MessageDialog.openError(getShell(), Messages.ResolveTreeConflictWizard_revertError, revertException.getMessage());
return false;
}
}
if (mainPage.getDeleteResource() != null) {
try {
mainPage.getDeleteResource().delete(true, new NullProgressMonitor());
} catch (CoreException e) {
SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
MessageDialog.openError(getShell(), Messages.ResolveTreeConflictWizard_deleteError, e.getMessage());
return false;
}
}
if (mainPage.getMarkResolved() || mainPage.refreshConflicts()) {
try {
if (mainPage.getMarkResolved()) {
IResource[] resolvedResources = { treeConflict.getResource() };
ResolveOperation resolveOperation = new ResolveOperation(targetPart, resolvedResources, ISVNConflictResolver.Choice.chooseMerged) {
protected boolean canRunAsJob() {
return false;
}
};
resolveOperation.run();
}
if (mainPage.refreshConflicts()) {
IResource[] refreshResources = { svnResource.getResource() };
TreeConflictsView.refresh(refreshResources);
}
} catch (Exception e) {
SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
MessageDialog.openError(getShell(), Messages.ResolveTreeConflictWizard_markResolvedError, e.getMessage());
return false;
}
}
return true;
}
use of org.tigris.subversion.subclipse.core.ISVNLocalResource in project subclipse by subclipse.
the class PropertyCompareLocalResourceNode method getProperties.
public void getProperties(boolean recursive) {
ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
ISVNClientAdapter svnClient = null;
try {
svnClient = svnResource.getRepository().getSVNClient();
properties = svnClient.getProperties(resource.getLocation().toFile(), recursive);
} catch (Exception e) {
SVNUIPlugin.log(Status.ERROR, e.getMessage(), e);
} finally {
svnResource.getRepository().returnSVNClient(svnClient);
}
}
use of org.tigris.subversion.subclipse.core.ISVNLocalResource in project subclipse by subclipse.
the class ResourceEditionNode method getChildren.
/**
* Enumerate children of this node (if any).
*
* @see IStructureComparator#getChildren
*/
public Object[] getChildren() {
if (children == null) {
children = new ResourceEditionNode[0];
ISVNLocalResource mylocalResource = null;
if (localResource instanceof SVNLocalResourceNode) {
mylocalResource = ((SVNLocalResourceNode) localResource).getLocalResource();
try {
if (!mylocalResource.isDirty() && mylocalResource.getResource().getProjectRelativePath().toString().equals(getRemoteResource().getProjectRelativePath()) && mylocalResource.getStatus().getLastChangedRevision().equals(getRemoteResource().getLastChangedRevision())) {
return children;
}
} catch (CoreException e) {
SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
}
}
if (resource != null) {
try {
SVNUIPlugin.runWithProgress(null, true, /* cancelable */
new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException {
try {
ISVNRemoteResource[] members = resource.members(monitor);
List<ResourceEditionNode> nonHiddenChildren = new ArrayList<ResourceEditionNode>();
for (int i = 0; i < members.length; i++) {
if (!ignoreHiddenChanges || members[i].getResource() == null || !Util.isHidden(members[i].getResource(), false)) {
ResourceEditionNode child = new ResourceEditionNode(members[i], pegRevision);
SVNLocalResourceNode localNode = matchLocalResource((ISVNRemoteResource) members[i]);
if (localNode != null) {
child.setLocalResource(localNode);
localNode.setRemoteResource(child);
try {
child.setCharset(localNode.getCharset());
} catch (CoreException e) {
SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
}
}
nonHiddenChildren.add(child);
}
}
children = new ResourceEditionNode[nonHiddenChildren.size()];
nonHiddenChildren.toArray(children);
} catch (TeamException e) {
throw new InvocationTargetException(e);
}
}
});
} catch (InterruptedException e) {
// operation canceled
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
if (t instanceof TeamException) {
SVNUIPlugin.log(((TeamException) t).getStatus());
}
}
}
}
return children;
}
use of org.tigris.subversion.subclipse.core.ISVNLocalResource in project subclipse by subclipse.
the class RevisionAwareDifferencer method compareStatusAndRevisions.
/**
* Compares two nodes to determine if they are equal. Returns NODE_EQUAL of they are the same,
* NODE_NOT_EQUAL if they are different, and NODE_UNKNOWN if comparison was not possible.
*/
protected int compareStatusAndRevisions(Object left, Object right) {
ISVNLocalResource localResource = null;
if (left instanceof SVNLocalResourceNode) {
localResource = ((SVNLocalResourceNode) left).getLocalResource();
}
ISVNRemoteResource edition = null;
if (right instanceof ResourceEditionNode)
edition = ((ResourceEditionNode) right).getRemoteResource();
if (localResource == null || edition == null) {
return NODE_UNKNOWN;
}
// if they're both non-files, they're the same
if (localResource.isFolder() && edition.isContainer()) {
return NODE_EQUAL;
}
// if they have different types, they're different
if (localResource.isFolder() != edition.isContainer()) {
return NODE_NOT_EQUAL;
}
String leftLocation = localResource.getRepository().getLocation();
String rightLocation = edition.getRepository().getLocation();
if (!leftLocation.equals(rightLocation)) {
return NODE_UNKNOWN;
}
LocalResourceStatus localStatus = null;
try {
localStatus = localResource.getStatus();
if (localStatus == null) {
return NODE_UNKNOWN;
}
if (!localResource.isDirty() && localResource.getResource().getProjectRelativePath().toString().equals(edition.getProjectRelativePath()) && localStatus.getLastChangedRevision().equals(edition.getLastChangedRevision())) {
return NODE_EQUAL;
}
if (!localResource.isDirty() && !localResource.isFolder()) {
if (changedResources == null && diffFiles != null) {
parseDiffs();
}
if (changedResources == null) {
for (int i = 0; i < diffSummary.length; i++) {
if (localResource.getResource().getProjectRelativePath().toString().equals(projectRelativePath) || localResource.getResource().getProjectRelativePath().toString().equals(projectRelativePath + diffSummary[i].getPath())) {
return NODE_NOT_EQUAL;
}
}
return NODE_EQUAL;
}
if (changedResources.contains(localResource.getResource().getLocation().toString())) {
return NODE_NOT_EQUAL;
}
return NODE_EQUAL;
}
} catch (SVNException e) {
return NODE_UNKNOWN;
}
return NODE_UNKNOWN;
}
Aggregations