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]);
}
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);
}
}
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);
}
Aggregations