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