Search in sources :

Example 1 with ProjectDependency

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

the class PackageJsonHelper method adjustProjectDescriptionAfterConversion.

private void adjustProjectDescriptionAfterConversion(ProjectDescriptionBuilder target, boolean applyDefaultValues, String defaultProjectName, String valueOfTopLevelPropertyMain) {
    // store whether target has a declared mainModule *before* applying the default values
    boolean hasN4jsSpecificMainModule = target.getMainModule() != null;
    // apply default values (if desired)
    if (applyDefaultValues) {
        applyDefaults(target, defaultProjectName);
    }
    // (note: this makes use of the source containers, so it possibly relies on default values having been applied)
    if (valueOfTopLevelPropertyMain != null) {
        if (!hasN4jsSpecificMainModule) {
            // only if no N4JS-specific "mainModule" property was given
            List<String> sourceContainerPaths = target.getSourceContainers().stream().flatMap(scd -> ProjectDescriptionUtils.getPathsNormalized(scd).stream()).collect(Collectors.toList());
            String mainModulePath = ProjectDescriptionUtils.convertMainPathToModuleSpecifier(valueOfTopLevelPropertyMain, sourceContainerPaths);
            if (mainModulePath != null) {
                target.setMainModule(mainModulePath);
            }
        }
    }
    // sanitize dependencies: remove implementation projects from dependencies if API projects also given
    // (this is a work-around for supporting the API/Impl concept with npm/yarn: in a client project, both the API
    // and implementation projects will be specified as dependency in the package.json and the following code will
    // filter out implementation projects to not confuse API/Impl logic in other places)
    Set<String> projectNamesToRemove = new HashSet<>();
    List<ProjectDependency> projectDependencies = target.getDependencies();
    for (ProjectDependency dep : projectDependencies) {
        String otherProject = dep.getPackageName();
        for (String suffix : N4JSGlobals.API_PROJECT_NAME_SUFFIXES) {
            if (otherProject.endsWith(suffix)) {
                projectNamesToRemove.add(otherProject.substring(0, otherProject.length() - suffix.length()));
                break;
            }
        }
    }
    if (!projectNamesToRemove.isEmpty()) {
        for (int i = projectDependencies.size() - 1; i >= 0; i--) {
            if (projectNamesToRemove.contains(projectDependencies.get(i).getPackageName())) {
                projectDependencies.remove(i);
            }
        }
    }
}
Also used : JSONModelUtils.asStringsInArrayOrEmpty(org.eclipse.n4js.json.model.utils.JSONModelUtils.asStringsInArrayOrEmpty) Inject(com.google.inject.Inject) JSONValue(org.eclipse.n4js.json.JSON.JSONValue) VERSION(org.eclipse.n4js.packagejson.PackageJsonProperties.VERSION) SourceContainerDescription(org.eclipse.n4js.packagejson.projectDescription.SourceContainerDescription) VENDOR_ID(org.eclipse.n4js.packagejson.PackageJsonProperties.VENDOR_ID) DependencyType(org.eclipse.n4js.packagejson.projectDescription.DependencyType) HashSet(java.util.HashSet) ProjectDependency(org.eclipse.n4js.packagejson.projectDescription.ProjectDependency) N4JSGlobals(org.eclipse.n4js.N4JSGlobals) PROJECT_TYPE(org.eclipse.n4js.packagejson.PackageJsonProperties.PROJECT_TYPE) JSONDocument(org.eclipse.n4js.json.JSON.JSONDocument) PackageJsonUtils.asProjectReferencesInArrayOrEmpty(org.eclipse.n4js.packagejson.PackageJsonUtils.asProjectReferencesInArrayOrEmpty) MAIN_MODULE(org.eclipse.n4js.packagejson.PackageJsonProperties.MAIN_MODULE) ProjectDescriptionBuilder(org.eclipse.n4js.packagejson.projectDescription.ProjectDescriptionBuilder) PackageJsonUtils.asProjectReferenceOrNull(org.eclipse.n4js.packagejson.PackageJsonUtils.asProjectReferenceOrNull) SourceContainerType(org.eclipse.n4js.packagejson.projectDescription.SourceContainerType) JSONModelUtils.asNameValuePairsOrEmpty(org.eclipse.n4js.json.model.utils.JSONModelUtils.asNameValuePairsOrEmpty) JSONModelUtils.asNonEmptyStringOrNull(org.eclipse.n4js.json.model.utils.JSONModelUtils.asNonEmptyStringOrNull) ProjectDescriptionUtils(org.eclipse.n4js.utils.ProjectDescriptionUtils) ProjectType(org.eclipse.n4js.packagejson.projectDescription.ProjectType) GENERATOR_SOURCE_MAPS(org.eclipse.n4js.packagejson.PackageJsonProperties.GENERATOR_SOURCE_MAPS) OUTPUT(org.eclipse.n4js.packagejson.PackageJsonProperties.OUTPUT) PACKAGES(org.eclipse.n4js.packagejson.PackageJsonProperties.PACKAGES) PackageJsonUtils.asModuleFiltersInObjectOrEmpty(org.eclipse.n4js.packagejson.PackageJsonUtils.asModuleFiltersInObjectOrEmpty) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) Set(java.util.Set) PackageJsonUtils.parseProjectType(org.eclipse.n4js.packagejson.PackageJsonUtils.parseProjectType) VersionNumber(org.eclipse.n4js.semver.Semver.VersionNumber) JSONModelUtils.getProperty(org.eclipse.n4js.json.model.utils.JSONModelUtils.getProperty) Collectors(java.util.stream.Collectors) GENERATOR_DTS(org.eclipse.n4js.packagejson.PackageJsonProperties.GENERATOR_DTS) Objects(java.util.Objects) SemverHelper(org.eclipse.n4js.semver.SemverHelper) List(java.util.List) NPMVersionRequirement(org.eclipse.n4js.semver.Semver.NPMVersionRequirement) JSONObject(org.eclipse.n4js.json.JSON.JSONObject) PackageJsonUtils.asSourceContainerDescriptionsOrEmpty(org.eclipse.n4js.packagejson.PackageJsonUtils.asSourceContainerDescriptionsOrEmpty) MAIN(org.eclipse.n4js.packagejson.PackageJsonProperties.MAIN) NameValuePair(org.eclipse.n4js.json.JSON.NameValuePair) JSONModelUtils.asStringOrNull(org.eclipse.n4js.json.model.utils.JSONModelUtils.asStringOrNull) JSONModelUtils.asBooleanOrDefault(org.eclipse.n4js.json.model.utils.JSONModelUtils.asBooleanOrDefault) GENERATOR_REWRITE_CJS_IMPORTS(org.eclipse.n4js.packagejson.PackageJsonProperties.GENERATOR_REWRITE_CJS_IMPORTS) Collections(java.util.Collections) ProjectDescription(org.eclipse.n4js.packagejson.projectDescription.ProjectDescription) ProjectDependency(org.eclipse.n4js.packagejson.projectDescription.ProjectDependency) HashSet(java.util.HashSet)

