# Repository Structure

The repository is structured as follows:

    bundles  --- contains any standard eclipse plugin and the emf code generator.
    features --- contains any tooling kernel or af3 feature definition (set of plugins).
    products --- contains product descriptions (set of features): produces the resulting zips.
    releng   --- common build configuration and p2 update sites.
    tests    --- junit integration or module tests of the application, or single fragments respectively.
    
## bundles

The bundle folder is composed of the following repositories:

    af3           --- git submodule of the af3 plugins.
    af3-rcp       --- git submodule containing the org.fortiss.af3.rcapplication plugin.
    emf-generator --- contains the emf code generator and its launch configuration.
    kernel        --- git submodule of the tooling kernel plugins.
    
Two maven pom files are found in this folder:

    pom.xml               --- specifies the to-be-compiled eclipse plugins activated by the given build flags.
    pom-bundle-parent.xml --- compilation-specific configuration: currently, it only adds the required openjfx libraries to the tycho classpath.
    
The `pom.xml` file is the entry point for the compilation, whereas the `pom-bundle-parent.xml` is included from bundle repos (such as AF3).

Note that all plugins are build pom-less: this means that no `pom.xml` config file is needed within standard Eclipse plugins. It is only required at the level above. Therefore, a maven extension is specified within the “.mvn” folder within the root of the maven-releng repository.

## docker

Contains the build specification for the docker container used in the CI Jobs.

## features

contains the tooling kernel and AF3 feature as git submodules. Each of these features contains the full set of plugins as of now. However they might be regrouped according to functionality groups in future.

## products

contains the AF3 phoenix product as git submodule.

## releng

contains the following modules:

    org.fortiss.af3.configuration --- Common configuration of all maven modules such as maven plugin versions and configuration. Moreover, commonly used variables are specified here.
    org.fortiss.af3.target        --- Target definition file that specifies all available plugins of the compilation and runtime platform. The definition of p2 sites is only allowed here. (There is only one exception in the product)
    org.fortiss.af3.update        --- Contains the configuration to produce the AF3 p2 update site.
    org.fortiss.tooling.update    --- Contains the configuration to produce the Tooling kernel update site.
    
## Tests

Contains a git submodule containing the AF3 JUnit tests.

# Build process

 - We use the maven phase _verify_ for building, not _package_, which is the default. We are forced to use this phase, since we must perform post-package product patching (no other phase qualifies). This is also the reason to introduce the _build.tests_ flag to skip the testing phases that are located between the _packaging_ and _verify_ phases.
 - The flag _build.emf_ is required to avoid triggering the code generation multiple times.
  
## Updating references of submodules

To update references to AF3 in order to build a new release 
 * execute `git submodule update --remote` in root maven-releng and
 * commit and push changes

## Build flags

The build itself is controlled by environment variables passed by invoked maven commands. These variables activate build profiles in the maven configuration.  

The following build flags are configured:
    
    build.emf     --- activates the emf code generation. required when setting "build.af3" or "build.kernel".
    build.af3     --- activates the compilation of af3 plugins.
    build.tooling --- activates the compilation of tooling kernel plugins.
    build.tests   --- runs the junit integration tests on the resulting product.
  
The build flags are used for a modular build configuration. For instance, another project could only depend on the tooling and implement a product that is totally different from AF3.  
The flag _build.tooling_ just produces a p2 update site that can be reused by subsequent builds. This update site is ignored if the flag is specified. thus, the combination of _build.af3_ and _build.tooling_ will not use the tooling update site.  An equivalent mechanism is implemented for _build.tests_ that additionally uses an AF3 p2 update site.
  
## Updating the Docker build container

  * Clone the repository.
  * Navigate to the cloned directory in a UNIX shell and apply the following commands.
  * `docker login git.fortiss.org:5001 -u <USERNAME>`
  * `docker build -t git.fortiss.org:5001/af3/maven-releng docker/`
  * Delete the outdated `af3/maven-releng` container
  * `docker push git.fortiss.org:5001/af3/maven-releng`

## Debugging Build Failures

Whenever a CI job fails, it may be caused by a problematic source code change, a bug in the maven-releng configuration, the docker image, or related to the Gitlab CI pipeline. The following pieces of information shall provides hints to debug such issues.

* As a first measure, ensure that the AF3 and Kernel builds in your local AF3 developer installation. Ensure that you are on the branches that you want to test.
* If this test succeeds, do a local AF3 maven build following the instructions for a [local build](https://git.fortiss.org/af3/af3/-/wikis/Setting_up_a_local_build).
* If the build finishes sucessfully, check whether the failure is caused by the docker container configuration. Therefore, on a Linux machine, install the `gitlab-runner` and `docker` packages and build the docker image locally by executing `docker build -t maven-releng docker/` within your clone of this repository. Afterwards, execute the stage from the CI script that failed by executing
  `gitlab-runner exec docker <job-name>`. Please not that pipelines are not supported if executing the `gitlab-runner` tool locally. Hence you must ensure that all required build artifacts are available in the job to test. For instance, if the test phase fails, `gitlab-ci.yml` must be modified to clone all submodules and use all build flags defined in the build job. Finally, if the isse is resolved by a change in the `Dockerfile`, follow the instructions in the *Structure* section to upload the changes to the Gitlab repository. Otherwise, just push the changes of the `gitlab-ci.yml` script.
* If this point is reached, the CI build failure may caused by some pipeline misconfiguration, for instance due to wrong artifact passing. Another likely reason is an outdated docker image in the repository's Container Registry.