1 11 package org.eclipse.pde.internal.core.builders; 12 13 import org.eclipse.core.resources.IFile; 14 import org.eclipse.core.runtime.IProgressMonitor; 15 import org.eclipse.osgi.util.NLS; 16 import org.eclipse.pde.core.plugin.IPluginModelBase; 17 import org.eclipse.pde.core.plugin.PluginRegistry; 18 import org.eclipse.pde.internal.core.PDECoreMessages; 19 import org.w3c.dom.Attr ; 20 import org.w3c.dom.Element ; 21 import org.w3c.dom.NodeList ; 22 23 24 public abstract class PluginBaseErrorReporter extends ExtensionsErrorReporter { 25 26 public PluginBaseErrorReporter(IFile file) { 27 super(file); 28 } 29 30 33 public void validateContent(IProgressMonitor monitor) { 34 Element element = getDocumentRoot(); 35 if (element == null) 36 return; 37 String elementName = element.getNodeName(); 38 if (!getRootElementName().equals(elementName)) { 39 reportIllegalElement(element, CompilerFlags.ERROR); 40 } else { 41 validateTopLevelAttributes(element); 42 NodeList children = element.getChildNodes(); 43 for (int i = 0; i < children.getLength(); i++) { 44 if (monitor.isCanceled()) 45 break; 46 Element child = (Element )children.item(i); 47 String name = child.getNodeName(); 48 if (name.equals("extension")) { validateExtension(child); 50 } else if (name.equals("extension-point")) { validateExtensionPoint(child); 52 } else if (name.equals("runtime")){ validateRuntime(child); 54 } else if (name.equals("requires")) { validateRequires(child); 56 } else { 57 int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT); 58 if (severity != CompilerFlags.IGNORE) 59 reportIllegalElement(element, severity); 60 } 61 } 62 } 63 } 64 65 protected void validateTopLevelAttributes(Element element) { 66 if (assertAttributeDefined(element, "id", CompilerFlags.ERROR)) { validatePluginID(element, element.getAttributeNode("id")); } 69 if (assertAttributeDefined(element, "version", CompilerFlags.ERROR)) { validateVersionAttribute(element, element.getAttributeNode("version")); } 72 if (assertAttributeDefined(element, "name", CompilerFlags.ERROR)) { validateTranslatableString(element, element.getAttributeNode("name"), true); } 75 Attr attr = element.getAttributeNode("provider-name"); if (attr != null) 77 validateTranslatableString(element, attr, true); 78 } 79 80 protected abstract String getRootElementName(); 81 82 protected void validateRequires(Element element) { 83 int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT); 84 NodeList children = element.getChildNodes(); 85 for (int i = 0; i < children.getLength(); i++) { 86 Element child = (Element )children.item(i); 87 if (child.getNodeName().equals("import")) { validateImport(child); 89 } else if (severity != CompilerFlags.IGNORE) { 90 reportIllegalElement(child, severity); 91 } 92 } 93 } 94 95 protected void validateImport(Element element) { 96 if (assertAttributeDefined(element, "plugin", CompilerFlags.ERROR)) { validatePluginIDRef(element, element.getAttributeNode("plugin")); } 99 Attr attr = element.getAttributeNode("version"); if (attr != null) 101 validateVersionAttribute(element, attr); 102 103 attr = element.getAttributeNode("match"); if (attr != null) 105 validateMatch(element, attr); 106 107 attr = element.getAttributeNode("export"); if (attr != null) 109 validateBoolean(element, attr); 110 111 attr = element.getAttributeNode("optional"); if (attr != null) 113 validateBoolean(element, attr); 114 } 115 116 protected void validateRuntime(Element element) { 117 int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT); 118 NodeList children = element.getChildNodes(); 119 for (int i = 0; i < children.getLength(); i++) { 120 Element child = (Element )children.item(i); 121 if (child.getNodeName().equals("library")) { validateLibrary(child); 123 } else if (severity != CompilerFlags.IGNORE) { 124 reportIllegalElement(child, severity); 125 } 126 } 127 128 } 129 130 protected void validateLibrary(Element element) { 131 assertAttributeDefined(element, "name", CompilerFlags.ERROR); 133 int unknownSev = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT); 134 int deprecatedSev = CompilerFlags.getFlag(fProject, CompilerFlags.P_DEPRECATED); 135 NodeList children = element.getChildNodes(); 136 for (int i = 0; i < children.getLength(); i++) { 137 Element child = (Element )children.item(i); 138 String elementName = child.getNodeName(); 139 if ("export".equals(elementName)) { assertAttributeDefined(child, "name", CompilerFlags.ERROR); } else if ("packages".equals(elementName)) { if (deprecatedSev != CompilerFlags.IGNORE) { 143 reportDeprecatedElement(child, deprecatedSev); 144 } 145 } else if (unknownSev != CompilerFlags.IGNORE) { 146 reportIllegalElement(child, unknownSev); 147 } 148 } 149 } 150 151 protected void validatePluginIDRef(Element element, Attr attr) { 152 if(!validatePluginID(element, attr)){ 153 return; 154 } 155 int severity = CompilerFlags 156 .getFlag(fProject, CompilerFlags.P_UNRESOLVED_IMPORTS); 157 if ("true".equals(element.getAttribute("optional")) && severity == CompilerFlags.ERROR) severity = CompilerFlags.WARNING; 159 if (severity != CompilerFlags.IGNORE) { 160 IPluginModelBase model = PluginRegistry.findModel(attr.getValue()); 161 if (model == null || !model.isEnabled()) { 162 report(NLS.bind(PDECoreMessages.Builders_Manifest_dependency, attr.getValue()), 163 getLine(element, attr.getName()), 164 severity, 165 PDEMarkerFactory.CAT_FATAL); 166 } 167 } 168 } 169 170 private void reportDeprecatedElement(Element element, int severity) { 171 report(NLS.bind(PDECoreMessages.Builders_Manifest_deprecated_3_0, element.getNodeName()), getLine(element), severity, PDEMarkerFactory.CAT_DEPRECATION); 172 } 173 174 } 175 | Popular Tags |