Search in sources :

Example 41 with ISVNRepositoryLocation

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);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ISVNRepositoryLocation(org.tigris.subversion.subclipse.core.ISVNRepositoryLocation) GetRemoteResourceCommand(org.tigris.subversion.subclipse.core.commands.GetRemoteResourceCommand) SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision) SVNException(org.tigris.subversion.subclipse.core.SVNException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 42 with ISVNRepositoryLocation

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);
        }
    }
}
Also used : HashMap(java.util.HashMap) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) FileInputStream(java.io.FileInputStream) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TeamException(org.eclipse.team.core.TeamException) ISVNRepositoryLocation(org.tigris.subversion.subclipse.core.ISVNRepositoryLocation) Entry(java.util.Map.Entry) FileOutputStream(java.io.FileOutputStream) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) IResource(org.eclipse.core.resources.IResource) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 43 with ISVNRepositoryLocation

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();
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) TeamException(org.eclipse.team.core.TeamException) ISVNRepositoryLocation(org.tigris.subversion.subclipse.core.ISVNRepositoryLocation) SVNTeamProvider(org.tigris.subversion.subclipse.core.SVNTeamProvider) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter) HashSet(java.util.HashSet) Hashtable(java.util.Hashtable) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) InvocationTargetException(java.lang.reflect.InvocationTargetException) FileInputStream(java.io.FileInputStream) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TeamException(org.eclipse.team.core.TeamException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) FileOutputStream(java.io.FileOutputStream) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Transfer(org.eclipse.swt.dnd.Transfer) Clipboard(org.eclipse.swt.dnd.Clipboard) File(java.io.File) IResource(org.eclipse.core.resources.IResource) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 44 with ISVNRepositoryLocation

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);
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) Group(org.eclipse.swt.widgets.Group) FocusListener(org.eclipse.swt.events.FocusListener) Listener(org.eclipse.swt.widgets.Listener) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) FocusEvent(org.eclipse.swt.events.FocusEvent) TeamException(org.eclipse.team.core.TeamException) ChooseUrlDialog(org.tigris.subversion.subclipse.ui.dialogs.ChooseUrlDialog) ISVNRepositoryLocation(org.tigris.subversion.subclipse.core.ISVNRepositoryLocation) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FocusListener(org.eclipse.swt.events.FocusListener)

Example 45 with ISVNRepositoryLocation

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());
}
Also used : WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryComparator(org.tigris.subversion.subclipse.core.repo.RepositoryComparator) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ISVNRepositoryLocation(org.tigris.subversion.subclipse.core.ISVNRepositoryLocation) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AdaptableList(org.tigris.subversion.subclipse.ui.util.AdaptableList) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

ISVNRepositoryLocation (org.tigris.subversion.subclipse.core.ISVNRepositoryLocation)69 ISVNClientAdapter (org.tigris.subversion.svnclientadapter.ISVNClientAdapter)20 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 IResource (org.eclipse.core.resources.IResource)15 ISVNLocalResource (org.tigris.subversion.subclipse.core.ISVNLocalResource)15 TeamException (org.eclipse.team.core.TeamException)14 ArrayList (java.util.ArrayList)13 SVNException (org.tigris.subversion.subclipse.core.SVNException)13 SVNUrl (org.tigris.subversion.svnclientadapter.SVNUrl)13 SVNClientException (org.tigris.subversion.svnclientadapter.SVNClientException)12 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)11 File (java.io.File)10 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)9 ISVNRemoteResource (org.tigris.subversion.subclipse.core.ISVNRemoteResource)8 LocalResourceStatus (org.tigris.subversion.subclipse.core.resources.LocalResourceStatus)8 SVNRevision (org.tigris.subversion.svnclientadapter.SVNRevision)8 Iterator (java.util.Iterator)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 ISVNRemoteFolder (org.tigris.subversion.subclipse.core.ISVNRemoteFolder)7 List (java.util.List)6