Lines 29-34
Link Here
|
29 |
import org.eclipse.pde.internal.core.search.PluginJavaSearchUtil; |
29 |
import org.eclipse.pde.internal.core.search.PluginJavaSearchUtil; |
30 |
import org.eclipse.pde.internal.core.util.*; |
30 |
import org.eclipse.pde.internal.core.util.*; |
31 |
import org.osgi.framework.*; |
31 |
import org.osgi.framework.*; |
|
|
32 |
import org.w3c.dom.Element; |
33 |
import org.w3c.dom.NodeList; |
34 |
import org.xml.sax.SAXException; |
32 |
|
35 |
|
33 |
public class BundleErrorReporter extends JarManifestErrorReporter { |
36 |
public class BundleErrorReporter extends JarManifestErrorReporter { |
34 |
|
37 |
|
Lines 47-53
Link Here
|
47 |
|
50 |
|
48 |
fModel = PluginRegistry.findModel(fProject); |
51 |
fModel = PluginRegistry.findModel(fProject); |
49 |
// be paranoid. something could have gone wrong reading the file etc. |
52 |
// be paranoid. something could have gone wrong reading the file etc. |
50 |
if (fModel == null || !validateBundleSymbolicName()) |
53 |
if (fModel == null || !validateBundleSymbolicName(monitor)) |
51 |
return; |
54 |
return; |
52 |
|
55 |
|
53 |
validateFragmentHost(); |
56 |
validateFragmentHost(); |
Lines 132-138
Link Here
|
132 |
/** |
135 |
/** |
133 |
* @return boolean false if fatal |
136 |
* @return boolean false if fatal |
134 |
*/ |
137 |
*/ |
135 |
private boolean validateBundleSymbolicName() { |
138 |
private boolean validateBundleSymbolicName(IProgressMonitor monitor) { |
136 |
IHeader header = validateRequiredHeader(Constants.BUNDLE_SYMBOLICNAME); |
139 |
IHeader header = validateRequiredHeader(Constants.BUNDLE_SYMBOLICNAME); |
137 |
if (header == null) |
140 |
if (header == null) |
138 |
return false; |
141 |
return false; |
Lines 147-153
Link Here
|
147 |
if (!validateBundleManifestVersion()) |
150 |
if (!validateBundleManifestVersion()) |
148 |
return false; |
151 |
return false; |
149 |
validatePluginId(header, id); |
152 |
validatePluginId(header, id); |
150 |
validateSingleton(header, elements[0]); |
153 |
validateSingleton(monitor, header, elements[0]); |
151 |
|
154 |
|
152 |
return true; |
155 |
return true; |
153 |
} |
156 |
} |
Lines 162-176
Link Here
|
162 |
} |
165 |
} |
163 |
|
166 |
|
164 |
// validateBundleManifestVersion must be called before this function. Relies on fOSGiR4 being set correctly |
167 |
// validateBundleManifestVersion must be called before this function. Relies on fOSGiR4 being set correctly |
165 |
private void validateSingleton(IHeader header, ManifestElement element) { |
168 |
private void validateSingleton(IProgressMonitor monitor, IHeader header, ManifestElement element) { |
166 |
String singletonAttr = element.getAttribute(ICoreConstants.SINGLETON_ATTRIBUTE); |
169 |
String singletonAttr = element.getAttribute(ICoreConstants.SINGLETON_ATTRIBUTE); |
167 |
String singletonDir = element.getDirective(Constants.SINGLETON_DIRECTIVE); |
170 |
String singletonDir = element.getDirective(Constants.SINGLETON_DIRECTIVE); |
168 |
IPluginBase base = fModel.getPluginBase(); |
171 |
|
169 |
// must check the existence of plugin.xml file instead of using IPluginBase because if the bundle is not a singleton, |
172 |
if (hasExtensions(monitor)) { |
170 |
// it won't be registered with the extension registry and will always return 0 when querying extensions/extension points |
|
|
171 |
boolean hasExtensions = base != null && fProject.findMember(ICoreConstants.PLUGIN_PATH) != null; |
172 |
|
173 |
if (hasExtensions) { |
174 |
if (TargetPlatformHelper.getTargetVersion() >= 3.1) { |
173 |
if (TargetPlatformHelper.getTargetVersion() >= 3.1) { |
175 |
if (!"true".equals(singletonDir)) { //$NON-NLS-1$ |
174 |
if (!"true".equals(singletonDir)) { //$NON-NLS-1$ |
176 |
if ("true".equals(singletonAttr)) { //$NON-NLS-1$ |
175 |
if ("true".equals(singletonAttr)) { //$NON-NLS-1$ |
Lines 213-218
Link Here
|
213 |
validateBooleanDirectiveValue(header, element, Constants.SINGLETON_DIRECTIVE); |
212 |
validateBooleanDirectiveValue(header, element, Constants.SINGLETON_DIRECTIVE); |
214 |
} |
213 |
} |
215 |
|
214 |
|
|
|
215 |
|
216 |
private void validateFragmentHost() { |
216 |
private void validateFragmentHost() { |
217 |
IHeader header = getHeader(Constants.FRAGMENT_HOST); |
217 |
IHeader header = getHeader(Constants.FRAGMENT_HOST); |
218 |
if (header == null) { |
218 |
if (header == null) { |
Lines 1083-1086
Link Here
|
1083 |
} catch (CoreException e) { |
1083 |
} catch (CoreException e) { |
1084 |
} |
1084 |
} |
1085 |
} |
1085 |
} |
|
|
1086 |
|
1087 |
private boolean hasExtensions(IProgressMonitor monitor) { |
1088 |
// must check the existence and content of plugin.xml file instead of using IPluginBase because if the bundle is not a singleton, |
1089 |
// it won't be registered with the extension registry and will always return 0 when querying extensions/extension points |
1090 |
IPluginBase base = fModel.getPluginBase(); |
1091 |
if(base==null) { |
1092 |
return false; |
1093 |
} else { |
1094 |
IFile file = fProject.getFile(ICoreConstants.PLUGIN_FILENAME_DESCRIPTOR); |
1095 |
|
1096 |
if (!file.exists()) { |
1097 |
return false; |
1098 |
} else { |
1099 |
PluginXMLEmptyReporter reporter = new PluginXMLEmptyReporter(file); |
1100 |
DefaultSAXParser.parse(file, reporter ); |
1101 |
reporter.validateContent(monitor); |
1102 |
return reporter.hasExtensions(); |
1103 |
} |
1104 |
} |
1105 |
} |
1106 |
|
1107 |
/** |
1108 |
* Class to quickly scan plugin.xml for extensions or extension points |
1109 |
* Does no do any actual error or warning reporting, just uses the XMLErrorReporter to |
1110 |
* get its built-in fast SAX parsing. |
1111 |
***/ |
1112 |
|
1113 |
static class PluginXMLEmptyReporter extends XMLErrorReporter { |
1114 |
|
1115 |
boolean fHasExtentions = false; |
1116 |
|
1117 |
public PluginXMLEmptyReporter(IFile file) { |
1118 |
super(file); |
1119 |
} |
1120 |
|
1121 |
protected void removeFileMarkers() { |
1122 |
// noop - we are just checking for content in another file so should not clear other file markers. |
1123 |
} |
1124 |
|
1125 |
public void validateContent(IProgressMonitor monitor) { |
1126 |
Element element = getDocumentRoot(); |
1127 |
if (element == null) |
1128 |
return; |
1129 |
|
1130 |
String elementName = element.getNodeName(); |
1131 |
if (!"plugin".equals(elementName) && !"fragment".equals(elementName)) { //$NON-NLS-1$ //$NON-NLS-2$ |
1132 |
return; |
1133 |
} else { |
1134 |
NodeList children = element.getChildNodes(); |
1135 |
for (int i = 0; i < children.getLength(); i++) { |
1136 |
if (monitor.isCanceled()) |
1137 |
break; |
1138 |
Element child = (Element) children.item(i); |
1139 |
String name = child.getNodeName(); |
1140 |
if (name.equals("extension")) { //$NON-NLS-1$ |
1141 |
fHasExtentions = true; |
1142 |
return; |
1143 |
} else if (name.equals("extension-point")) { //$NON-NLS-1$ |
1144 |
fHasExtentions = true; |
1145 |
return; |
1146 |
} |
1147 |
} |
1148 |
} |
1149 |
} |
1150 |
|
1151 |
// Have to override this to avoid classcast exception on casting DOM nodes. |
1152 |
public void characters(char[] characters, int start, int length) throws SAXException { |
1153 |
} |
1154 |
|
1155 |
public boolean hasExtensions() { |
1156 |
return fHasExtentions; |
1157 |
} |
1158 |
|
1159 |
} |
1086 |
} |
1160 |
} |