diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/views/markers/internal/ContentGeneratorDescriptor.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/views/markers/internal/ContentGeneratorDescriptor.java index 9b1242f4c78..855249c9899 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/views/markers/internal/ContentGeneratorDescriptor.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/views/markers/internal/ContentGeneratorDescriptor.java @@ -20,6 +20,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.TreeSet; import java.util.stream.Stream; @@ -44,8 +45,10 @@ public class ContentGeneratorDescriptor { private IConfigurationElement configurationElement; private MarkerField[] allFields; + private MarkerField[] allFieldsWithExtensions; private Collection markerTypes; private MarkerField[] initialVisible; + private MarkerField[] initialVisibleWithExtensions; private Collection groups; private Collection generatorExtensions = new ArrayList<>(); private Map allTypesTable; @@ -105,7 +108,14 @@ public boolean allTypesSelected(Collection selectedTypes) { * @return {@link MarkerField}[] */ public MarkerField[] getAllFields() { - return allFields; + if (allFieldsWithExtensions == null) { + List fields = new ArrayList<>(); + fields.addAll(Arrays.asList(allFields)); + getExtensionsDescriptorsStream().map(d -> Arrays.asList(d.getAllFields())).flatMap(Collection::stream) + .forEach(fields::add); + allFieldsWithExtensions = fields.toArray(MarkerField[]::new); + } + return allFieldsWithExtensions; } /** @@ -156,7 +166,14 @@ public String getId() { * @return {@link MarkerField}[] */ public MarkerField[] getInitialVisible() { - return initialVisible; + if (initialVisibleWithExtensions == null) { + List fields = new ArrayList<>(); + fields.addAll(Arrays.asList(initialVisible)); + getExtensionsDescriptorsStream().map(d -> Arrays.asList(d.getInitialVisible())).flatMap(Collection::stream) + .forEach(fields::add); + initialVisibleWithExtensions = fields.toArray(MarkerField[]::new); + } + return initialVisibleWithExtensions; } /** @@ -198,6 +215,8 @@ public Collection getMarkerTypes() { MarkerType[] types = MarkerTypesModel.getInstance().getType(IMarker.PROBLEM).getAllSubTypes(); markerTypes.addAll(Arrays.asList(types)); } + getExtensionsDescriptorsStream().map(ContentGeneratorDescriptor::getMarkerTypes).flatMap(Collection::stream) + .forEach(markerTypes::add); } return markerTypes; } @@ -278,4 +297,18 @@ public void initializeFromConfigurationElement( public void removeExtension(IConfigurationElement element) { generatorExtensions.remove(element); } + + private Stream getExtensionsDescriptorsStream() { + if (generatorExtensions != null) { + MarkerSupportRegistry registry = MarkerSupportRegistry.getInstance(); + return generatorExtensions.stream() + .map(extensionConfigElem -> extensionConfigElem + .getAttribute(MarkerSupportInternalUtilities.ATTRIBUTE_ID)) + .filter(id -> id != null && !id.isBlank()) + .map(contentGeneratorId -> registry.getContentGenDescriptor(contentGeneratorId)) + .filter(generator -> generator != null); + } + return Stream.empty(); + } + } diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/MarkerSupportViewTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/MarkerSupportViewTest.java index ada02ad47e2..b76f1895892 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/MarkerSupportViewTest.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/MarkerSupportViewTest.java @@ -14,7 +14,11 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.util.Arrays; import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.swt.widgets.Button; @@ -25,8 +29,13 @@ import org.eclipse.ui.internal.views.markers.FiltersConfigurationDialog; import org.eclipse.ui.internal.views.markers.MarkerContentGenerator; import org.eclipse.ui.tests.harness.util.UITestCase; +import org.eclipse.ui.views.markers.MarkerField; import org.eclipse.ui.views.markers.MarkerSupportView; +import org.eclipse.ui.views.markers.internal.ContentGeneratorDescriptor; +import org.eclipse.ui.views.markers.internal.MarkerGroup; import org.eclipse.ui.views.markers.internal.MarkerMessages; +import org.eclipse.ui.views.markers.internal.MarkerSupportRegistry; +import org.eclipse.ui.views.markers.internal.MarkerType; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -125,6 +134,70 @@ public void limitDisabled() throws Exception { assertFalse(isLimitEnabled); } + @Test + public void markerContentGeneratorExtensionLoaded() throws Exception { + MarkerSupportView view = (MarkerSupportView) PlatformUI.getWorkbench().getActiveWorkbenchWindow() + .getActivePage().showView(PROBLEM_VIEW_ID); + + MarkerContentGenerator generator = getMarkerContentGenerator(view); + ContentGeneratorDescriptor descriptor = MarkerSupportRegistry.getInstance() + .getContentGenDescriptor(generator.getId()); + + assertNotNull(descriptor); + + MarkerField[] allFields = descriptor.getAllFields(); + List allFieldNames = mapToNames(allFields); + String fieldName1 = "Problem Key"; + String fieldName2 = "Problem Key V2"; + + assertTrue( + "Expected loading marker field '" + fieldName1 + + "' from marker content generator extensions, but got only " + allFieldNames, + allFieldNames.contains(fieldName1)); + assertTrue( + "Expected recursively loading marker field '" + fieldName2 + + "' from marker content generator extensions, but got only " + allFieldNames, + allFieldNames.contains(fieldName2)); + + MarkerField[] initiallyVisibleFields = descriptor.getInitialVisible(); + List initiallyVisibleFieldNames = mapToNames(initiallyVisibleFields); + + assertTrue("Expected marker field '" + fieldName1 + + "' from marker content generator extension being visible according to 'visible' attribute in the extension," + + " but only the following marker fields are visible " + initiallyVisibleFieldNames, + initiallyVisibleFieldNames.contains(fieldName1)); + assertFalse("Expected marker field '" + fieldName2 + + "' from marker content generator extension being not visible according to 'visible' attribute in the extension," + + " but the following marker fields are visible " + initiallyVisibleFieldNames, + initiallyVisibleFieldNames.contains(fieldName2)); + + String markerTypeId = "org.eclipse.ui.tests.markers.artificial.problem"; + MarkerType markerTypeFromExtension = descriptor.getType(markerTypeId); + List markerTypeIds = descriptor.getMarkerTypes().stream().map(MarkerType::getId) + .collect(Collectors.toList()); + + assertNotNull("Marker type with id '" + markerTypeId + "' not loaded from marker content generator extension.", + markerTypeFromExtension); + assertTrue("Expected marker type id '" + markerTypeId + "' being in marker types list, but we have only " + + markerTypeIds, markerTypeIds.contains(markerTypeId)); + + Collection groups = descriptor.getMarkerGroups(); + List groupIds = groups.stream().map(MarkerGroup::getId).collect(Collectors.toList()); + String groupId = "org.eclipse.ui.tests.test.extended"; + + assertTrue("Expected loading group id '" + groupId + + "' from marker content generator extension, but got only the following group ids: " + groupIds, + groupIds.contains(groupId)); + } + + private List mapToNames(MarkerField[] markerFields) { + if (markerFields == null || markerFields.length == 0) { + return Collections.emptyList(); + } + + return Arrays.stream(markerFields).map(mf -> mf.getName()).collect(Collectors.toList()); + } + public static MarkerContentGenerator getMarkerContentGenerator(MarkerSupportView view) { MarkerContentGenerator generator = null; try { diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/ProblemKeyMarkerField.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/ProblemKeyMarkerField.java new file mode 100644 index 00000000000..cfdcdba4822 --- /dev/null +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/ProblemKeyMarkerField.java @@ -0,0 +1,16 @@ +package org.eclipse.ui.tests.markers; + +import org.eclipse.ui.views.markers.MarkerField; +import org.eclipse.ui.views.markers.MarkerItem; + +public class ProblemKeyMarkerField extends MarkerField { + + @Override + public String getValue(MarkerItem item) { + if (item == null) { + return ""; + } + return item.getAttributeValue("problemKey", ""); + } + +} diff --git a/tests/org.eclipse.ui.tests/plugin.xml b/tests/org.eclipse.ui.tests/plugin.xml index 3c15b5d245a..e86b19feccf 100644 --- a/tests/org.eclipse.ui.tests/plugin.xml +++ b/tests/org.eclipse.ui.tests/plugin.xml @@ -3411,7 +3411,58 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +