コード例 #1
0
 /**
  * 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);
 }
コード例 #2
0
 /** @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);
   }
 }
コード例 #3
0
 protected void reportUnusedElement(Element element, int severity) {
   Node parent = element.getParentNode();
   report(
       NLS.bind(
           MDECoreMessages.Builders_Manifest_unused_element,
           (new String[] {element.getNodeName(), parent.getNodeName()})),
       getLine(element),
       severity,
       MDEMarkerFactory.CAT_OTHER);
 }
コード例 #4
0
 private void validateInstallHandler(Element element) {
   NodeList elements = getChildrenByName(element, "install-handler"); // $NON-NLS-1$
   if (elements.getLength() > 0) {
     if (fMonitor.isCanceled()) return;
     Element handler = (Element) elements.item(0);
     NamedNodeMap attributes = handler.getAttributes();
     for (int i = 0; i < attributes.getLength(); i++) {
       String name = attributes.item(i).getNodeName();
       if (!name.equals("library") && !name.equals("handler")) // $NON-NLS-1$ //$NON-NLS-2$
       reportUnknownAttribute(handler, name, CompilerFlags.ERROR);
     }
     reportExtraneousElements(elements, 1);
   }
 }
コード例 #5
0
  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);
    }
  }
コード例 #6
0
 protected void validateTranslatableElementContent(Element element) {
   int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_NOT_EXTERNALIZED);
   if (severity == CompilerFlags.IGNORE) return;
   String value = getTextContent(element);
   if (value == null) return;
   if (!value.startsWith("%")) { // $NON-NLS-1$
     report(
         NLS.bind(MDECoreMessages.Builders_Manifest_non_ext_element, element.getNodeName()),
         getLine(element),
         severity,
         MDEMarkerFactory.P_UNTRANSLATED_NODE,
         element,
         null,
         MDEMarkerFactory.CAT_NLS);
   } else if (fModel instanceof AbstractNLModel) {
     NLResourceHelper helper = ((AbstractNLModel) fModel).getNLResourceHelper();
     if (helper == null || !helper.resourceExists(value)) {
       report(
           NLS.bind(MDECoreMessages.Builders_Manifest_key_not_found, value.substring(1)),
           getLine(element),
           severity,
           MDEMarkerFactory.CAT_NLS);
     }
   }
 }
コード例 #7
0
 /**
  * @param parentElement
  * @param childElement
  * @param severity
  */
 private void reportMaxOccurenceViolation(ElementOccurrenceResult result, int severity) {
   Element childElement = result.getElement();
   String allowedOccurrences = new Integer(result.getAllowedOccurrences()).toString();
   String message =
       NLS.bind(
           MDECoreMessages.ExtensionsErrorReporter_maxOccurrence,
           new String[] {allowedOccurrences, childElement.getNodeName()});
   report(
       message,
       getLine(childElement),
       severity,
       MDEMarkerFactory.P_ILLEGAL_XML_NODE,
       childElement,
       null,
       MDEMarkerFactory.CAT_FATAL);
 }
コード例 #8
0
 private void validateUpdateURL(Element parent) {
   NodeList list = getChildrenByName(parent, "update"); // $NON-NLS-1$
   if (list.getLength() > 0) {
     if (fMonitor.isCanceled()) return;
     Element update = (Element) list.item(0);
     assertAttributeDefined(update, "url", CompilerFlags.ERROR); // $NON-NLS-1$
     NamedNodeMap attributes = update.getAttributes();
     for (int i = 0; i < attributes.getLength(); i++) {
       String name = attributes.item(i).getNodeName();
       if (name.equals("url")) { // $NON-NLS-1$
         validateURL(update, "url"); // $NON-NLS-1$
       } else if (!name.equals("label")) { // $NON-NLS-1$
         reportUnknownAttribute(update, name, CompilerFlags.ERROR);
       }
     }
     reportExtraneousElements(list, 1);
   }
 }
