Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d580d9bc1e683c078e35aae86b9fe12506aad2f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
/*******************************************************************************
 * Copyright (c) 2005, 2012 BEA Systems, Inc. and others
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    mkaufman@bea.com - initial API and implementation
 *    IBM Corporation - updated test to reflect changes for https://bugs.eclipse.org/bugs/show_bug.cgi?id=185601
 *******************************************************************************/

package org.eclipse.jdt.apt.tests;

import junit.framework.Test;
import junit.framework.TestSuite;

import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.apt.core.internal.AptPlugin;
import org.eclipse.jdt.apt.core.internal.generatedfile.GeneratedSourceFolderManager;
import org.eclipse.jdt.apt.core.util.AptConfig;
import org.eclipse.jdt.apt.tests.annotations.helloworld.HelloWorldAnnotationProcessor;
import org.eclipse.jdt.apt.tests.annotations.messager.MessagerAnnotationProcessor;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.tests.util.Util;

public class AptBuilderTests extends APTTestBase
{

	public AptBuilderTests(String name)
	{
		super( name );
	}

	public static Test suite()
	{
		return new TestSuite( AptBuilderTests.class );
	}

	public void setUp() throws Exception
	{
		super.setUp();
		
		//
		// project will be deleted by super-class's tearDown() method
		// create a project with a src directory as the project root directory
		//
		IPath projectPath = env.addProject( getProjectName_ProjectRootAsSrcDir(), "1.5" );
		env.addExternalJars( projectPath, Util.getJavaClassLibs() );
		fullBuild( projectPath );

		// remove old package fragment root so that names don't collide
		env.setOutputFolder( projectPath, "bin" ); //$NON-NLS-1$

		IJavaProject jproj = env.getJavaProject( projectPath );
		AptConfig.setEnabled( jproj, true );
		TestUtil.createAndAddAnnotationJar( jproj );
		
	}

	public static String getProjectName_ProjectRootAsSrcDir()
	{
		return AptBuilderTests.class.getName() + "NoSrcProject"; //$NON-NLS-1$
	}
	
	public IPath getSourcePath( String projectName )
	{
		if ( getProjectName_ProjectRootAsSrcDir().equals( projectName) )
			return new Path( "/" + getProjectName_ProjectRootAsSrcDir() );
		else
		{
			IProject project = env.getProject( projectName );
			IFolder srcFolder = project.getFolder( "src" ); //$NON-NLS-1$
			IPath srcRoot = srcFolder.getFullPath();
			return srcRoot;
		}
	}
	public void testGeneratedFileInBuilder() throws Exception
	{
		_testGeneratedFileInBuilder0( getProjectName() );
	}
	
	/**
	 *  Regresses Buzilla 103745 & 95661
	 */

	public void testGeneratedFileInBuilder_ProjectRootAsSourceDir() throws Exception
	{
		_testGeneratedFileInBuilder0( getProjectName_ProjectRootAsSrcDir() );
	}
	
	
	public void testGeneratedFileInBuilder1() throws Exception{
		_testGeneratedFileInBuilder1( getProjectName() );
	}
	
	private void _testGeneratedFileInBuilder0(String projectName){
		IProject project = env.getProject( projectName );
		IPath srcRoot = getSourcePath( projectName );
		
		String code = "package p1;\n"
			+ "//import org.eclipse.jdt.apt.tests.annotations.helloworld.HelloWorldAnnotation;"
			+ "\n" + "public class A " + "\n" + "{"
			+ "    //@HelloWorldAnnotation" + "\n"
			+ "    public static void main( String[] argv )" + "\n" + "    {"
			+ "\n"
			+ "        generatedfilepackage.GeneratedFileTest.helloWorld();"
			+ "\n" + "    }" + "\n" + "}" + "\n";
	
		IPath p1aPath = env.addClass( srcRoot, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
			code );

		fullBuild( project.getFullPath() );

		expectingOnlyProblemsFor( p1aPath );
		expectingOnlySpecificProblemFor( p1aPath, new ExpectedProblem(
			"A", "generatedfilepackage cannot be resolved", p1aPath ) ); //$NON-NLS-1$ //$NON-NLS-2$	

		code = "package p1;\n"
			+ "import org.eclipse.jdt.apt.tests.annotations.helloworld.HelloWorldAnnotation;"
			+ "\n" + "public class A " + "\n" + "{"
			+ "    @HelloWorldAnnotation" + "\n"
			+ "    public static void main( String[] argv )" + "\n" + "    {"
			+ "\n"
			+ "         generatedfilepackage.GeneratedFileTest.helloWorld();"
			+ "\n" + "    }" + "\n" + "}" + "\n";

		env.addClass( srcRoot, "p1", "A", code );
		fullBuild( project.getFullPath() );

		expectingOnlyProblemsFor( new IPath[0] );
	}

