Search in sources :

Example 1 with UpdateResult

use of org.eclipse.n4js.xtext.ide.server.build.XWorkspaceManager.UpdateResult in project n4js by eclipse.

the class XWorkspaceBuilder method doIncrementalWorkspaceUpdateAndBuild.

/**
 * Based on the raw, "reported changes" accumulated in {@link #newDirtyFiles} / {@link #newDeletedFiles}, do the
 * following:
 * <ol>
 * <li>perform an update of the workspace configuration, if necessary, which may lead to additional "discovered
 * changes" (e.g. resources in newly added source folders),
 * <li><em>move</em> the "reported changes" together with the "discovered changes" to {@link #dirtyFiles} /
 * {@link #deletedFiles} / {@link #affectedByDeletedProjects},
 * <li>then trigger an incremental build.
 * </ol>
 */
protected IResourceDescription.Event doIncrementalWorkspaceUpdateAndBuild(CancelIndicator cancelIndicator) {
    // in case many incremental build tasks pile up in the queue (e.g. while a non-cancelable initial build is
    // running), we don't want to repeatedly invoke IWorkspaceManager#update() in each of those tasks but only in
    // the last one; therefore, we here check for a cancellation:
    operationCanceledManager.checkCanceled(cancelIndicator);
    Set<URI> newDirtyFiles = new LinkedHashSet<>(this.newDirtyFiles);
    Set<URI> newDeletedFiles = new LinkedHashSet<>(this.newDeletedFiles);
    boolean newRefreshRequest = this.newRefreshRequest;
    this.newDirtyFiles.clear();
    this.newDeletedFiles.clear();
    this.newRefreshRequest = false;
    Stopwatch stopwatch = Stopwatch.createStarted();
    if (newRefreshRequest) {
        lspLogger.log("Refreshing ...");
    }
    UpdateResult updateResult = workspaceManager.update(newDirtyFiles, newDeletedFiles, newRefreshRequest);
    WorkspaceChanges changes = updateResult.changes;
    List<URI> actualDirtyFiles = UtilN4.concat(changes.getAddedURIs(), changes.getChangedURIs());
    List<URI> actualDeletedFiles = new ArrayList<>(changes.getRemovedURIs());
    if (newRefreshRequest) {
        // scan all source folders of all projects for source file additions, changes, and deletions
        // - including source files of added projects,
        // - including source files of added source folders of existing projects,
        // - including source files of removed source folders of existing projects,
        // - *not* including source files of removed projects.
        actualDirtyFiles = new ArrayList<>();
        actualDeletedFiles = new ArrayList<>();
        for (ProjectBuilder projectBuilder : workspaceManager.getProjectBuilders()) {
            ResourceChangeSet sourceFileChanges = projectBuilder.scanForSourceFileChanges();
            actualDirtyFiles.addAll(sourceFileChanges.getDirty());
            actualDeletedFiles.addAll(sourceFileChanges.getDeleted());
        }
    } else {
        // scan only the added source folders (including those of added projects) for source files
        actualDirtyFiles.addAll(scanAddedSourceFoldersForNewSourceFiles(changes, scanner));
        // collect URIs from removed source folders (*not* including those of removed projects)
        actualDeletedFiles.addAll(getURIsFromRemovedSourceFolders(changes));
    }
    queue(this.dirtyFiles, actualDeletedFiles, actualDirtyFiles);
    queue(this.deletedFiles, actualDirtyFiles, actualDeletedFiles);
    // take care of removed projects
    Set<ProjectConfigSnapshot> deletedProjects = new HashSet<>();
    for (ProjectConfigSnapshot prjConfig : changes.getRemovedProjects()) {
        deletedProjects.add(prjConfig);
    }
    for (ProjectConfigSnapshot prjConfig : Iterables.concat(changes.getAddedProjects(), changes.getChangedProjects())) {
        deletedProjects.remove(prjConfig);
    }
    for (ProjectConfigSnapshot delPrj : deletedProjects) {
        ImmutableSet<? extends ProjectConfigSnapshot> affected = updateResult.oldWorkspaceConfigSnapshot.getProjectsDependingOn(delPrj.getName());
        this.affectedByDeletedProjects.addAll(affected);
    }
    handleContentsOfRemovedProjects(updateResult.removedProjectsContents);
    if (newRefreshRequest) {
        lspLogger.log("... refresh done (" + stopwatch.toString() + "; " + "projects added/removed: " + changes.getAddedProjects().size() + "/" + changes.getRemovedProjects().size() + "; " + "files dirty/deleted: " + dirtyFiles.size() + "/" + deletedFiles.size() + ").");
    }
    for (String cyclicProject : updateResult.cyclicProjectChanges) {
        ProjectConfigSnapshot projectConfig = workspaceManager.getWorkspaceConfig().findProjectByID(cyclicProject);
        Collection<URI> projectDescriptionUris = projectConfig.getProjectDescriptionUris();
        dirtyFiles.addAll(projectDescriptionUris);
    }
    if (dirtyFiles.isEmpty() && deletedFiles.isEmpty() && affectedByDeletedProjects.isEmpty()) {
        return new ResourceDescriptionChangeEvent(Collections.emptyList());
    }
    return doIncrementalBuild(cancelIndicator);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Stopwatch(com.google.common.base.Stopwatch) ArrayList(java.util.ArrayList) ResourceChangeSet(org.eclipse.n4js.xtext.ide.server.ResourceChangeSet) URI(org.eclipse.emf.common.util.URI) ResourceDescriptionChangeEvent(org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent) WorkspaceChanges(org.eclipse.n4js.xtext.workspace.WorkspaceChanges) ProjectConfigSnapshot(org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot) UpdateResult(org.eclipse.n4js.xtext.ide.server.build.XWorkspaceManager.UpdateResult) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

Stopwatch (com.google.common.base.Stopwatch)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 URI (org.eclipse.emf.common.util.URI)1 ResourceChangeSet (org.eclipse.n4js.xtext.ide.server.ResourceChangeSet)1 UpdateResult (org.eclipse.n4js.xtext.ide.server.build.XWorkspaceManager.UpdateResult)1 ProjectConfigSnapshot (org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot)1 WorkspaceChanges (org.eclipse.n4js.xtext.workspace.WorkspaceChanges)1 ResourceDescriptionChangeEvent (org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent)1