Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load marker content generator details from marker content generator extensions (fix for #2193) #2207

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.HashMap;
iloveeclipse marked this conversation as resolved.
Show resolved Hide resolved
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;
Expand All @@ -45,8 +46,10 @@ public class ContentGeneratorDescriptor {

private IConfigurationElement configurationElement;
private MarkerField[] allFields;
private MarkerField[] allFieldsWithExtensions;
private Collection<MarkerType> markerTypes;
private MarkerField[] initialVisible;
private MarkerField[] initialVisibleWithExtensions;
private Collection<MarkerGroup> groups;
private Collection<IConfigurationElement> generatorExtensions = new ArrayList<>();
private Map<String, MarkerType> allTypesTable;
Expand Down Expand Up @@ -79,6 +82,7 @@ private void addDefinedGroups(Collection<MarkerGroup> groupss) {
*/
public void addExtensions(Collection<IConfigurationElement> extensions) {
generatorExtensions = extensions;
clearCaches();
}

/**
Expand All @@ -97,7 +101,7 @@ private void addGroupsFrom(IConfigurationElement element, Collection<MarkerGroup
* @return boolean
*/
public boolean allTypesSelected(Collection<MarkerType> selectedTypes) {
return selectedTypes.containsAll(markerTypes);
return selectedTypes.containsAll(getMarkerTypes());
}

/**
Expand All @@ -106,7 +110,14 @@ public boolean allTypesSelected(Collection<MarkerType> selectedTypes) {
* @return {@link MarkerField}[]
*/
public MarkerField[] getAllFields() {
return allFields;
if (allFieldsWithExtensions == null) {
List<MarkerField> 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;
}

/**
Expand Down Expand Up @@ -157,7 +168,14 @@ public String getId() {
* @return {@link MarkerField}[]
*/
public MarkerField[] getInitialVisible() {
return initialVisible;
if (initialVisibleWithExtensions == null) {
List<MarkerField> 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;
}

/**
Expand Down Expand Up @@ -215,6 +233,8 @@ public Collection<MarkerType> 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;
}
Expand Down Expand Up @@ -247,7 +267,7 @@ public Map<String, MarkerType> getTypesTable() {
if (allTypesTable == null) {
travkin79 marked this conversation as resolved.
Show resolved Hide resolved
allTypesTable = new HashMap<>();

Iterator<MarkerType> allIterator = markerTypes.iterator();
Iterator<MarkerType> allIterator = getMarkerTypes().iterator();
while (allIterator.hasNext()) {
MarkerType next = allIterator.next();
allTypesTable.put(next.getId(), next);
Expand Down Expand Up @@ -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<ContentGeneratorDescriptor> 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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String> 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<String> 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<String> 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<MarkerGroup> groups = descriptor.getMarkerGroups();
List<String> 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<String> 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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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", "");
}

}
72 changes: 71 additions & 1 deletion tests/org.eclipse.ui.tests/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3461,7 +3461,58 @@
</markerContentGenerator>
<markerContentGenerator
id="org.eclipse.ui.tests.customScopeContentGenerator">
</markerContentGenerator>
</markerContentGenerator>
<markerField
trancexpress marked this conversation as resolved.
Show resolved Hide resolved
class="org.eclipse.ui.tests.markers.ProblemKeyMarkerField"
id="org.eclipse.ui.tests.markerField.problemKey"
name="Problem Key">
</markerField>
<markerField
class="org.eclipse.ui.tests.markers.ProblemKeyMarkerField"
id="org.eclipse.ui.tests.markerField.problemKeyV2"
name="Problem Key V2">
</markerField>
<markerContentGenerator
id="org.eclipse.ui.tests.additionalProblemMarkerContentGenerator"
name="Additional Problem Marker Content Generator">
<markerFieldReference
visible="true"
id="org.eclipse.ui.tests.markerField.problemKey">
</markerFieldReference>
<markerTypeReference
id="org.eclipse.ui.tests.markers.static.analysis.problem">
</markerTypeReference>
<markerTypeReference
id="org.eclipse.ui.tests.markers.artificial.problem">
</markerTypeReference>
</markerContentGenerator>
<markerContentGeneratorExtension
generatorId="org.eclipse.ui.ide.problemsGenerator"
id="org.eclipse.ui.tests.additionalProblemMarkerContentGenerator">
<markerGrouping
id="org.eclipse.ui.tests.test.extended"
label="Extended Problem Category">
</markerGrouping>
</markerContentGeneratorExtension>
<markerContentGeneratorExtension
generatorId="org.eclipse.ui.ide.allMarkersGenerator"
id="org.eclipse.ui.tests.additionalProblemMarkerContentGenerator">
</markerContentGeneratorExtension>
<markerContentGenerator
id="org.eclipse.ui.tests.additionalProblemMarkerContentGenerator2"
name="Additional Problem Marker Content Generator 2">
<markerFieldReference
visible="false"
id="org.eclipse.ui.tests.markerField.problemKeyV2">
</markerFieldReference>
<markerTypeReference
id="org.eclipse.ui.tests.markers.static.analysis.problem">
</markerTypeReference>
</markerContentGenerator>
<markerContentGeneratorExtension
generatorId="org.eclipse.ui.tests.additionalProblemMarkerContentGenerator"
id="org.eclipse.ui.tests.additionalProblemMarkerContentGenerator2">
</markerContentGeneratorExtension>
</extension>
<extension
id="categoryTestMarker"
Expand Down Expand Up @@ -4888,5 +4939,24 @@
categoryId="org.eclipse.ui.tests.issue1832">
</categoryActivityBinding>
</extension>
<extension
id="markers.static.analysis.problem"
name="Static Analysis Test Problem"
point="org.eclipse.core.resources.markers">
<super
type="org.eclipse.core.resources.problemmarker">
</super>
<persistent
value="true">
</persistent>
<attribute
name="problemKey">
</attribute>
</extension>
<extension
id="markers.artificial.problem"
name="Artificial Test Problem"
point="org.eclipse.core.resources.markers">
</extension>

</plugin>
Loading