Search in sources :

Example 6 with N4JSExternalProject

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;
}
Also used : N4JSExternalProject(org.eclipse.n4js.external.N4JSExternalProject) URI(org.eclipse.emf.common.util.URI) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Example 7 with N4JSExternalProject

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);
}
Also used : N4JSExternalProject(org.eclipse.n4js.external.N4JSExternalProject) SubMonitor(org.eclipse.core.runtime.SubMonitor) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject) HashSet(java.util.HashSet) Sets.newHashSet(com.google.common.collect.Sets.newHashSet)

Example 8 with N4JSExternalProject

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);
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) N4JSProject(org.eclipse.n4js.internal.N4JSProject) N4JSExternalProject(org.eclipse.n4js.external.N4JSExternalProject) URI(org.eclipse.emf.common.util.URI)

Example 9 with N4JSExternalProject

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);
}
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)

Example 10 with N4JSExternalProject

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);
}
Also used : N4JSExternalProject(org.eclipse.n4js.external.N4JSExternalProject) SubMonitor(org.eclipse.core.runtime.SubMonitor) IProject(org.eclipse.core.resources.IProject)

Aggregations

N4JSExternalProject (org.eclipse.n4js.external.N4JSExternalProject)10 File (java.io.File)5 URI (org.eclipse.emf.common.util.URI)5 IProject (org.eclipse.core.resources.IProject)4 SubMonitor (org.eclipse.core.runtime.SubMonitor)4 ProjectDescription (org.eclipse.n4js.n4mf.ProjectDescription)4 Optional (com.google.common.base.Optional)2 IFile (org.eclipse.core.resources.IFile)2 IN4JSProject (org.eclipse.n4js.projectModel.IN4JSProject)2 ExternalProject (org.eclipse.n4js.utils.resources.ExternalProject)2 FluentIterable.from (com.google.common.collect.FluentIterable.from)1 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)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 HashSet (java.util.HashSet)1 Logger (org.apache.log4j.Logger)1 IResource (org.eclipse.core.resources.IResource)1