Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTill Brychcy2018-02-12 22:43:44 +0000
committerTill Brychcy2018-02-19 21:43:59 +0000
commit86b105d1761e70cf1cca4f74c60ede1ff3f77520 (patch)
treefb39f9a1d3a763b9a70d044cb351e44b837b2504 /org.eclipse.jdt.apt.tests
parente603dedfdfd718d3d302f1cd90c78085d81e98f0 (diff)
downloadeclipse.jdt.core-86b105d1761e70cf1cca4f74c60ede1ff3f77520.tar.gz
eclipse.jdt.core-86b105d1761e70cf1cca4f74c60ede1ff3f77520.tar.xz
eclipse.jdt.core-86b105d1761e70cf1cca4f74c60ede1ff3f77520.zip
Bug 531072 - [testsources][apt] classes generated for test sources need
to be put in a test source folder Change-Id: Ieb06760c55d8fe3bd04954ca13d1b9fb4f67d846
Diffstat (limited to 'org.eclipse.jdt.apt.tests')
-rw-r--r--org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/APTTestBase.java16
-rw-r--r--org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/AptBuilderTests.java4
-rw-r--r--org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/AptReconcileTests.java4
-rw-r--r--org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/FileGenerationTests.java84
-rw-r--r--org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/PreferencesTests.java72
-rw-r--r--org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/StarProcessorTests.java4
6 files changed, 163 insertions, 21 deletions
diff --git a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/APTTestBase.java b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/APTTestBase.java
index 77b8b6bf6a..1fbd644e88 100644
--- a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/APTTestBase.java
+++ b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/APTTestBase.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2008 BEA Systems, Inc.
+ * Copyright (c) 2005, 2018 BEA Systems, Inc.
* 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
@@ -25,6 +25,7 @@ import org.eclipse.jdt.apt.tests.annotations.BaseProcessor;
import org.eclipse.jdt.apt.tests.annotations.ProcessorTestStatus;
import org.eclipse.jdt.apt.tests.annotations.generic.GenericFactory;
import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.tests.builder.BuilderTests;
import org.eclipse.jdt.core.tests.builder.Problem;
import org.eclipse.jdt.core.tests.util.Util;
@@ -101,6 +102,17 @@ public abstract class APTTestBase extends BuilderTests{
return javaProj;
}
+ /**
+ * Add a test source folder to the current project and return it
+ * @return IPath
+ * @throws JavaModelException
+ */
+ protected IPath addTestSourceFolder() throws JavaModelException {
+ IJavaProject currentJavaProject = getCurrentJavaProject();
+ return env.addPackageFragmentRoot(currentJavaProject.getPath(), "src-tests", null, null,
+ "bin-tests", true);
+ }
+
protected void tearDown()
throws Exception
{
@@ -130,7 +142,7 @@ public abstract class APTTestBase extends BuilderTests{
IPath srcRoot = srcFolder.getFullPath();
return srcRoot;
}
-
+
private String concate(String[] messages){
final int len = messages == null ? 0 : messages.length;
StringBuilder buffer = new StringBuilder();
diff --git a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/AptBuilderTests.java b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/AptBuilderTests.java
index dd3efcd0e9..f871f00e11 100644
--- a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/AptBuilderTests.java
+++ b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/AptBuilderTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2012 BEA Systems, Inc. and others
+ * Copyright (c) 2005, 2018 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
@@ -698,7 +698,7 @@ public class AptBuilderTests extends APTTestBase
expectingNoProblems();
expectingNoMarkers();
- GeneratedSourceFolderManager mgr = AptPlugin.getAptProject(javaProj).getGeneratedSourceFolderManager();
+ GeneratedSourceFolderManager mgr = AptPlugin.getAptProject(javaProj).getGeneratedSourceFolderManager(false);
IFolder srcFolder = mgr.getFolder();
assertEquals(true, srcFolder.exists());
// delete the gen source folder
diff --git a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/AptReconcileTests.java b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/AptReconcileTests.java
index 423e57bd72..95b7e5457f 100644
--- a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/AptReconcileTests.java
+++ b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/AptReconcileTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 BEA Systems, Inc.
+ * Copyright (c) 2005, 2018 BEA Systems, Inc.
* 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
@@ -318,7 +318,7 @@ public class AptReconcileTests extends ModifyingResourceTests
assertProblems( "UnexpectedProblems", "" );
IJavaProject jp = _workingCopy.getJavaProject();
- GeneratedFileManager gfm = AptPlugin.getAptProject(jp).getGeneratedFileManager();
+ GeneratedFileManager gfm = AptPlugin.getAptProject(jp).getGeneratedFileManager(false);
if ( !gfm.containsWorkingCopyMapEntriesForParent((IFile)_workingCopy.getResource()))
fail( "Expected to find map entries in GeneratedFileManager");
diff --git a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/FileGenerationTests.java b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/FileGenerationTests.java
index 9078503f56..6bff09ee1b 100644
--- a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/FileGenerationTests.java
+++ b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/FileGenerationTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 BEA Systems, Inc.
+ * Copyright (c) 2005, 2018 BEA Systems, Inc.
* 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
@@ -105,7 +105,7 @@ public class FileGenerationTests extends APTTestBase {
fullBuild( project.getFullPath() );
expectingNoProblems();
- Map<String,String> options = AptConfig.getProcessorOptions(jproj);
+ Map<String,String> options = AptConfig.getProcessorOptions(jproj, false);
String sourcepath = options.get("-sourcepath");
assertTrue(sourcepath.contains("__foo_src"));
@@ -159,7 +159,7 @@ public class FileGenerationTests extends APTTestBase {
expectingNoProblems();
// Look for the file
- Map<String,String> options = AptConfig.getProcessorOptions(JavaCore.create(project));
+ Map<String,String> options = AptConfig.getProcessorOptions(JavaCore.create(project), false);
// We'll find it in the binary output directory
String outputRootPath = options.get("-d");
File theFile = new File(new File(outputRootPath), TEXT_FILE_NAME);
@@ -219,7 +219,7 @@ public class FileGenerationTests extends APTTestBase {
expectingNoProblems();
AptProject aptProj = new AptProject(env.getJavaProject(getProjectName()));
- GeneratedFileManager gfm = aptProj.getGeneratedFileManager();
+ GeneratedFileManager gfm = aptProj.getGeneratedFileManager(false);
String genSrcDir = AptConfig.getGenSrcDir(env.getJavaProject(getProjectName()));
String P = File.separator;
@@ -229,4 +229,80 @@ public class FileGenerationTests extends APTTestBase {
assertTrue("expected src/test/Test.java to be designated as parent file", gfm.isParentFile(parentFile));
assertTrue("expected .apt_generated/test/A.java to be designated as generated file", gfm.isGeneratedFile(generatedFile));
}
+
+ public void testTestSourceGen() throws Exception
+ {
+ IJavaProject jproj = env.getJavaProject( getProjectName() );
+ IProject project = env.getProject( getProjectName() );
+ IPath srcRoot = getSourcePath();
+
+ String mainCode =
+ "package test;" + "\n" +
+ "import org.eclipse.jdt.apt.tests.annotations.helloworld.HelloWorldAnnotation;" + "\n" +
+ "@HelloWorldAnnotation(\"GeneratedFileMain\")" + "\n" +
+ "public class Main" + "\n" +
+ "{" + "\n" +
+ " generatedfilepackage.GeneratedFileMain gfm;" + "\n" +
+ "}";
+ String testCode =
+ "package test;" + "\n" +
+ "import org.eclipse.jdt.apt.tests.annotations.helloworld.HelloWorldAnnotation;" + "\n" +
+ "@HelloWorldAnnotation" + "\n" +
+ "public class Test" + "\n" +
+ "{" + "\n" +
+ " generatedfilepackage.GeneratedFileTest gft;" + "\n" +
+ " generatedfilepackage.GeneratedFileMain gfm;" + "\n" +
+ "}";
+
+ AptConfig.setGenSrcDir(jproj, "__main_foo_src");
+ AptConfig.setGenTestSrcDir(jproj, "__test_foo_src");
+
+ IPath testSrcRoot = addTestSourceFolder();
+
+ env.addClass(srcRoot, "test", "Main", mainCode);
+ env.addClass(testSrcRoot, "test", "Test", testCode);
+
+ fullBuild( project.getFullPath() );
+ expectingNoProblems();
+
+ assertTrue(AptConfig.getProcessorOptions(jproj, false).get("-sourcepath").contains("__main_foo_src"));
+ assertTrue(AptConfig.getProcessorOptions(jproj, true).get("-sourcepath").contains("__test_foo_src"));
+ assertEquals(ProcessorTestStatus.NO_ERRORS, ProcessorTestStatus.getErrors());
+
+ String P = File.separator;
+
+ AptProject aptProj = new AptProject(env.getJavaProject(getProjectName()));
+ GeneratedFileManager maingfm = aptProj.getGeneratedFileManager(false);
+ GeneratedFileManager testgfm = aptProj.getGeneratedFileManager(true);
+
+ IFile mainParentFile = project.getFile("src" + P + "test" + P + "Main.java");
+ IFile mainGeneratedFile = project.getFile("__main_foo_src" + P + "generatedfilepackage" + P + "GeneratedFileMain.java");
+
+ IFile testParentFile = project.getFile("src-tests" + P + "test" + P + "Test.java");
+ IFile testGeneratedFile = project.getFile("__test_foo_src" + P + "generatedfilepackage" + P + "GeneratedFileTest.java");
+
+ assertTrue("expected "
+ + mainParentFile.getProjectRelativePath()
+ + " to be designated as main parent file", maingfm.isParentFile(mainParentFile));
+ assertTrue("expected " + mainGeneratedFile.getProjectRelativePath()
+ + " to be designated as main generated file", maingfm.isGeneratedFile(mainGeneratedFile));
+ assertFalse("expected "
+ + testParentFile.getProjectRelativePath()
+ + " not to be designated as main parent file", maingfm.isParentFile(testParentFile));
+ assertFalse("expected " + testGeneratedFile.getProjectRelativePath()
+ + " not to be designated as main generated file", maingfm.isGeneratedFile(testGeneratedFile));
+
+ assertTrue("expected "
+ + testParentFile.getProjectRelativePath()
+ + " to be designated as test parent file", testgfm.isParentFile(testParentFile));
+ assertTrue("expected " + testGeneratedFile.getProjectRelativePath()
+ + " to be designated as test generated file", testgfm.isGeneratedFile(testGeneratedFile));
+ assertFalse("expected "
+ + mainParentFile.getProjectRelativePath()
+ + " not to be designated as test parent file", testgfm.isParentFile(mainParentFile));
+ assertFalse("expected " + mainGeneratedFile.getProjectRelativePath()
+ + " not to be designated as test generated file", testgfm.isGeneratedFile(mainGeneratedFile));
+
+ }
+
}
diff --git a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/PreferencesTests.java b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/PreferencesTests.java
index ff4ded6041..64bd1ba8c8 100644
--- a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/PreferencesTests.java
+++ b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/PreferencesTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 BEA Systems, Inc.
+ * Copyright (c) 2005, 2018 BEA Systems, Inc.
* 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
@@ -179,7 +179,7 @@ public class PreferencesTests extends APTTestBase {
AptConfig.addProcessorOption(jproj, "space", "\"text with spaces\"");
AptConfig.addProcessorOption(jproj, "quux", null);
AptConfig.addProcessorOption(jproj, "quux", null); // adding twice should have no effect
- Map<String, String> options = AptConfig.getProcessorOptions(jproj);
+ Map<String, String> options = AptConfig.getProcessorOptions(jproj, false);
String val = options.get("foo");
assertEquals(val, "bar");
val = options.get("quux");
@@ -187,7 +187,7 @@ public class PreferencesTests extends APTTestBase {
val = options.get("space");
assertEquals(val, "\"text with spaces\"");
AptConfig.removeProcessorOption(jproj, "foo");
- options = AptConfig.getProcessorOptions(jproj);
+ options = AptConfig.getProcessorOptions(jproj, false);
assertFalse(options.containsKey("foo"));
assertTrue(options.containsKey("quux"));
AptConfig.removeProcessorOption(jproj, "quux");
@@ -196,7 +196,7 @@ public class PreferencesTests extends APTTestBase {
AptConfig.addProcessorOption(null, "workspace option", "corresponding value");
AptConfig.addProcessorOption(null, "foo", "whatever");
AptConfig.removeProcessorOption(null, "foo");
- options = AptConfig.getProcessorOptions(null);
+ options = AptConfig.getProcessorOptions(null, false);
assertFalse(options.containsKey("foo"));
assertTrue(options.containsKey("workspace option"));
AptConfig.removeProcessorOption(null, "workspace option");
@@ -207,7 +207,7 @@ public class PreferencesTests extends APTTestBase {
*/
public void testAutomaticOptions() throws Exception {
IJavaProject jproj = env.getJavaProject( getProjectName() );
- Map<String,String> options = AptConfig.getProcessorOptions(jproj);
+ Map<String,String> options = AptConfig.getProcessorOptions(jproj, false);
String classpath = options.get("-classpath");
assertNotNull(classpath);
@@ -235,13 +235,19 @@ public class PreferencesTests extends APTTestBase {
public void testGenSrcDir() throws Exception {
IJavaProject jproj = env.getJavaProject( getProjectName() );
String genSrcDir = AptConfig.getGenSrcDir(jproj);
+ String genTestSrcDir = AptConfig.getGenTestSrcDir(jproj);
assertEquals(AptPreferenceConstants.DEFAULT_GENERATED_SOURCE_FOLDER_NAME, genSrcDir);
+ assertEquals(AptPreferenceConstants.DEFAULT_GENERATED_TEST_SOURCE_FOLDER_NAME, genTestSrcDir);
final String newDir = "gen/src";
+ final String newTestDir = "gen/src-tests";
AptConfig.setGenSrcDir(jproj, newDir);
+ AptConfig.setGenTestSrcDir(jproj, newTestDir);
genSrcDir = AptConfig.getGenSrcDir(jproj);
+ genTestSrcDir = AptConfig.getGenTestSrcDir(jproj);
assertEquals(newDir, genSrcDir);
+ assertEquals(newTestDir, genTestSrcDir);
}
@@ -264,56 +270,104 @@ public class PreferencesTests extends APTTestBase {
boolean aptEnabled = AptConfig.isEnabled(javaProj);
// test 1: make sure apt is disabled by default
assertEquals(false, aptEnabled);
- final GeneratedSourceFolderManager gsfm = AptPlugin.getAptProject(javaProj).getGeneratedSourceFolderManager();
+ final GeneratedSourceFolderManager gsfm = AptPlugin.getAptProject(javaProj).getGeneratedSourceFolderManager(false);
+ final GeneratedSourceFolderManager testgsfm = AptPlugin.getAptProject(javaProj).getGeneratedSourceFolderManager(true);
IFolder srcFolder = gsfm.getFolder();
+ IFolder testSrcFolder = testgsfm.getFolder();
String folderName = srcFolder.getProjectRelativePath().toOSString();
+ String testFolderName = testSrcFolder.getProjectRelativePath().toOSString();
// test 2: apt is disabled, then folder should not exists
assertEquals(srcFolder.exists(), false);
+ assertEquals(testSrcFolder.exists(), false);
+
// test 3: folder name has not been configured, then it should be the default.
// folder name should be the default name.
assertEquals(folderName, AptPreferenceConstants.DEFAULT_GENERATED_SOURCE_FOLDER_NAME);
+ assertEquals(testFolderName, AptPreferenceConstants.DEFAULT_GENERATED_TEST_SOURCE_FOLDER_NAME);
// set folder name while apt is disabled
String newName = ".gensrcdir";
+ String newTestName = ".gentestsrcdir";
+
AptConfig.setGenSrcDir(javaProj, newName);
+ AptConfig.setGenTestSrcDir(javaProj, newTestName);
+
srcFolder = gsfm.getFolder();
+ testSrcFolder = testgsfm.getFolder();
+
folderName = srcFolder.getProjectRelativePath().toOSString();
+ testFolderName = testSrcFolder.getProjectRelativePath().toOSString();
+
// test 4: apt still disabled but folder name changed, make sure the folder is not on disk.
assertEquals(false, srcFolder.exists());
+ assertEquals(false, testSrcFolder.exists());
+
// test 5: make sure we got the new name
assertEquals(newName, folderName);
+ assertEquals(newTestName, testFolderName);
+
// test 6: make sure the source folder is not on the classpath.
assertEquals( false, isOnClasspath(javaProj, srcFolder.getFullPath()) );
+ assertEquals( false, isOnClasspath(javaProj, testSrcFolder.getFullPath()) );
// enable apt
AptConfig.setEnabled(javaProj, true);
aptEnabled = AptConfig.isEnabled(javaProj);
// test 7: make sure it's enabled after we called the API to enable it.
assertEquals(true, aptEnabled);
- srcFolder = gsfm.getFolder();
+ srcFolder = gsfm.getFolder();
+ testSrcFolder = testgsfm.getFolder();
+
folderName = srcFolder.getProjectRelativePath().toOSString();
+ testFolderName = testSrcFolder.getProjectRelativePath().toOSString();
+
// test 8: apt enabled, the source folder should be on disk
assertEquals(true, srcFolder.exists());
+ // generated test source folder should NOT exist, as the project has no test source folder
+ assertEquals(false, testSrcFolder.exists());
+
// test 9: make sure the name matches
assertEquals(newName, folderName);
+ assertEquals(newTestName, testFolderName);
+
// test 10: apt is enabled, folder must be on classpath.
assertEquals( true, isOnClasspath(javaProj, srcFolder.getFullPath()) );
-
+ // generated test source folder should NOT be on classpath, as the project has no test source folder
+ assertEquals( false, isOnClasspath(javaProj, testSrcFolder.getFullPath()) );
+
+ // test 11: now add a test source folder, generated test source folder should then exist and be on classpath
+ env.removePackageFragmentRoot(projectPath, "");
+ env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$
+ env.addPackageFragmentRoot( projectPath, "src" );
+ env.addPackageFragmentRoot(javaProj.getPath(), "src-tests", null, null,
+ "bin-tests", true);
+ fullBuild( javaProj.getProject().getFullPath() );
+ assertEquals(true, testSrcFolder.exists());
+ assertEquals(true, isOnClasspath(javaProj, testSrcFolder.getFullPath()) );
+
+
// now disable apt.
AptConfig.setEnabled(javaProj, false);
aptEnabled = AptConfig.isEnabled(javaProj);
// test 11: make sure it's disabled.
assertEquals(false, aptEnabled);
+
srcFolder = gsfm.getFolder();
+ testSrcFolder = testgsfm.getFolder();
+
folderName = srcFolder.getProjectRelativePath().toOSString();
+ testFolderName = testSrcFolder.getProjectRelativePath().toOSString();
// test 12: make sure we deleted the source folder when we disable apt
assertEquals(false, srcFolder.exists());
+ assertEquals(false, testSrcFolder.exists());
// test 13: make sure we didn't overwrite the configure folder name
assertEquals(newName, folderName);
+ assertEquals(newTestName, testFolderName);
// test 14: make sure we cleaned up the classpath.
assertEquals( false, isOnClasspath(javaProj, srcFolder.getFullPath()) );
+ assertEquals( false, isOnClasspath(javaProj, testSrcFolder.getFullPath()) );
}
-
+
private boolean isOnClasspath(IJavaProject javaProj, IPath path)
throws JavaModelException
{
diff --git a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/StarProcessorTests.java b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/StarProcessorTests.java
index 663c8c0728..2a9ee94736 100644
--- a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/StarProcessorTests.java
+++ b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/StarProcessorTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Walter Harley.
+ * Copyright (c) 2009, 2018 Walter Harley 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
@@ -694,7 +694,7 @@ public class StarProcessorTests extends APTTestBase
expectingNoProblems();
expectingNoMarkers();
- GeneratedSourceFolderManager mgr = AptPlugin.getAptProject(javaProj).getGeneratedSourceFolderManager();
+ GeneratedSourceFolderManager mgr = AptPlugin.getAptProject(javaProj).getGeneratedSourceFolderManager(false);
IFolder srcFolder = mgr.getFolder();
assertEquals(true, srcFolder.exists());
// delete the gen source folder

Back to the top