use of org.tigris.subversion.subclipse.core.ISVNRepositoryLocation in project subclipse by subclipse.
the class ResolveTreeConflictWizardMainPage method getRemoteResource.
private void getRemoteResource(ResolveTreeConflictWizard wizard, final SVNTreeConflict treeConflict) {
ISVNRepositoryLocation repository = wizard.getSvnResource().getRepository();
SVNRevision revision = new SVNRevision.Number(treeConflict.getConflictDescriptor().getSrcRightVersion().getPegRevision());
try {
SVNUrl url = new SVNUrl(treeConflict.getConflictDescriptor().getSrcRightVersion().getReposURL() + "/" + treeConflict.getConflictDescriptor().getSrcRightVersion().getPathInRepos());
GetRemoteResourceCommand command = new GetRemoteResourceCommand(repository, url, revision);
command.run(new NullProgressMonitor());
remoteResource = command.getRemoteResource();
} catch (Exception e) {
SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
}
}
use of org.tigris.subversion.subclipse.core.ISVNRepositoryLocation in project subclipse by subclipse.
the class GenerateDiffFileOperation method createEclipsePatch.
private void createEclipsePatch(IResource[] paths, File outputFile, boolean recurse) throws SVNClientException {
FileOutputStream os = null;
InputStream is = null;
ISVNClientAdapter client = null;
ISVNRepositoryLocation repository = null;
try {
byte[] buffer = new byte[4096];
os = new FileOutputStream(outputFile);
if (paths.length > 0) {
os.write(ECLIPSE_PATCH_HEADER.getBytes());
os.write(EOL.getBytes());
}
Map projectToResources = new HashMap();
for (int i = 0; i < paths.length; i++) {
IResource resource = paths[i];
IProject project = resource.getProject();
List files = (List) projectToResources.get(project);
if (files == null) {
files = new ArrayList();
projectToResources.put(project, files);
}
files.add(resource.getLocation().toFile());
}
for (Iterator iEntry = projectToResources.entrySet().iterator(); iEntry.hasNext(); ) {
Entry entry = (Entry) iEntry.next();
IResource project = (IResource) entry.getKey();
List files = (List) entry.getValue();
repository = SVNWorkspaceRoot.getSVNResourceFor(project).getRepository();
client = repository.getSVNClient();
os.write(ECLIPSE_PROJECT_MARKER.getBytes());
os.write(project.getName().getBytes());
os.write(EOL.getBytes());
File tempFile = File.createTempFile("tempDiff", ".txt");
tempFile.deleteOnExit();
client.createPatch((File[]) files.toArray(new File[files.size()]), project.getLocation().toFile(), tempFile, recurse);
SVNWorkspaceRoot.getSVNResourceFor(project).getRepository().returnSVNClient(client);
client = null;
repository = null;
try {
is = new FileInputStream(tempFile);
int bytes_read;
while ((bytes_read = is.read(buffer)) != -1) os.write(buffer, 0, bytes_read);
} finally {
if (is != null)
try {
is.close();
} catch (IOException e) {
}
}
}
} catch (Exception e) {
throw new SVNClientException(e);
} finally {
if (os != null)
try {
os.close();
} catch (IOException e) {
}
if (repository != null) {
repository.returnSVNClient(client);
}
}
}
use of org.tigris.subversion.subclipse.core.ISVNRepositoryLocation 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();
}
}
use of org.tigris.subversion.subclipse.core.ISVNRepositoryLocation in project subclipse by subclipse.
the class DirectorySelectionPage method createControl.
public void createControl(Composite parent) {
Composite composite = createComposite(parent, 3);
// set F1 help
PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.SHARING_MODULE_PAGE);
useProjectNameButton = createRadioButton(composite, Policy.bind("ModuleSelectionPage.moduleIsProject"), // $NON-NLS-1$
3);
useSpecifiedNameButton = createRadioButton(composite, Policy.bind("ModuleSelectionPage.specifyModule"), // $NON-NLS-1$
1);
text = createTextField(composite);
text.setEnabled(false);
text.addListener(SWT.Modify, new Listener() {
public void handleEvent(Event event) {
setUrlText();
result = text.getText().trim();
if (result.length() == 0) {
result = null;
setPageComplete(false);
} else {
setPageComplete(true);
}
}
});
FocusListener focusListener = new FocusAdapter() {
public void focusGained(FocusEvent e) {
((Text) e.getSource()).selectAll();
}
public void focusLost(FocusEvent e) {
((Text) e.getSource()).setText(((Text) e.getSource()).getText());
}
};
text.addFocusListener(focusListener);
browseButton = new Button(composite, SWT.PUSH);
// $NON-NLS-1$
browseButton.setText(Policy.bind("SharingWizard.browse"));
browseButton.setEnabled(false);
browseButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent se) {
try {
ISVNRepositoryLocation repositoryLocation = repositoryLocationProvider.getLocation();
ChooseUrlDialog dialog = new ChooseUrlDialog(getShell(), repositoryLocationProvider.getProject());
dialog.setRepositoryLocation(repositoryLocation);
if (dialog.open() == ChooseUrlDialog.OK && dialog.getUrl() != null) {
text.setText(dialog.getUrl().toString().substring(repositoryLocation.getLocation().length() + 1) + "/" + repositoryLocationProvider.getProject().getName());
text.setFocus();
text.setSelection(text.getText().indexOf(repositoryLocationProvider.getProject().getName()), text.getText().length());
}
} catch (Exception e) {
}
}
});
Group urlGroup = new Group(composite, SWT.NONE);
// $NON-NLS-1$
urlGroup.setText(Policy.bind("SharingWizard.url"));
GridLayout layout = new GridLayout();
layout.numColumns = 1;
urlGroup.setLayout(layout);
GridData data = new GridData();
data.verticalAlignment = GridData.FILL;
data.horizontalAlignment = GridData.FILL;
data.horizontalSpan = 3;
urlGroup.setLayoutData(data);
urlText = createTextField(urlGroup);
urlText.setEditable(false);
initializeSelection();
setUrlText();
useProjectNameButton.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
setUrlText();
useProjectName = useProjectNameButton.getSelection();
if (useProjectName) {
text.setEnabled(false);
browseButton.setEnabled(false);
result = null;
setPageComplete(true);
} else {
text.setEnabled(true);
text.setFocus();
text.selectAll();
browseButton.setEnabled(true);
result = text.getText();
if (result.length() == 0) {
result = null;
setPageComplete(false);
} else {
setPageComplete(true);
}
}
}
});
setControl(composite);
setPageComplete(true);
}
use of org.tigris.subversion.subclipse.core.ISVNRepositoryLocation in project subclipse by subclipse.
the class RepositorySelectionPage method createControl.
/**
* Creates the UI part of the page.
*
* @param parent the parent of the created widgets
*/
public void createControl(Composite parent) {
Composite composite = createComposite(parent, 1);
// set F1 help
PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.SHARING_SELECT_REPOSITORY_PAGE);
createWrappingLabel(composite, Policy.bind("RepositorySelectionPage.description"), 0, /* indent */
1);
useNewRepo = createRadioButton(composite, Policy.bind("RepositorySelectionPage.useNew"), // $NON-NLS-1$
1);
useExistingRepo = createRadioButton(composite, Policy.bind("RepositorySelectionPage.useExisting"), // $NON-NLS-1$
1);
table = createTable(composite, 1);
table.setContentProvider(new WorkbenchContentProvider());
table.setLabelProvider(new WorkbenchLabelProvider());
table.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
result = (ISVNRepositoryLocation) ((IStructuredSelection) table.getSelection()).getFirstElement();
settings.put(LAST_LOCATION, result.getLocation());
setPageComplete(canFinish());
}
});
SelectionListener selectionListener = new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (useNewRepo.getSelection()) {
table.getTable().setEnabled(false);
result = null;
} else {
table.getTable().setEnabled(true);
result = (ISVNRepositoryLocation) ((IStructuredSelection) table.getSelection()).getFirstElement();
}
setPageComplete(canFinish());
}
};
useNewRepo.addSelectionListener(selectionListener);
useExistingRepo.addSelectionListener(selectionListener);
setControl(composite);
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
locations = SVNUIPlugin.getPlugin().getRepositoryManager().getKnownRepositoryLocations(monitor);
}
};
try {
new ProgressMonitorDialog(getShell()).run(true, false, runnable);
} catch (Exception e) {
SVNUIPlugin.openError(getShell(), null, null, e, SVNUIPlugin.LOG_TEAM_EXCEPTIONS);
}
Arrays.sort(locations, new RepositoryComparator());
AdaptableList input = new AdaptableList(locations);
table.setInput(input);
if (locations.length == 0) {
useNewRepo.setSelection(true);
} else {
useExistingRepo.setSelection(true);
int selectionIndex = 0;
String lastLocation = settings.get(LAST_LOCATION);
if (lastLocation != null) {
for (int i = 0; i < locations.length; i++) {
ISVNRepositoryLocation location = locations[i];
if (lastLocation.equals(location.getLocation())) {
selectionIndex = i;
break;
}
}
}
table.setSelection(new StructuredSelection(locations[selectionIndex]));
result = locations[selectionIndex];
}
setPageComplete(canFinish());
}
Aggregations