Search in sources :

Example 1 with BuildOrderIterator

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

the class XWorkspaceBuilder method doIncrementalBuild.

/**
 * Run the build on the workspace
 */
private IResourceDescription.Event doIncrementalBuild(CancelIndicator cancelIndicator) {
    lspLogger.log("Building ...");
    WorkspaceConfigSnapshot workspaceConfig = workspaceManager.getWorkspaceConfig();
    boolean hasDependencyCycle = workspaceConfig.hasDependencyCycle();
    try {
        Set<URI> dirtyFilesToBuild = new LinkedHashSet<>(this.dirtyFiles);
        Set<URI> deletedFilesToBuild = new LinkedHashSet<>(this.deletedFiles);
        Map<String, Set<URI>> project2dirty = computeProjectToUriMap(dirtyFilesToBuild);
        Map<String, Set<URI>> project2deleted = computeProjectToUriMap(deletedFilesToBuild);
        Set<String> changedProjects = Sets.union(project2dirty.keySet(), project2deleted.keySet());
        List<ProjectConfigSnapshot> changedPCs = changedProjects.stream().map(workspaceConfig::findProjectByID).collect(Collectors.toList());
        BuildOrderIterator pboIterator = buildOrderFactory.createBuildOrderIterator(workspaceConfig, changedPCs);
        pboIterator.visit(affectedByDeletedProjects);
        while (pboIterator.hasNext()) {
            ProjectConfigSnapshot projectConfig = pboIterator.next();
            String projectName = projectConfig.getName();
            ProjectBuilder projectBuilder = workspaceManager.getProjectBuilder(projectName);
            Set<URI> projectDirty = project2dirty.getOrDefault(projectName, Collections.emptySet());
            Set<URI> projectDeleted = project2deleted.getOrDefault(projectName, Collections.emptySet());
            XBuildResult projectResult;
            AffectedResourcesRecordingFactory recordingFactory = new AffectedResourcesRecordingFactory(buildRequestFactory);
            try {
                projectResult = projectBuilder.doIncrementalBuild(recordingFactory, projectDirty, projectDeleted, toBeConsideredDeltas, cancelIndicator);
            } catch (Throwable t) {
                // re-schedule the affected files since a subsequent build may not detect those as affected
                // anymore but we may have produced artifacts for these already
                this.dirtyFiles.addAll(recordingFactory.getAffectedResources());
                throw t;
            }
            List<Delta> newlyBuiltDeltas = projectResult.getAffectedResources();
            recordBuildProgress(newlyBuiltDeltas);
            pboIterator.visitAffected(newlyBuiltDeltas);
        }
        List<IResourceDescription.Delta> result = toBeConsideredDeltas;
        onBuildDone(false, false, hasDependencyCycle, Optional.absent());
        lspLogger.log("... build done.");
        return new ResourceDescriptionChangeEvent(result);
    } catch (Throwable th) {
        boolean wasCanceled = operationCanceledManager.isOperationCanceledException(th);
        onBuildDone(false, wasCanceled, hasDependencyCycle, Optional.of(th));
        if (wasCanceled) {
            lspLogger.log("... build canceled.");
            operationCanceledManager.propagateIfCancelException(th);
        }
        // unknown exception or error (and not a cancellation case):
        // QueueExecutorService will log this as an error with stack trace, so here we just use #log():
        lspLogger.log("... build ABORTED due to exception: " + th.getMessage());
        throw th;
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) WorkspaceConfigSnapshot(org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot) HashSet(java.util.HashSet) ResourceChangeSet(org.eclipse.n4js.xtext.ide.server.ResourceChangeSet) LinkedHashSet(java.util.LinkedHashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) URI(org.eclipse.emf.common.util.URI) ResourceDescriptionChangeEvent(org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent) ProjectConfigSnapshot(org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) DefaultResourceDescriptionDelta(org.eclipse.xtext.resource.impl.DefaultResourceDescriptionDelta) BuildOrderIterator(org.eclipse.n4js.xtext.workspace.BuildOrderIterator)

Example 2 with BuildOrderIterator

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

the class XWorkspaceBuilder method doInitialBuild.

/**
 * Run a full build on the entire workspace, i.e. build all projects.
 *
 * @return the delta.
 */
private IResourceDescription.Event doInitialBuild() {
    lspLogger.log("Initial build ...");
    Stopwatch stopwatch = Stopwatch.createStarted();
    WorkspaceConfigSnapshot workspaceConfig = workspaceManager.getWorkspaceConfig();
    boolean hasDependencyCycle = workspaceConfig.hasDependencyCycle();
    try {
        Collection<? extends ProjectConfigSnapshot> allProjects = workspaceManager.getProjectConfigs();
        BuildOrderIterator pboIterator = buildOrderFactory.createBuildOrderIterator(workspaceConfig, allProjects);
        logBuildOrder(workspaceConfig);
        List<IResourceDescription.Delta> allDeltas = new ArrayList<>();
        while (pboIterator.hasNext()) {
            ProjectConfigSnapshot projectConfig = pboIterator.next();
            String projectID = projectConfig.getName();
            ProjectBuilder projectBuilder = workspaceManager.getProjectBuilder(projectID);
            XBuildResult partialresult = projectBuilder.doInitialBuild(buildRequestFactory, allDeltas);
            allDeltas.addAll(partialresult.getAffectedResources());
        }
        onBuildDone(true, false, hasDependencyCycle, Optional.absent());
        stopwatch.stop();
        lspLogger.log("... initial build done (" + stopwatch.toString() + ").");
        return new ResourceDescriptionChangeEvent(allDeltas);
    } catch (Throwable th) {
        boolean wasCanceled = operationCanceledManager.isOperationCanceledException(th);
        onBuildDone(true, wasCanceled, hasDependencyCycle, Optional.of(th));
        if (wasCanceled) {
            lspLogger.log("... initial build canceled.");
            operationCanceledManager.propagateIfCancelException(th);
        }
        lspLogger.error("... initial build ABORTED due to exception:", th);
        throw th;
    }
}
Also used : WorkspaceConfigSnapshot(org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot) Stopwatch(com.google.common.base.Stopwatch) ArrayList(java.util.ArrayList) ResourceDescriptionChangeEvent(org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent) ProjectConfigSnapshot(org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) DefaultResourceDescriptionDelta(org.eclipse.xtext.resource.impl.DefaultResourceDescriptionDelta) BuildOrderIterator(org.eclipse.n4js.xtext.workspace.BuildOrderIterator)

Example 3 with BuildOrderIterator

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

the class XWorkspaceBuilder method logBuildOrder.

/**
 * Prints build order
 */
private void logBuildOrder(WorkspaceConfigSnapshot workspaceConfig) {
    if (LOG.isInfoEnabled()) {
        BuildOrderIterator visitAll = buildOrderFactory.createBuildOrderIterator(workspaceConfig).visitAll();
        String output = "Project build order:\n  " + IteratorExtensions.join(visitAll, "\n  ", ProjectConfigSnapshot::getName);
        LOG.info(output);
    }
}
Also used : BuildOrderIterator(org.eclipse.n4js.xtext.workspace.BuildOrderIterator)

Example 4 with BuildOrderIterator

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

the class AbstractIdeTest method assertProjectBuildOrder.

/**
 * Asserts the build order of all projects in the workspace.
 */
protected void assertProjectBuildOrder(String expectedProjectBuildOrder) {
    WorkspaceConfigSnapshot workspaceConfig = concurrentIndex.getWorkspaceConfigSnapshot();
    BuildOrderIterator iter = projectBuildOrderFactory.createBuildOrderIterator(workspaceConfig).visitAll();
    String buildOrderString = org.eclipse.n4js.utils.Strings.toString(pd -> pd.getName(), () -> iter);
    assertEquals("Project build order did not match expectation.", expectedProjectBuildOrder, buildOrderString);
}
Also used : WorkspaceConfigSnapshot(org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot) BuildOrderIterator(org.eclipse.n4js.xtext.workspace.BuildOrderIterator)

Example 5 with BuildOrderIterator

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

the class AbstractBuildOrderTest method assertBuildOrder.

final void assertBuildOrder(String buildOrder, Collection<Collection<String>> cycles) {
    WorkspaceConfigSnapshot workspaceConfig = concurrentIndex.getWorkspaceConfigSnapshot();
    BuildOrderInfo projectBuildOrderInfo = projectBuildOrderFactory.createBuildOrderInfo(workspaceConfig);
    BuildOrderIterator boIterator = projectBuildOrderFactory.createBuildOrderIterator(workspaceConfig).visitAll();
    try {
        String names = IteratorExtensions.join(boIterator, ", ", it -> it.getName());
        assertEquals(buildOrder, names);
    } catch (Exception exc) {
        throw new RuntimeException("Never happens since toString never throws an exception. Bogus xtext warning", exc);
    }
    assertEquals(cycles.size(), projectBuildOrderInfo.getProjectCycles().size());
    Set<String> expectedCycles = cycles.stream().map(it -> Strings.join(", ", it)).collect(Collectors.toSet());
    for (List<String> cycle : projectBuildOrderInfo.getProjectCycles()) {
        String detectedCycle = Strings.join(", ", cycle);
        assertTrue("Cycle " + detectedCycle + " not found in " + expectedCycles, expectedCycles.contains(detectedCycle));
    }
}
Also used : BuildOrderInfo(org.eclipse.n4js.xtext.workspace.BuildOrderInfo) Collection(java.util.Collection) BuildOrderIterator(org.eclipse.n4js.xtext.workspace.BuildOrderIterator) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) AbstractIdeTest(org.eclipse.n4js.ide.tests.helper.server.AbstractIdeTest) Collectors(java.util.stream.Collectors) WorkspaceConfigSnapshot(org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot) IteratorExtensions(org.eclipse.xtext.xbase.lib.IteratorExtensions) Strings(org.eclipse.n4js.utils.Strings) List(java.util.List) BuildOrderInfo(org.eclipse.n4js.xtext.workspace.BuildOrderInfo) Pair(org.eclipse.xtext.xbase.lib.Pair) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) WorkspaceConfigSnapshot(org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot) BuildOrderIterator(org.eclipse.n4js.xtext.workspace.BuildOrderIterator)

Aggregations

BuildOrderIterator (org.eclipse.n4js.xtext.workspace.BuildOrderIterator)5 WorkspaceConfigSnapshot (org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot)4 Set (java.util.Set)2 ProjectConfigSnapshot (org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot)2 Delta (org.eclipse.xtext.resource.IResourceDescription.Delta)2 DefaultResourceDescriptionDelta (org.eclipse.xtext.resource.impl.DefaultResourceDescriptionDelta)2 ResourceDescriptionChangeEvent (org.eclipse.xtext.resource.impl.ResourceDescriptionChangeEvent)2 Stopwatch (com.google.common.base.Stopwatch)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 URI (org.eclipse.emf.common.util.URI)1 AbstractIdeTest (org.eclipse.n4js.ide.tests.helper.server.AbstractIdeTest)1 Strings (org.eclipse.n4js.utils.Strings)1 ResourceChangeSet (org.eclipse.n4js.xtext.ide.server.ResourceChangeSet)1