Search in sources :

Example 1 with ExternalProject

use of org.eclipse.n4js.utils.resources.ExternalProject in project n4js by eclipse.

the class N4JSBuilderParticipant method getGeneratorMarkers.

@Override
protected Map<OutputConfiguration, Iterable<IMarker>> getGeneratorMarkers(IProject builtProject, Collection<OutputConfiguration> outputConfigurations) throws CoreException {
    if (builtProject instanceof ExternalProject) {
        return emptyMap();
    }
    Map<OutputConfiguration, Iterable<IMarker>> generatorMarkers = newHashMap();
    for (OutputConfiguration config : outputConfigurations) {
        if (config.isCleanUpDerivedResources()) {
            List<IMarker> markers = Lists.newArrayList();
            for (IContainer container : getOutputs(builtProject, config)) {
                Iterables.addAll(markers, getDerivedResourceMarkers().findDerivedResourceMarkers(container, getGeneratorIdProvider().getGeneratorIdentifier()));
            }
            generatorMarkers.put(config, markers);
        }
    }
    return generatorMarkers;
}
Also used : ExternalProject(org.eclipse.n4js.utils.resources.ExternalProject) OutputConfiguration(org.eclipse.xtext.generator.OutputConfiguration) IMarker(org.eclipse.core.resources.IMarker) IContainer(org.eclipse.core.resources.IContainer)

Example 2 with ExternalProject

use of org.eclipse.n4js.utils.resources.ExternalProject in project n4js by eclipse.

the class N4JSProjectExplorerHelper method getProject.

/**
 * Returns with the corresponding {@link IN4JSProject N4JS project} for the given {@link IProject Eclipse project}
 * argument. Returns with {@code null} if
 * <ul>
 * <li>the {@code project} argument is {@code null} or</li>
 * <li>no {@link IN4JSProject#exists() existing} {@link IN4JSProject N4JS project} project can be found with the
 * desired project ID.</li>
 * </ul>
 *
 * @param project
 *            the searched project.
 * @return the N4JS project or {@code null} if such project does not exist.
 */
public IN4JSProject getProject(IProject project) {
    checkArgument(!(project instanceof ExternalProject), "Expected Eclipse workspace project. Got: " + project);
    if (null == project || !project.exists() || !project.isOpen()) {
        return null;
    }
    final String projectName = Strings.nullToEmpty(project.getName());
    final IN4JSProject n4Project = core.create(createPlatformResourceURI(projectName, true));
    if (null == n4Project || !n4Project.exists() || n4Project.isExternal()) {
        return null;
    }
    return n4Project;
}
Also used : ExternalProject(org.eclipse.n4js.utils.resources.ExternalProject) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject)

Example 3 with ExternalProject

use of org.eclipse.n4js.utils.resources.ExternalProject in project n4js by eclipse.

the class N4JSProjectExplorerHelper method getVirtualNodesForProject.

/**
 * Returns with an array of virtual {@link Node node} instances for the project that should be revealed in the
 * project explorer.
 *
 * @param project
 *            the workspace project.
 * @return an array of virtual nodes.
 */