コード例 #9
0
 private void validateDescription(Element parent) {
   NodeList list = getChildrenByName(parent, "description"); // $NON-NLS-1$
   if (list.getLength() > 0) {
     if (fMonitor.isCanceled()) return;
     Element element = (Element) list.item(0);
     validateElementWithContent((Element) list.item(0), true);
     NamedNodeMap attributes = element.getAttributes();
     for (int i = 0; i < attributes.getLength(); i++) {
       Attr attr = (Attr) attributes.item(i);
       String name = attr.getName();
       if (name.equals("url")) { // $NON-NLS-1$
         validateURL(element, name);
       } else {
         reportUnknownAttribute(element, name, CompilerFlags.ERROR);
       }
     }
     reportExtraneousElements(list, 1);
   }
 }
コード例 #10
0
 protected void reportDeprecatedElement(Element element) {
   int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_DEPRECATED);
   if (severity != CompilerFlags.IGNORE) {
     report(
         NLS.bind(MDECoreMessages.Builders_Manifest_deprecated_element, element.getNodeName()),
         getLine(element),
         severity,
         MDEMarkerFactory.CAT_DEPRECATION);
   }
 }
コード例 #11
0
 /* (non-Javadoc)
  * @see org.eclipse.pde.internal.builders.XMLErrorReporter#validateContent(org.eclipse.core.runtime.IProgressMonitor)
  */
 public void validateContent(IProgressMonitor monitor) {
   fMonitor = monitor;
   Element element = getDocumentRoot();
   if (element == null) return;
   String elementName = element.getNodeName();
   if (!"feature".equals(elementName)) { // $NON-NLS-1$
     reportIllegalElement(element, CompilerFlags.ERROR);
   } else {
     validateFeatureAttributes(element);
     validateInstallHandler(element);
     validateDescription(element);
     validateLicense(element);
     validateCopyright(element);
     validateURLElement(element);
     validateIncludes(element);
     validateRequires(element);
     validatePlugins(element);
     validateData(element);
   }
 }
コード例 #12
0
  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);
        }
      }
    }
  }
コード例 #13
0
 private void validateData(Element parent) {
   NodeList list = getChildrenByName(parent, "data"); // $NON-NLS-1$
   for (int i = 0; i < list.getLength(); i++) {
     if (fMonitor.isCanceled()) return;
     Element data = (Element) list.item(i);
     assertAttributeDefined(data, "id", CompilerFlags.ERROR); // $NON-NLS-1$
     NamedNodeMap attributes = data.getAttributes();
     for (int j = 0; j < attributes.getLength(); j++) {
       Attr attr = (Attr) attributes.item(j);
       String name = attr.getName();
       if (!name.equals("id")
           && !name.equals("os")
           && !name.equals("ws") // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
           && !name.equals("nl")
           && !name.equals("arch") // $NON-NLS-1$ //$NON-NLS-2$
           && !name.equals("download-size")
           && !name.equals("install-size")) { // $NON-NLS-1$ //$NON-NLS-2$
         reportUnknownAttribute(data, name, CompilerFlags.ERROR);
       }
     }
   }
 }
