KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > builders > ExtensionsErrorReporter


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 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.core.builders;
12
13 import java.io.File JavaDoc;
14 import java.util.ArrayList JavaDoc;
15 import java.util.HashSet JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.StringTokenizer JavaDoc;
18
19 import org.eclipse.core.resources.IFile;
20 import org.eclipse.core.resources.IResource;
21 import org.eclipse.core.runtime.CoreException;
22 import org.eclipse.core.runtime.IPath;
23 import org.eclipse.core.runtime.IProgressMonitor;
24 import org.eclipse.core.runtime.Path;
25 import org.eclipse.jdt.core.IJavaProject;
26 import org.eclipse.jdt.core.JavaCore;
27 import org.eclipse.osgi.util.NLS;
28 import org.eclipse.pde.core.build.IBuild;
29 import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
30 import org.eclipse.pde.core.plugin.IPluginModelBase;
31 import org.eclipse.pde.core.plugin.PluginRegistry;
32 import org.eclipse.pde.core.plugin.TargetPlatform;
33 import org.eclipse.pde.internal.core.AbstractNLModel;
34 import org.eclipse.pde.internal.core.ClasspathUtilCore;
35 import org.eclipse.pde.internal.core.NLResourceHelper;
36 import org.eclipse.pde.internal.core.PDECore;
37 import org.eclipse.pde.internal.core.PDECoreMessages;
38 import org.eclipse.pde.internal.core.PDEStateHelper;
39 import org.eclipse.pde.internal.core.ischema.IMetaAttribute;
40 import org.eclipse.pde.internal.core.ischema.ISchema;
41 import org.eclipse.pde.internal.core.ischema.ISchemaAttribute;
42 import org.eclipse.pde.internal.core.ischema.ISchemaComplexType;
43 import org.eclipse.pde.internal.core.ischema.ISchemaCompositor;
44 import org.eclipse.pde.internal.core.ischema.ISchemaElement;
45 import org.eclipse.pde.internal.core.ischema.ISchemaEnumeration;
46 import org.eclipse.pde.internal.core.ischema.ISchemaObject;
47 import org.eclipse.pde.internal.core.ischema.ISchemaObjectReference;
48 import org.eclipse.pde.internal.core.ischema.ISchemaRestriction;
49 import org.eclipse.pde.internal.core.ischema.ISchemaRootElement;
50 import org.eclipse.pde.internal.core.ischema.ISchemaSimpleType;
51 import org.eclipse.pde.internal.core.ischema.ISchemaType;
52 import org.eclipse.pde.internal.core.schema.SchemaRegistry;
53 import org.eclipse.pde.internal.core.util.CoreUtility;
54 import org.eclipse.pde.internal.core.util.IdUtil;
55 import org.eclipse.pde.internal.core.util.PDEJavaHelper;
56 import org.w3c.dom.Attr JavaDoc;
57 import org.w3c.dom.Element JavaDoc;
58 import org.w3c.dom.NamedNodeMap JavaDoc;
59 import org.w3c.dom.Node JavaDoc;
60 import org.w3c.dom.NodeList JavaDoc;
61 import org.xml.sax.SAXException JavaDoc;
62
63 public class ExtensionsErrorReporter extends ManifestErrorReporter {
64     
65     private IPluginModelBase fModel;
66     private IBuild fBuildModel;
67     
68     public ExtensionsErrorReporter(IFile file) {
69         super(file);
70         fModel = PluginRegistry.findModel(file.getProject());
71         try {
72             if (fModel != null && fModel.getUnderlyingResource() != null)
73                 fBuildModel = ClasspathUtilCore.getBuild(fModel);
74         } catch (CoreException e) {
75         }
76     }
77     
78     /* (non-Javadoc)
79      * @see org.eclipse.pde.internal.builders.XMLErrorReporter#characters(char[], int, int)
80      */

81     public void characters(char[] characters, int start, int length)
82             throws SAXException JavaDoc {
83     }
84
85     public void validateContent(IProgressMonitor monitor) {
86         Element element = getDocumentRoot();
87         if (element == null)
88             return;
89         String JavaDoc elementName = element.getNodeName();
90         if (!"plugin".equals(elementName) && !"fragment".equals(elementName)) { //$NON-NLS-1$ //$NON-NLS-2$
91
reportIllegalElement(element, CompilerFlags.ERROR);
92         } else {
93             int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_DEPRECATED);
94             if (severity != CompilerFlags.IGNORE) {
95                 NamedNodeMap JavaDoc attrs = element.getAttributes();
96                 for (int i = 0; i < attrs.getLength(); i++) {
97                     reportUnusedAttribute(element, attrs.item(i).getNodeName(), severity);
98                 }
99             }
100             
101             NodeList JavaDoc children = element.getChildNodes();
102             for (int i = 0; i < children.getLength(); i++) {
103                 if (monitor.isCanceled())
104                     break;
105                 Element child = (Element)children.item(i);
106                 String JavaDoc name = child.getNodeName();
107                 if (name.equals("extension")) { //$NON-NLS-1$
108
validateExtension(child);
109                 } else if (name.equals("extension-point")) { //$NON-NLS-1$
110
validateExtensionPoint(child);
111                 } else {
112                     if (!name.equals("runtime") && !name.equals("requires")) { //$NON-NLS-1$ //$NON-NLS-2$
113
severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT);
114                         if (severity != CompilerFlags.IGNORE)
115                             reportIllegalElement(child, severity);
116                     } else {
117                         severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_DEPRECATED);
118                         if (severity != CompilerFlags.IGNORE)
119                             reportUnusedElement(child, severity);
120                     }
121                 }
122             }
123         }
124     }
125
126     protected void validateExtension(Element element) {
127         if (!assertAttributeDefined(element, "point", CompilerFlags.ERROR)) //$NON-NLS-1$
128
return;
129         String JavaDoc pointID = element.getAttribute("point"); //$NON-NLS-1$
130
IPluginExtensionPoint point = PDEStateHelper.findExtensionPoint(pointID);
131         if (point == null) {
132             int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNRESOLVED_EX_POINTS);
133             if (severity != CompilerFlags.IGNORE) {
134                 report(NLS.bind(PDECoreMessages.Builders_Manifest_ex_point, pointID),
135                     getLine(element, "point"), severity, PDEMarkerFactory.CAT_OTHER); //$NON-NLS-1$
136
}
137         } else {
138             SchemaRegistry registry = PDECore.getDefault().getSchemaRegistry();
139             ISchema schema = registry.getSchema(pointID);
140             if (schema != null) {
141                 validateElement(element, schema, true);
142             }
143         }
144     }
145     
146     /**
147      * @param parentElement
148      * @param childElement
149      * @param severity
150      */

