public interface HotCompiler
A HotCompiler is registered to a HotReloader through
HotReloader.addCompiler(compiler, reload, srcDirs)
.
The source files for the compiler are those under the srcDirs
and matching
the PathMatcher
.
When source files are created/updated/deleted, the changes are fed to the
compile(createdFiles,updatedFiles,deletedFiles)
method for recompilation. There is also a
compile(allFiles)
method for recompiling all source files.
A HotCompiler usually compiles source files to output files. However it may do something else, e.g. update an external device after a source file is updated.
An implementation of HotCompiler can be stateful, and not thread-safe.
A HotCompiler instance should not be shared, i.e. it should not be used in multiple
addCompiler()
calls.
Abstract Methods | |
---|---|
PathMatcher |
getPathMatcher()
The PathMatcher for source files.
|
void |
compile(Consumer<CharSequence> msgOut,
Set<Path> allFiles)
Compile all source files.
|
void |
compile(Consumer<CharSequence> msgOut,
Set<Path> createdFiles,
Set<Path> updatedFiles,
Set<Path> deletedFiles)
Compile changed source files.
|
PathMatcher getPathMatcher()
Only those files under the srcDirs
will be fed to this PathMatcher;
only those approved by this PathMatcher are source files for this compiler.
An example PathMatcher:
FileSystems.getDefault().getPathMatcher("glob:**.java")
.
FileSystem.getPathMatcher(String)
void compile(Consumer<CharSequence> msgOut, Set<Path> allFiles) throws Exception
This method is usually called in the initial phase of the HotReloader. It may also be called whenever the HotReloader thinks necessary.
The compiler does not necessarily do a clean build. For example, it may compare timestamps of source files and output files, skip source files that are older than the output files.
msgOut
- for diagnosis messages; see HotReloader.getMessageOut()
Exception
- if compilation fails; the exception message usually contains compilation errors.void compile(Consumer<CharSequence> msgOut, Set<Path> createdFiles, Set<Path> updatedFiles, Set<Path> deletedFiles) throws Exception
This method is called if some source files are created/updated/deleted.
msgOut
- for diagnosis messages; see HotReloader.getMessageOut()
Exception
- if compilation fails; the exception message usually contains compilation errors.