Opening a Project

Opening Projects

You can open an existing DaVinci Configurator project with the automation interface.

The method openProject(Object, Transformer) opens the project at the given project file location, delegates the given code to the opened IProject.

The project is automatically closed after leaving the code of the openProject(Object, Transformer) method.

The Object given as a project file is converted to Path using ScriptConverters.TO_PATH ScriptConverters.TO_PATH

Opening a project from .dvjson file
scriptTask('taskName', DV_APPLICATION) {
  code {
    // replace getProjectFileToLoad() with the path to the .dvjson file to be loaded
    projects.openProject(getProjectFileToLoad()) {

        // the opened IProject is available inside this Closure
        scriptLogger.info 'Project loaded and ready'
    }
  }
}

Opens and migrates an existing DaVinci Configurator Classic dvjson project to the new BSW Package.

The project is automatically closed after leaving the Closure code of the openAndMigrateProject(Object, Transformer) method.

Parameterized Project Load

You can also configure how a Dpa project is loaded, e.g. by disabling the generators. The method parameterizeProjectLoad(Action) returns a handle on the project specified by the given Action. Using the IOpenConfiguratorProjectApi, the Action may further customize the project's opening procedure.

The project is not opened until openProject() is called on the returned IProjectRef.

Parameterizing the project open procedure
scriptTask('taskName', DV_APPLICATION) {
  code {
    def project = projects.parameterizeProjectLoad {
      // replace getProjectFileToLoad() with the path to the .dvjson file to be loaded
      projectFile getProjectFileToLoad()
      // prevent activation of generators and validation
      loadGenerators false
      enableValidation false
    }

    project.openProject {
        // the opened IProject is available inside this Closure
        scriptLogger.info 'Project loaded and ready'
    }
  }
}

++++++

+++IOpenProjectApi contains the methods for parameterizing the process of opening a project.+++

+++

+++

DVJSON File

The method setProjectFile(Object) sets the .dvjson file of the project to be opened. The value given here is converted to Path using ScriptConverters.TO_PATH +++ScriptConverters.TO_SCRIPT_PATH+++. The given Path must be absolute.

+++

+++

Generators

Using setLoadGenerators(boolean) specifies whether or not to activate generators (including their validations) for the opened project.

+++

+++

Validation

setEnableValidation(boolean) specifies whether to activate validation for the opened project.

Open Project Details

+++

+++IProjectRef is a handle on a project not yet loaded but ready to be opened. This could be used to open the project.

IProjectRef instances can be obtained from form the following methods:

+++

+++The IProject is not really opened until IProjectRef.openProject(Transformer) is called. Here, the project is opened and the given code block is executed on the opened project. When IProjectRef.openProject(Transformer) returns the project has already been closed.

+++

+++

Advanced Open Project Use Cases

The method IProjectRef.advanced() provides methods for advanced usages of IProject instances. For example you can open a project which will not be closed when the open stack frame is left. This can be helpful for unit tests.
  • IProjectRefAdvancedUsage.openProject(): Open the project and return the IProject as reference, but you have to manually close the project.
The IProjectRefAdvancedUsage API this only for special use cases, with have very narrow scope. If you are not sure that you need it don't use it.

Opening AUTOSAR Files as Project

+++

+++

Sometimes it could be helpful to load AUTOSAR arxml files instead of a full-fledged DaVinci Configurator project. For example to modify the content of a file for test cases with the AutomationInterface, instead of using an XML editor.

You could load multiple arxml files into a temporary project, which allowed to read and write the loaded file content with the normal model APIs.

The following elements are loaded by default, without specifying the AUTOSAR files:

  • ModuleDefinitions from the BSW: To allow the usage of the BswmdModel
  • AUTOSAR standard definition: Refinement resolution of definitions

Caution: Some APIs and services may not be available for this type of project, like:

  • Validation: The validation is disabled by default
  • Generation: The generators are not loaded by default

The method parameterizeArxmlFileLoad(Action) allows to load multiple arxml files into a temporary project. The given Action is used to customize the project's opening procedure by the IOpenArxmlFilesProjectApi.

The arxml file project is not opened until openProject() is called on the returned IProjectRef.

Opening Arxml files as project
scriptTask('taskName', DV_APPLICATION) {
  code {
    def project = projects.parameterizeArxmlFileLoad {
      // Add here your arxml files to load
      arxmlFiles(arxmlFilesToLoad)
      rawAutosarDataMode = true
    }
    project.openProject {
        scriptLogger.info 'Project loaded and ready'
    }
  }
}

Arxml Files

Add arxml files to load with the method arxmlFiles(Collection). Multiple files and method calls are allowed. The given values are converted to Path instances using ScriptConverters.TO_PATH +++ScriptConverters.TO_PATH+++.

Raw AUTOSAR Data Mode

the method setRawAutosarDataMode(boolean) specifies whether or not to use the raw AUTOSAR data model.

Currently only this mode is supported! You have to set rawAutosarDataMode = true.

Note: In raw mode most of the provided services and APIs will disabled, see below for details.

Raw AUTOSAR models as Project

+++

+++

Sometimes it could be helpful to create an empty AUTOSAR model or load single ARXML file. This is called raw mode (IProjectHandlingRawApi).

You could for example create an empty AUTOSAR model add elements and then export the snippet as an ARXML file.

In raw mode most of the provided services and APIs will disabled, like:

  • Ecuc access
  • BswmdModel support
  • Generation
  • Validation
  • Workflow
  • Domain API
  • ChangeInspector
  • and more

Empty AUTOSAR model

The emptyAutosarModel(String, AsrPath, BiTransformer) method creates a new empty AUTOSAR model, only containing one MIARPackage created by this method with the path AsrPath. The passed AUTOSAR version defines the version of the AUTOSAR model, the version is specified in the format "4.2.1" or "4.0.3", ...

Create an empty AUTOSAR model
scriptTask("taskName", DV_APPLICATION) {
  code {
    def asrPkgToCreate = AsrPath.create("/MyPkg")
    def autosarVersion = "4.2.1"

    projects.raw.emptyAutosarModel(autosarVersion, asrPkgToCreate) {
      modelProject, myPkg ->
      // modelProject is the created IProject
      // myPkg is the MIARPackage specified above with asrPkgToCreate

      // Now you could use the model like any other project:
      transaction{
        // For example create a new sub package:
        def mySubPkg = myPkg.withSubPackage().byNameOrCreate("MySubPkg")
      }

      // Then export the package content
      def exportFolder = paths.getTempFolder()
      persistency.modelExport.exportModelTree(exportFolder, myPkg)
    }
  }
}