Search in sources :

Example 26 with IPluginExtension

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

the class CheckExtensionHelperManager method removeExtensions.

/**
 * Removes the extensions. Is called when the catalog still exists (it has not been deleted) and plugin extensions which no longer correspond
 * to the model exist. This is the case if the model becomes invalid. Extensions are then removed from the plugin model.
 *
 * @param catalog
 *          the catalog
 * @param pluginModel
 *          the plugin model
 * @param monitor
 *          the monitor
 * @throws CoreException
 *           the core exception
 */
public void removeExtensions(final CheckCatalog catalog, final IPluginModelBase pluginModel, final IProgressMonitor monitor) throws CoreException {
    QualifiedName name = nameConverter.toQualifiedName(projectUtil.getCatalogQualifiedName(catalog));
    for (IPluginExtension extension : findExtensions(pluginModel, name, ExtensionType.ALL)) {
        final ExtensionType extensionType = getExtensionType(extension);
        getExtensionHelper(extensionType).removeExtensionFromPluginBase(pluginModel, extension, catalog, extensionType);
    }
}
Also used : IPluginExtension(org.eclipse.pde.core.plugin.IPluginExtension) QualifiedName(org.eclipse.xtext.naming.QualifiedName)

Example 27 with IPluginExtension

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

the class CheckExtensionHelperManager method sortAllExtensions.

/**
 * Sorts the plug-in extensions alphabetically by extension point ID and then by extension ID (and name in case the IDs are equal or null).
 *
 * @param pluginModel
 *          the plugin model
 * @param monitor
 *          the monitor
 * @throws CoreException
 *           the core exception
 */
public void sortAllExtensions(final IPluginModelBase pluginModel, final IProgressMonitor monitor) throws CoreException {
    Ordering<IPluginExtension> ordering = Ordering.from((a, b) -> ComparisonChain.start().compare(a.getPoint(), b.getPoint()).compare(a.getId(), b.getId(), Ordering.natural().nullsLast()).compare(a.getName(), b.getName(), Ordering.natural().nullsLast()).result());
    List<IPluginExtension> catalogExtensions = Lists.newArrayList(findAllExtensions(pluginModel));
    List<IPluginExtension> orderedExtensions = ordering.sortedCopy(catalogExtensions);
    if (catalogExtensions.equals(orderedExtensions)) {
        return;
    }
    for (int i = 0; i < orderedExtensions.size(); i++) {
        IPluginExtension expected = orderedExtensions.get(i);
        IPluginExtension actual = catalogExtensions.get(i);
        if (!Objects.equals(actual, expected)) {
            // pluginModel.getExtensions().swap(expected, actual);
            for (int j = i; j < catalogExtensions.size(); j++) {
                pluginModel.getExtensions().remove(catalogExtensions.get(j));
            }
            for (int j = i; j < orderedExtensions.size(); j++) {
                pluginModel.getExtensions().add(orderedExtensions.get(j));
            }
            break;
        }
    }
}
Also used : IPluginExtension(org.eclipse.pde.core.plugin.IPluginExtension)

Aggregations

IPluginExtension (org.eclipse.pde.core.plugin.IPluginExtension)27 IPluginElement (org.eclipse.pde.core.plugin.IPluginElement)19 Test (org.junit.Test)12 CheckCatalog (com.avaloq.tools.ddk.check.check.CheckCatalog)4 IPluginObject (org.eclipse.pde.core.plugin.IPluginObject)3 QualifiedName (org.eclipse.xtext.naming.QualifiedName)3 XIssueExpression (com.avaloq.tools.ddk.check.check.XIssueExpression)1