Search in sources :

Example 26 with IN4JSProject

use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.

the class RuntimeEnvironmentsHelper method containsAllCompatible.

/**
 * Compares two provided lists of {@link IN4JSProject}. Assumes both contain instances of type
 * {@link ProjectType#RUNTIME_ENVIRONMENT}. Checks if either all elements of latter list are contained in first one,
 * or if all elements of latter one are compatible (are in extend chain) of elements of the first one. If this check
 * holds returns true, otherwise false (also when either of the lists is empty)
 *
 * @param runnerEnvironments
 *            lists which must contain (might be indirectly via extend chain) elements of latter list
 * @param requiredEnvironments
 *            lists that is checked if it is supported by first one
 * @return true if all elements of latter list are (directly or indirectly) compatible with elements of the first
 *         list.
 */
public boolean containsAllCompatible(List<RuntimeEnvironment> runnerEnvironments, List<RuntimeEnvironment> requiredEnvironments) {
    if (runnerEnvironments.isEmpty() || requiredEnvironments.isEmpty()) {
        LOGGER.debug("cannot compare empty runtime environments lists");
        return false;
    }
    if (runnerEnvironments.containsAll(requiredEnvironments))
        return true;
    // check compatible / extend feature
    boolean result = true;
    List<IN4JSProject> allRuntimeEnvironments = from(getAllProjects()).filter(p -> isRuntimeEnvironemnt(p)).toList();
    Map<IN4JSProject, List<String>> reExtendedEnvironments = allRuntimeEnvironments.stream().map(re -> getExtendedRuntimeEnvironmentsNames(re, allRuntimeEnvironments)).collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()));
    // if runnerEnvironments (first param) would be single IN4JSProject (instead of collection)
    // code below could be simplified
    Iterator<RuntimeEnvironment> iterRuntimeEnvironment = runnerEnvironments.iterator();
    while (result && iterRuntimeEnvironment.hasNext()) {
        RuntimeEnvironment re = iterRuntimeEnvironment.next();
        List<IN4JSProject> listExtendedEnvironments = reExtendedEnvironments.keySet().stream().filter(p -> p.getProjectId().equals(re.getProjectId())).collect(Collectors.toList());
        if (listExtendedEnvironments.size() != 1) {
            LOGGER.debug("Multiple projects with name " + re.getProjectId() + " : " + listExtendedEnvironments.stream().map(p -> p.getProjectId()).reduce(new String(), (String r, String e) -> r += ", " + e));
            LOGGER.error("Cannot obtain project for name " + re.getProjectId());
            return false;
        }
        IN4JSProject extendedRuntimeEnvironment = listExtendedEnvironments.get(0);
        List<String> listExtendedEnvironemntsNames = reExtendedEnvironments.get(extendedRuntimeEnvironment);
        result = result && requiredEnvironments.stream().map(bre -> {
            return bre.getProjectId();
        }).allMatch(breName -> listExtendedEnvironemntsNames.contains(breName));
    }
    return result;
}
Also used : InsolvableRuntimeEnvironmentException(org.eclipse.n4js.runner.exceptions.InsolvableRuntimeEnvironmentException) Inject(com.google.inject.Inject) IN4JSCore(org.eclipse.n4js.projectModel.IN4JSCore) IN4JSSourceContainerAware(org.eclipse.n4js.projectModel.IN4JSSourceContainerAware) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Logger(org.apache.log4j.Logger) Optional(com.google.common.base.Optional) FluentIterable.from(com.google.common.collect.FluentIterable.from) Map(java.util.Map) RuntimeEnvironment(org.eclipse.n4js.runner.extension.RuntimeEnvironment) SoureContainerAwareDependencyTraverser(org.eclipse.n4js.validation.helper.SoureContainerAwareDependencyTraverser) Iterator(java.util.Iterator) Predicate(java.util.function.Predicate) Collection(java.util.Collection) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) Set(java.util.Set) Collectors(java.util.stream.Collectors) ProjectType(org.eclipse.n4js.n4mf.ProjectType) DependencyCycleDetectedException(org.eclipse.n4js.runner.exceptions.DependencyCycleDetectedException) AbstractMap(java.util.AbstractMap) List(java.util.List) IN4JSArchive(org.eclipse.n4js.projectModel.IN4JSArchive) Entry(java.util.Map.Entry) Logger.getLogger(org.apache.log4j.Logger.getLogger) RuntimeEnvironment(org.eclipse.n4js.runner.extension.RuntimeEnvironment) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) ArrayList(java.util.ArrayList) List(java.util.List)

Example 27 with IN4JSProject

use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.

the class RuntimeEnvironmentsHelper method recursiveProvidedRuntimeLibrariesCollector.

/**
 * Maps passed collection of {@link IN4JSSourceContainerAware} to list of {@link IN4JSProject}, that is instances of
 * {@link IN4JSProject} project are returned as they are, while instances of {@link IN4JSArchive} have contained
 * project extracted. For each result of that transformation, examines its
 * {@link IN4JSProject#getProvidedRuntimeLibraries()} to check if they pass predicate test. Instances that do are
 * stored in the passed collection.
 *
 * Calls itself recursively on each processed element, accumulating results in collection passed along call chains.
 *
 * @param runtimeLibraries
 *            list of source containers to analyze (usually of type {@link ProjectType#RUNTIME_LIBRARY})
 * @param collection
 *            where provided runtime libraries are collected
 * @param predicate
 *            to test if provided project is of type {@link ProjectType#RUNTIME_LIBRARY}
 */
