Search in sources :

Example 1 with Subscriber

use of org.eclipse.team.core.subscribers.Subscriber in project bndtools by bndtools.

the class ReleaseUtils method getTeamOutOfSyncResources.

public static IResource[] getTeamOutOfSyncResources(IProject project, IProgressMonitor monitor) throws CoreException {
    RepositoryProvider provider = RepositoryProvider.getProvider(project);
    if (provider == null) {
        return new IResource[0];
    }
    Subscriber subscriber = provider.getSubscriber();
    subscriber.refresh(new IResource[] { project }, IResource.DEPTH_INFINITE, monitor);
    SyncInfoSet sis = new SyncInfoSet();
    subscriber.collectOutOfSync(new IResource[] { project }, IResource.DEPTH_INFINITE, sis, monitor);
    List<IResource> res = new ArrayList<IResource>();
    for (IResource resource : sis.getResources()) {
        if (resource instanceof IFile) {
            IFile file = (IFile) resource;
            if (file.getName().endsWith(".bnd") || file.getName().equals("packageinfo")) {
                continue;
            }
        }
        res.add(resource);
    }
    return res.toArray(new IResource[0]);
}
Also used : IFile(org.eclipse.core.resources.IFile) Subscriber(org.eclipse.team.core.subscribers.Subscriber) ArrayList(java.util.ArrayList) SyncInfoSet(org.eclipse.team.core.synchronize.SyncInfoSet) RepositoryProvider(org.eclipse.team.core.RepositoryProvider) IResource(org.eclipse.core.resources.IResource)

Example 2 with Subscriber

use of org.eclipse.team.core.subscribers.Subscriber in project linuxtools by eclipse.

the class PrepareChangeLogAction method prepareChangeLog.