public Node[] getVirtualNodesForProject(IProject project) {
    checkArgument(!(project instanceof ExternalProject), "Expected Eclipse workspace project. Got: " + project);
    if (null == project || !project.exists() || !project.isAccessible()) {
        return Node.EMPTY_NODES;
    }
    IN4JSProject n4Project = getProject(project);
    if (null == n4Project || !n4Project.exists() || n4Project.isExternal()) {
        return Node.EMPTY_NODES;
    }
    final Image image = ImageRef.LIB_PATH.asImage().get();
    final NamedNode rootNode = new NamedNode(project, "External Dependencies", image);
    Iterable<IN4JSProject> directDependencies = from(n4Project.getAllDirectDependencies()).filter(IN4JSProject.class);
    Iterable<IN4JSProject> runtimeLibraries = getExternalDependenciesOfType(directDependencies, RUNTIME_LIBRARY);
    if (!from(runtimeLibraries).isEmpty()) {
        Map<String, IN4JSProject> builtInRuntimeEnvironments = getBuiltInRuntimeEnvironments();
        Map<String, IN4JSProject> builtInRuntimeLibraries = getBuiltInRuntimeLibraries();
        Collection<IN4JSProject> libs = newHashSet();
        Collection<IN4JSProject> envs = newHashSet();
        for (IN4JSProject p : runtimeLibraries) {
            IN4JSProject dependency = builtInRuntimeLibraries.get(p.getProjectId());
            if (null != dependency) {
                libs.add(dependency);
            }
        }
        if (!libs.isEmpty()) {
            OUTER: for (IN4JSProject p : builtInRuntimeEnvironments.values()) {
                for (IN4JSProject providedLib : from(p.getProvidedRuntimeLibraries()).filter(IN4JSProject.class)) {
                    if (libs.contains(providedLib)) {
                        envs.add(p);
                        String extndedRuntimeEnvName = p.getExtendedRuntimeEnvironmentId().orNull();
                        if (null != extndedRuntimeEnvName) {
                            final IN4JSProject extension = builtInRuntimeEnvironments.get(extndedRuntimeEnvName);
                            if (null != extension) {
                                envs.add(extension);
                            }
                        }
                        continue OUTER;
                    }
                }
            }
        }
        NamedNode runtimeNode = new NamedNode(rootNode, "N4JS Runtime", image);
        if (!envs.isEmpty()) {
            NamedNode envsNode = new NamedNode(runtimeNode, "Runtime Environments", image);
            envsNode.addChild(from(envs).transform(p -> new BuiltInProjectNode(envsNode, p)));
            runtimeNode.addChild(envsNode);
        }
        if (!libs.isEmpty()) {
            NamedNode libsNode = new NamedNode(runtimeNode, "Runtime Libraries", image);
            libsNode.addChild(from(libs).transform(p -> new BuiltInProjectNode(libsNode, p)));
            runtimeNode.addChild(libsNode);
        }
        if (!Arrays2.isEmpty(runtimeNode.getChildren())) {
            rootNode.addChild(runtimeNode);
        }
    }
    Map<String, IN4JSProject> langProjects = getAvailableLangProjects();
    Map<String, IN4JSProject> mangelhaftProjects = getAvailableMangelhaftProjects();
    Map<String, IN4JSProject> npmProjects = getAvailableNpmProjects();
    Collection<IN4JSProject> requiredLangLibs = newHashSet();
    Collection<IN4JSProject> requiredMangelhaftLibs = newHashSet();
    Collection<IN4JSProject> requiredNpmLibs = newHashSet();
    for (IN4JSProject directDependecy : directDependencies) {
        if (directDependecy.exists() && directDependecy.isExternal()) {
            IN4JSProject externalDepenency = mangelhaftProjects.get(directDependecy.getProjectId());
            if (null != externalDepenency) {
                requiredMangelhaftLibs.add(externalDepenency);
            } else {
                externalDepenency = npmProjects.get(directDependecy.getProjectId());
                if (null != externalDepenency) {
                    requiredNpmLibs.add(externalDepenency);
                } else {
                    externalDepenency = langProjects.get(directDependecy.getProjectId());
                    if (null != externalDepenency) {
                        requiredLangLibs.add(externalDepenency);
                    }
                }
            }
        }
    }
    if (!requiredLangLibs.isEmpty()) {
        NamedNode langNode = new NamedNode(rootNode, EXTERNAL_LIBRARY_NAMES.get(LANG_CATEGORY), image);
        langNode.addChild(from(requiredLangLibs).transform(p -> new BuiltInProjectNode(langNode, p)));
        rootNode.addChild(langNode);
    }
    if (!requiredMangelhaftLibs.isEmpty()) {
        NamedNode mangNode = new NamedNode(rootNode, EXTERNAL_LIBRARY_NAMES.get(MANGELHAFT_CATEGORY), image);
        mangNode.addChild(from(requiredMangelhaftLibs).transform(p -> new BuiltInProjectNode(mangNode, p)));
        rootNode.addChild(mangNode);
    }
    if (!requiredNpmLibs.isEmpty()) {
        NamedNode npmNode = new NamedNode(rootNode, EXTERNAL_LIBRARY_NAMES.get(NPM_CATEGORY), image);
        npmNode.addChild(from(requiredNpmLibs).transform(p -> new BuiltInProjectNode(npmNode, p)));
        rootNode.addChild(npmNode);
    }
    return Arrays2.isEmpty(rootNode.getChildren()) ? new Node[0] : new Node[] { rootNode };
}
Also used : IFolder(org.eclipse.core.resources.IFolder) ExternalLibraryWorkspace(org.eclipse.n4js.external.ExternalLibraryWorkspace) LANG_CATEGORY(org.eclipse.n4js.external.libraries.ExternalLibrariesActivator.LANG_CATEGORY) Inject(com.google.inject.Inject) Image(org.eclipse.swt.graphics.Image) Maps.uniqueIndex(com.google.common.collect.Maps.uniqueIndex) MANGELHAFT_CATEGORY(org.eclipse.n4js.external.libraries.ExternalLibrariesActivator.MANGELHAFT_CATEGORY) IN4JSCore(org.eclipse.n4js.projectModel.IN4JSCore) Arrays2(org.eclipse.n4js.utils.collections.Arrays2) Strings(com.google.common.base.Strings) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) RUNTIME_ENVIRONMENT(org.eclipse.n4js.n4mf.ProjectType.RUNTIME_ENVIRONMENT) IProject(org.eclipse.core.resources.IProject) FluentIterable.from(com.google.common.collect.FluentIterable.from) Map(java.util.Map) EXTERNAL_LIBRARIES_SUPPLIER(org.eclipse.n4js.external.libraries.ExternalLibrariesActivator.EXTERNAL_LIBRARIES_SUPPLIER) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) IExternalResource(org.eclipse.n4js.utils.resources.IExternalResource) URI(java.net.URI) EnumSet(java.util.EnumSet) Collection(java.util.Collection) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) RUNTIME_CATEGORY(org.eclipse.n4js.external.libraries.ExternalLibrariesActivator.RUNTIME_CATEGORY) EXTERNAL_LIBRARY_NAMES(org.eclipse.n4js.external.libraries.ExternalLibrariesActivator.EXTERNAL_LIBRARY_NAMES) ExternalProject(org.eclipse.n4js.utils.resources.ExternalProject) URI.createFileURI(org.eclipse.emf.common.util.URI.createFileURI) ProjectType(org.eclipse.n4js.n4mf.ProjectType) URI.createPlatformResourceURI(org.eclipse.emf.common.util.URI.createPlatformResourceURI) Collections(java.util.Collections) ImageRef(org.eclipse.n4js.ui.ImageDescriptorCache.ImageRef) NPM_CATEGORY(org.eclipse.n4js.external.libraries.ExternalLibrariesActivator.NPM_CATEGORY) RUNTIME_LIBRARY(org.eclipse.n4js.n4mf.ProjectType.RUNTIME_LIBRARY) Singleton(com.google.inject.Singleton) ExternalProject(org.eclipse.n4js.utils.resources.ExternalProject) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) Image(org.eclipse.swt.graphics.Image)