コード例 #14
0
 private void validateImports(Element parent) {
   NodeList list = getChildrenByName(parent, "import"); // $NON-NLS-1$
   for (int i = 0; i < list.getLength(); i++) {
     if (fMonitor.isCanceled()) return;
     Element element = (Element) list.item(i);
     Attr plugin = element.getAttributeNode("plugin"); // $NON-NLS-1$
     Attr feature = element.getAttributeNode("feature"); // $NON-NLS-1$
     if (plugin == null && feature == null) {
       assertAttributeDefined(element, "plugin", CompilerFlags.ERROR); // $NON-NLS-1$
     } else if (plugin != null && feature != null) {
       reportExclusiveAttributes(
           element, "plugin", "feature", CompilerFlags.ERROR); // $NON-NLS-1$//$NON-NLS-2$
     } else if (plugin != null) {
       validatePluginID(element, plugin, false);
     } else if (feature != null) {
       validateFeatureID(element, feature);
     }
     NamedNodeMap attributes = element.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(element, attr);
       } else if (name.equals("match")) { // $NON-NLS-1$
         if (element.getAttributeNode("patch") != null) { // $NON-NLS-1$
           report(
               NLS.bind(MDECoreMessages.Builders_Feature_patchedMatch, attr.getValue()),
               getLine(element, attr.getValue()),
               CompilerFlags.ERROR,
               MDEMarkerFactory.CAT_FATAL);
         } else {
           validateMatch(element, attr);
         }
       } else if (name.equals("patch")) { // $NON-NLS-1$
         if ("true".equalsIgnoreCase(attr.getValue()) && feature == null) { // $NON-NLS-1$
           report(
               NLS.bind(MDECoreMessages.Builders_Feature_patchPlugin, attr.getValue()),
               getLine(element, attr.getValue()),
               CompilerFlags.ERROR,
               MDEMarkerFactory.CAT_FATAL);
         } else if ("true".equalsIgnoreCase(attr.getValue())
             && element.getAttributeNode("version") == null) { // $NON-NLS-1$ //$NON-NLS-2$
           report(
               NLS.bind(MDECoreMessages.Builders_Feature_patchedVersion, attr.getValue()),
               getLine(element, attr.getValue()),
               CompilerFlags.ERROR,
               MDEMarkerFactory.CAT_FATAL);
         } else {
           validateBoolean(element, attr);
         }
       } else if (!name.equals("plugin")
           && !name.equals("feature")
           && !name.equals("filter")) { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
         reportUnknownAttribute(element, name, CompilerFlags.ERROR);
       }
     }
   }
 }
コード例 #15
0
 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);
       }
     }
   }
 }
コード例 #16
0
  private void validateRequiredExtensionAttributes(Element element, ISchemaElement schemaElement) {
    int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_NO_REQUIRED_ATT);
    if (severity == CompilerFlags.IGNORE) return;

    ISchemaAttribute[] attInfos = schemaElement.getAttributes();
    for (int i = 0; i < attInfos.length; i++) {
      ISchemaAttribute attInfo = attInfos[i];
      if (attInfo.getUse() == ISchemaAttribute.REQUIRED) {
        boolean found = element.getAttributeNode(attInfo.getName()) != null;
        if (!found && attInfo.getKind() == IMetaAttribute.JAVA) {
          NodeList children = element.getChildNodes();
          for (int j = 0; j < children.getLength(); j++) {
            if (attInfo.getName().equals(children.item(j).getNodeName())) {
              found = true;
              break;
            }
          }
        }
        if (!found) {
          reportMissingRequiredAttribute(element, attInfo.getName(), severity);
        }
      }
    }
  }
コード例 #17
0
 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$
   }
 }
コード例 #18
0
  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$
      }
    }
  }
コード例 #19
0
 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);
     }
   }
 }
コード例 #20
0
  public void validateContent(IProgressMonitor monitor) {
    Element element = getDocumentRoot();
    if (element == null) return;
    String elementName = element.getNodeName();
    if (!"plugin".equals(elementName)
        && !"fragment".equals(elementName)) { // $NON-NLS-1$ //$NON-NLS-2$
      reportIllegalElement(element, CompilerFlags.ERROR);
    } else {
      int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_DEPRECATED);
      if (severity != CompilerFlags.IGNORE) {
        NamedNodeMap attrs = element.getAttributes();
        for (int i = 0; i < attrs.getLength(); i++) {
          reportUnusedAttribute(element, attrs.item(i).getNodeName(), severity);
        }
      }

      NodeList children = element.getChildNodes();
      for (int i = 0; i < children.getLength(); i++) {
        if (monitor.isCanceled()) break;
        Element child = (Element) children.item(i);
        String name = child.getNodeName();
        if (name.equals("extension")) { // $NON-NLS-1$
          validateExtension(child);
        } else if (name.equals("extension-point")) { // $NON-NLS-1$
          validateExtensionPoint(child);
        } else {
          if (!name.equals("runtime") && !name.equals("requires")) { // $NON-NLS-1$ //$NON-NLS-2$
            severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT);
            if (severity != CompilerFlags.IGNORE) reportIllegalElement(child, severity);
          } else {
            severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_DEPRECATED);
            if (severity != CompilerFlags.IGNORE) reportUnusedElement(child, severity);
          }
        }
      }

      IExtensions extensions = fModel.getExtensions();
      if (extensions != null
          && extensions.getExtensions().length == 0
          && extensions.getExtensionPoints().length == 0)
        report(
            MDECoreMessages.Builders_Manifest_useless_file,
            -1,
            IMarker.SEVERITY_WARNING,
            MDEMarkerFactory.P_USELESS_FILE,
            MDEMarkerFactory.CAT_OTHER);
    }
  }
