Search in sources :

Example 1 with ProjectNameFilterWorkingSet

use of org.eclipse.n4js.ui.workingsets.ProjectNameFilterAwareWorkingSetManager.ProjectNameFilterWorkingSet in project n4js by eclipse.

the class GHOLD_101_WorkingSetsTest_PluginUITest method testProjectNameFilterWorkingSetGrouping.

/**
 */
@Test
public void testProjectNameFilterWorkingSetGrouping() throws CoreException {
    final Multimap<String, String> filterNamesMapping = LinkedHashMultimap.create();
    filterNamesMapping.putAll(OTHERS_WORKING_SET_ID, newArrayList("org.eclipse.n4js.mangelhaft", "org.eclipse.n4js.mangelhaft.assert", "org.eclipse.n4js.mangelhaft.assert.test", "org.eclipse.n4js.mangelhaft.types", "eu.numberfour.mangelhaft.reporter.console", "eu.numberfour.mangelhaft.reporter.html", "org.eclipse.n4js.mangelhaft.reporter.ide", "org.eclipse.n4js.mangelhaft.reporter.ide.test", "eu.numberfour.mangelhaft.reporter.xunit", "eu.numberfour.mangelhaft.runner.html", "org.eclipse.n4js.mangelhaft.runner.ide", "eu.numberfour.mangelhaft.runner.node", "org.eclipse.n4js.mangelhaft.test"));
    filterNamesMapping.putAll(".*-runtime-.*", newArrayList("n4js-runtime-es2015", "n4js-runtime-esnext", "n4js-runtime-fetch", "n4js-runtime-html5", "n4js-runtime-n4", "n4js-runtime-n4-tests", "n4js-runtime-node", "n4js-runtime-node-tests", "n4js-runtime-v8"));
    filterNamesMapping.putAll(".*lib.*", newArrayList("org.eclipse.lib.format", "org.eclipse.lib.format.api", "org.eclipse.lib.format.api-tests", "org.eclipse.lib.i18n.api", "org.eclipse.lib.i18n.api-tests", "org.eclipse.lib.jtl", "org.eclipse.lib.jtl.api", "org.eclipse.lib.jtl.api-tests", "org.eclipse.lib.jtl.tests", "org.eclipse.lib.model.base", "org.eclipse.lib.model.base.api", "org.eclipse.lib.model.base.api-tests", "org.eclipse.lib.model.base.tests", "org.eclipse.lib.model.common", "org.eclipse.lib.model.common.api", "org.eclipse.lib.model.common.api-tests", "org.eclipse.lib.model.common.tests", "org.eclipse.lib.model.core", "org.eclipse.lib.model.core.api", "org.eclipse.lib.model.core.api-tests", "org.eclipse.lib.model.core.zoo.berlin", "org.eclipse.lib.model.gen", "org.eclipse.lib.model.gen.api", "org.eclipse.lib.model.gen.api-tests", "org.eclipse.lib.notificationCenter.api", "org.eclipse.lib.notificationCenter.api-tests", "org.eclipse.lib.npm-dependencies", "org.eclipse.lib.transaction", "org.eclipse.lib.transaction.api", "org.eclipse.lib.transaction.api-tests", "org.eclipse.lib.util"));
    filterNamesMapping.putAll(".*lib.*api.*", newArrayList("org.eclipse.lib.format.api", "org.eclipse.lib.format.api-tests", "org.eclipse.lib.i18n.api", "org.eclipse.lib.i18n.api-tests", "org.eclipse.lib.jtl.api", "org.eclipse.lib.jtl.api-tests", "org.eclipse.lib.model.base.api", "org.eclipse.lib.model.base.api-tests", "org.eclipse.lib.model.common.api", "org.eclipse.lib.model.common.api-tests", "org.eclipse.lib.model.core.api", "org.eclipse.lib.model.core.api-tests", "org.eclipse.lib.model.gen.api", "org.eclipse.lib.model.gen.api-tests", "org.eclipse.lib.notificationCenter.api", "org.eclipse.lib.notificationCenter.api-tests", "org.eclipse.lib.transaction.api", "org.eclipse.lib.transaction.api-tests"));
    filterNamesMapping.putAll(".*lib.*api.*test.*", newArrayList("org.eclipse.lib.format.api-tests", "org.eclipse.lib.i18n.api-tests", "org.eclipse.lib.jtl.api-tests", "org.eclipse.lib.model.base.api-tests", "org.eclipse.lib.model.common.api-tests", "org.eclipse.lib.model.core.api-tests", "org.eclipse.lib.model.gen.api-tests", "org.eclipse.lib.notificationCenter.api-tests", "org.eclipse.lib.transaction.api-tests"));
    final IWorkspaceDescription workspaceDescription = ResourcesPlugin.getWorkspace().getDescription();
    final boolean autoBuild = workspaceDescription.isAutoBuilding();
    try {
        // No need for the build at all.
        workspaceDescription.setAutoBuilding(false);
        for (final String projectName : filterNamesMapping.values()) {
            JavaProjectSetupUtil.createSimpleProject(projectName);
        }
    } finally {
        workspaceDescription.setAutoBuilding(autoBuild);
    }
    activateWorkingSetManager(ProjectNameFilterAwareWorkingSetManager.class);
    final WorkingSetManager manager = broker.getActiveManager();
    final WorkingSetDiffBuilder builder = new WorkingSetDiffBuilder(manager);
    final List<WorkingSet> workingSets = newArrayList();
    final WorkingSet other = new ProjectNameFilterWorkingSet(compile(OTHERS_WORKING_SET_ID), OTHERS_WORKING_SET_ID, manager);
    builder.add(other);
    workingSets.add(other);
    for (final String workingSetId : filterNamesMapping.keySet()) {
        final WorkingSet workingSet = new ProjectNameFilterWorkingSet(compile(workingSetId), workingSetId, manager);
        builder.add(workingSet);
        workingSets.add(workingSet);
    }
    final Diff<WorkingSet> diff = builder.build(toArray(workingSets, WorkingSet.class), toArray(workingSets, WorkingSet.class));
    manager.updateState(diff);
    broker.refreshNavigator();
    waitForIdleState();
    commonViewer.expandToLevel(2);
    waitForIdleState();
    final TreeItem[] treeItems = commonViewer.getTree().getItems();
    final int expectedItemCount = filterNamesMapping.keySet().size();
    assertTrue("Expected exactly " + expectedItemCount + " items in the Project Explorer. Input was: " + Arrays.toString(treeItems), treeItems.length == expectedItemCount);
    final List<ProjectNameFilterWorkingSet> workingSetsFromTree = from(asList(treeItems)).transform(item -> item.getData()).filter(ProjectNameFilterWorkingSet.class).toList();
    assertEquals("Mismatching number of working sets.", expectedItemCount, workingSetsFromTree.size());
    for (final TreeItem treeItem : treeItems) {
        final Pattern filter = ((ProjectNameFilterWorkingSet) treeItem.getData()).getFilter();
        final Collection<String> expectedProjectNames = filterNamesMapping.get(filter.pattern());
        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 : Pattern(java.util.regex.Pattern) TreeItem(org.eclipse.swt.widgets.TreeItem) ProjectTypeAwareWorkingSetManager(org.eclipse.n4js.ui.workingsets.ProjectTypeAwareWorkingSetManager) ProjectNameFilterAwareWorkingSetManager(org.eclipse.n4js.ui.workingsets.ProjectNameFilterAwareWorkingSetManager) ManualAssociationAwareWorkingSetManager(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager) WorkingSetManager(org.eclipse.n4js.ui.workingsets.WorkingSetManager) IWorkspaceDescription(org.eclipse.core.resources.IWorkspaceDescription) WorkingSetDiffBuilder(org.eclipse.n4js.ui.workingsets.WorkingSetDiffBuilder) ProjectNameFilterWorkingSet(org.eclipse.n4js.ui.workingsets.ProjectNameFilterAwareWorkingSetManager.ProjectNameFilterWorkingSet) ManualAssociationWorkingSet(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager.ManualAssociationWorkingSet) ProjectNameFilterWorkingSet(org.eclipse.n4js.ui.workingsets.ProjectNameFilterAwareWorkingSetManager.ProjectNameFilterWorkingSet) ProjectTypeWorkingSet(org.eclipse.n4js.ui.workingsets.ProjectTypeAwareWorkingSetManager.ProjectTypeWorkingSet) WorkingSet(org.eclipse.n4js.ui.workingsets.WorkingSet) Test(org.junit.Test)

Aggregations

Pattern (java.util.regex.Pattern)1 IWorkspaceDescription (org.eclipse.core.resources.IWorkspaceDescription)1 ManualAssociationAwareWorkingSetManager (org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager)1 ManualAssociationWorkingSet (org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager.ManualAssociationWorkingSet)1 ProjectNameFilterAwareWorkingSetManager (org.eclipse.n4js.ui.workingsets.ProjectNameFilterAwareWorkingSetManager)1 ProjectNameFilterWorkingSet (org.eclipse.n4js.ui.workingsets.ProjectNameFilterAwareWorkingSetManager.ProjectNameFilterWorkingSet)1 ProjectTypeAwareWorkingSetManager (org.eclipse.n4js.ui.workingsets.ProjectTypeAwareWorkingSetManager)1 ProjectTypeWorkingSet (org.eclipse.n4js.ui.workingsets.ProjectTypeAwareWorkingSetManager.ProjectTypeWorkingSet)1 WorkingSet (org.eclipse.n4js.ui.workingsets.WorkingSet)1 WorkingSetDiffBuilder (org.eclipse.n4js.ui.workingsets.WorkingSetDiffBuilder)1 WorkingSetManager (org.eclipse.n4js.ui.workingsets.WorkingSetManager)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1 Test (org.junit.Test)1