Search in sources :

Example 76 with ISVNClientAdapter

use of org.tigris.subversion.svnclientadapter.ISVNClientAdapter 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 77 with ISVNClientAdapter

use of org.tigris.subversion.svnclientadapter.ISVNClientAdapter 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 78 with ISVNClientAdapter

use of org.tigris.subversion.svnclientadapter.ISVNClientAdapter in project subclipse by subclipse.

the class SvnWizardBranchTagPage method updateTagsProperty.

private void updateTagsProperty(SVNUrl toUrl) {
    ISVNClientAdapter svnClient = null;
    try {
        ISVNProperty property = null;
        // $NON-NLS-1$
        property = svnResource.getSvnProperty("subclipse:tags");
        if (property == null)
            return;
        newAlias = new Alias();
        // $NON-NLS-1$
        newAlias.setBranch(toUrl.toString().toUpperCase().indexOf("TAGS") == -1);
        String relativePath = toUrl.toString().substring(svnResource.getRepository().getUrl().toString().length());
        newAlias.setRelativePath(relativePath);
        SVNRevision revision = null;
        if (revisionButton.getSelection())
            revision = SVNRevision.getRevision(revisionText.getText().trim());
        else {
            svnClient = svnResource.getRepository().getSVNClient();
            ISVNInfo svnInfo = svnClient.getInfo(url);
            revision = SVNRevision.getRevision(svnInfo.getRevision().toString());
        }
        newAlias.setRevision(Integer.parseInt(revision.toString()));
        newAlias.setName(toUrl.getLastPathSegment());
        BranchTagPropertyUpdateDialog dialog = new BranchTagPropertyUpdateDialog(getShell(), resource, newAlias, // $NON-NLS-1$
        "BranchTagPropertyUpdateDialog");
        if (dialog.open() == BranchTagPropertyUpdateDialog.OK)
            newAlias = dialog.getNewAlias();
        else
            newAlias = null;
    } catch (Exception e) {
    } finally {
        svnResource.getRepository().returnSVNClient(svnClient);
    }
}
Also used : BranchTagPropertyUpdateDialog(org.tigris.subversion.subclipse.ui.dialogs.BranchTagPropertyUpdateDialog) Alias(org.tigris.subversion.subclipse.core.history.Alias) ISVNInfo(org.tigris.subversion.svnclientadapter.ISVNInfo) ISVNProperty(org.tigris.subversion.svnclientadapter.ISVNProperty) SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 79 with ISVNClientAdapter

use of org.tigris.subversion.svnclientadapter.ISVNClientAdapter in project subclipse by subclipse.

the class SVNClientManager method setConfigDir.

/**
 * @param configDir The configDir to set.
 */
public void setConfigDir(File configDir) {
    this.configDir = configDir;
    if (cachedClients == null)
        return;
    // Update configDir in stored clients
    Set<String> keys = cachedClients.keySet();
    for (String key : keys) {
        ISVNClientAdapter svnClient = cachedClients.get(key);
        if (svnClient != null) {
            try {
                svnClient.setConfigDirectory(configDir);
            } catch (SVNClientException e) {
                break;
            }
        }
    }
}
Also used : SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 80 with ISVNClientAdapter

use of org.tigris.subversion.svnclientadapter.ISVNClientAdapter in project subclipse by subclipse.

the class SVNRepositoryLocation method getSVNClient.

/**
 * get the svn client corresponding to the repository
 *
 * @throws SVNException
 */
public ISVNClientAdapter getSVNClient() throws SVNException {
    ISVNClientAdapter svnClient = SVNProviderPlugin.getPlugin().getSVNClient();
    svnClient.addNotifyListener(NotificationListener.getInstance());
    return svnClient;
}
Also used : ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Aggregations

ISVNClientAdapter (org.tigris.subversion.svnclientadapter.ISVNClientAdapter)108 SVNClientException (org.tigris.subversion.svnclientadapter.SVNClientException)67 SVNException (org.tigris.subversion.subclipse.core.SVNException)37 File (java.io.File)28 IResource (org.eclipse.core.resources.IResource)27 CoreException (org.eclipse.core.runtime.CoreException)22 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)21 TeamException (org.eclipse.team.core.TeamException)21 ISVNLocalResource (org.tigris.subversion.subclipse.core.ISVNLocalResource)20 ISVNRepositoryLocation (org.tigris.subversion.subclipse.core.ISVNRepositoryLocation)20 ISVNInfo (org.tigris.subversion.svnclientadapter.ISVNInfo)19 SVNUrl (org.tigris.subversion.svnclientadapter.SVNUrl)19 ArrayList (java.util.ArrayList)18 SVNRevision (org.tigris.subversion.svnclientadapter.SVNRevision)18 InvocationTargetException (java.lang.reflect.InvocationTargetException)15 ISVNProperty (org.tigris.subversion.svnclientadapter.ISVNProperty)13 OperationProgressNotifyListener (org.tigris.subversion.subclipse.core.client.OperationProgressNotifyListener)9 IProject (org.eclipse.core.resources.IProject)8 List (java.util.List)7 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)7