Java Code Examples for org.eclipse.xtext.builder.impl.BuildData#getResourceSet()

The following examples show how to use org.eclipse.xtext.builder.impl.BuildData#getResourceSet() . 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: N4ClusteringBuilderState.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
protected void installSourceLevelURIs(BuildData buildData) {
	ResourceSet resourceSet = buildData.getResourceSet();
	Iterable<URI> sourceLevelUris = Iterables.concat(buildData.getToBeUpdated(), buildData.getURIQueue());
	Set<URI> sourceUris = newHashSet();
	for (URI uri : sourceLevelUris) {
		if (buildData.getSourceLevelURICache().getOrComputeIsSource(uri, resourceServiceProviderRegistry)) {
			sourceUris.add(uri);
			// unload resources loaded from storage previously
			Resource resource = resourceSet.getResource(uri, false);
			if (resource instanceof StorageAwareResource) {
				if (((StorageAwareResource) resource).isLoadedFromStorage()) {
					resource.unload();
				}
			}
		}
	}
	SourceLevelURIsAdapter.setSourceLevelUris(resourceSet, sourceUris);
}
 
Example 2
Source File: DoUpdateImplementation.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
public DoUpdateImplementation(N4ClusteringBuilderState state, BuildData buildData,
		ResourceDescriptionsData newData, IProgressMonitor monitor, IBuildLogger buildLogger,
		IResourceLoader crossLinkingResourceLoader, IResourceClusteringPolicy clusteringPolicy) {
	this.clusteringPolicy = clusteringPolicy;
	this.crossLinkingResourceLoader = crossLinkingResourceLoader;
	this.buildLogger = buildLogger;
	this.state = state;
	this.buildData = buildData;
	this.newData = newData;
	this.progress = SubMonitor.convert(monitor);
	this.cancelMonitor = new MonitorBasedCancelIndicator(progress);
	this.toBeDeleted = buildData.getAndRemoveToBeDeleted();
	this.resourceSet = buildData.getResourceSet();
	this.newState = new CurrentDescriptions(resourceSet, newData, buildData);
	this.currentProject = state.getBuiltProject(buildData);
	this.queue = buildData.getURIQueue();
}
 
Example 3
Source File: WriteNewResourceDescriptionsImplementation.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
public WriteNewResourceDescriptionsImplementation(N4ClusteringBuilderState state, BuildData buildData,
		IResourceDescriptions oldState,
		CurrentDescriptions newState, IProgressMonitor monitor,
		IBuildLogger buildLogger,
		IResourceLoader globalIndexResourceLoader,
		IResourceClusteringPolicy clusteringPolicy, CompilerPhases compilerPhases) {
	this.compilerPhases = compilerPhases;
	this.clusteringPolicy = clusteringPolicy;
	this.globalIndexResourceLoader = globalIndexResourceLoader;
	this.state = state;
	this.buildData = buildData;
	this.oldState = oldState;
	this.newState = newState;
	this.progress = SubMonitor.convert(monitor, buildData.getToBeUpdated().size());
	this.buildLogger = buildLogger;
	this.resourceSet = buildData.getResourceSet();
	this.currentProject = state.getBuiltProject(buildData);
}
 
Example 4
Source File: ClusteringBuilderState.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void installSourceLevelURIs(BuildData buildData) {
	ResourceSet resourceSet = buildData.getResourceSet();
	Iterable<URI> sourceLevelUris = Iterables.concat(buildData.getToBeUpdated(), buildData.getURIQueue());
	Set<URI> sourceUris = newHashSet();
	for (URI uri : sourceLevelUris) {
		if (buildData.getSourceLevelURICache().getOrComputeIsSource(uri, resourceServiceProviderRegistry)) {
			sourceUris.add(uri);
			// unload resources loaded from storage previously
			Resource resource = resourceSet.getResource(uri, false);
			if (resource instanceof StorageAwareResource) {
				if (((StorageAwareResource) resource).isLoadedFromStorage()) {
					resource.unload();
				}
			}
		}
	}
	SourceLevelURIsAdapter.setSourceLevelUris(resourceSet, sourceUris);
}
 
Example 5
Source File: MonitoredClusteringBuilderState.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Override which installs an {@link DirectLinkingSourceLevelURIsAdapter} instead of Xtext's
 * {@link org.eclipse.xtext.resource.persistence.SourceLevelURIsAdapter} so that the builder can modify
 * {@link org.eclipse.xtext.builder.impl.SourceLevelURICache#getSources()} and get these changes reflected in the adapter.
 */
@Override
protected void installSourceLevelURIs(final BuildData buildData) {
  ResourceSet resourceSet = buildData.getResourceSet();
  Iterable<URI> sourceLevelUris = Iterables.concat(buildData.getToBeUpdated(), buildData.getURIQueue());
  for (URI uri : sourceLevelUris) {
    if (buildData.getSourceLevelURICache().getOrComputeIsSource(uri, resourceServiceProviderRegistry)) {
      // unload resources loaded from storage previously
      Resource resource = resourceSet.getResource(uri, false);
      if (resource instanceof StorageAwareResource && ((StorageAwareResource) resource).isLoadedFromStorage()) {
        resource.unload();
      }
    }
  }
  DirectLinkingSourceLevelURIsAdapter.setSourceLevelUris(resourceSet, buildData.getSourceLevelURICache().getSources());
}
 
Example 6
Source File: MonitoredClusteringBuilderState.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/** {@inheritDoc} */
protected void writeNewResourceDescriptions(final BuildData buildData, final IResourceDescriptions oldState, final CurrentDescriptions newState, final ResourceDescriptionsData newData, final IProgressMonitor monitor) {
  final List<List<URI>> toWriteGroups = phaseOneBuildSorter.sort(buildData.getToBeUpdated());
  final List<URI> toBuild = Lists.newLinkedList();
  ResourceSet resourceSet = buildData.getResourceSet();
  BuildPhases.setIndexing(resourceSet, true);
  int totalSize = 0;
  for (List<URI> group : toWriteGroups) {
    totalSize = totalSize + group.size();
  }
  final SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.MonitoredClusteringBuilderState_WRITE_DESCRIPTIONS, totalSize);

  try {
    traceSet.started(BuildIndexingEvent.class);
    /*
     * We handle one group at a time to enforce strict ordering between some specific source types.
     * I.e. We start processing a source type (or a set of them) only after all occurrences of another source on which the depend has been written into the
     * index.
     * One list sorted by source type would not be enough to enforce such ordering in a parallel loading scenario.
     * In fact, in this case we might start processing sources before the ones they depend on are still being handled.
     */
    for (Collection<URI> fileExtensionBuildGroup : toWriteGroups) {
      toBuild.addAll(writeResources(fileExtensionBuildGroup, buildData, oldState, newState, subMonitor));
    }
    flushChanges(newData);
  } finally {
    // Clear the flags
    BuildPhases.setIndexing(resourceSet, false);
    resourceSet.getLoadOptions().remove(ILazyLinkingResource2.MARK_UNRESOLVABLE_XREFS);
    phaseTwoBuildSorter.sort(toBuild).stream().flatMap(List::stream).forEach(buildData::queueURI);
    traceSet.ended(BuildIndexingEvent.class);
  }

}
 
Example 7
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();
    }
}