Example 4 with ExternalProject

use of org.eclipse.n4js.utils.resources.ExternalProject in project n4js by eclipse.

the class ExternalProjectCacheLoader method load.

@Override
public Optional<Pair<N4JSExternalProject, ProjectDescription>> load(final URI rootLocation) throws Exception {
    ProjectDescription projectDescription = packageManager.loadManifestFromProjectRoot(rootLocation);
    if (null != projectDescription) {
        File projectRoot = new File(rootLocation.toFileString());
        ExternalProject p = new ExternalProject(projectRoot, NATURE_ID, BUILDER_ID);
        IN4JSProject pp = new N4JSEclipseProject(p, rootLocation, model);
        N4JSExternalProject ppp = new N4JSExternalProject(projectRoot, pp);
        return Optional.of(Tuples.create(ppp, projectDescription));
    }
    return Optional.absent();
}
Also used : N4JSExternalProject(org.eclipse.n4js.external.N4JSExternalProject) N4JSExternalProject(org.eclipse.n4js.external.N4JSExternalProject) ExternalProject(org.eclipse.n4js.utils.resources.ExternalProject) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) ProjectDescription(org.eclipse.n4js.n4mf.ProjectDescription) File(java.io.File)

Example 5 with ExternalProject

use of org.eclipse.n4js.utils.resources.ExternalProject in project n4js by eclipse.