private void prepareChangeLog(IProgressMonitor monitor) {
    Object element = selected.getFirstElement();
    IResource resource = null;
    Vector<PatchFile> newList = new Vector<>();
    Vector<PatchFile> removeList = new Vector<>();
    Vector<PatchFile> changeList = new Vector<>();
    int totalChanges = 0;
    if (element instanceof IResource) {
        resource = (IResource) element;
    } else if (element instanceof ISynchronizeModelElement) {
        ISynchronizeModelElement sme = (ISynchronizeModelElement) element;
        resource = sme.getResource();
    } else if (element instanceof IAdaptable) {
        resource = ((IAdaptable) element).getAdapter(IResource.class);
    }
    if (resource == null)
        return;
    IProject project = resource.getProject();
    // Get the repository provider so we can support multiple types of
    // code repositories without knowing exactly which (e.g. CVS, SVN, etc..).
    RepositoryProvider r = RepositoryProvider.getProvider(project);
    if (r == null)
        return;
    SyncInfoSet set = new SyncInfoSet();
    Subscriber s = r.getSubscriber();
    if (s == null)
        return;
    if (element instanceof ISynchronizeModelElement) {
        // We can extract the ChangeLog list from the synchronize view which
        // allows us to skip items removed from the view
        ISynchronizeModelElement d = (ISynchronizeModelElement) element;
        while (d.getParent() != null) d = (ISynchronizeModelElement) d.getParent();
        extractSynchronizeModelInfo(d, new Path(""), newList, removeList, changeList);
        totalChanges = newList.size() + removeList.size() + changeList.size();
    } else {
        // We can then get a list of all out-of-sync resources.
        IResource[] resources = new IResource[] { project };
        try {
            s.refresh(resources, IResource.DEPTH_INFINITE, monitor);
        } catch (TeamException e) {
        // Ignore, continue anyways
        }
        s.collectOutOfSync(resources, IResource.DEPTH_INFINITE, set, monitor);
        SyncInfo[] infos = set.getSyncInfos();
        totalChanges = infos.length;
        // New, Removed, and Changed lists.
        for (SyncInfo info : infos) {
            int kind = SyncInfo.getChange(info.getKind());
            PatchFile p = new PatchFile(info.getLocal());
            // for ChangeLog files.
            if (!(p.getPath().lastSegment().equals("ChangeLog"))) {
                // $NON-NLS-1$
                switch(kind) {
                    case SyncInfo.ADDITION:
                        p.setNewfile(true);
                        newList.add(p);
                        break;
                    case SyncInfo.DELETION:
                        p.setRemovedFile(true);
                        removeList.add(p);
                        break;
                    case SyncInfo.CHANGE:
                        if (info.getLocal().getType() == IResource.FILE) {
                            changeList.add(p);
                        }
                        break;
                }
            } else {
                this.changeLogModified = true;
            }
        }
    }
    if (totalChanges == 0)
        // nothing to parse
        return;
    PatchFile[] patchFileInfoList = new PatchFile[totalChanges];
    // Group like changes together and sort them by path name.
    // We want removed files, then new files, then changed files.
    // To get this, we put them in the array in reverse order.
    int index = 0;
    if (changeList.size() > 0) {
        // Get the repository provider so we can support multiple types of
        // code repositories without knowing exactly which (e.g. CVS, SVN, etc..).
        Collections.sort(changeList, new PatchFileComparator());
        int size = changeList.size();
        for (int i = 0; i < size; ++i) {
            PatchFile p = changeList.get(i);
            getChangedLines(s, p, monitor);
            patchFileInfoList[index + (size - i - 1)] = p;
        }
        index += size;
    }
    if (newList.size() > 0) {
        Collections.sort(newList, new PatchFileComparator());
        int size = newList.size();
        for (int i = 0; i < size; ++i) patchFileInfoList[index + (size - i - 1)] = newList.get(i);
        index += size;
    }
    if (removeList.size() > 0) {
        Collections.sort(removeList, new PatchFileComparator());
        int size = removeList.size();
        for (int i = 0; i < size; ++i) patchFileInfoList[index + (size - i - 1)] = removeList.get(i);
    }
    // now, find out modified functions/classes.
    // try to use the the extension point. so it can be extended easily
    // for all files in patch file info list, get function guesses of each
    // file.
    // $NON-NLS-1$
    monitor.subTask(Messages.getString("ChangeLog.WritingMessage"));
    int unitwork = 250 / patchFileInfoList.length;
    for (PatchFile pf : patchFileInfoList) {
        // for each file
        if (pf != null) {
            // any ChangeLog changes will have null entries for them
            String[] funcGuessList = guessFunctionNames(pf);
            outputMultipleEntryChangeLog(pf, funcGuessList);
        }
        monitor.worked(unitwork);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IAdaptable(org.eclipse.core.runtime.IAdaptable) ISynchronizeModelElement(org.eclipse.team.ui.synchronize.ISynchronizeModelElement) IProject(org.eclipse.core.resources.IProject) TeamException(org.eclipse.team.core.TeamException) Subscriber(org.eclipse.team.core.subscribers.Subscriber) SyncInfo(org.eclipse.team.core.synchronize.SyncInfo) SyncInfoSet(org.eclipse.team.core.synchronize.SyncInfoSet) Vector(java.util.Vector) RepositoryProvider(org.eclipse.team.core.RepositoryProvider) IResource(org.eclipse.core.resources.IResource)

Example 3 with Subscriber

use of org.eclipse.team.core.subscribers.Subscriber 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

IResource (org.eclipse.core.resources.IResource)3 RepositoryProvider (org.eclipse.team.core.RepositoryProvider)3 Subscriber (org.eclipse.team.core.subscribers.Subscriber)3 SyncInfoSet (org.eclipse.team.core.synchronize.SyncInfoSet)3 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 TeamException (org.eclipse.team.core.TeamException)2 SyncInfo (org.eclipse.team.core.synchronize.SyncInfo)2 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 LineNumberReader (java.io.LineNumberReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 Vector (java.util.Vector)1 RangeDifference (org.eclipse.compare.rangedifferencer.RangeDifference)1 IStorage (org.eclipse.core.resources.IStorage)1 CoreException (org.eclipse.core.runtime.CoreException)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 IPath (org.eclipse.core.runtime.IPath)1