From 6dc4255bc53908e8e20acdc7b6c65db891733a38 Mon Sep 17 00:00:00 2001 From: Peter Stange Date: Fri, 29 May 2020 11:47:24 +0200 Subject: [PATCH] Add parameter for EA database connection and filter for packages to exportEA script and gradle config --- Config.groovy | 22 ++++ scripts/exportEA.gradle | 18 +++- scripts/exportEAP.vbs | 150 +++++++++++++++++---------- src/docs/manual/05_contributors.adoc | 1 + 4 files changed, 134 insertions(+), 57 deletions(-) diff --git a/Config.groovy b/Config.groovy index f419689de..bd6e82337 100644 --- a/Config.groovy +++ b/Config.groovy @@ -114,3 +114,25 @@ confluence.with { // proxy = [host: 'my.proxy.com', port: 1234, schema: 'http'] } //end::confluenceConfig[] +//***************************************************************************************** +//tag::exportEAConfig[] +//Configuration for the export script 'exportEA.vbs'. +// The following parameters can be used to change the default behaviour of 'exportEA'. +// All parameter are optionally. +// Parameter 'connection' allows to select a certain database connection by using the ConnectionString as used for +// directly connecting to the project database instead of looking for EAP/EAPX files inside and below the 'src' folder. +// Parameter 'packageFilter' is an array of package GUID's to be used for export. All images inside and in all packages below the package represented by its GUID are exported. +// A packageGUID, that is not found in the currently opened project, is silently skipped. +// PackageGUID of multiple project files can be mixed in case multiple projects have to be opened. + +exportEA.with { +// OPTIONAL: Set the connection to a certain project or comment it out to use all project files inside the src folder or its child folder. +// connection = "DBType=1;Connect=Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=[THE_DB_NAME_OF_THE_PROJECT];Data Source=[server_hosting_database.com];LazyLoad=1;" +// OPTIONAL: Add one or multiple packageGUIDs to be used for export. All packages are analysed, if no packageFilter is set. +// packageFilter = [ +// "{A237ECDE-5419-4d47-AECC-B836999E7AE0}", +// "{B73FA2FB-267D-4bcd-3D37-5014AD8806D6}" +// ] +} +//end::exportEAConfig[] + \ No newline at end of file diff --git a/scripts/exportEA.gradle b/scripts/exportEA.gradle index 718980533..9a88a0c99 100644 --- a/scripts/exportEA.gradle +++ b/scripts/exportEA.gradle @@ -69,8 +69,24 @@ use `gradle exportEA` to re-export files new File(docDir, 'src/docs/ea/readme.ad').write(readme) } doLast { + logger.info("docToolchain > exportEA: "+docDir) + logger.info("docToolchain > exportEA: "+mainConfigFile) + def configFile = new File(docDir, mainConfigFile) + def config = new ConfigSlurper().parse(configFile.text) + def scriptParameterString = "" + if(!config.exportEA.connection.isEmpty()){ + logger.info("docToolchain > exportEA: found "+config.exportEA.connection) + scriptParameterString = scriptParameterString + "-c \"${config.exportEA.connection}\"" + } + if (!config.exportEA.packageFilter.isEmpty()){ + def packageFilterToCreate = config.exportEA.packageFilter as List + logger.info("docToolchain > exportEA: package filter list size: "+packageFilterToCreate.size()) + packageFilterToCreate.each { packageFilter -> + scriptParameterString = scriptParameterString + " -p \"${packageFilter}\"" + } + } //execute through cscript in order to make sure that we get WScript.echo right - "%SystemRoot%\\System32\\cscript.exe //nologo ${projectDir}/scripts/exportEAP.vbs".executeCmd() + "%SystemRoot%\\System32\\cscript.exe //nologo ${projectDir}/scripts/exportEAP.vbs ${scriptParameterString}".executeCmd() //the VB Script is only capable of writing iso-8859-1-Files. //we now have to convert them to UTF-8 new File(docDir, 'src/docs/ea/.').eachFileRecurse { file -> diff --git a/scripts/exportEAP.vbs b/scripts/exportEAP.vbs index a5a42ef30..8a9e0d651 100644 --- a/scripts/exportEAP.vbs +++ b/scripts/exportEAP.vbs @@ -41,7 +41,7 @@ If (prefix<>"") Then post = "_" End If - MakeDir(path&prefix&post) + MakeDir(path&prefix&post) set objFile = objFSO.OpenTextFile(path&prefix&post&strFileName&".ad",ForAppending, True) name = currentElement.Name name = Replace(name,vbCr,"") @@ -123,39 +123,38 @@ End Sub Sub SaveDiagram(currentModel, currentDiagram) - ' Open the diagram - Repository.OpenDiagram(currentDiagram.DiagramID) + ' Open the diagram + Repository.OpenDiagram(currentDiagram.DiagramID) - ' Save and close the diagram - If (currentModel.Name="Model") Then - ' When we work with the default model, we don't need a sub directory - path = "/src/docs/images/ea/" - Else - path = "/src/docs/images/ea/" & currentModel.Name & "/" - End If - diagramName = Replace(currentDiagram.Name," ","_") - diagramName = Replace(diagramName,vbCr,"") - diagramName = Replace(diagramName,vbLf,"") - filename = path & diagramName & ".png" - MakeDir("." & path) - projectInterface.SaveDiagramImageToFile(fso.GetAbsolutePathName(".")&filename) - ' projectInterface.putDiagramImageToFile currentDiagram.DiagramID,fso.GetAbsolutePathName(".")&filename,1 - WScript.echo " extracted image to ." & filename - Repository.CloseDiagram(currentDiagram.DiagramID) - For Each diagramElement In currentDiagram.DiagramObjects - Set currentElement = Repository.GetElementByID(diagramElement.ElementID) - WriteNote currentModel, currentElement, currentElement.Notes, diagramName&"_notes" - Next - For Each diagramLink In currentDiagram.DiagramLinks - set currentConnector = Repository.GetConnectorByID(diagramLink.ConnectorID) - WriteNote currentModel, currentConnector, currentConnector.Notes, diagramName&"_links" - Next + ' Save and close the diagram + If (currentModel.Name="Model") Then + ' When we work with the default model, we don't need a sub directory + path = "/src/docs/images/ea/" + Else + path = "/src/docs/images/ea/" & currentModel.Name & "/" + End If + diagramName = Replace(currentDiagram.Name," ","_") + diagramName = Replace(diagramName,vbCr,"") + diagramName = Replace(diagramName,vbLf,"") + filename = path & diagramName & ".png" + MakeDir("." & path) + projectInterface.SaveDiagramImageToFile(fso.GetAbsolutePathName(".")&filename) + ' projectInterface.putDiagramImageToFile currentDiagram.DiagramID,fso.GetAbsolutePathName(".")&filename,1 + WScript.echo " extracted image to ." & filename + Repository.CloseDiagram(currentDiagram.DiagramID) + For Each diagramElement In currentDiagram.DiagramObjects + Set currentElement = Repository.GetElementByID(diagramElement.ElementID) + WriteNote currentModel, currentElement, currentElement.Notes, diagramName&"_notes" + Next + For Each diagramLink In currentDiagram.DiagramLinks + set currentConnector = Repository.GetConnectorByID(diagramLink.ConnectorID) + WriteNote currentModel, currentConnector, currentConnector.Notes, diagramName&"_links" + Next End Sub ' ' Recursively saves all diagrams under the provided package and its children ' Sub DumpDiagrams(thePackage,currentModel) - Set currentPackage = thePackage ' export element notes @@ -194,23 +193,44 @@ End If End Sub - Function SearchEAProjects(path) - - For Each folder In path.SubFolders - SearchEAProjects folder - Next - - For Each file In path.Files - If fso.GetExtensionName (file.Path) = "eap" OR fso.GetExtensionName (file.Path) = "eapx" Then - WScript.echo "found "&file.path - If (Left(file.name, 1) = "_") Then - WScript.echo "skipping, because it start with `_` (replication)" - Else - OpenProject(file.Path) - End If - End If - Next - + Function SearchEAProjects(path) + For Each folder In path.SubFolders + SearchEAProjects folder + Next + + For Each file In path.Files + If fso.GetExtensionName (file.Path) = "eap" OR fso.GetExtensionName (file.Path) = "eapx" Then + WScript.echo "found "&file.path + If (Left(file.name, 1) = "_") Then + WScript.echo "skipping, because it start with `_` (replication)" + Else + OpenProject(file.Path) + End If + End If + Next + End Function + + 'Gets the package object as referenced by its GUID from the Enterprise Architect project. + 'Looks for the model node, the package is a child of as it is required for the diagram export. + 'Calls the Sub routine DumpDiagrams for the model and package found. + 'An error is printed to console only if the packageGUID is not found in the project. + Function DumpPackageDiagrams(EAapp, packageGUID) + WScript.echo "DumpPackageDiagrams" + WScript.echo packageGUID + Dim package + Set package = EAapp.Repository.GetPackageByGuid(packageGUID) + If (package Is Nothing) Then + WScript.echo "invalid package - as package is not part of the project" + Else + Dim currentModel + Set currentModel = package + while currentModel.IsModel = false + Set currentModel = EAapp.Repository.GetPackageByID(currentModel.parentID) + wend + ' Iterate through all child packages and save out their diagrams + ' save all diagrams of package itself + call DumpDiagrams(package, currentModel) + End If End Function Sub OpenProject(file) @@ -238,19 +258,11 @@ WScript.echo file GUID = Mid(file, InStrRev(file,"{")+0,38) WScript.echo GUID - Dim package - set package = EAapp.Repository.GetPackageByGuid(GUID) - WScript.echo TypeName(package) - set currentModel = package - while currentModel.IsModel = false - set currentModel = EAapp.Repository.GetPackageByID(currentModel.parentID) - WScript.echo currentModel.parentID - wend ' Iterate through all child packages and save out their diagrams - For Each childPackage In package.Packages - call DumpDiagrams(childPackage, currentModel) - Next + call DumpPackageDiagrams(EAapp, GUID) Else + If packageFilter.Count = 0 Then + WScript.echo "done" ' Iterate through all model nodes For Each currentModel In Repository.Models ' Iterate through all child packages and save out their diagrams @@ -258,13 +270,39 @@ call DumpDiagrams(childPackage,currentModel) Next Next + Else + ' Iterate through all packages found in the package filter given by script parameter. + For Each packageGUID In packageFilter + call DumpPackageDiagrams(EAapp, packageGUID) + Next + End If End If EAapp.Repository.CloseFile() End Sub + Private connectionString + Private packageFilter + Set packageFilter = CreateObject("System.Collections.ArrayList") + Set objArguments = WScript.Arguments + Dim argCount + argCount = 0 + While objArguments.Count > argCount+1 + Select Case objArguments(argCount) + Case "-c" + connectionString = objArguments(argCount+1) + Case "-p" + packageFilter.Add objArguments(argCount+1) + End Select + argCount = argCount + 2 + WEnd set fso = CreateObject("Scripting.fileSystemObject") WScript.echo "Image extractor" + If IsEmpty(connectionString) Then WScript.echo "looking for .eap(x) files in " & fso.GetAbsolutePathName(".") & "/src" 'Dim f As Scripting.Files SearchEAProjects fso.GetFolder("./src") + Else + WScript.echo "opening database connection now" + OpenProject(connectionString) + End If WScript.echo "finished exporting images" diff --git a/src/docs/manual/05_contributors.adoc b/src/docs/manual/05_contributors.adoc index c01fb4f09..acfc33259 100644 --- a/src/docs/manual/05_contributors.adoc +++ b/src/docs/manual/05_contributors.adoc @@ -46,6 +46,7 @@ Here is an incomplete and unordered list of contributors: - https://github.com/mindyou[Maarten Gribnau] - https://github.com/mpriess[Michael Prieß] - https://github.com/stehlih[Heiko Stehli] +- https://github.com/peterstange[Peter Stange] - https://github.com/nilsmahlstaedt[Nils Mahlstädt] @ https://github.com/hmmh[hmmh] (please update your entry to match your preferences! :-)