use of org.eclipse.core.runtime.jobs.ISchedulingRule in project polymap4-core by Polymap4.
the class Resource method touch.
/* (non-Javadoc)
* @see IResource#touch(IProgressMonitor)
*/
public void touch(IProgressMonitor monitor) throws CoreException {
monitor = Policy.monitorFor(monitor);
try {
String message = NLS.bind(Messages.resources_touch, getFullPath());
monitor.beginTask(message, Policy.totalWork);
final ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this);
try {
workspace.prepareOperation(rule, monitor);
ResourceInfo info = checkAccessibleAndLocal(DEPTH_ZERO);
workspace.beginOperation(true);
// fake a change by incrementing the content ID
info = getResourceInfo(false, true);
info.incrementContentId();
// forget content-related caching flags
info.clear(M_CONTENT_CACHE);
workspace.updateModificationStamp(info);
monitor.worked(Policy.opWork);
} catch (OperationCanceledException e) {
workspace.getWorkManager().operationCanceled();
throw e;
} finally {
workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
}
} finally {
monitor.done();
}
}
use of org.eclipse.core.runtime.jobs.ISchedulingRule in project polymap4-core by Polymap4.
the class Project method close.
/* (non-Javadoc)
* @see IProject#close(IProgressMonitor)
*/
public void close(IProgressMonitor monitor) throws CoreException {
monitor = Policy.monitorFor(monitor);
try {
String msg = NLS.bind(Messages.resources_closing_1, getName());
monitor.beginTask(msg, Policy.totalWork);
final ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this);
try {
workspace.prepareOperation(rule, monitor);
ResourceInfo info = getResourceInfo(false, false);
int flags = getFlags(info);
checkExists(flags, true);
monitor.subTask(msg);
if (!isOpen(flags))
return;
// Signal that this resource is about to be closed. Do this at the very
// beginning so that infrastructure pieces have a chance to do clean up
// while the resources still exist.
workspace.beginOperation(true);
workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_CLOSE, this));
// flush the build order early in case there is a problem
workspace.flushBuildOrder();
IProgressMonitor sub = Policy.subMonitorFor(monitor, Policy.opWork / 2, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL);
IStatus saveStatus = workspace.getSaveManager().save(ISaveContext.PROJECT_SAVE, this, sub);
internalClose();
monitor.worked(Policy.opWork / 2);
if (saveStatus != null && !saveStatus.isOK())
throw new ResourceException(saveStatus);
} catch (OperationCanceledException e) {
workspace.getWorkManager().operationCanceled();
throw e;
} finally {
workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
}
} finally {
monitor.done();
}
}
use of org.eclipse.core.runtime.jobs.ISchedulingRule in project polymap4-core by Polymap4.
the class Project method setDescription.
/* (non-Javadoc)
* @see IProject#setDescription(IProjectDescription, int, IProgressMonitor)
*/
public void setDescription(IProjectDescription description, int updateFlags, IProgressMonitor monitor) throws CoreException {
// FIXME - update flags should be honored:
// KEEP_HISTORY means capture .project file in local history
// FORCE means overwrite any existing .project file
monitor = Policy.monitorFor(monitor);
try {
monitor.beginTask(Messages.resources_setDesc, Policy.totalWork);
ISchedulingRule rule = null;
if ((updateFlags & IResource.AVOID_NATURE_CONFIG) != 0)
rule = workspace.getRuleFactory().modifyRule(this);
else
rule = workspace.getRoot();
try {
// need to use root rule because nature configuration calls third party code
workspace.prepareOperation(rule, monitor);
ResourceInfo info = getResourceInfo(false, false);
checkAccessible(getFlags(info));
// if nothing has changed, we don't need to do anything
ProjectDescription oldDescription = internalGetDescription();
ProjectDescription newDescription = (ProjectDescription) description;
boolean hasPublicChanges = oldDescription.hasPublicChanges(newDescription);
boolean hasPrivateChanges = oldDescription.hasPrivateChanges(newDescription);
if (!hasPublicChanges && !hasPrivateChanges)
return;
checkDescription(this, newDescription, false);
// If we're out of sync and !FORCE, then fail.
// If the file is missing, we want to write the new description then throw an exception.
boolean hadSavedDescription = true;
if (((updateFlags & IResource.FORCE) == 0)) {
hadSavedDescription = getLocalManager().hasSavedDescription(this);
if (hadSavedDescription && !getLocalManager().isDescriptionSynchronized(this)) {
String message = NLS.bind(Messages.resources_projectDescSync, getName());
throw new ResourceException(IResourceStatus.OUT_OF_SYNC_LOCAL, getFullPath(), message, null);
}
}
// see if we have an old .prj file
if (!hadSavedDescription)
hadSavedDescription = workspace.getMetaArea().hasSavedProject(this);
workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_CHANGE, this));
workspace.beginOperation(true);
MultiStatus status = basicSetDescription(newDescription, updateFlags);
if (hadSavedDescription && !status.isOK())
throw new CoreException(status);
// write the new description to the .project file
writeDescription(oldDescription, updateFlags, hasPublicChanges, hasPrivateChanges);
// increment the content id even for private changes
info = getResourceInfo(false, true);
info.incrementContentId();
workspace.updateModificationStamp(info);
if (!hadSavedDescription) {
String msg = NLS.bind(Messages.resources_missingProjectMetaRepaired, getName());
status.merge(new ResourceStatus(IResourceStatus.MISSING_DESCRIPTION_REPAIRED, getFullPath(), msg));
}
if (!status.isOK())
throw new CoreException(status);
} finally {
workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
}
} finally {
monitor.done();
}
}
use of org.eclipse.core.runtime.jobs.ISchedulingRule in project polymap4-core by Polymap4.
the class Project method create.
/* (non-Javadoc)
* @see IProject#create(IProjectDescription, IProgressMonitor)
*/
public void create(IProjectDescription description, int updateFlags, IProgressMonitor monitor) throws CoreException {
monitor = Policy.monitorFor(monitor);
try {
monitor.beginTask(Messages.resources_create, Policy.totalWork);
checkValidPath(path, PROJECT, false);
final ISchedulingRule rule = workspace.getRuleFactory().createRule(this);
try {
workspace.prepareOperation(rule, monitor);
if (description == null) {
description = new ProjectDescription();
description.setName(getName());
}
assertCreateRequirements(description);
workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_CREATE, this));
workspace.beginOperation(true);
workspace.createResource(this, updateFlags);
workspace.getMetaArea().create(this);
ProjectInfo info = (ProjectInfo) getResourceInfo(false, true);
// setup description to obtain project location
ProjectDescription desc = (ProjectDescription) ((ProjectDescription) description).clone();
desc.setLocationURI(FileUtil.canonicalURI(description.getLocationURI()));
desc.setName(getName());
internalSetDescription(desc, false);
// see if there potentially are already contents on disk
final boolean hasSavedDescription = getLocalManager().hasSavedDescription(this);
boolean hasContent = hasSavedDescription;
// if there is no project description, there might still be content on disk
if (!hasSavedDescription)
hasContent = getLocalManager().hasSavedContent(this);
try {
// look for a description on disk
if (hasSavedDescription) {
updateDescription();
// make sure the .location file is written
workspace.getMetaArea().writePrivateDescription(this);
} else {
// write out the project
writeDescription(IResource.FORCE);
}
} catch (CoreException e) {
workspace.deleteResource(this);
throw e;
}
// inaccessible projects have a null modification stamp.
// set this after setting the description as #setDescription
// updates the stamp
info.clearModificationStamp();
// if a project already had content on disk, mark the project as having unknown children
if (hasContent)
info.set(ICoreConstants.M_CHILDREN_UNKNOWN);
workspace.getSaveManager().requestSnapshot();
} catch (OperationCanceledException e) {
workspace.getWorkManager().operationCanceled();
throw e;
} finally {
workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
}
} finally {
monitor.done();
}
}
use of org.eclipse.core.runtime.jobs.ISchedulingRule in project polymap4-core by Polymap4.
the class SaveManager method save.
public IStatus save(int kind, boolean keepConsistencyWhenCanceled, Project project, IProgressMonitor parentMonitor) throws CoreException {
InternalMonitorWrapper monitor = new InternalMonitorWrapper(parentMonitor);
monitor.ignoreCancelState(keepConsistencyWhenCanceled);
try {
isSaving = true;
String message = Messages.resources_saving_0;
monitor.beginTask(message, 7);
message = Messages.resources_saveWarnings;
MultiStatus warnings = new MultiStatus(ResourcesPlugin.PI_RESOURCES, IStatus.WARNING, message, null);
ISchedulingRule rule = project != null ? (IResource) project : workspace.getRoot();
try {
workspace.prepareOperation(rule, monitor);
workspace.beginOperation(false);
hookStartSave(kind, project);
long start = System.currentTimeMillis();
Map contexts = computeSaveContexts(getSaveParticipantPlugins(), kind, project);
broadcastLifecycle(PREPARE_TO_SAVE, contexts, warnings, Policy.subMonitorFor(monitor, 1));
try {
broadcastLifecycle(SAVING, contexts, warnings, Policy.subMonitorFor(monitor, 1));
switch(kind) {
case ISaveContext.FULL_SAVE:
// save the complete tree and remember all of the required saved states
saveTree(contexts, Policy.subMonitorFor(monitor, 1));
// reset the snapshot state.
initSnap(null);
// save master table right after saving tree to ensure correct tree number is saved
cleanMasterTable();
// save all of the markers and all sync info in the workspace
persistMarkers = 0l;
persistSyncInfo = 0l;
visitAndSave(workspace.getRoot());
monitor.worked(1);
if (Policy.DEBUG_SAVE) {
// $NON-NLS-1$ //$NON-NLS-2$
Policy.debug("Total Save Markers: " + persistMarkers + "ms");
// $NON-NLS-1$ //$NON-NLS-2$
Policy.debug("Total Save Sync Info: " + persistSyncInfo + "ms");
}
// reset the snap shot files
resetSnapshots(workspace.getRoot());
// remove unused files
removeUnusedSafeTables();
removeUnusedTreeFiles();
// history pruning can be always canceled
monitor.ignoreCancelState(false);
workspace.getFileSystemManager().getHistoryStore().clean(Policy.subMonitorFor(monitor, 1));
monitor.ignoreCancelState(keepConsistencyWhenCanceled);
// write out all metainfo (e.g., workspace/project descriptions)
saveMetaInfo(warnings, Policy.subMonitorFor(monitor, 1));
break;
case ISaveContext.SNAPSHOT:
snapTree(workspace.getElementTree(), Policy.subMonitorFor(monitor, 1));
// snapshot the markers and sync info for the workspace
persistMarkers = 0l;
persistSyncInfo = 0l;
visitAndSnap(workspace.getRoot());
monitor.worked(1);
if (Policy.DEBUG_SAVE) {
// $NON-NLS-1$ //$NON-NLS-2$
Policy.debug("Total Snap Markers: " + persistMarkers + "ms");
// $NON-NLS-1$ //$NON-NLS-2$
Policy.debug("Total Snap Sync Info: " + persistSyncInfo + "ms");
}
collapseTrees();
clearSavedDelta();
// write out all metainfo (e.g., workspace/project descriptions)
saveMetaInfo(warnings, Policy.subMonitorFor(monitor, 1));
break;
case ISaveContext.PROJECT_SAVE:
writeTree(project, IResource.DEPTH_INFINITE);
monitor.worked(1);
// save markers and sync info
visitAndSave(project);
monitor.worked(1);
// reset the snapshot file
resetSnapshots(project);
IStatus result = saveMetaInfo(project, null);
if (!result.isOK())
warnings.merge(result);
monitor.worked(1);
break;
}
// save contexts
commit(contexts);
if (kind == ISaveContext.FULL_SAVE)
removeClearDeltaMarks();
// this must be done after committing save contexts to update participant save numbers
saveMasterTable();
broadcastLifecycle(DONE_SAVING, contexts, warnings, Policy.subMonitorFor(monitor, 1));
hookEndSave(kind, project, start);
return warnings;
} catch (CoreException e) {
broadcastLifecycle(ROLLBACK, contexts, warnings, Policy.subMonitorFor(monitor, 1));
// rollback ResourcesPlugin master table
restoreMasterTable();
// re-throw
throw e;
}
} catch (OperationCanceledException e) {
workspace.getWorkManager().operationCanceled();
throw e;
} finally {
workspace.endOperation(rule, false, Policy.monitorFor(null));
}
} finally {
isSaving = false;
monitor.done();
}
}
Aggregations