use of org.eclipse.pde.core.plugin.IPluginElement in project dsl-devkit by dsldevkit.
the class CheckMarkerHelpExtensionHelper method createAttributeElement.
/**
* Creates the attribute element and adds it to the give marker help element.
*
* @param markerHelpElement
* the marker help element
* @param issueCode
* the issue code
* @return the i plugin element
* @throws CoreException
* the core exception if the plugin element could not be created
*/
private IPluginElement createAttributeElement(final IPluginElement markerHelpElement, final String issueCode) throws CoreException {
IPluginElement attributeElement = markerHelpElement.getModel().getFactory().createElement(markerHelpElement);
attributeElement.setName(ATTRIBUTE_ELEMENT);
attributeElement.setAttribute(ATTRIBUTE_NAME_TAG, Issue.CODE_KEY);
attributeElement.setAttribute(ATTRIBUTE_VALUE_TAG, issueCode);
return attributeElement;
}
use of org.eclipse.pde.core.plugin.IPluginElement in project dsl-devkit by dsldevkit.
the class CheckMarkerHelpExtensionHelper method getElements.
/**
* Creates a marker help element for every check in the catalog. The new elements are added to the given extension.
*
* @param catalog
* the catalog
* @param extension
* the extension to add the new element to
* @return new marker help elements in given extension which don't exist yet, but should; returns an empty list if the extension is up to date
* @throws CoreException
* the core exception
*/
@Override
public Iterable<IPluginElement> getElements(final CheckCatalog catalog, final IPluginExtension extension) throws CoreException {
List<IPluginElement> result = Lists.newArrayList();
Multimap<String, String> contextIdToAttributeValues = HashMultimap.<String, String>create();
for (Check check : catalog.getAllChecks()) {
final String contextId = getQualifiedContextId(extension, check);
for (String issueCode : getIssueCodeValues(check)) {
if (!contextIdToAttributeValues.get(contextId).contains(issueCode)) {
contextIdToAttributeValues.put(contextId, issueCode);
IPluginElement markerHelp = createMarkerHelpElement(extension, check, contextId);
markerHelp.add(createAttributeElement(markerHelp, issueCode));
result.add(markerHelp);
}
}
}
return result;
}
use of org.eclipse.pde.core.plugin.IPluginElement in project dsl-devkit by dsldevkit.
the class CheckMarkerHelpExtensionHelper method doUpdateExtension.
@Override
protected void doUpdateExtension(final CheckCatalog catalog, final IPluginExtension extension, final Iterable<IPluginElement> elements) throws CoreException {
final IQualifiedNameProvider nameProvider = getFromServiceProvider(IQualifiedNameProvider.class, catalog);
// Get current marker help element context IDs for this catalog
List<String> catalogContextIds = Lists.newArrayList();
for (final Check check : catalog.getAllChecks()) {
catalogContextIds.add(getQualifiedContextId(extension, check));
}
// Remove elements of this catalog
for (IPluginElement e : elements) {
if (e.getAttribute(CONTEXT_ID_ATTRIBUTE_TAG) != null) {
String contextId = e.getAttribute(CONTEXT_ID_ATTRIBUTE_TAG).getValue();
if (isCatalogContextId(nameProvider.apply(catalog), EcoreUtil.getURI(catalog), extension, contextId)) {
extension.remove(e);
}
}
}
// Add new elements
Iterable<? extends IPluginObject> updatedElements = getElements(catalog, extension);
for (IPluginObject object : updatedElements) {
extension.add(object);
}
}
use of org.eclipse.pde.core.plugin.IPluginElement in project dsl-devkit by dsldevkit.
the class CheckMarkerHelpExtensionHelper method isExtensionUpdateRequired.
@Override
protected boolean isExtensionUpdateRequired(final CheckCatalog catalog, final IPluginExtension extension, final Iterable<IPluginElement> elements) {
// TODO should check if this check is too expensive; consider rewriting contents instead
if (!super.isExtensionUpdateRequired(catalog, extension, elements)) {
return false;
}
final IQualifiedNameProvider nameProvider = getFromServiceProvider(IQualifiedNameProvider.class, catalog);
// collect all data in the extension model: mapping<context id, pair<execution mode, issue code>>
HashMultimap<String, Pair<String, String>> contextToValue = HashMultimap.<String, Pair<String, String>>create();
for (IPluginElement e : elements) {
if (e.getAttribute(CONTEXT_ID_ATTRIBUTE_TAG) != null) {
String contextId = e.getAttribute(CONTEXT_ID_ATTRIBUTE_TAG).getValue();
String mode = e.getAttribute(MARKERTYPE_ATTRIBUTE_TAG).getValue();
if (isCatalogContextId(nameProvider.apply(catalog), EcoreUtil.getURI(catalog), extension, contextId)) {
for (IPluginObject o : e.getChildren()) {
if (o instanceof IPluginElement && ((IPluginElement) o).getAttribute(ATTRIBUTE_VALUE_TAG) != null) {
// NOPMD
IPluginAttribute attribute = ((IPluginElement) o).getAttribute(ATTRIBUTE_VALUE_TAG);
contextToValue.put(contextId, Tuples.create(mode, attribute.getValue()));
}
}
}
}
}
// check that the real model and the extension model have the same number of issue codes
Iterable<String> allExtensionIssueCodes = Iterables.transform(contextToValue.values(), new Function<Pair<String, String>, String>() {
@Override
public String apply(final Pair<String, String> input) {
return input.getSecond();
}
});
if (Iterables.size(allExtensionIssueCodes) != Sets.newHashSet(getAllIssueCodeValues(catalog)).size()) {
return true;
}
// check all relevant data, e.g. detect change of execution mode
for (final Check check : catalog.getAllChecks()) {
final Iterable<String> allModelIssueCodes = getIssueCodeValues(check);
for (final String issueCode : allModelIssueCodes) {
final String contextId = getQualifiedContextId(extension, check);
if (contextToValue.containsKey(contextId)) {
Set<Pair<String, String>> modeToValues = contextToValue.get(contextId);
try {
Iterables.find(modeToValues, new Predicate<Pair<String, String>>() {
@Override
public boolean apply(final Pair<String, String> input) {
return input.getFirst().equals(getCheckType(check)) && input.getSecond().equals(issueCode);
}
});
} catch (NoSuchElementException e) {
return true;
}
} else {
// context id not present in extension model
return true;
}
}
}
return false;
}
use of org.eclipse.pde.core.plugin.IPluginElement in project dsl-devkit by dsldevkit.
the class CheckMarkerHelpExtensionTest method testMarkerTypeUpdate.
/**
* Tests if the marker type attribute is updated if the trigger kind changes for a check.
*
* @throws Exception
* the exception
*/
@Test
public void testMarkerTypeUpdate() throws Exception {
IPluginExtension extension = createMarkerHelpExtension(parser.parse(CATALOG_WITH_FIRST_CHECK_LIVE));
assertEquals("Before update: Markertype is fast.", MARKERTYPE_FAST, ((IPluginElement) extension.getChildren()[0]).getAttribute(CheckMarkerHelpExtensionHelper.MARKERTYPE_ATTRIBUTE_TAG).getValue());
CheckCatalog updateMarkertype = parser.parse(CATALOG_WITH_FIRST_CHECK_ONDEMAND);
markerUtil.updateExtension(updateMarkertype, extension);
assertEquals("After update: Markertype is expensive.", MARKERTYPE_EXPENSIVE, ((IPluginElement) extension.getChildren()[0]).getAttribute(CheckMarkerHelpExtensionHelper.MARKERTYPE_ATTRIBUTE_TAG).getValue());
}
Aggregations