01: /*******************************************************************************
02: * Copyright (c) 2007 BEA Systems, Inc.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * wharley@bea.com - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.apt.pluggable.tests;
11:
12: import junit.framework.Test;
13: import junit.framework.TestSuite;
14:
15: import org.eclipse.core.resources.IProject;
16: import org.eclipse.jdt.apt.core.util.AptConfig;
17: import org.eclipse.jdt.core.IJavaProject;
18:
19: /**
20: * Basic tests for the Filer interface in the IDE.
21: * @see javax.annotation.processing.Filer
22: */
23: public class FilerTests extends TestBase {
24:
25: public FilerTests(String name) {
26: super (name);
27: }
28:
29: public static Test suite() {
30: return new TestSuite(FilerTests.class);
31: }
32:
33: /**
34: * Test generation of a source file, using the GenClass6 annotation
35: * @see javax.annotation.processing.Filer#createClassFile(CharSequence, javax.lang.model.element.Element...)
36: */
37: public void testCreateSourceFile() throws Throwable {
38: // Temporary workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=201931
39: // Bail out on Linux
40: String osName = System.getProperty("os.name");
41: if (null == osName || !osName.contains("Windows")) {
42: return;
43: }
44:
45: IJavaProject jproj = createJavaProject(_projectName);
46: IProject proj = jproj.getProject();
47: IdeTestUtils.copyResources(proj, "targets/filer01a",
48: "src/targets/filer");
49: AptConfig.setEnabled(jproj, true);
50: fullBuild();
51: expectingNoProblems();
52:
53: // Check whether generated sources were generated and compiled
54: expectingFile(proj, ".apt_generated/gen6/Generated01.java");
55: final String[] expectedClasses = { "targets.filer.Parent01",
56: "gen6.Generated01" };
57: expectingUniqueCompiledClasses(expectedClasses);
58:
59: // Check whether non-source resource was generated in final round
60: expectingFile(proj, ".apt_generated/summary.txt");
61:
62: //TODO: if a parent file is modified,
63: // the generated file should be regenerated and recompiled.
64: // The generated resource file should be regenerated (but not compiled).
65:
66: // Modify target file to remove annotation and incrementally rebuild;
67: // generated file should be deleted.
68: IdeTestUtils.copyResources(proj, "targets/filer01b",
69: "src/targets/filer");
70: incrementalBuild();
71: expectingNoProblems();
72:
73: final String[] expectedClasses2 = { "targets.filer.Parent01" };
74: expectingUniqueCompiledClasses(expectedClasses2);
75:
76: expectingNoFile(proj, ".apt_generated/gen6/Generated01.java");
77: expectingNoFile(proj, ".apt_generated/summary.txt");
78: }
79:
80: }
|