- All Known Implementing Classes:
AbstractJctCompiler
javac does by default, for JDK
17.- Since:
- 0.0.1
- Author:
- Ashley Scopes
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final AnnotationProcessorDiscoveryDefault setting for how to apply annotation processor discovery when no processors are explicitly defined (AnnotationProcessorDiscovery.INCLUDE_DEPENDENCIES).static final CompilationModeDefault setting for the compilation mode to use (CompilationMode.COMPILATION_AND_ANNOTATION_PROCESSING).static final LoggingModeDefault setting for logging diagnostics (LoggingMode.ENABLED).static final booleanDefault setting for displaying warnings as errors (false).static final LoggingModeDefault setting for logging file manager operations (LoggingMode.DISABLED).static final booleanDefault setting for fixing modules being placed on the classpath by mistake (true).static final booleanDefault setting for inclusion of the current class path (true).static final booleanDefault setting for inclusion of the current module path (true).static final booleanDefault setting for inclusion of the system module path (true).static final LocaleDefault setting for locale (Locale.ROOT).static final CharsetDefault charset to use for compiler logs (StandardCharsets.UTF_8).static final booleanDefault setting for preview features (false).static final booleanDefault setting for deprecation warnings (true).static final booleanDefault setting for displaying warnings (true).static final booleanDefault setting for verbose logging (false). -
Method Summary
Modifier and TypeMethodDescriptionaddAnnotationProcessorOptions(Iterable<String> annotationProcessorOptions) Add options to pass to any annotation processors.default JctCompileraddAnnotationProcessorOptions(String annotationProcessorOption, String... annotationProcessorOptions) Add options to pass to any annotation processors.addAnnotationProcessors(Iterable<? extends Processor> annotationProcessors) Add annotation processors to invoke.default JctCompileraddAnnotationProcessors(Processor annotationProcessor, Processor... annotationProcessors) Add annotation processors to invoke.addCompilerOptions(Iterable<String> compilerOptions) Add command line options to pass tojavac.default JctCompileraddCompilerOptions(String compilerOption, String... compilerOptions) Add command line options to pass tojavac.annotationProcessorDiscovery(AnnotationProcessorDiscovery annotationProcessorDiscovery) Set how to perform annotation processor discovery.compilationMode(CompilationMode compilationMode) Set the compilation mode to use for this compiler.Invoke the compilation and return the compilation result.default JctCompilationInvoke the compilation and return the compilation result.compile(Workspace workspace, Collection<String> classNames) Invoke the compilation and return the compilation result.<E extends Exception>
JctCompilerconfigure(JctCompilerConfigurer<E> configurer) Apply a given configurer to this compiler that can throw a checked exception.diagnosticLoggingMode(LoggingMode diagnosticLoggingMode) Set how to handle diagnostic capture.failOnWarnings(boolean enabled) Set whether to enable treating warnings as errors or not.fileManagerLoggingMode(LoggingMode fileManagerLoggingMode) Set how to handle logging calls to underlying file managers.fixJvmModulePathMismatch(boolean fixJvmModulePathMismatch) Get whether we will attempt to fix modules appearing on the classpath, or non-modules appearing on the module path.Get how to perform annotation processor discovery.Get an immutable snapshot view of the current annotation processor options that are set.Get an immutable snapshot view of the current annotation processors that are explicitly set to be run, in the order that they were provided to the compiler.Get the compilation mode that is in use.Get an immutable snapshot view of the current compiler options that are set.Get the default release to use if no release or target version is specified.Get the current diagnostic logging mode.Get the effective release to use for the actual compilation.Get the current file manager logging mode.Get the output locale.Get the charset being used to write compiler logs with.getName()Get the friendly printable name of this compiler object.Get the current release version that is set, ornullif left to the compiler to decide.Get the current source version that is set, ornullif left to the compiler to decide.Get the current target version that is set, ornullif left to the compiler default.inheritClassPath(boolean inheritClassPath) Set whether the class path is inherited from the caller JVM or not.inheritModulePath(boolean inheritModulePath) Set whether the module path is inherited from the caller JVM or not.inheritSystemModulePath(boolean inheritSystemModulePath) Set whether the system module path is inherited from the caller JVM or not.booleanDetermine whether warnings are being treated as errors or not.booleanGet whether we will attempt to fix modules appearing on the classpath, or non-modules appearing on the module path.booleanGet whether the class path is inherited from the caller JVM or not.booleanGet whether the module path is inherited from the caller JVM or not.booleanGet whether the system module path is inherited from the caller JVM or not.booleanDetermine whether preview features are enabled or not.booleanDetermine whether deprecation warnings are enabled or not.booleanDetermine whether warnings are enabled or not.booleanDetermine whether verbose logging is enabled or not.Set the output locale.logCharset(Charset logCharset) Set the charset being used to write compiler logs with.Set the friendly name of this compiler.previewFeatures(boolean enabled) Set whether to enable preview features or not.default JctCompilerrelease(int release) Set the release version.Set the release version.default JctCompilerrelease(SourceVersion release) Set the release version.showDeprecationWarnings(boolean enabled) Set whether to enable deprecation warnings or not.showWarnings(boolean enabled) Set whether to enable displaying warnings or not.default JctCompilersource(int source) Set the source version.Set the source version.default JctCompilersource(SourceVersion source) Set the source version.default JctCompilertarget(int target) Set the target version.Set the target version.default JctCompilertarget(SourceVersion target) Set the target version.default JctCompilerRequest that the compiler uses a language version that corresponds to the runtime language version in use on the JVM running tests.verbose(boolean enabled) Set whether to use verbose output or not.
-
Field Details
-
DEFAULT_SHOW_DEPRECATION_WARNINGS
Default setting for deprecation warnings (true).- See Also:
-
DEFAULT_LOCALE
Default setting for locale (Locale.ROOT). -
DEFAULT_PREVIEW_FEATURES
Default setting for preview features (false).- See Also:
-
DEFAULT_VERBOSE
Default setting for verbose logging (false).- See Also:
-
DEFAULT_SHOW_WARNINGS
Default setting for displaying warnings (true).- See Also:
-
DEFAULT_FAIL_ON_WARNINGS
Default setting for displaying warnings as errors (false).- See Also:
-
DEFAULT_FIX_JVM_MODULE_PATH_MISMATCH
Default setting for fixing modules being placed on the classpath by mistake (true).- See Also:
-
DEFAULT_INHERIT_CLASS_PATH
Default setting for inclusion of the current class path (true).- See Also:
-
DEFAULT_INHERIT_MODULE_PATH
Default setting for inclusion of the current module path (true).- See Also:
-
DEFAULT_INHERIT_SYSTEM_MODULE_PATH
Default setting for inclusion of the system module path (true).- See Also:
-
DEFAULT_FILE_MANAGER_LOGGING_MODE
Default setting for logging file manager operations (LoggingMode.DISABLED). -
DEFAULT_DIAGNOSTIC_LOGGING_MODE
Default setting for logging diagnostics (LoggingMode.ENABLED). -
DEFAULT_COMPILATION_MODE
Default setting for the compilation mode to use (CompilationMode.COMPILATION_AND_ANNOTATION_PROCESSING). -
DEFAULT_ANNOTATION_PROCESSOR_DISCOVERY
Default setting for how to apply annotation processor discovery when no processors are explicitly defined (AnnotationProcessorDiscovery.INCLUDE_DEPENDENCIES). -
DEFAULT_LOG_CHARSET
Default charset to use for compiler logs (StandardCharsets.UTF_8).
-
-
Method Details
-
compile
Invoke the compilation and return the compilation result.The actual classes to compile will be dynamically discovered. If you wish to specify the specific classes to compile, see
compile(Workspace, String, String...)orcompile(Workspace, Collection).- Parameters:
workspace- the workspace to compile.- Returns:
- the compilation result.
- Throws:
JctCompilerException- if the compiler threw an unhandled exception. This should not occur for compilation failures generally.IllegalStateException- if no compilation units were found.UncheckedIOException- if an IO error occurs.- See Also:
-
compile
default JctCompilation compile(Workspace workspace, String firstClassName, String... additionalClassNames) Invoke the compilation and return the compilation result.Only classes matching the given class names will be compiled.
If you wish to let JCT determine which classes to compile dynamically, see
compile(Workspace)instead.- Parameters:
workspace- the workspace to compile.firstClassName- the first class name to compile.additionalClassNames- any additional class names to compile.- Returns:
- the compilation result.
- Throws:
JctCompilerException- if the compiler threw an unhandled exception. This should not occur for compilation failures generally.NullPointerException- if any class names are null.IllegalStateException- if no compilation units were found.UncheckedIOException- if an IO error occurs.- See Also:
-
compile
Invoke the compilation and return the compilation result.Only classes matching the given class names will be compiled.
If you wish to let JCT determine which classes to compile dynamically, see
compile(Workspace)instead.- Parameters:
workspace- the workspace to compile.classNames- the class names to compile.- Returns:
- the compilation result.
- Throws:
JctCompilerException- if the compiler threw an unhandled exception. This should not occur for compilation failures usually.NullPointerException- if theclassNamescollection contains any null values, or if the collection itself is null.IllegalArgumentException- if the collection is empty.IllegalStateException- if no compilation units were found.UncheckedIOException- if an IO error occurs.- See Also:
-
configure
Apply a given configurer to this compiler that can throw a checked exception.- Type Parameters:
E- any exception that may be thrown.- Parameters:
configurer- the configurer to invoke.- Returns:
- this compiler object for further call chaining.
- Throws:
E- any exception that may be thrown by the configurer.
-
getName
Get the friendly printable name of this compiler object.- Returns:
- the name of the compiler.
-
name
Set the friendly name of this compiler.- Parameters:
name- the name to set.- Returns:
- this compiler object for further call chaining.
-
getAnnotationProcessorOptions
Get an immutable snapshot view of the current annotation processor options that are set.- Returns:
- the current annotation processor options that are set.
-
addAnnotationProcessorOptions
Add options to pass to any annotation processors.- Parameters:
annotationProcessorOptions- the options to pass.- Returns:
- this compiler object for further call chaining.
-
addAnnotationProcessorOptions
default JctCompiler addAnnotationProcessorOptions(String annotationProcessorOption, String... annotationProcessorOptions) Add options to pass to any annotation processors.- Parameters:
annotationProcessorOption- the first option to pass.annotationProcessorOptions- additional options to pass.- Returns:
- this compiler object for further call chaining.
-
getAnnotationProcessors
Get an immutable snapshot view of the current annotation processors that are explicitly set to be run, in the order that they were provided to the compiler.- Returns:
- the current annotation processors that are set.
-
addAnnotationProcessors
Add annotation processors to invoke.This bypasses the discovery process of annotation processors provided in the annotation processor path.
- Parameters:
annotationProcessors- the processors to invoke.- Returns:
- this compiler object for further call chaining.
-
addAnnotationProcessors
default JctCompiler addAnnotationProcessors(Processor annotationProcessor, Processor... annotationProcessors) Add annotation processors to invoke.This bypasses the discovery process of annotation processors provided in the annotation processor path.
- Parameters:
annotationProcessor- the first processor to invoke.annotationProcessors- additional processors to invoke.- Returns:
- this compiler object for further call chaining.
-
getCompilerOptions
Get an immutable snapshot view of the current compiler options that are set.- Returns:
- the current compiler options that are set.
-
addCompilerOptions
Add command line options to pass tojavac.- Parameters:
compilerOptions- the options to add.- Returns:
- this compiler object for further call chaining.
-
addCompilerOptions
Add command line options to pass tojavac.- Parameters:
compilerOption- the first option to add.compilerOptions- additional options to add.- Returns:
- this compiler object for further call chaining.
-
isVerbose
boolean isVerbose()Determine whether verbose logging is enabled or not.Unless otherwise changed or specified, implementations should default to
DEFAULT_VERBOSE.Note that enabling this is compiler-specific behaviour. There is no guarantee that the output target or the format or verbosity of output will be consistent between different compiler implementations.
- Returns:
- whether verbose logging is enabled or not.
-
verbose
Set whether to use verbose output or not.Unless otherwise changed or specified, implementations should default to
DEFAULT_VERBOSE.Note that enabling this is compiler-specific behaviour. There is no guarantee that the output target or the format or verbosity of output will be consistent between different compiler implementations.
- Parameters:
enabled-truefor verbose output,falsefor normal output.- Returns:
- this compiler for further call chaining.
-
isPreviewFeatures
boolean isPreviewFeatures()Determine whether preview features are enabled or not.Unless otherwise changed or specified, implementations should default to
DEFAULT_PREVIEW_FEATURES.- Returns:
- whether preview features are enabled or not.
-
previewFeatures
Set whether to enable preview features or not.Unless otherwise changed or specified, implementations should default to
DEFAULT_PREVIEW_FEATURES.- Parameters:
enabled-trueto enable preview features, orfalseto disable them.- Returns:
- this compiler object for further call chaining.
-
isShowWarnings
boolean isShowWarnings()Determine whether warnings are enabled or not.Unless otherwise changed or specified, implementations should default to
DEFAULT_SHOW_WARNINGS.- Returns:
- whether warnings are enabled or not.
-
showWarnings
Set whether to enable displaying warnings or not.Unless otherwise changed or specified, implementations should default to
DEFAULT_SHOW_WARNINGS.- Parameters:
enabled-trueto enable warnings.falseto disable them.- Returns:
- this compiler object for further call chaining.
-
isShowDeprecationWarnings
boolean isShowDeprecationWarnings()Determine whether deprecation warnings are enabled or not.Unless otherwise changed or specified, implementations should default to
DEFAULT_SHOW_DEPRECATION_WARNINGS.- Returns:
- whether deprecation warnings are enabled or not.
-
showDeprecationWarnings
Set whether to enable deprecation warnings or not.This is ignored if
showWarnings(boolean)is disabled.Unless otherwise changed or specified, implementations should default to
DEFAULT_SHOW_DEPRECATION_WARNINGS.- Parameters:
enabled-trueto enable deprecation warnings.falseto disable them.- Returns:
- this compiler object for further call chaining.
-
isFailOnWarnings
boolean isFailOnWarnings()Determine whether warnings are being treated as errors or not.Unless otherwise changed or specified, implementations should default to
DEFAULT_FAIL_ON_WARNINGS.- Returns:
- whether warnings are being treated as errors or not.
-
failOnWarnings
Set whether to enable treating warnings as errors or not.This is ignored if
showWarnings(boolean)is disabled.Unless otherwise changed or specified, implementations should default to
DEFAULT_FAIL_ON_WARNINGS.- Parameters:
enabled-trueto enable treating warnings as errors.falseto disable them.- Returns:
- this compiler object for further call chaining.
-
getCompilationMode
Get the compilation mode that is in use.Unless otherwise changed or specified, implementations should default to
DEFAULT_COMPILATION_MODE.- Returns:
- the compilation mode.
-
compilationMode
Set the compilation mode to use for this compiler.Unless otherwise changed or specified, implementations should default to
DEFAULT_COMPILATION_MODE.- Parameters:
compilationMode- the compilation mode to use.- Returns:
- this compiler object for further call chaining.
-
getDefaultRelease
Get the default release to use if no release or target version is specified.This can not be configured.
- Returns:
- the default release version to use.
-
getEffectiveRelease
Get the effective release to use for the actual compilation.This may be determined from the
source,target,release, anddefault release.- Returns:
- the effective release.
-
getRelease
Get the current release version that is set, ornullif left to the compiler to decide. default.Unless explicitly defined, the default setting is expected to be a sane compiler-specific default.
- Returns:
- the release version string, if set.
-
release
Set the release version.This will clear any source and target version that is set.
Unless explicitly defined, the default setting is expected to be a sane compiler-specific default.
- Parameters:
release- the version to set.- Returns:
- this compiler object for further call chaining.
-
release
Set the release version.This will clear any source and target version that is set.
Unless explicitly defined, the default setting is expected to be a sane compiler-specific default.
- Parameters:
release- the version to set.- Returns:
- this compiler object for further call chaining.
-
release
Set the release version.This will clear any source and target version that is set.
Unless explicitly defined, the default setting is expected to be a sane compiler-specific default.
- Parameters:
release- the version to set.- Returns:
- this compiler object for further call chaining.
-
useRuntimeRelease
Request that the compiler uses a language version that corresponds to the runtime language version in use on the JVM running tests.For example, running this on JRE 19 would set the release to "19".
This calls
internally.- Returns:
- this compiler object for further call chaining.
-
getSource
Get the current source version that is set, ornullif left to the compiler to decide. default.Unless explicitly defined, the default setting is expected to be a sane compiler-specific default.
- Returns:
- the source version string, if set.
-
source
Set the source version.This will clear any release version that is set.
Unless explicitly defined, the default setting is expected to be a sane compiler-specific default.
- Parameters:
source- the version to set.- Returns:
- this compiler object for further call chaining.
-
source
Set the source version.This will clear any release version that is set.
Unless explicitly defined, the default setting is expected to be a sane compiler-specific default.
- Parameters:
source- the version to set.- Returns:
- this compiler object for further call chaining.
-
source
Set the source version.This will clear any release version that is set.
Unless explicitly defined, the default setting is expected to be a sane compiler-specific default.
- Parameters:
source- the version to set.- Returns:
- this compiler object for further call chaining.
-
getTarget
Get the current target version that is set, ornullif left to the compiler default.Unless explicitly defined, the default setting is expected to be a sane compiler-specific default.
- Returns:
- the target version string, if set.
-
target
Set the target version.This will clear any release version that is set.
Unless explicitly defined, the default setting is expected to be a sane compiler-specific default.
- Parameters:
target- the version to set.- Returns:
- this compiler object for further call chaining.
-
target
Set the target version.This will clear any release version that is set.
Unless explicitly defined, the default setting is expected to be a sane compiler-specific default.
- Parameters:
target- the version to set.- Returns:
- this compiler object for further call chaining.
-
target
Set the target version.This will clear any release version that is set.
Unless explicitly defined, the default setting is expected to be a sane compiler-specific default.
- Parameters:
target- the version to set.- Returns:
- this compiler object for further call chaining.
-
isFixJvmModulePathMismatch
boolean isFixJvmModulePathMismatch()Get whether we will attempt to fix modules appearing on the classpath, or non-modules appearing on the module path.This enables correct classpath and module path detection when the test pack is a module but the code being compiled in the test is not, and vice versa. We need this because many build systems decide whether to populate the
--module-pathflat or the--classpathwith JPMS-enabled dependencies based on whether the project under compilation is a JPMS module itself.This only applies if
isInheritModulePath()orisInheritClassPath()is enabled, and only applies to the current JVM classpath and module path.Unless otherwise changed or specified, implementations should default to
DEFAULT_FIX_JVM_MODULE_PATH_MISMATCH.- Returns:
trueif enabled, orfalseif disabled.
-
fixJvmModulePathMismatch
Get whether we will attempt to fix modules appearing on the classpath, or non-modules appearing on the module path.Unless otherwise changed or specified, implementations should default to
DEFAULT_FIX_JVM_MODULE_PATH_MISMATCH.- Parameters:
fixJvmModulePathMismatch- whether to enable the mismatch fixing or not.- Returns:
- this compiler object for further call chaining.
-
isInheritClassPath
boolean isInheritClassPath()Get whether the class path is inherited from the caller JVM or not.Unless otherwise changed or specified, implementations should default to
DEFAULT_INHERIT_CLASS_PATH.- Returns:
- whether the current class path is being inherited or not.
-
inheritClassPath
Set whether the class path is inherited from the caller JVM or not.Unless otherwise changed or specified, implementations should default to
DEFAULT_INHERIT_CLASS_PATH.- Parameters:
inheritClassPath-trueto include it, orfalseto exclude it.- Returns:
- this compiler object for further call chaining.
-
isInheritModulePath
boolean isInheritModulePath()Get whether the module path is inherited from the caller JVM or not.Unless otherwise changed or specified, implementations should default to
DEFAULT_INHERIT_MODULE_PATH.- Returns:
- whether the module path is being inherited or not.
-
inheritModulePath
Set whether the module path is inherited from the caller JVM or not.Unless otherwise changed or specified, implementations should default to
DEFAULT_INHERIT_MODULE_PATH.- Parameters:
inheritModulePath-trueto include it, orfalseto exclude it.- Returns:
- this compiler object for further call chaining.
-
isInheritSystemModulePath
boolean isInheritSystemModulePath()Get whether the system module path is inherited from the caller JVM or not.Unless otherwise changed or specified, implementations should default to
DEFAULT_INHERIT_SYSTEM_MODULE_PATH.- Returns:
- whether the system module path is being inherited or not.
-
inheritSystemModulePath
Set whether the system module path is inherited from the caller JVM or not.Unless otherwise changed or specified, implementations should default to
DEFAULT_INHERIT_SYSTEM_MODULE_PATH.- Parameters:
inheritSystemModulePath-trueto include it, orfalseto exclude it.- Returns:
- this compiler object for further call chaining.
-
getLocale
Get the output locale.Unless otherwise changed or specified, implementations should default to
DEFAULT_LOCALE.- Returns:
- the output locale to use.
-
locale
Set the output locale.Unless otherwise changed or specified, implementations should default to
DEFAULT_LOCALE.- Parameters:
locale- the locale to use.- Returns:
- this compiler for further call chaining.
-
getLogCharset
Get the charset being used to write compiler logs with.Unless otherwise changed or specified, implementations should default to
DEFAULT_LOG_CHARSET.- Returns:
- the charset.
-
logCharset
Set the charset being used to write compiler logs with.Unless otherwise changed or specified, implementations should default to
DEFAULT_LOG_CHARSET.- Parameters:
logCharset- the charset to use.- Returns:
- this compiler for further call chaining.
-
getFileManagerLoggingMode
Get the current file manager logging mode.Unless otherwise changed or specified, implementations should default to
DEFAULT_FILE_MANAGER_LOGGING_MODE.- Returns:
- the current file manager logging mode.
-
fileManagerLoggingMode
Set how to handle logging calls to underlying file managers.Unless otherwise changed or specified, implementations should default to
DEFAULT_FILE_MANAGER_LOGGING_MODE.- Parameters:
fileManagerLoggingMode- the mode to use for file manager logging.- Returns:
- this compiler for further call chaining.
-
getDiagnosticLoggingMode
Get the current diagnostic logging mode.Unless otherwise changed or specified, implementations should default to
DEFAULT_DIAGNOSTIC_LOGGING_MODE.- Returns:
- the current diagnostic logging mode.
-
diagnosticLoggingMode
Set how to handle diagnostic capture.Unless otherwise changed or specified, implementations should default to
DEFAULT_DIAGNOSTIC_LOGGING_MODE.- Parameters:
diagnosticLoggingMode- the mode to use for diagnostic capture.- Returns:
- this compiler for further call chaining.
-
getAnnotationProcessorDiscovery
Get how to perform annotation processor discovery.Unless otherwise changed or specified, implementations should default to
DEFAULT_ANNOTATION_PROCESSOR_DISCOVERY.Specifying any annotation processors explicitly with
addAnnotationProcessors(Iterable)oraddAnnotationProcessors(Processor, Processor...)will bypass this setting, treating it as being disabled.- Returns:
- the processor discovery mode to use.
-
annotationProcessorDiscovery
Set how to perform annotation processor discovery.Unless otherwise changed or specified, implementations should default to
DEFAULT_ANNOTATION_PROCESSOR_DISCOVERY.Specifying any annotation processors explicitly with
addAnnotationProcessors(Iterable)oraddAnnotationProcessors(Processor, Processor...)will bypass this setting, treating it as being disabled.- Parameters:
annotationProcessorDiscovery- the processor discovery mode to use.- Returns:
- this compiler for further call chaining.
-