Kernel API Generator
Principle
The Kernel API Generator is a tool that helps to generate a kernel.api file based on a Java classpath.
The generated file lists the public and protected types, methods and fields of the selected classes,
as well as those of their supertypes.
Use
To generate the kernel.api file, execute the generateKernelApi task as follows:
./gradlew generateKernelApi
This task is available in Application and Add-On Library projects.
It compiles the project sources itself, so there is no need to execute the build task first.
The kernel.api file is generated in the build/kernelApi directory of the project,
which is created if it does not exist.
By default, all the classes compiled by the project are used to generate the Kernel API. To select a subset of them, configure the options described in Options.
The generateKernelApi task is not executed by the build task and no other task consumes its output,
so it must be executed explicitly each time the API exposed by the Kernel changes.
The generated file must then be stored at the root of the Application classpath,
usually the src/main/resources directory of the Kernel project or of the Runtime Environment project.
Warning
A supertype which is not on the classpath is skipped by the tool, without any error or warning message,
so an incomplete classpath produces an incomplete kernel.api file.
Execute the task with the --info option to print the classpath used by the tool:
./gradlew generateKernelApi --info
When the generation fails, the task deletes the kernel.api file,
so the build directory never keeps an outdated file.
To generate the kernel.api file, make sure to compile all the project Java sources (by running the build task for example),
then execute the execTool task as followed:
./gradlew execTool --name=kernelAPIGenerator \
--toolProperty=kernel.api.generator.classpath="C:/my-kernel/build/classes/java/main" \
--toolProperty=output.dir="C:/my-kernel/build" \
--toolProperty=kernel.api.generator.includes.patterns="**/*.class" \
--toolProperty=kernel.api.generator.excludes.patterns="" \
--console plain
The kernel.api file is generated in the directory defined by the output.dir property.
Warning
The directory specified by the output.dir must exist, it is not automatically created.
If the directory does not exist, the kernel.api file is not generated and the execution silently ends (no warning or error message).
Options
The tool is configured with the properties of the generateKernelApi task,
in the build.gradle.kts file of the project:
import com.microej.gradle.tasks.GenerateKernelApiTask
tasks.named<GenerateKernelApiTask>("generateKernelApi") {
includes.set(listOf("com/mycompany/kernel/**"))
excludes.set(listOf("**/internal/**"))
}
includes: Ant-style patterns of the classes to include, relative to the directory of the classes compiled by the project.Default value:
**/*.class(which means all the classes compiled by the project).
excludes: Ant-style patterns of the classes to exclude, relative to the directory of the classes compiled by the project.Default value: empty (which means no excluded classes).
classpath: Classpath searched by the tool.Default value: the runtime classpath of the project, which contains the classes compiled by the project, its resources and its dependencies.
The include and exclude patterns are matched against the directories of this classpath, which contain the classes compiled by the project. The JAR files of this classpath, which contain the dependencies, are searched to resolve the supertypes of the selected classes, but their classes are never selected.
outputDirectory: Directory of the generatedkernel.apifile.Default value:
build/kernelApi.
The task fails when no class matches the include and exclude patterns, instead of generating an empty file.
The tool is configured with the --toolProperty options of the execTool task:
kernel.api.generator.classpath: List of the absolute paths of the JAR files or directories containing Java class files, for exampleC:/folder1/lib.jar;C:/folder2.Default value: no default value, this option is required.
output.dir: Absolute path of the destination directory of the generatedkernel.apifiles. It is important to note that this directory must exist.Default value: no default value, this option is required.
kernel.api.generator.includes.patterns: Ant-style pattern of the classes to include.Default value:
**/*.class(which means all the classes).
kernel.api.generator.excludes.patterns: Ant-style pattern of the classes to exclude.Default value: empty (which means no excluded classes).
