/**
  * Validates that the version of the given plug-in is available in the registry. Adds a warning if
  * the plug-in could not be found.
  *
  * @param plugin xml element describing the plug-in to look for in the registry
  * @param attr set of element attributes
  */
 private void validateVersion(Element plugin, Attr attr) {
   String id = plugin.getAttribute("id"); // $NON-NLS-1$
   String version = plugin.getAttribute("version"); // $NON-NLS-1$
   if (id.trim().length() == 0
       || version.trim().length() == 0
       || version.equals("0.0.0")) // $NON-NLS-1$
   return;
   ModelEntry entry = MonitorRegistry.findEntry(id);
   if (entry != null) {
     IMonitorModelBase[] allModels = entry.getActiveModels();
     for (int i = 0; i < allModels.length; i++) {
       IMonitorModelBase availablePlugin = allModels[i];
       if (id.equals(availablePlugin.getMonitorBase().getId())) {
         if (version.equals(availablePlugin.getMonitorBase().getVersion())) {
           return;
         }
       }
     }
   }
   report(
       NLS.bind(
           MDECoreMessages.Builders_Feature_mismatchPluginVersion, new String[] {version, id}),
       getLine(plugin, attr.getName()),
       CompilerFlags.WARNING,
       MDEMarkerFactory.CAT_OTHER);
 }
  private void validateUnpack(Element parent) {
    int severity = CompilerFlags.getFlag(fProject, CompilerFlags.F_UNRESOLVED_PLUGINS);
    if (severity == CompilerFlags.IGNORE) {
      return;
    }
    if (severity == CompilerFlags.ERROR) {
      // this might not be an error, so max the flag at WARNING level.
      severity = CompilerFlags.WARNING;
    }
    String unpack = parent.getAttribute("unpack"); // $NON-NLS-1$
    IMonitorModelBase pModel = MonitorRegistry.findModel(parent.getAttribute("id")); // $NON-NLS-1$
    if (pModel == null) {
      return;
    }

    if (pModel instanceof IBundlePluginModel) {
      IBundlePluginModel bModel = (IBundlePluginModel) pModel;
      IManifestHeader header =
          bModel
              .getBundleModel()
              .getBundle()
              .getManifestHeader(ICoreConstants.ECLIPSE_BUNDLE_SHAPE);
      if (header != null) {
        String value = header.getValue();
        String unpackValue =
            "true".equals(unpack) ? "jar" : "dir"; // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        if (value != null && !value.equalsIgnoreCase(unpackValue)) {
          String message =
              NLS.bind(
                  MDECoreMessages.Builders_Feature_mismatchUnpackBundleShape,
                  (new String[] {
                    "unpack=" + unpack, parent.getAttribute("id"), "Eclipse-BundleShape: " + value
                  })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
          report(message, getLine(parent), severity, MDEMarkerFactory.CAT_OTHER);
        }
      }
    }

    if ("true".equals(unpack)
        && !CoreUtility.guessUnpack(pModel.getBundleDescription())) { // $NON-NLS-1$
      String message =
          NLS.bind(
              MDECoreMessages.Builders_Feature_missingUnpackFalse,
              (new String[] {
                parent.getAttribute("id"), "unpack=\"false\""
              })); //$NON-NLS-1$ //$NON-NLS-2$
      report(message, getLine(parent), severity, MDEMarkerFactory.CAT_OTHER);
    }
  }
 /** @param element */
 private void validatePlugins(Element parent) {
   NodeList list = getChildrenByName(parent, "plugin"); // $NON-NLS-1$
   for (int i = 0; i < list.getLength(); i++) {
     if (fMonitor.isCanceled()) return;
     Element plugin = (Element) list.item(i);
     assertAttributeDefined(plugin, "id", CompilerFlags.ERROR); // $NON-NLS-1$
     assertAttributeDefined(plugin, "version", CompilerFlags.ERROR); // $NON-NLS-1$
     NamedNodeMap attributes = plugin.getAttributes();
     boolean isFragment =
         plugin.getAttribute("fragment").equals("true"); // $NON-NLS-1$ //$NON-NLS-2$
     for (int j = 0; j < attributes.getLength(); j++) {
       Attr attr = (Attr) attributes.item(j);
       String name = attr.getName();
       if (name.equals("id")) { // $NON-NLS-1$
         validatePluginID(plugin, attr, isFragment);
       } else if (name.equals("version")) { // $NON-NLS-1$
         validateVersionAttribute(plugin, attr);
         validateVersion(plugin, attr);
       } else if (name.equals("fragment") || name.equals("unpack")) { // $NON-NLS-1$ //$NON-NLS-2$
         validateBoolean(plugin, attr);
       } else if (!name.equals("os")
           && !name.equals("ws")
           && !name.equals("nl") // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
           && !name.equals("arch")
           && !name.equals("download-size") // $NON-NLS-1$ //$NON-NLS-2$
           && !name.equals("install-size")
           && !name.equals("filter")) { // $NON-NLS-1$ //$NON-NLS-2$
         reportUnknownAttribute(plugin, name, CompilerFlags.ERROR);
       }
     }
     validateUnpack(plugin);
   }
 }
 protected void reportDeprecatedRootElement(Element element, String suggestion) {
   int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_DEPRECATED);
   if (severity != CompilerFlags.IGNORE) {
     String point = element.getAttribute("point"); // $NON-NLS-1$
     if (point == null) return; // should never come to this...
     String message;
     if (suggestion != null)
       message =
           NLS.bind(
               MDECoreMessages.Builders_Manifest_deprecated_rootElementSuggestion,
               point,
               suggestion);
     else message = NLS.bind(MDECoreMessages.Builders_Manifest_deprecated_rootElement, point);
     report(
         message,
         getLine(element, "point"),
         severity,
         MDEMarkerFactory.CAT_DEPRECATION); // $NON-NLS-1$
   }
 }
  private void validateInternalExtensionAttribute(Element element, ISchemaElement schemaElement) {
    int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_INTERNAL);
    if (severity == CompilerFlags.IGNORE) return;

    if (schemaElement instanceof ISchemaRootElement) {
      ISchemaRootElement rootElement = (ISchemaRootElement) schemaElement;
      String epid = schemaElement.getSchema().getPluginId();
      String pid = fModel.getMonitorBase().getId();
      if (epid == null || pid == null) return;
      if (rootElement.isInternal() && !epid.equals(pid)) {
        String point = element.getAttribute("point"); // $NON-NLS-1$
        if (point == null) return; // should never come to this...
        report(
            NLS.bind(MDECoreMessages.Builders_Manifest_internal_rootElement, point),
            getLine(element, "point"),
            severity,
            MDEMarkerFactory.CAT_DEPRECATION); // $NON-NLS-1$
      }
    }
  }
 protected void validateExtension(Element element) {
   if (!assertAttributeDefined(element, "point", CompilerFlags.ERROR)) // $NON-NLS-1$
   return;
   String pointID = element.getAttribute("point"); // $NON-NLS-1$
   if (!MDECore.getDefault().getExtensionsRegistry().hasExtensionPoint(pointID)) {
     int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNRESOLVED_EX_POINTS);
     if (severity != CompilerFlags.IGNORE) {
       report(
           NLS.bind(MDECoreMessages.Builders_Manifest_ex_point, pointID),
           getLine(element, "point"),
           severity,
           MDEMarkerFactory.CAT_OTHER); // $NON-NLS-1$
     }
   } else {
     SchemaRegistry reg = MDECore.getDefault().getSchemaRegistry();
     ISchema schema = reg.getSchema(pointID);
     if (schema != null) {
       validateElement(element, schema, true);
     }
   }
 }
  private void validateIncludes(Element parent) {
    NodeList list = getChildrenByName(parent, "includes"); // $NON-NLS-1$
    for (int i = 0; i < list.getLength(); i++) {
      if (fMonitor.isCanceled()) return;
      Element include = (Element) list.item(i);
      if (assertAttributeDefined(include, "id", CompilerFlags.ERROR) // $NON-NLS-1$
          && assertAttributeDefined(
              include,
              "version", //$NON-NLS-1$
              CompilerFlags.ERROR)) {

        validateFeatureID(include, include.getAttributeNode("id")); // $NON-NLS-1$
      }
      NamedNodeMap attributes = include.getAttributes();
      for (int j = 0; j < attributes.getLength(); j++) {
        Attr attr = (Attr) attributes.item(j);
        String name = attr.getName();
        if (name.equals("version")) { // $NON-NLS-1$
          validateVersionAttribute(include, attr);
        } else if (name.equals("optional")) { // $NON-NLS-1$
          validateBoolean(include, attr);
        } else if (name.equals("search-location")) { // $NON-NLS-1$
          String value = include.getAttribute("search-location"); // $NON-NLS-1$
          if (!value.equals("root")
              && !value.equals("self")
              && !value.equals("both")) { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            reportIllegalAttributeValue(include, attr);
          }
        } else if (!name.equals("id")
            && !name.equals("name")
            && !name.equals("os")
            && !name.equals("ws") // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
            && !name.equals("nl")
            && !name.equals("arch")
            && !name.equals("filter")) { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
          reportUnknownAttribute(include, name, CompilerFlags.ERROR);
        }
      }
    }
  }
 private void validateDiscoveryURL(Element parent) {
   NodeList list = getChildrenByName(parent, "discovery"); // $NON-NLS-1$
   if (list.getLength() > 0) {
     if (fMonitor.isCanceled()) return;
     Element discovery = (Element) list.item(0);
     assertAttributeDefined(discovery, "url", CompilerFlags.ERROR); // $NON-NLS-1$
     NamedNodeMap attributes = discovery.getAttributes();
     for (int i = 0; i < attributes.getLength(); i++) {
       String name = attributes.item(i).getNodeName();
       if (name.equals("url")) { // $NON-NLS-1$
         validateURL(discovery, "url"); // $NON-NLS-1$
       } else if (name.equals("type")) { // $NON-NLS-1$
         String value = discovery.getAttribute("type"); // $NON-NLS-1$
         if (!value.equals("web") && !value.equals("update")) { // $NON-NLS-1$ //$NON-NLS-2$
           reportIllegalAttributeValue(discovery, (Attr) attributes.item(i));
         }
         reportDeprecatedAttribute(discovery, discovery.getAttributeNode("type")); // $NON-NLS-1$
       } else if (!name.equals("label")) { // $NON-NLS-1$
         reportUnknownAttribute(discovery, name, CompilerFlags.ERROR);
       }
     }
   }
 }