use of org.eclipse.n4js.external.N4JSExternalProject in project n4js by eclipse.
the class ProjectStateChangeListener method visit.
boolean visit(IResourceDelta delta) {
IResource resource = delta.getResource();
if (resource instanceof IProject) {
IProject project = (IProject) resource;
String name = project.getName();
N4JSExternalProject externalProject = projectProvider.getProject(name);
if (null != externalProject && externalProject.exists()) {
URI uri = URIUtils.convert(externalProject);
boolean isN4Project = packageManager.isN4ProjectRoot(uri);
if (isN4Project) {
if (CHANGED == delta.getKind() && (delta.getFlags() & OPEN) != 0) {
// Workspace project close/open
if (project.isOpen()) {
toClean.add(externalProject);
} else {
toBuild.add(externalProject);
}
} else if (REMOVED == delta.getKind()) {
// Workspace project deletion
toBuild.add(externalProject);
} else if (ADDED == delta.getKind()) {
// Workspace project creation
toClean.add(externalProject);
}
}
}
}
return true;
}
use of org.eclipse.n4js.external.N4JSExternalProject in project n4js by eclipse.
the class EclipseExternalLibraryWorkspace method registerProjectsInternal.
private RegisterResult registerProjectsInternal(NpmProjectAdaptionResult result, IProgressMonitor monitor, boolean triggerCleanbuild) {
Collection<IProject> extPrjCleaned = null;
Collection<IProject> extPrjBuilt = null;
if (!ExternalLibrariesActivator.requiresInfrastructureForLibraryManager()) {
logger.warn("Built-in libraries and NPM support are disabled.");
}
checkState(result.isOK(), "Expected: OK, but actual was: " + result);
SubMonitor subMonitor = convert(monitor, 3);
// Clean projects.
Set<N4JSExternalProject> projectsToClean = from(result.getToBeBuilt().getToBeDeleted()).transform(uri -> projectProvider.getProject(new File(uri).getName())).filter(notNull()).toSet();
if (!Iterables.isEmpty(projectsToClean)) {
extPrjCleaned = builder.clean(projectsToClean, subMonitor.newChild(1));
}
subMonitor.worked(1);
// Update internal state.
updateState();
// Rebuild whole external workspace. Filter out projects that are present in the Eclipse workspace (if any).
Collection<N4JSExternalProject> projectsToBuild = getExternalProjects(result);
Set<N4JSExternalProject> allProjectsToBuild = new HashSet<>();
allProjectsToBuild.addAll(projectsToBuild);
allProjectsToBuild.addAll(newHashSet(collector.getExtProjectsDependendingOn(projectsToBuild)));
allProjectsToBuild.addAll(newHashSet(collector.getExtProjectsDependendingOn(projectsToClean)));
// Also includes projects that exist already in the index, but are shadowed.
if (!Iterables.isEmpty(allProjectsToBuild)) {
extPrjBuilt = builder.build(allProjectsToBuild, subMonitor.newChild(1));
}
subMonitor.worked(1);
Set<IProject> wsPrjToRebuild = newHashSet();
if (triggerCleanbuild) {
Set<N4JSExternalProject> affectedProjects = new HashSet<>();
affectedProjects.addAll(newHashSet(projectsToClean));
affectedProjects.addAll(newHashSet(allProjectsToBuild));
wsPrjToRebuild.addAll(newHashSet(collector.getWSProjectsDependendingOn(affectedProjects)));
scheduler.scheduleBuildIfNecessary(wsPrjToRebuild);
}
return new RegisterResult(extPrjCleaned, extPrjBuilt, wsPrjToRebuild);
}
use of org.eclipse.n4js.external.N4JSExternalProject in project n4js by eclipse.
the class BuildOrderComputer method getBuildOrder.
/**
* Convenience method for {@link #getBuildOrder(N4JSProject[])}
*/
public VertexOrder<IN4JSProject> getBuildOrder(N4JSExternalProject[] projects) {
N4JSProject[] n4jsPrjs = new N4JSProject[projects.length];
for (int i = 0; i < projects.length; i++) {
N4JSExternalProject project = projects[i];
URI locationURI = URIUtils.convert(project);
N4JSProject prjDependency = (N4JSProject) core.findProject(locationURI).orNull();
n4jsPrjs[i] = prjDependency;
}
return getBuildOrder(n4jsPrjs);
}
use of org.eclipse.n4js.external.N4JSExternalProject in project n4js by eclipse.
the class ExternalLibrariesReloadHelper method reloadLibrariesInternal.
private void reloadLibrariesInternal(final boolean refreshNpmDefinitions, final IProgressMonitor monitor) throws InvocationTargetException {
final SubMonitor subMonitor = SubMonitor.convert(monitor, refreshNpmDefinitions ? 2 : 1);
if (monitor instanceof Cancelable) {
// No cancel is allowed from now on.
((Cancelable) monitor).setCancelable(false);
}
if (monitor.isCanceled()) {
return;
}
// Refresh the type definitions for the npm packages if required.
if (refreshNpmDefinitions) {
final IStatus refreshStatus = npmManager.refreshInstalledNpmPackages(subMonitor.newChild(1));
if (!refreshStatus.isOK()) {
throw new InvocationTargetException(new CoreException(refreshStatus));
}
}
// Make sure to rebuild only those external ones that are not in the workspace.
// Get all accessible workspace projects...
final Collection<String> workspaceProjectNames = from(asList(getWorkspace().getRoot().getProjects())).filter(p -> p.isAccessible()).transform(p -> p.getName()).toSet();
// And build all those externals that has no corresponding workspace project.
final Collection<N4JSExternalProject> toBuild = from(projectProvider.getProjects()).filter(p -> !workspaceProjectNames.contains(p.getName())).toList();
final Collection<IProject> workspaceProjectsToRebuild = collector.getWSProjectsDependendingOn(toBuild);
builderHelper.build(toBuild, subMonitor.newChild(1));
scheduler.scheduleBuildIfNecessary(workspaceProjectsToRebuild);
}
use of org.eclipse.n4js.external.N4JSExternalProject in project n4js by eclipse.
the class ExternalIndexUpdater method buildAddedLocations.
/**
* Adds projects to Index that are in a added location or depend on removed/added projects
*/
private void buildAddedLocations(Set<URI> addedLocations, IProgressMonitor monitor) {
Collection<N4JSExternalProject> addedProjects = externalWorkspace.getProjectsIn(addedLocations);
SubMonitor subMonitor = convert(monitor, 2);
// Build external projects that depend on added projects. (only non-user-workspace)
Set<N4JSExternalProject> extProjectsToBuild = newHashSet();
extProjectsToBuild.addAll(extProjectsDependingOnRemovedProjects);
extProjectsToBuild.addAll(addedProjects);
extProjectsToBuild.addAll(collector.getExtProjectsDependendingOn(addedProjects));
builder.build(extProjectsToBuild, subMonitor.newChild(1));
subMonitor.worked(1);
// Schedule rebuild of workspace projects
Set<IProject> wsProjectsToRebuild = newHashSet();
wsProjectsToRebuild.addAll(wsProjectsDependingOnRemovedProjects);
wsProjectsToRebuild.addAll(collector.getWSProjectsDependendingOn(addedProjects));
wsProjectsToRebuild.addAll(collector.getWSProjectsDependendingOn(extProjectsToBuild));
scheduler.scheduleBuildIfNecessary(wsProjectsToRebuild);
subMonitor.worked(1);
}
Aggregations