use of org.tigris.subversion.subclipse.core.ISVNLocalResource in project subclipse by subclipse.
the class SVNFolderCompareEditorInput method prepareInput.
protected Object prepareInput(IProgressMonitor monitor) throws InterruptedException {
final boolean threeWay = ancestor != null;
if (right == null || left == null) {
// $NON-NLS-1$
setMessage(Policy.bind("SVNCompareEditorInput.different"));
return null;
}
initLabels();
final Object[] result = new Object[] { null };
ISVNClientAdapter svnClient = null;
try {
// do the diff
// $NON-NLS-1$
monitor.beginTask(Policy.bind("SVNCompareEditorInput.comparing"), 30);
IProgressMonitor sub = new SubProgressMonitor(monitor, 30);
// $NON-NLS-1$
sub.beginTask(Policy.bind("SVNCompareEditorInput.comparing"), 100);
try {
svnClient = folder1.getRepository().getSVNClient();
SVNDiffSummary[] diffSummary = null;
if (folder1.getRepositoryRelativePath().equals(folder2.getRepositoryRelativePath()) && localResource1 != null) {
IResource resource1 = localResource1.getResource();
if (resource1 != null) {
ISVNLocalResource svnResource1 = SVNWorkspaceRoot.getSVNResourceFor(resource1);
if (svnResource1 != null) {
SVNRevision pegRevision = svnResource1.getRevision();
if (pegRevision != null) {
diffSummary = svnClient.diffSummarize(folder1.getUrl(), pegRevision, folder2.getRevision(), folder1.getRevision(), Depth.infinity, true);
}
}
} else {
diffSummary = svnClient.diffSummarize(folder1.getUrl(), SVNRevision.HEAD, folder2.getRevision(), folder1.getRevision(), Depth.infinity, true);
}
}
if (diffSummary == null)
diffSummary = svnClient.diffSummarize(folder1.getUrl(), folder1.getRevision(), folder2.getUrl(), folder2.getRevision(), Depth.infinity, true);
diffSummary = getDiffSummaryWithSubfolders(diffSummary);
left.setDiffSummary(diffSummary);
right.setDiffSummary(diffSummary);
left.setRoot(true);
right.setRoot(true);
result[0] = new SummaryDifferencer().findDifferences(threeWay, sub, null, ancestor, left, right);
} finally {
sub.done();
}
if (result[0] instanceof DiffNode) {
IDiffElement[] diffs = ((DiffNode) result[0]).getChildren();
if (diffs == null || diffs.length == 0) {
result[0] = null;
}
}
return result[0];
} catch (OperationCanceledException e) {
throw new InterruptedException(e.getMessage());
} catch (Exception e) {
return e.getMessage();
} finally {
folder1.getRepository().returnSVNClient(svnClient);
monitor.done();
}
}
use of org.tigris.subversion.subclipse.core.ISVNLocalResource in project subclipse by subclipse.
the class SVNLocalCompareSummaryInput method getDiffSummary.
private SVNDiffSummary[] getDiffSummary(RemoteResourceStatus[] statuses, ISVNLocalResource resource) {
List diffSummaryList = new ArrayList();
int rootPathLength = resource.getResource().getLocation().toString().length() + 1;
for (int i = 0; i < statuses.length; i++) {
if (statuses[i].getFile() != null && !statuses[i].getNodeKind().equals(SVNNodeKind.DIR)) {
SVNStatusKind textStatus = statuses[i].getTextStatus();
boolean propertyChanges = !statuses[i].getPropStatus().equals(SVNStatusKind.NORMAL) && !statuses[i].getPropStatus().equals(SVNStatusKind.NONE);
boolean localChanges = false;
if (textStatus.equals(SVNStatusKind.NONE) && propertyChanges && statuses[i].getNodeKind().equals(SVNNodeKind.FILE)) {
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(statuses[i].getPath()));
if (file != null) {
ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(file);
try {
LocalResourceStatus localStatus = svnResource.getStatus();
if (localStatus != null) {
localChanges = localStatus.isAdded() || localStatus.isDirty();
}
} catch (SVNException e) {
}
}
}
if (!textStatus.equals(SVNStatusKind.NONE) || !propertyChanges || localChanges) {
SVNDiffKind diffKind = null;
if (statuses[i].getTextStatus().equals(SVNStatusKind.ADDED))
diffKind = SVNDiffKind.ADDED;
else if (statuses[i].getTextStatus().equals(SVNStatusKind.DELETED))
diffKind = SVNDiffKind.DELETED;
else
diffKind = SVNDiffKind.MODIFIED;
SVNDiffSummary diffSummary = new SVNDiffSummary(statuses[i].getPath().substring(rootPathLength).replaceAll("\\\\", "/"), diffKind, propertyChanges, // $NON-NLS-1$ //$NON-NLS-2$
statuses[i].getNodeKind().toInt());
diffSummaryList.add(diffSummary);
}
}
}
SVNDiffSummary[] diffSummaries = new SVNDiffSummary[diffSummaryList.size()];
diffSummaryList.toArray(diffSummaries);
return diffSummaries;
}
use of org.tigris.subversion.subclipse.core.ISVNLocalResource in project subclipse by subclipse.
the class WorkspaceAction method isEnabled.
/**
* The action is enabled for the appropriate resources. This method checks that:
*
* <ol>
* <li>there is no overlap between a selected file and folder (overlapping folders is allowed
* because of logical vs. physical mapping problem in views)
* <li>the state of the resources match the conditions provided by:
* <ul>
* <li>isEnabledForIgnoredResources()
* <li>isEnabledForManagedResources()
* <li>isEnabledForUnManagedResources() (i.e. not ignored and not managed)
* </ul>
* </ol>
*
* @see TeamAction#isEnabled()
*/
protected boolean isEnabled() throws TeamException {
// invoke the inherited method so that overlaps are maintained
IResource[] resources = super.getSelectedResources();
// disable if no resources are selected
if (resources.length == 0)
return false;
// disable properly for single resource enablement
if (!isEnabledForMultipleResources() && resources.length != 1)
return false;
// validate enabled for each resource in the selection
List folderPaths = new ArrayList();
List filePaths = new ArrayList();
for (int i = 0; i < resources.length; i++) {
IResource resource = resources[i];
// only enable for accessible resources
if ((!resource.isAccessible()) && (!isEnabledForInaccessibleResources()))
return false;
// no SVN actions are enabled if the selection contains a linked resource
if (SVNWorkspaceRoot.isLinkedResource(resource))
return false;
// only enable for resources in a project shared with SVN
if (RepositoryProvider.getProvider(resource.getProject(), SVNProviderPlugin.getTypeId()) == null) {
return false;
}
// collect files and folders separately to check for overlap later
IPath resourceFullPath = resource.getFullPath();
if (resource.getType() == IResource.FILE) {
filePaths.add(resourceFullPath);
} else {
folderPaths.add(resourceFullPath);
}
// ensure that resource management state matches what the action requires
ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
if (!isEnabledForSVNResource(svnResource)) {
return false;
}
}
// NOTE: folder overlap must be allowed because of logical vs. physical
if (!folderPaths.isEmpty()) {
for (Iterator fileIter = filePaths.iterator(); fileIter.hasNext(); ) {
IPath resourcePath = (IPath) fileIter.next();
for (Iterator it = folderPaths.iterator(); it.hasNext(); ) {
IPath folderPath = (IPath) it.next();
if (folderPath.isPrefixOf(resourcePath)) {
return false;
}
}
}
}
return true;
}
use of org.tigris.subversion.subclipse.core.ISVNLocalResource in project subclipse by subclipse.
the class SvnWizardUpdatePage method getCommonRoot.
private String getCommonRoot() {
ArrayList<String> urlList = new ArrayList<String>();
for (int i = 0; i < resources.length; i++) {
ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resources[i]);
try {
String anUrl = svnResource.getStatus().getUrlString();
if (anUrl != null)
urlList.add(anUrl);
} catch (SVNException e1) {
}
}
urlStrings = new String[urlList.size()];
urlList.toArray(urlStrings);
if (urlStrings.length == 0)
return null;
String urlString = urlStrings[0];
if (urlStrings.length == 1)
return urlString;
String commonRoot = null;
tag1: for (int i = 0; i < urlString.length(); i++) {
String partialPath = urlString.substring(0, i + 1);
if (partialPath.endsWith("/")) {
// $NON-NLS-1$
for (int j = 1; j < urlStrings.length; j++) {
if (!urlStrings[j].startsWith(partialPath))
break tag1;
}
commonRoot = partialPath.substring(0, i);
}
}
return commonRoot;
}
use of org.tigris.subversion.subclipse.core.ISVNLocalResource in project subclipse by subclipse.
the class GenerateDiffFileOperation method run.
/**
* @see IRunnableWithProgress#run(IProgressMonitor)
*/
public void run(IProgressMonitor monitor) throws InvocationTargetException {
ISVNClientAdapter svnClient = null;
ISVNRepositoryLocation repository = null;
try {
// $NON-NLS-1$
monitor.beginTask("", 500);
// $NON-NLS-1$
monitor.setTaskName(Policy.bind("GenerateSVNDiff.working"));
OutputStream os;
if (toClipboard) {
os = new ByteArrayOutputStream();
} else {
os = new FileOutputStream(outputFile);
}
// $NON-NLS-1$ //$NON-NLS-2$
File tmpFile = File.createTempFile("sub", "");
tmpFile.deleteOnExit();
ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resources[0]);
newFiles = new ArrayList();
if (unaddedResources.length > 0) {
// });
for (int i = 0; i < unaddedResources.length; i++) newFiles.add(unaddedResources[i]);
if (newFiles.size() > 0) {
try {
// associate the resources with their respective RepositoryProvider
Hashtable table = getProviderMapping((IResource[]) newFiles.toArray(new IResource[newFiles.size()]));
Set keySet = table.keySet();
Iterator iterator = keySet.iterator();
while (iterator.hasNext()) {
IProgressMonitor subMonitor = Policy.subMonitorFor(monitor, 100);
SVNTeamProvider provider = (SVNTeamProvider) iterator.next();
List list = (List) table.get(provider);
IResource[] providerResources = (IResource[]) list.toArray(new IResource[list.size()]);
provider.add(providerResources, IResource.DEPTH_INFINITE, subMonitor);
}
} catch (TeamException e) {
throw new InvocationTargetException(e);
}
}
}
repository = svnResource.getRepository();
svnClient = repository.getSVNClient();
try {
monitor.worked(100);
File[] files = getVersionedFiles();
if (selectedResources == null)
svnClient.diff(files, tmpFile, recursive);
else {
if (eclipseFormat) {
HashSet includedResources = new HashSet();
includedResources.addAll(Arrays.asList(unaddedResources));
includedResources.addAll(Arrays.asList(resources));
createEclipsePatch((IResource[]) includedResources.toArray(new IResource[0]), tmpFile, recursive);
} else {
File relativeToPath = null;
if (projectRelative) {
relativeToPath = selectedResources[0].getProject().getLocation().toFile();
} else {
relativeToPath = getRelativeToPath();
if (relativeToPath.isFile()) {
relativeToPath = relativeToPath.getParentFile();
}
}
svnClient.createPatch(files, relativeToPath, tmpFile, recursive);
}
}
monitor.worked(300);
InputStream is = new FileInputStream(tmpFile);
byte[] buffer = new byte[30000];
int length;
while ((length = is.read(buffer)) != -1) {
os.write(buffer, 0, length);
}
is.close();
} finally {
os.close();
}
if (newFiles.size() > 0) {
for (int i = 0; i < newFiles.size(); i++) {
IResource resource = (IResource) newFiles.get(i);
try {
SVNWorkspaceRoot.getSVNResourceFor(resource).revert();
} catch (Exception e) {
}
}
}
boolean emptyDiff = false;
if (toClipboard) {
final ByteArrayOutputStream baos = (ByteArrayOutputStream) os;
if (baos.size() == 0) {
emptyDiff = true;
} else {
Display.getDefault().syncExec(new Runnable() {
public void run() {
TextTransfer plainTextTransfer = TextTransfer.getInstance();
Clipboard clipboard = new Clipboard(shell.getDisplay());
clipboard.setContents(new String[] { baos.toString() }, new Transfer[] { plainTextTransfer });
clipboard.dispose();
}
});
}
} else {
if (outputFile.length() == 0) {
emptyDiff = true;
outputFile.delete();
}
}
// check for empty diff and report
if (emptyDiff) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(shell, // $NON-NLS-1$
Policy.bind("GenerateSVNDiff.noDiffsFoundTitle"), // $NON-NLS-1$
Policy.bind("GenerateSVNDiff.noDiffsFoundMsg"));
}
});
}
} catch (Exception e) {
throw new InvocationTargetException(e);
} finally {
if (repository != null) {
repository.returnSVNClient(svnClient);
}
monitor.done();
}
}
Aggregations