use of org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot in project n4js by eclipse.
the class N4JSWorkspaceConfigFactory method createWorkspaceConfig.
@Override
public XIWorkspaceConfig createWorkspaceConfig(URI workspaceBaseURI) {
N4JSWorkspaceConfig result = doCreateWorkspaceConfig(workspaceBaseURI);
WorkspaceConfigSnapshot emptyWC = configSnapshotFactory.createWorkspaceConfigSnapshot(workspaceBaseURI);
result.update(emptyWC, Collections.emptySet(), Collections.emptySet(), true);
return result;
}
use of org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot in project n4js by eclipse.
the class N4JSClusteringStorageAwareResourceLoader method sort.
/**
* The given list of load results is sorted by this method to improve the post processing of N4JS started by the
* {@link N4JSPostProcessor}. During post processing, other dependency resources will be processed too in a
* recursive fashion. However, by sorting load results beforehand here, that will not be necessary since
* dependencies already have been processed. Note however that in case of dependency cycles, sorting cannot avoid
* the recursive post processing of dependencies.
*/
@Override
protected List<LoadResult> sort(XBuildContext context, List<LoadResult> results) {
if (results.isEmpty()) {
return results;
}
WorkspaceConfigSnapshot wcs = WorkspaceConfigAdapter.getWorkspaceConfig(context.getResourceSet());
ProjectConfigSnapshot pcs = wcs.findProjectContaining(results.get(0).uri);
if (pcs == null) {
return results;
}
Set<LoadResult> noDeps = new LinkedHashSet<>();
Multimap<LoadResult, LoadResult> dependsOn = HashMultimap.create();
Multimap<LoadResult, LoadResult> dependsOnInverse = HashMultimap.create();
initDependencyMaps(results, pcs, noDeps, dependsOn, dependsOnInverse);
List<LoadResult> sortedResults = sortLoadResults(results, noDeps, dependsOn, dependsOnInverse);
return sortedResults;
}
use of org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot in project n4js by eclipse.
the class ResourceTaskManager method updateSharedDirtyState.
/**
* Updates this manager and all its {@link ResourceTaskContext}s with the given changes to the persisted state
* index. Should only be invoked internally from {@link ResourceTaskContext} after
* {@link ResourceTaskContext#refreshContext(int, Iterable, CancelIndicator) refreshing} its internal state.
*
* @param uri
* uri of the resource that has changed or was deleted.
* @param newDesc
* the new resource description or <code>null</code> if the resource was deleted.
*/
protected synchronized void updateSharedDirtyState(URI uri, IResourceDescription newDesc) {
// update my dirty state instance
if (newDesc != null) {
dirtyIndex.addDescription(uri, newDesc);
} else {
dirtyIndex.removeDescription(uri);
}
// update dirty state instance in each resource task context (except the one that caused the change)
WorkspaceConfigSnapshot capturedWorkspaceConfig = workspaceConfig;
IResourceDescription replacementDesc = newDesc == null ? getPersistedIndexDescription(uri) : null;
for (Entry<URI, ResourceTaskContext> currEntry : uri2RTCsOnQueue.entrySet()) {
URI currURI = currEntry.getKey();
ResourceTaskContext currRTC = currEntry.getValue();
if (currURI.equals(uri)) {
continue;
}
doSubmitTask(currRTC, "updateSharedDirtyState of existing context", (rtc, ci) -> {
if (newDesc != null) {
// happens in case a resource context has changed
rtc.onDirtyStateChanged(newDesc, ci);
} else {
// happens in case a resource context was disposed
if (replacementDesc != null) {
rtc.onPersistedStateChanged(Collections.singleton(replacementDesc), Collections.emptySet(), capturedWorkspaceConfig, ci);
} else {
rtc.onPersistedStateChanged(Collections.emptyList(), Collections.singleton(uri), capturedWorkspaceConfig, ci);
}
}
return null;
});
}
}
use of org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot in project n4js by eclipse.
the class ConcurrentIndex method setProjectIndex.
/**
* Sets the index for the given project name.
*/
public ResourceDescriptionsData setProjectIndex(String projectID, ResourceDescriptionsData projectIndex) {
Objects.requireNonNull(projectID);
Objects.requireNonNull(projectIndex);
ResourceDescriptionsData oldProjectIndex;
WorkspaceConfigSnapshot currWorkspaceConfig;
synchronized (this) {
oldProjectIndex = projectID2Index.put(projectID, projectIndex);
currWorkspaceConfig = workspaceConfig;
}
if ((oldProjectIndex != null && !oldProjectIndex.isEmpty()) || !projectIndex.isEmpty()) {
// check avoids many notifications during initialization
notifyListeners(currWorkspaceConfig, ImmutableMap.of(projectID, projectIndex), ImmutableList.of(), ImmutableSet.of());
}
return oldProjectIndex;
}
use of org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot in project n4js by eclipse.
the class ConcurrentIndex method changeOrRemoveProjects.
/**
* Add or remove projects, or change the configuration of existing projects.
* <p>
* For important notes on the meaning of the two parameters, see method
* {@link ProjectSet#update(Iterable, Iterable)}.
*/
public WorkspaceConfigSnapshot changeOrRemoveProjects(Iterable<? extends ProjectConfigSnapshot> changedProjects, Iterable<String> removedProjectIDs) {
Objects.requireNonNull(changedProjects);
Objects.requireNonNull(removedProjectIDs);
ImmutableList<? extends ProjectConfigSnapshot> changedProjectsCpy = ImmutableList.copyOf(changedProjects);
ImmutableSet<String> removedProjectIDsCpy = ImmutableSet.copyOf(removedProjectIDs);
WorkspaceConfigSnapshot newWorkspaceConfig;
ImmutableSet.Builder<String> actuallyRemovedProjectsBuilder = ImmutableSet.builder();
synchronized (this) {
for (String removedProjectID : removedProjectIDsCpy) {
if (projectID2Index.remove(removedProjectID) != null) {
actuallyRemovedProjectsBuilder.add(removedProjectID);
}
}
newWorkspaceConfig = configSnapshotFactory.update(workspaceConfig, changedProjectsCpy, removedProjectIDsCpy);
workspaceConfig = newWorkspaceConfig;
}
ImmutableSet<String> actuallyRemovedProjects = actuallyRemovedProjectsBuilder.build();
if (!changedProjectsCpy.isEmpty() || !actuallyRemovedProjects.isEmpty()) {
notifyListeners(newWorkspaceConfig, ImmutableMap.of(), changedProjectsCpy, actuallyRemovedProjects);
}
return newWorkspaceConfig;
}
Aggregations