use of org.eclipse.n4js.packagejson.projectDescription.ProjectDescription in project n4js by eclipse.
the class DtsUtils method isDtsExportableReference.
/**
* Tells whether references (e.g. imports, type references) to the given resource and its contents can be exported
* to .d.ts. Iff this returns <code>false</code>, the .d.ts export will be cut off at this reference.
*/
public static boolean isDtsExportableReference(Resource resource, TranspilerState state) {
if (resource == null) {
return false;
}
if (N4Scheme.isResourceWithN4Scheme(resource)) {
return true;
}
N4JSProjectConfigSnapshot project = state.workspaceAccess.findProjectContaining(resource);
ProjectDescription pd = project != null ? project.getProjectDescription() : null;
return pd != null && pd.hasN4JSNature() && (N4JSLanguageUtils.isDtsGenerationActive(pd) || isDefinition(pd) || isRuntime(pd));
}
use of org.eclipse.n4js.packagejson.projectDescription.ProjectDescription in project n4js by eclipse.
the class NodeModulesDiscoveryHelper method getWorkspacesOfYarnWorkspaceProject.
private List<String> getWorkspacesOfYarnWorkspaceProject(File yarnProjectFolder, Map<Path, ProjectDescription> pdCache) {
// obtain value of property "workspaces" in package.json located in folder 'candidate'
final ProjectDescription prjDescr = pdCache.computeIfAbsent(yarnProjectFolder.toPath(), // load value from package.json
p -> {
FileURI location = new FileURI(yarnProjectFolder);
// yarn projects do not have a related root, hence location is given
ProjectDescription pd = projectDescriptionLoader.loadProjectDescriptionAtLocation(location, null);
return pd;
});
final List<String> workspaces = (prjDescr != null && prjDescr.isYarnWorkspaceRoot()) ? prjDescr.getWorkspaces() : null;
return workspaces;
}
use of org.eclipse.n4js.packagejson.projectDescription.ProjectDescription in project n4js by eclipse.
the class ProjectDiscoveryHelper method getOrCreateProjectDescription.
/**
* @return the potentially cached {@link ProjectDescription} for the project in the given directory or creates it.
* In case creation fails, null is returned.
*/
private ProjectDescription getOrCreateProjectDescription(Path path, Path relatedRoot, Map<Path, ProjectDescription> cache) {
if (!cache.containsKey(path) || cache.get(path).getRelatedRootLocation() == null) {
FileURI location = new FileURI(path.toFile());
FileURI relatedRootLocation = relatedRoot == null ? null : new FileURI(relatedRoot.toFile());
ProjectDescription pd = projectDescriptionLoader.loadProjectDescriptionAtLocation(location, relatedRootLocation);
cache.put(path, pd);
}
ProjectDescription pd = cache.get(path);
if (pd != null && relatedRoot != null && pd.getRelatedRootLocation() != null && !Objects.equals(relatedRoot, pd.getRelatedRootLocation().toPath())) {
// recompute project description in case the nodeModulesDiscoveryHelper added it
ProjectDescriptionBuilder pdb = pd.change();
pd = pdb.setRelatedRootLocation(new FileURI(relatedRoot.toFile())).setId(pdb.computeProjectID()).build();
cache.put(path, pd);
}
return pd;
}
use of org.eclipse.n4js.packagejson.projectDescription.ProjectDescription in project n4js by eclipse.
the class ProjectDiscoveryHelper method findDependencies.
private void findDependencies(Set<Path> allProjectDirs, Path prjDir, NodeModulesFolder nodeModulesFolder, Map<Path, ProjectDescription> pdCache, Set<Path> workList, Set<Path> dependencies) {
Path relatedRoot = nodeModulesFolder.getRelatedRoot();
Path prjNodeModules = prjDir.resolve(N4JSGlobals.NODE_MODULES);
ProjectDescription prjDescr = getOrCreateProjectDescription(prjDir, relatedRoot, pdCache);
if (prjDescr == null) {
return;
}
for (ProjectDependency dependency : prjDescr.getProjectDependencies()) {
String depName = dependency.getPackageName();
Path depLocation = findDependencyLocation(nodeModulesFolder, prjNodeModules, depName);
if (isNewDependency(allProjectDirs, prjDir, pdCache, depLocation, relatedRoot)) {
addDependency(depLocation, relatedRoot, pdCache, workList, dependencies);
}
}
}
use of org.eclipse.n4js.packagejson.projectDescription.ProjectDescription in project n4js by eclipse.
the class ProjectDiscoveryHelper method collectGlobMatches.
private void collectGlobMatches(String glob, Path yarnRoot, Map<Path, ProjectDescription> pdCache, Set<Path> allProjectDirs) {
int depth = glob.contains("**") ? Integer.MAX_VALUE : glob.split("/").length + 1;
@SuppressWarnings("resource") PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("glob:" + yarnRoot.resolve(glob));
try {
EnumSet<FileVisitOption> options = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
Files.walkFileTree(yarnRoot, options, depth, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
if (dir.endsWith(N4JSGlobals.NODE_MODULES)) {
return FileVisitResult.SKIP_SUBTREE;
}
if (pathMatcher.matches(dir)) {
Path dirName = dir.getName(dir.getNameCount() - 1);
if (dirName.toString().startsWith("@")) {
// note: project names must not start with '@' (unless it is a parent folder)
collectProjects(dir, yarnRoot, false, pdCache, allProjectDirs);
return FileVisitResult.SKIP_SUBTREE;
} else {
File pckJson = dir.resolve(N4JSGlobals.PACKAGE_JSON).toFile();
if (pckJson.isFile()) {
ProjectDescription projectDescription = getOrCreateProjectDescription(dir, yarnRoot, pdCache);
// #removeUnnecessaryPlainjsProjects() below)
if (projectDescription != null) {
allProjectDirs.add(dir);
}
return FileVisitResult.SKIP_SUBTREE;
}
}
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) {
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations