Search in sources :

Example 21 with ProjectConfigSnapshot

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

the class WorkspaceConfigAllContainerState method getVisibleContainerHandles.

@Override
public List<String> getVisibleContainerHandles(String containerHandle) {
    WorkspaceConfigSnapshot ws = getWorkspaceConfig();
    ProjectConfigSnapshot project = ws != null ? ws.findProjectByID(containerHandle) : null;
    if (project == null) {
        return Collections.singletonList(containerHandle);
    }
    Set<String> visible = project.getDependencies();
    Set<String> visibleAndSelf = new LinkedHashSet<>();
    visibleAndSelf.add(containerHandle);
    visibleAndSelf.addAll(visible);
    return ImmutableList.copyOf(visibleAndSelf);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) WorkspaceConfigSnapshot(org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot) ProjectConfigSnapshot(org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot)

Example 22 with ProjectConfigSnapshot

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

the class N4JSWorkspaceConfig method affectedByPropertyChanges.

/**
 * Tells whether the property {@link PackageJsonProperties#DEFINES_PACKAGE "definesPackage"} changed.
 */
private static boolean affectedByPropertyChanges(ProjectConfigSnapshot newProjectConfig, WorkspaceConfigSnapshot oldWorkspaceConfig) {
    ProjectConfigSnapshot oldProjectConfig = oldWorkspaceConfig.findProjectByID(newProjectConfig.getName());
    if (oldProjectConfig == null) {
        return true;
    }
    N4JSProjectConfigSnapshot oldCasted = (N4JSProjectConfigSnapshot) oldProjectConfig;
    N4JSProjectConfigSnapshot newCasted = (N4JSProjectConfigSnapshot) newProjectConfig;
    if (didDefinitionPropertiesChange(oldCasted, newCasted)) {
        return true;
    }
    if (!Objects.equals(oldCasted.getPackageName(), newCasted.getPackageName())) {
        return true;
    }
    return false;
}
Also used : ProjectConfigSnapshot(org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot)

Example 23 with ProjectConfigSnapshot

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

the class N4JSWorkspaceConfig method recomputeSemanticDependenciesIfNecessary.

/**
 * The list of {@link N4JSProjectConfig#getSemanticDependencies() semantic dependencies} of
 * {@link N4JSProjectConfig}s is tricky for three reasons:
 * <ol>
 * <li>the semantic dependencies do not contain names of non-existing projects (in case of unresolved project
 * references in the package.json),
 * <li>the order of the semantic dependencies depends on the characteristics of the target projects (mainly the
 * {@link ProjectDescription#getDefinesPackage() "defines package"} property),
 * <li>each implicitly added dependency to a definition project PI depends on the characteristics of the target
 * project PT triggering this implicit dependency (i.e. the defined project) <em>and</em> the overall workspace
 * contents (Are definition projects available in the workspace for project PT?).
 * </ol>
 * Therefore, the "semantic dependencies" of a project P can change even without a change in the
 * <code>package.json</code> file of P. To detect and apply these changes is the purpose of this method.
 */
protected WorkspaceChanges recomputeSemanticDependenciesIfNecessary(WorkspaceConfigSnapshot oldWorkspaceConfig, WorkspaceChanges changes) {
    boolean needRecompute = !changes.getAddedProjects().isEmpty() || !changes.getRemovedProjects().isEmpty() || Iterables.any(changes.getChangedProjects(), pc -> affectedByPropertyChanges(pc, oldWorkspaceConfig));
    if (needRecompute) {
        List<ProjectConfigSnapshot> projectsWithChangedSemanticDeps = new ArrayList<>();
        for (XIProjectConfig pc : getProjects()) {
            String projectID = pc.getName();
            N4JSProjectConfigSnapshot oldSnapshot = (N4JSProjectConfigSnapshot) oldWorkspaceConfig.findProjectByID(projectID);
            if (oldSnapshot == null) {
                continue;
            }
            // convert to list in next line, because we want the below #equals() check to also include the order:
            List<String> oldSemanticDeps = new ArrayList<>(oldSnapshot.getDependencies());
            List<String> newSemanticDeps = ((N4JSProjectConfig) pc).getSemanticDependencies().stream().map(ProjectDependency::getPackageName).collect(Collectors.toList());
            if (!newSemanticDeps.equals(oldSemanticDeps)) {
                ProjectConfigSnapshot newSnapshot = configSnapshotFactory.createProjectConfigSnapshot(pc);
                if (!newSnapshot.equals(oldSnapshot)) {
                    projectsWithChangedSemanticDeps.add(newSnapshot);
                }
            }
        }
        if (!projectsWithChangedSemanticDeps.isEmpty()) {
            changes = changes.merge(WorkspaceChanges.createProjectsChanged(projectsWithChangedSemanticDeps));
        }
    }
    return changes;
}
Also used : Iterables(com.google.common.collect.Iterables) ConfigSnapshotFactory(org.eclipse.n4js.xtext.workspace.ConfigSnapshotFactory) URI(org.eclipse.emf.common.util.URI) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ProjectDependency(org.eclipse.n4js.packagejson.projectDescription.ProjectDependency) ProjectDescriptionLoader(org.eclipse.n4js.utils.ProjectDescriptionLoader) HashMultimap(com.google.common.collect.HashMultimap) N4JSGlobals(org.eclipse.n4js.N4JSGlobals) DefinitionProjectMap(org.eclipse.n4js.workspace.utils.DefinitionProjectMap) FluentIterable(com.google.common.collect.FluentIterable) Map(java.util.Map) XIWorkspaceConfig(org.eclipse.n4js.xtext.workspace.XIWorkspaceConfig) UriExtensions(org.eclipse.xtext.util.UriExtensions) Path(java.nio.file.Path) PackageJsonProperties(org.eclipse.n4js.packagejson.PackageJsonProperties) ProjectType(org.eclipse.n4js.packagejson.projectDescription.ProjectType) XIProjectConfig(org.eclipse.n4js.xtext.workspace.XIProjectConfig) FileURI(org.eclipse.n4js.workspace.locations.FileURI) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) WorkspaceChanges(org.eclipse.n4js.xtext.workspace.WorkspaceChanges) ProjectConfigSnapshot(org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot) Collectors(java.util.stream.Collectors) WorkspaceConfigSnapshot(org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) List(java.util.List) IterableExtensions(org.eclipse.xtext.xbase.lib.IterableExtensions) Collections(java.util.Collections) ProjectDiscoveryHelper(org.eclipse.n4js.utils.ProjectDiscoveryHelper) ProjectDescription(org.eclipse.n4js.packagejson.projectDescription.ProjectDescription) SemanticDependencySupplier(org.eclipse.n4js.workspace.utils.SemanticDependencySupplier) ProjectConfigSnapshot(org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot) ArrayList(java.util.ArrayList) XIProjectConfig(org.eclipse.n4js.xtext.workspace.XIProjectConfig)

