Search in sources :

Example 56 with IFileStore

use of org.eclipse.core.filesystem.IFileStore 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 57 with IFileStore

use of org.eclipse.core.filesystem.IFileStore 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 58 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project tdi-studio-se by Talend.

the class RenameAction method getNewName.

/**
     * Gets the new file name.
     * 
     * @return The new file name
     */
private String getNewName() {
    IFileStore fileStore = snapshot.getFileStore();
    List<String> oldNames = new ArrayList<String>();
    try {
        for (String oldName : fileStore.getParent().childNames(EFS.NONE, null)) {
            oldNames.add(removeSuffix(oldName));
        }
    } catch (CoreException e) {
        Activator.log(IStatus.ERROR, NLS.bind(Messages.accessFileFailedMsg, fileStore.getName()), e);
        return null;
    }
    String oldName = fileStore.getName();
    IInputValidator validator = new InputValidator(oldNames, oldName);
    InputDialog dialog = new InputDialog(treeViewer.getControl().getShell(), Messages.renameTitle, Messages.newNameLabel, removeSuffix(oldName), validator);
    if (dialog.open() == Window.OK) {
        return oldName.replace(removeSuffix(oldName), dialog.getValue());
    }
    return null;
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) CoreException(org.eclipse.core.runtime.CoreException) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException) IInputValidator(org.eclipse.jface.dialogs.IInputValidator) ArrayList(java.util.ArrayList) IFileStore(org.eclipse.core.filesystem.IFileStore) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 59 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project tdi-studio-se by Talend.

the class Host method saveHostProperties.

/**
     * Saves the properties.
     */
private void saveHostProperties() {
    Properties props = new Properties();
    IPath hostDir;
    try {
        hostDir = getHostDir();
    } catch (JvmCoreException e) {
        Activator.log(IStatus.ERROR, Messages.savePropertiesFileFailedMsg, e);
        return;
    }
    IFileStore fileStore = Util.getFileStore(Host.PROPERTIES_FILE, hostDir);
    OutputStream os = null;
    try {
        os = fileStore.openOutputStream(EFS.NONE, null);
        props.setProperty(Host.HOST_PROP_KEY, hostName);
        //$NON-NLS-1$
        props.storeToXML(os, "Host Properties");
    } catch (CoreException e) {
        Activator.log(IStatus.ERROR, NLS.bind(Messages.openOutputStreamFailedMsg, fileStore.toURI().getPath()), e);
    } catch (IOException e) {
        try {
            fileStore.delete(EFS.NONE, null);
        } catch (CoreException e1) {
        // do nothing
        }
        Activator.log(IStatus.ERROR, NLS.bind(Messages.writePropertiesFileFailedMsg, fileStore.toURI().getPath()), e);
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
            // do nothing
            }
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException) OutputStream(java.io.OutputStream) IFileStore(org.eclipse.core.filesystem.IFileStore) IOException(java.io.IOException) Properties(java.util.Properties) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException)

Example 60 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project tdi-studio-se by Talend.

the class DumpCpuProfilingDataAction method performRun.

/*
     * @see AbstractJobAction#performRun(IProgressMonitor)
     */
@Override
protected IStatus performRun(IProgressMonitor monitor) {
    IActiveJvm jvm = section.getJvm();
    if (jvm == null) {
        return Status.CANCEL_STATUS;
    }
    IFileStore fileStore = null;
    try {
        fileStore = jvm.getCpuProfiler().dump();
    } catch (JvmCoreException e) {
        Activator.log(Messages.dumpCpuProfileDataFailedMsg, e);
        return Status.CANCEL_STATUS;
    }
    section.setPinned(true);
    OpenSnapshotAction.openEditor(fileStore);
    return Status.OK_STATUS;
}
Also used : IActiveJvm(org.talend.designer.runtime.visualization.IActiveJvm) IFileStore(org.eclipse.core.filesystem.IFileStore) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException)

Aggregations

IFileStore (org.eclipse.core.filesystem.IFileStore)105 CoreException (org.eclipse.core.runtime.CoreException)49 IPath (org.eclipse.core.runtime.IPath)29 IOException (java.io.IOException)26 IFileInfo (org.eclipse.core.filesystem.IFileInfo)25 IRemoteFileProxy (org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy)18 URI (java.net.URI)16 InputStream (java.io.InputStream)14 Path (org.eclipse.core.runtime.Path)14 IFile (org.eclipse.core.resources.IFile)12 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)12 InputStreamReader (java.io.InputStreamReader)11 PartInitException (org.eclipse.ui.PartInitException)11 BufferedReader (java.io.BufferedReader)10 URISyntaxException (java.net.URISyntaxException)10 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)10 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)10 Test (org.junit.Test)10 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)9 IStatus (org.eclipse.core.runtime.IStatus)9