use of org.eclipse.n4js.external.libraries.ExternalLibrariesActivator.MANGELHAFT_CATEGORY in project n4js by eclipse.
the class N4JSProjectExplorerHelper method getVirtualNodesForProject.
/**
* Returns with an array of virtual {@link Node node} instances for the project that should be revealed in the
* project explorer.
*
* @param project
* the workspace project.
* @return an array of virtual nodes.
*/
public Node[] getVirtualNodesForProject(IProject project) {
checkArgument(!(project instanceof ExternalProject), "Expected Eclipse workspace project. Got: " + project);
if (null == project || !project.exists() || !project.isAccessible()) {
return Node.EMPTY_NODES;
}
IN4JSProject n4Project = getProject(project);
if (null == n4Project || !n4Project.exists() || n4Project.isExternal()) {
return Node.EMPTY_NODES;
}
final Image image = ImageRef.LIB_PATH.asImage().get();
final NamedNode rootNode = new NamedNode(project, "External Dependencies", image);
Iterable<IN4JSProject> directDependencies = from(n4Project.getAllDirectDependencies()).filter(IN4JSProject.class);
Iterable<IN4JSProject> runtimeLibraries = getExternalDependenciesOfType(directDependencies, RUNTIME_LIBRARY);
if (!from(runtimeLibraries).isEmpty()) {
Map<String, IN4JSProject> builtInRuntimeEnvironments = getBuiltInRuntimeEnvironments();
Map<String, IN4JSProject> builtInRuntimeLibraries = getBuiltInRuntimeLibraries();
Collection<IN4JSProject> libs = newHashSet();
Collection<IN4JSProject> envs = newHashSet();
for (IN4JSProject p : runtimeLibraries) {
IN4JSProject dependency = builtInRuntimeLibraries.get(p.getProjectId());
if (null != dependency) {
libs.add(dependency);
}
}
if (!libs.isEmpty()) {
OUTER: for (IN4JSProject p : builtInRuntimeEnvironments.values()) {
for (IN4JSProject providedLib : from(p.getProvidedRuntimeLibraries()).filter(IN4JSProject.class)) {
if (libs.contains(providedLib)) {
envs.add(p);
String extndedRuntimeEnvName = p.getExtendedRuntimeEnvironmentId().orNull();
if (null != extndedRuntimeEnvName) {
final IN4JSProject extension = builtInRuntimeEnvironments.get(extndedRuntimeEnvName);
if (null != extension) {
envs.add(extension);
}
}
continue OUTER;
}
}
}
}
NamedNode runtimeNode = new NamedNode(rootNode, "N4JS Runtime", image);
if (!envs.isEmpty()) {
NamedNode envsNode = new NamedNode(runtimeNode, "Runtime Environments", image);
envsNode.addChild(from(envs).transform(p -> new BuiltInProjectNode(envsNode, p)));
runtimeNode.addChild(envsNode);
}
if (!libs.isEmpty()) {
NamedNode libsNode = new NamedNode(runtimeNode, "Runtime Libraries", image);
libsNode.addChild(from(libs).transform(p -> new BuiltInProjectNode(libsNode, p)));
runtimeNode.addChild(libsNode);
}
if (!Arrays2.isEmpty(runtimeNode.getChildren())) {
rootNode.addChild(runtimeNode);
}
}
Map<String, IN4JSProject> langProjects = getAvailableLangProjects();
Map<String, IN4JSProject> mangelhaftProjects = getAvailableMangelhaftProjects();
Map<String, IN4JSProject> npmProjects = getAvailableNpmProjects();
Collection<IN4JSProject> requiredLangLibs = newHashSet();
Collection<IN4JSProject> requiredMangelhaftLibs = newHashSet();
Collection<IN4JSProject> requiredNpmLibs = newHashSet();
for (IN4JSProject directDependecy : directDependencies) {
if (directDependecy.exists() && directDependecy.isExternal()) {
IN4JSProject externalDepenency = mangelhaftProjects.get(directDependecy.getProjectId());
if (null != externalDepenency) {
requiredMangelhaftLibs.add(externalDepenency);
} else {
externalDepenency = npmProjects.get(directDependecy.getProjectId());
if (null != externalDepenency) {
requiredNpmLibs.add(externalDepenency);
} else {
externalDepenency = langProjects.get(directDependecy.getProjectId());
if (null != externalDepenency) {
requiredLangLibs.add(externalDepenency);
}
}
}
}
}
if (!requiredLangLibs.isEmpty()) {
NamedNode langNode = new NamedNode(rootNode, EXTERNAL_LIBRARY_NAMES.get(LANG_CATEGORY), image);
langNode.addChild(from(requiredLangLibs).transform(p -> new BuiltInProjectNode(langNode, p)));
rootNode.addChild(langNode);
}
if (!requiredMangelhaftLibs.isEmpty()) {
NamedNode mangNode = new NamedNode(rootNode, EXTERNAL_LIBRARY_NAMES.get(MANGELHAFT_CATEGORY), image);
mangNode.addChild(from(requiredMangelhaftLibs).transform(p -> new BuiltInProjectNode(mangNode, p)));
rootNode.addChild(mangNode);
}
if (!requiredNpmLibs.isEmpty()) {
NamedNode npmNode = new NamedNode(rootNode, EXTERNAL_LIBRARY_NAMES.get(NPM_CATEGORY), image);
npmNode.addChild(from(requiredNpmLibs).transform(p -> new BuiltInProjectNode(npmNode, p)));
rootNode.addChild(npmNode);
}
return Arrays2.isEmpty(rootNode.getChildren()) ? new Node[0] : new Node[] { rootNode };
}
Aggregations