Skip to content

Commit 572a347

Browse files
committed
refactor builder tests
1 parent 8fe6793 commit 572a347

14 files changed

+54
-102
lines changed

base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/builder/BasicGroovyBuildTests.java

+23-42
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ private IPath[] createModularProject(final String name, final boolean isGroovy)
7676
} else {
7777
env.removeGroovyNature(name);
7878
}
79-
env.setOutputFolder(prjPath, "bin");
80-
env.removePackageFragmentRoot(prjPath, "");
81-
IPath srcPath = env.addPackageFragmentRoot(prjPath, "src");
79+
IPath srcPath = env.getPackageFragmentRootPath(prjPath, "src");
8280
try {
8381
return new IPath[] {prjPath, srcPath, env.addClass(srcPath,
8482
"module-info", "module " + name.toLowerCase() + " {\n}\n")};
@@ -88,16 +86,14 @@ private IPath[] createModularProject(final String name, final boolean isGroovy)
8886
}
8987

9088
private IPath[] createSimpleProject(final String name, final boolean isGroovy) throws Exception {
91-
IPath path = env.addProject(name, "1.8");
89+
IPath prjPath = env.addProject(name, "1.8");
9290
if (isGroovy) {
93-
env.addGroovyJars(path);
91+
env.addGroovyJars(prjPath);
9492
} else {
9593
env.removeGroovyNature(name);
9694
}
97-
fullBuild(path);
98-
env.setOutputFolder(path, "bin");
99-
env.removePackageFragmentRoot(path, "");
100-
return new IPath[] {path, env.addPackageFragmentRoot(path, "src")};
95+
fullBuild(prjPath);
96+
return new IPath[] {prjPath, env.getPackageFragmentRootPath(prjPath, "src")};
10197
}
10298

