Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 234023 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/pde/api/tools/model/tests/TagScannerTests.java (-3 / +3 lines)
Lines 79-85 Link Here
79
	 */
79
	 */
80
	protected void doScan(String name, IApiDescription manifest, IClassFileContainer cfc) {
80
	protected void doScan(String name, IApiDescription manifest, IClassFileContainer cfc) {
81
		try {
81
		try {
82
			TagScanner.newScanner().scan(getCompilationUnit(name), manifest, cfc);
82
			TagScanner.newScanner().scan(getCompilationUnit(name), manifest, cfc, null);
83
		}
83
		}
84
		catch(CoreException e) {
84
		catch(CoreException e) {
85
			fail(MessageFormat.format("Error scanning: {0}", new String[] {name}));
85
			fail(MessageFormat.format("Error scanning: {0}", new String[] {name}));
Lines 93-99 Link Here
93
	 */
93
	 */
94
	protected void doScan(String name, IApiDescription manifest) {
94
	protected void doScan(String name, IApiDescription manifest) {
95
		try {
95
		try {
96
			TagScanner.newScanner().scan(getCompilationUnit(name), manifest, null);
96
			TagScanner.newScanner().scan(getCompilationUnit(name), manifest, null, null);
97
		}
97
		}
98
		catch(CoreException e) {
98
		catch(CoreException e) {
99
			fail(MessageFormat.format("Error scanning: {0}", new String[] {name}));
99
			fail(MessageFormat.format("Error scanning: {0}", new String[] {name}));
Lines 152-158 Link Here
152
		};
152
		};
153
		IApiDescription manifest = newDescription();
153
		IApiDescription manifest = newDescription();
154
		try { 
154
		try { 
155
			TagScanner.newScanner().scan(getCompilationUnit("a/b/c/TestMethod10.java"), manifest, container);
155
			TagScanner.newScanner().scan(getCompilationUnit("a/b/c/TestMethod10.java"), manifest, container, null);
156
		} catch (CoreException e) {
156
		} catch (CoreException e) {
157
			return;
157
			return;
158
		}
158
		}
(-)src_ant/org/eclipse/pde/api/tools/internal/tasks/ApiFileGeneratorTask.java (-65 / +102 lines)
Lines 30-35 Link Here
30
import org.apache.tools.ant.BuildException;
30
import org.apache.tools.ant.BuildException;
31
import org.apache.tools.ant.Task;
31
import org.apache.tools.ant.Task;
32
import org.eclipse.core.runtime.CoreException;
32
import org.eclipse.core.runtime.CoreException;
33
import org.eclipse.jdt.core.JavaCore;
33
import org.eclipse.osgi.util.ManifestElement;
34
import org.eclipse.osgi.util.ManifestElement;
34
import org.eclipse.pde.api.tools.internal.ApiDescription;
35
import org.eclipse.pde.api.tools.internal.ApiDescription;
35
import org.eclipse.pde.api.tools.internal.ApiSettingsXmlVisitor;
36
import org.eclipse.pde.api.tools.internal.ApiSettingsXmlVisitor;
Lines 40-45 Link Here
40
import org.eclipse.pde.api.tools.internal.provisional.scanner.TagScanner;
41
import org.eclipse.pde.api.tools.internal.provisional.scanner.TagScanner;
41
import org.eclipse.pde.api.tools.internal.util.Util;
42
import org.eclipse.pde.api.tools.internal.util.Util;
42
import org.osgi.framework.BundleException;
43
import org.osgi.framework.BundleException;
44
import org.osgi.framework.Constants;
43
import org.xml.sax.Attributes;
45
import org.xml.sax.Attributes;
44
import org.xml.sax.InputSource;
46
import org.xml.sax.InputSource;
45
import org.xml.sax.SAXException;
47
import org.xml.sax.SAXException;
Lines 158-163 Link Here
158
				return (path.isFile() && Util.isJavaFileName(path.getName())) || path.isDirectory();
160
				return (path.isFile() && Util.isJavaFileName(path.getName())) || path.isDirectory();
159
			}
161
			}
160
		});
162
		});
163
		File manifestFile = null;
164
		Map manifestMap = null;
