Search in sources :

Example 1 with IPluginModelBase

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

the class CheckMarkerHelpExtensionHelper method getPluginId.

/**
 * Gets the plugin id of the project.
 *
 * @param extension
 *          the extension
 * @return the plugin id
 */
private String getPluginId(final IPluginExtension extension) {
    // TODO if marker help extensions used the ID attribute, it would be possible to find the extension
    // contributor using Platform.getExtensionRegistry.findExtension(extension.getId()).getContributor().getName()
    // or similar; that would be more elegant. PluginRegistry#findModel(IProject) is expensive!
    IResource file = extension.getModel().getUnderlyingResource();
    if (file.getProject() == null) {
        return null;
    }
    IPluginModelBase pluginModel = PluginRegistry.findModel(file.getProject());
    return pluginModel != null ? pluginModel.getPluginBase().getId() : null;
}
Also used : IPluginModelBase(org.eclipse.pde.core.plugin.IPluginModelBase) IResource(org.eclipse.core.resources.IResource)

Example 2 with IPluginModelBase

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

the class CheckMarkerHelpExtensionTest method createMarkerHelpExtension.

/**
 * Creates a marker help extension.
 *
 * @param catalog
 *          the catalog to create the extension for
 * @return the plugin extension
 * @throws CoreException
 *           the core exception
 */
