Search in sources :

Example 1 with IPluginObject

use of org.eclipse.pde.core.plugin.IPluginObject 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);
    }
}
Also used : IQualifiedNameProvider(org.eclipse.xtext.naming.IQualifiedNameProvider) IPluginElement(org.eclipse.pde.core.plugin.IPluginElement) Check(com.avaloq.tools.ddk.check.check.Check) IPluginObject(org.eclipse.pde.core.plugin.IPluginObject)

Example 2 with IPluginObject

use of org.eclipse.pde.core.plugin.IPluginObject 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;
}
Also used : IPluginElement(org.eclipse.pde.core.plugin.IPluginElement) Check(com.avaloq.tools.ddk.check.check.Check) IPluginAttribute(org.eclipse.pde.core.plugin.IPluginAttribute) IQualifiedNameProvider(org.eclipse.xtext.naming.IQualifiedNameProvider) IPluginObject(org.eclipse.pde.core.plugin.IPluginObject) NoSuchElementException(java.util.NoSuchElementException) Pair(org.eclipse.xtext.util.Pair)

Example 3 with IPluginObject

use of org.eclipse.pde.core.plugin.IPluginObject in project dsl-devkit by dsldevkit.

the class AbstractCheckExtensionHelper method createExtension.

/**
 * Creates the extension. Note that the <code>id</code> attribute is optional and thus not created.
 *
 * @param catalog
 *          the catalog for which to crate the extension content.
 * @param extensionId
 *          the extension id, may be <code>null</code>
 * @param pluginModel
 *          the model
 * @return the plugin extension
 * @throws CoreException
 *           a core exception
 */
protected IPluginExtension createExtension(final CheckCatalog catalog, final String extensionId, final IPluginModelBase pluginModel) throws CoreException {
    IPluginExtension newExtension = pluginModel.getFactory().createExtension();
    newExtension.setPoint(getExtensionPointId());
    if (extensionId != null) {
        newExtension.setId(extensionId);
    }
    if (getExtensionPointName(catalog) != null) {
        newExtension.setName(getExtensionPointName(catalog));
    }
    // Add contents to the extension
    for (final IPluginObject p : getElements(catalog, newExtension)) {
        newExtension.add(p);
    }
    return newExtension;
}
Also used : IPluginExtension(org.eclipse.pde.core.plugin.IPluginExtension) IPluginObject(org.eclipse.pde.core.plugin.IPluginObject)

Example 4 with IPluginObject

use of org.eclipse.pde.core.plugin.IPluginObject in project dsl-devkit by dsldevkit.

the class CheckMarkerHelpExtensionTest method testAddElement.

/**
 * Tests, if the marker help extension is updated correctly, i.e. add marker help elements for new checks
 * and delete the elements of removed checks.
 *
 * @throws Exception
 *           the exception
 */
@Test
public void testAddElement() throws Exception {
    final CheckCatalog catalogWithOneCheck = parser.parse(CATALOG_WITH_FIRST_CHECK_LIVE);
    IPluginExtension extension = createMarkerHelpExtension(catalogWithOneCheck);
    assertEquals("Original catalog has one marker help extension", 1, extension.getChildCount());
    CheckCatalog catalogWithTwoChecks = parser.parse(CATALOG_WITH_TWO_CHECKS);
    markerUtil.updateExtension(catalogWithTwoChecks, extension);
    Set<String> contextIds = Sets.newHashSet();
    // Test if the marker help element for the old Check has been removed
    for (IPluginObject element : extension.getChildren()) {
        contextIds.add(((IPluginElement) element).getAttribute(CheckMarkerHelpExtensionHelper.CONTEXT_ID_ATTRIBUTE_TAG).getValue());
    }
    assertEquals("The extension has two elements", 2, extension.getChildCount());
    assertTrue("Both checks are elements of the extension ", contextIds.containsAll(Sets.newHashSet(FIRSTCHECK_CONTEXID, SECONDCHECK_CONTEXTID)));
}
Also used : IPluginExtension(org.eclipse.pde.core.plugin.IPluginExtension) IPluginElement(org.eclipse.pde.core.plugin.IPluginElement) IPluginObject(org.eclipse.pde.core.plugin.IPluginObject) CheckCatalog(com.avaloq.tools.ddk.check.check.CheckCatalog) Test(org.junit.Test)

Example 5 with IPluginObject

use of org.eclipse.pde.core.plugin.IPluginObject in project dsl-devkit by dsldevkit.

the class CheckMarkerHelpExtensionTest method testCheckHasTwoIssueCodes.

/**
 * Tests if a marker help element is added if an additional issueCode is added to an existing check.
 *
 * @throws Exception
 *           the exception
 */
@Test
public void testCheckHasTwoIssueCodes() throws Exception {
    IPluginExtension extension = createMarkerHelpExtension(parser.parse(CATALOG_WITH_FIRST_CHECK_LIVE));
    CheckCatalog twoIssueCodes = parser.parse(CATALOG_CHECK_HAS_TWO_ISSUECODES);
    markerUtil.updateExtension(twoIssueCodes, extension);
    List<String> issueCodesOfCheck = Lists.newArrayList();
    for (final XIssueExpression i : generatorExtension.issues(twoIssueCodes.getChecks().get(0))) {
        issueCodesOfCheck.add(CheckGeneratorExtensions.issueCodeValue(twoIssueCodes.getChecks().get(0), CheckGeneratorExtensions.issueCode(i)));
    }
    List<String> issueCodesInExtension = Lists.newArrayList();
    for (IPluginObject obj : extension.getChildren()) {
        for (IPluginObject element : ((IPluginElement) obj).getChildren()) {
            issueCodesInExtension.add(((IPluginElement) element).getAttribute(CheckMarkerHelpExtensionHelper.ATTRIBUTE_VALUE_TAG).getValue());
        }
    }
    assertTrue("A marker help element for both issueCodes has been created.", Iterables.elementsEqual(issueCodesInExtension, issueCodesOfCheck));
    assertEquals("extension has two marker help elements", 2, issueCodesInExtension.size());
}
Also used : IPluginExtension(org.eclipse.pde.core.plugin.IPluginExtension) XIssueExpression(com.avaloq.tools.ddk.check.check.XIssueExpression) IPluginElement(org.eclipse.pde.core.plugin.IPluginElement) IPluginObject(org.eclipse.pde.core.plugin.IPluginObject) CheckCatalog(com.avaloq.tools.ddk.check.check.CheckCatalog) Test(org.junit.Test)

Aggregations

IPluginObject (org.eclipse.pde.core.plugin.IPluginObject)5 IPluginElement (org.eclipse.pde.core.plugin.IPluginElement)4 IPluginExtension (org.eclipse.pde.core.plugin.IPluginExtension)3 Check (com.avaloq.tools.ddk.check.check.Check)2 CheckCatalog (com.avaloq.tools.ddk.check.check.CheckCatalog)2 IQualifiedNameProvider (org.eclipse.xtext.naming.IQualifiedNameProvider)2 Test (org.junit.Test)2 XIssueExpression (com.avaloq.tools.ddk.check.check.XIssueExpression)1 NoSuchElementException (java.util.NoSuchElementException)1 IPluginAttribute (org.eclipse.pde.core.plugin.IPluginAttribute)1 Pair (org.eclipse.xtext.util.Pair)1