11/*******************************************************************************
2- * Copyright (c) 2000,2013 IBM Corporation and others.
2+ * Copyright (c) 2000,2011 IBM Corporation and others.
33 * All rights reserved. This program and the accompanying materials
44 * are made available under the terms of the Eclipse Public License v1.0
55 * which accompanies this distribution, and is available at
1212
1313import org .eclipse .core .resources .*;
1414import org .eclipse .core .runtime .*;
15+
1516import org .eclipse .jdt .core .*;
1617import org .eclipse .jdt .core .compiler .*;
1718import org .eclipse .jdt .internal .compiler .util .SimpleLookupTable ;
2021import org .eclipse .jdt .internal .core .util .Util ;
2122
2223import java .io .*;
23- import java .lang .reflect .InvocationTargetException ;
24- import java .lang .reflect .Method ;
2524import java .util .*;
2625
2726public class JavaBuilder extends IncrementalProjectBuilder {
@@ -158,7 +157,7 @@ protected IProject[] build(int kind, Map ignored, IProgressMonitor monitor) thro
158157if (this .currentProject ==null || !this .currentProject .isAccessible ())return new IProject [0 ];
159158
160159if (DEBUG )
161- System .out .println ("\n JavaBuilder: Starting build of " +this .currentProject .getName ()//$NON-NLS-1$
160+ System .out .println ("\n Starting build of " +this .currentProject .getName ()//$NON-NLS-1$
162161+" @ " +new Date (System .currentTimeMillis ()));//$NON-NLS-1$
163162this .notifier =new BuildNotifier (monitor ,this .currentProject );
164163this .notifier .begin ();
@@ -170,39 +169,39 @@ protected IProject[] build(int kind, Map ignored, IProgressMonitor monitor) thro
170169if (isWorthBuilding ()) {
171170if (kind ==FULL_BUILD ) {
172171if (DEBUG )
173- System .out .println ("JavaBuilder: Performing full build as requested" );//$NON-NLS-1$
172+ System .out .println ("Performing full build as requested by user " );//$NON-NLS-1$
174173buildAll ();
175174}else {
176175if ((this .lastState =getLastState (this .currentProject )) ==null ) {
177176if (DEBUG )
178- System .out .println ("JavaBuilder: Performing full build since last saved state was not found" );//$NON-NLS-1$
177+ System .out .println ("Performing full build since last saved state was not found" );//$NON-NLS-1$
179178buildAll ();
180179}else if (hasClasspathChanged ()) {
181180// if the output location changes, do not delete the binary files from old location
182181// the user may be trying something
183182if (DEBUG )
184- System .out .println ("JavaBuilder: Performing full build since classpath has changed" );//$NON-NLS-1$
183+ System .out .println ("Performing full build since classpath has changed" );//$NON-NLS-1$
185184buildAll ();
186185}else if (this .nameEnvironment .sourceLocations .length >0 ) {
187186// if there is no source to compile & no classpath changes then we are done
188187SimpleLookupTable deltas =findDeltas ();
189188if (deltas ==null ) {
190189if (DEBUG )
191- System .out .println ("JavaBuilder: Performing full build since deltas are missing after incremental request" );//$NON-NLS-1$
190+ System .out .println ("Performing full build since deltas are missing after incremental request" );//$NON-NLS-1$
192191buildAll ();
193192}else if (deltas .elementSize >0 ) {
194193buildDeltas (deltas );
195194}else if (DEBUG ) {
196- System .out .println ("JavaBuilder: Nothing to build since deltas were empty" );//$NON-NLS-1$
195+ System .out .println ("Nothing to build since deltas were empty" );//$NON-NLS-1$
197196}
198197}else {
199198if (hasStructuralDelta ()) {// double check that a jar file didn't get replaced in a binary project
200199if (DEBUG )
201- System .out .println ("JavaBuilder: Performing full build since there are structural deltas" );//$NON-NLS-1$
200+ System .out .println ("Performing full build since there are structural deltas" );//$NON-NLS-1$
202201buildAll ();
203202}else {
204203if (DEBUG )
205- System .out .println ("JavaBuilder: Nothing to build since there are no source folders and no deltas" );//$NON-NLS-1$
204+ System .out .println ("Nothing to build since there are no source folders and no deltas" );//$NON-NLS-1$
206205this .lastState .tagAsNoopBuild ();
207206}
208207}
@@ -240,16 +239,16 @@ protected IProject[] build(int kind, Map ignored, IProgressMonitor monitor) thro
240239}
241240IProject []requiredProjects =getRequiredProjects (true );
242241if (DEBUG )
243- System .out .println ("JavaBuilder: Finished build of " +this .currentProject .getName ()//$NON-NLS-1$
244- +" @ " +new Date (System .currentTimeMillis ()) + " \n " );//$NON-NLS-1$ //$NON-NLS-2 $
242+ System .out .println ("Finished build of " +this .currentProject .getName ()//$NON-NLS-1$
243+ +" @ " +new Date (System .currentTimeMillis ()));//$NON-NLS-1$
245244return requiredProjects ;
246245}
247246
248247private void buildAll () {
249248this .notifier .checkCancel ();
250249this .notifier .subTask (Messages .bind (Messages .build_preparingBuild ,this .currentProject .getName ()));
251250if (DEBUG &&this .lastState !=null )
252- System .out .println ("JavaBuilder: Clearing last state : " +this .lastState );//$NON-NLS-1$
251+ System .out .println ("Clearing last state : " +this .lastState );//$NON-NLS-1$
253252clearLastState ();
254253BatchImageBuilder imageBuilder =new Java2ScriptBatchImageBuilder (this ,true );
255254imageBuilder .build ();
@@ -260,14 +259,14 @@ private void buildDeltas(SimpleLookupTable deltas) {
260259this .notifier .checkCancel ();
261260this .notifier .subTask (Messages .bind (Messages .build_preparingBuild ,this .currentProject .getName ()));
262261if (DEBUG &&this .lastState !=null )
263- System .out .println ("JavaBuilder: Clearing last state : " +this .lastState );//$NON-NLS-1$
262+ System .out .println ("Clearing last state : " +this .lastState );//$NON-NLS-1$
264263clearLastState ();// clear the previously built state so if the build fails, a full build will occur next time
265264IncrementalImageBuilder imageBuilder =new Java2ScriptIncrementalImageBuilder (this );
266265if (imageBuilder .build (deltas )) {
267266recordNewState (imageBuilder .newState );
268267}else {
269268if (DEBUG )
270- System .out .println ("JavaBuilder: Performing full build since incremental build failed" );//$NON-NLS-1$
269+ System .out .println ("Performing full build since incremental build failed" );//$NON-NLS-1$
271270buildAll ();
272271}
273272}
@@ -277,7 +276,7 @@ protected void clean(IProgressMonitor monitor) throws CoreException {
277276if (this .currentProject ==null || !this .currentProject .isAccessible ())return ;
278277
279278if (DEBUG )
280- System .out .println ("\n JavaBuilder: Cleaning " +this .currentProject .getName ()//$NON-NLS-1$
279+ System .out .println ("\n Cleaning " +this .currentProject .getName ()//$NON-NLS-1$
281280+" @ " +new Date (System .currentTimeMillis ()));//$NON-NLS-1$
282281this .notifier =new BuildNotifier (monitor ,this .currentProject );
283282this .notifier .begin ();
@@ -286,7 +285,7 @@ protected void clean(IProgressMonitor monitor) throws CoreException {
286285
287286initializeBuilder (CLEAN_BUILD ,true );
288287if (DEBUG )
289- System .out .println ("JavaBuilder: Clearing last state as part of clean : " +this .lastState );//$NON-NLS-1$
288+ System .out .println ("Clearing last state as part of clean : " +this .lastState );//$NON-NLS-1$
290289clearLastState ();
291290removeProblemsAndTasksFor (this .currentProject );
292291new BatchImageBuilder (this ,false ).cleanOutputFolders (false );
@@ -298,7 +297,7 @@ protected void clean(IProgressMonitor monitor) throws CoreException {
298297cleanup ();
299298}
300299if (DEBUG )
301- System .out .println ("JavaBuilder: Finished cleaning " +this .currentProject .getName ()//$NON-NLS-1$
300+ System .out .println ("Finished cleaning " +this .currentProject .getName ()//$NON-NLS-1$
302301+" @ " +new Date (System .currentTimeMillis ()));//$NON-NLS-1$
303302}
304303
@@ -367,12 +366,12 @@ private SimpleLookupTable findDeltas() {
367366if (delta !=null ) {
368367if (delta .getKind () !=IResourceDelta .NO_CHANGE ) {
369368if (DEBUG )
370- System .out .println ("JavaBuilder: Found source delta for: " +this .currentProject .getName ());//$NON-NLS-1$
369+ System .out .println ("Found source delta for: " +this .currentProject .getName ());//$NON-NLS-1$
371370deltas .put (this .currentProject ,delta );
372371}
373372}else {
374373if (DEBUG )
375- System .out .println ("JavaBuilder: Missing delta for: " +this .currentProject .getName ());//$NON-NLS-1$
374+ System .out .println ("Missing delta for: " +this .currentProject .getName ());//$NON-NLS-1$
376375this .notifier .subTask ("" );//$NON-NLS-1$
377376return null ;
378377}
@@ -402,12 +401,12 @@ private SimpleLookupTable findDeltas() {
402401if (delta !=null ) {
403402if (delta .getKind () !=IResourceDelta .NO_CHANGE ) {
404403if (DEBUG )
405- System .out .println ("JavaBuilder: Found binary delta for: " +p .getName ());//$NON-NLS-1$
404+ System .out .println ("Found binary delta for: " +p .getName ());//$NON-NLS-1$
406405deltas .put (p ,delta );
407406}
408407}else {
409408if (DEBUG )
410- System .out .println ("JavaBuilder: Missing delta for: " +p .getName ());//$NON-NLS-1$
409+ System .out .println ("Missing delta for: " +p .getName ());//$NON-NLS-1$
411410this .notifier .subTask ("" );//$NON-NLS-1$
412411return null ;
413412}
@@ -515,7 +514,7 @@ private boolean hasClasspathChanged() {
515514}catch (CoreException ignore ) {// skip it
516515}
517516if (DEBUG ) {
518- System .out .println ("JavaBuilder: New location: " +newSourceLocations [n ] +"\n != old location: " +oldSourceLocations [o ]);//$NON-NLS-1$ //$NON-NLS-2$
517+ System .out .println ("New location: " +newSourceLocations [n ] +"\n != old location: " +oldSourceLocations [o ]);//$NON-NLS-1$ //$NON-NLS-2$
519518printLocations (newSourceLocations ,oldSourceLocations );
520519}
521520return true ;
@@ -529,7 +528,7 @@ private boolean hasClasspathChanged() {
529528}catch (CoreException ignore ) {// skip it
530529}
531530if (DEBUG ) {
532- System .out .println ("JavaBuilder: Added non-empty source folder" );//$NON-NLS-1$
531+ System .out .println ("Added non-empty source folder" );//$NON-NLS-1$
533532printLocations (newSourceLocations ,oldSourceLocations );
534533}
535534return true ;
@@ -540,7 +539,7 @@ private boolean hasClasspathChanged() {
540539continue ;
541540}
542541if (DEBUG ) {
543- System .out .println ("JavaBuilder: Removed non-empty source folder" );//$NON-NLS-1$
542+ System .out .println ("Removed non-empty source folder" );//$NON-NLS-1$
544543printLocations (newSourceLocations ,oldSourceLocations );
545544}
546545return true ;
@@ -553,14 +552,14 @@ private boolean hasClasspathChanged() {
553552for (n =o =0 ;n <newLength &&o <oldLength ;n ++,o ++) {
554553if (newBinaryLocations [n ].equals (oldBinaryLocations [o ]))continue ;
555554if (DEBUG ) {
556- System .out .println ("JavaBuilder: New location: " +newBinaryLocations [n ] +"\n != old location: " +oldBinaryLocations [o ]);//$NON-NLS-1$ //$NON-NLS-2$
555+ System .out .println ("New location: " +newBinaryLocations [n ] +"\n != old location: " +oldBinaryLocations [o ]);//$NON-NLS-1$ //$NON-NLS-2$
557556printLocations (newBinaryLocations ,oldBinaryLocations );
558557}
559558return true ;
560559}
561560if (n <newLength ||o <oldLength ) {
562561if (DEBUG ) {
563- System .out .println ("JavaBuilder: Number of binary folders/jar files has changed:" );//$NON-NLS-1$
562+ System .out .println ("Number of binary folders/jar files has changed:" );//$NON-NLS-1$
564563printLocations (newBinaryLocations ,oldBinaryLocations );
565564}
566565return true ;
@@ -614,15 +613,7 @@ private int initializeBuilder(int kind, boolean forBuild) throws CoreException {
614613// Flush the existing external files cache if this is the beginning of a build cycle
615614String projectName =this .currentProject .getName ();
616615if (builtProjects ==null ||builtProjects .contains (projectName )) {
617- try {
618- Method method =JavaModel .class .getMethod ("flushExternalFileCache" ,new Class [] {Void .class });
619- if (method !=null ) {
620- method .invoke (JavaModel .class ,new Object [0 ]);
621- }
622- }catch (Throwable e ) {
623- e .printStackTrace ();
624- }
625- //JavaModel.flushExternalFileCache();
616+ JavaModel .flushExternalFileCache ();
626617builtProjects =new ArrayList ();
627618}
628619builtProjects .add (projectName );
@@ -677,7 +668,7 @@ private boolean isWorthBuilding() throws CoreException {
677668// Abort build only if there are classpath errors
678669if (isClasspathBroken (this .javaProject .getRawClasspath (),this .currentProject )) {
679670if (DEBUG )
680- System .out .println ("JavaBuilder: Aborted build because project has classpath errors (incomplete or involved in cycle)" );//$NON-NLS-1$
671+ System .out .println ("Aborted build because project has classpath errors (incomplete or involved in cycle)" );//$NON-NLS-1$
681672
682673removeProblemsAndTasksFor (this .currentProject );// remove all compilation problems
683674
@@ -707,18 +698,18 @@ private boolean isWorthBuilding() throws CoreException {
707698JavaProject prereq = (JavaProject )JavaCore .create (p );
708699if (prereq .hasCycleMarker () &&JavaCore .WARNING .equals (this .javaProject .getOption (JavaCore .CORE_CIRCULAR_CLASSPATH ,true ))) {
709700if (DEBUG )
710- System .out .println ("JavaBuilder: Continued to build even though prereq project " +p .getName ()//$NON-NLS-1$
701+ System .out .println ("Continued to build even though prereq project " +p .getName ()//$NON-NLS-1$
711702+" was not built since its part of a cycle" );//$NON-NLS-1$
712703continue ;
713704}
714705if (!hasJavaBuilder (p )) {
715706if (DEBUG )
716- System .out .println ("JavaBuilder: Continued to build even though prereq project " +p .getName ()//$NON-NLS-1$
707+ System .out .println ("Continued to build even though prereq project " +p .getName ()//$NON-NLS-1$
717708+" is not built by JavaBuilder" );//$NON-NLS-1$
718709continue ;
719710}
720711if (DEBUG )
721- System .out .println ("JavaBuilder: Aborted build because prereq project " +p .getName ()//$NON-NLS-1$
712+ System .out .println ("Aborted build because prereq project " +p .getName ()//$NON-NLS-1$
722713+" was not built" );//$NON-NLS-1$
723714
724715removeProblemsAndTasksFor (this .currentProject );// make this the only problem for this project
@@ -755,7 +746,7 @@ void mustPropagateStructuralChanges() {
755746IProject project =this .workspaceRoot .getProject (participantPath .segment (0 ));
756747if (hasBeenBuilt (project )) {
757748if (DEBUG )
758- System .out .println ("JavaBuilder: Requesting another build iteration since cycle participant " +project .getName ()//$NON-NLS-1$
749+ System .out .println ("Requesting another build iteration since cycle participant " +project .getName ()//$NON-NLS-1$
759750+" has not yet seen some structural changes" );//$NON-NLS-1$
760751needRebuild ();
761752return ;
@@ -765,10 +756,10 @@ void mustPropagateStructuralChanges() {
765756}
766757
767758private void printLocations (ClasspathLocation []newLocations ,ClasspathLocation []oldLocations ) {
768- System .out .println ("JavaBuilder: New locations:" );//$NON-NLS-1$
759+ System .out .println ("New locations:" );//$NON-NLS-1$
769760for (int i =0 ,length =newLocations .length ;i <length ;i ++)
770761System .out .println (" " +newLocations [i ].debugPathString ());//$NON-NLS-1$
771- System .out .println ("JavaBuilder: Old locations:" );//$NON-NLS-1$
762+ System .out .println ("Old locations:" );//$NON-NLS-1$
772763for (int i =0 ,length =oldLocations .length ;i <length ;i ++)
773764System .out .println (" " +oldLocations [i ].debugPathString ());//$NON-NLS-1$
774765}
@@ -799,7 +790,7 @@ private void recordNewState(State state) {
799790}
800791
801792if (DEBUG )
802- System .out .println ("JavaBuilder: Recording new state : " +state );//$NON-NLS-1$
793+ System .out .println ("Recording new state : " +state );//$NON-NLS-1$
803794// state.dump();
804795JavaModelManager .getJavaModelManager ().setLastBuiltState (currentProject ,newState );
805796}