Search in sources :

Example 1 with BuildData

use of org.eclipse.xtext.builder.impl.BuildData 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 2 with BuildData

use of org.eclipse.xtext.builder.impl.BuildData in project xtext-eclipse by eclipse.

the class Bug349445Test method testUpdate.

@Test
public void testUpdate() {
    testMe.update(new BuildData(null, null, new ToBeBuilt(), new QueuedBuildData(null)), null);
    assertEquals(1, loadCalled);
}
Also used : QueuedBuildData(org.eclipse.xtext.builder.impl.QueuedBuildData) BuildData(org.eclipse.xtext.builder.impl.BuildData) ToBeBuilt(org.eclipse.xtext.builder.impl.ToBeBuilt) QueuedBuildData(org.eclipse.xtext.builder.impl.QueuedBuildData) Test(org.junit.Test)

Example 3 with BuildData

use of org.eclipse.xtext.builder.impl.BuildData in project xtext-eclipse by eclipse.

the class PersistableResourceDescriptionsTest method update.

private Map<URI, IResourceDescription.Delta> update(Set<URI> toBeUpdated, Set<URI> toBeDeleted) {
    ResourceSet resourceSet = createResourceSet();
    try {
        ToBeBuilt toBeBuilt = new ToBeBuilt();
        if (toBeDeleted != null)
            toBeBuilt.getToBeDeleted().addAll(toBeDeleted);
        if (toBeUpdated != null)
            toBeBuilt.getToBeUpdated().addAll(toBeUpdated);
        BuildData buildData = new BuildData("", resourceSet, toBeBuilt, builderInjector.getInstance(QueuedBuildData.class));
        ImmutableList<Delta> update = builderState.update(buildData, new NullProgressMonitor());
        return Maps.uniqueIndex(update, new Function<IResourceDescription.Delta, URI>() {

            @Override
            public URI apply(IResourceDescription.Delta from) {
                return from.getUri();
            }
        });
    } finally {
        resourceSet.getResources().clear();
    }
}
Also used : BuildData(org.eclipse.xtext.builder.impl.BuildData) QueuedBuildData(org.eclipse.xtext.builder.impl.QueuedBuildData) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ToBeBuilt(org.eclipse.xtext.builder.impl.ToBeBuilt) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) QueuedBuildData(org.eclipse.xtext.builder.impl.QueuedBuildData) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI)

Aggregations

BuildData (org.eclipse.xtext.builder.impl.BuildData)3 QueuedBuildData (org.eclipse.xtext.builder.impl.QueuedBuildData)3 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2 ToBeBuilt (org.eclipse.xtext.builder.impl.ToBeBuilt)2 Delta (org.eclipse.xtext.resource.IResourceDescription.Delta)2 ResourceDelta (org.eclipse.core.internal.events.ResourceDelta)1 Workspace (org.eclipse.core.internal.resources.Workspace)1 ElementTree (org.eclipse.core.internal.watson.ElementTree)1 IResourceDelta (org.eclipse.core.resources.IResourceDelta)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 URI (org.eclipse.emf.common.util.URI)1 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)1 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)1 Test (org.junit.Test)1