private void recursiveProvidedRuntimeLibrariesCollector(com.google.common.collect.ImmutableList<? extends IN4JSSourceContainerAware> runtimeLibraries, Collection<IN4JSProject> collection, Predicate<IN4JSProject> predicate) {
    runtimeLibraries.forEach(runtimeLibrary -> {
        IN4JSProject project = (extractProject(runtimeLibrary));
        if (predicate.test(project))
            collection.add(project);
        recursiveProvidedRuntimeLibrariesCollector(project.getProvidedRuntimeLibraries(), collection, predicate);
    });
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject)

Example 28 with IN4JSProject

use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.

the class RuntimeEnvironmentsHelper method getEnvironemntWithAncestorsRecursive.

private void getEnvironemntWithAncestorsRecursive(IN4JSProject project, Set<IN4JSProject> environemtns) {
    if (!project.getProjectType().equals(ProjectType.RUNTIME_ENVIRONMENT)) {
        return;
    }
    Optional<IN4JSSourceContainerAware> maybePArent = project.getExtendedRuntimeEnvironment();
    if (maybePArent.isPresent()) {
        IN4JSProject parent = (IN4JSProject) maybePArent.get();
        environemtns.add(parent);
        getEnvironemntWithAncestorsRecursive(parent, environemtns);
    }
    return;
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) IN4JSSourceContainerAware(org.eclipse.n4js.projectModel.IN4JSSourceContainerAware)

Example 29 with IN4JSProject

use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.

the class RunnerHelper method recursiveExtendedREsCollector.

/**
 * Collects transitive collection of project extended RuntimeEnvironemnts
 *
 * @see RuntimeEnvironmentsHelper#recursiveDependencyCollector
 */
public void recursiveExtendedREsCollector(IN4JSSourceContainerAware sourceContainer, Collection<IN4JSProject> addHere, Iterable<IN4JSProject> projects) {
    final IN4JSProject project = extractProject(sourceContainer);
    if (project.getProjectType().equals(ProjectType.RUNTIME_ENVIRONMENT)) {
        addHere.add(project);
        // TODO RLs can extend each other, should we use recursive RL deps collector?
        // if RLs extend each other and are provided by REs in hierarchy we will collect them anyway
        // if RLs extend each other but are from independent REs, that is and error?
        project.getProvidedRuntimeLibraries().forEach(rl -> addHere.add(extractProject(rl)));
        Optional<String> ep = project.getExtendedRuntimeEnvironmentId();
        Optional<IN4JSProject> extendedRE = Optional.absent();
        if (ep.isPresent()) {
            extendedRE = findRuntimeEnvironemtnWithName(ep.get(), projects);
        }
        if (extendedRE.isPresent()) {
            IN4JSProject e = extendedRE.get();
            recursiveExtendedREsCollector(e, addHere, projects);
        }
    }
}
Also used : IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject)

Example 30 with IN4JSProject

use of org.eclipse.n4js.projectModel.IN4JSProject in project n4js by eclipse.

the class N4JSAllContainersState method tryValidateManifest.

private void tryValidateManifest(final IResourceDelta delta) {
    final String fullPath = delta.getFullPath().toString();
    final URI folderUri = URI.createPlatformResourceURI(fullPath, true);
    final IN4JSProject project = core.findProject(folderUri).orNull();
    if (null != project && project.exists()) {
        final URI manifestLocation = project.getManifestLocation().orNull();
        if (null != manifestLocation) {
            final IFile manifest = delta.getResource().getProject().getFile(N4MF_MANIFEST);
            final ResourceSet resourceSet = core.createResourceSet(Optional.of(project));
            final Resource resource = resourceSet.getResource(manifestLocation, true);
            final Job job = Job.create("", monitor -> {
                validatorExtension.updateValidationMarkers(manifest, resource, ALL, monitor);
                return OK_STATUS;
            });
            job.setPriority(INTERACTIVE);
            job.schedule();
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IN4JSProject(org.eclipse.n4js.projectModel.IN4JSProject) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Job(org.eclipse.core.runtime.jobs.Job) URI(org.eclipse.emf.common.util.URI)

Aggregations

IN4JSProject (org.eclipse.n4js.projectModel.IN4JSProject)93 URI (org.eclipse.emf.common.util.URI)32 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)13 List (java.util.List)11 Inject (com.google.inject.Inject)9 Map (java.util.Map)9 IProject (org.eclipse.core.resources.IProject)9 IN4JSCore (org.eclipse.n4js.projectModel.IN4JSCore)9 Optional (com.google.common.base.Optional)7 File (java.io.File)7 Collection (java.util.Collection)7 HashSet (java.util.HashSet)7 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 Set (java.util.Set)6 Collectors (java.util.stream.Collectors)6 IOException (java.io.IOException)5 IN4JSArchive (org.eclipse.n4js.projectModel.IN4JSArchive)5 IN4JSSourceContainer (org.eclipse.n4js.projectModel.IN4JSSourceContainer)5 FluentIterable.from (com.google.common.collect.FluentIterable.from)4