public class JavacCompiler extends Object implements HotCompiler
This compiler compiles ".java" files under the srcDirs
to ".class" files under the outDir.
See also HotReloader.onJavaFiles(String...).
The source directory structure must follow the package structure.
Each java file must contain only one top-level class.
For example, class "foo.Bar" must be defined in a "foo/Bar.java" file
under one of the srcDirs.
This compiler compares timestamps of source files and output files,
skips java files that are older than the corresponding class files.
This can be problematic. If necessary, delete the outDir and restart JVM.
This implementation depends on ToolProvider.getSystemJavaCompiler().
| Constructor and Description |
|---|
JavacCompiler(List<Path> srcDirs,
Path outDir,
List<Path> extraClassPaths,
List<String> javacOptions)
Create a JavacCompiler.
|
| Instance 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.
|
| Static Method | |
Path |
tmpOutDirFor(String... srcDirs)
Create an
outDir under "/tmp" for srcDirs. |
public static Path tmpOutDirFor(String... srcDirs) throws Exception
outDir under "/tmp" for srcDirs.
The exact location is uniquely determined by the srcDirs.
An example dir: "/tmp/bayou/hot_reloader_javac_out/67E5A7ED8DDE8CE4"
Exceptionpublic PathMatcher getPathMatcher()
All ".java" files are matched, except files like "package-info.java".
getPathMatcher in interface HotCompilerFileSystem.getPathMatcher(String)public void compile(Consumer<CharSequence> msgOut, Set<Path> allFiles) throws Exception
HotCompilerThis 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.
compile in interface HotCompilermsgOut - for diagnosis messages; see HotReloader.getMessageOut()Exception - if compilation fails; the exception message usually contains compilation errors.public void compile(Consumer<CharSequence> msgOut, Set<Path> createdFiles, Set<Path> updatedFiles, Set<Path> deletedFiles) throws Exception
HotCompilerThis method is called if some source files are created/updated/deleted.
compile in interface HotCompilermsgOut - for diagnosis messages; see HotReloader.getMessageOut()Exception - if compilation fails; the exception message usually contains compilation errors.