コード例 #21
0
 private void validateFeatureAttributes(Element element) {
   if (fMonitor.isCanceled()) return;
   assertAttributeDefined(element, "id", CompilerFlags.ERROR); // $NON-NLS-1$
   assertAttributeDefined(element, "version", CompilerFlags.ERROR); // $NON-NLS-1$
   NamedNodeMap attributes = element.getAttributes();
   for (int i = 0; i < attributes.getLength(); i++) {
     String name = attributes.item(i).getNodeName();
     if (!attrs.contains(name)) {
       reportUnknownAttribute(element, name, CompilerFlags.ERROR);
     } else if (name.equals("id")) { // $NON-NLS-1$
       validatePluginID(element, (Attr) attributes.item(i));
     } else if (name.equals("primary") || name.equals("exclusive")) { // $NON-NLS-1$ //$NON-NLS-2$
       validateBoolean(element, (Attr) attributes.item(i));
     } else if (name.equals("version")) { // $NON-NLS-1$
       validateVersionAttribute(element, (Attr) attributes.item(i));
     }
     if (name.equals("primary")) { // $NON-NLS-1$
       reportDeprecatedAttribute(element, (Attr) attributes.item(i));
     } else if (name.equals("plugin")) { // $NON-NLS-1$
       validatePluginID(element, (Attr) attributes.item(i), false);
     }
   }
 }
コード例 #22
0
  protected void validateExtensionPoint(Element element) {
    if (assertAttributeDefined(element, "id", CompilerFlags.ERROR)) { // $NON-NLS-1$
      Attr idAttr = element.getAttributeNode("id"); // $NON-NLS-1$
      double schemaVersion = getSchemaVersion();
      String message = null;
      if (schemaVersion < 3.2 && !IdUtil.isValidSimpleID(idAttr.getValue()))
        message = NLS.bind(MDECoreMessages.Builders_Manifest_simpleID, idAttr.getValue());
      else if (schemaVersion >= 3.2) {
        if (!IdUtil.isValidCompositeID(idAttr.getValue())) {
          message = NLS.bind(MDECoreMessages.Builders_Manifest_compositeID, idAttr.getValue());
        }
      }

      if (message != null)
        report(
            message,
            getLine(element, idAttr.getName()),
            CompilerFlags.WARNING,
            MDEMarkerFactory.CAT_OTHER);
    }

    assertAttributeDefined(element, "name", CompilerFlags.ERROR); // $NON-NLS-1$

    int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ATTRIBUTE);
    NamedNodeMap attrs = element.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
      Attr attr = (Attr) attrs.item(i);
      String name = attr.getName();
      if ("name".equals(name)) { // $NON-NLS-1$
        validateTranslatableString(element, attr, true);
      } else if (!"id".equals(name)
          && !"schema".equals(name)
          && severity != CompilerFlags.IGNORE) { // $NON-NLS-1$ //$NON-NLS-2$
        reportUnknownAttribute(element, name, severity);
      }
    }

    severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT);
    if (severity != CompilerFlags.IGNORE) {
      NodeList children = element.getChildNodes();
      for (int i = 0; i < children.getLength(); i++)
        reportIllegalElement((Element) children.item(i), severity);
    }

    // Validate the "schema" attribute of the extension point
    Attr attr = element.getAttributeNode(IMonitorExtensionPoint.P_SCHEMA);
    // Only validate the attribute if it was defined
    if (attr != null) {
      String schemaValue = attr.getValue();
      IResource res = getFile().getProject().findMember(schemaValue);
      String errorMessage = null;
      // Check to see if the value specified is an extension point schema and it exists
      if (!(res instanceof IFile
          && (res.getName().endsWith(".exsd")
              || //$NON-NLS-1$
              res.getName().endsWith(".mxsd")))) // $NON-NLS-1$
      errorMessage = MDECoreMessages.ExtensionsErrorReporter_InvalidSchema;
      // Report an error if one was found
      if (errorMessage != null) {
        severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_RESOURCE);
        if (severity != CompilerFlags.IGNORE)
          report(
              NLS.bind(errorMessage, schemaValue),
              getLine(element),
              severity,
              MDEMarkerFactory.CAT_OTHER);
      }
    }
  }
