Search in sources :

Example 21 with N4JSPackageName

use of org.eclipse.n4js.workspace.utils.N4JSPackageName in project n4js by eclipse.

the class N4jsLibsAccess method loadDepenencies.

private static Set<N4JSPackageName> loadDepenencies(Path projectPath, boolean includeDevDependencies, boolean excludeNestedProjects, boolean includeDepsOfNestedProjects) throws IOException {
    Set<N4JSPackageName> result = new LinkedHashSet<>();
    Map<N4JSPackageName, Path> nodeModuleProjects = getNodeModuleProjects(projectPath);
    // add dependencies of project at 'projectPath'
    List<N4JSPackageName> dependencyNames = loadDepenencies(projectPath, includeDevDependencies);
    result.addAll(dependencyNames);
    // add dependencies of nested projects (if requested)
    if (includeDepsOfNestedProjects) {
        for (Path nestedProjectPath : nodeModuleProjects.values()) {
            Set<N4JSPackageName> nestedDependencyNames = loadDepenencies(nestedProjectPath, // never include devDependencies of nested projects!
            false, excludeNestedProjects, includeDepsOfNestedProjects);
            result.addAll(nestedDependencyNames);
        }
    }
    // remove nested projects (if requested)
    if (excludeNestedProjects) {
        result.removeAll(nodeModuleProjects.keySet());
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Path(java.nio.file.Path) N4JSPackageName(org.eclipse.n4js.workspace.utils.N4JSPackageName)

Example 22 with N4JSPackageName

use of org.eclipse.n4js.workspace.utils.N4JSPackageName in project n4js by eclipse.

the class N4jsLibsAccess method getNodeModuleProjects.

/**
 * Returns name/path of all projects nested inside the node_modules folder of the project at the given location.
 */
private static Map<N4JSPackageName, Path> getNodeModuleProjects(Path projectPath) {
    Map<N4JSPackageName, Path> result = new HashMap<>();
    Path nodeModulesPath = projectPath.resolve(N4JSGlobals.NODE_MODULES);
    if (Files.exists(nodeModulesPath)) {
        for (File childDir : nodeModulesPath.toFile().listFiles(File::isDirectory)) {
            if (childDir.getName().startsWith("@")) {
                for (File grandChildDir : childDir.listFiles(File::isDirectory)) {
                    if (isNpmPackage(grandChildDir.toPath())) {
                        result.put(new N4JSPackageName(childDir.getName() + '/' + grandChildDir.getName()), grandChildDir.toPath());
                    }
                }
            } else if (isNpmPackage(childDir.toPath())) {
                result.put(new N4JSPackageName(childDir.getName()), childDir.toPath());
            }
        }
    }
    return result;
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) N4JSPackageName(org.eclipse.n4js.workspace.utils.N4JSPackageName) File(java.io.File)

Example 23 with N4JSPackageName

use of org.eclipse.n4js.workspace.utils.N4JSPackageName in project n4js by eclipse.

the class AbstractIdeTest method installN4JSRuntime.

/**
 * Installs the given libsToInstall into the given target project. Respects yarn setups.
 *
 * @see N4jsLibsAccess#installN4jsLibs
 */
protected void installN4JSRuntime() {
    File root = getProjectRoot();
    N4JSPackageName projectName = new N4JSPackageName(root);
    installN4jsLibs(projectName, new N4JSPackageName[] { N4JSGlobals.N4JS_RUNTIME });
}
Also used : N4JSPackageName(org.eclipse.n4js.workspace.utils.N4JSPackageName) File(java.io.File)

Aggregations

N4JSPackageName (org.eclipse.n4js.workspace.utils.N4JSPackageName)23 N4JSProjectConfigSnapshot (org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot)9 Path (java.nio.file.Path)8 File (java.io.File)5 ArrayList (java.util.ArrayList)5 LinkedHashMap (java.util.LinkedHashMap)5 HashMap (java.util.HashMap)3 Entry (java.util.Map.Entry)3 Set (java.util.Set)3 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)3 Optional (com.google.common.base.Optional)2 FluentIterable (com.google.common.collect.FluentIterable)2 Multimap (com.google.common.collect.Multimap)2 Sets (com.google.common.collect.Sets)2 IOException (java.io.IOException)2 Files (java.nio.file.Files)2 FileTime (java.nio.file.attribute.FileTime)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2