Search in sources :

Example 11 with RefactoringDescriptorProxy

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();
    }
}
Also used : Entry(java.util.Map.Entry) Set(java.util.Set) HashSet(java.util.HashSet) IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Entry(java.util.Map.Entry) RefactoringDescriptorProxy(org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy) Iterator(java.util.Iterator) Collection(java.util.Collection) Map(java.util.Map) HashMap(java.util.HashMap) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 12 with RefactoringDescriptorProxy

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();
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) IPath(org.eclipse.core.runtime.IPath) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) IOException(java.io.IOException) Document(org.w3c.dom.Document) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) SAXException(org.xml.sax.SAXException) RefactoringDescriptorProxy(org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy) BufferedInputStream(java.io.BufferedInputStream) IFileStore(org.eclipse.core.filesystem.IFileStore) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) HashSet(java.util.HashSet)

Example 13 with RefactoringDescriptorProxy

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();
    }
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) RefactoringDescriptorProxy(org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IFileStore(org.eclipse.core.filesystem.IFileStore) IOException(java.io.IOException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 14 with RefactoringDescriptorProxy

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()]);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) RefactoringDescriptorProxy(org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy) IProject(org.eclipse.core.resources.IProject) HashSet(java.util.HashSet)

Aggregations

RefactoringDescriptorProxy (org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy)14 HashSet (java.util.HashSet)10 Set (java.util.Set)10 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)9 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 ArrayList (java.util.ArrayList)4 IFileStore (org.eclipse.core.filesystem.IFileStore)4 BufferedInputStream (java.io.BufferedInputStream)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 Iterator (java.util.Iterator)3 NodeList (org.w3c.dom.NodeList)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 IProject (org.eclipse.core.resources.IProject)2 IPath (org.eclipse.core.runtime.IPath)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2