165
		if (targetProjectFolder.exists() && targetProjectFolder.isDirectory()) {
166
			File manifestDir = new File(targetProjectFolder, "META-INF"); //$NON-NLS-1$
167
			if (manifestDir.exists() && manifestDir.isDirectory()) {
168
				manifestFile = new File(manifestDir, "MANIFEST.MF"); //$NON-NLS-1$
169
			}
170
			if (manifestFile.exists()) {
171
				BufferedInputStream inputStream = null;
172
				try {
173
					inputStream = new BufferedInputStream(new FileInputStream(manifestFile));
174
					manifestMap = ManifestElement.parseBundleManifest(inputStream, null);
175
				} catch (FileNotFoundException e) {
176
					ApiPlugin.log(e);
177
				} catch (IOException e) {
178
					ApiPlugin.log(e);
179
				} catch (BundleException e) {
180
					ApiPlugin.log(e);
181
				} finally {
182
					if (inputStream != null) {
183
						try {
184
							inputStream.close();
185
						} catch(IOException e) {
186
							// ignore
187
						}
188
					}
189
				}
190
			}
191
		}
161
		ApiDescription apiDescription = new ApiDescription(this.projectName);
192
		ApiDescription apiDescription = new ApiDescription(this.projectName);
162
		TagScanner tagScanner = TagScanner.newScanner();
193
		TagScanner tagScanner = TagScanner.newScanner();
163
		if (allFiles != null) {
194
		if (allFiles != null) {
Lines 167-173 Link Here
167
					System.out.println("Unit name[" + i + "] : " + unit.getName()); //$NON-NLS-1$ //$NON-NLS-2$
198
					System.out.println("Unit name[" + i + "] : " + unit.getName()); //$NON-NLS-1$ //$NON-NLS-2$
168
				}
199
				}
169
				try {
200
				try {
170
					tagScanner.scan(unit, apiDescription, classFileContainer);
201
					//default to highest, since we have no EE context
202
					//TODO should use EE context to resolve a compliance level
203
					Map options = JavaCore.getOptions();
204
					options.put(JavaCore.COMPILER_COMPLIANCE, resolveCompliance(manifestMap));
205
					tagScanner.scan(unit, apiDescription, classFileContainer, options);
171
				} catch (CoreException e) {
206
				} catch (CoreException e) {
172
					ApiPlugin.log(e);
207
					ApiPlugin.log(e);
173
				}
208
				}
Lines 176-250 Link Here
176
		// check the manifest file
211
		// check the manifest file
177
		String componentName = this.projectName;
212
		String componentName = this.projectName;
178
		String componentID = this.projectName;
213
		String componentID = this.projectName;
