feature-gen

open-source Open-source module
tapir-extensions-featuregen is an open-source module which is hosted at tapir-extensions. Feel free to contribute!

The FeatureIDE project allows to create both feature model files as well as variant configuration files with an Eclipse plugin. The feature-gen project generates a Java API from the model files to be used in the application code. Although the FeatureIDE module supports already the creation of tapir features and variants from the FeatureIDE model files, a drawback is that the model files have to be contained in the same project as the annotated classes. This is the reason why we developed this module. It uses not the FeatureIDE model files to generate the tapir code, but rather the classes which are generated by feature-gen. This allows to use a single model for your features and generate code for both your application and your test code in a consistent way.

Dependency

<dependency>
  <groupId>io.tapir-test</groupId>
  <artifactId>tapir-extensions-featuregen</artifactId>
  <version>1.3.0</version>
</dependency>
Caution
Although the feature-gen extension is open-source, it requires the product line testing modules of tapir which are not part of the non-commercial licenses.

Features

To generate the features from your feature model, you can use the dynamic active annotation FeatureGenFeatures. Reference the enumeration generated from feature-gen and the annotation will generate all features. The following example assumes that your root feature is named Root and thus the enum generated from feature-gen is named RootFeature.

@FeatureGenFeatures(RootFeature)
class Features {  
}

Per default the features get the suffixes Feature. You can change the prefixes and the suffixes of your features with the annotation properties prefix and suffix.

@FeatureGenFeatures(value=RootFeature, prefix='MyPrefix', suffix='MySuffix')
class Features {  
}

As with all of tapir’s dynamic active annotations you can implement an own annotation processor if you need even more control. The default annotation processor is FeatureIDEFeaturesProcessor with an order of -10000.

Caution
For technical (and modularisation) reasons it is currently recommended to let feature-gen generate in one module and reference it in the module containing your tapir features and variants. Otherwise the annotation is not able to find the referenced enumeration during the build process.

Variants

To generate a variant from your variant model file, you can use the dynamic active annotation FeatureGenVariant. Reference the class annotated with FeatureIDEVariant and the class annotated with FeatureGenFeatures and the annotated class will be turned into a variant. All selected features are added to the variant. The following example assumes that the features class is named Features as in the above example and that the variant from your feature-gen module is named Variant1.

@FeatureGenVariant(featuresClass=Features, variantClass=Variant1)
class TapirVariant1 {  
}

Per default the annotation uses the name of the annotated class as name for the variant. In order to change this behaviour, you can set the name in the annotation.

@FeatureGenVariant(featuresClass=Features, variantClass=Variant1, name='MyVariant')
class TapirVariant1 {  
}

As with all of tapir’s dynamic active annotations you can implement an own annotation processor if you need even more control. The default annotation processor is FeatureGenVariantProcessor with an order of -10000.