use of org.tigris.subversion.subclipse.core.ISVNLocalResource 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.ISVNLocalResource in project subclipse by subclipse.
the class LocalResource method getUrl.
/**
* get the url of the resource in the repository The resource does not need to exist in repository
*
* @return the url or null if cannot get the url (when project is not managed)
* @throws SVNException
*/
public SVNUrl getUrl() {
try {
LocalResourceStatus status = getStatusFromCache();
if (status.isManaged()) {
// if the resource is managed, get the url directly
return status.getUrl();
} else {
// otherwise, get the url of the parent
SVNUrl parentUrl = null;
ISVNLocalResource parent = getParent();
if (parent != null) {
parentUrl = parent.getUrl();
}
if (parentUrl == null) {
// we cannot find the url
return null;
}
return parentUrl.appendPath(resource.getName());
}
} catch (SVNException e) {
return null;
}
}
use of org.tigris.subversion.subclipse.core.ISVNLocalResource in project subclipse by subclipse.
the class AliasManager method transformUrl.
public static String transformUrl(IResource resource, Alias alias) {
String aliasUrl = alias.getUrl();
String a;
ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
ISVNRepositoryLocation repository = svnResource.getRepository();
if (svnResource.getUrl().toString().length() <= aliasUrl.length())
a = "";
else
a = svnResource.getUrl().toString().substring(aliasUrl.length());
String b = repository.getUrl().toString();
String c;
if (alias.getRelativePath() == null)
c = "";
else
c = alias.getRelativePath();
return b + c + a;
}
use of org.tigris.subversion.subclipse.core.ISVNLocalResource in project subclipse by subclipse.
the class AliasManager method getAliases.
private Alias[] getAliases(IResource resource, boolean checkParents) {
ArrayList<Alias> aliases = new ArrayList<Alias>();
if (resource != null) {
ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
try {
if (svnResource.isManaged()) {
ISVNProperty property = null;
// $NON-NLS-1$
property = svnResource.getSvnProperty("subclipse:tags");
if (property != null && property.getValue() != null)
getAliases(aliases, property.getValue(), svnResource.getUrl().toString());
if (checkParents) {
IResource checkResource = resource;
while (checkResource.getParent() != null) {
checkResource = checkResource.getParent();
Alias[] parentAliases = getAliases(checkResource, false);
for (Alias parentAlias : parentAliases) {
if (aliases.contains(parentAlias)) {
Alias checkAlias = (Alias) aliases.get(aliases.indexOf(parentAlias));
if (parentAlias.getRevision() < checkAlias.getRevision()) {
aliases.remove(checkAlias);
aliases.add(parentAlias);
}
} else
aliases.add(parentAlias);
}
}
}
}
} catch (SVNException e) {
}
}
Alias[] aliasArray = new Alias[aliases.size()];
aliases.toArray(aliasArray);
return aliasArray;
}
use of org.tigris.subversion.subclipse.core.ISVNLocalResource in project subclipse by subclipse.
the class SVNHistoryPage method inputSet.
public boolean inputSet() {
Object input = getInput();
if (input instanceof IResource) {
IResource res = (IResource) input;
RepositoryProvider teamProvider = RepositoryProvider.getProvider(res.getProject(), SVNProviderPlugin.getTypeId());
if (teamProvider != null) {
try {
ISVNLocalResource localResource = SVNWorkspaceRoot.getSVNResourceFor(res);
LocalResourceStatus localResourceStatus = (localResource != null) ? localResource.getStatus() : null;
if (localResource != null && localResourceStatus.isManaged() && (!localResourceStatus.isAdded() || localResourceStatus.isCopied())) {
this.resource = res;
this.remoteResource = localResource.getBaseResource();
this.projectProperties = ProjectProperties.getProjectProperties(res);
boolean includeBugs = projectProperties != null;
boolean includeTags = tagsPropertySet(res);
if (includeTags != this.includeTags || this.includeBugs != includeBugs) {
this.includeTags = includeTags;
this.includeBugs = includeBugs;
refreshTable();
}
this.historyTableProvider.setRemoteResource(this.remoteResource);
this.historyTableProvider.setProjectProperties(this.projectProperties);
if (historySearchViewerFilter != null) {
// HistorySearchViewerFilter[] filters = { historySearchViewerFilter };
// this.tableHistoryViewer.setFilters(filters);
this.tableHistoryViewer.resetFilters();
this.tableHistoryViewer.addFilter(historySearchViewerFilter);
historySearchDialog = new HistorySearchDialog(getSite().getShell(), remoteResource);
historySearchDialog.setSearchAll(false);
historySearchDialog.setStartRevision(historySearchViewerFilter.getStartRevision());
historySearchDialog.setEndRevision(historySearchViewerFilter.getEndRevision());
historySearchViewerFilter = null;
getClearSearchAction().setEnabled(true);
} else {
this.tableHistoryViewer.resetFilters();
getClearSearchAction().setEnabled(false);
}
this.tableHistoryViewer.setInput(this.remoteResource);
// setTitleToolTip(baseResource.getRepositoryRelativePath());
return true;
}
} catch (TeamException e) {
SVNUIPlugin.openError(getSite().getShell(), null, null, e);
}
}
} else if (input instanceof ISVNRemoteResource) {
this.resource = null;
this.remoteResource = (ISVNRemoteResource) input;
boolean includeTags = tagsPropertySet(remoteResource);
if (includeTags != this.includeTags) {
this.includeTags = includeTags;
refreshTable();
}
try {
this.projectProperties = ProjectProperties.getProjectProperties(this.remoteResource);
} catch (SVNException e) {
if (!e.operationInterrupted()) {
SVNUIPlugin.openError(getSite().getShell(), null, null, e);
}
}
boolean includeBugs = projectProperties != null;
if (includeTags != this.includeTags || this.includeBugs != includeBugs) {
this.includeTags = includeTags;
this.includeBugs = includeBugs;
refreshTable();
}
this.historyTableProvider.setRemoteResource(this.remoteResource);
this.historyTableProvider.setProjectProperties(this.projectProperties);
if (historySearchViewerFilter != null) {
// HistorySearchViewerFilter[] filters = { historySearchViewerFilter };
// this.tableHistoryViewer.setFilters(filters);
this.tableHistoryViewer.resetFilters();
this.tableHistoryViewer.addFilter(historySearchViewerFilter);
historySearchDialog = new HistorySearchDialog(getSite().getShell(), remoteResource);
historySearchDialog.setSearchAll(false);
historySearchDialog.setStartRevision(historySearchViewerFilter.getStartRevision());
historySearchDialog.setEndRevision(historySearchViewerFilter.getEndRevision());
historySearchViewerFilter = null;
getClearSearchAction().setEnabled(true);
} else {
this.tableHistoryViewer.resetFilters();
getClearSearchAction().setEnabled(false);
}
this.tableHistoryViewer.setInput(this.remoteResource);
// setTitleToolTip(remoteResource.getRepositoryRelativePath());
return true;
}
return false;
}
Aggregations