Search in sources :

Example 1 with ProjectDescription

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

the class N4JSProjectBuilder method newBuildRequest.

@Override
protected XBuildRequest newBuildRequest(IBuildRequestFactory buildRequestFactory, Set<URI> changedFiles, Set<URI> deletedFiles, List<Delta> externalDeltas, CancelIndicator cancelIndicator) {
    XBuildRequest request = super.newBuildRequest(buildRequestFactory, changedFiles, deletedFiles, externalDeltas, cancelIndicator);
    ProjectDescription pd = getProjectConfig().getProjectDescription();
    if (N4JSLanguageUtils.isDtsGenerationActive(pd)) {
        request.addAfterBuildRequestListener(new DtsAfterBuildListener(getProjectConfig()));
    }
    request.addAfterBuildFileListener((uri) -> {
        Resource resource = getResource(uri);
        if (resource instanceof N4JSResource) {
            N4JSResource n4jsResource = (N4JSResource) resource;
            ASTFlowInfo flowInfo = n4jsResource.getASTMetaInfoCache().getFlowInfo();
            // release memory
            flowInfo.reset();
            n4jsResource.unloadAST();
        }
    });
    return request;
}
Also used : N4JSResource(org.eclipse.n4js.resource.N4JSResource) Resource(org.eclipse.emf.ecore.resource.Resource) N4JSResource(org.eclipse.n4js.resource.N4JSResource) ASTFlowInfo(org.eclipse.n4js.postprocessing.ASTFlowInfo) ProjectDescription(org.eclipse.n4js.packagejson.projectDescription.ProjectDescription) XBuildRequest(org.eclipse.n4js.xtext.ide.server.build.XBuildRequest)

Example 2 with ProjectDescription

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

the class DtsSubGenerator method isActive.

@Override
public boolean isActive(Resource input) {
    boolean superIsActive = super.isActive(input);
    if (!superIsActive) {
        return false;
    }
    N4JSWorkspaceConfigSnapshot ws = workspaceAccess.getWorkspaceConfig(input);
    N4JSProjectConfigSnapshot project = ws.findProjectContaining(input.getURI());
    if (project != null) {
        ProjectDescription pd = project.getProjectDescription();
        return N4JSLanguageUtils.isDtsGenerationActive(pd);
    }
    return false;
}
Also used : N4JSWorkspaceConfigSnapshot(org.eclipse.n4js.workspace.N4JSWorkspaceConfigSnapshot) N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) ProjectDescription(org.eclipse.n4js.packagejson.projectDescription.ProjectDescription)

Example 3 with ProjectDescription

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

the class ProjectDescriptionLoader method loadProjectDescriptionAtLocation.

/**
 * Same as {@link #loadPackageJSONAtLocation(SafeURI)}.
 */
public ProjectDescription loadProjectDescriptionAtLocation(URI location, URI relatedRootLocation, JSONDocument packageJSON) {
    if (location == null) {
        return null;
    }
    adjustMainPath(location, packageJSON);
    ProjectDescriptionBuilder pdbFromPackageJSON = packageJSON != null ? packageJsonHelper.convertToProjectDescription(packageJSON, true, null) : null;
    if (pdbFromPackageJSON != null) {
        setInformationFromFileSystem(location, pdbFromPackageJSON);
        pdbFromPackageJSON.setLocation(location);
        pdbFromPackageJSON.setRelatedRootLocation(relatedRootLocation);
        ProjectDescription result = pdbFromPackageJSON.build();
        return result;
    } else {
        return null;
    }
}
Also used : ProjectDescription(org.eclipse.n4js.packagejson.projectDescription.ProjectDescription) ProjectDescriptionBuilder(org.eclipse.n4js.packagejson.projectDescription.ProjectDescriptionBuilder)

Example 4 with ProjectDescription

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

the class ProjectDiscoveryHelper method collectYarnWorkspaceProjects.

/**
 * Adds all paths to projects to the given set of {@code projects} that match the workspace property of the given
 * yarn workspace project.
 */
private void collectYarnWorkspaceProjects(Path yarnProjectRoot, Map<Path, ProjectDescription> pdCache, Set<Path> allProjectDirs) {
    ProjectDescription projectDescription = getOrCreateProjectDescription(yarnProjectRoot, null, pdCache);
    if (projectDescription == null) {
        return;
    }
    List<String> workspaces = projectDescription.getWorkspaces();
    if (workspaces == null) {
        return;
    }
    // add the yarn workspace root project even if it is a PLAINJS project
    // Rationale:
    // 1) otherwise not possible for later code to distinguish between yarn workspace and side-by-side use cases,
    // 2) having the workspace root project or not makes a huge difference (projects exist inside projects) and it
    // is better to always stick to one situation (otherwise many tests would have to be provided in two variants),
    // 3) the yarn workspace root project has always been included.
    allProjectDirs.add(yarnProjectRoot);
    Set<Path> memberProjects = new LinkedHashSet<>();
    for (String workspaceGlob : workspaces) {
        collectGlobMatches(workspaceGlob, yarnProjectRoot, pdCache, memberProjects);
    }
    removeUnnecessaryPlainjsProjects(memberProjects, pdCache);
    for (Path member : memberProjects) {
        allProjectDirs.add(member);
    }
}
Also used : Path(java.nio.file.Path) LinkedHashSet(java.util.LinkedHashSet) ProjectDescription(org.eclipse.n4js.packagejson.projectDescription.ProjectDescription)

Example 5 with ProjectDescription

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

the class ProjectDiscoveryHelper method collectAllProjectDirs.

/**
 * Collects all projects and uses the approach described above with each of the given workspace root folders.
 * <p>
 * Notes:
 * <ul>
 * <li/>Projects and dependencies are sorted to avoid indeterminism from file system.
 * <li/>Dependencies (i.e. projects in {@code node_modules} folders) are listed after all workspace projects.
 * <li/>Projects in packages folders have a symlink in the node_modules folder (created by yarn). The symlink is not
 * used in favor for the path in the packages folder because we want to support workspaces that have not yet
 * initialized by yarn.
 * </ul>
 * <p>
 */
public Map<Path, ProjectDescription> collectAllProjectDirs(Collection<Path> workspaceRoots) {
    Map<Path, ProjectDescription> pdCache = new HashMap<>();
    Set<Path> projects = collectAllProjects(workspaceRoots, pdCache);
    Set<Path> dependencies = collectNecessaryDependencies(projects, pdCache);
    List<Path> sortedProjects = new ArrayList<>(projects);
    Collections.sort(sortedProjects);
    List<Path> sortedDependecies = new ArrayList<>();
    sortedDependecies.addAll(dependencies);
    Collections.sort(sortedDependecies);
    sortedProjects.addAll(sortedDependecies);
    Map<Path, ProjectDescription> sortedProjectMap = new LinkedHashMap<>();
    for (Path projectLocation : sortedProjects) {
        ProjectDescription pd = getProjectDescription(projectLocation, pdCache);
        Preconditions.checkNotNull(pd);
        sortedProjectMap.put(projectLocation, pd);
    }
    return sortedProjectMap;
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) ProjectDescription(org.eclipse.n4js.packagejson.projectDescription.ProjectDescription) LinkedHashMap(java.util.LinkedHashMap)

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