Search in sources :

Example 16 with Delta

use of org.eclipse.xtext.resource.IResourceDescription.Delta in project xtext-eclipse by eclipse.

the class XtextBuilder method doClean.

/**
 * @param monitor the progress monitor to use for reporting progress to the user. It is the caller's responsibility
 *        to call done() on the given monitor. Accepts null, indicating that no progress should be
 *        reported and that the operation cannot be cancelled.
 */
protected void doClean(ToBeBuilt toBeBuilt, IProgressMonitor monitor) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, 2);
    ImmutableList<Delta> deltas = builderState.clean(toBeBuilt.getToBeDeleted(), progress.newChild(1));
    if (participant != null) {
        Set<URI> sourceURIs = new SourceLevelURICache().getSourcesFrom(toBeBuilt.getToBeDeleted(), resourceServiceProvideRegistry);
        participant.build(new BuildContext(this, getResourceSetProvider().get(getProject()), deltas, sourceURIs, BuildType.CLEAN), progress.newChild(1));
    } else {
        progress.worked(1);
    }
}
Also used : IResourceDelta(org.eclipse.core.resources.IResourceDelta) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) SubMonitor(org.eclipse.core.runtime.SubMonitor) URI(org.eclipse.emf.common.util.URI)

Example 17 with Delta

use of org.eclipse.xtext.resource.IResourceDescription.Delta in project n4js by eclipse.

the class N4JSGenerateImmediatelyBuilderState method doUpdate.

/**
 * {@inheritDoc}
 *
 * Initializes an adapter which is attached to the builder's resource set. This adapter will be used later on to
 * process each delta after the corresponding resource was validated.
 *
 * @param buildData
 *            the data that should be considered for the update
 * @param newData
 *            the new resource descriptions as they are to be persisted (the new index after the build). Initially
 *            contains the old resource descriptions.
 * @param monitor
 *            The progress monitor
 * @return A list of deltas describing all changes made by the build.
 */
@Override
protected Collection<Delta> doUpdate(BuildData buildData, ResourceDescriptionsData newData, IProgressMonitor monitor) {
    builderStateLogger.log("N4JSGenerateImmediatelyBuilderState.doUpdate() >>>");
    logBuildData(buildData, " of before #doUpdate");
    IProject project = getProject(buildData);
    try (ClosableMeasurement m = dcBuild.getClosableMeasurement("build " + Instant.now())) {
        BuildType buildType = N4JSBuildTypeTracker.getBuildType(project);
        IBuildParticipantInstruction instruction;
        if (buildType == null) {
            instruction = IBuildParticipantInstruction.NOOP;
        } else {
            instruction = findJSBuilderParticipant().prepareBuild(project, buildType);
        }
        // removed after the build automatically;
        // the resource set is discarded afterwards, anyway
        buildData.getResourceSet().eAdapters().add(instruction);
    } catch (CoreException e) {
        handleCoreException(e);
    }
    Collection<Delta> modifiedDeltas = super.doUpdate(buildData, newData, monitor);
    logBuildData(buildData, " of after #doUpdate");
    builderStateLogger.log("Modified deltas: " + modifiedDeltas);
    builderStateLogger.log("N4JSGenerateImmediatelyBuilderState.doUpdate() <<<");
    return modifiedDeltas;
}
Also used : ClosableMeasurement(org.eclipse.n4js.smith.ClosableMeasurement) IBuildParticipantInstruction(org.eclipse.n4js.ui.building.instructions.IBuildParticipantInstruction) CoreException(org.eclipse.core.runtime.CoreException) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) DefaultResourceDescriptionDelta(org.eclipse.xtext.resource.impl.DefaultResourceDescriptionDelta) BuildType(org.eclipse.xtext.builder.IXtextBuilderParticipant.BuildType) IProject(org.eclipse.core.resources.IProject)

Example 18 with Delta

use of org.eclipse.xtext.resource.IResourceDescription.Delta in project n4js by eclipse.

the class BuildInstruction method finish.

@Override
public void finish(List<Delta> deltas, IProgressMonitor progressMonitor) throws CoreException {
    for (Delta delta : deltas) {
        if (delta.getNew() == null) {
            String uri = delta.getUri().toString();
            recordDerivedResources(uri);
            deleteObsoleteResources(uri, progressMonitor);
        }
    }
    deleteEmptyDirectories(progressMonitor);
}
Also used : Delta(org.eclipse.xtext.resource.IResourceDescription.Delta)

Example 19 with Delta

use of org.eclipse.xtext.resource.IResourceDescription.Delta in project dsl-devkit by dsldevkit.

the class MonitoredClusteringBuilderState method clean.

