Search in sources :

Example 11 with ProjectConfigSnapshot

use of org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot in project n4js by eclipse.

the class N4JSWorkspaceConfig method didDependenciesChange.

/**
 * Tells whether the dependencies of the given project changed w.r.t. the given old workspace config.
 */
private static boolean didDependenciesChange(ProjectConfigSnapshot projectConfig, WorkspaceConfigSnapshot oldWorkspaceConfig) {
    ProjectConfigSnapshot oldProjectConfig = oldWorkspaceConfig.findProjectByID(projectConfig.getName());
    N4JSProjectConfigSnapshot newCasted = (N4JSProjectConfigSnapshot) projectConfig;
    N4JSProjectConfigSnapshot oldCasted = (N4JSProjectConfigSnapshot) oldProjectConfig;
    return oldProjectConfig == null || !Objects.equals(oldCasted.getPackageName(), newCasted.getPackageName()) || !Objects.equals(((N4JSProjectConfigSnapshot) projectConfig).getDependencies(), ((N4JSProjectConfigSnapshot) oldProjectConfig).getDependencies());
}
Also used : ProjectConfigSnapshot(org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot)

Example 12 with ProjectConfigSnapshot

use of org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot in project n4js by eclipse.

the class N4JSWorkspaceConfig method detectAddedRemovedProjects.

private WorkspaceChanges detectAddedRemovedProjects(WorkspaceConfigSnapshot oldWorkspaceConfig, boolean alsoDetectChangedProjects) {
    // update all projects
    reloadAllProjectInformationFromDisk();
    // detect project additions, removals (and also changes, iff 'alsoDetectChangedProjects' is set)
    Map<URI, ProjectConfigSnapshot> oldProjectsMap = IterableExtensions.toMap(oldWorkspaceConfig.getProjects(), ProjectConfigSnapshot::getPath);
    Map<URI, N4JSProjectConfig> newProjectsMap = IterableExtensions.toMap(getProjects(), XIProjectConfig::getPath);
    WorkspaceChanges changes = new WorkspaceChanges();
    for (URI uri : Sets.union(oldProjectsMap.keySet(), newProjectsMap.keySet())) {
        boolean isOld = oldProjectsMap.containsKey(uri);
        boolean isNew = newProjectsMap.containsKey(uri);
        if (isOld && !isNew) {
            // deleted
            changes = changes.merge(WorkspaceChanges.createProjectRemoved(oldProjectsMap.get(uri)));
        } else if (!isOld && isNew) {
            // added
            ProjectConfigSnapshot newPC = configSnapshotFactory.createProjectConfigSnapshot(newProjectsMap.get(uri));
            changes = changes.merge(WorkspaceChanges.createProjectAdded(newPC));
        } else if (isOld && isNew) {
            // check name change
            String oldPackageName = ((N4JSProjectConfigSnapshot) oldProjectsMap.get(uri)).getPackageName();
            String newPackageName = newProjectsMap.get(uri).getPackageName();
            if (Objects.equals(oldPackageName, newPackageName)) {
                // no change
                if (alsoDetectChangedProjects) {
                    ProjectConfigSnapshot oldPC = oldProjectsMap.get(uri);
                    ProjectConfigSnapshot newPC = configSnapshotFactory.createProjectConfigSnapshot(newProjectsMap.get(uri));
                    changes = changes.merge(N4JSProjectConfig.computeChanges(oldPC, newPC));
                }
            } else {
                // names changed
                ProjectConfigSnapshot newPC = configSnapshotFactory.createProjectConfigSnapshot(newProjectsMap.get(uri));
                changes = changes.merge(WorkspaceChanges.createProjectAdded(newPC));
                changes = changes.merge(WorkspaceChanges.createProjectRemoved(oldProjectsMap.get(uri)));
            }
        }
    }
    return changes;
}
Also used : ProjectConfigSnapshot(org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot) WorkspaceChanges(org.eclipse.n4js.xtext.workspace.WorkspaceChanges) XIProjectConfig(org.eclipse.n4js.xtext.workspace.XIProjectConfig) URI(org.eclipse.emf.common.util.URI) FileURI(org.eclipse.n4js.workspace.locations.FileURI)

Example 13 with ProjectConfigSnapshot

use of org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot in project n4js by eclipse.

the class N4JSWorkspaceConfig method doMinimalUpdate.

/**
 * Based on the given dirty/deleted files, performs a workspace update with as few computations as possible.
 */
private WorkspaceChanges doMinimalUpdate(WorkspaceConfigSnapshot oldWorkspaceConfig, Set<URI> dirtyFiles, Set<URI> deletedFiles) {
    WorkspaceChanges changes = WorkspaceChanges.createUrisRemovedAndChanged(deletedFiles, dirtyFiles);
    boolean needToDetectAddedRemovedProjects = false;
    for (URI changedResource : Iterables.concat(dirtyFiles, deletedFiles)) {
        String lastSegment = changedResource.lastSegment();
        boolean isPackageJson = lastSegment != null && lastSegment.equals(N4JSGlobals.PACKAGE_JSON);
        if (!isPackageJson) {
            continue;
        }
        ProjectConfigSnapshot oldProject = oldWorkspaceConfig.findProjectContaining(changedResource);
        XIProjectConfig project = oldProject != null ? findProjectByName(oldProject.getName()) : null;
        if (oldProject != null && project != null) {
            // an existing project was modified (maybe removed)
            changes = changes.merge(((N4JSProjectConfig) project).update(oldWorkspaceConfig, changedResource, configSnapshotFactory));
            if (((N4JSProjectConfig) project).isWorkspaceProject()) {
                needToDetectAddedRemovedProjects = true;
            }
        } else {
            // a new project was created
            needToDetectAddedRemovedProjects = true;
        }
    }
    needToDetectAddedRemovedProjects |= isProjectDiscoveryRequired(changes, oldWorkspaceConfig);
    if (needToDetectAddedRemovedProjects) {
        changes = changes.merge(detectAddedRemovedProjects(oldWorkspaceConfig, false));
    }
    return changes;
}
Also used : WorkspaceChanges(org.eclipse.n4js.xtext.workspace.WorkspaceChanges) ProjectConfigSnapshot(org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot) XIProjectConfig(org.eclipse.n4js.xtext.workspace.XIProjectConfig) URI(org.eclipse.emf.common.util.URI) FileURI(org.eclipse.n4js.workspace.locations.FileURI)

