Search in sources :

Example 6 with ElementTree

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;
}
Also used : ElementTree(org.eclipse.core.internal.watson.ElementTree)

Example 7 with ElementTree

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.");
    }
}
Also used : BuildData(org.eclipse.xtext.builder.impl.BuildData) QueuedBuildData(org.eclipse.xtext.builder.impl.QueuedBuildData) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) ResourceDelta(org.eclipse.core.internal.events.ResourceDelta) IResourceDelta(org.eclipse.core.resources.IResourceDelta) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) ResourceDelta(org.eclipse.core.internal.events.ResourceDelta) IResourceDelta(org.eclipse.core.resources.IResourceDelta) SubMonitor(org.eclipse.core.runtime.SubMonitor) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) ElementTree(org.eclipse.core.internal.watson.ElementTree) Workspace(org.eclipse.core.internal.resources.Workspace)

Example 8 with ElementTree

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;
}
Also used : ElementTree(org.eclipse.core.internal.watson.ElementTree)

Aggregations

ElementTree (org.eclipse.core.internal.watson.ElementTree)8 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BuilderPersistentInfo (org.eclipse.core.internal.events.BuilderPersistentInfo)1 ResourceDelta (org.eclipse.core.internal.events.ResourceDelta)1 Workspace (org.eclipse.core.internal.resources.Workspace)1 ElementTreeReader (org.eclipse.core.internal.watson.ElementTreeReader)1 IResourceDelta (org.eclipse.core.resources.IResourceDelta)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)1 BuildData (org.eclipse.xtext.builder.impl.BuildData)1 QueuedBuildData (org.eclipse.xtext.builder.impl.QueuedBuildData)1 Delta (org.eclipse.xtext.resource.IResourceDescription.Delta)1