protected void collectSuites(IPluginModelBase model, Set<String> visited) {
   if (!model.isEnabled()) return;
   BundleDescription description = model.getBundleDescription();
   if (!visited.add(description.getSymbolicName())) return;
   model.addModelChangedListener(this);
   listentingTo.add(model);
   for (IPluginExtension ext : model.getExtensions(true).getExtensions())
     if ("org.xpect.testSuite".equals(ext.getPoint())) {
       for (IPluginObject child : ext.getChildren()) {
         if (child instanceof IPluginElement) {
           IPluginElement pluginElement = (IPluginElement) child;
           IPluginAttribute clazz = pluginElement.getAttribute("class");
           IPluginAttribute fileExtension = pluginElement.getAttribute("fileExtension");
           if (clazz != null && fileExtension != null) {
             LazyClass<Object> lazyClass =
                 LazyClass.create(
                     Object.class, clazz.getValue(), (Function<String, Class<?>>) null);
             TestSuiteInfo info =
                 new TestSuiteInfo(lazyClass, Collections.singleton(fileExtension.getValue()));
             this.extToInfo.put(fileExtension.getValue(), info);
           }
         }
       }
     }
   for (BundleDescription desc : description.getDependents()) {
     collectSuites(PluginRegistry.findModel(desc), visited);
   }
 }
  private void inspectExtension(ISchema schema, IPluginParent parent, IFile file) {
    IPluginObject[] children = parent.getChildren();

    if (parent instanceof PluginElementNode && parent.getParent() instanceof PluginElementNode) {
      // check if this node corresponds to a Java type attribute which would have been defined has
      // an element
      PluginElementNode node = (PluginElementNode) parent;
      PluginElementNode parentNode = (PluginElementNode) parent.getParent();
      ISchemaElement schemaElement = schema.findElement(parentNode.getName());
      if (schemaElement != null) {
        ISchemaAttribute attInfo = schemaElement.getAttribute(node.getName());
        if (attInfo != null && attInfo.getKind() == IMetaAttribute.JAVA)
          checkMatch(node.getAttribute("class"), file); // $NON-NLS-1$
      }
    }

    for (int i = 0; i < children.length; i++) {
      IPluginElement child = (IPluginElement) children[i];
      ISchemaElement schemaElement = schema.findElement(child.getName());
      if (schemaElement != null) {
        IPluginAttribute[] attributes = child.getAttributes();
        for (int j = 0; j < attributes.length; j++) {
          IPluginAttribute attr = attributes[j];
          ISchemaAttribute attInfo = schemaElement.getAttribute(attr.getName());
          if (attInfo != null
              && attInfo.getKind() == IMetaAttribute.JAVA
              && attr instanceof IDocumentAttributeNode) checkMatch(attr, file);
        }
      }
      inspectExtension(schema, child, file);
    }
  }
 private void updateUIDescriptionText(IPluginElement parentElement) {
   IPluginObject pluginObject = parentElement.getChildren()[0];
   if (pluginObject instanceof IPluginElement) {
     IPluginElement element = (IPluginElement) pluginObject;
     if (element.getName().equals(F_CS_ELEMENT_DESCRIPTION)
         && PDETextHelper.isDefinedAfterTrim(element.getText())) {
       // Triggers listener to update data description on load
       fDescriptionText.setText(element.getText().trim());
     }
   }
 }
  private void processCheatSheetElement(IPluginElement parentElement, String generatedID) {
    // Get the id attribute
    IPluginAttribute idAttribute = parentElement.getAttribute(ICompCSConstants.ATTRIBUTE_ID);

    // Check for the generated ID for this cheat sheet
    // If a cheat sheet exists with the generated ID already, read its
    // description and populate the description text accordingly
    if ((idAttribute != null)
        && PDETextHelper.isDefined(idAttribute.getValue())
        && generatedID.equals(idAttribute.getValue())) {
      // Matching cheat sheet extension found
      // Process children if any
      if (parentElement.getChildCount() > 0) {
        // Update the description text widget
        updateUIDescriptionText(parentElement);
      }
      updateUICategoryComboAttribute(parentElement);
    }
  }
 /**
  * Process category elements
  *
  * @param parentElement
  */
 private void updateUICategoryComboElement(IPluginElement parentElement) {
   // Get the id attribute
   IPluginAttribute idAttribute = parentElement.getAttribute(ICompCSConstants.ATTRIBUTE_ID);
   // Get the name attribute
   IPluginAttribute nameAttribute = parentElement.getAttribute(ICompCSConstants.ATTRIBUTE_NAME);
   // Add the category to the combo box only if
   // (1) the category name is defined
   // (2) the category has not already been added to the combo box
   if ((nameAttribute != null)
       && PDETextHelper.isDefined(nameAttribute.getValue())
       && (idAttribute != null)
       && PDETextHelper.isDefined(idAttribute.getValue())
       && (fCategoryTrackerUtil.containsCategoryName(nameAttribute.getValue()) == false)) {
     // TODO: MP: LOW: CompCS: Reference translated value
     fCategoryCombo.add(nameAttribute.getValue());
     // Assocate the category ID with the category name
     fCategoryTrackerUtil.associate(
         idAttribute.getValue(),
         nameAttribute.getValue(),
         CSCategoryTrackerUtil.F_TYPE_OLD_CATEGORY);
   }
 }
 private void processCategoryElements(IPluginExtension[] extensions) {
   // Linear search:  Process all cheat sheet extensions found
   for (int i = 0; i < extensions.length; i++) {
     if (extensions[i].getChildCount() == 0) {
       // Extension has no children, skip to the next extension
       continue;
     }
     IPluginExtension extension = extensions[i];
     IPluginObject[] pluginObjects = extension.getChildren();
     // Process all children
     for (int j = 0; j < pluginObjects.length; j++) {
       if (pluginObjects[j] instanceof IPluginElement) {
         IPluginElement element = (IPluginElement) pluginObjects[j];
         if (element.getName().equals(F_CS_ELEMENT_CATEGORY)) {
           // Category element
           // Update the category combo
           updateUICategoryComboElement(element);
         }
       }
     }
   }
 }
 private void processCheatSheetElements(IPluginExtension[] extensions) {
   // Query cheat sheet extensions for information required to update
   // the description text and category combo widgets
   // Linear search:  Process all cheat sheet extensions found
   for (int i = 0; i < extensions.length; i++) {
     if (extensions[i].getChildCount() == 0) {
       // Extension has no children, skip to the next extension
       continue;
     }
     IPluginExtension extension = extensions[i];
     IPluginObject[] pluginObjects = extension.getChildren();
     // Process all children
     for (int j = 0; j < pluginObjects.length; j++) {
       if (pluginObjects[j] instanceof IPluginElement) {
         IPluginElement element = (IPluginElement) pluginObjects[j];
         if (element.getName().equals(F_CS_ELEMENT_CHEATSHEET)) {
           // Cheat sheet element
           processCheatSheetElement(element, fDataCheatSheetID);
         }
       }
     }
   }
 }
