public class TeaVM extends Object implements TeaVMHost, ServiceRepository
TeaVM itself. This class builds a JavaScript VM that runs a certain code.
Here you can specify entry points into your code (such like main method).
TeaVM guarantees that all required classes and methods will be provided by
built VM.
Here is a typical code snippet:
ClassLoader classLoader = ...; // obtain ClassLoader somewhere
ClassHolderSource classSource = new ClasspathClassHolderSource(classLoader);
TeaVM vm = new TeaVMBuilder()
.setClassLoader(classLoader)
.setClassSource(classSource)
.build();
vm.setMinifying(false); // optionally disable obfuscation
vm.installPlugins(); // install all default plugins
// that are found in a classpath
vm.entryPoint("main", new MethodReference(
"fully.qualified.ClassName", "main",
ValueType.array(ValueType.object("java.lang.String")),
ValueType.VOID));
StringBuilder sb = new StringBuilder();
vm.build(sb, null);
vm.checkForMissingItems();
| Modifier and Type | Method and Description |
|---|---|
void |
add(ClassHolderTransformer transformer) |
void |
add(DependencyListener listener) |
void |
add(MethodReference methodRef,
Generator generator) |
void |
add(MethodReference methodRef,
Injector injector) |
void |
add(RendererListener listener) |
void |
build(Appendable writer,
BuildTarget target)
Does actual build.
|
void |
build(File dir,
String fileName) |
TeaVMEntryPoint |
entryPoint(MethodReference ref)
Adds an entry point.
|
TeaVMEntryPoint |
entryPoint(String name,
MethodReference ref)
Adds an entry point.
|
void |
exportType(String name,
String className) |
MethodNodeCache |
getAstCache() |
Collection<String> |
getClasses() |
ClassLoader |
getClassLoader()
Gets class loaded that is used by TeaVM.
|
ClassReaderSource |
getClassSource()
Gets a
ClassReaderSource which is used by this TeaVM instance. |
DebugInformationEmitter |
getDebugEmitter() |
ClassReaderSource |
getDependencyClassSource()
Gets a
ClassReaderSource which is similar to that of getClassSource(),
except that it also contains classes with applied transformations together with
classes, generated via DependencyChecker.submitClass(ClassHolder). |
DependencyInfo |
getDependencyInfo() |
Collection<MethodReference> |
getMethods() |
ProblemProvider |
getProblemProvider() |
ProgramCache |
getProgramCache() |
TeaVMProgressListener |
getProgressListener() |
Properties |
getProperties()
Gets configuration properties.
|
<T> T |
getService(Class<T> type) |
ListableClassReaderSource |
getWrittenClasses() |
void |
installPlugins()
Finds and install all plugins in the current class path.
|
boolean |
isBytecodeLogging() |
boolean |
isIncremental() |
boolean |
isMinifying()
Reports whether this TeaVM instance uses obfuscation when generating the JavaScript code.
|
ListableClassHolderSource |
link(DependencyInfo dependency) |
TeaVMEntryPoint |
linkMethod(MethodReference ref) |
void |
linkType(String className) |
<T> void |
registerService(Class<T> type,
T instance) |
void |
setAstCache(MethodNodeCache methodAstCache) |
void |
setBytecodeLogging(boolean bytecodeLogging) |
void |
setDebugEmitter(DebugInformationEmitter debugEmitter) |
void |
setIncremental(boolean incremental) |
void |
setMinifying(boolean minifying)
Specifies whether this TeaVM instance uses obfuscation when generating the JavaScript code.
|
void |
setProgramCache(ProgramCache programCache) |
void |
setProgressListener(TeaVMProgressListener progressListener) |
void |
setProperties(Properties properties)
Specifies configuration properties for TeaVM and its plugins.
|
boolean |
wasCancelled() |
public void add(DependencyListener listener)
public void add(ClassHolderTransformer transformer)
public void add(MethodReference methodRef, Generator generator)
public void add(MethodReference methodRef, Injector injector)
public void add(RendererListener listener)
public ClassLoader getClassLoader()
TeaVMHostTeaVMBuilder.setClassLoader(ClassLoader)getClassLoader in interface TeaVMHostpublic boolean isMinifying()
setMinifying(boolean)public void setMinifying(boolean minifying)
minifying - whether TeaVM should obfuscate code.isMinifying()public boolean isBytecodeLogging()
public void setBytecodeLogging(boolean bytecodeLogging)
public void setProperties(Properties properties)
properties - configuration properties to set. These properties will be copied into this VM instance,
so VM won't see any further changes in this object.public Properties getProperties()
TeaVMHostsetProperties(Properties).getProperties in interface TeaVMHostpublic MethodNodeCache getAstCache()
public void setAstCache(MethodNodeCache methodAstCache)
public ProgramCache getProgramCache()
public void setProgramCache(ProgramCache programCache)
public boolean isIncremental()
public void setIncremental(boolean incremental)
public TeaVMProgressListener getProgressListener()
public void setProgressListener(TeaVMProgressListener progressListener)
public boolean wasCancelled()
public ProblemProvider getProblemProvider()
public TeaVMEntryPoint entryPoint(String name, MethodReference ref)
Adds an entry point. TeaVM guarantees, that all methods that are required by the entry point
will be available at run-time in browser. Also you need to specify for each parameter of entry point
which actual types will be passed here by calling TeaVMEntryPoint.withValue(int, String).
It is highly recommended to read explanation on TeaVMEntryPoint class documentation.
You should call this method after installing all plugins and interceptors, but before doing the actual build.
name - the name under which this entry point will be available for JavaScript code.ref - a full reference to the method which is an entry point.public TeaVMEntryPoint entryPoint(MethodReference ref)
Adds an entry point. TeaVM guarantees, that all methods that are required by the entry point
will be available at run-time in browser. Also you need to specify for each parameter of entry point
which actual types will be passed here by calling TeaVMEntryPoint.withValue(int, String).
It is highly recommended to read explanation on TeaVMEntryPoint class documentation.
You should call this method after installing all plugins and interceptors, but before doing the actual build.
ref - a full reference to the method which is an entry point.public TeaVMEntryPoint linkMethod(MethodReference ref)
public void linkType(String className)
public ClassReaderSource getClassSource()
ClassReaderSource which is used by this TeaVM instance. It is exactly what was
passed to TeaVMBuilder.setClassSource(ClassHolderSource).public ClassReaderSource getDependencyClassSource()
ClassReaderSource which is similar to that of getClassSource(),
except that it also contains classes with applied transformations together with
classes, generated via DependencyChecker.submitClass(ClassHolder).public Collection<String> getClasses()
public Collection<MethodReference> getMethods()
public DependencyInfo getDependencyInfo()
public ListableClassReaderSource getWrittenClasses()
public DebugInformationEmitter getDebugEmitter()
public void setDebugEmitter(DebugInformationEmitter debugEmitter)
public void build(Appendable writer, BuildTarget target) throws RenderingException
Does actual build. Call this method after TeaVM is fully configured and all entry points
are specified. This method may fail if there are items (classes, methods and fields)
that are required by entry points, but weren't found in classpath. In this case no
actual generation happens and no exceptions thrown, but you can further call
getProblemProvider() to learn the build state.
writer - where to generate JavaScript. Should not be null.target - where to generate additional resources. Can be null, but if there are
plugins or inteceptors that generate additional resources, the build process will fail.RenderingException - when something went wrong during rendering phase.public ListableClassHolderSource link(DependencyInfo dependency)
public void build(File dir, String fileName) throws RenderingException
RenderingExceptionpublic void installPlugins()
Finds and install all plugins in the current class path. The standard ServiceLoader
approach is used to find plugins. So this method scans all
META-INF/services/org.teavm.vm.spi.TeaVMPlugin resources and
obtains all implementation classes that are enumerated there.
public <T> T getService(Class<T> type)
getService in interface ServiceRepositorypublic <T> void registerService(Class<T> type, T instance)
registerService in interface TeaVMHostCopyright © 2015. All rights reserved.