	/**
	 *  slight variation to _testGeneratedFileInBuilder0. 
	 *  Difference: 
	 *   The method invocation is not fully qualified and an import is added. 
	 */
	private void _testGeneratedFileInBuilder1( String projectName )
	{
		IProject project = env.getProject( projectName );
		IPath srcRoot = getSourcePath( projectName );	

		String code = "package p1;\n"
			+ "import org.eclipse.jdt.apt.tests.annotations.helloworld.HelloWorldAnnotation;"
			+ "import generatedfilepackage.GeneratedFileTest;"
			+ "\n" + "public class A " + "\n" + "{"
			+ "    @HelloWorldAnnotation" + "\n"
			+ "    public static void main( String[] argv )" + "\n" + "    {"
			+ "\n"
			+ "        GeneratedFileTest.helloWorld();"
			+ "\n" + "    }" + "\n" + "}" + "\n";

		env.addClass( srcRoot, "p1", "A", code );
		fullBuild( project.getFullPath() );

		expectingOnlyProblemsFor( new IPath[0] );
	}
	
	/**
	 *  Try generating a bogus type name; expect exception 
	 */
	public void testGeneratingIllegalTypeName()
	{
		String projectName = getProjectName();
		clearProcessorResult(HelloWorldAnnotationProcessor.class);
		IProject project = env.getProject( projectName );
		IPath srcRoot = getSourcePath( projectName );	

		String code = "package p1;\n"
			+ "import org.eclipse.jdt.apt.tests.annotations.helloworld.HelloWorldAnnotation;"
			+ "import generatedfilepackage.GeneratedFileTest;"
			+ "\n" + "public class A " + "\n" + "{"
			+ "    @HelloWorldAnnotation(\"Bad-Type-Name\")" + "\n"
			+ "    public static void main( String[] argv )" + "\n" + "    {"
			+ "\n"
			+ "        GeneratedFileTest.helloWorld();"
			+ "\n" + "    }" + "\n" + "}" + "\n";

		env.addClass( srcRoot, "p1", "A", code );
		fullBuild( project.getFullPath() );
		assertEquals("Could not generate text file due to IOException", getProcessorResult(HelloWorldAnnotationProcessor.class));

		// Type "lowercase" would cause a warning in the new type wizard, because it doesn't start with caps.
		// Test that we do not issue a warning or error in this case.
		String code2 = "package p1;\n"
			+ "import org.eclipse.jdt.apt.tests.annotations.helloworld.HelloWorldAnnotation;"
			+ "import generatedfilepackage.lowercase;"
			+ "\n" + "public class A " + "\n" + "{"
			+ "    @HelloWorldAnnotation(\"lowercase\")" + "\n"
			+ "    public static void main( String[] argv )" + "\n" + "    {"
			+ "\n"
			+ "        lowercase.helloWorld();"
			+ "\n" + "    }" + "\n" + "}" + "\n";

		env.addClass( srcRoot, "p1", "A", code2 );
		fullBuild( project.getFullPath() );
		expectingNoProblems();
	}
	
