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