use of org.eclipse.n4js.xtext.workspace.XIProjectConfig in project n4js by eclipse.
the class N4JSWorkspaceConfig method detectAddedRemovedProjects.
private WorkspaceChanges detectAddedRemovedProjects(WorkspaceConfigSnapshot oldWorkspaceConfig, boolean alsoDetectChangedProjects) {
// update all projects
reloadAllProjectInformationFromDisk();
// detect project additions, removals (and also changes, iff 'alsoDetectChangedProjects' is set)
Map<URI, ProjectConfigSnapshot> oldProjectsMap = IterableExtensions.toMap(oldWorkspaceConfig.getProjects(), ProjectConfigSnapshot::getPath);
Map<URI, N4JSProjectConfig> newProjectsMap = IterableExtensions.toMap(getProjects(), XIProjectConfig::getPath);
WorkspaceChanges changes = new WorkspaceChanges();
for (URI uri : Sets.union(oldProjectsMap.keySet(), newProjectsMap.keySet())) {
boolean isOld = oldProjectsMap.containsKey(uri);
boolean isNew = newProjectsMap.containsKey(uri);
if (isOld && !isNew) {
// deleted
changes = changes.merge(WorkspaceChanges.createProjectRemoved(oldProjectsMap.get(uri)));
} else if (!isOld && isNew) {
// added
ProjectConfigSnapshot newPC = configSnapshotFactory.createProjectConfigSnapshot(newProjectsMap.get(uri));
changes = changes.merge(WorkspaceChanges.createProjectAdded(newPC));
} else if (isOld && isNew) {
// check name change
String oldPackageName = ((N4JSProjectConfigSnapshot) oldProjectsMap.get(uri)).getPackageName();
String newPackageName = newProjectsMap.get(uri).getPackageName();
if (Objects.equals(oldPackageName, newPackageName)) {
// no change
if (alsoDetectChangedProjects) {
ProjectConfigSnapshot oldPC = oldProjectsMap.get(uri);
ProjectConfigSnapshot newPC = configSnapshotFactory.createProjectConfigSnapshot(newProjectsMap.get(uri));
changes = changes.merge(N4JSProjectConfig.computeChanges(oldPC, newPC));
}
} else {
// names changed
ProjectConfigSnapshot newPC = configSnapshotFactory.createProjectConfigSnapshot(newProjectsMap.get(uri));
changes = changes.merge(WorkspaceChanges.createProjectAdded(newPC));
changes = changes.merge(WorkspaceChanges.createProjectRemoved(oldProjectsMap.get(uri)));
}
}
}
return changes;
}
use of org.eclipse.n4js.xtext.workspace.XIProjectConfig in project n4js by eclipse.
the class N4JSWorkspaceConfig method doMinimalUpdate.
/**
* Based on the given dirty/deleted files, performs a workspace update with as few computations as possible.
*/
private WorkspaceChanges doMinimalUpdate(WorkspaceConfigSnapshot oldWorkspaceConfig, Set<URI> dirtyFiles, Set<URI> deletedFiles) {
WorkspaceChanges changes = WorkspaceChanges.createUrisRemovedAndChanged(deletedFiles, dirtyFiles);
boolean needToDetectAddedRemovedProjects = false;
for (URI changedResource : Iterables.concat(dirtyFiles, deletedFiles)) {
String lastSegment = changedResource.lastSegment();
boolean isPackageJson = lastSegment != null && lastSegment.equals(N4JSGlobals.PACKAGE_JSON);
if (!isPackageJson) {
continue;
}
ProjectConfigSnapshot oldProject = oldWorkspaceConfig.findProjectContaining(changedResource);
XIProjectConfig project = oldProject != null ? findProjectByName(oldProject.getName()) : null;
if (oldProject != null && project != null) {
// an existing project was modified (maybe removed)
changes = changes.merge(((N4JSProjectConfig) project).update(oldWorkspaceConfig, changedResource, configSnapshotFactory));
if (((N4JSProjectConfig) project).isWorkspaceProject()) {
needToDetectAddedRemovedProjects = true;
}
} else {
// a new project was created
needToDetectAddedRemovedProjects = true;
}
}
needToDetectAddedRemovedProjects |= isProjectDiscoveryRequired(changes, oldWorkspaceConfig);
if (needToDetectAddedRemovedProjects) {
changes = changes.merge(detectAddedRemovedProjects(oldWorkspaceConfig, false));
}
return changes;
}
use of org.eclipse.n4js.xtext.workspace.XIProjectConfig 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;
}
Aggregations