179
		if (targetProjectFolder.exists() && targetProjectFolder.isDirectory()) {
214
		if (manifestMap != null && DEBUG) {
180
			File manifestDir = new File(targetProjectFolder, "META-INF"); //$NON-NLS-1$
215
			for (Iterator iterator = manifestMap.keySet().iterator(); iterator.hasNext(); ) {
181
			if (manifestDir.exists() && manifestDir.isDirectory()) {
216
				Object key = iterator.next();
182
				File manifestFile = new File(manifestDir, "MANIFEST.MF"); //$NON-NLS-1$
217
				System.out.print("key = " + key); //$NON-NLS-1$
183
				if (manifestFile.exists()) {
218
				System.out.println(" value = " + manifestMap.get(key)); //$NON-NLS-1$
184
					BufferedInputStream inputStream = null;
219
			}
185
					Map manifestMap = null;
220
			String localization = (String) manifestMap.get(org.osgi.framework.Constants.BUNDLE_LOCALIZATION);
186
					try {
221
			String name = (String) manifestMap.get(org.osgi.framework.Constants.BUNDLE_NAME);
187
						inputStream = new BufferedInputStream(new FileInputStream(manifestFile));
222
			String nameKey = (name != null && name.startsWith("%")) ? name.substring(1) : null; //$NON-NLS-1$;
188
						manifestMap = ManifestElement.parseBundleManifest(inputStream, null);
223
			if (nameKey != null) {
189
					} catch (FileNotFoundException e) {
224
				Properties properties = new Properties();
190
						ApiPlugin.log(e);
225
				BufferedInputStream inputStream = null;
191
					} catch (IOException e) {
226
				try {
192
						ApiPlugin.log(e);
227
					inputStream = new BufferedInputStream(new FileInputStream(new File(targetProjectFolder, localization + ".properties"))); //$NON-NLS-1$
193
					} catch (BundleException e) {
228
					properties.load(inputStream);
194
						ApiPlugin.log(e);
229
				} catch(IOException e) {
195
					} finally {
230
					ApiPlugin.log(e);
196
						if (inputStream != null) {
231
				} finally {
197
							try {
232
					if (inputStream != null) {
198
								inputStream.close();
199
							} catch(IOException e) {
200
								// ignore
201
							}
202
						}
203
					}
204
					if (manifestMap != null && DEBUG) {
205
						for (Iterator iterator = manifestMap.keySet().iterator(); iterator.hasNext(); ) {
206
							Object key = iterator.next();
207
							System.out.print("key = " + key); //$NON-NLS-1$
208
							System.out.println(" value = " + manifestMap.get(key)); //$NON-NLS-1$
209
						}
210
					}
211
					String localization = (String) manifestMap.get(org.osgi.framework.Constants.BUNDLE_LOCALIZATION);
212
					String name = (String) manifestMap.get(org.osgi.framework.Constants.BUNDLE_NAME);
213
					String nameKey = (name != null && name.startsWith("%")) ? name.substring(1) : null; //$NON-NLS-1$;
214
					if (nameKey != null) {
215
						Properties properties = new Properties();
216
						inputStream = null;
217
						try {
233
						try {
218
							inputStream = new BufferedInputStream(new FileInputStream(new File(targetProjectFolder, localization + ".properties"))); //$NON-NLS-1$
234
							inputStream.close();
219
							properties.load(inputStream);
220
						} catch(IOException e) {
235
						} catch(IOException e) {
221
							ApiPlugin.log(e);
236
							// ignore
222
						} finally {
223
							if (inputStream != null) {
224
								try {
225
									inputStream.close();
226
								} catch(IOException e) {
227
									// ignore
228
								}
229
							}
230
						}
231
						String property = properties.getProperty(nameKey);
232
						if (property != null) {
233
							componentName = property.trim();
234
						}
235
					} else {
236
						componentName = name;
237
					}
238
					String symbolicName = (String) manifestMap.get(org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME);
239
					if (symbolicName != null) {
240
						int indexOf = symbolicName.indexOf(';');
241
						if (indexOf == -1) {
242
							componentID = symbolicName.trim();
243
						} else {
244
							componentID = symbolicName.substring(0, indexOf).trim();
245
						}
237
						}
246
					}
238
					}
247
				}
239
				}
240
				String property = properties.getProperty(nameKey);
241
				if (property != null) {
242
					componentName = property.trim();
243
				}
244
			} else {
245
				componentName = name;
246
			}
247
			String symbolicName = (String) manifestMap.get(org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME);
248
			if (symbolicName != null) {
249
				int indexOf = symbolicName.indexOf(';');
250
				if (indexOf == -1) {
251
					componentID = symbolicName.trim();
252
				} else {
253
					componentID = symbolicName.substring(0, indexOf).trim();
254
				}
248
			}
255
			}
249
		}
256
		}
250
		try {
257
		try {
Lines 260-265 Link Here
260
		}
267
		}
261
	}
268
	}
262
269
270
	/**
271
	 * Resolves the compiler compliance based on the BREE entry in the MANIFEST.MF file
272
	 * @param manifestmap
273
	 * @return The derived {@link JavaCore#COMPILER_COMPLIANCE} from the BREE in the manifest map, 
274
	 * or {@link JavaCore#VERSION_1_3} if there is no BREE entry in the map or if the BREE entry does not directly map 
275
	 * to one of {"1.3", "1.4", "1.5", "1.6"}.
276
	 */
277
	private String resolveCompliance(Map manifestmap) {
278
		if(manifestmap != null) {
279
			String eename = (String) manifestmap.get(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT);
280
			if(eename != null) {
281
				if("J2SE-1.4".equals(eename)) { //$NON-NLS-1$
282
					return JavaCore.VERSION_1_4;
283
				}
284
				if("J2SE-1.5".equals(eename)) { //$NON-NLS-1$
285
					return JavaCore.VERSION_1_5;
286
				}
287
				if("JavaSE-1.6".equals(eename)) { //$NON-NLS-1$
288
					return JavaCore.VERSION_1_6;
289
				}
290
			}
291
		}
292
		return JavaCore.VERSION_1_3;
293
	}
