Skip to main content

Custom Anchors

Custom anchorsAnchorA marker within generated source code reserved for adding custom logic during re-expansion. are points in the templates where developers can add custom code so that the code is reinserted after re-expanding.

You can add a custom anchorAnchorA marker within generated source code reserved for adding custom logic during re-expansion. to the template of an ExpanderExpanderA unit of generation that combines a data tree instance (functional M1 model) with a template to generate an artifact. or Feature by using @custom:{anchor-name}:

base() ::= <<
package <packageName>;

public class <className> {
@custom:fields
}
>>

This will generate a start and end anchorAnchorA marker within generated source code reserved for adding custom logic during re-expansion. to mark where developers can add custom code.

package org.example;

public class MyClass {
// anchor:custom-fields:start
// anchor:custom-fields:end
}
Custom Anchor Names

Custom AnchorAnchorA marker within generated source code reserved for adding custom logic during re-expansion. names should be unique within each ArtifactArtifactA build or deployment result, such as a Docker container image or Java archive, produced by a software project.. When you have a part of the template that reoccurs, you can use interpolation to create a unique name.

E.g. this template contains a custom anchorAnchorA marker within generated source code reserved for adding custom logic during re-expansion. for each fieldFieldA property of a DataElement expanded to a database column and user interface input element. to add annotations:

base() ::= <<
package <packageName>;

public class <className> {
<fields:fieldDeclaration();separator="\n">
}
>>

fieldDeclaration(field) ::= <<
@custom:<field.name>-annotations
private <field.type> <field.name>;
>>

Harvesting ext code​

Ext code in JEE Application Projects

In JEE ApplicationApplicationThe overarching model container grouping all components, domain logic, and configurations for an enterprise solution. projects, the base expandersExpanderA unit of generation that combines a data tree instance (functional M1 model) with a template to generate an artifact. generate /ext directories that are harvested. Expansion resourcesExpansion Resource (ExpansionResource). A reusable resource bundle containing expanders and features that provide specific application capabilities, defined in the expansion settings and added to the classpath during expansion. that expand into these projects do not need to implement ext harvestingHarvestingThe process of extracting and persisting custom code from anchors and ext directories back into source directories..

HarvestingHarvestingThe process of extracting and persisting custom code from anchors and ext directories back into source directories. ext code is implemented by expansion steps, which copy the code from and to the harvest directories in the source repository.

The harvest-expanders provide a reusable way to harvest ext code. It has a builtin mechanism that remembers which files are generated by expandersExpanderA unit of generation that combines a data tree instance (functional M1 model) with a template to generate an artifact.. This allows it to harvest only files that were added by the developer, so that the custom files no longer need to be placed in a separate ext directory.

A guide on how to use the harvest expandersExpanderA unit of generation that combines a data tree instance (functional M1 model) with a template to generate an artifact. can be found in the Developer Guides: Customization Support