Example 14 with ProjectConfigSnapshot

use of org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot in project n4js by eclipse.

the class ProjectSetTest method testRemoveAndRecreate.

/**
 * Tests the special cases described in {@link ProjectSet#update(Iterable, Iterable)}.
 */
@Test
public void testRemoveAndRecreate() {
    String projectName = "TestProject";
    URI rootA = URI.createFileURI("///some/folder");
    URI rootB = URI.createFileURI("///another/folder");
    N4JSProjectConfigSnapshot projectBelowRootA = createProjectConfig(rootA.appendSegment(projectName));
    N4JSProjectConfigSnapshot projectBelowRootB = createProjectConfig(rootB.appendSegment(projectName));
    ProjectSet set1 = new ProjectSet(Collections.singleton(projectBelowRootA));
    ProjectSet set2 = set1.update(Collections.singleton(projectBelowRootB), Collections.singleton(projectName));
    assertEquals(1, set2.size());
    ProjectConfigSnapshot projectInSet2 = IterableExtensions.head(set2.getProjects());
    assertEquals(rootB.appendSegment(projectName), projectInSet2.getPath());
    assertEquals(projectBelowRootB, projectInSet2);
}
Also used : N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) ProjectConfigSnapshot(org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot) N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) URI(org.eclipse.emf.common.util.URI) ProjectSet(org.eclipse.n4js.xtext.workspace.ProjectSet) Test(org.junit.Test)

Example 15 with ProjectConfigSnapshot

use of org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot in project n4js by eclipse.

the class ResourceTaskContext method updateIndex.

/**
 * Update this context's internal index and trigger a refresh if required.
 */
protected void updateIndex(Collection<? extends IResourceDescription> changedDescs, Set<URI> removedURIs, WorkspaceConfigSnapshot newWorkspaceConfig, CancelIndicator cancelIndicator) {
    WorkspaceConfigSnapshot oldWorkspaceConfig = workspaceConfig;
    // update my cached state
    List<IResourceDescription.Delta> allDeltas = createDeltas(changedDescs, removedURIs);
    for (IResourceDescription.Delta delta : allDeltas) {
        URI deltaURI = delta.getUri();
        WorkspaceConfigSnapshot wcs = delta.getNew() != null ? newWorkspaceConfig : oldWorkspaceConfig;
        ProjectConfigSnapshot project = wcs != null ? wcs.findProjectContaining(deltaURI) : null;
        if (project != null) {
            indexSnapshot.register(project.getName(), delta);
        }
    }
    workspaceConfig = newWorkspaceConfig;
    boolean workspaceConfigChanged = workspaceConfig != null ? !workspaceConfig.equals(oldWorkspaceConfig) : oldWorkspaceConfig != null;
    if (workspaceConfigChanged) {
        WorkspaceConfigAdapter.installWorkspaceConfig(mainResourceSet, workspaceConfig);
    }
    // refresh if I am affected by the changes
    boolean isAffected = workspaceConfigChanged;
    if (!isAffected) {
        IResourceDescription.Manager rdm = getResourceDescriptionManager(mainURI);
        IResourceDescription candidateDesc = indexSnapshot.getResourceDescription(mainURI);
        if (rdm != null && candidateDesc != null) {
            isAffected = isAffected(candidateDesc, rdm, allDeltas);
        }
    }
    if (isAffected) {
        refreshContext(cancelIndicator);
    }
}
Also used : WorkspaceConfigSnapshot(org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot) ProjectConfigSnapshot(org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) URI(org.eclipse.emf.common.util.URI)

Aggregations

ProjectConfigSnapshot (org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot)25 URI (org.eclipse.emf.common.util.URI)9 WorkspaceConfigSnapshot (org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot)9 Stopwatch (com.google.common.base.Stopwatch)4 Path (java.nio.file.Path)4 ArrayList (java.util.ArrayList)4 LinkedHashSet (java.util.LinkedHashSet)4 FileURI (org.eclipse.n4js.workspace.locations.FileURI)4 WorkspaceChanges (org.eclipse.n4js.xtext.workspace.WorkspaceChanges)4 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)4 HashSet (java.util.HashSet)3 Set (java.util.Set)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Injector (com.google.inject.Injector)2 File (java.io.File)2 Collections (java.util.Collections)2 TreeMap (java.util.TreeMap)2 N4JSProjectConfigSnapshot (org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot)2 ResourceChangeSet (org.eclipse.n4js.xtext.ide.server.ResourceChangeSet)2 XIProjectConfig (org.eclipse.n4js.xtext.workspace.XIProjectConfig)2