Search in sources :

Example 1 with Cancelable

use of org.eclipse.n4js.utils.Cancelable 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);
}
Also used : ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) Job(org.eclipse.core.runtime.jobs.Job) ResourcesPlugin.getWorkspace(org.eclipse.core.resources.ResourcesPlugin.getWorkspace) SubMonitor(org.eclipse.core.runtime.SubMonitor) Collection(java.util.Collection) N4JSExternalProject(org.eclipse.n4js.external.N4JSExternalProject) Inject(com.google.inject.Inject) CoreException(org.eclipse.core.runtime.CoreException) NpmManager(org.eclipse.n4js.external.NpmManager) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Logger(org.apache.log4j.Logger) IStatus(org.eclipse.core.runtime.IStatus) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) Cancelable(org.eclipse.n4js.utils.Cancelable) IProject(org.eclipse.core.resources.IProject) Arrays.asList(java.util.Arrays.asList) FluentIterable.from(com.google.common.collect.FluentIterable.from) RebuildWorkspaceProjectsScheduler(org.eclipse.n4js.external.RebuildWorkspaceProjectsScheduler) ExternalProjectsCollector(org.eclipse.n4js.external.ExternalProjectsCollector) Singleton(com.google.inject.Singleton) IStatus(org.eclipse.core.runtime.IStatus) N4JSExternalProject(org.eclipse.n4js.external.N4JSExternalProject) CoreException(org.eclipse.core.runtime.CoreException) SubMonitor(org.eclipse.core.runtime.SubMonitor) Cancelable(org.eclipse.n4js.utils.Cancelable) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProject(org.eclipse.core.resources.IProject)

Aggregations

FluentIterable.from (com.google.common.collect.FluentIterable.from)1 Inject (com.google.inject.Inject)1 Singleton (com.google.inject.Singleton)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1 Logger (org.apache.log4j.Logger)1 IProject (org.eclipse.core.resources.IProject)1 ResourcesPlugin.getWorkspace (org.eclipse.core.resources.ResourcesPlugin.getWorkspace)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)1 Job (org.eclipse.core.runtime.jobs.Job)1 ExternalProjectsCollector (org.eclipse.n4js.external.ExternalProjectsCollector)1 N4JSExternalProject (org.eclipse.n4js.external.N4JSExternalProject)1 NpmManager (org.eclipse.n4js.external.NpmManager)1 RebuildWorkspaceProjectsScheduler (org.eclipse.n4js.external.RebuildWorkspaceProjectsScheduler)1