use of org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy in project che by eclipse.
the class RefactoringHistoryManager method removeRefactoringDescriptors.
/**
* Removes refactoring descriptors from the managed history.
*
* @param proxies
* the refactoring descriptors
* @param monitor
* the progress monitor to use
* @param task
* the task label to use
* @throws CoreException
* if an error occurs
*/
void removeRefactoringDescriptors(final RefactoringDescriptorProxy[] proxies, final IProgressMonitor monitor, final String task) throws CoreException {
try {
final Map paths = new HashMap();
monitor.beginTask(task, proxies.length + 300);
for (int index = 0; index < proxies.length; index++) {
final IPath path = stampToPath(proxies[index].getTimeStamp());
Collection collection = (Collection) paths.get(path);
if (collection == null) {
collection = new ArrayList(64);
paths.put(path, collection);
}
collection.add(proxies[index]);
}
final IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 300);
try {
final Set entries = paths.entrySet();
subMonitor.beginTask(task, entries.size());
for (final Iterator iterator = entries.iterator(); iterator.hasNext(); ) {
final Map.Entry entry = (Map.Entry) iterator.next();
final Collection collection = (Collection) entry.getValue();
removeRefactoringDescriptors((RefactoringDescriptorProxy[]) collection.toArray(new RefactoringDescriptorProxy[collection.size()]), (IPath) entry.getKey(), new SubProgressMonitor(subMonitor, 1), task);
}
} finally {
subMonitor.done();
}
} finally {
monitor.done();
}
}
use of org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy in project che by eclipse.
the class RefactoringHistoryManager method addRefactoringDescriptor.
/**
* Adds the specified refactoring descriptor to the refactoring history.
*
* @param descriptor
* the refactoring descriptor to add
* @param sort
* <code>true</code> if the refactoring descriptor should be
* inserted into the history according to its time stamp,
* <code>false</code> if the descriptor is assumed to be the
* most recent one, and its simply appended
* @param monitor
* the progress monitor to use
* @throws CoreException
* if an error occurs while adding the descriptor to the history
*/
void addRefactoringDescriptor(final RefactoringDescriptor descriptor, final boolean sort, final IProgressMonitor monitor) throws CoreException {
try {
monitor.beginTask(RefactoringCoreMessages.RefactoringHistoryService_updating_history, 18);
final long stamp = descriptor.getTimeStamp();
if (stamp >= 0) {
final IPath path = stampToPath(stamp);
final IFileStore folder = fHistoryStore.getFileStore(path);
final IFileStore history = folder.getChild(RefactoringHistoryService.NAME_HISTORY_FILE);
final IFileStore index = folder.getChild(RefactoringHistoryService.NAME_INDEX_FILE);
final RefactoringDescriptorProxy[] proxies = new RefactoringDescriptorProxy[] { new DefaultRefactoringDescriptorProxy(descriptor.getDescription(), descriptor.getProject(), descriptor.getTimeStamp()) };
if (history.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)).exists()) {
InputStream input = null;
try {
input = new BufferedInputStream(history.openInputStream(EFS.NONE, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)));
final Document document = getCachedDocument(path, input);
try {
input.close();
input = null;
} catch (IOException exception) {
// Do nothing
}
monitor.worked(1);
final Document result = transformDescriptor(descriptor, false);
if (result != null) {
boolean found = false;
final NodeList list = result.getElementsByTagName(IRefactoringSerializationConstants.ELEMENT_REFACTORING);
final Element root = document.getDocumentElement();
if (sort) {
final String string = Long.toString(stamp);
for (int offset = 0; offset < list.getLength(); offset++) {
final Element element = (Element) list.item(offset);
final String attribute = element.getAttribute(IRefactoringSerializationConstants.ATTRIBUTE_STAMP);
if (attribute != null) {
if (string.compareTo(attribute) > 0) {
root.insertBefore(document.importNode(element, true), element);
found = true;
break;
}
}
}
}
if (!found)
root.appendChild(document.importNode(list.item(0), true));
writeHistoryEntry(history, document, new SubProgressMonitor(monitor, 10, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL), RefactoringCoreMessages.RefactoringHistoryService_updating_history);
if (sort) {
final Set set = new HashSet(64);
readRefactoringDescriptorProxies(index, null, set, 0, Long.MAX_VALUE, new SubProgressMonitor(monitor, 2), RefactoringCoreMessages.RefactoringHistoryService_updating_history);
writeIndexEntry(index, (RefactoringDescriptorProxy[]) set.toArray(new RefactoringDescriptorProxy[set.size()]), EFS.NONE, new SubProgressMonitor(monitor, 3, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL), RefactoringCoreMessages.RefactoringHistoryService_updating_history);
} else
writeIndexEntry(index, proxies, EFS.APPEND, new SubProgressMonitor(monitor, 5, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL), RefactoringCoreMessages.RefactoringHistoryService_updating_history);
}
} catch (ParserConfigurationException exception) {
throw createCoreException(exception);
} catch (IOException exception) {
throw createCoreException(exception);
} catch (SAXException exception) {
throw createCoreException(exception);
} finally {
if (input != null) {
try {
input.close();
} catch (IOException exception) {
// Do nothing
}
}
}
} else {
try {
final Document result = transformDescriptor(descriptor, false);
writeHistoryEntry(history, result, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL), RefactoringCoreMessages.RefactoringHistoryService_updating_history);
writeIndexEntry(index, proxies, EFS.NONE, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL), RefactoringCoreMessages.RefactoringHistoryService_updating_history);
} catch (IOException exception) {
throw createCoreException(exception);
}
}
}
} finally {
monitor.done();
}
}
use of org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy in project che by eclipse.
the class RefactoringHistoryManager method readRefactoringDescriptorProxies.
/**
* Reads refactoring descriptor proxies.
*
* @param store
* the file store to read
* @param project
* the name of the project, or <code>null</code> for the
* workspace
* @param collection
* the collection of proxies to fill in
* @param start
* the start time stamp, inclusive
* @param end
* the end time stamp, inclusive
* @param monitor
* the progress monitor to use
* @param task
* the task label to use
* @throws CoreException
* if an error occurs
*/
private static void readRefactoringDescriptorProxies(final IFileStore store, final String project, final Collection collection, final long start, final long end, final IProgressMonitor monitor, final String task) throws CoreException {
try {
monitor.beginTask(RefactoringCoreMessages.RefactoringHistoryService_retrieving_history, 22);
final IFileInfo info = store.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 2, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
if (!info.isDirectory() && info.exists() && store.getName().equalsIgnoreCase(RefactoringHistoryService.NAME_INDEX_FILE)) {
InputStream stream = null;
try {
stream = store.openInputStream(EFS.NONE, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
final RefactoringDescriptorProxy[] proxies = readRefactoringDescriptorProxies(stream, project, start, end);
for (int index = 0; index < proxies.length; index++) collection.add(proxies[index]);
monitor.worked(1);
} catch (IOException exception) {
throw createCoreException(exception);
} finally {
monitor.worked(1);
if (stream != null) {
try {
stream.close();
} catch (IOException exception) {
// Do nothing
}
}
monitor.worked(1);
}
} else
monitor.worked(4);
if (monitor.isCanceled())
throw new OperationCanceledException();
final IFileStore[] stores = store.childStores(EFS.NONE, new SubProgressMonitor(monitor, 2, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
final IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 12);
try {
subMonitor.beginTask(task, stores.length);
for (int index = 0; index < stores.length; index++) readRefactoringDescriptorProxies(stores[index], project, collection, start, end, new SubProgressMonitor(subMonitor, 1), task);
} finally {
subMonitor.done();
}
} finally {
monitor.done();
}
}
use of org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy in project che by eclipse.
the class AbstractRefactoringHistoryResourceMapping method getProjects.
/**
* {@inheritDoc}
*/
public final IProject[] getProjects() {
final Set set = new HashSet();
final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
final RefactoringDescriptorProxy[] proxies = fRefactoringHistory.getDescriptors();
for (int index = 0; index < proxies.length; index++) {
final String name = proxies[index].getProject();
if (//$NON-NLS-1$
name != null && !"".equals(name))
set.add(root.getProject(name));
}
return (IProject[]) set.toArray(new IProject[set.size()]);
}
Aggregations