Efficient way to batch import XMI in Enterprise Architect

Our team uses Enterprise Architect version 10 and SVN for the repository. Since the EAP file size is quite large (for example, 80 MB), we export each package to a separate XMI and save it in SVN . The EAP file itself is EAP after some milestone. The problem is the synchronization of the EAP file with the work of the employee during development, we need to import a large number of XMI (for example, the total number may be 500 files).

I know that after updating the EAP file, we can use the Control Package -> Get All Latest. Therefore, this problem occurs only during parallel development.

We used keyboard shorcuts for import, as shown below:

  • Ctrl + Alt + I (Import Package from XMI File)
  • Select a file name to import
  • Alt + I (Import)
  • Enter (Yes)
  • Repeat steps 2 through 4 until the module completes.

But still importing several hundred files is inefficient.

I checked that the management pack has batch import / export. Batch import / export works when I explicitly hardcoded the XMI Filename , but the options are not available when using version control (batch import / export options are gray).

Are there any better ways to sync EAP and XMI files?

+6
source share
2 answers

EA has a scripting interface. You can automate the import using this. I have not used it, but probably not bad.

I'm not sure I fully understand your work environment, but I have some common points that may be of interest. Perhaps if you use EA differently (especially my first point below), the need to import packages might disappear.

Multiworker

Firstly, several people can work in one EAP file at a time. An EAP file is nothing more than an Access database file, and EA uses a lock to stop multiple people from editing the same package at the same time. But you can comfortably several times simultaneously edit different packages in one EAP file. A good way to do this is to place the EAP file in a file share.

Integrated Version Control

Secondly, EA can interact directly with SVN (and other version control systems). Cm. . In short, you can configure your EAP file so that individual packages (and all below) are controlled by SVN. Then you can check a single package, edit it, check it back. Or you can check the entire branch below the package (including subpackages that are themselves controlled by SVN).

Under the hood, EA imports and exports XMI files and validates and displays them from SVN, while the EAP file is always the main version. Just like what you do manually, but automated. This makes sense, given that you can use one single EAP file. You have to be a little careful to go back - links originating from objects in old versions of one package may point to objects that no longer exist (but you can look at import log errors to make sure that this is so). He gets a little used to it, but it works very well.

In addition, the built-in function of the basic base package is all you need and works very well, especially if you use the same EAP file.

Large database engine

Third, you do not have to have an EAP file. The database of models can be in any suitable database system (MySQL, SQL Server, Oracle, etc.). Thus, you get all sorts of options for expanding your use, which is similar to WAN / Internet, etc.

In short, Sparx fully understood how EA can be used in a multi-workplace environment and should be used.

+4
source

I created an EA script using JScript to automate

