org.eclipse.xtext.builder.resourceloader.IResourceLoader.LoadOperationException Java Examples

The following examples show how to use org.eclipse.xtext.builder.resourceloader.IResourceLoader.LoadOperationException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WriteNewResourceDescriptionsImplementation.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private void indexNextResource(LoadResult loadResult) {
	URI uri = null;
	Resource resource = null;
	try {
		uri = loadResult.getUri();
		progress.subTask("Indexing " + uri.lastSegment());
		buildLogger.log("Indexing " + uri);
		resource = state.addResource(loadResult.getResource(), resourceSet);

		registerDelta(uri, resource);
	} catch (final RuntimeException ex) {
		if (ex instanceof LoadOperationException) {
			uri = ((LoadOperationException) ex).getUri();
		}
		if (uri == null) {
			LOGGER.error("Error loading resource", ex); //$NON-NLS-1$
		} else {
			if (resourceSet.getURIConverter().exists(uri, Collections.emptyMap())) {
				LOGGER.error("Error loading resource from: " + uri.toString(), ex); //$NON-NLS-1$
			}
			if (resource != null) {
				resourceSet.getResources().remove(resource);
			}
			final IResourceDescription oldDescription = oldState.getResourceDescription(uri);
			if (oldDescription != null) {
				newState.register(new DefaultResourceDescriptionDelta(oldDescription, null));
			}
		}
	} finally {
		progress.worked(1);
	}
}
 
Example #2
Source File: DoUpdateImplementation.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
private int doUpdateCluster() {
	int clusterIndex = 0;

	final List<Delta> changedDeltas = Lists.newArrayList();
	while (!queue.isEmpty()) {
		checkCancelled();
		if (!continueProcessing(clusterIndex)) {
			break;
		}
		URI changedURI = null;
		Resource resource = null;
		Delta newDelta = null;

		try {
			// Load the resource and create a new resource description
			LoadResult loadResult = loadOperation.next();
			changedURI = loadResult.getUri();
			progress.subTask("Linking " + changedURI.lastSegment() + " and dependencies");
			URI actualResourceURI = loadResult.getResource().getURI();
			resource = state.addResource(loadResult.getResource(), resourceSet);
			reportProgress();

			if (!removeFromQueue(changedURI)) {
				break;
			}

			buildLogger.log("Linking " + changedURI);
			newDelta = resolveLinks(actualResourceURI, resource);
		} catch (final WrappedException ex) {
			if (ex instanceof LoadOperationException) {
				changedURI = ((LoadOperationException) ex).getUri();
			}
			Throwable cause = ex.getCause();
			boolean wasResourceNotFound = false;
			if (cause instanceof CoreException) {
				if (IResourceStatus.RESOURCE_NOT_FOUND == ((CoreException) cause).getStatus()
						.getCode()) {
					wasResourceNotFound = true;
				}
			}
			if (changedURI == null) {
				LOGGER.error("Error loading resource", ex); //$NON-NLS-1$
			} else {
				if (!removeFromQueue(changedURI)) {
					break;
				}
				if (!wasResourceNotFound)
					LOGGER.error("Error loading resource from: " + changedURI.toString(), ex); //$NON-NLS-1$
				if (resource != null) {
					resourceSet.getResources().remove(resource);
				}
				newDelta = createRemoveDelta(changedURI);
			}
		}

		if (newDelta != null) {
			clusterIndex++;
			if (processNewDelta(newDelta)) {
				changedDeltas.add(newDelta);
			}
		}
	}
	loadOperation.cancel();
	queueAffectedResources(changedDeltas);
	return clusterIndex;
}
 
Example #3
Source File: ClusteringBuilderState.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Create new resource descriptions for a set of resources given by their URIs.
 *
 * @param buildData
 *            The underlying data for the write operation.
 * @param oldState
 *            The old index
 * @param newState
 *            The new index
 * @param monitor
 *            The progress monitor used for user feedback
 */
protected void writeNewResourceDescriptions(
        BuildData buildData,
        IResourceDescriptions oldState,
        CurrentDescriptions newState,
        final IProgressMonitor monitor) {
    int index = 0;
    ResourceSet resourceSet = buildData.getResourceSet();
    Set<URI> toBeUpdated = buildData.getToBeUpdated();
    final SubMonitor subMonitor = SubMonitor.convert(monitor, "Write new resource descriptions", toBeUpdated.size() + 1); // TODO: NLS
    IProject currentProject = getBuiltProject(buildData);
    LoadOperation loadOperation = null;
    try {
    	compilerPhases.setIndexing(resourceSet, true);
        loadOperation = globalIndexResourceLoader.create(resourceSet, currentProject);
        loadOperation.load(toBeUpdated);

        while (loadOperation.hasNext()) {
            if (subMonitor.isCanceled()) {
                loadOperation.cancel();
                throw new OperationCanceledException();
            }

            if (!clusteringPolicy.continueProcessing(resourceSet, null, index)) {
                clearResourceSet(resourceSet);
            }

            URI uri = null;
            Resource resource = null;
            try {
                LoadResult loadResult = loadOperation.next();
                uri = loadResult.getUri();
                resource = addResource(loadResult.getResource(), resourceSet);
                subMonitor.subTask("Writing new resource description " + resource.getURI().lastSegment());
                if (LOGGER.isDebugEnabled()) {
                	LOGGER.debug("Writing new resource description " + uri);
                }

                final IResourceDescription.Manager manager = getResourceDescriptionManager(uri);
                if (manager != null) {
                    // We don't care here about links, we really just want the exported objects so that we can link in the
                    // next phase.
                    final IResourceDescription description = manager.getResourceDescription(resource);
                    final IResourceDescription copiedDescription = new CopiedResourceDescription(description);
                    // We also don't care what kind of Delta we get here; it's just a temporary transport vehicle. That interface
                    // could do with some clean-up, too, because all we actually want to do is register the new resource
                    // description, not the delta.
                    newState.register(new DefaultResourceDescriptionDelta(oldState.getResourceDescription(uri), copiedDescription));
                    buildData.queueURI(uri);
                }
            } catch (final RuntimeException ex) {
                if(ex instanceof LoadOperationException) {
                    uri = ((LoadOperationException) ex).getUri();
                }
                if (uri == null) {
                    LOGGER.error("Error loading resource", ex); //$NON-NLS-1$
                } else {
                    if (resourceSet.getURIConverter().exists(uri, Collections.emptyMap())) {
                        LOGGER.error("Error loading resource from: " + uri.toString(), ex); //$NON-NLS-1$
                    }
                    if (resource != null) {
                        resourceSet.getResources().remove(resource);
                    }
                    final IResourceDescription oldDescription = oldState.getResourceDescription(uri);
                    if (oldDescription != null) {
                        newState.register(new DefaultResourceDescriptionDelta(oldDescription, null));
                    }
                }
                // If we couldn't load it, there's no use trying again: do not add it to the queue
            }
            index++;
            subMonitor.split(1);
        }
    } finally {
    	compilerPhases.setIndexing(resourceSet, false);
        if(loadOperation != null) loadOperation.cancel();
    }
}