10399
private void addJUnitAndSpock(final IPath projectPath) throws Exception {
@@ -385,20 +381,22 @@ public void testProjectCompilerConfigScript2() throws Exception {
385381

386382
@Test // https://github.com/groovy/groovy-eclipse/issues/550
387383
public void testProjectBasedirAsOutputLocation() throws Exception {
388-
IPath path = env.addProject("Project", "1.8");
389-
env.setOutputFolder(path, "");
390-
env.addGroovyJars(path);
384+
IPath prj = env.addProject("Project", "1.8");
385+
env.removePackageFragmentRoot(prj, "src");
386+
env.addPackageFragmentRoot(prj, "");
387+
env.setOutputFolder(prj, "");
388+
env.addGroovyJars(prj);
391389

392390
//@formatter:off
393-
env.addGroovyClass(path, "p", "Script",
391+
env.addGroovyClass(prj, "p", "Script",
394392
"package p\n" +
395393
"println 'Groovy!'\n");
396394
//@formatter:on
397395

398-
fullBuild(path);
396+
fullBuild(prj);
399397
expectingNoProblems();
400398
expectingCompiledClasses("p.Script");
401-
executeClass(path, "p.Script", "Groovy!", null);
399+
executeClass(prj, "p.Script", "Groovy!", null);
402400
}
403401

404402
@Test
@@ -3342,10 +3340,10 @@ public void test98667() throws Exception {
33423340
}
33433341

33443342
@Test // https://bugs.eclipse.org/bugs/show_bug.cgi?id=164707
3345-
public void testBug164707() throws Exception {
3346-
IPath projectPath = env.addProject("Project");
3347-
env.getJavaProject(projectPath).setOption(JavaCore.COMPILER_SOURCE, "invalid");
3348-
fullBuild(projectPath);
3343+
public void testBug164707() {
3344+
IPath prj = env.addProject("Project");
3345+
env.getJavaProject(prj).setOption(JavaCore.COMPILER_SOURCE, "invalid");
3346+
fullBuild(prj);
33493347
expectingNoProblems();
33503348
}
33513349

@@ -3447,41 +3445,24 @@ public void testTags4() throws Exception {
34473445
assertEquals("Wrong priority", IMarker.PRIORITY_HIGH, priority);
34483446
}
34493447

3450-
@Test // When a groovy file name clashes with an existing type
3448+
@Test // a groovy file name clashes with an existing type
34513449
public void testBuildClash() throws Exception {
34523450
IPath[] paths = createSimpleProject("Project", true);
34533451

34543452
//@formatter:off
34553453
env.addGroovyClass(paths[1], "", "Stack",
34563454
"class StackTester {\n" +
3457-
" def o = new Stack();\n" +
3458-
" public static void main(String[] args) {\n" +
3459-
" System.out.println('>>'+new StackTester().o.getClass());\n" +
3460-
" System.out.println(\"Hello world\");\n" +
3461-
" }\n" +
3462-
"}\n");
3463-
//@formatter:on
3464-
3465-
incrementalBuild(paths[0]);
3466-
expectingCompiledClasses("StackTester");
3467-
expectingNoProblems();
3468-
executeClass(paths[0], "StackTester", ">>class java.util.Stack\nHello world\n", "");
3469-
3470-
//@formatter:off
3471-
env.addGroovyClass(paths[1], "", "Stack",
3472-
"class StackTester {\n" +
3473-
" def o = new Stack();\n" +
3474-
" public static void main(String[] args) {\n" +
3475-
" System.out.println('>>'+new StackTester().o.getClass());\n" +
3476-
" System.out.println(\"Hello world\");\n" +
3455+
" def x = new Stack()\n" +
3456+
" static main(args) {\n" +
3457+
" print(new StackTester().x.class)\n" +
34773458
" }\n" +
34783459
"}\n");
34793460
//@formatter:on
34803461

34813462
incrementalBuild(paths[0]);
3482-
expectingCompiledClasses("StackTester");
34833463
expectingNoProblems();
3484-
executeClass(paths[0], "StackTester", ">>class java.util.Stack\nHello world\n", "");
3464+
expectingCompiledClasses("StackTester", "StackTester"); // twice?
3465+
executeClass(paths[0], "StackTester", "class java.util.Stack", "");
34853466
}
34863467

34873468
@Test

base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/builder/BuildAccessRulesTests.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ public final class BuildAccessRulesTests extends BuilderTestSuite {
4949
@Before
5050
public void setUp() throws Exception {
5151
prj = env.addProject("Project", "1.7");
52-
src = prj.append("src");
53-
env.createFolder(src);
52+
src = env.getPackageFragmentRootPath(prj, "src");
5453
env.setClasspath(prj, new IClasspathEntry[] {
5554
JavaCore.newSourceEntry(src),
5655
GroovyRuntime.newGroovyClasspathContainerEntry(false, false, null),

base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/builder/BuilderTestSuite.java

+16-3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.eclipse.core.runtime.FileLocator;
3737
import org.eclipse.core.runtime.IPath;
3838
import org.eclipse.core.runtime.Platform;
39+
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
3940
import org.eclipse.jdt.core.IAccessRule;
4041
import org.eclipse.jdt.core.IClasspathAttribute;
4142
import org.eclipse.jdt.core.IClasspathEntry;
@@ -161,7 +162,6 @@ protected final void incrementalBuild(IPath projectPath) {
161162
}
162163
}
163164

164-
@SuppressWarnings("cast")
165165
protected void executeClass(IPath projectPath, String className, String expectingOutput, String expectedError) {
166166
List<String> classpath = new ArrayList<>();
167167
IPath workspacePath = env.getWorkspaceRootPath();
@@ -315,9 +315,9 @@ public IPath addProject(String projectName) {
315315
public IPath addProject(String projectName, String compliance) {
316316
try {
317317
IPath projectPath = super.addProject(projectName, compliance);
318+
removePackageFragmentRoot(projectPath, "");
319+
addPackageFragmentRoot(projectPath, "src");
318320

319-
new ProjectScope(getProject(projectName)).getNode(JavaRuntime.ID_PLUGIN)
320-
.put(JavaRuntime.PREF_COMPILER_COMPLIANCE_DOES_NOT_MATCH_JRE, JavaCore.IGNORE);
321321
IClasspathAttribute[] attributes;
322322
if (JavaCore.compareJavaVersions(compliance, "9") < 0) {
323323
attributes = new IClasspathAttribute[0];
@@ -327,6 +327,9 @@ public IPath addProject(String projectName, String compliance) {
327327
addEntry(projectPath, JavaCore.newContainerEntry(JavaRuntime.newDefaultJREContainerPath(), new IAccessRule[0], attributes, false));
328328

329329
addGroovyNature(projectName);
330+
IProject project = getProject(projectName);
331+
setPreference(project, "org.codehaus.groovy.eclipse.dsl", "org.codehaus.groovy.eclipse.dsl.disabled", "true");
332+
setPreference(project, JavaRuntime.ID_PLUGIN, JavaRuntime.PREF_COMPILER_COMPLIANCE_DOES_NOT_MATCH_JRE, "ignore");
330333

331334
return projectPath;
332335
} catch (JavaModelException e) {
@@ -462,6 +465,16 @@ public IPath addGroovyClassExtension(IPath packageFragmentRootPath, String packa
462465
return addGroovyClassExtension(packageFragmentRootPath, className, contents, fileExtension);
463466
}
464467

468+
public void setPreference(IProject project, String node, String key, String val) {
469+
IEclipsePreferences prefs = new ProjectScope(project).getNode(node);
470+
prefs.put(key, val);
471+
try {
472+
prefs.flush();
473+
} catch (org.osgi.service.prefs.BackingStoreException e) {
474+
throw new RuntimeException(e);
475+
}
476+
}
477+
465478
public <U extends ICompilationUnit> U getUnit(IPath path) {
466479
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
467480
@SuppressWarnings("unchecked")

base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/builder/FullProjectTests.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ private static void assertContainsProblem(Set<IProblem> problems, String expecte
5858
private IPath[] createGroovyProject() throws Exception {
5959
IPath prj = env.addProject("Project");
6060
env.addGroovyJars(prj);
61-
env.setOutputFolder(prj, "bin");
62-
env.removePackageFragmentRoot(prj, "");
63-
return new IPath[] {prj, env.addPackageFragmentRoot(prj, "src")};
61+
return new IPath[] {prj, env.getPackageFragmentRootPath(prj, "src")};
6462
}
6563

6664
//--------------------------------------------------------------------------

base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/builder/STCScriptsTests.java

-4
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,8 @@ private IPath createGenericProject() throws Exception {
4141
return env.getProject("Project").getFullPath();
4242
}
4343
IPath projectPath = env.addProject("Project");
44-
// remove old package fragment root so that names don't collide
45-
env.removePackageFragmentRoot(projectPath, "");
4644
env.addGroovyJars(projectPath);
4745
fullBuild(projectPath);
48-
env.addPackageFragmentRoot(projectPath, "src");
49-
env.setOutputFolder(projectPath, "bin");
5046
return projectPath;
5147
}
5248

base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/builder/ScriptFolderTests.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2019 the original author or authors.
2+
* Copyright 2009-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -409,10 +409,7 @@ private CompilationUnit createScriptInGroovyProject(String name, String contents
409409
IPath projectPath = env.addProject("Project");
410410
env.addGroovyJars(projectPath);
411411

412-
// remove old package fragment root so that names don't collide
413-
env.removePackageFragmentRoot(projectPath, "");
414412
env.addPackageFragmentRoot(projectPath, "scripts");
415-
env.setOutputFolder(projectPath, "bin");
416413
IProject project = env.getProject("Project");
417414
IPath path;
418415
if (isGroovy) {

base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/locations/SourceLocationsTests.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,9 @@ private ICompilationUnit createCompUnit(String pack, String name, String text) t
282282
private IPath createGenericProject() throws Exception {
283283
IPath projectPath = env.addProject("Project");
284284
env.addGroovyJars(projectPath);
285-
env.removePackageFragmentRoot(projectPath, "");
286-
IPath root = env.addPackageFragmentRoot(projectPath, "src");
287-
env.setOutputFolder(projectPath, "bin");
288285
fullBuild(projectPath);
289-
return root;
286+
287+
return env.getPackageFragmentRootPath(projectPath, "src");
290288
}
291289

292290
//--------------------------------------------------------------------------

base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/model/ASTTransformsTests.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2019 the original author or authors.
2+
* Copyright 2009-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,11 +38,6 @@ public void setUp() throws Exception {
3838
IPath projectPath = env.addProject("Project");
3939
env.addGroovyJars(projectPath);
4040
fullBuild(projectPath);
41-
42-
// remove old package fragment root so that names don't collide
43-
env.removePackageFragmentRoot(projectPath, "");
44-
env.addPackageFragmentRoot(projectPath, "src");
45-
env.setOutputFolder(projectPath, "bin");
4641
}
4742

4843
@Test

base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/model/GroovyCompilationUnitTests.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2019 the original author or authors.
2+
* Copyright 2009-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -55,11 +55,7 @@ public void testCreateJavaCompilationUnit() throws Exception {
5555
IPath projectPath = env.addProject("Project");
5656
fullBuild(projectPath);
5757

58-
// remove old package fragment root so that names don't collide
59-
env.removePackageFragmentRoot(projectPath, "");
60-
61-
IPath root = env.addPackageFragmentRoot(projectPath, "src");
62-
env.setOutputFolder(projectPath, "bin");
58+
IPath root = env.getPackageFragmentRootPath(projectPath, "src");
6359

6460
IPath path = env.addClass(root, "p1", "Hello",
6561
"package p1;\n" +

base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/model/GroovyContentTypeTests.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2019 the original author or authors.
2+
* Copyright 2009-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -172,10 +172,8 @@ private void checkJavaProject(IProject proj) throws Exception {
172172

173173
private static IProject createProject() throws Exception {
174174
IPath projectPath = env.addProject("Project");
175-
env.removePackageFragmentRoot(projectPath, "");
176175

177-
IPath root = env.addPackageFragmentRoot(projectPath, "src");
178-
env.setOutputFolder(projectPath, "bin");
176+
IPath root = env.getPackageFragmentRootPath(projectPath, "src");
179177

180178
env.addClass(root, "p1", "HelloJava",
181179
"package p1;\n" +

base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/model/GroovyTypeRootTestSuite.java

+3-12
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ protected final IFile createProject(boolean isGroovy) throws Exception {
2828
env.removeGroovyNature("Project");
2929
}
3030

31-
// remove old package fragment root so that names don't collide
32-
env.removePackageFragmentRoot(projectPath, "");
33-
34-
IPath root = env.addPackageFragmentRoot(projectPath, "src");
35-
env.setOutputFolder(projectPath, "bin");
31+
IPath root = env.getPackageFragmentRootPath(projectPath, "src");
3632

3733
if (isGroovy) {
3834
env.addGroovyJars(projectPath);
@@ -66,14 +62,9 @@ protected final IFile createSimpleJavaProject() throws Exception {
6662
protected final IPath createEmptyGroovyProject() throws Exception {
6763
IPath projectPath = env.addProject("Project");
6864
env.addGroovyJars(projectPath);
69-
70-
// remove old package fragment root so that names don't collide
71-
env.removePackageFragmentRoot(projectPath, "");
72-
IPath root = env.addPackageFragmentRoot(projectPath, "src");
73-
74-
env.setOutputFolder(projectPath, "bin");
7565
fullBuild(projectPath);
76-
return root;
66+
67+
return env.getPackageFragmentRootPath(projectPath, "src");
7768
}
7869

7970
protected final IPath createAnnotationGroovyProject() throws Exception {

base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/model/MoveRenameCopyTests.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,11 @@ private void checkExist(GroovyCompilationUnit unit) {
126126

127127
private GroovyCompilationUnit createSimpleGroovyProject(String pack, String contents) throws Exception {
128128
IPath projectPath = env.addProject("Project");
129-
env.addGroovyNature("Project");
130129
env.addGroovyJars(projectPath);
131130
fullBuild(projectPath);
132131
expectingNoProblems();
133-
// remove old package fragment root so that names don't collide
134-
env.removePackageFragmentRoot(projectPath, "");
135132

136-
IPath root = env.addPackageFragmentRoot(projectPath, "src");
137-
env.setOutputFolder(projectPath, "bin");
133+
IPath root = env.getPackageFragmentRootPath(projectPath, "src");
138134
IPath path = env.addGroovyClass(root, "", "Groovy", contents);
139135
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
140136
return (GroovyCompilationUnit) JavaCore.createCompilationUnitFrom(file);

base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/search/SearchTestSuite.java

-6
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,7 @@ public final void setUpSearchTestCase() throws Exception {
7575

7676
protected IProject createGroovyProject() throws Exception {
7777
IPath projectPath = env.addProject("Project");
78-
env.addGroovyNature("Project");
7978
env.addGroovyJars(projectPath);
80-
81-
// remove old package fragment root so that names don't collide
82-
env.removePackageFragmentRoot(projectPath, "");
83-
env.addPackageFragmentRoot(projectPath, "src");
84-
env.setOutputFolder(projectPath, "bin");
8579
env.fullBuild(projectPath);
8680

8781
return env.getProject("Project");

ide-test/org.codehaus.groovy.alltests/GDT Face tests.launch

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog" />
3434
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.codehaus.groovy.alltests" />
3535
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider" />
36-
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea -Xmx1g -Dgroovy.antlr4=false -Dgroovy.enable.parameterized.type.cache=false" />
36+
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea -Xmx1536m -Dgroovy.antlr4=false -Dgroovy.enable.parameterized.type.cache=false" />
3737
<stringAttribute key="pde.version" value="3.3" />
3838
<stringAttribute key="product" value="org.eclipse.platform.ide" />
3939
<booleanAttribute key="run_in_ui_thread" value="true" />

0 commit comments

Comments
 (0)