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