use of org.eclipse.n4js.packagejson.projectDescription.ProjectDependency in project n4js by eclipse.
the class N4JSProjectConfig method getDependencies.
/**
* The dependencies of this project as given in the <code>package.json</code> file.
*/
@Override
public Set<String> getDependencies() {
List<ProjectDependency> deps = projectDescription.getProjectDependencies();
Set<String> result = new LinkedHashSet<>(deps.size());
for (ProjectDependency dep : deps) {
result.add(getProjectIdForPackageName(dep.getPackageName()));
}
return result;
}
use of org.eclipse.n4js.packagejson.projectDescription.ProjectDependency in project n4js by eclipse.
the class N4JSWorkspaceConfig method recomputeSemanticDependenciesIfNecessary.
/**
* The list of {@link N4JSProjectConfig#getSemanticDependencies() semantic dependencies} of
* {@link N4JSProjectConfig}s is tricky for three reasons:
* <ol>
* <li>the semantic dependencies do not contain names of non-existing projects (in case of unresolved project
* references in the package.json),
* <li>the order of the semantic dependencies depends on the characteristics of the target projects (mainly the
* {@link ProjectDescription#getDefinesPackage() "defines package"} property),
* <li>each implicitly added dependency to a definition project PI depends on the characteristics of the target
* project PT triggering this implicit dependency (i.e. the defined project) <em>and</em> the overall workspace
* contents (Are definition projects available in the workspace for project PT?).
* </ol>
* Therefore, the "semantic dependencies" of a project P can change even without a change in the
* <code>package.json</code> file of P. To detect and apply these changes is the purpose of this method.
*/
protected WorkspaceChanges recomputeSemanticDependenciesIfNecessary(WorkspaceConfigSnapshot oldWorkspaceConfig, WorkspaceChanges changes) {
boolean needRecompute = !changes.getAddedProjects().isEmpty() || !changes.getRemovedProjects().isEmpty() || Iterables.any(changes.getChangedProjects(), pc -> affectedByPropertyChanges(pc, oldWorkspaceConfig));
if (needRecompute) {
List<ProjectConfigSnapshot> projectsWithChangedSemanticDeps = new ArrayList<>();
for (XIProjectConfig pc : getProjects()) {
String projectID = pc.getName();
N4JSProjectConfigSnapshot oldSnapshot = (N4JSProjectConfigSnapshot) oldWorkspaceConfig.findProjectByID(projectID);
if (oldSnapshot == null) {
continue;
}
// convert to list in next line, because we want the below #equals() check to also include the order:
List<String> oldSemanticDeps = new ArrayList<>(oldSnapshot.getDependencies());
List<String> newSemanticDeps = ((N4JSProjectConfig) pc).getSemanticDependencies().stream().map(ProjectDependency::getPackageName).collect(Collectors.toList());
if (!newSemanticDeps.equals(oldSemanticDeps)) {
ProjectConfigSnapshot newSnapshot = configSnapshotFactory.createProjectConfigSnapshot(pc);
if (!newSnapshot.equals(oldSnapshot)) {
projectsWithChangedSemanticDeps.add(newSnapshot);
}
}
}
if (!projectsWithChangedSemanticDeps.isEmpty()) {
changes = changes.merge(WorkspaceChanges.createProjectsChanged(projectsWithChangedSemanticDeps));
}
}
return changes;
}
use of org.eclipse.n4js.packagejson.projectDescription.ProjectDependency in project n4js by eclipse.
the class SemanticDependencySupplier method computeSemanticDependencies.
/**
* Actually computes the semantic dependencies, see {@link N4JSProjectConfig#getSemanticDependencies()}.
*/
public List<ProjectDependency> computeSemanticDependencies(DefinitionProjectMap definitionProjects, List<ProjectDependency> dependencies) {
Set<String> implicitDependencies = new LinkedHashSet<>();
Set<String> existingDependencies = new LinkedHashSet<>();
List<ProjectDependency> moveToTop = new ArrayList<>();
List<ProjectDependency> keepAtPosition = new ArrayList<>();
boolean sawDefinitionsOnly = true;
for (ProjectDependency dependency : dependencies) {
N4JSPackageName dependencyName = dependency.getN4JSProjectName();
existingDependencies.add(dependencyName.getRawName());
N4JSPackageName definitionProjectName = definitionProjects.getDefinitionProject(dependencyName);
if (definitionProjectName != null) {
implicitDependencies.add(definitionProjectName.getRawName());
}
boolean isDefinitionProject = definitionProjects.isDefinitionProject(dependencyName);
sawDefinitionsOnly &= isDefinitionProject;
if (isDefinitionProject) {
moveToTop.add(dependency);
} else {
keepAtPosition.add(dependency);
}
}
implicitDependencies.removeAll(existingDependencies);
if (implicitDependencies.isEmpty() && (sawDefinitionsOnly || moveToTop.isEmpty())) {
return dependencies;
}
List<ProjectDependency> result = new ArrayList<>(implicitDependencies.size() + moveToTop.size() + keepAtPosition.size());
result.addAll(moveToTop);
for (String implicitDependencyString : implicitDependencies) {
ProjectDependency implicitDependency = new ProjectDependency(implicitDependencyString, DependencyType.IMPLICIT, "", SemverUtils.createEmptyVersionRequirement());
result.add(implicitDependency);
}
result.addAll(keepAtPosition);
return result;
}
Aggregations