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