	/**
	 *  Try running two processors on the same file, and look for interactions.
	 *  Regression for https://bugs.eclipse.org/bugs/show_bug.cgi?id=175794
	 */
	public void testTwoAnnotations()
	{
		String projectName = getProjectName();
		clearProcessorResult(HelloWorldAnnotationProcessor.class);
		clearProcessorResult(MessagerAnnotationProcessor.class);
		IProject project = env.getProject( projectName );
		IPath srcRoot = getSourcePath( projectName );	

		String codeMessageFirst = "package p1;\n"
			+ "import org.eclipse.jdt.apt.tests.annotations.helloworld.HelloWorldAnnotation;\n"
			+ "import org.eclipse.jdt.apt.tests.annotations.messager.MessagerAnnotation;\n"
			+ "import generatedfilepackage.GeneratedFileTest;\n"
			+ "@MessagerAnnotation(severity=MessagerAnnotation.Severity.ERROR)\n"
			+ "@HelloWorldAnnotation\n"
			+ "public class A {\n"
			+ "    public static void main( String[] argv ) {\n"
			+ "        GeneratedFileTest.helloWorld();\n"
			+ "    }\n"
			+ "}\n";

		IPath p1aPath = env.addClass( srcRoot, "p1", "A", codeMessageFirst );
		fullBuild( project.getFullPath() );
		checkProcessorResult(HelloWorldAnnotationProcessor.class);
		checkProcessorResult(MessagerAnnotationProcessor.class);
		expectingOnlySpecificProblemFor( p1aPath, new ExpectedProblem(
			"A", MessagerAnnotationProcessor.PROBLEM_TEXT_ERROR, p1aPath ) ); //$NON-NLS-1$ //$NON-NLS-2$	
	}
	

	
	/**
	 *  This test makes sure we run apt on generated files during build
	 */

	public void testNestedGeneratedFileInBuilder() throws Exception
	{
		IProject project = env.getProject( getProjectName() );
		IPath srcRoot = getSourcePath( getProjectName() );
		
		String code = "package p1;\n"
			+ "//import org.eclipse.jdt.apt.tests.annotations.nestedhelloworld.NestedHelloWorldAnnotation;"
			+ "import generatedfilepackage.GeneratedFileTest;"
			+ "\n" + "public class A " + "\n" + "{"
			+ "    //@NestedHelloWorldAnnotation" + "\n"
			+ "    public static void main( String[] argv )" + "\n" + "    {"
			+ "\n"
			+ "        GeneratedFileTest.helloWorld();"
			+ "\n" + "    }" + "\n" + "}" + "\n";

		
		IPath p1aPath = env.addClass( srcRoot, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
			code );

		fullBuild( project.getFullPath() );

		expectingOnlyProblemsFor( p1aPath );
		expectingOnlySpecificProblemFor( p1aPath, new ExpectedProblem(
			"A", "GeneratedFileTest cannot be resolved", p1aPath ) ); //$NON-NLS-1$ //$NON-NLS-2$	

		code = "package p1;\n"
			+ "import org.eclipse.jdt.apt.tests.annotations.nestedhelloworld.NestedHelloWorldAnnotation;\n"
			+ "import generatedfilepackage.GeneratedFileTest;"
			+ "\n" + "public class A " + "\n" + "{"
			+ "    @NestedHelloWorldAnnotation" + "\n"
			+ "    public static void main( String[] argv )" + "\n" + "    {"
			+ "\n"
			+ "        GeneratedFileTest.helloWorld();"
			+ "\n" + "    }" + "\n" + "}" + "\n";

		env.addClass( srcRoot, "p1", "A", code );
		fullBuild( project.getFullPath() );

		expectingOnlyProblemsFor( new IPath[0] );
	}
		
	
	/**
	 *   This test makes sure that our extra-dependency stuff is hooked up in the build.  
	 *   Specifically, we test to make sure that Extra dependencies only appear when 
	 *   an annotation processor looks up a type by name.  We also test that expected
	 *   build output is there because of the dependency.
	 */

