Class TeaVM
- java.lang.Object
-
- org.teavm.vm.TeaVM
-
- All Implemented Interfaces:
ServiceRepository,TeaVMHost
public class TeaVM extends java.lang.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();
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(DependencyListener listener)voidadd(ClassHolderTransformer transformer)voidadd(MethodReference methodRef, BootstrapMethodSubstitutor substitutor)voidadd(MethodReference methodRef, DependencyPlugin dependencyPlugin)voidaddVirtualMethods(java.util.function.Predicate<MethodReference> virtualMethods)voidbuild(java.io.File dir, java.lang.String fileName)voidbuild(BuildTarget buildTarget, java.lang.String outputName)Does actual build.voidentryPoint(java.lang.String className)voidentryPoint(java.lang.String className, java.lang.String name)java.util.Collection<java.lang.String>getClasses()java.lang.ClassLoadergetClassLoader()Gets class loaded that is used by TeaVM.ClassReaderSourcegetDependencyClassSource()DependencyInfogetDependencyInfo()<T extends TeaVMHostExtension>
TgetExtension(java.lang.Class<T> extensionType)java.util.Collection<MethodReference>getMethods()TeaVMOptimizationLevelgetOptimizationLevel()java.lang.String[]getPlatformTags()ProblemProvidergetProblemProvider()ProgramCachegetProgramCache()TeaVMProgressListenergetProgressListener()java.util.PropertiesgetProperties()Gets configuration properties.<T> TgetService(java.lang.Class<T> type)ListableClassReaderSourcegetWrittenClasses()voidinstallPlugins()Finds and install all plugins in the current class path.ListableClassHolderSourcelink(DependencyAnalyzer dependency)voidpreserveType(java.lang.String className)<T> voidregisterService(java.lang.Class<T> type, T instance)voidsetCacheStatus(CacheStatus cacheStatus)voidsetLastKnownClasses(int lastKnownClasses)voidsetOptimizationLevel(TeaVMOptimizationLevel optimizationLevel)voidsetProgramCache(ProgramCache programCache)voidsetProgressListener(TeaVMProgressListener progressListener)voidsetProperties(java.util.Properties properties)Specifies configuration properties for TeaVM and its plugins.booleanwasCancelled()
-
-
-
Method Detail
-
addVirtualMethods
public void addVirtualMethods(java.util.function.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 java.lang.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(java.util.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 java.util.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 java.lang.String[] getPlatformTags()
- Specified by:
getPlatformTagsin interfaceTeaVMHost
-
entryPoint
public void entryPoint(java.lang.String className, java.lang.String name)
-
entryPoint
public void entryPoint(java.lang.String className)
-
preserveType
public void preserveType(java.lang.String className)
-
getDependencyClassSource
public ClassReaderSource getDependencyClassSource()
-
getClasses
public java.util.Collection<java.lang.String> getClasses()
-
getMethods
public java.util.Collection<MethodReference> getMethods()
-
getDependencyInfo
public DependencyInfo getDependencyInfo()
-
getWrittenClasses
public ListableClassReaderSource getWrittenClasses()
-
setLastKnownClasses
public void setLastKnownClasses(int lastKnownClasses)
-
build
public void build(BuildTarget buildTarget, java.lang.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)
-
build
public void build(java.io.File dir, java.lang.String fileName)
-
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(java.lang.Class<T> type)
- Specified by:
getServicein interfaceServiceRepository
-
registerService
public <T> void registerService(java.lang.Class<T> type, T instance)- Specified by:
registerServicein interfaceTeaVMHost
-
getExtension
public <T extends TeaVMHostExtension> T getExtension(java.lang.Class<T> extensionType)
- Specified by:
getExtensionin interfaceTeaVMHost
-
-