294
	
295
	/**
296
	 * Resolves if the '.project' file belongs to an API enabled project or not
297
	 * @param dotProjectFile
298
	 * @return true if the '.project' file is for an API enabled project, false otherwise
299
	 */
263
	private boolean isAPIToolsNature(File dotProjectFile) {
300
	private boolean isAPIToolsNature(File dotProjectFile) {
264
		if (!dotProjectFile.exists()) return false;
301
		if (!dotProjectFile.exists()) return false;
265
		BufferedInputStream stream = null;
302
		BufferedInputStream stream = null;
(-)src/org/eclipse/pde/api/tools/internal/provisional/scanner/TagScanner.java (-4 / +24 lines)
Lines 24-29 Link Here
24
import org.eclipse.core.runtime.IStatus;
24
import org.eclipse.core.runtime.IStatus;
25
import org.eclipse.core.runtime.NullProgressMonitor;
25
import org.eclipse.core.runtime.NullProgressMonitor;
26
import org.eclipse.core.runtime.Status;
26
import org.eclipse.core.runtime.Status;
27
import org.eclipse.jdt.core.ICompilationUnit;
27
import org.eclipse.jdt.core.JavaCore;
28
import org.eclipse.jdt.core.JavaCore;
28
import org.eclipse.jdt.core.Signature;
29
import org.eclipse.jdt.core.Signature;
29
import org.eclipse.jdt.core.dom.AST;
30
import org.eclipse.jdt.core.dom.AST;
Lines 461-467 Link Here
461
	private TagScanner() {}
462
	private TagScanner() {}
462
	
463
	
463
	/**
464
	/**
464
	 * Scans the specified source {@linkplain CompilationUnit} for contributed API javadoc tags.
465
	 * Scans the specified source {@linkplain CompilationUnit} for contributed API Javadoc tags.
465
	 * Tags on methods will have unresolved signatures.
466
	 * Tags on methods will have unresolved signatures.
466
	 * 
467
	 * 
467
	 * @param source the source file to scan for tags
468
	 * @param source the source file to scan for tags
Lines 469-488 Link Here
469
	 * @throws CoreException
470
	 * @throws CoreException
470
	 */
471
	 */
471
	public void scan(CompilationUnit source, IApiDescription description) throws CoreException {
472
	public void scan(CompilationUnit source, IApiDescription description) throws CoreException {
472
		scan(source, description, null);
473
		scan(source, description, null, null);
474
	}
475
	
476
	/**
477
	 * Scans the specified {@link ICompilationUnit} for contributed API Javadoc tags.
478
	 * Tags on methods will have unresolved signatures.
479
	 * @param unit the compilation unit source
480
	 * @param description the API description to annotate with any new tag rules found
481
	 * @param container optional class file container containing the class file for the given source
482
	 * 	that can be used to resolve method signatures if required (for tags on methods). If 
483
	 * 	not provided (<code>null</code>), method signatures will be unresolved.
484
	 * @throws CoreException
485
	 */
486
	public void scan(ICompilationUnit unit, IApiDescription description, IClassFileContainer container) throws CoreException {
487
		scan(new CompilationUnit(unit), description, container, unit.getJavaProject().getOptions(true));
473
	}
488
	}
474
	
489
	
475
	/**
490
	/**
476
	 * Scans the specified source {@linkplain CompilationUnit} for contributed API javadoc tags.
491
	 * Scans the specified source {@linkplain CompilationUnit} for contributed API javadoc tags.
492
	 * Tags on methods will have unresolved signatures.
477
	 * 
493
	 * 
478
	 * @param source the source file to scan for tags
494
	 * @param source the source file to scan for tags
479
	 * @param description the API description to annotate with any new tag rules found
495
	 * @param description the API description to annotate with any new tag rules found
480
	 * @param container optional class file container containing the class file for the given source
496
	 * @param container optional class file container containing the class file for the given source
481
	 * 	that can be used to resolve method signatures if required (for tags on methods). If 
497
	 * 	that can be used to resolve method signatures if required (for tags on methods). If 
482
	 * 	not provided (<code>null</code>), method signatures will be unresolved.
498
	 * 	not provided (<code>null</code>), method signatures will be unresolved.
499
	 * @param options a map of Java compiler options to use when creating the AST to scan
500
	 * 
483
	 * @throws CoreException 
501
	 * @throws CoreException 
484
	 */
502
	 */
485
	public void scan(CompilationUnit source, IApiDescription description, IClassFileContainer container) throws CoreException {
503
	public void scan(CompilationUnit source, IApiDescription description, IClassFileContainer container, Map options) throws CoreException {
486
		ASTParser parser = ASTParser.newParser(AST.JLS3);
504
		ASTParser parser = ASTParser.newParser(AST.JLS3);
487
		InputStream inputStream = null;
505
		InputStream inputStream = null;
488
		try {
506
		try {
Lines 506-512 Link Here
506
				}
524
				}
507
			}
525
			}
508
		}
526
		}
