Lines 10-19
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.pde.api.tools.internal.builder; |
11 |
package org.eclipse.pde.api.tools.internal.builder; |
12 |
|
12 |
|
13 |
import java.util.ArrayList; |
|
|
14 |
import java.util.HashSet; |
13 |
import java.util.HashSet; |
15 |
import java.util.Iterator; |
14 |
import java.util.Iterator; |
16 |
import java.util.List; |
|
|
17 |
import java.util.Set; |
15 |
import java.util.Set; |
18 |
|
16 |
|
19 |
import org.eclipse.core.resources.IFile; |
17 |
import org.eclipse.core.resources.IFile; |
Lines 86-94
Link Here
|
86 |
} else if (Util.isJavaFileName(fileName)) { |
84 |
} else if (Util.isJavaFileName(fileName)) { |
87 |
IProject project = resource.getProject(); |
85 |
IProject project = resource.getProject(); |
88 |
if (this.project.equals(project)) { |
86 |
if (this.project.equals(project)) { |
89 |
if (delta.getKind() == IResourceDelta.ADDED) { |
|
|
90 |
IncrementalApiBuilder.this.addremovedeltas.add(delta); |
91 |
} |
92 |
IncrementalApiBuilder.this.changedtypes.add(resource); |
87 |
IncrementalApiBuilder.this.changedtypes.add(resource); |
93 |
} |
88 |
} |
94 |
else if (this.projects != null && this.projects.contains(project)) { |
89 |
else if (this.projects != null && this.projects.contains(project)) { |
Lines 102-110
Link Here
|
102 |
} |
97 |
} |
103 |
|
98 |
|
104 |
ApiAnalysisBuilder builder = null; |
99 |
ApiAnalysisBuilder builder = null; |
105 |
//IProject project = null; |
|
|
106 |
HashSet changedtypes = new HashSet(16); |
100 |
HashSet changedtypes = new HashSet(16); |
107 |
HashSet addremovedeltas = new HashSet(8); |
101 |
HashSet removedtypes = new HashSet(16); |
108 |
StringSet typenames = new StringSet(16); |
102 |
StringSet typenames = new StringSet(16); |
109 |
StringSet packages = new StringSet(16); |
103 |
StringSet packages = new StringSet(16); |
110 |
|
104 |
|
Lines 164-170
Link Here
|
164 |
localmonitor.done(); |
158 |
localmonitor.done(); |
165 |
} |
159 |
} |
166 |
this.changedtypes.clear(); |
160 |
this.changedtypes.clear(); |
167 |
this.addremovedeltas.clear(); |
161 |
this.removedtypes.clear(); |
168 |
this.typenames.clear(); |
162 |
this.typenames.clear(); |
169 |
this.packages.clear(); |
163 |
this.packages.clear(); |
170 |
} |
164 |
} |
Lines 177-183
Link Here
|
177 |
* @param state |
171 |
* @param state |
178 |
* @param monitor |
172 |
* @param monitor |
179 |
*/ |
173 |
*/ |
180 |
private void build(final IProject project, final State state, IApiBaseline baseline, BuildState buildstate, IProgressMonitor monitor) throws CoreException { |
174 |
void build(final IProject project, final State state, IApiBaseline baseline, BuildState buildstate, IProgressMonitor monitor) throws CoreException { |
181 |
IApiBaseline wsprofile = null; |
175 |
IApiBaseline wsprofile = null; |
182 |
try { |
176 |
try { |
183 |
// clear the old state so a full build will occur if this one is cancelled or terminates prematurely |
177 |
// clear the old state so a full build will occur if this one is cancelled or terminates prematurely |
Lines 204-211
Link Here
|
204 |
if(comp == null) { |
198 |
if(comp == null) { |
205 |
return; |
199 |
return; |
206 |
} |
200 |
} |
207 |
List tnames = new ArrayList(typesize), |
201 |
HashSet tnames = new HashSet(typesize), |
208 |
cnames = new ArrayList(typesize); |
202 |
cnames = new HashSet(typesize); |
209 |
collectAllQualifiedNames(project, this.changedtypes, tnames, cnames, localmonitor.newChild(1)); |
203 |
collectAllQualifiedNames(project, this.changedtypes, tnames, cnames, localmonitor.newChild(1)); |
210 |
this.builder.updateMonitor(localmonitor, 1); |
204 |
this.builder.updateMonitor(localmonitor, 1); |
211 |
this.builder.getAnalyzer().analyzeComponent(buildstate, |
205 |
this.builder.getAnalyzer().analyzeComponent(buildstate, |
Lines 239-245
Link Here
|
239 |
* @param state |
233 |
* @param state |
240 |
* @param typesToCheck |
234 |
* @param typesToCheck |
241 |
*/ |
235 |
*/ |
242 |
private void collectAffectedSourceFiles(final IProject project, State state, Set typesToCheck) { |
236 |
void collectAffectedSourceFiles(final IProject project, State state, Set typesToCheck) { |
243 |
// the qualifiedStrings are of the form 'p1/p2' & the simpleStrings are just 'X' |
237 |
// the qualifiedStrings are of the form 'p1/p2' & the simpleStrings are just 'X' |
244 |
char[][][] internedQualifiedNames = ReferenceCollection.internQualifiedNames(this.packages); |
238 |
char[][][] internedQualifiedNames = ReferenceCollection.internQualifiedNames(this.packages); |
245 |
// if a well known qualified name was found then we can skip over these |
239 |
// if a well known qualified name was found then we can skip over these |
Lines 255-271
Link Here
|
255 |
Object[] valueTable = state.getReferences().valueTable; |
249 |
Object[] valueTable = state.getReferences().valueTable; |
256 |
IFile file = null; |
250 |
IFile file = null; |
257 |
String typeLocator = null; |
251 |
String typeLocator = null; |
258 |
next : for (int i = 0, l = valueTable.length; i < l; i++) { |
252 |
for (int i = 0; i < valueTable.length; i++) { |
259 |
typeLocator = (String) keyTable[i]; |
253 |
typeLocator = (String) keyTable[i]; |
260 |
if (typeLocator != null) { |
254 |
if (typeLocator != null) { |
261 |
ReferenceCollection refs = (ReferenceCollection) valueTable[i]; |
255 |
ReferenceCollection refs = (ReferenceCollection) valueTable[i]; |
262 |
if (refs.includes(internedQualifiedNames, internedSimpleNames, null)) { |
256 |
if (refs.includes(internedQualifiedNames, internedSimpleNames, null)) { |
263 |
file = project.getFile(typeLocator); |
257 |
file = project.getFile(typeLocator); |
264 |
if (file == null) { |
258 |
if (file == null) { |
265 |
continue next; |
259 |
continue; |
266 |
} |
260 |
} |
267 |
if (ApiAnalysisBuilder.DEBUG) { |
261 |
if (ApiAnalysisBuilder.DEBUG) { |
268 |
System.out.println(" adding affected source file " + typeLocator); //$NON-NLS-1$ |
262 |
System.out.println(" adding affected source file " + file.getName()); //$NON-NLS-1$ |
269 |
} |
263 |
} |
270 |
typesToCheck.add(file); |
264 |
typesToCheck.add(file); |
271 |
} |
265 |
} |
Lines 277-295
Link Here
|
277 |
* Finds affected source files for a resource that has changed that either contains class files or is itself a class file |
271 |
* Finds affected source files for a resource that has changed that either contains class files or is itself a class file |
278 |
* @param binaryDelta |
272 |
* @param binaryDelta |
279 |
*/ |
273 |
*/ |
280 |
private void findAffectedSourceFiles(IResourceDelta binaryDelta) { |
274 |
void findAffectedSourceFiles(IResourceDelta binaryDelta) { |
281 |
IResource resource = binaryDelta.getResource(); |
275 |
IResource resource = binaryDelta.getResource(); |
282 |
if(resource.getType() == IResource.FILE) { |
276 |
if(resource.getType() == IResource.FILE) { |
283 |
if (Util.isClassFile(resource.getName())) { |
277 |
if (Util.isClassFile(resource.getName())) { |
|
|
278 |
IPath typePath = resolveJavaPathFromResource(resource); |
279 |
if(typePath == null) { |
280 |
return; |
281 |
} |
284 |
switch (binaryDelta.getKind()) { |
282 |
switch (binaryDelta.getKind()) { |
285 |
case IResourceDelta.REMOVED : |
283 |
case IResourceDelta.REMOVED : { |
286 |
this.addremovedeltas.add(binaryDelta); |
284 |
//directly add the removed type |
|
|
285 |
this.removedtypes.add(typePath.toString().replace('/', '.')); |
286 |
} |
287 |
//$FALL-THROUGH$ |
287 |
//$FALL-THROUGH$ |
288 |
case IResourceDelta.ADDED : { |
288 |
case IResourceDelta.ADDED : { |
289 |
IPath typePath = resolveJavaPathFromResource(resource); |
|
|
290 |
if(typePath == null) { |
291 |
return; |
292 |
} |
293 |
if (ApiAnalysisBuilder.DEBUG) { |
289 |
if (ApiAnalysisBuilder.DEBUG) { |
294 |
System.out.println("Found added/removed class file " + typePath); //$NON-NLS-1$ |
290 |
System.out.println("Found added/removed class file " + typePath); //$NON-NLS-1$ |
295 |
} |
291 |
} |
Lines 300-309
Link Here
|
300 |
if ((binaryDelta.getFlags() & IResourceDelta.CONTENT) == 0) { |
296 |
if ((binaryDelta.getFlags() & IResourceDelta.CONTENT) == 0) { |
301 |
return; // skip it since it really isn't changed |
297 |
return; // skip it since it really isn't changed |
302 |
} |
298 |
} |
303 |
IPath typePath = resolveJavaPathFromResource(resource); |
|
|
304 |
if(typePath == null) { |
305 |
return; |
306 |
} |
307 |
if (ApiAnalysisBuilder.DEBUG) { |
299 |
if (ApiAnalysisBuilder.DEBUG) { |
308 |
System.out.println("Found changed class file " + typePath); //$NON-NLS-1$ |
300 |
System.out.println("Found changed class file " + typePath); //$NON-NLS-1$ |
309 |
} |
301 |
} |
Lines 342-357
Link Here
|
342 |
* @param cnames the list to collect the changed type names into |
334 |
* @param cnames the list to collect the changed type names into |
343 |
* @param monitor |
335 |
* @param monitor |
344 |
*/ |
336 |
*/ |
345 |
private void collectAllQualifiedNames(final IProject project, final HashSet alltypes, List tnames, List cnames, final IProgressMonitor monitor) { |
337 |
void collectAllQualifiedNames(final IProject project, final HashSet alltypes, HashSet tnames, HashSet cnames, final IProgressMonitor monitor) { |
346 |
IType[] types = null; |
338 |
IType[] types = null; |
347 |
IFile file = null; |
339 |
IFile file = null; |
|
|
340 |
ICompilationUnit unit = null; |
341 |
IType type = null; |
348 |
for (Iterator iterator = alltypes.iterator(); iterator.hasNext(); ) { |
342 |
for (Iterator iterator = alltypes.iterator(); iterator.hasNext(); ) { |
349 |
file = (IFile) iterator.next(); |
343 |
file = (IFile) iterator.next(); |
350 |
ICompilationUnit unit = (ICompilationUnit) JavaCore.create(file); |
344 |
unit = (ICompilationUnit) JavaCore.create(file); |
351 |
if(!unit.exists()) { |
345 |
if(!unit.exists()) { |
352 |
continue; |
346 |
continue; |
353 |
} |
347 |
} |
354 |
IType type = unit.findPrimaryType(); |
348 |
type = unit.findPrimaryType(); |
355 |
if(type == null) { |
349 |
if(type == null) { |
356 |
continue; |
350 |
continue; |
357 |
} |
351 |
} |
Lines 360-379
Link Here
|
360 |
this.builder.updateMonitor(monitor, 0); |
354 |
this.builder.updateMonitor(monitor, 0); |
361 |
this.builder.cleanupCompatibilityMarkers(file); |
355 |
this.builder.cleanupCompatibilityMarkers(file); |
362 |
this.builder.updateMonitor(monitor, 0); |
356 |
this.builder.updateMonitor(monitor, 0); |
|
|
357 |
this.builder.cleanupUsageMarkers(file); |
358 |
this.builder.updateMonitor(monitor, 0); |
363 |
cnames.add(type.getFullyQualifiedName()); |
359 |
cnames.add(type.getFullyQualifiedName()); |
364 |
try { |
360 |
try { |
365 |
this.builder.cleanupUsageMarkers(file); |
|
|
366 |
this.builder.updateMonitor(monitor, 0); |
367 |
types = unit.getAllTypes(); |
361 |
types = unit.getAllTypes(); |
368 |
String tname = null; |
|
|
369 |
for (int i = 0; i < types.length; i++) { |
362 |
for (int i = 0; i < types.length; i++) { |
370 |
IType type2 = types[i]; |
363 |
if (types[i].isMember()) { |
371 |
if (type2.isMember()) { |
364 |
tnames.add(types[i].getFullyQualifiedName('$')); |
372 |
tname = type2.getFullyQualifiedName('$'); |
|
|
373 |
} else { |
365 |
} else { |
374 |
tname = type2.getFullyQualifiedName(); |
366 |
tnames.add(types[i].getFullyQualifiedName()); |
375 |
} |
367 |
} |
376 |
tnames.add(tname); |
|
|
377 |
} |
368 |
} |
378 |
} catch (JavaModelException e) { |
369 |
} catch (JavaModelException e) { |
379 |
ApiPlugin.log(e.getStatus()); |
370 |
ApiPlugin.log(e.getStatus()); |
Lines 381-488
Link Here
|
381 |
this.builder.updateMonitor(monitor, 0); |
372 |
this.builder.updateMonitor(monitor, 0); |
382 |
} |
373 |
} |
383 |
// inject removed types inside changed type names so that we can properly detect type removal |
374 |
// inject removed types inside changed type names so that we can properly detect type removal |
384 |
IResourceDelta delta = null; |
375 |
cnames.addAll(this.removedtypes); |
385 |
for (Iterator iterator = this.addremovedeltas.iterator(); iterator.hasNext(); ) { |
|
|
386 |
delta = (IResourceDelta) iterator.next(); |
387 |
if (delta.getKind() != IResourceDelta.REMOVED) { |
388 |
continue; |
389 |
} |
390 |
IResource resource = delta.getResource(); |
391 |
IPath typePath = resolveJavaPathFromResource(resource); |
392 |
if(typePath == null) { |
393 |
continue; |
394 |
} |
395 |
// record removed type names (package + type) |
396 |
StringBuffer buffer = new StringBuffer(); |
397 |
String[] segments = typePath.segments(); |
398 |
for (int i = 0, max = segments.length; i < max; i++) { |
399 |
if (i > 0) { |
400 |
buffer.append('.'); |
401 |
} |
402 |
buffer.append(segments[i]); |
403 |
} |
404 |
cnames.add(String.valueOf(buffer)); |
405 |
} |
406 |
// clean up markers on added deltas |
407 |
if (!this.addremovedeltas.isEmpty()) { |
408 |
IResource manifestFile = Util.getManifestFile(project); |
409 |
if (manifestFile != null) { |
410 |
try { |
411 |
IMarker[] markers = manifestFile.findMarkers(IApiMarkerConstants.COMPATIBILITY_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE); |
412 |
for (int i = 0, max = markers.length; i < max; i++) { |
413 |
IMarker marker = markers[i]; |
414 |
String typeName = marker.getAttribute(IApiMarkerConstants.MARKER_ATTR_PROBLEM_TYPE_NAME, null); |
415 |
if (typeName != null) { |
416 |
for (Iterator iterator = this.addremovedeltas.iterator(); iterator.hasNext(); ) { |
417 |
delta = (IResourceDelta) iterator.next(); |
418 |
if (delta.getKind() != IResourceDelta.ADDED) { |
419 |
continue; |
420 |
} |
421 |
ICompilationUnit unit = (ICompilationUnit) JavaCore.create(delta.getResource()); |
422 |
if(!unit.exists()) { |
423 |
continue; |
424 |
} |
425 |
IType type = unit.findPrimaryType(); |
426 |
if(type == null) { |
427 |
continue; |
428 |
} |
429 |
if (typeName.equals(type.getFullyQualifiedName())) { |
430 |
marker.delete(); |
431 |
return; |
432 |
} else { |
433 |
// check secondary types |
434 |
try { |
435 |
types = unit.getAllTypes(); |
436 |
for (int j = 0; j < types.length; j++) { |
437 |
IType type2 = types[i]; |
438 |
String fullyQualifiedName = null; |
439 |
if (type2.isMember()) { |
440 |
fullyQualifiedName = type2.getFullyQualifiedName('$'); |
441 |
} else { |
442 |
fullyQualifiedName = type2.getFullyQualifiedName(); |
443 |
} |
444 |
if (typeName.equals(fullyQualifiedName)) { |
445 |
marker.delete(); |
446 |
return; |
447 |
} |
448 |
} |
449 |
} catch (JavaModelException e) { |
450 |
ApiPlugin.log(e.getStatus()); |
451 |
} |
452 |
} |
453 |
} |
454 |
} |
455 |
} |
456 |
} catch (CoreException e) { |
457 |
ApiPlugin.log(e.getStatus()); |
458 |
} |
459 |
} |
460 |
} |
461 |
IResource resource = project.findMember(ApiAnalysisBuilder.MANIFEST_PATH); |
376 |
IResource resource = project.findMember(ApiAnalysisBuilder.MANIFEST_PATH); |
462 |
if (resource != null) { |
377 |
if (resource != null) { |
463 |
try { |
378 |
try { |
464 |
IMarker[] markers = resource.findMarkers(IApiMarkerConstants.COMPATIBILITY_PROBLEM_MARKER, false, IResource.DEPTH_ZERO); |
379 |
IMarker[] markers = resource.findMarkers(IApiMarkerConstants.COMPATIBILITY_PROBLEM_MARKER, false, IResource.DEPTH_ZERO); |
465 |
loop: for (int i = 0, max = markers.length; i < max; i++) { |
380 |
for (int i = 0; i < markers.length; i++) { |
466 |
IMarker marker = markers[i]; |
381 |
if(tnames.contains(Util.getTypeNameFromMarker(markers[i]))) { |
467 |
String typeNameFromMarker = Util.getTypeNameFromMarker(marker); |
382 |
markers[i].delete(); |
468 |
for (Iterator iterator = tnames.iterator(); iterator.hasNext(); ) { |
|
|
469 |
String typeName = (String) iterator.next(); |
470 |
if (typeName.equals(typeNameFromMarker)) { |
471 |
marker.delete(); |
472 |
continue loop; |
473 |
} |
474 |
} |
383 |
} |
475 |
} |
384 |
} |
476 |
markers = resource.findMarkers(IApiMarkerConstants.SINCE_TAGS_PROBLEM_MARKER, false, IResource.DEPTH_ZERO); |
385 |
markers = resource.findMarkers(IApiMarkerConstants.SINCE_TAGS_PROBLEM_MARKER, false, IResource.DEPTH_ZERO); |
477 |
loop: for (int i = 0, max = markers.length; i < max; i++) { |
386 |
for (int i = 0; i < markers.length; i++) { |
478 |
IMarker marker = markers[i]; |
387 |
if(tnames.contains(Util.getTypeNameFromMarker(markers[i]))) { |
479 |
String typeNameFromMarker = Util.getTypeNameFromMarker(marker); |
388 |
markers[i].delete(); |
480 |
for (Iterator iterator = tnames.iterator(); iterator.hasNext(); ) { |
|
|
481 |
String typeName = (String) iterator.next(); |
482 |
if (typeName.equals(typeNameFromMarker)) { |
483 |
marker.delete(); |
484 |
continue loop; |
485 |
} |
486 |
} |
389 |
} |
487 |
} |
390 |
} |
488 |
} catch (CoreException e) { |
391 |
} catch (CoreException e) { |
Lines 490-496
Link Here
|
490 |
} |
393 |
} |
491 |
} |
394 |
} |
492 |
} |
395 |
} |
493 |
|
396 |
|
494 |
/** |
397 |
/** |
495 |
* Resolves the java path from the given resource |
398 |
* Resolves the java path from the given resource |
496 |
* @param resource |
399 |
* @param resource |