Class TeaVM
- java.lang.Object
-
- org.teavm.vm.TeaVM
-
- All Implemented Interfaces:
ServiceRepository,TeaVMHost
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
mainmethod). 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();- Author:
- Alexey Andreev
-
-
Method Summary
-
-
-
Method Detail
-
addVirtualMethods
public void addVirtualMethods(Predicate<MethodReference> virtualMethods)
-
add
public void add(DependencyListener listener)
-
add
public void add(ClassHolderTransformer transformer)
-
add
public void add(MethodReference methodRef, BootstrapMethodSubstitutor substitutor)
-
add
public void add(MethodReference methodRef, DependencyPlugin dependencyPlugin)
-
getClassLoader
public ClassLoader getClassLoader()
Description copied from interface:TeaVMHostGets class loaded that is used by TeaVM. This class loader is usually specified byTeaVMBuilder.setClassLoader(ClassLoader)- Specified by:
getClassLoaderin interfaceTeaVMHost- Returns:
- class loader that can be used by plugins.
-
setProperties
public void setProperties(Properties properties)
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
public Properties getProperties()
Description copied from interface:TeaVMHostGets configuration properties. These properties are usually specified bysetProperties(Properties).- Specified by:
getPropertiesin interfaceTeaVMHost- Returns:
- a copy of all of the VM properties. Any further changes to returned objects will not be visible to VM.
-
getProgramCache
public ProgramCache getProgramCache()
-
setProgramCache
public void setProgramCache(ProgramCache programCache)
-
setCacheStatus
public void setCacheStatus(CacheStatus cacheStatus)
-
getOptimizationLevel
public TeaVMOptimizationLevel getOptimizationLevel()
-
setOptimizationLevel
public void setOptimizationLevel(TeaVMOptimizationLevel optimizationLevel)
-
getProgressListener
public TeaVMProgressListener getProgressListener()
-
setProgressListener
public void setProgressListener(TeaVMProgressListener progressListener)
-
wasCancelled
public boolean wasCancelled()
-
getProblemProvider
public ProblemProvider getProblemProvider()
-
getPlatformTags
public String[] getPlatformTags()
- Specified by:
getPlatformTagsin interfaceTeaVMHost
-
entryPoint
public void entryPoint(String className)
-
preserveType
public void preserveType(String className)
-
getDependencyClassSource
public ClassReaderSource getDependencyClassSource()
-
getClasses
public Collection<String> getClasses()
-
getMethods
public Collection<MethodReference> getMethods()
-
getDependencyInfo
public DependencyInfo getDependencyInfo()
-
getWrittenClasses
public ListableClassReaderSource getWrittenClasses()
-
setLastKnownClasses
public void setLastKnownClasses(int lastKnownClasses)
-
build
public void build(BuildTarget buildTarget, String outputName)
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
public ListableClassHolderSource link(DependencyAnalyzer dependency)
-
installPlugins
public void installPlugins()
Finds and install all plugins in the current class path. The standard
ServiceLoaderapproach is used to find plugins. So this method scans allMETA-INF/services/org.teavm.vm.spi.TeaVMPluginresources and obtains all implementation classes that are enumerated there.
-
getService
public <T> T getService(Class<T> type)
- Specified by:
getServicein interfaceServiceRepository
-
registerService
public <T> void registerService(Class<T> type, T instance)
- Specified by:
registerServicein interfaceTeaVMHost
-
getExtension
public <T extends TeaVMHostExtension> T getExtension(Class<T> extensionType)
- Specified by:
getExtensionin interfaceTeaVMHost
-
-