Search in sources :

Example 16 with ProjectConfigSnapshot

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

the class XWorkspaceManager method applyWorkspaceChanges.

/**
 * Apply the given workspace changes to this manager's internal state and notify the workspace index.
 */
protected UpdateResult applyWorkspaceChanges(WorkspaceChanges changes) {
    // collects contents of removed projects before actually removing anything
    List<IResourceDescription> removedProjectsContents = collectAllResourceDescriptions(changes.getRemovedProjects());
    removeProjects(changes.getRemovedProjects());
    updateProjects(changes.getChangedProjects());
    addProjects(changes.getAddedProjects());
    WorkspaceConfigSnapshot oldWCS = workspaceConfigSnapshot;
    Collection<ImmutableList<String>> oldCycles = oldWCS.getBuildOrderInfo().getProjectCycles();
    workspaceConfigSnapshot = workspaceIndex.changeOrRemoveProjects(Iterables.concat(changes.getAddedProjects(), changes.getChangedProjects()), Iterables.transform(changes.getRemovedProjects(), ProjectConfigSnapshot::getName));
    Collection<ImmutableList<String>> newCycles = workspaceConfigSnapshot.getBuildOrderInfo().getProjectCycles();
    Set<String> cyclicProjectChanges = new HashSet<>();
    for (List<String> cycle : Iterables.concat(oldCycles, newCycles)) {
        for (String projectName : cycle) {
            cyclicProjectChanges.add(projectName);
        }
    }
    return new UpdateResult(oldWCS, changes, removedProjectsContents, cyclicProjectChanges);
}
Also used : WorkspaceConfigSnapshot(org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot) ProjectConfigSnapshot(org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) ImmutableList(com.google.common.collect.ImmutableList) HashSet(java.util.HashSet)

Example 17 with ProjectConfigSnapshot

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

the class XWorkspaceManager method addProjects.

/**
 * Adds a project to the workspace
 */
protected void addProjects(Iterable<? extends ProjectConfigSnapshot> projectConfigs) {
    for (ProjectConfigSnapshot projectConfig : withoutDuplicates(projectConfigs)) {
        ProjectBuilder projectBuilder = projectBuilderProvider.get();
        projectBuilder.initialize(projectConfig);
        projectID2ProjectBuilder.put(projectConfig.getName(), projectBuilder);
    }
}
Also used : ProjectConfigSnapshot(org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot)

Example 18 with ProjectConfigSnapshot

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

the class XWorkspaceManager method getProjectBuilder.

/**
 * @param nestedURI
 *            the contained uri
 * @return the project builder.
 */
public ProjectBuilder getProjectBuilder(URI nestedURI) {
    ProjectConfigSnapshot projectConfig = getProjectConfig(nestedURI);
    String projectID = null;
    if (projectConfig != null) {
        projectID = projectConfig.getName();
    }
    return getProjectBuilder(projectID);
}
Also used : ProjectConfigSnapshot(org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot)

Example 19 with ProjectConfigSnapshot

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

the class XStatefulIncrementalBuilder method isResourceInOutputDirectory.

private boolean isResourceInOutputDirectory(Resource resource, IResourceServiceProvider serviceProvider) {
    XWorkspaceManager workspaceManager = serviceProvider.get(XWorkspaceManager.class);
    if (workspaceManager == null) {
        return false;
    }
    OutputConfigurationProvider outputConfProvider = serviceProvider.get(OutputConfigurationProvider.class);
    URI resourceUri = resource.getURI();
    ProjectConfigSnapshot projectConfig = workspaceManager.getProjectConfig(resourceUri);
    Set<OutputConfiguration> outputConfigurations = outputConfProvider.getOutputConfigurations(resource);
    URI projectBaseUri = projectConfig.getPath();
    Path resourcePath = URIUtils.toPath(resourceUri);
    for (OutputConfiguration outputConf : outputConfigurations) {
        for (String outputDir : outputConf.getOutputDirectories()) {
            URI outputUri = projectBaseUri.appendSegment(outputDir);
            Path outputPath = URIUtils.toPath(outputUri);
            if (resourcePath.startsWith(outputPath)) {
                return true;
            }
        }
    }
    return false;
}
Also used : Path(java.nio.file.Path) ProjectConfigSnapshot(org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot) OutputConfiguration(org.eclipse.xtext.generator.OutputConfiguration) OutputConfigurationProvider(org.eclipse.xtext.generator.OutputConfigurationProvider) URI(org.eclipse.emf.common.util.URI)

Example 20 with ProjectConfigSnapshot

use of org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot 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)

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