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