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;
}
}
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;
}
}
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);
}
}
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);
}
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));
}
}
Aggregations