	public void testExtraDependencies()
	{
		String codeA = "package p1.p2.p3.p4;\n"
			+  "public class A { B b; }";
		
		String codeB1 = "package p1.p2.p3.p4;\n"
			+  "public class B { }";
		
		String codeB2 = "package p1.p2.p3.p4;\n"
			+  "public class B { public static void main( String[] argv ) {} }";
		
		String codeC = "package p1.p2.p3.p4;\n"
			+  "public class C { }";
		
		String codeC2 = "package p1.p2.p3.p4;\n"
			+  "public class C { public int foo; }";
		
		String codeD = "package p1.p2.p3.p4;\n"
			+  "public class D { }";
		 
		String codeE = "package p1.p2.p3.p4;\n"
			+  "public class E { }";
		
		IProject project = env.getProject( getProjectName() );
		IPath srcRoot = getSourcePath( getProjectName() );
		
		env.addClass( srcRoot, "p1.p2.p3.p4", "A", //$NON-NLS-1$ //$NON-NLS-2$
			codeA );
		
		env.addClass( srcRoot, "p1.p2.p3.p4", "B", //$NON-NLS-1$ //$NON-NLS-2$
			codeB1 );
		
		env.addClass( srcRoot, "p1.p2.p3.p4", "C", //$NON-NLS-1$ //$NON-NLS-2$
			codeC );
		
		env.addClass( srcRoot, "p1.p2.p3.p4", "D", //$NON-NLS-1$ //$NON-NLS-2$
			codeD );
		
		env.addClass( srcRoot, "p1.p2.p3.p4", "E", //$NON-NLS-1$ //$NON-NLS-2$
			codeE );
		
		fullBuild( project.getFullPath() );
		expectingNoProblems();
		
		// touch B - make sure its public shape changes.
		env.addClass( srcRoot, "p1.p2.p3.p4", "B", //$NON-NLS-1$ //$NON-NLS-2$
			codeB2 );
		
		incrementalBuild( project.getFullPath() );
		expectingNoProblems();
		expectingCompiledClasses(new String[]{"p1.p2.p3.p4.B", "p1.p2.p3.p4.A"}); //$NON-NLS-1$ //$NON-NLS-2$
		expectingCompilingOrder(new String[]{"p1.p2.p3.p4.B", "p1.p2.p3.p4.A"}); //$NON-NLS-1$ //$NON-NLS-2$

		//
		//  Now have p1.p2.p3.p4.A w/ an anontation whose processor looks up p1.p2.p3.p4.C by name 
		//
		
		// new code for A with an annotation processor that should introduce a dep on C
		codeA = "package p1.p2.p3.p4;\n"
			+  "import org.eclipse.jdt.apt.tests.annotations.extradependency.ExtraDependencyAnnotation;" + "\n" 
			+  "@ExtraDependencyAnnotation" + "\n" 
			+  "public class A {  }";
		
		env.addClass( srcRoot, "p1.p2.p3.p4", "A", //$NON-NLS-1$ //$NON-NLS-2$
			codeA );
		
		fullBuild( project.getFullPath() );
		expectingNoProblems();
		
		// touch C
		env.addClass( srcRoot, "p1.p2.p3.p4", "C", //$NON-NLS-1$ //$NON-NLS-2$
			codeC2 );
		
		incrementalBuild( project.getFullPath() );
		expectingNoProblems();
		
		//
		// Note that p1.p2.p3.p4.A is showing up twice because it has annotations, and we need to 
		// parse the source, parsing runs through the compiler, and this registers the 
		// file a second time with the Compiler#DebugRequestor 
		//
		expectingCompiledClasses(new String[]{"p1.p2.p3.p4.C", "p1.p2.p3.p4.A"}); //$NON-NLS-1$ //$NON-NLS-2$
		expectingCompilingOrder(new String[]{"p1.p2.p3.p4.C", "p1.p2.p3.p4.A"}); //$NON-NLS-1$ //$NON-NLS-2$
		
		//
		// now make sure that p1.p2.p3.p4.C is not compiled when A uses NoOp Annotation
		//
		
		// new code for A with an annotation processor that should remove a dep on C
		codeA = "package p1.p2.p3.p4;\n"
			+  "import org.eclipse.jdt.apt.tests.annotations.noop.NoOpAnnotation;" + "\n" 
			+  "@NoOpAnnotation" + "\n" 
			+  "public class A { B b; D d; }";
		
		env.addClass( srcRoot, "p1.p2.p3.p4", "A", //$NON-NLS-1$ //$NON-NLS-2$
			codeA );
		
		fullBuild( project.getFullPath() );
		expectingNoProblems();
		
		// touch C
		env.addClass( srcRoot, "p1.p2.p3.p4", "C", //$NON-NLS-1$ //$NON-NLS-2$
			codeC2 );
		
		incrementalBuild( project.getFullPath() );
		expectingNoProblems();
		
		//
		// Note that p1.p2.p3.p4.A is showing up twice because it has annotations, and we need to 
		// parse the source, parsing runs through the compiler, and this registers the 
		// file a second time with the Compiler#DebugRequestor 
		//
		expectingCompiledClasses(new String[]{"p1.p2.p3.p4.C" }); //$NON-NLS-1$ //$NON-NLS-2$
		expectingCompilingOrder(new String[]{"p1.p2.p3.p4.C" }); //$NON-NLS-1$ //$NON-NLS-2$
	}

