Skip to content

Commit fdfbd17

Browse files
committed
Switch all IT build hook scripts from BeanShell to Groovy
Also make them more idiomatic: * remove unnecessary semicolons * replace FileUtils.fileRead by File::text * replace some getter calls with property read as well as remove use of JarFile::entries, replaced with either JarFile::getEntry (at the expense of possibly reading the entries several types) or JarFile::stream.
1 parent a5621d8 commit fdfbd17

File tree

8 files changed

+181
-262
lines changed

8 files changed

+181
-262
lines changed

src/it/e2e/postbuild.groovy

Lines changed: 35 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,60 @@
1-
import java.io.*;
2-
import java.util.*;
3-
import java.util.jar.*;
4-
import org.codehaus.plexus.util.*;
1+
import java.util.jar.JarFile
52

63
try {
7-
File modelModuleFile = new File(basedir, "e2e-model-gwt/target/classes/it/test/model/TestModel.gwt.xml");
4+
File modelModuleFile = new File(basedir, "e2e-model-gwt/target/classes/it/test/model/TestModel.gwt.xml")
85
if (!modelModuleFile.isFile()) {
9-
System.err.println("it/test/model/TestModel.gwt.xml module is missing or is not a file.");
10-
return false;
6+
System.err.println("it/test/model/TestModel.gwt.xml module is missing or is not a file.")
7+
return false
118
}
12-
String modelModule = FileUtils.fileRead(modelModuleFile);
13-
if (modelModule.contains("<super-source")) {
14-
System.err.println("Model GWT module has generated sources whereas it contained sources.");
15-
return false;
9+
if (modelModuleFile.text.contains("<super-source")) {
10+
System.err.println("Model GWT module has generated sources whereas it contained sources.")
11+
return false
1612
}
1713

18-
File sharedModuleFile = new File(basedir, "e2e-shared-gwt/target/classes/it/test/E2EShared.gwt.xml");
14+
File sharedModuleFile = new File(basedir, "e2e-shared-gwt/target/classes/it/test/E2EShared.gwt.xml")
1915
if (!sharedModuleFile.isFile()) {
20-
System.err.println("it/test/E2EShared.gwt.xml module is missing or is not a file.");
21-
return false;
16+
System.err.println("it/test/E2EShared.gwt.xml module is missing or is not a file.")
17+
return false
2218
}
23-
String sharedModule = FileUtils.fileRead(sharedModuleFile);
24-
if (!sharedModule.contains("it.test.model.TestModel")) {
25-
System.err.println("Shared GWT module doesn't inherit it.test.model.TestModel.");
26-
return false;
19+
if (!sharedModuleFile.text.contains("it.test.model.TestModel")) {
20+
System.err.println("Shared GWT module doesn't inherit it.test.model.TestModel.")
21+
return false
2722
}
2823

29-
File clientModuleFile = new File(basedir, "e2e-client/target/classes/it/test/E2E.gwt.xml");
24+
File clientModuleFile = new File(basedir, "e2e-client/target/classes/it/test/E2E.gwt.xml")
3025
if (!clientModuleFile.isFile()) {
31-
System.err.println("it/test/E2E.gwt.xml module is missing or is not a file.");
32-
return false;
26+
System.err.println("it/test/E2E.gwt.xml module is missing or is not a file.")
27+
return false
3328
}
34-
String clientModule = FileUtils.fileRead(clientModuleFile);
35-
if (!clientModule.contains("it.test.E2EShared")) {
36-
System.err.println("Client GWT module doesn't inherit it.test.E2EShared.");
37-
return false;
29+
if (!clientModuleFile.text.contains("it.test.E2EShared")) {
30+
System.err.println("Client GWT module doesn't inherit it.test.E2EShared.")
31+
return false
3832
}
3933

40-
File target = new File(basedir, "e2e-server/target");
34+
File target = new File(basedir, "e2e-server/target")
4135
if (!target.exists() || !target.isDirectory()) {
42-
System.err.println("target file is missing or not a directory.");
43-
return false;
36+
System.err.println("target file is missing or not a directory.")
37+
return false
4438
}
4539

46-
File war = new File(target, "e2e-server-1.0.war");
40+
File war = new File(target, "e2e-server-1.0.war")
4741
if (!war.exists() || war.isDirectory()) {
48-
System.err.println("war file is missing or a directory.");
49-
return false;
42+
System.err.println("war file is missing or a directory.")
43+
return false
5044
}
5145

52-
JarFile jarFile = new JarFile(war);
53-
Enumeration entries = jarFile.entries();
54-
55-
boolean seenNocacheJs = false;
56-
boolean seenGwtLib = false;
57-
while (entries.hasMoreElements()) {
58-
JarEntry entry = entries.nextElement();
59-
String name = entry.getName();
60-
if (name.equals("e2e/e2e.nocache.js")) {
61-
seenNocacheJs = true;
62-
} else if (name.startsWith("WEB-INF/lib/e2e-") && name.endsWith("-gwt.jar")) {
63-
seenGwtLib = true;
64-
}
65-
}
66-
if (!seenNocacheJs) {
67-
System.err.println("e2e/e2e.nocache.js missing from final war");
68-
return false;
46+
JarFile jarFile = new JarFile(war)
47+
if (jarFile.getEntry("e2e/e2e.nocache.js") == null) {
48+
System.err.println("e2e/e2e.nocache.js missing from final war")
49+
return false
6950
}
70-
if (seenGwtLib) {
71-
System.err.println("gwt-lib erroneously packaged into final war");
72-
return false;
51+
if (jarFile.stream().anyMatch { it.name.startsWith("WEB-INF/lib/e2e-") && it.name.endsWith("-gwt.jar") }) {
52+
System.err.println("gwt-lib erroneously packaged into final war")
53+
return false
7354
}
7455
} catch (Throwable t) {
75-
t.printStackTrace();
76-
return false;
56+
t.printStackTrace()
57+
return false
7758
}
7859

79-
return true;
60+
return true

src/it/forceCompilation/postbuild.bsh

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
try {
2+
File buildLogFile = new File(basedir, "build.log")
3+
if (!buildLogFile.exists() || buildLogFile.isDirectory()) {
4+
System.err.println("build.log file is missing or a directory.")
5+
return false
6+
}
7+
8+
String buildLog = buildLogFile.text
9+
int first = buildLog.indexOf("Compiling module it.test.Test")
10+
int last = buildLog.lastIndexOf("Compiling module it.test.Test")
11+
if (first == last) {
12+
System.err.println("build.log talks only once about compiling GWT module")
13+
return false
14+
}
15+
16+
if (!new File(basedir, "target/gwt-application-1.0/test/test.nocache.js").exists()) {
17+
System.err.println("GWT module has not been compiled.")
18+
return false
19+
}
20+
21+
} catch (Throwable t) {
22+
t.printStackTrace()
23+
return false
24+
}
25+
26+
return true

src/it/gwt-app/postbuild.groovy

Lines changed: 31 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,56 @@
1-
import java.io.*;
2-
import java.util.*;
3-
import java.util.jar.*;
4-
import org.codehaus.plexus.util.*;
1+
import java.util.jar.JarFile
52

63
try {
7-
File target = new File(basedir, "target");
4+
File target = new File(basedir, "target")
85
if (!target.isDirectory()) {
9-
System.err.println("target file is missing or not a directory.");
10-
return false;
6+
System.err.println("target file is missing or not a directory.")
7+
return false
118
}
129

13-
File moduleFile = new File(target, "classes/it/test/Test.gwt.xml");
10+
File moduleFile = new File(target, "classes/it/test/Test.gwt.xml")
1411
if (!moduleFile.isFile()) {
15-
System.err.println("it/test/Test.gwt.xml module is missing or is not a file.");
16-
return false;
12+
System.err.println("it/test/Test.gwt.xml module is missing or is not a file.")
13+
return false
1714
}
18-
String module = FileUtils.fileRead(moduleFile);
15+
String module = moduleFile.text
1916
if (module.contains("shared")) {
20-
System.err.println("GWT module has generated sources whereas it contained sources.");
21-
return false;
17+
System.err.println("GWT module has generated sources whereas it contained sources.")
18+
return false
2219
}
2320

24-
File war = new File(target, "gwt-application-1.0.war");
21+
File war = new File(target, "gwt-application-1.0.war")
2522
if (!war.isFile()) {
26-
System.err.println("war file is missing or a not a file.");
27-
return false;
23+
System.err.println("war file is missing or a not a file.")
24+
return false
2825
}
2926

30-
JarFile jarFile = new JarFile(war);
31-
Enumeration entries = jarFile.entries();
32-
33-
boolean seenNocacheJs = false;
34-
boolean seenWebInf = false;
35-
while (entries.hasMoreElements()) {
36-
JarEntry entry = entries.nextElement();
37-
String name = entry.getName();
38-
if (name.equals("test/test.nocache.js")) {
39-
seenNocacheJs = true;
40-
} else if (name.startsWith("WEB-INF/")) {
41-
seenWebInf = true;
42-
}
43-
}
44-
if (!seenNocacheJs) {
45-
System.err.println("test/test.nocache.js missing from war");
46-
return false;
27+
JarFile jarFile = new JarFile(war)
28+
if (jarFile.getEntry("test/test.nocache.js") == null) {
29+
System.err.println("test/test.nocache.js missing from war")
30+
return false
4731
}
48-
if (seenWebInf) {
49-
System.err.println("war file erroneously contains a WEB-INF/");
50-
return false;
32+
if (jarFile.stream().anyMatch { it.name.startsWith("WEB-INF/") }) {
33+
System.err.println("war file erroneously contains a WEB-INF/")
34+
return false
5135
}
5236

53-
File buildLogFile = new File(basedir, "build.log");
37+
File buildLogFile = new File(basedir, "build.log")
5438
if (!buildLogFile.exists() || buildLogFile.isDirectory()) {
55-
System.err.println("build.log file is missing or a directory.");
56-
return false;
39+
System.err.println("build.log file is missing or a directory.")
40+
return false
5741
}
58-
String buildLog = FileUtils.fileRead(buildLogFile);
42+
String buildLog = buildLogFile.text
5943
if (buildLog.contains("build is platform dependent")) {
60-
System.err.println("Encoding is not set.");
61-
return false;
44+
System.err.println("Encoding is not set.")
45+
return false
6246
}
6347
if (!buildLog.contains("Tests run: 3, Failures: 0, Errors: 0, Skipped: 0")) {
64-
System.err.println("build.log does not talk about running tests");
65-
return false;
48+
System.err.println("build.log does not talk about running tests")
49+
return false
6650
}
6751
} catch (Throwable t) {
68-
t.printStackTrace();
69-
return false;
52+
t.printStackTrace()
53+
return false
7054
}
7155

72-
return true;
56+
return true

0 commit comments

Comments
 (0)