Here the script performs the export:

 !INC Local Scripts.EAConstants-JScript /* * Script Name : Export List of SVN Packages * Author : SDK * Purpose : Export a package and all of its subpackages information related to version * controlled. The exported file then can be used to automatically import * the XMIs * Date : 30 July 2013 * HOW TO USE : 1. Select the package that you would like to export in the Project Browser * 2. Change the output filepath in this script if necessary. * By default it is "D:\\EAOutput.txt" * 3. Send the output file to your colleague who wanted to import the XMIs */ var f; function main() { // UPDATE THE FOLLOWING OUTPUT FILE PATH IF NECESSARY var filename = "D:\\EAOutput.txt"; var ForReading = 1, ForWriting = 2, ForAppending = 8; Repository.EnsureOutputVisible( "Script" ); Repository.ClearOutput( "Script" ); Session.Output("Start generating output...please wait..."); var treeSelectedType = Repository.GetTreeSelectedItemType(); switch ( treeSelectedType ) { case otPackage: { var fso = new ActiveXObject("Scripting.FileSystemObject"); f = fso.OpenTextFile(filename, ForWriting, true); var selectedObject as EA.Package; selectedObject = Repository.GetContextObject(); reportPackage(selectedObject); loopChildPackages(selectedObject); f.Close(); Session.Output( "Done! Check your output at " + filename); break; } default: { Session.Prompt( "This script does not support items of this type.", promptOK ); } } } function loopChildPackages(thePackage) { for (var j = 0 ; j < thePackage.Packages.Count; j++) { var child as EA.Package; child = thePackage.Packages.GetAt(j); reportPackage(child); loopChildPackages(child); } } function getParentPath(childPackage) { if (childPackage.ParentID != 0) { var parentPackage as EA.Package; parentPackage = Repository.GetPackageByID(childPackage.ParentID); return getParentPath(parentPackage) + "/" + parentPackage.Name; } return ""; } function reportPackage(thePackage) { f.WriteLine("GUID=" + thePackage.PackageGUID + ";" + "NAME=" + thePackage.Name + ";" + "VCCFG=" + getVCCFG(thePackage) + ";" + "XML=" + thePackage.XMLPath + ";" + "PARENT=" + getParentPath(thePackage).substring(1) + ";" ); } function getVCCFG(thePackage) { if (thePackage.IsVersionControlled) { var array = new Array(); array = (thePackage.Flags).split(";"); for (var z = 0 ; z < array.length; z++) { var pos = array[z].indexOf('='); if (pos > 0) { var key = array[z].substring(0, pos); var value = array[z].substring(pos + 1); if (key=="VCCFG") { return (value); } } } } return ""; } main(); 

And the script execute the import:

 !INC Local Scripts.EAConstants-JScript /* * Script Name : Import List Of SVN Packages * Author : SDK * Purpose : Imports a package with all of its sub packages generated from * "Export List Of SVN Packages" script * Date : 01 Aug 2013 * HOW TO USE : 1. Get the output file generated by "Export List Of SVN Packages" script * from your colleague * 2. Get the XMIs in the SVN local copy * 3. Change the path to the output file in this script if necessary (var filename). * By default it is "D:\\EAOutput.txt" * 4. Change the path to local SVN * 5. Run the script */ var f; var svnPath; function main() { // CHANGE THE FOLLOWING TWO LINES ACCORDING TO YOUR INPUT AND LOCAL SVN COPY var filename = "D:\\EAOutput.txt"; svnPath = "D:\\svn.xxx.com\\yyy\\docs\\design\\"; var ForReading = 1, ForWriting = 2, ForAppending = 8; Repository.EnsureOutputVisible( "Script" ); Repository.ClearOutput( "Script" ); Session.Output("[INFO] Start importing packages from " + filename + ". Please wait..."); var fso = new ActiveXObject("Scripting.FileSystemObject"); f = fso.OpenTextFile(filename, ForReading); // Read from the file and display the results. while (!f.AtEndOfStream) { var r = f.ReadLine(); parseLine(r); Session.Output("--------------------------------------------------------------------------------"); } f.Close(); Session.Output("[INFO] Finished"); } function parseLine(line) { Session.Output("[INFO] Parsing " + line); var array = new Array(); array = (line).split(";"); var guid; var name; var isVersionControlled; var xmlPath; var parentPath; isVersionControlled = false; xmlPath = ""; for (var z = 0 ; z < array.length; z++) { var pos = array[z].indexOf('='); if (pos > 0) { var key = array[z].substring(0, pos); var value = array[z].substring(pos + 1); if (key=="GUID") { guid = value; } else if (key=="NAME") { name = value; } else if (key=="VCCFG") { if (value != "") { isVersionControlled = true; } } else if (key=="XML") { if (isVersionControlled) { xmlPath = value; } } else if (key=="PARENT") { parentPath = value; } } } // Quick check for target if already exist to speed up process var targetPackage as EA.Package; targetPackage = Repository.GetPackageByGuid(guid); if (targetPackage != null) { // target exists, do not do anything Session.Output("[DEBUG] Target package \"" + name + "\" already exist"); return; } var paths = new Array(); var packages = new Array(paths.Count); for (var i = 0; i < paths.Count; i++) { packages[i] = null; } paths = (parentPath).split("/"); if (paths.Count < 2) { Session.Output("[INFO] Skipped root or level1"); return; } packages[0] = selectRoot(paths[0]); packages[1] = selectPackage(packages[0], paths[1]); if (packages[1] == null) { Session.Output("[ERROR] Cannot find " + paths[0] + "/" + paths[1] + "in Project Browser"); return; } for (var j = 2; j < paths.length; j++) { packages[j] = selectPackage(packages[j - 1], paths[j]); if (packages[j] == null) { Session.Output("[DEBUG] Creating " + packages[j].Name); // create the parent package var parent as EA.Package; parent = Repository.GetPackageByGuid(packages[j-1].PackageGUID); packages[j] = parent.Packages.AddNew(paths[j], ""); packages[j].Update(); parent.Update(); parent.Packages.Refresh(); break; } } // Check if name (package to import) already exist or not var targetPackage = selectPackage(packages[paths.length - 1], name); if (targetPackage == null) { if (xmlPath == "") { Session.Output("[DEBUG] Creating " + name); // The package is not SVN controlled var newPackage as EA.Package; newPackage = packages[paths.length - 1].Packages.AddNew(name,""); Session.Output("New GUID = " + newPackage.PackageGUID); newPackage.Update(); packages[paths.length - 1].Update(); packages[paths.length - 1].Packages.Refresh(); } else { // The package is not SVN controlled Session.Output("[DEBUG] Need to import: " + svnPath + xmlPath); var project as EA.Project; project = Repository.GetProjectInterface; var result; Session.Output("GUID = " + packages[paths.length - 1].PackageGUID); Session.Output("GUID XML = " + project.GUIDtoXML(packages[paths.length - 1].PackageGUID)); Session.Output("XMI file = " + svnPath + xmlPath); result = project.ImportPackageXMI(project.GUIDtoXML(packages[paths.length - 1].PackageGUID), svnPath + xmlPath, 1, 0); Session.Output(result); packages[paths.length - 1].Update(); packages[paths.length - 1].Packages.Refresh(); } } else { // target exists, do not do anything Session.Output("[DEBUG] Target package \"" + name + "\" already exist"); } } function selectPackage(thePackage, childName) { var childPackage as EA.Package; childPackage = null; if (thePackage == null) return null; for (var i = 0; i < thePackage.Packages.Count; i++) { childPackage = thePackage.Packages.GetAt(i); if (childPackage.Name == childName) { Session.Output("[DEBUG] Found " + childName); return childPackage; } } Session.Output("[DEBUG] Cannot find " + childName); return null; } function selectRoot(rootName) { for (var y = 0; y < Repository.Models.Count; y++) { root = Repository.Models.GetAt(y); if (root.Name == rootName) { return root; } } return null; } main(); 
+1
source

Source: https://habr.com/ru/post/945767/


All Articles