Search in sources :

Example 16 with ProjectDescription

use of org.eclipse.n4js.packagejson.projectDescription.ProjectDescription in project n4js by eclipse.

the class ProjectDiscoveryHelper method removeUnnecessaryPlainjsProjects.

/**
 * Removes from <code>projects</code> all "unnecessary" {@link ProjectType#PLAINJS PLAINJS} projects. A PLAINJS
 * project P is "unnecessary" if there does not exist an N4JS project P' in <code>projects</code> that has a
 * dependency to P.
 */
private void removeUnnecessaryPlainjsProjects(Set<Path> projects, Map<Path, ProjectDescription> pdCache) {
    Map<String, Path> plainjsProjects = new HashMap<>();
    Set<String> projectsRequiredByAnN4JSProject = new HashSet<>();
    for (Path project : projects) {
        // if it is null it was not added before
        ProjectDescription pd = getProjectDescription(project, pdCache);
        if (pd == null) {
            continue;
        }
        ProjectType type = pd.getType();
        if (type == ProjectType.PLAINJS) {
            // note: in case a name occurs twice yarn would throw an error
            plainjsProjects.put(pd.getPackageName(), project);
        } else {
            List<String> deps = pd.getProjectDependencies().stream().map(ProjectReference::getPackageName).collect(Collectors.toList());
            projectsRequiredByAnN4JSProject.addAll(deps);
        }
    }
    plainjsProjects.keySet().removeAll(projectsRequiredByAnN4JSProject);
    for (String plainJsName : plainjsProjects.keySet()) {
        projects.remove(plainjsProjects.get(plainJsName));
    }
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ProjectType(org.eclipse.n4js.packagejson.projectDescription.ProjectType) ProjectDescription(org.eclipse.n4js.packagejson.projectDescription.ProjectDescription) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 17 with ProjectDescription

use of org.eclipse.n4js.packagejson.projectDescription.ProjectDescription 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 18 with ProjectDescription

use of org.eclipse.n4js.packagejson.projectDescription.ProjectDescription in project n4js by eclipse.

the class MockWorkspaceSupplier method loadProjectDescription.

/**
 * See {@link #createWorkspaceConfig()}.
 */
protected Optional<Pair<FileURI, ProjectDescription>> loadProjectDescription() {
    FileURI candidateProjectPath = new FileURI(new File("").getAbsoluteFile());
    ProjectDescription pd = projectDescriptionLoader.loadProjectDescriptionAtLocation(candidateProjectPath, null);
    return Optional.fromNullable(pd != null ? Pair.of(candidateProjectPath, pd) : null);
}
Also used : FileURI(org.eclipse.n4js.workspace.locations.FileURI) File(java.io.File) ProjectDescription(org.eclipse.n4js.packagejson.projectDescription.ProjectDescription)

Example 19 with ProjectDescription

use of org.eclipse.n4js.packagejson.projectDescription.ProjectDescription in project n4js by eclipse.

the class ProjectDiscoveryTest method getActualFolders.

private ArrayList<String> getActualFolders(Path tmpDir, Path workspaceRoot) {
    Map<Path, ProjectDescription> projects = projectDiscoveryHelper.collectAllProjectDirs(Collections.singleton(workspaceRoot));
    ArrayList<String> actualFolders = new ArrayList<>();
    for (Path projectDir : projects.keySet()) {
        String relativeFolder = tmpDir.relativize(projectDir).toString();
        actualFolders.add(relativeFolder);
    }
    Collections.sort(actualFolders);
    return actualFolders;
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) ProjectDescription(org.eclipse.n4js.packagejson.projectDescription.ProjectDescription)

Aggregations

ProjectDescription (org.eclipse.n4js.packagejson.projectDescription.ProjectDescription)19 Path (java.nio.file.Path)8 FileURI (org.eclipse.n4js.workspace.locations.FileURI)6 N4JSProjectConfigSnapshot (org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot)4 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 File (java.io.File)2 HashMap (java.util.HashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 ProjectDependency (org.eclipse.n4js.packagejson.projectDescription.ProjectDependency)2 ProjectDescriptionBuilder (org.eclipse.n4js.packagejson.projectDescription.ProjectDescriptionBuilder)2 ProjectType (org.eclipse.n4js.packagejson.projectDescription.ProjectType)2 N4JSSourceFolderSnapshot (org.eclipse.n4js.workspace.N4JSSourceFolderSnapshot)2 FluentIterable (com.google.common.collect.FluentIterable)1 HashMultimap (com.google.common.collect.HashMultimap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 Sets (com.google.common.collect.Sets)1 IOException (java.io.IOException)1 FileVisitOption (java.nio.file.FileVisitOption)1