Search in sources :

Example 1 with IFileRevision

use of org.eclipse.team.core.history.IFileRevision in project bndtools by bndtools.

the class ReleaseUtils method getTeamRevision.

/**
     * If the bundle repository is shared e.g. CVS, this will return the remote file revision if it exists
     * 
     * @param repository
     * @param jar
     * @return The file revision or <code>null</code> if the bundle repository is not shared or the Jar does not exist
     *         in the remote repository
     */
public static IFileRevision getTeamRevision(RepositoryPlugin repository, Jar jar) {
    IFolder repoRoot = ReleaseUtils.getLocalRepoLocation(repository);
    IProject repoProject = repoRoot.getProject();
    RepositoryProvider repoProvider = RepositoryProvider.getProvider(repoProject);
    if (repoProvider == null) {
        return null;
    }
    IFile path = getJarFileLocation(repository, jar);
    IFileRevision[] revs = getTeamRevisions(path, IFileHistoryProvider.SINGLE_REVISION, new NullProgressMonitor());
    if (revs == null) {
        return null;
    }
    return revs.length == 0 ? null : revs[0];
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IFileRevision(org.eclipse.team.core.history.IFileRevision) RepositoryProvider(org.eclipse.team.core.RepositoryProvider) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 2 with IFileRevision

use of org.eclipse.team.core.history.IFileRevision in project bndtools by bndtools.

the class ReleaseUtils method getTeamRevisions.

/**
     * Returns the file revisions for the given resource. If the flags contains IFileHistoryProvider.SINGLE_REVISION
     * then only the revision corresponding to the base corresponding to the local resource is fetched. If the flags
     * contains IFileHistoryProvider.SINGLE_LINE_OF_DESCENT the resulting history will be restricted to a single
     * line-of-descent (e.g. a single branch).
     *
     * @param resource
     * @param flags
     * @param monitor
     * @return the file revisions for the given resource
     */
public static IFileRevision[] getTeamRevisions(IResource resource, int flags, IProgressMonitor monitor) {
    RepositoryProvider provider = RepositoryProvider.getProvider(resource.getProject());
    if (provider == null) {
        return null;
    }
    IFileHistory history = provider.getFileHistoryProvider().getFileHistoryFor(resource, flags, monitor);
    if (history == null) {
        return new IFileRevision[0];
    }
    return history.getFileRevisions();
}
Also used : IFileHistory(org.eclipse.team.core.history.IFileHistory) IFileRevision(org.eclipse.team.core.history.IFileRevision) RepositoryProvider(org.eclipse.team.core.RepositoryProvider)

Example 3 with IFileRevision

use of org.eclipse.team.core.history.IFileRevision in project linuxtools by eclipse.

the class PrepareChangeLogAction method getChangedLines.

private void getChangedLines(Subscriber s, PatchFile p, IProgressMonitor monitor) {
    try {
        // For an outgoing changed resource, find out which lines
        // differ from the local file and its previous local version
        // (i.e. we don't want to force a diff with the repository).
        IDiff d = s.getDiff(p.getResource());
        if (d instanceof IThreeWayDiff && ((IThreeWayDiff) d).getDirection() == IThreeWayDiff.OUTGOING) {
            IThreeWayDiff diff = (IThreeWayDiff) d;
            monitor.beginTask(null, 100);
            IResourceDiff localDiff = (IResourceDiff) diff.getLocalChange();
            IResource resource = localDiff.getResource();
            if (resource instanceof IFile) {
                IFile file = (IFile) resource;
                // $NON-NLS-1$
                monitor.subTask(Messages.getString("ChangeLog.MergingDiffs"));
                String osEncoding = file.getCharset();
                IFileRevision ancestorState = localDiff.getBeforeState();
                IStorage ancestorStorage;
                if (ancestorState != null) {
                    ancestorStorage = ancestorState.getStorage(monitor);
                    p.setStorage(ancestorStorage);
                } else {
                    return;
                }
                try {
                    // We compare using a standard differencer to get ranges
                    // of changes.  We modify them to be document-based (i.e.
                    // first line is line 1) and store them for later parsing.
                    LineComparator left = new LineComparator(ancestorStorage.getContents(), osEncoding);
                    LineComparator right = new LineComparator(file.getContents(), osEncoding);
                    for (RangeDifference tmp : RangeDifferencer.findDifferences(left, right)) {
                        if (tmp.kind() == RangeDifference.CHANGE) {
                            // Right side of diff are all changes found in local file.
                            int rightLength = tmp.rightLength() > 0 ? tmp.rightLength() : tmp.rightLength() + 1;
                            // We also want to store left side of the diff which are changes to the ancestor as it may contain
                            // functions/methods that have been removed.
                            int leftLength = tmp.leftLength() > 0 ? tmp.leftLength() : tmp.leftLength() + 1;
                            // Only store left side changes if the storage exists and we add one to the start line number
                            if (p.getStorage() != null)
                                p.addLineRange(tmp.leftStart(), tmp.leftStart() + leftLength, false);
                            p.addLineRange(tmp.rightStart(), tmp.rightStart() + rightLength, true);
                        }
                    }
                } catch (UnsupportedEncodingException e) {
                // do nothing for now
                }
            }
            monitor.done();
        }
    } catch (CoreException e) {
    // Do nothing if error occurs
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IFileRevision(org.eclipse.team.core.history.IFileRevision) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IDiff(org.eclipse.team.core.diff.IDiff) IResourceDiff(org.eclipse.team.core.mapping.IResourceDiff) IStorage(org.eclipse.core.resources.IStorage) RangeDifference(org.eclipse.compare.rangedifferencer.RangeDifference) LineComparator(org.eclipse.linuxtools.internal.changelog.core.LineComparator) CoreException(org.eclipse.core.runtime.CoreException) IThreeWayDiff(org.eclipse.team.core.diff.IThreeWayDiff) IResource(org.eclipse.core.resources.IResource)

Example 4 with IFileRevision

use of org.eclipse.team.core.history.IFileRevision in project linuxtools by eclipse.

the class PrepareCommitHandler method loadClipboard.

private void loadClipboard(IProgressMonitor monitor) {
    IEditorPart currentEditor;
    try {
        currentEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    } catch (Exception e) {
        // no editor is active now so do nothing
        return;
    }
    if (currentEditor == null) {
        return;
    }
    IFile changelog = getChangelogFile(getDocumentLocation(currentEditor, false));
    if (changelog == null) {
        return;
    }
    String diffResult = "";
    IProject project = null;
    IResource[] resources = new IResource[] { changelog };
    project = changelog.getProject();
    RepositoryProvider r = RepositoryProvider.getProvider(project);
    if (r == null) {
        // There is no repository provider for this project, i.e
        return;
    // it's not shared.
    }
    SyncInfoSet set = new SyncInfoSet();
    Subscriber s = r.getSubscriber();
    try {
        s.refresh(resources, IResource.DEPTH_ZERO, monitor);
    } catch (TeamException e1) {
    // Ignore, continue anyways
    }
    s.collectOutOfSync(resources, IResource.DEPTH_ZERO, set, monitor);
    SyncInfo[] infos = set.getSyncInfos();
    if (infos.length == 1) {
        int kind = SyncInfo.getChange(infos[0].getKind());
        if (kind == SyncInfo.CHANGE) {
            try {
                IDiff d = s.getDiff(infos[0].getLocal());
                if (d instanceof IThreeWayDiff && ((IThreeWayDiff) d).getDirection() == IThreeWayDiff.OUTGOING) {
                    IThreeWayDiff diff = (IThreeWayDiff) d;
                    monitor.beginTask(null, 100);
                    IResourceDiff localDiff = (IResourceDiff) diff.getLocalChange();
                    IFile file = (IFile) localDiff.getResource();
                    monitor.subTask(Messages.getString(// $NON-NLS-1$
                    "ChangeLog.MergingDiffs"));
                    String osEncoding = file.getCharset();
                    IFileRevision ancestorState = localDiff.getBeforeState();
                    IStorage ancestorStorage;
                    if (ancestorState != null)
                        ancestorStorage = ancestorState.getStorage(monitor);
                    else {
                        ancestorStorage = null;
                        return;
                    }
                    try {
                        LineComparator left = new LineComparator(ancestorStorage.getContents(), osEncoding);
                        LineComparator right = new LineComparator(file.getContents(), osEncoding);
                        for (RangeDifference tmp : RangeDifferencer.findDifferences(left, right)) {
                            if (tmp.kind() == RangeDifference.CHANGE) {
                                LineNumberReader l = new LineNumberReader(new InputStreamReader(file.getContents()));
                                int rightLength = tmp.rightLength() > 0 ? tmp.rightLength() : tmp.rightLength() + 1;
                                String line0 = null;
                                String preDiffResult = "";
                                for (int i = 0; i < tmp.rightStart(); ++i) {
                                    // usage if needed.
                                    try {
                                        String line = l.readLine();
                                        if (line0 == null)
                                            line0 = line;
                                        preDiffResult += line + "\n";
                                    } catch (IOException e) {
                                        break;
                                    }
                                }
                                for (int i = 0; i < rightLength; ++i) {
                                    try {
                                        String line = l.readLine();
                                        // used as a commit comment.
                                        if (i == rightLength - tmp.rightStart()) {
                                            if (tmp.rightStart() != 0 && line.equals(line0)) {
                                                diffResult = preDiffResult += diffResult;
                                                // stop
                                                i = rightLength;
                                            // loop
                                            } else
                                                diffResult += line + "\n";
                                        } else
                                            // $NON-NLS-1$
                                            diffResult += line + "\n";
                                    } catch (IOException e) {
                                    // do nothing
                                    }
                                }
                            }
                        }
                    } catch (UnsupportedEncodingException e) {
                    // do nothing for now
                    }
                    monitor.done();
                }
            } catch (CoreException e) {
            // do nothing
            }
        }
    }
    if (!diffResult.equals(""))
        populateClipboardBuffer(diffResult);
}
Also used : IFile(org.eclipse.core.resources.IFile) IDiff(org.eclipse.team.core.diff.IDiff) LineNumberReader(java.io.LineNumberReader) TeamException(org.eclipse.team.core.TeamException) RangeDifference(org.eclipse.compare.rangedifferencer.RangeDifference) LineComparator(org.eclipse.linuxtools.internal.changelog.core.LineComparator) Subscriber(org.eclipse.team.core.subscribers.Subscriber) SyncInfo(org.eclipse.team.core.synchronize.SyncInfo) IThreeWayDiff(org.eclipse.team.core.diff.IThreeWayDiff) SyncInfoSet(org.eclipse.team.core.synchronize.SyncInfoSet) InputStreamReader(java.io.InputStreamReader) IFileRevision(org.eclipse.team.core.history.IFileRevision) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IEditorPart(org.eclipse.ui.IEditorPart) IResourceDiff(org.eclipse.team.core.mapping.IResourceDiff) IOException(java.io.IOException) IStorage(org.eclipse.core.resources.IStorage) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TeamException(org.eclipse.team.core.TeamException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) RepositoryProvider(org.eclipse.team.core.RepositoryProvider) IResource(org.eclipse.core.resources.IResource)

Aggregations

IFileRevision (org.eclipse.team.core.history.IFileRevision)4 IFile (org.eclipse.core.resources.IFile)3 RepositoryProvider (org.eclipse.team.core.RepositoryProvider)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 RangeDifference (org.eclipse.compare.rangedifferencer.RangeDifference)2 IProject (org.eclipse.core.resources.IProject)2 IResource (org.eclipse.core.resources.IResource)2 IStorage (org.eclipse.core.resources.IStorage)2 CoreException (org.eclipse.core.runtime.CoreException)2 LineComparator (org.eclipse.linuxtools.internal.changelog.core.LineComparator)2 IDiff (org.eclipse.team.core.diff.IDiff)2 IThreeWayDiff (org.eclipse.team.core.diff.IThreeWayDiff)2 IResourceDiff (org.eclipse.team.core.mapping.IResourceDiff)2 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 LineNumberReader (java.io.LineNumberReader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IFolder (org.eclipse.core.resources.IFolder)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 TeamException (org.eclipse.team.core.TeamException)1