Pom-O-Matic Solve your Build troubles with Pom-O-Matic!
The FOAM build is a node tool which executes Javascript methods (Tasks) against Project Object Model (POM)(or a more lighthearted acronym expansion: Pom-O-Matic) files.
The build manages options and tasks:
- options - provide build specific command line arguments that manipulate flags or set environment variables to impact the selection and operation of tasks.
- tasks - methods which act against the source code to generate an application.
POMs are JSON files which identify source code, application configuration, and build instructions. They are hierarchical and can exist at any level of a code repository.
There are two types of POMs
- Tooling - poms which configure the Build environment itself.
- options and tasks add support for build specific command line options and methods to process the source code.
- For example, JavaTooling adds options to allow the configuration of the Java target version, and provide command line arguments to control creating a JAR file or start the JVM with JDPA enabled. And adds tasks for building and starting from JAR file locally or building a TAR file for remote deployment.
- Multiple Tooling POMs can define the same task name; All will be executed in the order encountered during tooling setup.
- The build defaults to Tooling task
allwhen no tasks are specified on the command line. (seeJavaTooling)
- Build - poms which declare build inputs.
- Such as code and deployment configuration to include.
- For example, specifying the models to generate Java from and specifying the configuration to include in a JAR file.
There are three distinct build phases:
- Tooling - the build loads Tooling POMs which add options for command line control, and build tasks specific to the type of code generation, compilation, and deployment to be supported.
- Environment and Registration - the build processes the Build POMs to:
- set environment variable values for options added during the Tooling phase
- (i.e., Java target release = 21)
- register Build POM tasks to be run when same-named Tooling tasks are run
- (i.e., buildJavaOpts JAVA_OPTS=-Dxyz before the JVM is started).
foam.POM({ ... envs: { appName: 'foam', }, ... tasks: [ function javacParameters() { JAVA_RELEASE = 21; }, function buildJavaOpts() { JAVA_OPTS += ` -DGO_HOME=${APP_HOME}`; } - set environment variable values for options added during the Tooling phase
- Task - the build processes the command line arguments, for options added during the Tooling phase, and prepares a set of tasks which are then executed. The tasks themselves, act on the Build POMs.
Three input styles are supported
- single character (-h) - for a very few tasks.
- GNU getopt word style (--help) plus optional arguments.
- word style without the leading --, again with optional arguments.
The word style arguments can be listed individually or comma seperated.
- For example --cleanAll,all
Build examples for each Tooling feature is available with task usage
$ node foam3/tools/build.js --usage
Build help is generated by the help option and can be invoked in a number of ways:
$ node foam3/tools/build.js --help$ node foam3/tools/build.js -h$ node foam3/tools/build.js -?
Help output is broken in three sections: options, tasks, environment variables (envs). Help can display just one of the sections by passing an argument to help.
For example, the following will only output the environment variables.
$ node foam3/tools/build.js --help:envs
Help can also output the usage or information of a single option, task, or environment variable.
$ node foam3/tools/build.js --help:topic
For example, the following will only output usage of help itself
$ node foam3/tools/build.js --help:help
Help will output partial matches when an exact match for the help topic is not found.
Option --show-envs will cause the build to output the final value of all options at the point of exit on error, or just before start CORE.
POMs are hierarchical and a POM is responsible for the files in it's directory and child directories which themselves do not contain a POM.
TODO
- name - a non-unique identifier that distinguishes the POM in it's local scope. Used when reporting POM issues. Also used to set APP_NAME. A different APP_NAME can be specified in envs.
foam.POM({
name: 'foam',
...
- exclude - directories under this POM which should not be processed if they do not contain a POM.
- envs - map of key-values pairs to set build environment variables or options.
foam.POM({
name: 'foam-full',
...
envs: {
appName: 'foam'
},
- licenses - source code licenses which applies to the source managed by this POM.
- version - major[-minor-revision] string used to distinguish a build. The version is also inserted into the build and available from within. Used in jar file naming, and also for journal versioning.
foam.POM({
...
version: '1.0.0',
- projects - (and flags - test)
- files -
- javaFiles -
- journalFiles -
- flowDocFiles - (FUTURE)
- tasks - (project defined tasks)
- copy - (build provided tasks)
- Tooling specific - java, javaDependencies, javaFiles (above)
TODO
- name - a non-unique identifier that distinguishes the POM in it's local scope. Used when reporting POM issues.
- envs - environment variables that are internal to the tooling itself. For example a calculated value that many tasks share, or that one task sets-up for another.
- options - defines a property whose value can be manipulated to impact a task.
- tasks - defines a method which acts against the repository.
The build looks for tooling poms in:
tools/foam3/tools/
For example, Custom tooling located in tools/CustomTooling.js can be added into the build with:
-T+Custom
NOTE The tooling directive -T must proceed all other build arguments.
TODO
TODO
TODO
Option --flags:test will include all source and configuration flagged as test to allow using test and benchmark logic form a normally built application.
- --nop:option - The No-Op option takes a comman seperated list of task names not to execute. For example if you are dealing with pure .java files, then issuing --nop:genJS will speed your build times.
- -l / --live-reload - Source runs only: watches the
.jsfiles under the project root and pushes each save to the open browser, which reloads the changed class in place. Seedoc/guides/LiveReload.md.
- Project tooling provides tasks for creating a new FOAM based project, complete with an example Model and Test case. The task will create the default directory layout along with required poms, and initial journal configuration for logging in and mananging the new Model.
./build.sh -T+setup/Project --appName:example --package:com.foamdev --adminPassword:badpassword # then build and run with deployment/demo/run.sh # login with demo user - username: demo, password: demopassword # or admin user - username: admin, password: badpassword # # Run the test cases with ./build.sh --server-tests:ExampleTest - RemoteInstall tooling provide tasks to install a release on a remote instance.
- see
doc/guides/Deployment.md - After building with task tar (-k), re-run the build with RemoteInstall tooling to upload and install the tarball on a remote host.
# build tar ball ./build.sh -ckJhttps # deploy to remote host ./build.sh -TStandard,Java,RemoteInstall --user:foam --user-id:3626 --backup:false --remote-hostname:moosehead - see
- ESLint Linting support
- see
eslint.md
# Run check on default src/ directory: ./build.sh -TESLint # see ussage with ./build.sh -TESLint --usage - see
Third party repositories can be built from source with the addition of a small pom file.
Create a pom file at the root of your project with a name matching the the repository, ThirdParty-pom.js for example. In it, specify javaFiles, resources, licenses, and javaDependencies. Note the paths are relative to your root project.
Example:
```
foam.POM({
name: 'ThirdParty',
javaFiles: [
{ name: '../ThirdParty/src/main/java/*' }
],
copy: [
{ source: '../ThirdParty/src/main/resources' }
],
licenses: `
// Add license header
`,
javaDependencies: [
...
]
})
```
Add this pom file to your root project pom projects section.
```
foam.POM({
...
projects: [
...
{ name: 'ThirdParty-pom' }
],
...
})
```
Build as you would normally for your project.
Java Preview Features can be specified as such in a pom:
```
foam.POM({
...
tasks: [
function buildJavaOpts() {
JAVA_OPTS += ` --add-modules jdk.incubator.vector --enable-preview`;
}
],
```