KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > builders > PluginBaseErrorReporter


1 /*******************************************************************************
2  * Copyright (c) 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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     /* (non-Javadoc)
29      * @see org.eclipse.pde.internal.builders.ExtensionsErrorReporter#validateContent(org.eclipse.core.runtime.IProgressMonitor)
30      */

31     public void validateContent(IProgressMonitor monitor) {
32         Element element = getDocumentRoot();
33         if (element == null)
34             return;
35         String JavaDoc 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 JavaDoc name = child.getNodeName();
46                 if (name.equals("extension")) { //$NON-NLS-1$
47
validateExtension(child);
48                 } else if (name.equals("extension-point")) { //$NON-NLS-1$
49
validateExtensionPoint(child);
50                 } else if (name.equals("runtime")){ //$NON-NLS-1$
51
validateRuntime(child);
52                 } else if (name.equals("requires")) { //$NON-NLS-1$
53
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)) { //$NON-NLS-1$
65
validatePluginID(element, element.getAttributeNode("id")); //$NON-NLS-1$
66
}
67         if (assertAttributeDefined(element, "version", CompilerFlags.ERROR)) { //$NON-NLS-1$
68
validateVersionAttribute(element, element.getAttributeNode("version")); //$NON-NLS-1$
69
}
70         if (assertAttributeDefined(element, "name", CompilerFlags.ERROR)) { //$NON-NLS-1$
71
validateTranslatableString(element, element.getAttributeNode("name"), true); //$NON-NLS-1$
72
}
73         Attr attr = element.getAttributeNode("provider-name"); //$NON-NLS-1$
74
if (attr != null)
75             validateTranslatableString(element, attr, true);
76     }
77         
78     protected abstract String JavaDoc 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")) { //$NON-NLS-1$
86
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)) { //$NON-NLS-1$
95
validatePluginIDRef(element, element.getAttributeNode("plugin")); //$NON-NLS-1$
96
}
97         Attr attr = element.getAttributeNode("version"); //$NON-NLS-1$
98
if (attr != null)
99             validateVersionAttribute(element, attr);
100         
101         attr = element.getAttributeNode("match"); //$NON-NLS-1$
102
if (attr != null)
103             validateMatch(element, attr);
104         
105         attr = element.getAttributeNode("export"); //$NON-NLS-1$
106
if (attr != null)
107             validateBoolean(element, attr);
108         
109         attr = element.getAttributeNode("optional"); //$NON-NLS-1$
110
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")) { //$NON-NLS-1$
120
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); //$NON-NLS-1$
130

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 JavaDoc elementName = child.getNodeName();
137             if ("export".equals(elementName)) { //$NON-NLS-1$
138
assertAttributeDefined(child, "name", CompilerFlags.ERROR); //$NON-NLS-1$
139
} else if ("packages".equals(elementName)) { //$NON-NLS-1$
140
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) //$NON-NLS-1$ //$NON-NLS-2$
156
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()), //$NON-NLS-1$
161
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