Class TeaVM
- All Implemented Interfaces:
ServiceRepository
,TeaVMHost
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();
-
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(DependencyListener listener) void
add
(ClassHolderTransformer transformer) void
add
(MethodReference methodRef, BootstrapMethodSubstitutor substitutor) void
add
(MethodReference methodRef, DependencyPlugin dependencyPlugin) void
addVirtualMethods
(Predicate<MethodReference> virtualMethods) void
void
build
(BuildTarget buildTarget, String outputName) Does actual build.void
entryPoint
(String className) void
entryPoint
(String className, String name) Gets class loaded that is used by TeaVM.<T extends TeaVMHostExtension>
TgetExtension
(Class<T> extensionType) String[]
Gets configuration properties.<T> T
getService
(Class<T> type) void
Finds and install all plugins in the current class path.link
(DependencyAnalyzer dependency) void
preserveType
(String className) <T> void
registerService
(Class<T> type, T instance) void
setCacheStatus
(CacheStatus cacheStatus) void
setLastKnownClasses
(int lastKnownClasses) void
setOptimizationLevel
(TeaVMOptimizationLevel optimizationLevel) void
setProgramCache
(ProgramCache programCache) void
setProgressListener
(TeaVMProgressListener progressListener) void
setProperties
(Properties properties) Specifies configuration properties for TeaVM and its plugins.boolean
-
Method Details
-
addVirtualMethods
-
add
-
add
-
add
-
add
-
getClassLoader
Description copied from interface:TeaVMHost
Gets class loaded that is used by TeaVM. This class loader is usually specified byTeaVMBuilder.setClassLoader(ClassLoader)
- Specified by:
getClassLoader
in interfaceTeaVMHost
- Returns:
- class loader that can be used by plugins.
-
setProperties
Specifies configuration properties for TeaVM and its plugins. You should call this method before installing any plugins or interceptors.- Parameters:
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.
-
getProperties
Description copied from interface:TeaVMHost
Gets configuration properties. These properties are usually specified bysetProperties(Properties)
.- Specified by:
getProperties
in interfaceTeaVMHost
- Returns:
- a copy of all of the VM properties. Any further changes to returned objects will not be visible to VM.
-
getProgramCache
-
setProgramCache
-
setCacheStatus
-
getOptimizationLevel
-
setOptimizationLevel
-
getProgressListener
-
setProgressListener
-
wasCancelled
public boolean wasCancelled() -
getProblemProvider
-
getPlatformTags
- Specified by:
getPlatformTags
in interfaceTeaVMHost
-
entryPoint
-
entryPoint
-
preserveType
-
getDependencyClassSource
-
getClasses
-
getMethods
-
getDependencyInfo
-
getWrittenClasses
-
setLastKnownClasses
public void setLastKnownClasses(int lastKnownClasses) -
build
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.- Parameters:
buildTarget
- where to generate additional resources. Can be null, but if there are plugins or interceptors that generate additional resources, the build process will fail.outputName
- name of output file within buildTarget. Should not be null.
-
link
-
build
-
installPlugins
public 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 allMETA-INF/services/org.teavm.vm.spi.TeaVMPlugin
resources and obtains all implementation classes that are enumerated there. -
getService
- Specified by:
getService
in interfaceServiceRepository
-
registerService
- Specified by:
registerService
in interfaceTeaVMHost
-
getExtension
- Specified by:
getExtension
in interfaceTeaVMHost
-