Example 24 with ProjectConfigSnapshot

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

the class InProcessExecuter method n4jsc.

/**
 * Calls main entry point of N4jsc with the given args. Checks that the given exit code equals the actual exit code
 * of the invocation. Removes {@link N4jscOptions#USAGE} text if desired.
 */
protected CliCompileResult n4jsc(Path workDir, String[] args, CliCompileResult cliResult) {
    Stopwatch sw = Stopwatch.createStarted();
    try {
        setRedirections();
        cliResult.workingDir = workDir.toString();
        N4jscMain.main(workDir, args);
        cliResult.exitCode = 0;
    } catch (SystemExitException e) {
        cliResult.exitCode = e.status;
    } catch (Exception e) {
        cliResult.exception = e;
        if (cliResult.exitCode == ProcessResult.NO_EXIT_CODE) {
            cliResult.exitCode = -1;
        }
    } finally {
        cliResult.duration = sw.stop().elapsed(TimeUnit.MILLISECONDS);
        cliResult.stdOut = systemOutRedirecter.getSystemOut();
        cliResult.errOut = systemOutRedirecter.getSystemErr();
        if (isEnabledBackend) {
            N4jscTestLanguageClient callback = (N4jscTestLanguageClient) N4jscFactory.getLanguageClient();
            cliResult.issues = callback.issues;
            cliResult.errors = callback.errors;
            cliResult.warnings = callback.warnings;
            cliResult.transpiledFiles = callback.transpiledFiles;
            cliResult.deletedFilesCount = callback.getDeletionsCount();
            // save projects
            Injector injector = N4jscFactory.getOrCreateInjector();
            XWorkspaceManager workspaceManager = injector.getInstance(XWorkspaceManager.class);
            Set<? extends ProjectConfigSnapshot> projects = workspaceManager.getProjectConfigs();
            Map<String, String> projectMap = new TreeMap<>();
            for (ProjectConfigSnapshot pConfig : projects) {
                Path projectPath = URIUtils.toPath(pConfig.getPath());
                Path relativeProjectPath = workDir.relativize(projectPath);
                projectMap.put(pConfig.getName(), relativeProjectPath.toString());
            }
            cliResult.projects = projectMap;
        }
        unsetRedirections();
    }
    return cliResult;
}
Also used : Path(java.nio.file.Path) ProjectConfigSnapshot(org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot) Injector(com.google.inject.Injector) SystemExitException(org.eclipse.n4js.cli.helper.SystemExitRedirecter.SystemExitException) Stopwatch(com.google.common.base.Stopwatch) TreeMap(java.util.TreeMap) SystemExitException(org.eclipse.n4js.cli.helper.SystemExitRedirecter.SystemExitException) XWorkspaceManager(org.eclipse.n4js.xtext.ide.server.build.XWorkspaceManager)

Example 25 with ProjectConfigSnapshot

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

the class AbstractIdeTest method assertDependenciesOf.

/**
 * Asserts that the project with the given project ids has dependencies to the expected list of project ids.
 */
protected void assertDependenciesOf(String projectID, String... expectedProjects) {
    WorkspaceConfigSnapshot wc = concurrentIndex.getWorkspaceConfigSnapshot();
    ProjectConfigSnapshot project = wc.findProjectByID(projectID);
    ImmutableSet<String> dependencies = project.getDependencies();
    assertProjectsInWorkspace(expectedProjects, dependencies);
}
Also used : WorkspaceConfigSnapshot(org.eclipse.n4js.xtext.workspace.WorkspaceConfigSnapshot) ProjectConfigSnapshot(org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot)

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