Search in sources :

Example 1 with WorkspaceConfigSnapshot

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;
}
Also used : WorkspaceConfigSnapshot(org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot) N4JSWorkspaceConfig(org.eclipse.n4js.workspace.N4JSWorkspaceConfig)

Example 2 with WorkspaceConfigSnapshot

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) WorkspaceConfigSnapshot(org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot) ProjectConfigSnapshot(org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot)

Example 3 with WorkspaceConfigSnapshot

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;
        });
    }
}
Also used : WorkspaceConfigSnapshot(org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) URI(org.eclipse.emf.common.util.URI)

Example 4 with WorkspaceConfigSnapshot

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;
}
Also used : ResourceDescriptionsData(org.eclipse.xtext.resource.impl.ResourceDescriptionsData) WorkspaceConfigSnapshot(org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot)

Example 5 with WorkspaceConfigSnapshot

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;
}
Also used : WorkspaceConfigSnapshot(org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot) ImmutableSet(com.google.common.collect.ImmutableSet)

Aggregations

WorkspaceConfigSnapshot (org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot)20 ProjectConfigSnapshot (org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot)10 URI (org.eclipse.emf.common.util.URI)7 ArrayList (java.util.ArrayList)5 BuildOrderIterator (org.eclipse.n4js.xtext.workspace.BuildOrderIterator)5 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)5 ImmutableSet (com.google.common.collect.ImmutableSet)4 LinkedHashSet (java.util.LinkedHashSet)4 Set (java.util.Set)4 Collections (java.util.Collections)3 HashSet (java.util.HashSet)3 List (java.util.List)3 FluentIterable (com.google.common.collect.FluentIterable)2 Iterables (com.google.common.collect.Iterables)2 Sets (com.google.common.collect.Sets)2 Path (java.nio.file.Path)2 Collection (java.util.Collection)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Delta (org.eclipse.xtext.resource.IResourceDescription.Delta)2