Lines 14-21
Link Here
|
14 |
package org.eclipse.ajdt.core.builder; |
14 |
package org.eclipse.ajdt.core.builder; |
15 |
|
15 |
|
16 |
import java.io.File; |
16 |
import java.io.File; |
|
|
17 |
import java.lang.reflect.Field; |
17 |
import java.util.ArrayList; |
18 |
import java.util.ArrayList; |
18 |
import java.util.Arrays; |
19 |
import java.util.Arrays; |
|
|
20 |
import java.util.Collection; |
19 |
import java.util.Hashtable; |
21 |
import java.util.Hashtable; |
20 |
import java.util.Iterator; |
22 |
import java.util.Iterator; |
21 |
import java.util.List; |
23 |
import java.util.List; |
Lines 23-29
Link Here
|
23 |
import java.util.Set; |
25 |
import java.util.Set; |
24 |
|
26 |
|
25 |
import org.aspectj.ajde.core.AjCompiler; |
27 |
import org.aspectj.ajde.core.AjCompiler; |
|
|
28 |
import org.aspectj.ajde.core.ICompilerConfiguration; |
26 |
import org.aspectj.ajdt.internal.core.builder.AjState; |
29 |
import org.aspectj.ajdt.internal.core.builder.AjState; |
|
|
30 |
import org.aspectj.ajdt.internal.core.builder.CompilerConfigurationChangeFlags; |
27 |
import org.aspectj.ajdt.internal.core.builder.IStateListener; |
31 |
import org.aspectj.ajdt.internal.core.builder.IStateListener; |
28 |
import org.aspectj.ajdt.internal.core.builder.IncrementalStateManager; |
32 |
import org.aspectj.ajdt.internal.core.builder.IncrementalStateManager; |
29 |
import org.eclipse.ajdt.core.AJLog; |
33 |
import org.eclipse.ajdt.core.AJLog; |
Lines 37-49
Link Here
|
37 |
import org.eclipse.ajdt.core.text.CoreMessages; |
41 |
import org.eclipse.ajdt.core.text.CoreMessages; |
38 |
import org.eclipse.ajdt.internal.core.AspectJRTInitializer; |
42 |
import org.eclipse.ajdt.internal.core.AspectJRTInitializer; |
39 |
import org.eclipse.ajdt.internal.core.ajde.CoreCompilerConfiguration; |
43 |
import org.eclipse.ajdt.internal.core.ajde.CoreCompilerConfiguration; |
40 |
import org.eclipse.ajdt.internal.core.ajde.CoreOutputLocationManager; |
44 |
import org.eclipse.core.internal.resources.ResourceException; |
41 |
import org.eclipse.core.resources.IContainer; |
45 |
import org.eclipse.core.resources.IContainer; |
|
|
46 |
import org.eclipse.core.resources.IFile; |
42 |
import org.eclipse.core.resources.IFolder; |
47 |
import org.eclipse.core.resources.IFolder; |
43 |
import org.eclipse.core.resources.IMarker; |
48 |
import org.eclipse.core.resources.IMarker; |
44 |
import org.eclipse.core.resources.IProject; |
49 |
import org.eclipse.core.resources.IProject; |
45 |
import org.eclipse.core.resources.IResource; |
50 |
import org.eclipse.core.resources.IResource; |
46 |
import org.eclipse.core.resources.IResourceDelta; |
51 |
import org.eclipse.core.resources.IResourceDelta; |
|
|
52 |
import org.eclipse.core.resources.IResourceDeltaVisitor; |
47 |
import org.eclipse.core.resources.IResourceStatus; |
53 |
import org.eclipse.core.resources.IResourceStatus; |
48 |
import org.eclipse.core.resources.IResourceVisitor; |
54 |
import org.eclipse.core.resources.IResourceVisitor; |
49 |
import org.eclipse.core.resources.IWorkspaceRoot; |
55 |
import org.eclipse.core.resources.IWorkspaceRoot; |
Lines 52-59
Link Here
|
52 |
import org.eclipse.core.runtime.CoreException; |
58 |
import org.eclipse.core.runtime.CoreException; |
53 |
import org.eclipse.core.runtime.IPath; |
59 |
import org.eclipse.core.runtime.IPath; |
54 |
import org.eclipse.core.runtime.IProgressMonitor; |
60 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
|
61 |
import org.eclipse.core.runtime.IStatus; |
55 |
import org.eclipse.core.runtime.NullProgressMonitor; |
62 |
import org.eclipse.core.runtime.NullProgressMonitor; |
56 |
import org.eclipse.core.runtime.Path; |
63 |
import org.eclipse.core.runtime.Path; |
|
|
64 |
import org.eclipse.core.runtime.Status; |
57 |
import org.eclipse.core.runtime.SubProgressMonitor; |
65 |
import org.eclipse.core.runtime.SubProgressMonitor; |
58 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
66 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
59 |
import org.eclipse.jdt.core.IClasspathEntry; |
67 |
import org.eclipse.jdt.core.IClasspathEntry; |
Lines 62-68
Link Here
|
62 |
import org.eclipse.jdt.core.JavaCore; |
70 |
import org.eclipse.jdt.core.JavaCore; |
63 |
import org.eclipse.jdt.core.JavaModelException; |
71 |
import org.eclipse.jdt.core.JavaModelException; |
64 |
import org.eclipse.jdt.internal.core.ClasspathEntry; |
72 |
import org.eclipse.jdt.internal.core.ClasspathEntry; |
|
|
73 |
import org.eclipse.jdt.internal.core.JavaModelManager; |
65 |
import org.eclipse.jdt.internal.core.JavaProject; |
74 |
import org.eclipse.jdt.internal.core.JavaProject; |
|
|
75 |
import org.eclipse.jdt.internal.core.builder.State; |
66 |
import org.eclipse.jdt.internal.core.util.Util; |
76 |
import org.eclipse.jdt.internal.core.util.Util; |
67 |
import org.eclipse.osgi.util.NLS; |
77 |
import org.eclipse.osgi.util.NLS; |
68 |
import org.osgi.service.prefs.BackingStoreException; |
78 |
import org.osgi.service.prefs.BackingStoreException; |
Lines 156-164
Link Here
|
156 |
} |
166 |
} |
157 |
|
167 |
|
158 |
if (kind != FULL_BUILD) { |
168 |
if (kind != FULL_BUILD) { |
159 |
// XXX need to add check here for whether the classpath has changed |
169 |
if (!sourceFilesChanged(dta, project) && !classpathChanged(dta, project)){ |
160 |
if (!sourceFilesChanged(dta, project)){ |
170 |
AJLog.log(AJLog.BUILDER,"build: Examined delta - no source file or classpath changes for project " //$NON-NLS-1$ |
161 |
AJLog.log(AJLog.BUILDER,"build: Examined delta - no source file changes for project " //$NON-NLS-1$ |
|
|
162 |
+ project.getName() ); |
171 |
+ project.getName() ); |
163 |
|
172 |
|
164 |
// if the source files of any projects which the current |
173 |
// if the source files of any projects which the current |
Lines 186-191
Link Here
|
186 |
|
195 |
|
187 |
IAJCompilerMonitor compilerMonitor = (IAJCompilerMonitor) compiler.getBuildProgressMonitor(); |
196 |
IAJCompilerMonitor compilerMonitor = (IAJCompilerMonitor) compiler.getBuildProgressMonitor(); |
188 |
|
197 |
|
|
|
198 |
|
189 |
// Bug 43711 must do a clean and rebuild if we can't |
199 |
// Bug 43711 must do a clean and rebuild if we can't |
190 |
// find a buildConfig file from a previous compilation |
200 |
// find a buildConfig file from a previous compilation |
191 |
if (kind == FULL_BUILD || |
201 |
if (kind == FULL_BUILD || |
Lines 197-206
Link Here
|
197 |
} else { |
207 |
} else { |
198 |
AJLog.log(AJLog.BUILDER,"Unable to empty output folder on build all - why cant we find the IJavaProject?"); //$NON-NLS-1$ |
208 |
AJLog.log(AJLog.BUILDER,"Unable to empty output folder on build all - why cant we find the IJavaProject?"); //$NON-NLS-1$ |
199 |
} |
209 |
} |
|
|
210 |
} else { |
211 |
// doing an incremental build |
212 |
if (AspectJCorePreferences.isIncrementalCompilationOptimizationsEnabled()) { |
213 |
// Bug 245566: |
214 |
// facilitate incremental compilation by checking |
215 |
// classpath for projects that have changed since the last build |
216 |
long timestamp = getLastBuildTimeStamp(compiler); |
217 |
compilerConfig.setClasspathElementsWithModifiedContents(getChangedRequiredProjects(timestamp)); |
218 |
} |
200 |
} |
219 |
} |
201 |
compilerMonitor.prepare(new SubProgressMonitor(progressMonitor,100)); |
220 |
compilerMonitor.prepare(new SubProgressMonitor(progressMonitor,100)); |
202 |
|
221 |
|
203 |
AJLog.log(AJLog.BUILDER_CLASSPATH,"Classpath="+compilerConfig.getClasspath()); //$NON-NLS-1$ |
222 |
AJLog.log(AJLog.BUILDER_CLASSPATH,"Classpath = " + compilerConfig.getClasspath()); //$NON-NLS-1$ |
204 |
|
223 |
|
205 |
// ---------------------------------------- |
224 |
// ---------------------------------------- |
206 |
// Do the compilation |
225 |
// Do the compilation |
Lines 217-226
Link Here
|
217 |
|
236 |
|
218 |
doRefreshAfterBuild(project, dependingProjects, javaProject); |
237 |
doRefreshAfterBuild(project, dependingProjects, javaProject); |
219 |
|
238 |
|
220 |
// update the relationship map |
239 |
// not needed now. This will be used to help create the relationship |
221 |
CoreOutputLocationManager outputLocManager = (CoreOutputLocationManager) |
240 |
// map more efficiently |
222 |
compilerConfig.getOutputLocationManager(); |
241 |
// CoreOutputLocationManager outputLocManager = (CoreOutputLocationManager) |
223 |
Set/*File*/ touchedFiles = outputLocManager.getTouchedClassFiles(); |
242 |
// compilerConfig.getOutputLocationManager(); |
|
|
243 |
// Set/*File*/ touchedFiles = outputLocManager.getTouchedClassFiles(); |
244 |
|
245 |
// update the relationship map |
224 |
boolean inc = (kind == IncrementalProjectBuilder.INCREMENTAL_BUILD) || (kind == IncrementalProjectBuilder.AUTO_BUILD); |
246 |
boolean inc = (kind == IncrementalProjectBuilder.INCREMENTAL_BUILD) || (kind == IncrementalProjectBuilder.AUTO_BUILD); |
225 |
AJModel.getInstance().createMap(project,true,inc); |
247 |
AJModel.getInstance().createMap(project,true,inc); |
226 |
|
248 |
|
Lines 235-240
Link Here
|
235 |
return requiredProjects; |
257 |
return requiredProjects; |
236 |
} |
258 |
} |
237 |
|
259 |
|
|
|
260 |
// check to see if the .classpath has changed. |
261 |
// we know exactly where it is located, so no need for a visitor |
262 |
private boolean classpathChanged(IResourceDelta dta, IProject project) { |
263 |
IResourceDelta[] children = dta.getAffectedChildren(); |
264 |
for (int i = 0; i < children.length; i++) { |
265 |
IResourceDelta child = children[i]; |
266 |
if (child.getResource().getName().equals(".classpath")) { |
267 |
return true; |
268 |
} |
269 |
} |
270 |
return false; |
271 |
} |
272 |
|
273 |
private long getLastBuildTimeStamp(AjCompiler compiler) { |
274 |
AjState state = IncrementalStateManager.retrieveStateFor(compiler.getId()); |
275 |
if (state != null) { |
276 |
return state.getLastBuildTime(); |
277 |
} else { |
278 |
return 0; |
279 |
} |
280 |
} |
281 |
|
238 |
private String buildKindString(int kind) { |
282 |
private String buildKindString(int kind) { |
239 |
switch(kind) { |
283 |
switch(kind) { |
240 |
case IncrementalProjectBuilder.AUTO_BUILD: |
284 |
case IncrementalProjectBuilder.AUTO_BUILD: |
Lines 250-256
Link Here
|
250 |
} |
294 |
} |
251 |
} |
295 |
} |
252 |
|
296 |
|
253 |
/** |
297 |
/** |
|
|
298 |
* returns a list of fully qualified names of entries on the classpath |
299 |
* that have been rebuilt since last build |
300 |
* @return |
301 |
*/ |
302 |
private List /*String*/ getChangedRequiredProjects(long lastBuildTimestamp) { |
303 |
try { |
304 |
// first find all the projects that have changed since last build |
305 |
IProject[] projectsOnClasspath = getRequiredProjects(getProject(), true); |
306 |
List /*IProject*/ changedProjects = new ArrayList(); |
307 |
for (int i = 0; i < projectsOnClasspath.length; i++) { |
308 |
IProject project = projectsOnClasspath[i]; |
309 |
|
310 |
// get timestamp of last build for this project |
311 |
long otherTimestamp = -1; |
312 |
if (AspectJPlugin.isAJProject(project)) { |
313 |
AjCompiler compiler = AspectJPlugin.getDefault().getCompilerFactory().getCompilerForProject(project); |
314 |
otherTimestamp = getLastBuildTimeStamp(compiler); |
315 |
} else if (project.hasNature(JavaCore.NATURE_ID)) { |
316 |
Object s = JavaModelManager.getJavaModelManager().getLastBuiltState(project, null); |
317 |
if (s != null && s instanceof State) { |
318 |
State state = (State) s; |
319 |
// need to use reflection to get at the last build time |
320 |
otherTimestamp = getLastBuildTime(state); |
321 |
} |
322 |
} else { |
323 |
otherTimestamp = -1; |
324 |
} |
325 |
if (lastBuildTimestamp <= otherTimestamp) { |
326 |
changedProjects.add(project); |
327 |
} |
328 |
} |
329 |
List /*String*/ changedEntries = new ArrayList(); |
330 |
|
331 |
// now that we have all the projects, need to find out what they contribute to |
332 |
// this project's path. could be itself, a jar, or a class folder |
333 |
if (changedProjects.size() > 0) { |
334 |
IClasspathEntry[] thisClasspath = JavaCore.create(getProject()).getResolvedClasspath(true); |
335 |
for (Iterator projIter = changedProjects.iterator(); projIter |
336 |
.hasNext();) { |
337 |
IProject changedProject = (IProject) projIter.next(); |
338 |
for (int i = 0; i < thisClasspath.length; i++) { |
339 |
IClasspathEntry classpathEntry = thisClasspath[i]; |
340 |
switch (classpathEntry.getEntryKind()) { |
341 |
case IClasspathEntry.CPE_PROJECT: |
342 |
if (changedProject.getFullPath().equals(classpathEntry.getPath())) { |
343 |
// resolve project and add all entries |
344 |
changedEntries.addAll(listOfClassPathEntriesToListOfString(AspectJCorePreferences.resolveDependentProjectClasspath( |
345 |
changedProject, classpathEntry))); |
346 |
} |
347 |
break; |
348 |
case IClasspathEntry.CPE_LIBRARY: |
349 |
if (changedProject.getFullPath().isPrefixOf(classpathEntry.getPath())) { |
350 |
// only add if this path exists |
351 |
IWorkspaceRoot root = getProject().getWorkspace().getRoot(); |
352 |
IFile onPath = root.getFile(classpathEntry.getPath()); |
353 |
if (onPath.exists() || |
354 |
root.getFolder(onPath.getFullPath()).exists()) { // may be a folder |
355 |
changedEntries.add(onPath.getLocation().toPortableString()); |
356 |
} |
357 |
} |
358 |
} |
359 |
} |
360 |
} |
361 |
} |
362 |
// if all else went well, also add the inpath the the list of changed projects. |
363 |
// Adding the inpath always is just a conservative estimate of what has changed. |
364 |
// |
365 |
// For Java projects, we only know the last structural build time. Usually this is |
366 |
// fine, but if the Java project is on the inpath, then we care about the last |
367 |
// build of any kind, which we can't be sure of. |
368 |
// (Actually, we need to know this for Aspect path projects, but aspectj can give us |
369 |
// precise time of the last build. |
370 |
// |
371 |
// So, as a conservative estimate, put all inpath entries onto the list. |
372 |
Set inPathFiles = CoreCompilerConfiguration.getCompilerConfigurationForProject(getProject()).getInpath(); |
373 |
if (inPathFiles != null) { |
374 |
for (Iterator fileIter = inPathFiles.iterator(); fileIter.hasNext();) { |
375 |
File inpathFile = (File) fileIter.next(); |
376 |
changedEntries.add(inpathFile.getAbsolutePath()); |
377 |
} |
378 |
} |
379 |
return changedEntries; |
380 |
} catch (Exception e) { |
381 |
// something went wrong. |
382 |
// return null to imply everything's changed |
383 |
AspectJPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, AspectJPlugin.PLUGIN_ID, |
384 |
"Error determining list of entries on classpath that have changed.", e)); |
385 |
return null; |
386 |
} |
387 |
} |
388 |
|
389 |
private List/*String*/ listOfClassPathEntriesToListOfString( |
390 |
List/*IClassPathEntry*/ entries) { |
391 |
IWorkspaceRoot root = getProject().getWorkspace().getRoot(); |
392 |
List strings = new ArrayList(entries.size()); |
393 |
for (Iterator iterator = entries.iterator(); iterator |
394 |
.hasNext();) { |
395 |
IClasspathEntry entry = (IClasspathEntry) iterator.next(); |
396 |
IFile onPath = root.getFile(entry.getPath()); |
397 |
// only add if exists |
398 |
if (onPath.exists() || |
399 |
root.getFolder(onPath.getFullPath()).exists()) { // may be a class folder |
400 |
|
401 |
strings.add(onPath.getLocation().toPortableString()); |
402 |
} |
403 |
} |
404 |
return strings; |
405 |
} |
406 |
|
407 |
private static Field state_lastStructuralBuildTime = null; |
408 |
private static long getLastBuildTime(State state) throws Exception { |
409 |
if (state_lastStructuralBuildTime == null) { |
410 |
state_lastStructuralBuildTime = State.class.getDeclaredField("lastStructuralBuildTime"); |
411 |
state_lastStructuralBuildTime.setAccessible(true); |
412 |
} |
413 |
return state_lastStructuralBuildTime.getLong(state); |
414 |
} |
415 |
|
416 |
/** |
254 |
* Refreshes the project's out folders after a build |
417 |
* Refreshes the project's out folders after a build |
255 |
* try to be as precise as possible because this can be a time consuming task |
418 |
* try to be as precise as possible because this can be a time consuming task |
256 |
* |
419 |
* |
Lines 442-448
Link Here
|
442 |
/** |
605 |
/** |
443 |
* Copies non-src resources to the output directory (bug 78579). The main |
606 |
* Copies non-src resources to the output directory (bug 78579). The main |
444 |
* part of this method was taken from |
607 |
* part of this method was taken from |
445 |
* org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.findSourceFiles(IResourceDelta) |
608 |
* {@link org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.findSourceFiles(IResourceDelta)} |
446 |
* |
609 |
* |
447 |
* @param IJavaProject - the project which is being built |
610 |
* @param IJavaProject - the project which is being built |
448 |
* @param IResourceDelta - the projects delta |
611 |
* @param IResourceDelta - the projects delta |
Lines 456-467
Link Here
|
456 |
IPath srcPath = srcEntry.getPath().removeFirstSegments(1); |
619 |
IPath srcPath = srcEntry.getPath().removeFirstSegments(1); |
457 |
IContainer srcContainer = getContainerForGivenPath(srcPath,project.getProject()); |
620 |
IContainer srcContainer = getContainerForGivenPath(srcPath,project.getProject()); |
458 |
|
621 |
|
459 |
if(srcContainer.equals(project.getProject())) { |
622 |
// handle case where project root is a source folder |
|
|
623 |
if (srcContainer.equals(project.getProject())) { |
460 |
int segmentCount = delta.getFullPath().segmentCount(); |
624 |
int segmentCount = delta.getFullPath().segmentCount(); |
461 |
IResourceDelta[] children = delta.getAffectedChildren(); |
625 |
IResourceDelta[] children = delta.getAffectedChildren(); |
462 |
for (int j = 0, m = children.length; j < m; j++) |
626 |
for (int j = 0, m = children.length; j < m; j++) { |
463 |
if (!isExcludedFromProject(project,children[j].getFullPath(),srcEntries)) |
627 |
if (!isExcludedFromProject(project,children[j].getFullPath(),srcEntries)) { |
464 |
copyResources(project, children[j], srcEntry, segmentCount); |
628 |
copyResources(project, children[j], srcEntry, segmentCount); |
|
|
629 |
} |
630 |
} |
465 |
} else { |
631 |
} else { |
466 |
IPath projectRelativePath = srcEntry.getPath().removeFirstSegments(1); |
632 |
IPath projectRelativePath = srcEntry.getPath().removeFirstSegments(1); |
467 |
projectRelativePath.makeRelative(); |
633 |
projectRelativePath.makeRelative(); |
Lines 474-482
Link Here
|
474 |
int segmentCount = sourceDelta.getFullPath().segmentCount(); |
640 |
int segmentCount = sourceDelta.getFullPath().segmentCount(); |
475 |
IResourceDelta[] children = sourceDelta.getAffectedChildren(); |
641 |
IResourceDelta[] children = sourceDelta.getAffectedChildren(); |
476 |
try { |
642 |
try { |
477 |
for (int j = 0, m = children.length; j < m; j++) |
643 |
for (int j = 0, m = children.length; j < m; j++) { |
478 |
copyResources(project, children[j], srcEntry, segmentCount); |
644 |
copyResources(project, children[j], srcEntry, segmentCount); |
479 |
} catch (org.eclipse.core.internal.resources.ResourceException e) { |
645 |
} |
|
|
646 |
} catch (ResourceException e) { |
480 |
// catch the case that a package has been renamed and collides on disk with an as-yet-to-be-deleted package |
647 |
// catch the case that a package has been renamed and collides on disk with an as-yet-to-be-deleted package |
481 |
if (e.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) { |
648 |
if (e.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) { |
482 |
return false; |
649 |
return false; |
Lines 530-537
Link Here
|
530 |
// fall thru & collect all the resource files |
697 |
// fall thru & collect all the resource files |
531 |
case IResourceDelta.CHANGED : |
698 |
case IResourceDelta.CHANGED : |
532 |
IResourceDelta[] children = sourceDelta.getAffectedChildren(); |
699 |
IResourceDelta[] children = sourceDelta.getAffectedChildren(); |
533 |
for (int i = 0, l = children.length; i < l; i++) |
700 |
for (int i = 0, l = children.length; i < l; i++) { |
534 |
copyResources(javaProject, children[i],srcEntry, segmentCount); |
701 |
copyResources(javaProject, children[i],srcEntry, segmentCount); |
|
|
702 |
} |
535 |
return; |
703 |
return; |
536 |
case IResourceDelta.REMOVED : |
704 |
case IResourceDelta.REMOVED : |
537 |
IPath removedPackagePath = resource.getFullPath().removeFirstSegments(segmentCount); |
705 |
IPath removedPackagePath = resource.getFullPath().removeFirstSegments(segmentCount); |
Lines 544-558
Link Here
|
544 |
// only a package fragment was removed, same as removing multiple source files |
712 |
// only a package fragment was removed, same as removing multiple source files |
545 |
createFolder(removedPackagePath, outputFolder); // ensure package exists in the output folder |
713 |
createFolder(removedPackagePath, outputFolder); // ensure package exists in the output folder |
546 |
IResourceDelta[] removedChildren = sourceDelta.getAffectedChildren(); |
714 |
IResourceDelta[] removedChildren = sourceDelta.getAffectedChildren(); |
547 |
for (int j = 0, m = removedChildren.length; j < m; j++) |
715 |
for (int j = 0, m = removedChildren.length; j < m; j++) { |
548 |
copyResources(javaProject,removedChildren[j], srcEntry, segmentCount); |
716 |
copyResources(javaProject,removedChildren[j], srcEntry, segmentCount); |
|
|
717 |
} |
549 |
return; |
718 |
return; |
550 |
} |
719 |
} |
551 |
} |
720 |
} |
552 |
} |
721 |
} |
553 |
IFolder removedPackageFolder = outputFolder.getFolder(removedPackagePath); |
722 |
IFolder removedPackageFolder = outputFolder.getFolder(removedPackagePath); |
554 |
if (removedPackageFolder.exists()) |
723 |
if (removedPackageFolder.exists()) { |
555 |
removedPackageFolder.delete(IResource.FORCE, null); |
724 |
removedPackageFolder.delete(IResource.FORCE, null); |
|
|
725 |
} |
556 |
} |
726 |
} |
557 |
return; |
727 |
return; |
558 |
case IResource.FILE : |
728 |
case IResource.FILE : |
Lines 567-572
Link Here
|
567 |
|| resourcePath.getFileExtension().equals("java"))) { //$NON-NLS-1$ |
737 |
|| resourcePath.getFileExtension().equals("java"))) { //$NON-NLS-1$ |
568 |
return; |
738 |
return; |
569 |
} |
739 |
} |
|
|
740 |
|
570 |
IResource outputFile = outputFolder.getFile(resourcePath); |
741 |
IResource outputFile = outputFolder.getFile(resourcePath); |
571 |
switch (sourceDelta.getKind()) { |
742 |
switch (sourceDelta.getKind()) { |
572 |
case IResourceDelta.ADDED : |
743 |
case IResourceDelta.ADDED : |
Lines 580-596
Link Here
|
580 |
outputFile.setDerived(true); |
751 |
outputFile.setDerived(true); |
581 |
Util.setReadOnly(outputFile, false); // just in case the original was read only |
752 |
Util.setReadOnly(outputFile, false); // just in case the original was read only |
582 |
outputFile.refreshLocal(IResource.DEPTH_ZERO,null); |
753 |
outputFile.refreshLocal(IResource.DEPTH_ZERO,null); |
|
|
754 |
// mark this change so compiler knows about it. |
755 |
CoreCompilerConfiguration.getCompilerConfigurationForProject(getProject()) |
756 |
.configurationChanged( |
757 |
CompilerConfigurationChangeFlags.PROJECTSOURCERESOURCES_CHANGED); |
583 |
return; |
758 |
return; |
584 |
case IResourceDelta.REMOVED : |
759 |
case IResourceDelta.REMOVED : |
585 |
if (outputFile.exists()) { |
760 |
if (outputFile.exists()) { |
586 |
AJLog.log(AJLog.BUILDER,"Deleting removed file " + resourcePath);//$NON-NLS-1$ |
761 |
AJLog.log(AJLog.BUILDER,"Deleting removed file " + resourcePath);//$NON-NLS-1$ |
587 |
outputFile.delete(IResource.FORCE, null); |
762 |
outputFile.delete(IResource.FORCE, null); |
588 |
} |
763 |
} |
|
|
764 |
// mark this change so compiler knows about it. |
765 |
CoreCompilerConfiguration.getCompilerConfigurationForProject(getProject()) |
766 |
.configurationChanged( |
767 |
CompilerConfigurationChangeFlags.PROJECTSOURCERESOURCES_CHANGED); |
589 |
return; |
768 |
return; |
590 |
case IResourceDelta.CHANGED : |
769 |
case IResourceDelta.CHANGED : |
591 |
if ((sourceDelta.getFlags() & IResourceDelta.CONTENT) == 0 |
770 |
if ((sourceDelta.getFlags() & IResourceDelta.CONTENT) == 0 |
592 |
&& (sourceDelta.getFlags() & IResourceDelta.ENCODING) == 0) |
771 |
&& (sourceDelta.getFlags() & IResourceDelta.ENCODING) == 0) { |
593 |
return; // skip it since it really isn't changed |
772 |
return; // skip it since it really isn't changed |
|
|
773 |
} |
594 |
if (outputFile.exists()) { |
774 |
if (outputFile.exists()) { |
595 |
AJLog.log(AJLog.BUILDER,"Deleting existing file " + resourcePath);//$NON-NLS-1$ |
775 |
AJLog.log(AJLog.BUILDER,"Deleting existing file " + resourcePath);//$NON-NLS-1$ |
596 |
outputFile.delete(IResource.FORCE, null); |
776 |
outputFile.delete(IResource.FORCE, null); |
Lines 922-932
Link Here
|
922 |
// clean the output folders and do a refresh if not |
1102 |
// clean the output folders and do a refresh if not |
923 |
// automatically building (so that output dir reflects the |
1103 |
// automatically building (so that output dir reflects the |
924 |
// changes) |
1104 |
// changes) |
925 |
if (AspectJPlugin.getWorkspace().getDescription().isAutoBuilding()) { |
1105 |
cleanOutputFolders(JavaCore.create(project), |
926 |
cleanOutputFolders(JavaCore.create(project),false); |
1106 |
!AspectJPlugin.getWorkspace().getDescription().isAutoBuilding()); |
927 |
} else { |
|
|
928 |
cleanOutputFolders(JavaCore.create(project),true); |
929 |
} |
930 |
} |
1107 |
} |
931 |
|
1108 |
|
932 |
private void removeProblemsAndTasksFor(IResource resource) { |
1109 |
private void removeProblemsAndTasksFor(IResource resource) { |
Lines 937-996
Link Here
|
937 |
} |
1114 |
} |
938 |
} catch (CoreException e) { |
1115 |
} catch (CoreException e) { |
939 |
} |
1116 |
} |
940 |
AJLog.log(AJLog.BUILDER,"Removed problems and tasks for project "+resource.getName()); //$NON-NLS-1$ |
1117 |
if (resource != null) { |
|
|
1118 |
AJLog.log(AJLog.BUILDER,"Removed problems and tasks for project "+resource.getName()); //$NON-NLS-1$ |
1119 |
} |
941 |
} |
1120 |
} |
942 |
|
1121 |
|
943 |
public boolean sourceFilesChanged(IResourceDelta delta, IProject project) { |
1122 |
|
944 |
if (delta!=null && delta.getAffectedChildren().length!=0) { |
1123 |
/** |
945 |
List includedFileNames = BuildConfig.getIncludedSourceFiles(project); |
1124 |
* Determine if any source files have changed and if so record it in the compiler configuration for the |
|
|
1125 |
* project |
1126 |
* @param delta |
1127 |
* @param project |
1128 |
* @return true if a source file has changed. False otherwise |
1129 |
*/ |
1130 |
public boolean sourceFilesChanged(IResourceDelta delta, IProject project) { |
1131 |
AJLog.logStart("SourceFilesChanged"); |
1132 |
if (delta != null && delta.getAffectedChildren().length != 0) { |
1133 |
|
1134 |
// XXX might be better if this were a Set. |
1135 |
// look into this |
1136 |
List /*IFile*/ includedFileNames = BuildConfig.getIncludedSourceFiles(project); |
1137 |
// Set /*IFile*/ includedFileNames = BuildConfig.getIncludedSourceFilesSet(project); |
1138 |
|
946 |
IJavaProject ijp = JavaCore.create(project); |
1139 |
IJavaProject ijp = JavaCore.create(project); |
947 |
if (ijp == null) { |
1140 |
if (ijp == null) { |
948 |
return true; |
1141 |
return true; |
949 |
} |
1142 |
} |
950 |
try { |
1143 |
try { |
951 |
IPath outputPath = ijp.getOutputLocation(); |
1144 |
SourceFilesChangedVisitor visitor = new SourceFilesChangedVisitor(project, includedFileNames); |
952 |
if (project.getFullPath().equals(outputPath)) { |
1145 |
delta.accept(visitor); |
953 |
outputPath = null; |
1146 |
if (visitor.hasChanges()) { |
954 |
} |
1147 |
AJLog.log(AJLog.BUILDER,"build: Examined delta - " + visitor.getNumberChanged() + //$NON-NLS-1$ |
955 |
if (sourceFilesChanged(delta, includedFileNames,outputPath)) { |
1148 |
" changed, " + visitor.getNumberAdded() + " added, and " + //$NON-NLS-1$ //$NON-NLS-2$ |
956 |
AJLog.log(AJLog.BUILDER,"build: Examined delta - source file changes in " //$NON-NLS-1$ |
1149 |
visitor.getNumberRemoved() + " deleted source files in " //$NON-NLS-1$ |
957 |
+ "required project " + project.getName() ); //$NON-NLS-1$ |
1150 |
+ "required project " + project.getName() ); //$NON-NLS-1$ |
958 |
return true; |
1151 |
return true; |
959 |
} else { |
1152 |
} else { |
960 |
return false; |
1153 |
return false; |
961 |
} |
1154 |
} |
962 |
} catch (JavaModelException e) {} |
1155 |
} catch (CoreException e) { |
|
|
1156 |
AspectJPlugin.getDefault().getLog().log( |
1157 |
new Status(IStatus.ERROR, |
1158 |
AspectJPlugin.PLUGIN_ID, "Error finding source file changes", e)); |
1159 |
} |
963 |
} |
1160 |
} |
|
|
1161 |
AJLog.logEnd(AJLog.BUILDER,"SourceFilesChanged"); |
964 |
return true; |
1162 |
return true; |
965 |
} |
1163 |
} |
966 |
|
1164 |
|
967 |
private boolean sourceFilesChanged(IResourceDelta dta, List includedFileNames,IPath outputLocation) { //IProject project) { |
1165 |
private class SourceFilesChangedVisitor implements IResourceDeltaVisitor { |
968 |
if (dta == null) return false; |
1166 |
private final List includedFileNames; |
|
|
1167 |
private final CoreCompilerConfiguration compilerConfiguration; |
1168 |
private final IProject affectedProject; |
1169 |
private int numberChanged; |
1170 |
private int numberAdded; |
1171 |
private int numberRemoved; |
1172 |
|
1173 |
private SourceFilesChangedVisitor(IProject affectedProject, |
1174 |
List includedFileNames) { |
1175 |
this.includedFileNames = includedFileNames; |
1176 |
this.affectedProject = affectedProject; |
1177 |
compilerConfiguration = CoreCompilerConfiguration.getCompilerConfigurationForProject(affectedProject); |
1178 |
numberChanged = 0; |
1179 |
numberAdded = 0; |
1180 |
numberRemoved = 0; |
1181 |
} |
969 |
|
1182 |
|
970 |
if (outputLocation!=null && outputLocation.equals(dta.getFullPath()) ) { |
1183 |
/** |
971 |
return false; |
1184 |
* Look for changed resources that we care about. |
972 |
} |
1185 |
*/ |
973 |
String resname = dta.getFullPath().toString(); |
1186 |
public boolean visit(IResourceDelta delta) throws CoreException { |
974 |
|
1187 |
String resname = delta.getFullPath().toString(); |
975 |
if (CoreUtils.ASPECTJ_SOURCE_FILTER.accept(resname)) { |
1188 |
|
976 |
if ((includedFileNames==null) || includedFileNames.contains(dta.getResource()) |
1189 |
if (delta.getResource().getType() == IResource.FILE) { |
977 |
|| dta.getKind() == IResourceDelta.REMOVED) { |
1190 |
if (CoreUtils.ASPECTJ_SOURCE_FILTER.accept(resname)) { |
978 |
return true; |
1191 |
|
979 |
} else { |
1192 |
switch (delta.getKind()) { |
|
|
1193 |
case IResourceDelta.REMOVED: |
1194 |
case IResourceDelta.REMOVED_PHANTOM: |
1195 |
// don't check to see if these files are on the list of included |
1196 |
// files because they have already been removed and we won't find |
1197 |
// them on the list. |
1198 |
// be conservative and set the flag regardless. |
1199 |
compilerConfiguration.configurationChanged( |
1200 |
CompilerConfigurationChangeFlags.PROJECTSOURCEFILES_CHANGED); |
1201 |
numberRemoved++; |
1202 |
break; |
1203 |
|
1204 |
case IResourceDelta.ADDED: |
1205 |
case IResourceDelta.ADDED_PHANTOM: |
1206 |
if (includedFileNames.contains(delta.getResource())) { |
1207 |
compilerConfiguration.configurationChanged( |
1208 |
CompilerConfigurationChangeFlags.PROJECTSOURCEFILES_CHANGED); |
1209 |
numberAdded++; |
1210 |
break; |
1211 |
} |
1212 |
case IResourceDelta.CHANGED: |
1213 |
if (includedFileNames.contains(delta.getResource())) { |
1214 |
compilerConfiguration.addModifiedFile(new File(delta.getResource() |
1215 |
.getLocation().toPortableString())); |
1216 |
numberChanged++; |
1217 |
} |
1218 |
} |
1219 |
} else if (resname.endsWith(".classpath")) { //$NON-NLS-1$ |
1220 |
// also need to ensure that this is a project classpath |
1221 |
IContainer parent = delta.getResource().getParent(); |
1222 |
if (parent.getFullPath().equals(affectedProject.getFullPath())) { |
1223 |
// we don't know what has changed exactly. |
1224 |
// be conservative |
1225 |
compilerConfiguration.configurationChanged( |
1226 |
CompilerConfigurationChangeFlags.CLASSPATH_CHANGED | |
1227 |
CompilerConfigurationChangeFlags.ASPECTPATH_CHANGED | |
1228 |
CompilerConfigurationChangeFlags.INPATH_CHANGED); |
1229 |
} |
1230 |
} |
980 |
return false; |
1231 |
return false; |
|
|
1232 |
} else { |
1233 |
|
1234 |
// want to fully traverse this delta if not |
1235 |
// a leaf node |
1236 |
return true; |
981 |
} |
1237 |
} |
982 |
} else if (resname.endsWith(".classpath")){ //$NON-NLS-1$ |
1238 |
} |
983 |
return true; |
1239 |
public int getNumberChanged() { |
984 |
} else { |
1240 |
return numberChanged; |
985 |
boolean kids_results = false; |
1241 |
} |
986 |
int i = 0; |
1242 |
public int getNumberAdded() { |
987 |
IResourceDelta[] kids = dta.getAffectedChildren(); |
1243 |
return numberAdded; |
988 |
while (!kids_results && i < kids.length) { |
1244 |
} |
989 |
kids_results = kids_results | sourceFilesChanged(kids[i], includedFileNames, outputLocation); |
1245 |
public int getNumberRemoved() { |
990 |
i++; |
1246 |
return numberRemoved; |
991 |
} |
1247 |
} |
992 |
return kids_results; |
1248 |
|
993 |
} |
1249 |
public boolean hasChanges() { |
|
|
1250 |
return numberAdded + numberChanged + numberRemoved > 0; |
1251 |
} |
994 |
} |
1252 |
} |
995 |
|
1253 |
|
996 |
public static void addStateListener() { |
1254 |
public static void addStateListener() { |
Lines 1006-1013
Link Here
|
1006 |
public void pathChangeDetected() { |
1264 |
public void pathChangeDetected() { |
1007 |
} |
1265 |
} |
1008 |
|
1266 |
|
1009 |
public void buildSuccessful(boolean arg0) { |
1267 |
public void buildSuccessful(boolean wasFull) { |
1010 |
AJLog.log(AJLog.COMPILER,"AspectJ reports build successful, build was: "+(arg0?"FULL":"INCREMENTAL")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
1268 |
AJLog.log(AJLog.COMPILER,"AspectJ reports build successful, build was: " + //$NON-NLS-1$ |
|
|
1269 |
(wasFull ? "FULL" : "INCREMENTAL")); //$NON-NLS-1$ //$NON-NLS-2$ |
1011 |
} |
1270 |
} |
1012 |
|
1271 |
|
1013 |
public void detectedAspectDeleted(File f) { |
1272 |
public void detectedAspectDeleted(File f) { |