the class N4MFProjectDependencyStrategy method getProjectDependencies.

@Override
public List<IProject> getProjectDependencies(final IProject project) {
    final IN4JSEclipseProject n4Project = core.create(project).orNull();
    if (null != n4Project) {
        // This covers project dependencies, tests (if any), required REs and required RLs and APIs.
        final Collection<? extends IN4JSEclipseProject> dependencies = n4Project.getDependenciesAndImplementedApis();
        // This is for the provided runtime libraries.
        final Collection<IN4JSEclipseProject> providedRuntimeLibs = from(n4Project.getProvidedRuntimeLibraries()).filter(IN4JSEclipseProject.class).toList();
        // This is for the extended RE, if specified.
        final IN4JSSourceContainerAware srcContainerAware = n4Project.getExtendedRuntimeEnvironment().orNull();
        final IN4JSEclipseProject extendedRE = srcContainerAware instanceof IN4JSEclipseProject ? (IN4JSEclipseProject) srcContainerAware : null;
        int projectCount = dependencies.size() + providedRuntimeLibs.size();
        if (null != extendedRE) {
            projectCount++;
        }
        final IProject[] projects = new IProject[projectCount];
        int i = 0;
        for (final IN4JSEclipseProject dependency : dependencies) {
            projects[i++] = dependency.getProject();
        }
        for (final IN4JSEclipseProject providedRuntimeLib : providedRuntimeLibs) {
            projects[i++] = providedRuntimeLib.getProject();
        }
        if (null != extendedRE) {
            projects[i] = extendedRE.getProject();
        }
        return from(asList(projects)).filter(p -> !(p instanceof ExternalProject)).toList();
    } else {
        return emptyList();
    }
}
Also used : List(java.util.List) IProject(org.eclipse.core.resources.IProject) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) IN4JSEclipseProject(org.eclipse.n4js.ui.projectModel.IN4JSEclipseProject) FluentIterable.from(com.google.common.collect.FluentIterable.from) Collection(java.util.Collection) Inject(com.google.inject.Inject) IN4JSEclipseCore(org.eclipse.n4js.ui.projectModel.IN4JSEclipseCore) ExternalProject(org.eclipse.n4js.utils.resources.ExternalProject) IN4JSSourceContainerAware(org.eclipse.n4js.projectModel.IN4JSSourceContainerAware) IN4JSEclipseProject(org.eclipse.n4js.ui.projectModel.IN4JSEclipseProject) ExternalProject(org.eclipse.n4js.utils.resources.ExternalProject) IN4JSSourceContainerAware(org.eclipse.n4js.projectModel.IN4JSSourceContainerAware) IProject(org.eclipse.core.resources.IProject)

Aggregations

ExternalProject (org.eclipse.n4js.utils.resources.ExternalProject)11 IProject (org.eclipse.core.resources.IProject)5 File (java.io.File)4 URI (org.eclipse.emf.common.util.URI)4 N4JSExternalProject (org.eclipse.n4js.external.N4JSExternalProject)4 IFile (org.eclipse.core.resources.IFile)3 IN4JSProject (org.eclipse.n4js.projectModel.IN4JSProject)3 FluentIterable.from (com.google.common.collect.FluentIterable.from)2 Inject (com.google.inject.Inject)2 URI (java.net.URI)2 Collection (java.util.Collection)2 IContainer (org.eclipse.core.resources.IContainer)2 IFolder (org.eclipse.core.resources.IFolder)2 CoreException (org.eclipse.core.runtime.CoreException)2 ProjectDescription (org.eclipse.n4js.n4mf.ProjectDescription)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Strings (com.google.common.base.Strings)1 Maps.uniqueIndex (com.google.common.collect.Maps.uniqueIndex)1 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 Singleton (com.google.inject.Singleton)1