@Override
public synchronized ImmutableList<IResourceDescription.Delta> clean(final Set<URI> toBeRemoved, final IProgressMonitor monitor) {
    ensureLoaded();
    Set<URI> toBeRemovedCopy = ensureNotNull(toBeRemoved);
    SubMonitor subMonitor = SubMonitor.convert(monitor, org.eclipse.xtext.builder.builderState.Messages.AbstractBuilderState_0, 2);
    subMonitor.subTask(org.eclipse.xtext.builder.builderState.Messages.AbstractBuilderState_0);
    if (toBeRemovedCopy.isEmpty()) {
        return ImmutableList.of();
    }
    checkForCancellation(monitor);
    Collection<IResourceDescription.Delta> deltas = doClean(toBeRemovedCopy, subMonitor.newChild(1));
    final ResourceDescriptionsData newData = getCopiedResourceDescriptionsData();
    ResourceDescriptionChangeEvent event = null;
    try {
        checkForCancellation(monitor);
        for (IResourceDescription.Delta delta : deltas) {
            newData.removeDescription(delta.getOld().getURI());
        }
        event = new ResourceDescriptionChangeEvent(deltas);
        checkForCancellation(monitor);
        updateDeltas(event.getDeltas(), null, subMonitor.newChild(1));
        // update the reference
        setResourceDescriptionsData(newData, monitor);
    // CHECKSTYLE:CHECK-OFF IllegalCatch
    } catch (Throwable t) {
        // CHECKSTYLE:CHEKC-ON IllegalCatch
        if (newData instanceof AbstractResourceDescriptionsData) {
            ((AbstractResourceDescriptionsData) newData).rollbackChanges();
        }
        throw t;
    }
    notifyListeners(event);
    return event.getDeltas();
}
Also used : IResourceDescriptionsData(com.avaloq.tools.ddk.xtext.extensions.IResourceDescriptionsData) ResourceDescriptionsData(org.eclipse.xtext.resource.impl.ResourceDescriptionsData) NullResourceDescriptionsData(com.avaloq.tools.ddk.xtext.builder.layered.NullResourceDescriptionsData) AbstractResourceDescriptionsData(com.avaloq.tools.ddk.xtext.extensions.AbstractResourceDescriptionsData) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) DefaultResourceDescriptionDelta(org.eclipse.xtext.resource.impl.DefaultResourceDescriptionDelta) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) SubMonitor(org.eclipse.core.runtime.SubMonitor) AbstractResourceDescriptionsData(com.avaloq.tools.ddk.xtext.extensions.AbstractResourceDescriptionsData) URI(org.eclipse.emf.common.util.URI) ResourceDescriptionChangeEvent(org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent)

Example 20 with Delta

use of org.eclipse.xtext.resource.IResourceDescription.Delta in project dsl-devkit by dsldevkit.

the class MonitoredClusteringBuilderState method update.

@Override
@SuppressWarnings("PMD.AvoidInstanceofChecksInCatchClause")
public synchronized ImmutableList<Delta> update(final BuildData buildData, final IProgressMonitor monitor) {
    ensureLoaded();
    final SubMonitor subMonitor = SubMonitor.convert(monitor, org.eclipse.xtext.builder.builderState.Messages.AbstractBuilderState_0, 1);
    subMonitor.subTask(org.eclipse.xtext.builder.builderState.Messages.AbstractBuilderState_0);
    checkForCancellation(monitor);
    final ResourceDescriptionsData newData = getCopiedResourceDescriptionsData();
    Collection<IResourceDescription.Delta> result = null;
    try {
        result = doUpdate(buildData, newData, subMonitor.newChild(1));
        // update the reference
        setResourceDescriptionsData(newData, monitor);
    // CHECKSTYLE:CHECK-OFF IllegalCatch
    } catch (Throwable t) {
        // CHECKSTYLE:CHECK-ON IllegalCatch
        if (!operationCanceledManager.isOperationCanceledException(t)) {
            // $NON-NLS-1$
            LOGGER.error("Failed to update index. Executing rollback.", t);
        }
        if (newData instanceof AbstractResourceDescriptionsData) {
            ((AbstractResourceDescriptionsData) newData).rollbackChanges();
        }
        throw t;
    }
    final ResourceDescriptionChangeEvent event = new ResourceDescriptionChangeEvent(result);
    notifyListeners(event);
    return event.getDeltas();
}
Also used : IResourceDescriptionsData(com.avaloq.tools.ddk.xtext.extensions.IResourceDescriptionsData) ResourceDescriptionsData(org.eclipse.xtext.resource.impl.ResourceDescriptionsData) NullResourceDescriptionsData(com.avaloq.tools.ddk.xtext.builder.layered.NullResourceDescriptionsData) AbstractResourceDescriptionsData(com.avaloq.tools.ddk.xtext.extensions.AbstractResourceDescriptionsData) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) DefaultResourceDescriptionDelta(org.eclipse.xtext.resource.impl.DefaultResourceDescriptionDelta) SubMonitor(org.eclipse.core.runtime.SubMonitor) AbstractResourceDescriptionsData(com.avaloq.tools.ddk.xtext.extensions.AbstractResourceDescriptionsData) ResourceDescriptionChangeEvent(org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent)

Aggregations

Delta (org.eclipse.xtext.resource.IResourceDescription.Delta)38 URI (org.eclipse.emf.common.util.URI)22 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)17 SubMonitor (org.eclipse.core.runtime.SubMonitor)13 DefaultResourceDescriptionDelta (org.eclipse.xtext.resource.impl.DefaultResourceDescriptionDelta)10 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)8 Resource (org.eclipse.emf.ecore.resource.Resource)8 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 IFile (org.eclipse.core.resources.IFile)5 IProject (org.eclipse.core.resources.IProject)5 IResourceDelta (org.eclipse.core.resources.IResourceDelta)5 WrappedException (org.eclipse.emf.common.util.WrappedException)4 IJavaProject (org.eclipse.jdt.core.IJavaProject)4 QualifiedName (org.eclipse.xtext.naming.QualifiedName)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 CoreException (org.eclipse.core.runtime.CoreException)3 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)3 LoadOperationException (org.eclipse.xtext.builder.resourceloader.IResourceLoader.LoadOperationException)3 IContainer (org.eclipse.xtext.resource.IContainer)3