use of org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot in project n4js by eclipse.
the class N4JSWorkspaceConfig method didDependenciesChange.
/**
* Tells whether the dependencies of the given project changed w.r.t. the given old workspace config.
*/
private static boolean didDependenciesChange(ProjectConfigSnapshot projectConfig, WorkspaceConfigSnapshot oldWorkspaceConfig) {
ProjectConfigSnapshot oldProjectConfig = oldWorkspaceConfig.findProjectByID(projectConfig.getName());
N4JSProjectConfigSnapshot newCasted = (N4JSProjectConfigSnapshot) projectConfig;
N4JSProjectConfigSnapshot oldCasted = (N4JSProjectConfigSnapshot) oldProjectConfig;
return oldProjectConfig == null || !Objects.equals(oldCasted.getPackageName(), newCasted.getPackageName()) || !Objects.equals(((N4JSProjectConfigSnapshot) projectConfig).getDependencies(), ((N4JSProjectConfigSnapshot) oldProjectConfig).getDependencies());
}
use of org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot 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.ProjectConfigSnapshot 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.ProjectConfigSnapshot in project n4js by eclipse.
the class ProjectSetTest method testRemoveAndRecreate.
/**
* Tests the special cases described in {@link ProjectSet#update(Iterable, Iterable)}.
*/
@Test
public void testRemoveAndRecreate() {
String projectName = "TestProject";
URI rootA = URI.createFileURI("///some/folder");
URI rootB = URI.createFileURI("///another/folder");
N4JSProjectConfigSnapshot projectBelowRootA = createProjectConfig(rootA.appendSegment(projectName));
N4JSProjectConfigSnapshot projectBelowRootB = createProjectConfig(rootB.appendSegment(projectName));
ProjectSet set1 = new ProjectSet(Collections.singleton(projectBelowRootA));
ProjectSet set2 = set1.update(Collections.singleton(projectBelowRootB), Collections.singleton(projectName));
assertEquals(1, set2.size());
ProjectConfigSnapshot projectInSet2 = IterableExtensions.head(set2.getProjects());
assertEquals(rootB.appendSegment(projectName), projectInSet2.getPath());
assertEquals(projectBelowRootB, projectInSet2);
}
use of org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot in project n4js by eclipse.
the class ResourceTaskContext method updateIndex.
/**
* Update this context's internal index and trigger a refresh if required.
*/
protected void updateIndex(Collection<? extends IResourceDescription> changedDescs, Set<URI> removedURIs, WorkspaceConfigSnapshot newWorkspaceConfig, CancelIndicator cancelIndicator) {
WorkspaceConfigSnapshot oldWorkspaceConfig = workspaceConfig;
// update my cached state
List<IResourceDescription.Delta> allDeltas = createDeltas(changedDescs, removedURIs);
for (IResourceDescription.Delta delta : allDeltas) {
URI deltaURI = delta.getUri();
WorkspaceConfigSnapshot wcs = delta.getNew() != null ? newWorkspaceConfig : oldWorkspaceConfig;
ProjectConfigSnapshot project = wcs != null ? wcs.findProjectContaining(deltaURI) : null;
if (project != null) {
indexSnapshot.register(project.getName(), delta);
}
}
workspaceConfig = newWorkspaceConfig;
boolean workspaceConfigChanged = workspaceConfig != null ? !workspaceConfig.equals(oldWorkspaceConfig) : oldWorkspaceConfig != null;
if (workspaceConfigChanged) {
WorkspaceConfigAdapter.installWorkspaceConfig(mainResourceSet, workspaceConfig);
}
// refresh if I am affected by the changes
boolean isAffected = workspaceConfigChanged;
if (!isAffected) {
IResourceDescription.Manager rdm = getResourceDescriptionManager(mainURI);
IResourceDescription candidateDesc = indexSnapshot.getResourceDescription(mainURI);
if (rdm != null && candidateDesc != null) {
isAffected = isAffected(candidateDesc, rdm, allDeltas);
}
}
if (isAffected) {
refreshContext(cancelIndicator);
}
}
Aggregations