151     private void reportMaxOccurenceViolation(ElementOccurrenceResult result,
152             int severity) {
153         Element childElement = result.getElement();
154         String JavaDoc allowedOccurrences =
155             new Integer JavaDoc(result.getAllowedOccurrences()).toString();
156         String JavaDoc message = NLS.bind(
157                 PDECoreMessages.ExtensionsErrorReporter_maxOccurrence,
158                 new String JavaDoc[] { allowedOccurrences, childElement.getNodeName() });
159         report(message, getLine(childElement), severity,
160                 PDEMarkerFactory.P_ILLEGAL_XML_NODE, childElement, null,
161                 PDEMarkerFactory.CAT_FATAL);
162     }
163
164     /**
165      * @param parentElement
166      * @param childElement
167      * @param severity
168      */

169     private void reportMinOccurenceViolation(Element parentElement,
170             ElementOccurrenceResult result, int severity) {
171         
172         ISchemaElement childElement = result.getSchemaElement();
173         String JavaDoc allowedOccurrences =
174             new Integer JavaDoc(result.getAllowedOccurrences()).toString();
175         String JavaDoc message = NLS.bind(
176                 PDECoreMessages.ExtensionsErrorReporter_minOccurrence,
177                 new String JavaDoc[] { allowedOccurrences, childElement.getName()});
178         report(message, getLine(parentElement), severity,
179                 PDEMarkerFactory.CAT_FATAL);
180     }
181     
182     protected void validateElement(Element element, ISchema schema,
183             boolean isTopLevel) {
184         String JavaDoc elementName = element.getNodeName();
185         ISchemaElement schemaElement = schema.findElement(elementName);
186         
187         // Validate element occurrence violations
188
if ((schemaElement != null) &&
189                 (schemaElement.getType() instanceof ISchemaComplexType)) {
190             validateMaxElementMult(element, schemaElement);
191             validateMinElementMult(element, schemaElement);
192         }
193         
194         ISchemaElement parentSchema = null;
195         if (!"extension".equals(elementName)) { //$NON-NLS-1$
196
Node JavaDoc parent = element.getParentNode();
197             parentSchema = schema.findElement(parent.getNodeName());
198         } else if (isTopLevel == false) {
199             // This is an "extension" element; but, not a top level one.
200
// It is nested within another "extension" element somewhere
201
// e.g. "extension" element is a child element of another element
202
// that is not a "plugin" elment
203
// element
204
// Report illegal element
205
int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT);
206             reportIllegalElement(element, severity);
207             return;
208         }
209         
210         if (parentSchema != null) {
211             int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT);
212             if (severity != CompilerFlags.IGNORE) {
213                 HashSet JavaDoc allowedElements = new HashSet JavaDoc();
214                 computeAllowedElements(parentSchema.getType(), allowedElements);
215                 if (!allowedElements.contains(elementName)) {
216                     reportIllegalElement(element, severity);
217                     return;
218                 }
219             }
220             
221         }
222         if (schemaElement == null && parentSchema != null) {
223             ISchemaAttribute attr = parentSchema.getAttribute(elementName);
224             if (attr != null && attr.getKind() == IMetaAttribute.JAVA) {
225                 if (attr.isDeprecated())
226                     reportDeprecatedAttribute(element, element.getAttributeNode("class")); //$NON-NLS-1$
227
validateJavaAttribute(element, element.getAttributeNode("class")); //$NON-NLS-1$
228
}
229         } else {
230             if (schemaElement != null) {
231                 validateRequiredExtensionAttributes(element, schemaElement);
232                 validateExistingExtensionAttributes(element, element.getAttributes(), schemaElement);
233                 if (schemaElement.isDeprecated()) {
234                     if (schemaElement instanceof ISchemaRootElement)
235                         reportDeprecatedRootElement(element,
236                                 ((ISchemaRootElement)schemaElement).getDeprecatedSuggestion());
237                     else
238                         reportDeprecatedElement(element);
239                 }
240                 if (schemaElement.hasTranslatableContent())
241                     validateTranslatableElementContent(element);
242             }
243             NodeList JavaDoc children = element.getChildNodes();
244             for (int i = 0; i < children.getLength(); i++) {
245                 validateElement((Element)children.item(i), schema, false);
246             }
247         }
248     }
249
250     /**
251      * @param element
252      * @param schemaElement
253      */

