/** {@inheritDoc} */ public boolean accept(Object element) { boolean passes = true; if (element instanceof IFile) { IFile file = (IFile) element; IProject project = file.getProject(); if (RepositoryProvider.isShared(project)) { RepositoryProvider provider = RepositoryProvider.getProvider(project); if (provider != null) { Subscriber subscriber = provider.getSubscriber(); if (subscriber != null) { try { SyncInfo synchInfo = subscriber.getSyncInfo(file); if (synchInfo != null) { int kind = synchInfo.getKind(); passes = (SyncInfo.getDirection(kind) & SyncInfo.OUTGOING) == SyncInfo.OUTGOING; } } catch (TeamException e) { CheckstyleLog.log(e); } } } } } return passes; }
private void processContents() throws CoreException, UnsupportedEncodingException { Set<IFile> files = new HashSet<IFile>(); files.addAll(contentsOrigin.keySet()); files.addAll(contentsSource.keySet()); files.addAll(contentsRemote.keySet()); for (IFile file : files) { String originContent = contentsOrigin.get(file); String remoteContent = contentsRemote.get(file); String sourceContent = contentsSource.get(file); int remoteDiffKind = diffKind(originContent, remoteContent); int sourceDiffKind = diffKind(originContent, sourceContent); ThreeWayDiff threeWayDiff = mock(ThreeWayDiff.class); ITwoWayDiff remoteDiff = mock(ITwoWayDiff.class); ITwoWayDiff sourceDiff = mock(ITwoWayDiff.class); when(remoteDiff.getKind()).thenReturn(remoteDiffKind); when(sourceDiff.getKind()).thenReturn(sourceDiffKind); when(threeWayDiff.getLocalChange()).thenReturn(sourceDiff); when(threeWayDiff.getRemoteChange()).thenReturn(remoteDiff); when(subscriber.getDiff(file)).thenReturn(threeWayDiff); IStorageProvider originProvider = mock(IStorageProvider.class); IStorageProvider remoteProvider = mock(IStorageProvider.class); IStorageProvider sourceProvider = mock(IStorageProvider.class); IStorage originStorage = mock(IStorage.class); IStorage remoteStorage = mock(IStorage.class); IStorage sourceStorage = mock(IStorage.class); when(originProvider.getStorage(any(IProgressMonitor.class))).thenReturn(originStorage); when(remoteProvider.getStorage(any(IProgressMonitor.class))).thenReturn(remoteStorage); when(sourceProvider.getStorage(any(IProgressMonitor.class))).thenReturn(sourceStorage); when(originStorage.getContents()).then(openInputStream(originContent)); when(remoteStorage.getContents()).then(openInputStream(remoteContent)); when(sourceStorage.getContents()).then(openInputStream(sourceContent)); when(accessor.getStorageProvider(file, DiffSide.ORIGIN)).thenReturn(originProvider); when(accessor.getStorageProvider(file, DiffSide.REMOTE)).thenReturn(remoteProvider); when(accessor.getStorageProvider(file, DiffSide.SOURCE)).thenReturn(sourceProvider); } when(subscriber.members(root)).thenReturn(files.toArray(new IFile[0])); }
@Before public void setUp() { subscriber = mock(Subscriber.class); accessor = mock(IStorageProviderAccessor.class); sut = new RenameDetector(subscriber, accessor); root = mock(IProject.class); when(subscriber.roots()).thenReturn(new IResource[] {root}); }
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; monitor.subTask(Messages.getString("ChangeLog.MergingDiffs")); // $NON-NLS-1$ String osEncoding = file.getCharset(); IFileRevision ancestorState = localDiff.getBeforeState(); IStorage ancestorStorage; if (ancestorState != null) { ancestorStorage = ancestorState.getStorage(monitor); p.setStorage(ancestorStorage); } else ancestorStorage = null; 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 } }
private void prepareChangeLog(IProgressMonitor monitor) { Object element = selected.getFirstElement(); IResource resource = null; Vector<PatchFile> newList = new Vector<PatchFile>(); Vector<PatchFile> removeList = new Vector<PatchFile>(); Vector<PatchFile> changeList = new Vector<PatchFile>(); 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 = (IResource) ((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. s.collectOutOfSync(new IResource[] {project}, IResource.DEPTH_INFINITE, set, monitor); SyncInfo[] infos = set.getSyncInfos(); totalChanges = infos.length; // Iterate through the list of changed resources and categorize them into // New, Removed, and Changed lists. for (SyncInfo info : infos) { int kind = SyncInfo.getChange(info.getKind()); PatchFile p = new PatchFile(info.getLocal()); // Check the type of entry and sort into lists. Do not add an entry // for ChangeLog files. if (!(p.getPath().lastSegment().equals("ChangeLog"))) { // $NON-NLS-1$ if (kind == SyncInfo.ADDITION) { p.setNewfile(true); newList.add(p); } else if (kind == SyncInfo.DELETION) { p.setRemovedFile(true); removeList.add(p); } else if (kind == SyncInfo.CHANGE) { if (info.getLocal().getType() == IResource.FILE) { changeList.add(p); } } } else { this.changeLogModified = true; } } } if (totalChanges == 0) return; // nothing to parse 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. monitor.subTask(Messages.getString("ChangeLog.WritingMessage")); // $NON-NLS-1$ 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); } }