Persistency
The persistency API provides methods which allow to import and export model data from and to files. The files are normally in
the AUTOSAR .arxml format.
Model Export
The modelExport allows to export MDF model data into .arxml files. To access the export functionality use one of
the getModelExport() or modelExport(Closure) methods.
// You can access the API in every active project
def exportApi = persistency.modelExport
//Or you use a closure
persistency.modelExport {
}
Export ActiveEcuc
The method exportActiveEcucToFile(Object) exports the whole ActiveEcuC configuration into a single file of type
Path specified by the user.
scriptTask('taskName') {
code {
def destinationFile // Define the file to export into...
Path resultFile = persistency.modelExport.exportActiveEcucToFile(destinationFile)
}
}
The method exportActiveEcuc(Object) exports the whole ActiveEcuC configuration into a single file of type Path in
the folder specified by the user.
scriptTask('taskName') {
code {
def tempExportFolder // Define the folder to export into...
Path resultFile = persistency.modelExport.exportActiveEcuc(tempExportFolder)
}
}
Export PostBuild Variants (Post-build selectable)
The method exportPostBuildVariants(Object) exports the PostBuild variants info into the given folder
specified by the user. This will export the ActiveEcuc and miscellaneous data. The ActiveEcuC is exported into one file per variant (even for split projects), named as
<project-name>.<variant-name>.ecuc.arxml. Miscellaneous data is exported into one file per variant, named as <project-name>.<variant-name>.misc.arxml.
The files contain all data of the project except:
- ModuleConfigurations, ModuleDefinitions
- BswImplementations, EcuConfigurations
- Variant information like EvaluatedVariantSet
List<Path> of exported files.
scriptTask('taskName') {
code {
persistency.modelExport {
def tempExportFolder = paths.resolveTempPath(".")
List<Path> fileList = exportPostBuildVariants(tempExportFolder)
}
}
}
Export PreBuild Variants
The method exportPreBuildVariants(Object) exports the PreBuild variants info into the given folder
specified by the user. This will export the ActiveEcuc and miscellaneous data. The ActiveEcuC is exported into one file per variant (even for split projects), named as
<project-name>.<variant-name>.ecuc.arxml. Miscellaneous data is exported into one file per variant, named as <project-name>.<variant-name>.misc.arxml.
The files contain all data of the project except:
- ModuleConfigurations, ModuleDefinitions
- BswImplementations, EcuConfigurations
List<Path> of exported files.
scriptTask('taskName') {
code {
persistency.modelExport {
def tempExportFolder = paths.resolveTempPath(".")
List<Path> fileList = exportPreBuildVariants(tempExportFolder)
}
}
}
Export Module Configuration
The method exportModelTree(Object, MIObject, MIObject...) exports the specified model objects and their subtrees into a
single file of type Path in the folder specified by the user.
scriptTask('taskName') {
code {
Path location = paths.resolveScriptPath(".")
def moduleList = mdfModel("EcuC")
MIModuleConfiguration ecuC = moduleList.getFirst()
Path resultFile = persistency.modelExport.exportModelTree(location, ecuC)
}
}
Advanced Exports
The advanced export use case provides access to multiple IModelExporter for special export use cases like exporting the
system description for the RTE.
Normally you would retrieve an IModelExporter by its ID via getExporter(String). Each exporter also provides multiple export methods, for example
IModelExporter.export(Object, Object...)to export the model orIModelExporter.exportAsPostBuildVariants(Object, Object...)to export the model divided into files per PostBuild predefined variant.
You can retrieve a list of supported exporters from method getAvailableExporter(). The list can differ based on the loaded data in your project.
scriptTask('taskName') {
code {
def tempExportFolder = paths.resolveTempPath(".")
// Export with an exporter in one line
persistency.modelExport["activeEcuc"].export(tempExportFolder)
}
}
scriptTask('taskName') {
code {
def tempExportFolder = paths.resolveTempPath(".")
persistency.modelExport['everything'].exportAsPreBuildVariants(tempExportFolder)
}
}
scriptTask('taskName') {
code {
def tempExportFolder = paths.resolveTempPath(".")
def fileList
//Switch to the persistency export API
persistency.modelExport{
// The getAvailableExporter() returns all exporters in the system
def exporterList = getAvailableExporter()
// Select an exporter by its ID
def exporterOpt = getExporter("activeEcuc")
exporterOpt.ifPresent { exporter ->
// Export into folder, if exporter exists
fileList = exporter.export(tempExportFolder)
}
}
}
}
Export a Model Tree
The method exportModelTreeToFile(Object, MIObject, MIObject...) exports the specified model objects and their
subtrees into a single file of type Path specified by the user.
scriptTask('taskName') {
code {
def destinationFile // Define the file to export into...
MIARPackage autosarPkg = mdfModel(AsrPath.create("/MICROSAR"))
persistency.modelExport{
def resultPath = exportModelTreeToFile(destinationFile, autosarPkg)
}
}
}
The method exportModelTree(Object, MIObject, MIObject...) exports the specified model objects and their subtrees into a
single file of type Path in the folder specified by the user.
scriptTask('taskName') {
code {
def exportFolder = paths.resolveTempPath(".")
MIARPackage autosarPkg = mdfModel(AsrPath.create("/MICROSAR"))
def resultFile = persistency.modelExport.exportModelTree(exportFolder, autosarPkg)
}
}
Export a Model Tree including all referenced Elements
You could also export model trees including all referenced elements with the exporter modelTreeClosure:
scriptTask('taskName') {
code {
def exportFolder = paths.resolveTempPath(".")
MIARPackage microsarPkg = mdfModel(AsrPath.create("/MICROSAR"))
MIARPackage autosarPkg = mdfModel(AsrPath.create("/AUTOSAR"))
persistency.modelExport["modelTreeClosure"].export(exportFolder, autosarPkg, microsarPkg)
}
}
Usage of Exporter Arguments
You can use withExporterArgs(Map, Transformer) to specify exporter arguments like in the command line with --exporterArgs argument. The key is the
exporter ID, the value are the arguments to the exporter. See command line help for details.
persistency.modelExport {
// Specify the arguments with exporterId: "arguments"
withExporterArgs(modelTree: "--element /MICROSAR") {
// Call any export code with the active arguments.
getExporter("modelTree").get().exportToFile(destinationFile)
}
}
Model Import
To access the import functionality use one of the getModelImport() or modelImport(Transformer) methods.
// You can access the API in every active project
def importApi = persistency.modelImport
//Or you use a closure
persistency.modelImport {
}
Arxml Artifact Import
To import ARXML data, use either importArxmlArtefacts(...) or importModuleConfigurations(...). The
importArxmlArtefacts(...) methods are the new preferred API to import both MIModuleConfiguration and InternalBehavior MIARPackages into the
current model. The importModuleConfigurations(...) methods are kept for backward compatibility and import only MIModuleConfiguration into the
current ActiveEcuC.
def importFile // Define input file ...
// You can access the API inside the closure
persistency.modelImport {
importArxmlArtifacts(importFile)
}
def importFile // Define input file ...
// You can access the API inside the closure
persistency.modelImport {
importModuleConfigurations(importFile)
}
The method importArxmlArtifacts(Path) imports both MIModuleConfiguration and InternalBehavior
MIARPackage from the specified .arxml file into the current model.
The method importArxmlArtifacts(Path, Action) imports MIModuleConfiguration and InternalBehavior
MIARPackage from the specified .arxml file into the current model. The Closure can be used to specify the import mode and filter if necessary.
The method importArxmlArtifacts(List) imports both MIModuleConfiguration and InternalBehavior
MIARPackage from the specified .arxml files into the current model.
The method importArxmlArtifacts(List, Action) imports both MIModuleConfiguration and
InternalBehavior MIARPackage from the specified .arxml files into the current model. The Closure can be used to specify the import mode and filter if
necessary.
The method importModuleConfigurations(Path) imports MIModuleConfiguration from the specified
.arxml file into the current ActiveEcuC.
The method importModuleConfigurations(Path, Action) imports MIModuleConfiguration from the
specified .arxml file into the current ActiveEcuC. The Closure can be used to specify the import mode and filter if necessary.
The method importModuleConfigurations(List) imports MIModuleConfiguration from the specified
.arxml files into the current ActiveEcuC.
The method importModuleConfigurations(List, Action) imports MIModuleConfiguration from the
specified .arxml files into the current ActiveEcuC. The Closure can be used to specify the import mode and filter if necessary.
Specify Import Mode and Module Filter
Use the methods addToModel(Action), replaceInModel(Action) and mergeIntoModel(Action) to specify an import mode.
- The method
replaceInModel(Action)(this is the default mode) replaces already existing module configurations and InternalBehavior packages with the imported ones. - The method
addToModel(Action)adds new module configurations and InternalBehavior packages to the model. The selected modules and packages must not already exist. - The method
mergeIntoModel(Action)merges the selected modules into the model. If a selected module does not yet exist, this behaves likeaddToModel(Action). Otherwise, the imported configuration is merged into the existing module. If conflicts occur, the imported data replaces the existing data. This mode applies only to modules, package merging is not supported.
To specify a filter for the module configurations and InternalBehavior packages to import, use one of the methods:
module(DefRef)to select a single module configuration byDefRefmodule(List)to select multiple module configurations byAsrPath,DefRef, or definition referenceStringmodule(AsrPath)to select a single module configuration byAsrPathmodule(String)to select a single module configuration by definition referenceStringpkg(String)to select a singleMIARPackageby short namepkg(List)to select multipleMIARPackages by short namepkgMatching(Predicate)to select packages by predicate
// You can access the API inside the closure
def importFile = paths.resolvePath("./ImportFile.arxml")
persistency.modelImport {
importArxmlArtifacts(importFile) {
// add elements to the model
addToModel() {
// add module configurations to the current ActiveEcuC
module("/MICROSAR/LinIf") // -> filter on DefRef as String
def linNmAsrPath = AsrPath.create("/ActiveEcuC/LinNm")
module(linNmAsrPath) // -> filter on Autosar path as AsrPath instance
// add InternalBehavior packages to the current model
pkg("LinIf_ib_bswmd") // -> filter on package name
}
// replace already existing elements
replaceInModel() {
// replace already existing module configurations in the current ActiveEcuC
List<String> modulesToImport = Arrays.asList("/MICROSAR/LinSM")
module(modulesToImport) // filter on list of DefRef as String
// replace already existing InternalBehavior packages in the current model
pkg("LinSM_ib_bswmd") // -> filter on package name
}
mergeIntoModel() {
// add modules to merge
}
}
}
// In case, we use importModuleConfigurations, only module configurations (not packages) are importable
def importFile = paths.resolvePath("./ImportFile.arxml")
persistency.modelImport {
importModuleConfigurations(importFile) {
// add module configurations to the current ActiveEcuC
addToModel() {
module("/MICROSAR/LinIf") // -> filter on DefRef as String
def linNmAsrPath = AsrPath.create("/ActiveEcuC/LinNm")
module(linNmAsrPath) // -> filter on Autosar path as AsrPath instance
}
// replace already existing module configurations in the current ActiveEcuC
replaceInModel() {
List<String> modulesToImport = Arrays.asList("/MICROSAR/LinSM")
module(modulesToImport) // filter on list of DefRef as String
}
mergeIntoModel() {
// add modules to merge
}
}
}
Check BSW Package Compatibility
To check if the BSW package and project are compatible, use the method checkBswPkgCompatibility.
The method checkBswPkgCompatibility(Object) verifies if a BSW migration is needed for the given project.
isCompatible() returns true if the BSW Package and project are compatible otherwise
false.
getMessage() returns the message about the BSW Package
compatibility state.
scriptTask('taskName', DV_APPLICATION) {
code {
def res
res = bswCheck.checkBswPkgCompatibility("<PATH-TO-DVJSON-FILE>")
boolean isCompatible=res.compatible
String compatibilityStatus=res.message
}
}