	/**
	 *   Test that we do not recompile generated files that are
	 *   not changed even as their parent is modified.
	 */

	public void testCaching()
	{
		String code = "package p1;\n"
			+ "import org.eclipse.jdt.apt.tests.annotations.helloworld.HelloWorldAnnotation;"
			+ "\n" + "public class A " + "\n" + "{"
			+ "    @HelloWorldAnnotation" + "\n"
			+ "    public static void main( String[] argv )" + "\n" + "    {"
			+ "\n"
			+ "    }" 
			+ "\n" 
			+ "}" 
			+ "\n";
		
		String modifiedCode = "package p1;\n"
			+ "import org.eclipse.jdt.apt.tests.annotations.helloworld.HelloWorldAnnotation;"
			+ "\n" + "public class A " + "\n" + "{"
			+ "    @HelloWorldAnnotation" + "\n"
			+ "    public static void main( String[] argv )" + "\n" + "    {"
			+ "\n"
			+ "        "
			+ "\n" 
			+ "    }" 
			+ "\n" 
			+ "    public static void otherMethod()" + "\n" + "    {"
			+ "        System.out.println();\n"
			+ "    }"
			+ "}" 
			+ "\n";
		
		IProject project = env.getProject( getProjectName() );
		IPath srcRoot = getSourcePath( getProjectName() );
		
		env.addClass( srcRoot, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
			code );
		
		fullBuild( project.getFullPath() );
		expectingNoProblems();
		expectingCompiledClasses(new String[] {"p1.A", "generatedfilepackage.GeneratedFileTest"}); //$NON-NLS-1 //$NON_NLS-2$
		
		// touch A - make sure its public shape changes.
		env.addClass( srcRoot, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
			modifiedCode );
		incrementalBuild( project.getFullPath() );
		expectingNoProblems();
		expectingCompiledClasses(new String[]{"p1.A"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
	}

	/**
	 * This test makes sure that we delete generated files when the parent file 
	 * is deleted.  We also make sure that multi-parent support is working.
	 */

	public void testDeletedParentFile() throws Exception
	{
		IProject project = env.getProject( getProjectName() );
		IPath srcRoot = getSourcePath( getProjectName() );

		String a1Code = "package p1; " + "\n"
			+ "import org.eclipse.jdt.apt.tests.annotations.helloworld.HelloWorldAnnotation;" + "\n"
			+ "@HelloWorldAnnotation" + "\n"
			+ "public class A1 {}";
		String a2Code = "package p1; " + "\n"
			+ "import org.eclipse.jdt.apt.tests.annotations.helloworld.HelloWorldAnnotation;" + "\n"
			+ "@HelloWorldAnnotation" + "\n"
			+ "public class A2 {}";
		String bCode = "package p1; " + "\n"
			+ "public class B { generatedfilepackage.GeneratedFileTest gft; }";

		IPath p1a1Path = env.addClass( srcRoot, "p1", "A1", //$NON-NLS-1$ //$NON-NLS-2$
			a1Code );
		IPath p1a2Path = env.addClass( srcRoot, "p1", "A2", //$NON-NLS-1$ //$NON-NLS-2$
			a2Code );
		IPath p1bPath = env.addClass( srcRoot, "p1", "B", //$NON-NLS-1$ //$NON-NLS-2$
			bCode );
		
		fullBuild( project.getFullPath() );
		expectingNoProblems();
		
		// now delete file A1 and make sure we still have no problems
		TestUtil.deleteFile(p1a1Path);
		
		// sleep to let the resource-change event fire
		sleep( 1000 );
		
		incrementalBuild( project.getFullPath() );
		
		expectingNoProblems();
		
		// now delete file A2 and make sure we have a problem on B
		TestUtil.deleteFile( p1a2Path );

		// sleep to let the resource-change event fire
		// TODO: Is there a more reliable, consistent, and efficient way to wait?
		sleep( 1000 );

		incrementalBuild( project.getFullPath() );
		expectingOnlyProblemsFor( p1bPath );
		expectingOnlySpecificProblemFor( p1bPath, new ExpectedProblem(
			"B", "generatedfilepackage cannot be resolved to a type", p1bPath ) ); //$NON-NLS-1$ //$NON-NLS-2$	
	}
	
	public void testStopGeneratingFileInBuilder_FullBuild()
	{
		internalTestStopGeneratingFileInBuilder( true );
	}

	public void testStopGeneratingFileInBuilder_IncrementalBuild()
	{
		internalTestStopGeneratingFileInBuilder( false );
	}
	
	private void internalTestStopGeneratingFileInBuilder( boolean fullBuild )
	{
		IProject project = env.getProject( getProjectName() );
		IPath srcRoot = getSourcePath( getProjectName() );
		
		String code = "package p1;\n"
			+ "//import org.eclipse.jdt.apt.tests.annotations.helloworld.HelloWorldAnnotation;\n"
			+ "import generatedfilepackage.GeneratedFileTest;"
			+ "\n" + "public class A " + "\n" + "{"
			+ "    //@HelloWorldAnnotation" + "\n"
			+ "    public static void main( String[] argv )" + "\n" + "    {"
			+ "\n"
			+ "        GeneratedFileTest.helloWorld();"
			+ "\n" + "    }" + "\n" + "}" + "\n";

		
		IPath p1aPath = env.addClass( srcRoot, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$
			code );

		if ( fullBuild )
			fullBuild( project.getFullPath() );
		else
			incrementalBuild( project.getFullPath() );
		

		expectingOnlyProblemsFor( p1aPath );
		expectingOnlySpecificProblemsFor( p1aPath, new ExpectedProblem[]{ 
				new ExpectedProblem( "A", "The import generatedfilepackage cannot be resolved", p1aPath ),
				new ExpectedProblem( "A", "GeneratedFileTest cannot be resolved", p1aPath ) }
				); //$NON-NLS-1$ //$NON-NLS-2$	

		code = "package p1;\n"
			+ "import org.eclipse.jdt.apt.tests.annotations.helloworld.HelloWorldAnnotation;"
			+ "import generatedfilepackage.GeneratedFileTest;"
			+ "\n" + "public class A " + "\n" + "{"
			+ "    @HelloWorldAnnotation" + "\n"
			+ "    public static void main( String[] argv )" + "\n" + "    {"
			+ "\n"
			+ "        GeneratedFileTest.helloWorld();"
			+ "\n" + "    }" + "\n" + "}" + "\n";

		env.addClass( srcRoot, "p1", "A", code );
		if ( fullBuild )
			fullBuild( project.getFullPath() );
		else
			incrementalBuild( project.getFullPath() );
		
		expectingOnlyProblemsFor( new IPath[0] );

		// do a full build again.  This is necessary because generating the file
		// caused a classpath change, so the next inremental build will end up being
		// a full build because of the classpath change
		if ( ! fullBuild )
			fullBuild( project.getFullPath() );
		
		// now remove the annotation.  The generated file should go away
		// and we should see errors again
		code = "package p1;\n"
			+ "//import org.eclipse.jdt.apt.tests.annotations.helloworld.HelloWorldAnnotation;"
			+ "import generatedfilepackage.GeneratedFileTest;"
			+ "\n" + "public class A " + "\n" + "{"
			+ "    //@HelloWorldAnnotation" + "\n"
			+ "    public static void main( String[] argv )" + "\n" + "    {"
			+ "\n"
			+ "        GeneratedFileTest.helloWorld();"
			+ "\n" + "    }" + "\n" + "}" + "\n";

		env.addClass( srcRoot, "p1", "A", code );
		
		if ( fullBuild )
			fullBuild( project.getFullPath() );
		else
			incrementalBuild( project.getFullPath() );
		
		expectingOnlyProblemsFor( p1aPath );
		
		expectingOnlySpecificProblemFor( p1aPath, 
					new ExpectedProblem( "A", "GeneratedFileTest cannot be resolved", p1aPath ) ); //$NON-NLS-1$ 
	}
	
	public void testAPTRounding()
	{
		IProject project = env.getProject( getProjectName() );
		IPath srcRoot = getSourcePath( getProjectName()  );
		
		String codeX = "package p1;\n"
			+ "\n import org.eclipse.jdt.apt.tests.annotations.aptrounding.*;"
			+ "\n@GenBean\n"
			+ "public class X {}\n";
		
		env.addClass( srcRoot, "p1", "X", codeX );
		
		String codeY = "package p1;\n"
			+ "\n import org.eclipse.jdt.apt.tests.annotations.aptrounding.*;"
			+ "public class Y { @GenBean2 test.Bean _bean = null; }\n";
		
		env.addClass( srcRoot, "p1", "Y", codeY );

		fullBuild( project.getFullPath() );
		
		expectingNoProblems();
	}
	
	// After fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=185601,
	// the config marker 'Generated source folder * is not in classpath'
	// is not easy to simulate. So, this test doesn't really do anything
	public void testConfigMarker() throws Exception{
		final String projectName = "ConfigMarkerTestProject";	
		final IJavaProject javaProj = createJavaProject( projectName );
		// apt is currently disabled save off the cp before configuration
		final IClasspathEntry[] cp = javaProj.getRawClasspath();		
		IProject project = env.getProject( projectName );
		IPath srcRoot = getSourcePath( projectName );		
		// this will cause a type generation.
		String code = "package pkg;\n"
			+ "import org.eclipse.jdt.apt.tests.annotations.helloworld.HelloWorldAnnotation;"
			+ "\npublic class Foo{\n"
			+ "    @HelloWorldAnnotation\n"
			+ "    public static void main( String[] argv ){}"
			+ "\n}";
		
		env.addClass( srcRoot, "pkg", "Foo", code );
		
		AptConfig.setEnabled(javaProj, true);
		fullBuild( project.getFullPath() );
		expectingNoProblems();
		expectingNoMarkers();
		
		// wipe out the source folder from the classpath.
		javaProj.setRawClasspath(cp, null);
		fullBuild( project.getFullPath() );
		expectingNoProblems();
		// classpath should be updated with an entry for the source folder
		// make sure we do not post the marker about the incorrect classpath
		expectingNoMarkers();
		
		// take out the annotation and no type generation will occur.
		code = "package pkg;\n"
			+ "\npublic class Foo{\n"			
			+ "    public static void main( String[] argv ){}"
			+ "\n}";
		
		env.addClass( srcRoot, "pkg", "Foo", code );
		fullBuild( project.getFullPath() );		
		expectingNoProblems();
		// Make sure we cleaned out config marker from previous build
		// We don't need to generate types, hence we should not register the config marker 
		expectingNoMarkers();
	}
	
	public void testDeletedGeneratedSourceFolder()
		throws Exception
	{
		final String projectName = "DeleteGenSourceFolderTestProject";	
		final IJavaProject javaProj = createJavaProject( projectName );
		IProject project = env.getProject( projectName );
		IPath srcRoot = getSourcePath( projectName );		
		// this will cause a type generation.
		String code = "package pkg;\n"
			+ "import org.eclipse.jdt.apt.tests.annotations.helloworld.HelloWorldAnnotation;"
			+ "\npublic class Foo{\n"
			+ "    @HelloWorldAnnotation\n"
			+ "    public static void main( String[] argv ){}"
			+ "\n}";
		
		env.addClass( srcRoot, "pkg", "Foo", code );
		AptConfig.setEnabled(javaProj, true);
		fullBuild( project.getFullPath() );
		expectingNoProblems();
		expectingNoMarkers();
		
		GeneratedSourceFolderManager mgr = AptPlugin.getAptProject(javaProj).getGeneratedSourceFolderManager();
		IFolder srcFolder = mgr.getFolder();
		assertEquals(true, srcFolder.exists());
		// delete the gen source folder
		Util.delete(srcFolder);
		assertEquals(false, srcFolder.exists());
		
		// we would have re-created the folder on the next build
		fullBuild( project.getFullPath() );
		expectingNoProblems();
		expectingNoMarkers();
	}
	
}

Back to the top