509
		Map options = JavaCore.getOptions();
527
		if(options == null) {
528
			options = JavaCore.getOptions();
529
		}
510
		options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED);
530
		options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED);
511
		parser.setCompilerOptions(options);
531
		parser.setCompilerOptions(options);
512
		org.eclipse.jdt.core.dom.CompilationUnit cunit = (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(new NullProgressMonitor());
532
		org.eclipse.jdt.core.dom.CompilationUnit cunit = (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(new NullProgressMonitor());
(-)src/org/eclipse/pde/api/tools/internal/PluginProjectApiComponent.java (-7 / +5 lines)
Lines 196-213 Link Here
196
		}
196
		}
197
		TagScanner scanner = TagScanner.newScanner();
197
		TagScanner scanner = TagScanner.newScanner();
198
		Iterator iterator = sourceRoots.iterator();
198
		Iterator iterator = sourceRoots.iterator();
199
		ICompilationUnit[] units = null;
200
		IJavaElement[] pkgs = null;
199
		while (iterator.hasNext()) {
201
		while (iterator.hasNext()) {
200
			IPackageFragmentRoot root = (IPackageFragmentRoot) iterator.next();
202
			pkgs = ((IPackageFragmentRoot) iterator.next()).getChildren();
201
			IJavaElement[] pkgs = root.getChildren();
202
			for (int i = 0; i < pkgs.length; i++) {
203
			for (int i = 0; i < pkgs.length; i++) {
203
				if (pkgs[i] instanceof IPackageFragment) {
204
				if (pkgs[i] instanceof IPackageFragment) {
204
					IPackageFragment pkg = (IPackageFragment) pkgs[i];
205
					units = ((IPackageFragment) pkgs[i]).getCompilationUnits();
205
					ICompilationUnit[] units = pkg.getCompilationUnits();
206
					for (int j = 0; j < units.length; j++) {
206
					for (int j = 0; j < units.length; j++) {
207
						ICompilationUnit unit = units[j];
208
						CompilationUnit cu = new CompilationUnit(unit.getResource().getLocation().toOSString());
209
						try {
207
						try {
210
							scanner.scan(cu, apiDescription, this);
208
							scanner.scan(units[j], apiDescription, this);
211
						} catch (CoreException e) {
209
						} catch (CoreException e) {
212
							abort("Unable to initialize from Javadoc tags", e); //$NON-NLS-1$
210
							abort("Unable to initialize from Javadoc tags", e); //$NON-NLS-1$
213
						}
211
						}
(-)src/org/eclipse/pde/api/tools/internal/ProjectApiDescription.java (-1 / +1 lines)
Lines 227-233 Link Here
227
							restrictions = RestrictionModifiers.NO_RESTRICTIONS;
227
							restrictions = RestrictionModifiers.NO_RESTRICTIONS;
228
							fTimeStamp = resource.getModificationStamp();
228
							fTimeStamp = resource.getModificationStamp();
229
							try {
229
							try {
230
								TagScanner.newScanner().scan(new CompilationUnit(unit), ProjectApiDescription.this,
230
								TagScanner.newScanner().scan(unit, ProjectApiDescription.this,
231
									getClassFileContainer((IPackageFragmentRoot) fType.getPackageFragment().getParent()));
231
									getClassFileContainer((IPackageFragmentRoot) fType.getPackageFragment().getParent()));
232
							} catch (CoreException e) {
232
							} catch (CoreException e) {
233
								ApiPlugin.log(e.getStatus());
233
								ApiPlugin.log(e.getStatus());

Return to bug 234023