Beispiel #8
0
  @Override
  protected void updateModel(IProgressMonitor monitor) throws CoreException {
    IPluginBase plugin = model.getPluginBase();
    IPluginExtension extension = createExtension(EXTENSION_POINT, true);
    IPluginModelFactory factory = model.getPluginFactory();

    IPluginElement setElement = factory.createElement(extension);
    setElement.setName("plotting_tool_page");
    setElement.setAttribute(
        "class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_CLASS_NAME));
    setElement.setAttribute("id", getStringOption(KEY_EXTENSION_ID));
    setElement.setAttribute("icon", "icons/default.gif");
    setElement.setAttribute("tooltip", getStringOption(KEY_TOOLTIP));
    setElement.setAttribute("label", getStringOption(KEY_EXTENSION_NAME));
    setElement.setAttribute("cheat_sheet_id", getStringOption(KEY_CHEAT_SHEET_ID));
    setElement.setAttribute("visible", "true");
    setElement.setAttribute("category", getStringOption(KEY_CATEGORY));

    extension.add(setElement);
    if (!extension.isInTheModel()) {
      plugin.add(extension);
    }
  }
 /**
  * Process cheatsheet elements with a category attribute
  *
  * @param parentElement
  */
 private void updateUICategoryComboAttribute(IPluginElement element) {
   // Get the category attribute
   IPluginAttribute categoryAttribute = element.getAttribute(F_CS_ELEMENT_CATEGORY);
   // Process the category attribute
   if ((categoryAttribute != null) && PDETextHelper.isDefined(categoryAttribute.getValue())) {
     String id = categoryAttribute.getValue();
     // Check to see if the category ID has been defined
     if (fCategoryTrackerUtil.containsCategoryID(id)) {
       // Update the category combo selection
       String name = fCategoryTrackerUtil.getCategoryName(id);
       fCategoryCombo.setText(name);
     } else {
       // Add the category ID to the combo box (no assoicated name)
       // This can only happen if the category is defined outside of
       // the plug-in the cheat sheet is stored in
       fCategoryCombo.add(id);
       fCategoryCombo.setText(id);
       fCategoryTrackerUtil.associate(id, id, CSCategoryTrackerUtil.F_TYPE_OLD_CATEGORY);
     }
   }
 }
  @Override
  protected UnitCompilerDescriptor createDescriptor(IPluginElement extPointElement) {
    if (extPointElement.getName().equals("unitcompiler")) {
      String instrName = extPointElement.getAttribute("name").getValue();
      String instrClass = extPointElement.getAttribute("class").getValue();

      boolean enabled =
          Boolean.parseBoolean(extPointElement.getAttribute("defaultEnabled").getValue());
      IReportableUnitCompiler.Level defaultLevel = IReportableUnitCompiler.Level.IGNORE;

      try {
        String level = extPointElement.getAttribute("report").getValue();
        defaultLevel = IReportableUnitCompiler.Level.valueOf(level.toUpperCase());
      } catch (Exception e) {
        // noop
      }

      StringBuilder instrDesc = new StringBuilder();
      for (IPluginObject child : extPointElement.getChildren()) {
        IPluginElement childElement = (IPluginElement) child;
        if (childElement.getName().equals("description"))
          instrDesc.append(childElement.getText()).append(" ");
      }

      if (LOGGER.isDebugEnabled())
        LOGGER.debug(
            "Adding extension of unitcompiler from "
                + extPointElement.getPluginBase().getId()
                + " named:"
                + instrName
                + " class:"
                + instrClass
                + " desc:"
                + instrDesc);

      return new UnitCompilerDescriptor(
          extPointElement.getPluginBase().getId(),
          instrName,
          instrClass,
          instrDesc.toString(),
          enabled,
          defaultLevel);
    } else
      throw new IllegalArgumentException(
          "Was expecting unitcompiler tag, got " + extPointElement.getName());
  }
  private void executeAdd(IModelChangeProvider model, Object[] elements) {
    IPluginBase pluginBase = null;
    IBuild build = null;
    IBundleModel bundleModel = null;
    if (model instanceof IPluginModelBase) {
      pluginBase = ((IPluginModelBase) model).getPluginBase();
    } else if (model instanceof IBuildModel) {
      build = ((IBuildModel) model).getBuild();
    } else if (model instanceof IBundleModel) {
      bundleModel = (IBundleModel) model;
    }

    try {
      for (Object element : elements) {
        if (element instanceof IPluginImport) {
          pluginBase.add((IPluginImport) element);
        } else if (element instanceof IPluginLibrary) {
          pluginBase.add((IPluginLibrary) element);
        } else if (element instanceof IPluginExtensionPoint) {
          pluginBase.add((IPluginExtensionPoint) element);
        } else if (element instanceof IPluginExtension) {
          pluginBase.add((IPluginExtension) element);
        } else if (element instanceof IPluginElement) {
          IPluginElement e = (IPluginElement) element;
          Object parent = e.getParent();
          if (parent instanceof PluginLibraryNode && e instanceof PluginElementNode) {
            ((PluginLibraryNode) parent).addContentFilter((PluginElementNode) e);
          } else if (parent instanceof IPluginParent) {
            ((IPluginParent) parent).add(e);
          }
        } else if (element instanceof IBuildEntry) {
          IBuildEntry e = (IBuildEntry) element;
          build.add(e);
        } else if (element instanceof BundleObject) {
          if (element instanceof ImportPackageObject) {
            IManifestHeader header =
                bundleModel.getBundle().getManifestHeader(Constants.IMPORT_PACKAGE);
            if (header != null && header instanceof ImportPackageHeader) {
              ((ImportPackageHeader) header).addPackage((PackageObject) element);
            }
          }
          if (element instanceof RequireBundleObject) {
            IBaseModel aggModel = getEditor().getAggregateModel();
            if (aggModel instanceof BundlePluginModel) {
              BundlePluginModel pluginModel = (BundlePluginModel) aggModel;
              RequireBundleObject requireBundle = (RequireBundleObject) element;
              pluginBase = pluginModel.getPluginBase();
              String elementValue = requireBundle.getValue();
              IPluginImport importNode = null;
              if (pluginModel.getPluginFactory() instanceof BundlePluginModelBase)
                importNode =
                    ((BundlePluginModelBase) pluginModel.getPluginFactory())
                        .createImport(elementValue);
              String version =
                  ((RequireBundleObject) element).getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE);
              IManifestHeader header =
                  bundleModel.getBundle().getManifestHeader(Constants.REQUIRE_BUNDLE);
              int bundleManifestVersion =
                  BundlePluginBase.getBundleManifestVersion(
                      ((RequireBundleHeader) header).getBundle());
              boolean option =
                  (bundleManifestVersion > 1)
                      ? Constants.RESOLUTION_OPTIONAL.equals(
                          requireBundle.getDirective(Constants.RESOLUTION_DIRECTIVE))
                      : "true"
                          .equals(
                              requireBundle.getAttribute(
                                  ICoreConstants.OPTIONAL_ATTRIBUTE)); // $NON-NLS-1$;
              boolean exported =
                  (bundleManifestVersion > 1)
                      ? Constants.VISIBILITY_REEXPORT.equals(
                          requireBundle.getDirective(Constants.VISIBILITY_DIRECTIVE))
                      : "true"
                          .equals(
                              requireBundle.getAttribute(
                                  ICoreConstants.REPROVIDE_ATTRIBUTE)); // $NON-NLS-1$;
              if (importNode != null) {
                importNode.setVersion(version);
                importNode.setOptional(option);
                importNode.setReexported(exported);
              }
              if (pluginBase instanceof BundlePluginBase && importNode != null)
                ((BundlePluginBase) pluginBase).add(importNode);
            }
          }
          if (element instanceof ExportPackageObject) {
            IManifestHeader header =
                bundleModel.getBundle().getManifestHeader(Constants.EXPORT_PACKAGE);
            if (header != null && header instanceof ExportPackageHeader) {
              ((ExportPackageHeader) header).addPackage((PackageObject) element);
            }
          }
        }
      }
    } catch (CoreException e) {
      PDEPlugin.logException(e);
    }
  }
  private void executeRemove(IModelChangeProvider model, Object[] elements) {
    IPluginBase pluginBase = null;
    IBuild build = null;
    IBundleModel bundleModel = null;
    if (model instanceof IPluginModelBase) {
      pluginBase = ((IPluginModelBase) model).getPluginBase();
    } else if (model instanceof IBuildModel) {
      build = ((IBuildModel) model).getBuild();
    } else if (model instanceof IBundleModel) {
      bundleModel = (IBundleModel) model;
    }

    try {
      for (Object element : elements) {
        if (element instanceof IPluginImport) {
          pluginBase.remove((IPluginImport) element);
        } else if (element instanceof IPluginLibrary) {
          pluginBase.remove((IPluginLibrary) element);
        } else if (element instanceof IPluginExtensionPoint) {
          pluginBase.remove((IPluginExtensionPoint) element);
        } else if (element instanceof IPluginExtension) {
          pluginBase.remove((IPluginExtension) element);
        } else if (element instanceof IPluginElement) {
          IPluginElement e = (IPluginElement) element;
          Object parent = e.getParent();
          if (parent instanceof PluginLibraryNode && e instanceof PluginElementNode) {
            ((PluginLibraryNode) parent).removeContentFilter((PluginElementNode) e);
          } else if (parent instanceof IPluginParent) {
            ((IPluginParent) parent).remove(e);
          }
        } else if (element instanceof IBuildEntry) {
          IBuildEntry e = (IBuildEntry) element;
          build.remove(e);
        } else if (element instanceof BundleObject) {
          if (element instanceof ImportPackageObject) {
            IManifestHeader header =
                bundleModel.getBundle().getManifestHeader(Constants.IMPORT_PACKAGE);
            if (header != null && header instanceof ImportPackageHeader) {
              ((ImportPackageHeader) header).removePackage((PackageObject) element);
            }
          }
          if (element instanceof RequireBundleObject) {
            IBaseModel aggModel = getEditor().getAggregateModel();
            if (aggModel instanceof BundlePluginModel) {
              BundlePluginModel mod = (BundlePluginModel) aggModel;
              pluginBase = mod.getPluginBase();
              IPluginImport[] imports = pluginBase.getImports();
              IPluginImport currentImport = null;
              for (IPluginImport pluginImport : imports) {
                String elementValue = ((RequireBundleObject) element).getValue();
                if (pluginImport.getId().equals(elementValue)) {
                  currentImport = pluginImport;
                  break;
                }
              }
              IPluginImport[] plugins = {currentImport};
              if (pluginBase instanceof BundlePluginBase && currentImport != null)
                ((BundlePluginBase) pluginBase).remove(plugins);
            }
          }
          if (element instanceof ExportPackageObject) {
            IManifestHeader header =
                bundleModel.getBundle().getManifestHeader(Constants.EXPORT_PACKAGE);
            if (header != null && header instanceof ExportPackageHeader) {
              ((ExportPackageHeader) header).removePackage((PackageObject) element);
            }
          }
        }
      }
    } catch (CoreException e) {
      PDEPlugin.logException(e);
    }
  }