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 49f25fcdb7a..5a9e453b8cb 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 @@ -21,6 +21,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; @@ -45,8 +46,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; @@ -79,6 +82,7 @@ private void addDefinedGroups(Collection groupss) { */ public void addExtensions(Collection extensions) { generatorExtensions = extensions; + clearCaches(); } /** @@ -97,7 +101,7 @@ private void addGroupsFrom(IConfigurationElement element, Collection selectedTypes) { - return selectedTypes.containsAll(markerTypes); + return selectedTypes.containsAll(getMarkerTypes()); } /** @@ -106,7 +110,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; } /** @@ -157,7 +168,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; } /** @@ -215,6 +233,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; } @@ -247,7 +267,7 @@ public Map getTypesTable() { if (allTypesTable == null) { allTypesTable = new HashMap<>(); - Iterator allIterator = markerTypes.iterator(); + Iterator allIterator = getMarkerTypes().iterator(); while (allIterator.hasNext()) { MarkerType next = allIterator.next(); allTypesTable.put(next.getId(), next); @@ -294,5 +314,28 @@ public void initializeFromConfigurationElement( */ public void removeExtension(IConfigurationElement element) { generatorExtensions.remove(element); + clearCaches(); + } + + private void clearCaches() { + allFieldsWithExtensions = null; + initialVisibleWithExtensions = null; + markerTypes = null; + groups = null; + allTypesTable = null; } + + 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 814b4507d30..6350e67b8c6 100644 --- a/tests/org.eclipse.ui.tests/plugin.xml +++ b/tests/org.eclipse.ui.tests/plugin.xml @@ -3461,7 +3461,58 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +