vm.setProgressListener(progressListener);
}
vm.setMinifying(minifying);
vm.setBytecodeLogging(bytecodeLogging);
vm.setProperties(properties);
DebugInformationBuilder debugEmitter = debugInformationGenerated || sourceMapsFileGenerated ?
new DebugInformationBuilder() : null;
vm.setDebugEmitter(debugEmitter);
vm.setIncremental(incremental);
if (incremental) {
vm.setAstCache(astCache);
vm.setProgramCache(programCache);
}
vm.installPlugins();
for (ClassHolderTransformer transformer : transformers) {
vm.add(transformer);
}
if (mainClass != null) {
MethodDescriptor mainMethodDesc = new MethodDescriptor("main", String[].class, void.class);
vm.entryPoint("main", new MethodReference(mainClass, mainMethodDesc))
.withValue(1, "java.lang.String");
}
for (ClassAlias alias : classAliases) {
vm.exportType(alias.getAlias(), alias.getClassName());
}
for (MethodAlias methodAlias : methodAliases) {
MethodReference ref = new MethodReference(methodAlias.getClassName(), methodAlias.getMethodName(),
MethodDescriptor.parseSignature(methodAlias.getDescriptor()));
TeaVMEntryPoint entryPoint = vm.entryPoint(methodAlias.getAlias(), ref);
if (methodAlias.getTypes() != null) {
for (int i = 0; i < methodAlias.getTypes().length; ++i) {
String types = methodAlias.getTypes()[i];
if (types != null) {
for (String type : types.split(" +")) {
type = type.trim();
if (!type.isEmpty()) {
entryPoint.withValue(i, type);
}
}
}
}
}
}
targetDirectory.mkdirs();
try (Writer writer = new OutputStreamWriter(new BufferedOutputStream(
new FileOutputStream(new File(targetDirectory, targetFileName))), "UTF-8")) {
if (runtime == RuntimeCopyOperation.MERGED) {
vm.add(runtimeInjector);
}
vm.build(writer, new DirectoryBuildTarget(targetDirectory));
if (vm.wasCancelled()) {
log.info("Build cancelled");
cancelled = true;
return;
}
if (vm.hasMissingItems()) {
log.info("Missing items found");
return;
}
log.info("JavaScript file successfully built");
if (debugInformationGenerated) {
DebugInformation debugInfo = debugEmitter.getDebugInformation();
try (OutputStream debugInfoOut = new FileOutputStream(new File(targetDirectory,
targetFileName + ".teavmdbg"))) {
debugInfo.write(debugInfoOut);
}
log.info("Debug information successfully written");
}
if (sourceMapsFileGenerated) {
DebugInformation debugInfo = debugEmitter.getDebugInformation();
String sourceMapsFileName = targetFileName + ".map";
writer.append("\n//# sourceMappingURL=").append(sourceMapsFileName);
try (Writer sourceMapsOut = new OutputStreamWriter(new FileOutputStream(
new File(targetDirectory, sourceMapsFileName)), "UTF-8")) {
debugInfo.writeAsSourceMaps(sourceMapsOut, "src", targetFileName);