Example 2 with ProjectDependency

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

the class N4JSProjectConfig method init.

/**
 * Initializes {@link #packageNameToProjectIds} and {@link #semanticDependencies}.
 */
protected void init() {
    List<ProjectDependency> deps = projectDescription.getProjectDependencies();
    List<ProjectDependency> semanticDeps = semanticDependencySupplier.computeSemanticDependencies(workspace.definitionProjects, deps);
    Path relatedRootLocation = getRelatedRootLocation();
    HashSet<String> allNames = new HashSet<>(workspace.getAllPackageNames());
    semanticDeps.stream().forEach(d -> allNames.add(d.getPackageName()));
    packageNameToProjectIds = Collections.unmodifiableMap(semanticDependencySupplier.computePackageName2ProjectIdMap(workspace, projectDescription, relatedRootLocation, allNames));
    List<ProjectDependency> result = new ArrayList<>(semanticDeps.size());
    for (ProjectDependency sdep : semanticDeps) {
        String qualifiedName = getProjectIdForPackageName(sdep.getPackageName());
        ProjectDependency newDep = new ProjectDependency(qualifiedName, sdep.getType(), sdep.getVersionRequirementString(), sdep.getVersionRequirement());
        result.add(newDep);
    }
    semanticDependencies = Collections.unmodifiableList(result);
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) ProjectDependency(org.eclipse.n4js.packagejson.projectDescription.ProjectDependency) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 3 with ProjectDependency

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

