61 if (moduleName != null) { |
61 if (moduleName != null) { |
62 Path moduleInfoFile = srcDir.resolve("module-info.java"); |
62 Path moduleInfoFile = srcDir.resolve("module-info.java"); |
63 TKit.createTextFile(moduleInfoFile, List.of( |
63 TKit.createTextFile(moduleInfoFile, List.of( |
64 String.format("module %s {", moduleName), |
64 String.format("module %s {", moduleName), |
65 String.format(" exports %s;", packageName), |
65 String.format(" exports %s;", packageName), |
|
66 " requires java.desktop;", |
66 "}" |
67 "}" |
67 )); |
68 )); |
68 jarBuilder.addSourceFile(moduleInfoFile); |
69 jarBuilder.addSourceFile(moduleInfoFile); |
69 jarBuilder.setModuleVersion(appDesc.moduleVersion()); |
70 jarBuilder.setModuleVersion(appDesc.moduleVersion()); |
70 } |
71 } |
71 |
72 |
72 // Add package directive and replace class name in java source file. |
73 // Add package directive and replace class name in java source file. |
73 // Works with simple test Hello.java. |
74 // Works with simple test Hello.java. |
74 // Don't expect too much from these regexps! |
75 // Don't expect too much from these regexps! |
75 Pattern classDeclaration = Pattern.compile("(^.*\\bclass\\s+)Hello(.*$)"); |
76 Pattern classNameRegex = Pattern.compile("\\bHello\\b"); |
|
77 Pattern classDeclaration = Pattern.compile( |
|
78 "(^.*\\bclass\\s+)\\bHello\\b(.*$)"); |
76 Pattern importDirective = Pattern.compile( |
79 Pattern importDirective = Pattern.compile( |
77 "(?<=import (?:static )?+)[^;]+"); |
80 "(?<=import (?:static )?+)[^;]+"); |
78 AtomicBoolean classDeclared = new AtomicBoolean(); |
81 AtomicBoolean classDeclared = new AtomicBoolean(); |
79 AtomicBoolean packageInserted = new AtomicBoolean(packageName == null); |
82 AtomicBoolean packageInserted = new AtomicBoolean(packageName == null); |
80 |
83 |
83 return String.format("package %s;%s%s", packageName, |
86 return String.format("package %s;%s%s", packageName, |
84 System.lineSeparator(), line); |
87 System.lineSeparator(), line); |
85 }); |
88 }); |
86 |
89 |
87 Files.write(srcFile, Files.readAllLines(HELLO_JAVA).stream().map(line -> { |
90 Files.write(srcFile, Files.readAllLines(HELLO_JAVA).stream().map(line -> { |
|
91 Matcher m; |
88 if (classDeclared.getPlain()) { |
92 if (classDeclared.getPlain()) { |
|
93 if ((m = classNameRegex.matcher(line)).find()) { |
|
94 line = m.replaceAll(className); |
|
95 } |
89 return line; |
96 return line; |
90 } |
97 } |
91 |
98 |
92 Matcher m; |
|
93 if (!packageInserted.getPlain() && importDirective.matcher(line).find()) { |
99 if (!packageInserted.getPlain() && importDirective.matcher(line).find()) { |
94 line = packageInserter.apply(line); |
100 line = packageInserter.apply(line); |
95 } else if ((m = classDeclaration.matcher(line)).find()) { |
101 } else if ((m = classDeclaration.matcher(line)).find()) { |
96 classDeclared.setPlain(true); |
102 classDeclared.setPlain(true); |
97 line = m.group(1) + className + m.group(2); |
103 line = m.group(1) + className + m.group(2); |
212 Path outputFile = TKit.workDir().resolve(OUTPUT_FILENAME); |
218 Path outputFile = TKit.workDir().resolve(OUTPUT_FILENAME); |
213 ThrowingFunction.toFunction(Files::deleteIfExists).apply(outputFile); |
219 ThrowingFunction.toFunction(Files::deleteIfExists).apply(outputFile); |
214 new Executor() |
220 new Executor() |
215 .setDirectory(outputFile.getParent()) |
221 .setDirectory(outputFile.getParent()) |
216 .setExecutable(helloAppLauncher) |
222 .setExecutable(helloAppLauncher) |
|
223 .dumpOutput() |
217 .execute() |
224 .execute() |
218 .assertExitCodeIsZero(); |
225 .assertExitCodeIsZero(); |
219 |
226 |
220 verifyOutputFile(outputFile, defaultLauncherArgs); |
227 verifyOutputFile(outputFile, defaultLauncherArgs); |
221 } |
228 } |