private IPluginExtension createMarkerHelpExtension(final CheckCatalog catalog) throws CoreException {
    IFile pluginxml = workspace.getRoot().getFile(new Path("/test/plugin.xml"));
    IPluginModelBase pluginModel = new WorkspacePluginModel(pluginxml, false);
    return markerUtil.addExtensionToPluginBase(pluginModel, catalog, ExtensionType.CONTEXTS, null);
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IPluginModelBase(org.eclipse.pde.core.plugin.IPluginModelBase) WorkspacePluginModel(org.eclipse.pde.internal.core.plugin.WorkspacePluginModel)

Example 3 with IPluginModelBase

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

the class CheckExtensionGenerator method updateExtensions.

/**
 * Modifies an existing <code>plugin.xml</code> file.
 *
 * @param pluginXmlFile
 *          the plugin.xml file to modify
 * @param catalog
 *          the check catalog
 * @param monitor
 *          progress monitor
 * @throws CoreException
 *           if an error occurred while modifying the plugin.xml file
 * @see org.eclipse.pde.internal.ui.wizards.product.ProductIntroOperation
 */
private void updateExtensions(final IFile pluginXmlFile, final CheckCatalog catalog, final IProgressMonitor monitor) throws CoreException {
    // null means don't contact me...
    IStatus status = PDEPlugin.getWorkspace().validateEdit(new IFile[] { pluginXmlFile }, null);
    if (!status.isOK()) {
        throw new CoreException(new Status(IStatus.ERROR, Activator.getPluginId(), IStatus.ERROR, "Could not update plugin extensions", null));
    }
    if (!STANDARD_PLUGIN_FILENAME.equals(pluginXmlFile.getName())) {
        WorkspacePluginModel pluginModel = new CheckWorkspacePluginModel(pluginXmlFile, false);
        IPluginBase base = pluginModel.getPluginBase();
        base.setSchemaVersion(TargetPlatformHelper.getSchemaVersion());
        pluginModel.load();
        manager.updateExtensions(catalog, pluginModel, monitor);
        manager.addExtensions(catalog, pluginModel, monitor);
        manager.sortAllExtensions(pluginModel, monitor);
        pluginModel.save();
    } else {
        final ModelModification modification = new ModelModification(pluginXmlFile) {

            @Override
            protected void modifyModel(final IBaseModel model, final IProgressMonitor monitor) throws CoreException {
                // NOPMD NPath complexity
                if (!(model instanceof IPluginModelBase)) {
                    return;
                }
                IPluginModelBase pluginModel = (IPluginModelBase) model;
                manager.updateExtensions(catalog, pluginModel, monitor);
                manager.addExtensions(catalog, pluginModel, monitor);
                manager.sortAllExtensions(pluginModel, monitor);
            }

            @Override
            public boolean saveOpenEditor() {
                // do nothing with any open editor...
                return false;
            }
        };
        modifyModel(modification, monitor);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IBaseModel(org.eclipse.pde.core.IBaseModel) IStatus(org.eclipse.core.runtime.IStatus) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IPluginBase(org.eclipse.pde.core.plugin.IPluginBase) CoreException(org.eclipse.core.runtime.CoreException) ModelModification(org.eclipse.pde.internal.ui.util.ModelModification) IPluginModelBase(org.eclipse.pde.core.plugin.IPluginModelBase) WorkspacePluginModel(org.eclipse.pde.internal.core.plugin.WorkspacePluginModel)

Example 4 with IPluginModelBase

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

the class CheckExtensionGenerator method removeExtensions.

/**
 * Removes extensions registered for a check catalog. This operation has extension point specific behavior.
 * Validator, quickfix and preference extensions can safely be removed without any checking. The marker help
 * extension, however, contains elements from all catalogs of current project. Therefore only elements belonging
 * to given catalog may be removed, and not the whole extension. Table of contents and contexts extensions are
 * never removed once created - they are not catalog specific and do not harm.
 *
 * @param file
 *          the plugin.xml file to be modified
 * @param object
 *          the object
 * @param monitor
 *          a progress monitor
 * @throws CoreException
 *           if the file is read-only and cannot be edited
 */
private void removeExtensions(final IFile file, final Object object, final IProgressMonitor monitor) throws CoreException {
    // null means don't contact me...
    IStatus status = PDEPlugin.getWorkspace().validateEdit(new IFile[] { file }, null);
    if (status.getSeverity() != IStatus.OK) {
        throw new CoreException(new Status(IStatus.ERROR, Activator.getPluginId(), IStatus.ERROR, "Could not remove plugin extensions", null));
    }
    if (!STANDARD_PLUGIN_FILENAME.equals(file.getName())) {
        WorkspacePluginModel pluginModel = new CheckWorkspacePluginModel(file, false);
        IPluginBase base = pluginModel.getPluginBase();
        base.setSchemaVersion(TargetPlatformHelper.getSchemaVersion());
        pluginModel.load();
        if (object instanceof IEObjectDescription) {
            // called when catalog is deleted
            manager.removeExtensions((IEObjectDescription) object, pluginModel, monitor);
        } else if (object instanceof CheckCatalog) {
            // called in order to remove extensions in an invalid model
            manager.removeExtensions((CheckCatalog) object, pluginModel, monitor);
        }
        pluginModel.save();
    } else {
        final ModelModification mod = new ModelModification(file) {

            @Override
            protected void modifyModel(final IBaseModel model, final IProgressMonitor monitor) throws CoreException {
                if (!(model instanceof IPluginModelBase)) {
                    return;
                }
                IPluginModelBase pluginModel = (IPluginModelBase) model;
                if (object instanceof IEObjectDescription) {
                    // called when catalog is deleted
                    manager.removeExtensions((IEObjectDescription) object, pluginModel, monitor);
                } else if (object instanceof CheckCatalog) {
                    // called in order to remove extensions in an invalid model
                    manager.removeExtensions((CheckCatalog) object, pluginModel, monitor);
                }
            }

            @Override
            public boolean saveOpenEditor() {
                // prevent modifications to open plugin manifest editor; the editor will become dirty once the modification is performed
                return false;
            }
        };
        modifyModel(mod, monitor);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IBaseModel(org.eclipse.pde.core.IBaseModel) IStatus(org.eclipse.core.runtime.IStatus) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IPluginBase(org.eclipse.pde.core.plugin.IPluginBase) CoreException(org.eclipse.core.runtime.CoreException) ModelModification(org.eclipse.pde.internal.ui.util.ModelModification) CheckCatalog(com.avaloq.tools.ddk.check.check.CheckCatalog) IPluginModelBase(org.eclipse.pde.core.plugin.IPluginModelBase) WorkspacePluginModel(org.eclipse.pde.internal.core.plugin.WorkspacePluginModel) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Aggregations

IPluginModelBase (org.eclipse.pde.core.plugin.IPluginModelBase)4 WorkspacePluginModel (org.eclipse.pde.internal.core.plugin.WorkspacePluginModel)3 CoreException (org.eclipse.core.runtime.CoreException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 IBaseModel (org.eclipse.pde.core.IBaseModel)2 IPluginBase (org.eclipse.pde.core.plugin.IPluginBase)2 ModelModification (org.eclipse.pde.internal.ui.util.ModelModification)2 CheckCatalog (com.avaloq.tools.ddk.check.check.CheckCatalog)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 Path (org.eclipse.core.runtime.Path)1 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)1