use of org.eclipse.core.filesystem.IFileStore in project knime-core by knime.
the class EditMetaInfoAction method run.
/**
* {@inheritDoc}
*/
@Override
public void run() {
boolean isWorkflow = false;
if (m_parent.getChild(WorkflowPersistor.WORKFLOW_FILE).fetchInfo().exists()) {
isWorkflow = true;
}
// if no meta file is available
IFileStore metaFileTest = m_parent.getChild(WorkflowPersistor.METAINFO_FILE);
IFileInfo fetchInfo = metaFileTest.fetchInfo();
if (!fetchInfo.exists() || (fetchInfo.getLength() == 0)) {
// create one
File parentFile;
try {
parentFile = m_parent.toLocalFile(EFS.NONE, null);
} catch (CoreException e) {
throw new RuntimeException("Meta Info files can only be created" + " for local workflows or groups. " + m_parent.getName() + " doesn't provide a local file.");
}
if (parentFile == null) {
throw new RuntimeException("Meta Info files can only be created" + " for local workflows or groups. " + m_parent.getName() + " doesn't provide a local file.");
}
MetaInfoFile.createMetaInfoFile(parentFile, isWorkflow);
}
IFileStore metaFile = m_parent.getChild(WorkflowPersistor.METAINFO_FILE);
try {
IDE.openEditorOnFileStore(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), metaFile);
} catch (PartInitException e) {
String m = e.getMessage() == null ? "<no details>" : e.getMessage();
throw new RuntimeException("Unable to initialize editor for Meta Info file of " + m_parent.getName() + ": " + m, e);
}
}
use of org.eclipse.core.filesystem.IFileStore in project che by eclipse.
the class RefactoringHistoryManager method removeRefactoringDescriptors.
/**
* Removes refactoring descriptors from the managed history.
* <p>
* All refactoring descriptors must be from the history entry denoted by the
* specified path.
* </p>
*
* @param proxies
* the refactoring descriptors
* @param path
* the path of the history entry
* @param monitor
* the progress monitor to use
* @param task
* the task label to use
* @throws CoreException
* if an error occurs
*/
private void removeRefactoringDescriptors(final RefactoringDescriptorProxy[] proxies, final IPath path, final IProgressMonitor monitor, final String task) throws CoreException {
try {
monitor.beginTask(task, 5);
final IFileStore folder = fHistoryStore.getFileStore(path);
final IFileStore index = folder.getChild(RefactoringHistoryService.NAME_INDEX_FILE);
if (index.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)).exists()) {
final Set resultingProxies = new HashSet(64);
readRefactoringDescriptorProxies(index, null, resultingProxies, 0, Long.MAX_VALUE, new SubProgressMonitor(monitor, 1), task);
if (resultingProxies.size() == proxies.length)
removeIndexTree(folder, new SubProgressMonitor(monitor, 1), task);
else {
final IFileStore history = folder.getChild(RefactoringHistoryService.NAME_HISTORY_FILE);
if (history.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)).exists()) {
InputStream input = null;
Document document = null;
try {
input = new BufferedInputStream(history.openInputStream(EFS.NONE, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)));
document = getCachedDocument(path, input);
} 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
}
}
}
final Set removedNodes = new HashSet(proxies.length);
final NodeList list = document.getElementsByTagName(IRefactoringSerializationConstants.ELEMENT_REFACTORING);
final int length = list.getLength();
for (int offset = 0; offset < length; offset++) {
final Node node = list.item(offset);
final NamedNodeMap attributes = node.getAttributes();
if (attributes != null) {
final Node item = attributes.getNamedItem(IRefactoringSerializationConstants.ATTRIBUTE_STAMP);
if (item != null) {
final String value = item.getNodeValue();
if (value != null) {
for (int current = 0; current < proxies.length; current++) {
final RefactoringDescriptorProxy proxy = proxies[current];
final long stamp = proxy.getTimeStamp();
if (value.equals(String.valueOf(stamp))) {
resultingProxies.remove(new DefaultRefactoringDescriptorProxy(proxy.getDescription(), proxy.getProject(), stamp));
removedNodes.add(node);
}
}
}
}
}
}
for (final Iterator iterator = removedNodes.iterator(); iterator.hasNext(); ) {
final Node node = (Node) iterator.next();
node.getParentNode().removeChild(node);
}
try {
writeIndexEntry(index, (RefactoringDescriptorProxy[]) resultingProxies.toArray(new RefactoringDescriptorProxy[resultingProxies.size()]), EFS.NONE, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL), task);
writeHistoryEntry(history, document, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL), task);
} 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 requestDescriptor.
/**
* Requests the resolved refactoring descriptor associated with the given
* proxy.
*
* @param proxy
* the refactoring descriptor proxy
* @param monitor
* the progress monitor to use
* @return the associated refactoring descriptor, or <code>null</code>
*/
RefactoringDescriptor requestDescriptor(final RefactoringDescriptorProxy proxy, final IProgressMonitor monitor) {
try {
monitor.beginTask(RefactoringCoreMessages.RefactoringHistoryService_resolving_information, 2);
final long stamp = proxy.getTimeStamp();
if (stamp >= 0) {
InputStream input = null;
try {
final IFileStore folder = fHistoryStore.getFileStore(stampToPath(stamp));
final IFileStore file = folder.getChild(RefactoringHistoryService.NAME_HISTORY_FILE);
if (file.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)).exists()) {
input = new BufferedInputStream(file.openInputStream(EFS.NONE, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)));
final RefactoringSessionDescriptor descriptor = getCachedSession(file, fProjectName, input);
if (descriptor != null) {
final RefactoringDescriptor[] descriptors = descriptor.getRefactorings();
for (int index = 0; index < descriptors.length; index++) {
final RefactoringDescriptor refactoringDescriptor = descriptors[index];
if (refactoringDescriptor.getTimeStamp() == stamp) {
return refactoringDescriptor;
}
}
}
}
} catch (CoreException exception) {
RefactoringCorePlugin.log(exception);
} finally {
try {
if (input != null)
input.close();
} catch (IOException exception) {
RefactoringCorePlugin.log(exception);
}
}
}
} finally {
monitor.done();
}
return null;
}
use of org.eclipse.core.filesystem.IFileStore in project che by eclipse.
the class RefactoringHistoryService method setSharedRefactoringHistory.
/**
* Determines whether a project has a shared refactoring history.
* <p>
* If a shared refactoring history is enabled, refactorings executed on that
* particular project are stored in a hidden refactoring history folder of
* the project folder. If no shared refactoring history is enabled, all
* refactorings are tracked as well, but persisted internally in a
* plugin-specific way without altering the project.
* </p>
* <p>
* Note: this method simply copies the content of the refactoring history
* folder to the location corresponding to the shared history setting.
* Clients wishing to programmatically change the refactoring history
* location have to update the preference
* {@link RefactoringPreferenceConstants#PREFERENCE_SHARED_REFACTORING_HISTORY}
* located in the preference store of the
* <code>org.eclipse.ltk.core.refactoring</code> plugin accordingly.
* </p>
*
* @param project
* the project to set the shared refactoring history property
* @param enable
* <code>true</code> to enable a shared refactoring history,
* <code>false</code> otherwise
* @param monitor
* the progress monitor to use, or <code>null</code>
* @throws CoreException
* if an error occurs while changing the shared refactoring
* history property. Reasons include:
* <ul>
* <li>An I/O error occurs while changing the shared
* refactoring history property.</li>
* </ul>
*/
public static void setSharedRefactoringHistory(final IProject project, final boolean enable, IProgressMonitor monitor) throws CoreException {
Assert.isNotNull(project);
Assert.isTrue(project.isAccessible());
if (monitor == null)
monitor = new NullProgressMonitor();
try {
//$NON-NLS-1$
monitor.beginTask("", 300);
final String name = project.getName();
final URI uri = project.getLocationURI();
if (uri != null) {
try {
final IFileStore history = EFS.getLocalFileSystem().getStore(RefactoringCorePlugin.getDefault().getStateLocation()).getChild(NAME_HISTORY_FOLDER);
if (enable) {
final IFileStore source = history.getChild(name);
if (source.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 20)).exists()) {
IFileStore destination = EFS.getStore(uri).getChild(NAME_HISTORY_FOLDER);
if (destination.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 20)).exists())
destination.delete(EFS.NONE, new SubProgressMonitor(monitor, 20));
destination.mkdir(EFS.NONE, new SubProgressMonitor(monitor, 20));
source.copy(destination, EFS.OVERWRITE, new SubProgressMonitor(monitor, 20));
source.delete(EFS.NONE, new SubProgressMonitor(monitor, 20));
}
} else {
final IFileStore source = EFS.getStore(uri).getChild(NAME_HISTORY_FOLDER);
if (source.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 20)).exists()) {
IFileStore destination = history.getChild(name);
if (destination.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 20)).exists())
destination.delete(EFS.NONE, new SubProgressMonitor(monitor, 20));
destination.mkdir(EFS.NONE, new SubProgressMonitor(monitor, 20));
source.copy(destination, EFS.OVERWRITE, new SubProgressMonitor(monitor, 20));
source.delete(EFS.NONE, new SubProgressMonitor(monitor, 20));
}
}
} finally {
if (enable)
project.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 30));
else {
final IFolder folder = project.getFolder(NAME_HISTORY_FOLDER);
if (folder.exists())
folder.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 30));
}
}
}
} finally {
monitor.done();
}
}
use of org.eclipse.core.filesystem.IFileStore in project che by eclipse.
the class RefactoringHistoryManager method setComment.
/**
* Sets the comment of the specified refactoring.
*
* @param proxy
* the refactoring descriptor proxy
* @param comment
* the comment
* @param monitor
* the progress monitor to use
* @throws CoreException
* if an error occurs while setting the comment
*/
void setComment(final RefactoringDescriptorProxy proxy, final String comment, final IProgressMonitor monitor) throws CoreException {
try {
monitor.beginTask(RefactoringCoreMessages.RefactoringHistoryService_updating_history, 100);
final long stamp = proxy.getTimeStamp();
if (stamp >= 0) {
final IPath path = stampToPath(stamp);
final IFileStore folder = fHistoryStore.getFileStore(path);
final IFileStore history = folder.getChild(RefactoringHistoryService.NAME_HISTORY_FILE);
if (history.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 20, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)).exists()) {
InputStream input = null;
try {
input = new BufferedInputStream(history.openInputStream(EFS.NONE, new SubProgressMonitor(monitor, 40, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)));
final Document document = getCachedDocument(path, input);
try {
input.close();
input = null;
} catch (IOException exception) {
// Do nothing
}
final String time = String.valueOf(stamp);
final NodeList list = document.getElementsByTagName(IRefactoringSerializationConstants.ELEMENT_REFACTORING);
for (int index = 0; index < list.getLength(); index++) {
final Element element = (Element) list.item(index);
if (time.equals(element.getAttribute(IRefactoringSerializationConstants.ATTRIBUTE_STAMP))) {
element.setAttribute(IRefactoringSerializationConstants.ATTRIBUTE_COMMENT, comment);
break;
}
}
writeHistoryEntry(history, document, new SubProgressMonitor(monitor, 40, 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
}
}
}
}
}
} finally {
monitor.done();
}
}
Aggregations