Search in sources :

Example 1 with CheckCatalog

use of com.avaloq.tools.ddk.check.check.CheckCatalog in project dsl-devkit by dsldevkit.

the class CheckExtensionGenerator method changePluginXmlFile.

/**
 * Add an extension to the <code>plugin.xml</code> file.
 *
 * @param context
 *          build context
 * @param delta
 *          resource delta
 * @param monitor
 *          progress monitor
 * @throws CoreException
 *           the core exception
 */
public void changePluginXmlFile(final IBuildContext context, final Delta delta, final IProgressMonitor monitor) throws CoreException {
    URI uri = delta.getUri();
    CheckCatalog catalog = projectHelper.getCatalog(context, uri);
    if (catalog == null) {
        // $NON-NLS-1$
        throw new CoreException(new Status(IStatus.ERROR, Activator.getPluginId(), IStatus.ERROR, "No Catalog found", null));
    }
    IFile file = getPluginFile(uri);
    if (!validPluginFile(file)) {
        createNewFile(catalog, file, monitor);
    } else {
        if (!catalogValidates(catalog)) {
            removeExtensions(file, catalog, monitor);
        } else {
            updateExtensions(file, catalog, monitor);
        // TODO improve by only updating the manifest if the validator extension has changed..
        }
    }
    mergeManifest(catalog, monitor);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) CheckCatalog(com.avaloq.tools.ddk.check.check.CheckCatalog) URI(org.eclipse.emf.common.util.URI)

Example 2 with CheckCatalog

use of com.avaloq.tools.ddk.check.check.CheckCatalog 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());
}
Also used : IPluginExtension(org.eclipse.pde.core.plugin.IPluginExtension) IPluginElement(org.eclipse.pde.core.plugin.IPluginElement) CheckCatalog(com.avaloq.tools.ddk.check.check.CheckCatalog) Test(org.junit.Test)

Example 3 with CheckCatalog

use of com.avaloq.tools.ddk.check.check.CheckCatalog 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 4 with CheckCatalog

use of com.avaloq.tools.ddk.check.check.CheckCatalog 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)

Example 5 with CheckCatalog

use of com.avaloq.tools.ddk.check.check.CheckCatalog in project dsl-devkit by dsldevkit.

the class CheckOutlineTreeProvider method internalCreateChildren.

@Override
protected void internalCreateChildren(final DocumentRootNode parentNode, final EObject modelElement) {
    CheckCatalog catalog = (CheckCatalog) modelElement;
    if (catalog.getPackageName() != null) {
        getOutlineNodeFactory().createEStructuralFeatureNode(parentNode, catalog, CheckPackage.Literals.CHECK_CATALOG__PACKAGE_NAME, ImageDescriptor.createFromImage(checkImages.forPackage()), catalog.getPackageName(), true);
    }
    if (catalog.getImports() != null && !catalog.getImports().getImportDeclarations().isEmpty()) {
        EStructuralFeatureNode importNode = getOutlineNodeFactory().createEStructuralFeatureNode(parentNode, catalog, CheckPackage.Literals.CHECK_CATALOG__IMPORTS, ImageDescriptor.createFromImage(checkImages.forImportContainer()), "Import declarations", false);
        for (final org.eclipse.xtext.xtype.XImportDeclaration imported : catalog.getImports().getImportDeclarations()) {
            createNode(importNode, imported);
        }
    }
    EObjectNode catalogNode = createNode(parentNode, catalog);
    for (final Category category : catalog.getCategories()) {
        createNode(catalogNode, category);
    }
    for (final Check check : catalog.getChecks()) {
        createNode(catalogNode, check);
    }
}
Also used : Category(com.avaloq.tools.ddk.check.check.Category) EStructuralFeatureNode(org.eclipse.xtext.ui.editor.outline.impl.EStructuralFeatureNode) Check(com.avaloq.tools.ddk.check.check.Check) CheckCatalog(com.avaloq.tools.ddk.check.check.CheckCatalog) EObjectNode(org.eclipse.xtext.ui.editor.outline.impl.EObjectNode)

Aggregations

CheckCatalog (com.avaloq.tools.ddk.check.check.CheckCatalog)17 IPluginElement (org.eclipse.pde.core.plugin.IPluginElement)4 IPluginExtension (org.eclipse.pde.core.plugin.IPluginExtension)4 Test (org.junit.Test)4 Check (com.avaloq.tools.ddk.check.check.Check)3 ConfiguredCatalog (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCatalog)3 ConfiguredCheck (com.avaloq.tools.ddk.checkcfg.checkcfg.ConfiguredCheck)3 FormalParameter (com.avaloq.tools.ddk.check.check.FormalParameter)2 CheckConfiguration (com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration)2 Function (com.google.common.base.Function)2 CoreException (org.eclipse.core.runtime.CoreException)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)2 Template (org.eclipse.jface.text.templates.Template)2 TemplateProposal (org.eclipse.jface.text.templates.TemplateProposal)2 IPluginObject (org.eclipse.pde.core.plugin.IPluginObject)2 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)2 Check (org.eclipse.xtext.validation.Check)2 Category (com.avaloq.tools.ddk.check.check.Category)1