use of org.eclipse.core.internal.watson.ElementTree in project polymap4-core by Polymap4.
the class NotificationManager method getDelta.
/**
* Computes and returns the resource delta for the given event type and the
* given current tree state.
*/
protected ResourceDelta getDelta(ElementTree tree, int type) {
long id = workspace.getMarkerManager().getChangeId();
// If we have a delta from last time and no resources have changed
// since then, we can reuse the delta structure.
// However, be sure not to mix deltas from post_change with build events, because they use
// a different reference point for delta computation.
boolean postChange = type == IResourceChangeEvent.POST_CHANGE;
if (!postChange && lastDelta != null && !ElementTree.hasChanges(tree, lastDeltaState, ResourceComparator.getNotificationComparator(), true)) {
// marker state and insert it in to the delta which is being reused.
if (id != lastDeltaId) {
Map markerDeltas = workspace.getMarkerManager().getMarkerDeltas(lastPostBuildId);
lastDelta.updateMarkers(markerDeltas);
}
} else {
// We don't have a delta or something changed so recompute the whole deal.
ElementTree oldTree = postChange ? lastPostChangeTree : lastPostBuildTree;
long markerId = postChange ? lastPostChangeId : lastPostBuildId;
lastDelta = ResourceDeltaFactory.computeDelta(workspace, oldTree, tree, Path.ROOT, markerId + 1);
}
// remember the state of the world when this delta was consistent
lastDeltaState = tree;
lastDeltaId = id;
return lastDelta;
}
use of org.eclipse.core.internal.watson.ElementTree in project dsl-devkit by dsldevkit.
the class RebuildingXtextBuilder method doBuild.
/**
* Like the super implementation, except the build is not triggered if
* both toBeDeleted and toBeUpdated are empty. {@inheritDoc}
*/
@SuppressWarnings("nls")
@Override
protected void doBuild(final ToBeBuilt toBeBuilt, final IProgressMonitor monitor, final BuildType type) throws CoreException {
if (toBeBuilt.getToBeDeleted().size() != 0 || toBeBuilt.getToBeUpdated().size() != 0) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Starting " + type.name() + " build:" + "\ndeleted(" + toBeBuilt.getToBeDeleted().size() + ")=" + toBeBuilt.getToBeDeleted().toString() + "\nupdated(" + toBeBuilt.getToBeUpdated().size() + ")=" + toBeBuilt.getToBeUpdated().toString());
}
// build + participant + rebuild
SubMonitor progress = SubMonitor.convert(monitor, 1 + 1 + 1);
ResourceSet resourceSet = getResourceSetProvider().get(getProject());
resourceSet.getLoadOptions().put(ResourceDescriptionsProvider.NAMED_BUILDER_SCOPE, Boolean.TRUE);
if (resourceSet instanceof ResourceSetImpl) {
((ResourceSetImpl) resourceSet).setURIResourceMap(Maps.<URI, Resource>newHashMap());
}
BuildData buildData = new BuildData(getProject().getName(), resourceSet, toBeBuilt, queuedBuildData);
ImmutableList<Delta> deltas = builderState.update(buildData, progress.newChild(1));
if (participant != null) {
final BuildContext buildContext = new BuildContext(this, resourceSet, deltas, type);
// remember the current workspace tree
final ElementTree oldTree = ((Workspace) ResourcesPlugin.getWorkspace()).getElementTree();
oldTree.immutable();
participant.build(buildContext, progress.newChild(1));
if (buildContext.isRebuildRequired() && rebuilds++ <= 2) {
final ElementTree newTree = ((Workspace) ResourcesPlugin.getWorkspace()).getElementTree();
newTree.immutable();
final ResourceDelta generatedDelta = ResourceDeltaFactory.computeDelta((Workspace) ResourcesPlugin.getWorkspace(), oldTree, newTree, getProject().getFullPath(), -1);
// rebuild the generated delta
ResourcesPlugin.getWorkspace().checkpoint(false);
incrementalBuild(generatedDelta, progress.newChild(1));
}
} else {
progress.worked(2);
}
resourceSet.getResources().clear();
resourceSet.eAdapters().clear();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Build done.");
}
} else if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Ignoring empty " + type.name() + " build.");
}
}
use of org.eclipse.core.internal.watson.ElementTree in project polymap4-core by Polymap4.
the class BuildManager method needsBuild.
/**
* Returns true if the given builder needs to be invoked, and false
* otherwise.
*
* The algorithm is to compute the intersection of the set of projects that
* have changed since the last build, and the set of projects this builder
* cares about. This is an optimization, under the assumption that computing
* the forward delta once (not the resource delta) is more efficient than
* computing project deltas and invoking builders for projects that haven't
* changed.
*/
private boolean needsBuild(InternalBuilder builder, int trigger) {
// on some triggers we build regardless of the delta
switch(trigger) {
case IncrementalProjectBuilder.CLEAN_BUILD:
return true;
case IncrementalProjectBuilder.FULL_BUILD:
return true;
case IncrementalProjectBuilder.INCREMENTAL_BUILD:
if (currentBuilder.callOnEmptyDelta())
return true;
}
// compute the delta since the last built state
ElementTree oldTree = builder.getLastBuiltTree();
ElementTree newTree = workspace.getElementTree();
long start = System.currentTimeMillis();
currentDelta = (DeltaDataTree) deltaTreeCache.getDelta(null, oldTree, newTree);
if (currentDelta == null) {
if (Policy.DEBUG_BUILD_NEEDED) {
// $NON-NLS-1$ //$NON-NLS-2$
String message = "Checking if need to build. Starting delta computation between: " + oldTree.toString() + " and " + newTree.toString();
Policy.debug(message);
}
currentDelta = newTree.getDataTree().forwardDeltaWith(oldTree.getDataTree(), ResourceComparator.getBuildComparator());
if (Policy.DEBUG_BUILD_NEEDED)
// $NON-NLS-1$ //$NON-NLS-2$
Policy.debug("End delta computation. (" + (System.currentTimeMillis() - start) + "ms).");
deltaTreeCache.cache(null, oldTree, newTree, currentDelta);
}
// search for the builder's project
if (currentDelta.findNodeAt(builder.getProject().getFullPath()) != null) {
if (Policy.DEBUG_BUILD_NEEDED)
// $NON-NLS-1$
Policy.debug(toString(builder) + " needs building because of changes in: " + builder.getProject().getName());
return true;
}
// search for builder's interesting projects
IProject[] projects = builder.getInterestingProjects();
for (int i = 0; i < projects.length; i++) {
if (currentDelta.findNodeAt(projects[i].getFullPath()) != null) {
if (Policy.DEBUG_BUILD_NEEDED)
// $NON-NLS-1$
Policy.debug(toString(builder) + " needs building because of changes in: " + projects[i].getName());
return true;
}
}
return false;
}
Aggregations