コード例 #23
0
  protected void validateElement(Element element, ISchema schema, boolean isTopLevel) {
    String elementName = element.getNodeName();
    ISchemaElement schemaElement = schema.findElement(elementName);

    // Validate element occurrence violations
    if ((schemaElement != null) && (schemaElement.getType() instanceof ISchemaComplexType)) {
      validateMaxElementMult(element, schemaElement);
      validateMinElementMult(element, schemaElement);
    }

    ISchemaElement parentSchema = null;
    if (!"extension".equals(elementName)) { // $NON-NLS-1$
      Node parent = element.getParentNode();
      parentSchema = schema.findElement(parent.getNodeName());
    } else if (isTopLevel == false) {
      // This is an "extension" element; but, not a top level one.
      // It is nested within another "extension" element somewhere
      // e.g. "extension" element is a child element of another element
      // that is not a "plugin" elment
      // element
      // Report illegal element
      int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT);
      reportIllegalElement(element, severity);
      return;
    }

    if (parentSchema != null) {
      int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT);
      if (severity != CompilerFlags.IGNORE) {
        HashSet allowedElements = new HashSet();
        computeAllowedElements(parentSchema.getType(), allowedElements);
        if (!allowedElements.contains(elementName)) {
          reportIllegalElement(element, severity);
          return;
        }
      }
    }
    if (schemaElement == null && parentSchema != null) {
      ISchemaAttribute attr = parentSchema.getAttribute(elementName);
      if (attr != null && attr.getKind() == IMetaAttribute.JAVA) {
        if (attr.isDeprecated())
          reportDeprecatedAttribute(element, element.getAttributeNode("class")); // $NON-NLS-1$
        validateJavaAttribute(element, element.getAttributeNode("class")); // $NON-NLS-1$			
      }
    } else {
      if (schemaElement != null) {
        validateRequiredExtensionAttributes(element, schemaElement);
        validateExistingExtensionAttributes(element, element.getAttributes(), schemaElement);
        validateInternalExtensionAttribute(element, schemaElement);
        if (schemaElement.isDeprecated()) {
          if (schemaElement instanceof ISchemaRootElement)
            reportDeprecatedRootElement(
                element, ((ISchemaRootElement) schemaElement).getDeprecatedSuggestion());
          else reportDeprecatedElement(element);
        }
        if (schemaElement.hasTranslatableContent()) validateTranslatableElementContent(element);
        // Bug 213457 - look up elements based on the schema in which the parent is found
        schema = schemaElement.getSchema();
      }
      NodeList children = element.getChildNodes();
      for (int i = 0; i < children.getLength(); i++) {
        validateElement((Element) children.item(i), schema, false);
      }
    }
  }