the class N4JSConfigSnapshotFactory method createProjectConfigSnapshot.

@Override
public N4JSProjectConfigSnapshot createProjectConfigSnapshot(XIProjectConfig projectConfig) {
    N4JSProjectConfig projectConfigCasted = (N4JSProjectConfig) projectConfig;
    List<String> semanticDependencies = Lists.transform(projectConfigCasted.getSemanticDependencies(), ProjectDependency::getPackageName);
    return new N4JSProjectConfigSnapshot(projectConfigCasted.getProjectDescription(), projectConfig.getPath(), projectConfig.indexOnly(), projectConfig.isGeneratorEnabled(), semanticDependencies, Iterables.transform(projectConfig.getSourceFolders(), this::createSourceFolderSnapshot), projectConfigCasted.getPackageNameForProjectIdMap());
}
Also used : N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) ProjectDependency(org.eclipse.n4js.packagejson.projectDescription.ProjectDependency) N4JSProjectConfig(org.eclipse.n4js.workspace.N4JSProjectConfig)

Example 4 with ProjectDependency

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

the class PackageJsonHelper method convertDependencies.

private void convertDependencies(ProjectDescriptionBuilder target, List<NameValuePair> depPairs, boolean avoidDuplicates, DependencyType type) {
    Objects.requireNonNull(type);
    Set<String> existingProjectNames = new HashSet<>();
    if (avoidDuplicates) {
        for (ProjectDependency pd : target.getDependencies()) {
            existingProjectNames.add(pd.getPackageName());
        }
    }
    for (NameValuePair pair : depPairs) {
        String projectName = pair.getName();
        boolean addProjectDependency = true;
        addProjectDependency &= projectName != null && !projectName.isEmpty();
        addProjectDependency &= !(avoidDuplicates && existingProjectNames.contains(projectName));
        existingProjectNames.add(projectName);
        if (addProjectDependency) {
            JSONValue value = pair.getValue();
            String valueStr = asStringOrNull(value);
            NPMVersionRequirement versionRequirement = valueStr != null ? semverHelper.parse(valueStr) : null;
            ProjectDependency dep = new ProjectDependency(projectName, type, valueStr, versionRequirement);
            target.addDependency(dep);
        }
    }
}
Also used : JSONValue(org.eclipse.n4js.json.JSON.JSONValue) NameValuePair(org.eclipse.n4js.json.JSON.NameValuePair) ProjectDependency(org.eclipse.n4js.packagejson.projectDescription.ProjectDependency) NPMVersionRequirement(org.eclipse.n4js.semver.Semver.NPMVersionRequirement) HashSet(java.util.HashSet)

Example 5 with ProjectDependency

use of org.eclipse.n4js.packagejson.projectDescription.ProjectDependency 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);
        }
    }
}
Also used : Path(java.nio.file.Path) ProjectDependency(org.eclipse.n4js.packagejson.projectDescription.ProjectDependency) ProjectDescription(org.eclipse.n4js.packagejson.projectDescription.ProjectDescription)

Aggregations

ProjectDependency (org.eclipse.n4js.packagejson.projectDescription.ProjectDependency)8 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 LinkedHashSet (java.util.LinkedHashSet)3 ProjectDescription (org.eclipse.n4js.packagejson.projectDescription.ProjectDescription)3 Collections (java.util.Collections)2 List (java.util.List)2 Objects (java.util.Objects)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 N4JSGlobals (org.eclipse.n4js.N4JSGlobals)2 JSONValue (org.eclipse.n4js.json.JSON.JSONValue)2 NameValuePair (org.eclipse.n4js.json.JSON.NameValuePair)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 Inject (com.google.inject.Inject)1