254     private void validateMinElementMult(Element element,
255             ISchemaElement schemaElement) {
256         // Validate min element occurence violations
257
int minSeverity = CompilerFlags.getFlag(fProject,
258                 CompilerFlags.P_UNKNOWN_ELEMENT);
259         if (minSeverity != CompilerFlags.IGNORE) {
260             HashSet JavaDoc minElementSet = ElementOccurenceChecker
261                     .findMinOccurenceViolations(schemaElement, element);
262             Iterator JavaDoc minIterator = minElementSet.iterator();
263
264             while (minIterator.hasNext()) {
265                 reportMinOccurenceViolation(element,
266                         (ElementOccurrenceResult) minIterator.next(), minSeverity);
267             }
268         }
269     }
270
271     /**
272      * @param element
273      * @param schemaElement
274      */

275     private void validateMaxElementMult(Element element,
276             ISchemaElement schemaElement) {
277         // Validate max element occurence violations
278
int maxSeverity = CompilerFlags.getFlag(fProject,
279                 CompilerFlags.P_UNKNOWN_ELEMENT);
280         if (maxSeverity != CompilerFlags.IGNORE) {
281             HashSet JavaDoc maxElementSet = ElementOccurenceChecker
282                     .findMaxOccurenceViolations(schemaElement, element);
283             Iterator JavaDoc maxIterator = maxElementSet.iterator();
284             while (maxIterator.hasNext()) {
285                 reportMaxOccurenceViolation(
286                         (ElementOccurrenceResult) maxIterator.next(),
287                         maxSeverity);
288             }
289         }
290     }
291     
292     private void computeAllowedElements(ISchemaType type, HashSet JavaDoc elementSet) {
293         if (type instanceof ISchemaComplexType) {
294             ISchemaComplexType complexType = (ISchemaComplexType) type;
295             ISchemaCompositor compositor = complexType.getCompositor();
296             if (compositor != null)
297                 computeAllowedElements(compositor, elementSet);
298
299             ISchemaAttribute[] attrs = complexType.getAttributes();
300             for (int i = 0; i < attrs.length; i++) {
301                 if (attrs[i].getKind() == IMetaAttribute.JAVA)
302                     elementSet.add(attrs[i].getName());
303             }
304         }
305     }
306
307     private void computeAllowedElements(ISchemaCompositor compositor,
308             HashSet JavaDoc elementSet) {
309         ISchemaObject[] children = compositor.getChildren();
310         for (int i = 0; i < children.length; i++) {
311             ISchemaObject child = children[i];
312             if (child instanceof ISchemaObjectReference) {
313                 ISchemaObjectReference ref = (ISchemaObjectReference) child;
314                 ISchemaElement refElement = (ISchemaElement) ref
315                         .getReferencedObject();
316                 if (refElement != null)
317                     elementSet.add(refElement.getName());
318             } else if (child instanceof ISchemaCompositor) {
319                 computeAllowedElements((ISchemaCompositor) child, elementSet);
320             }
321         }
322     }
323
324
325     
326     private void validateRequiredExtensionAttributes(Element element, ISchemaElement schemaElement) {
327         int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_NO_REQUIRED_ATT);
328         if (severity == CompilerFlags.IGNORE)
329             return;
330         
331         ISchemaAttribute[] attInfos = schemaElement.getAttributes();
332         for (int i = 0; i < attInfos.length; i++) {
333             ISchemaAttribute attInfo = attInfos[i];
334             if (attInfo.getUse() == ISchemaAttribute.REQUIRED) {
335                 boolean found = element.getAttributeNode(attInfo.getName()) != null;
336                 if (!found && attInfo.getKind() == IMetaAttribute.JAVA) {
337                     NodeList JavaDoc children = element.getChildNodes();
338                     for (int j = 0; j < children.getLength(); j++) {
339                         if (attInfo.getName().equals(children.item(j).getNodeName())) {
340                             found = true;
341                             break;
342                         }
343                     }
344                 }
345                 if (!found) {
346                     reportMissingRequiredAttribute(element, attInfo.getName(), severity);
347                 }
348             }
349         }
350     }
351     
352     private void validateExistingExtensionAttributes(Element element, NamedNodeMap JavaDoc attrs,
353             ISchemaElement schemaElement) {
354         for (int i = 0; i < attrs.getLength(); i++) {
355             Attr JavaDoc attr = (Attr JavaDoc)attrs.item(i);
356             ISchemaAttribute attInfo = schemaElement.getAttribute(attr.getName());
357             if (attInfo == null) {
358                 HashSet JavaDoc allowedElements = new HashSet JavaDoc();
359                 computeAllowedElements(schemaElement.getType(), allowedElements);
360                 if (allowedElements.contains(attr.getName())) {
361                     validateJavaAttribute(element, attr);
362                 } else {
363                     int flag = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ATTRIBUTE);
364                     if (flag != CompilerFlags.IGNORE)
365                         reportUnknownAttribute(element, attr.getName(), flag);
366                 }
367             } else {
368                 validateExtensionAttribute(element, attr, attInfo);
369             }
370         }
371     }
372
373     private void validateExtensionAttribute(Element element, Attr JavaDoc attr, ISchemaAttribute attInfo) {
374         ISchemaSimpleType type = attInfo.getType();
375         ISchemaRestriction restriction = type.getRestriction();
376         if (restriction != null) {
377             validateRestrictionAttribute(element, attr, restriction);
378         }
379         
380         int kind = attInfo.getKind();
381         if (kind == IMetaAttribute.JAVA) {
382             validateJavaAttribute(element, attr);
383         } else if (kind == IMetaAttribute.RESOURCE) {
384             validateResourceAttribute(element, attr);
385         } else if (type.getName().equals("boolean")) { //$NON-NLS-1$
386
validateBoolean(element, attr);
387         }
388         
389         validateTranslatableString(element, attr, attInfo.isTranslatable());
390         
391         if (attInfo.isDeprecated()) {
392             reportDeprecatedAttribute(element, attr);
393         }
394     }
395
396     protected void validateExtensionPoint(Element element) {
397         if (assertAttributeDefined(element, "id", CompilerFlags.ERROR)) { //$NON-NLS-1$
398
Attr JavaDoc idAttr = element.getAttributeNode("id"); //$NON-NLS-1$
399
double schemaVersion = getSchemaVersion();
400             String JavaDoc message = null;
401             if (schemaVersion < 3.2 && !IdUtil.isValidSimpleID(idAttr.getValue()))
402                 message = NLS.bind(PDECoreMessages.Builders_Manifest_simpleID, idAttr.getValue());
403             else if (schemaVersion >= 3.2) {
404                 if (!IdUtil.isValidCompositeID(idAttr.getValue())) {
405                     message = NLS.bind(PDECoreMessages.Builders_Manifest_compositeID, idAttr.getValue());
406                 }
407             }
408            
409             if (message != null)
410                 report(message, getLine(element, idAttr.getName()), CompilerFlags.WARNING, PDEMarkerFactory.CAT_OTHER);
411         }
412
413         assertAttributeDefined(element, "name", CompilerFlags.ERROR); //$NON-NLS-1$
414

415         int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ATTRIBUTE);
416         NamedNodeMap JavaDoc attrs = element.getAttributes();
417         for (int i = 0; i < attrs.getLength(); i++) {
418             Attr JavaDoc attr = (Attr JavaDoc)attrs.item(i);
419             String JavaDoc name = attr.getName();
420             if ("name".equals(name)) { //$NON-NLS-1$
421
validateTranslatableString(element, attr, true);
422             } else if (!"id".equals(name) && !"schema".equals(name) && severity != CompilerFlags.IGNORE) { //$NON-NLS-1$ //$NON-NLS-2$
423
reportUnknownAttribute(element, name, severity);
424             }
425         }
426         
427         severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT);
428         if (severity != CompilerFlags.IGNORE) {
429             NodeList JavaDoc children = element.getChildNodes();
430             for (int i = 0; i < children.getLength(); i++)
431                 reportIllegalElement((Element)children.item(i), severity);
432         }
433         
434         // Validate the "schema" attribute of the extension point
435
Attr JavaDoc attr = element.getAttributeNode(IPluginExtensionPoint.P_SCHEMA);
436         // Only validate the attribute if it was defined
437
if (attr != null) {
438             String JavaDoc schemaValue = attr.getValue();
439             IResource res = getFile().getProject().findMember(schemaValue);
440             String JavaDoc errorMessage = null;
441             // Check to see if the value specified is an extension point schema and it exists
442
if (!(res instanceof IFile &&
443                     (res.getName().endsWith(".exsd") || //$NON-NLS-1$
444
res.getName().endsWith(".mxsd")))) //$NON-NLS-1$
445
errorMessage = PDECoreMessages.ExtensionsErrorReporter_InvalidSchema;
446             // Report an error if one was found
447
if (errorMessage != null) {
448                 severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_RESOURCE);
449                 if (severity != CompilerFlags.IGNORE)
450                     report(NLS.bind(errorMessage, schemaValue), getLine(element), severity,
451                             PDEMarkerFactory.CAT_OTHER);
452             }
453         }
454     }
455         
456     protected void validateTranslatableString(Element element, Attr JavaDoc attr, boolean shouldTranslate) {
457         if (!shouldTranslate)
458             return;
459         int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_NOT_EXTERNALIZED);
460         if (severity == CompilerFlags.IGNORE)
461             return;
462         String JavaDoc value = attr.getValue();
463         if (!value.startsWith("%")) { //$NON-NLS-1$
464
report(NLS.bind(PDECoreMessages.Builders_Manifest_non_ext_attribute, attr.getName()),
465                     getLine(element, attr.getName()),
466                     severity,
467                     PDEMarkerFactory.P_UNTRANSLATED_NODE,
468                     element, attr.getName(),
469                     PDEMarkerFactory.CAT_NLS);
470         } else if (fModel instanceof AbstractNLModel) {
471             NLResourceHelper helper = ((AbstractNLModel)fModel).getNLResourceHelper();
472             if (helper == null || !helper.resourceExists(value)) {
473                 report(NLS.bind(PDECoreMessages.Builders_Manifest_key_not_found, value.substring(1)), getLine(element, attr.getName()), severity,
474                         PDEMarkerFactory.CAT_NLS);
475             }
476         }
477     }
478     
479     protected void validateTranslatableElementContent(Element element) {
480         int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_NOT_EXTERNALIZED);
481         if (severity == CompilerFlags.IGNORE)
482             return;
483         String JavaDoc value = getTextContent(element);
484         if (value == null)
485             return;
486         if (!value.startsWith("%")) { //$NON-NLS-1$
487
report(NLS.bind(PDECoreMessages.Builders_Manifest_non_ext_element, element.getNodeName()),
488                     getLine(element),
489                     severity,
490                     PDEMarkerFactory.P_UNTRANSLATED_NODE,
491                     element, null, PDEMarkerFactory.CAT_NLS);
492         } else if (fModel instanceof AbstractNLModel) {
493             NLResourceHelper helper = ((AbstractNLModel)fModel).getNLResourceHelper();
494             if (helper == null || !helper.resourceExists(value)) {
495                 report(NLS.bind(PDECoreMessages.Builders_Manifest_key_not_found, value.substring(1)), getLine(element), severity, PDEMarkerFactory.CAT_NLS);
496             }
497         }
498     }
499
500     protected void validateResourceAttribute(Element element, Attr JavaDoc attr) {
501         int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_RESOURCE);
502         if (severity != CompilerFlags.IGNORE && !resourceExists(attr.getValue())) {
503             report(NLS.bind(PDECoreMessages.Builders_Manifest_resource, (new String JavaDoc[] { attr.getValue(), attr.getName() })),
504                             getLine(element,
505                             attr.getName()),
506                             severity,
507                             PDEMarkerFactory.CAT_OTHER);
508         }
509     }
510     
511     private boolean resourceExists(String JavaDoc location) {
512         String JavaDoc bundleJar=null;
513         IPath path = new Path(location);
514         if ("platform:".equals(path.getDevice()) && path.segmentCount() > 2) { //$NON-NLS-1$
515
if ("plugin".equals(path.segment(0))) { //$NON-NLS-1$
516
String JavaDoc id = path.segment(1);
517                 IPluginModelBase model = PluginRegistry.findModel(id);
518                 if (model != null && model.isEnabled()) {
519                     path = path.setDevice(null).removeFirstSegments(2);
520                     String JavaDoc bundleLocation = model.getInstallLocation();
521                     if(bundleLocation.endsWith(".jar")){ //$NON-NLS-1$
522
bundleJar=bundleLocation;
523                     } else {
524                         path = new Path(model.getInstallLocation()).append(path);
525                     }
526                     location = path.toString();
527                 }
528             }
529         } else if (path.getDevice()==null && path.segmentCount() > 3 && "platform:".equals(path.segment(0))){ //$NON-NLS-1$
530
if ("plugin".equals(path.segment(1))) { //$NON-NLS-1$
531
String JavaDoc id = path.segment(2);
532                 IPluginModelBase model = PluginRegistry.findModel(id);
533                 if (model != null && model.isEnabled()) {
534                     path = path.removeFirstSegments(3);
535                     String JavaDoc bundleLocation = model.getInstallLocation();
536                     if(bundleLocation.endsWith(".jar")){ //$NON-NLS-1$
537
bundleJar=bundleLocation;
538                     } else {
539                         path = new Path(model.getInstallLocation()).append(path);
540                     }
541                     location = path.toString();
542                 }
543             }
544         }
545
546         ArrayList JavaDoc paths = new ArrayList JavaDoc();
547         if (location.indexOf("$nl$") != -1) { //$NON-NLS-1$
548
StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(TargetPlatform.getNL(), "_"); //$NON-NLS-1$
549
String JavaDoc language = tokenizer.hasMoreTokens() ? tokenizer.nextToken() : null;
550             String JavaDoc country = tokenizer.hasMoreTokens() ? tokenizer.nextToken() : null;
551             if (language != null && country != null)
552                 paths.add(location
553                         .replaceAll(
554                                 "\\$nl\\$", "nl" + IPath.SEPARATOR + language + IPath.SEPARATOR + country)); //$NON-NLS-1$ //$NON-NLS-2$
555
if (language != null)
556                 paths.add(location.replaceAll(
557                         "\\$nl\\$", "nl" + IPath.SEPARATOR + language)); //$NON-NLS-1$ //$NON-NLS-2$
558
paths.add(location.replaceAll("\\$nl\\$", "")); //$NON-NLS-1$ //$NON-NLS-2$
559
} else {
560             paths.add(location);
561         }
562         
563         for (int i = 0; i < paths.size(); i++) {
564             if (bundleJar == null) {
565                 IPath currPath = new Path(paths.get(i).toString());
566                 if (currPath.isAbsolute() && currPath.toFile().exists())
567                     return true;
568                 if (fFile.getProject().findMember(currPath) != null)
569                     return true;
570                 if (fBuildModel != null && fBuildModel.getEntry("source." + paths.get(i)) != null) //$NON-NLS-1$
571
return true;
572             } else {
573                 if (CoreUtility.jarContainsResource(new File JavaDoc(bundleJar), paths.get(i).toString(), false))
574                     return true;
575             }
576         }
577         
578         return false;
579     }
580
581     protected void validateJavaAttribute(Element element, Attr JavaDoc attr) {
582         int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_CLASS);
583         if (severity == CompilerFlags.IGNORE)
584             return;
585
586         String JavaDoc value = attr.getValue();
587         IJavaProject javaProject = JavaCore.create(fFile.getProject());
588
589         // be careful: people have the option to use the format:
590
// fullqualifiedName:staticMethod
591
int index = value.indexOf(":"); //$NON-NLS-1$
592
if (index != -1)
593             value = value.substring(0, index);
594
595         if (!PDEJavaHelper.isOnClasspath(value, javaProject)) {
596             report(NLS.bind(PDECoreMessages.Builders_Manifest_class, (new String JavaDoc[] { value, attr.getName() })), getLine(
597                     element, attr.getName()), severity,
598                     PDEMarkerFactory.P_UNKNOWN_CLASS,
599                     element,
600                     attr.getName() + F_ATT_VALUE_PREFIX + attr.getValue(),
601                     PDEMarkerFactory.CAT_FATAL);
602         }
603     }
604     
605     protected void validateRestrictionAttribute(Element element, Attr JavaDoc attr, ISchemaRestriction restriction) {
606         Object JavaDoc[] children = restriction.getChildren();
607         String JavaDoc value = attr.getValue();
608         for (int i = 0; i < children.length; i++) {
609             Object JavaDoc child = children[i];
610             if (child instanceof ISchemaEnumeration) {
611                 ISchemaEnumeration enumeration = (ISchemaEnumeration) child;
612                 if (enumeration.getName().equals(value)) {
613                     return;
614                 }
615             }
616         }
617         reportIllegalAttributeValue(element, attr);
618     }
619     
620     protected void reportUnusedAttribute(Element element, String JavaDoc attName, int severity) {
621         String JavaDoc message = NLS.bind(PDECoreMessages.Builders_Manifest_unused_attribute, attName);
622         report(message, getLine(element, attName), severity, PDEMarkerFactory.CAT_OTHER);
623     }
624     
625     protected void reportUnusedElement(Element element, int severity) {
626         Node JavaDoc parent = element.getParentNode();
627             report(NLS.bind(PDECoreMessages.Builders_Manifest_unused_element, (new String JavaDoc[] {
628             element.getNodeName(), parent.getNodeName() })),
629                     getLine(element), severity,
630                     PDEMarkerFactory.CAT_OTHER);
631     }
632     
633     protected void reportDeprecatedElement(Element element) {
634         int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_DEPRECATED);
635         if (severity != CompilerFlags.IGNORE) {
636             report(NLS.bind(PDECoreMessages.Builders_Manifest_deprecated_element, element.getNodeName()), getLine(element), severity, PDEMarkerFactory.CAT_DEPRECATION);
637         }
638     }
639
640     protected void reportDeprecatedRootElement(Element element, String JavaDoc suggestion) {
641         int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_DEPRECATED);
642         if (severity != CompilerFlags.IGNORE) {
643             String JavaDoc point = element.getAttribute("point"); //$NON-NLS-1$
644
if (point == null) return; // should never come to this...
645
String JavaDoc message;
646             if (suggestion != null)
647                 message = NLS.bind(PDECoreMessages.Builders_Manifest_deprecated_rootElementSuggestion, point, suggestion);
648             else
649                 message = NLS.bind(PDECoreMessages.Builders_Manifest_deprecated_rootElement, point);
650             report(message, getLine(element, "point"), severity, PDEMarkerFactory.CAT_DEPRECATION); //$NON-NLS-1$
651
}
652     }
653 }
654
Popular Tags