Search in sources :

Example 1 with ProjectType

use of org.eclipse.n4js.n4mf.ProjectType 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 2 with ProjectType

use of org.eclipse.n4js.n4mf.ProjectType in project n4js by eclipse.

the class ProjectDescriptionImpl method setProjectType.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setProjectType(ProjectType newProjectType) {
    ProjectType oldProjectType = projectType;
    projectType = newProjectType == null ? PROJECT_TYPE_EDEFAULT : newProjectType;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, N4mfPackage.PROJECT_DESCRIPTION__PROJECT_TYPE, oldProjectType, projectType));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) ProjectType(org.eclipse.n4js.n4mf.ProjectType)

Example 3 with ProjectType

use of org.eclipse.n4js.n4mf.ProjectType in project n4js by eclipse.

the class GHOLD_101_WorkingSetsTest_PluginUITest method testProjectTypeWorkingSetGrouping.

/**
 */
@Test
public void testProjectTypeWorkingSetGrouping() throws CoreException {
    final Multimap<ProjectType, String> typeNamesMapping = HashMultimap.create();
    typeNamesMapping.putAll(LIBRARY, newArrayList("L1", "L2", "L3"));
    typeNamesMapping.putAll(TEST, newArrayList("T1", "T2"));
    typeNamesMapping.putAll(RUNTIME_ENVIRONMENT, newArrayList("RE1", "RE2", "RE3", "RE4"));
    typeNamesMapping.putAll(RUNTIME_LIBRARY, newArrayList("RL1"));
    for (final Entry<ProjectType, Collection<String>> entry : typeNamesMapping.asMap().entrySet()) {
        for (final String projectName : entry.getValue()) {
            createN4JSProject(projectName, entry.getKey());
        }
    }
    final Collection<String> othersProjectNames = newArrayList("O1", "O2");
    for (final String projectName : othersProjectNames) {
        createJSProject(projectName);
    }
    activateWorkingSetManager(ProjectTypeAwareWorkingSetManager.class);
    commonViewer.expandToLevel(2);
    waitForIdleState();
    final TreeItem[] treeItems = commonViewer.getTree().getItems();
    final int expectedItemCount = ProjectType.values().length + 1;
    assertTrue("Expected exactly " + expectedItemCount + " items in the Project Explorer. Input was: " + Arrays.toString(treeItems), treeItems.length == expectedItemCount);
    final List<ProjectTypeWorkingSet> workingSets = from(asList(treeItems)).transform(item -> item.getData()).filter(ProjectTypeWorkingSet.class).toList();
    assertEquals("Mismatching number of working sets.", expectedItemCount, workingSets.size());
    for (final TreeItem treeItem : treeItems) {
        final ProjectType type = ((ProjectTypeWorkingSet) treeItem.getData()).getType();
        final Collection<String> expectedProjectNames;
        if (null == type) {
            expectedProjectNames = othersProjectNames;
        } else {
            expectedProjectNames = typeNamesMapping.get(type);
        }
        assertEquals("Child item count mismatch: " + treeItem, expectedProjectNames.size(), treeItem.getItemCount());
        for (final TreeItem child : treeItem.getItems()) {
            final String childText = child.getText();
            assertTrue("Unexpected tree item label: " + childText + ". Expected any of: " + Iterables.toString(expectedProjectNames), expectedProjectNames.contains(childText));
        }
    }
}
Also used : ProjectTypeWorkingSet(org.eclipse.n4js.ui.workingsets.ProjectTypeAwareWorkingSetManager.ProjectTypeWorkingSet) TreeItem(org.eclipse.swt.widgets.TreeItem) ProjectType(org.eclipse.n4js.n4mf.ProjectType) Collection(java.util.Collection) Test(org.junit.Test)

Aggregations

ProjectType (org.eclipse.n4js.n4mf.ProjectType)3 Collection (java.util.Collection)2 Optional (com.google.common.base.Optional)1 FluentIterable.from (com.google.common.collect.FluentIterable.from)1 Inject (com.google.inject.Inject)1 AbstractMap (java.util.AbstractMap)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Logger (org.apache.log4j.Logger)1 Logger.getLogger (org.apache.log4j.Logger.getLogger)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1 IN4JSArchive (org.eclipse.n4js.projectModel.IN4JSArchive)1 IN4JSCore (org.eclipse.n4js.projectModel.IN4JSCore)1