View | Details | Raw Unified | Return to bug 228887 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/pde/internal/ui/PDEUIMessages.java (-2 / +2 lines)
Lines 2498-2506 Link Here
2498
2498
2499
	public static String UpdateActivationResolution_lazyStart_label;
2499
	public static String UpdateActivationResolution_lazyStart_label;
2500
2500
2501
	public static String AddSingleon_dir_label;
2501
	public static String AddSingleton_dir_label;
2502
2502
2503
	public static String AddSingleon_att_label;
2503
	public static String AddSingleton_att_label;
2504
2504
2505
	public static String AddSingleon_dir_desc;
2505
	public static String AddSingleon_dir_desc;
2506
2506
(-)src/org/eclipse/pde/internal/ui/pderesources.properties (-2 / +2 lines)
Lines 476-483 Link Here
476
AdvancedLauncherTab_workspacePlugins = Workspace
476
AdvancedLauncherTab_workspacePlugins = Workspace
477
AddActivationHeaderResolution_label=Add ''{0}'' header
477
AddActivationHeaderResolution_label=Add ''{0}'' header
478
AddBuildEntryResolution_add=Add {0} to the {1} build entry.
478
AddBuildEntryResolution_add=Add {0} to the {1} build entry.
479
AddSingleon_dir_desc=Plug-ins declaring extensions or extension points must set the 'singleton' directive to 'true'.
479
AddSingleton_dir_desc=Plug-ins declaring extensions or extension points must set the 'singleton' directive to 'true'.
480
AddSingleon_att_desc=Plug-ins declaring extensions or extension points must set the 'singleton' attribute to 'true'.
480
AddSingleton_att_desc=Plug-ins declaring extensions or extension points must set the 'singleton' attribute to 'true'.
481
AdvancedLauncherTab_selectAll = &Select All
481
AdvancedLauncherTab_selectAll = &Select All
482
AdvancedLauncherTab_deselectAll = D&eselect All
482
AdvancedLauncherTab_deselectAll = D&eselect All
483
AddLibraryDialog_emptyLibraries=Cannot add empty libraries.
483
AddLibraryDialog_emptyLibraries=Cannot add empty libraries.
(-)src/org/eclipse/pde/internal/ui/correction/AddSingletonToSymbolicName.java (-2 / +2 lines)
Lines 34-41 Link Here
34
34
35
	public String getLabel() {
35
	public String getLabel() {
36
		if (fisDirective)
36
		if (fisDirective)
37
			return PDEUIMessages.AddSingleon_dir_label;
37
			return PDEUIMessages.AddSingleton_dir_label;
38
		return PDEUIMessages.AddSingleon_att_label;
38
		return PDEUIMessages.AddSingleton_att_label;
39
	}
39
	}
40
40
41
	protected void createChange(BundleModel model) {
41
	protected void createChange(BundleModel model) {
(-)src/org/eclipse/pde/internal/core/builders/ExtensionsErrorReporter.java (-2 / +9 lines)
Lines 52-57 Link Here
52
		Element element = getDocumentRoot();
52
		Element element = getDocumentRoot();
53
		if (element == null)
53
		if (element == null)
54
			return;
54
			return;
55
		
56
		boolean foundExtensionsOrExtensionPoint = false;
55
		String elementName = element.getNodeName();
57
		String elementName = element.getNodeName();
56
		if (!"plugin".equals(elementName) && !"fragment".equals(elementName)) { //$NON-NLS-1$ //$NON-NLS-2$
58
		if (!"plugin".equals(elementName) && !"fragment".equals(elementName)) { //$NON-NLS-1$ //$NON-NLS-2$
57
			reportIllegalElement(element, CompilerFlags.ERROR);
59
			reportIllegalElement(element, CompilerFlags.ERROR);
Lines 72-79 Link Here
72
				String name = child.getNodeName();
74
				String name = child.getNodeName();
73
				if (name.equals("extension")) { //$NON-NLS-1$
75
				if (name.equals("extension")) { //$NON-NLS-1$
74
					validateExtension(child);
76
					validateExtension(child);
77
					foundExtensionsOrExtensionPoint = true;
75
				} else if (name.equals("extension-point")) { //$NON-NLS-1$
78
				} else if (name.equals("extension-point")) { //$NON-NLS-1$
76
					validateExtensionPoint(child);
79
					validateExtensionPoint(child);
80
					foundExtensionsOrExtensionPoint = true;
77
				} else {
81
				} else {
78
					if (!name.equals("runtime") && !name.equals("requires")) { //$NON-NLS-1$ //$NON-NLS-2$
82
					if (!name.equals("runtime") && !name.equals("requires")) { //$NON-NLS-1$ //$NON-NLS-2$
79
						severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT);
83
						severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT);
Lines 87-95 Link Here
87
				}
91
				}
88
			}
92
			}
89
93
90
			IExtensions extensions = fModel.getExtensions();
94
			// fModel.getExtensions() cannot be used since singleton might not be set to true in which cases getExtensions always return 0 even if there is extension points defined.
91
			if (extensions != null && extensions.getExtensions().length == 0 && extensions.getExtensionPoints().length == 0)
95
			//IExtensions extensions = fModel.getExtensions();
96
			//if (extensions != null && extensions.getExtensions().length == 0 && extensions.getExtensionPoints().length == 0)
97
			if(!foundExtensionsOrExtensionPoint) {
92
				report(PDECoreMessages.Builders_Manifest_useless_file, -1, IMarker.SEVERITY_WARNING, PDEMarkerFactory.P_USELESS_FILE, PDEMarkerFactory.CAT_OTHER);
98
				report(PDECoreMessages.Builders_Manifest_useless_file, -1, IMarker.SEVERITY_WARNING, PDEMarkerFactory.P_USELESS_FILE, PDEMarkerFactory.CAT_OTHER);
99
			}
93
		}
100
		}
94
	}
101
	}
95
102
(-)src/org/eclipse/pde/internal/core/builders/BundleErrorReporter.java (-10 / +84 lines)
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
}
(-)src/org/eclipse/pde/internal/core/builders/XMLErrorReporter.java (-1 / +1 lines)
Lines 149-155 Link Here
149
		return fErrorCount;
149
		return fErrorCount;
150
	}
150
	}
151
151
152
	private void removeFileMarkers() {
152
	protected void removeFileMarkers() {
153
		try {
153
		try {
154
			fFile.deleteMarkers(IMarker.PROBLEM, false, IResource.DEPTH_ZERO);
154
			fFile.deleteMarkers(IMarker.PROBLEM, false, IResource.DEPTH_ZERO);
155
			fFile.deleteMarkers(PDEMarkerFactory.MARKER_ID, false, IResource.DEPTH_ZERO);
155
			fFile.deleteMarkers(PDEMarkerFactory.MARKER_ID, false, IResource.DEPTH_ZERO);

Return to bug 228887