Overview
Large A complex upgrade project will may have many upgrade tasks (VBPs) and many upgrade features. The ScriptRules feature provides a means for organizing translation script rules into files based on upgrade features and then applying the content of those files to the upgrade tasks conditionally.
Script rules are placed in a ScriptRule.xml file one or more ScriptRule files which defines collections of script commands that may be conditionally merged with the translation script template to create different actual translation scripts. The ScriptRule syntax supports script parameters and conditional commands. This makes it possible, in one template, to describe a variety of common and task-specific upgrade commands.
ScriptRule files are also helpful for API-based upgrades tasks. These tasks use an EXE an custom migration executable implemented using gmslAPI rather than a XML script templategmBasic. The gmslAPI includes the ScriptRule class to assist with preparing a ScriptRule file content for use by the gmslAPI services.
Info |
---|
You may add a sample ScriptRules file from the Settings form Configuration/Template Files. |
Sample ScriptRules File
Most of the documentation for using ScriptRules is maintained in the sample ScriptRules file distributed with the product and listed below. To you this file, add it to your user folder, modify it with the rules you need, and reference it from your main script template.
Code Block | ||
---|---|---|
| ||
<!-- ScriptRule Overview AThe ScriptRule.xml file is an XML documentdefines named collections of script commands that may contain onemay orbe moreconditionally ScriptRulemerged with the template translation elements.script creating These elements and their attributesdifferent areactual describedtranslation belowscripts. This <ScriptRule id="name" Condition="condition" > elementsmakes it possible, with one ScriptRuletemplate, elementsto containautomate nameda scriptvariety commandof collectionscommon and task-specific upgrade options. The idScriptRule attributefiles isare thealso nameneeded offor theAPI-based ScriptRuleupgrade andtasks. is alsoThese used tasks inuse youran translationEXE scriptimplemented tousing activategmAPI therather rule.than a XML script template. The Condition attribute is used toThe controlgmAPI whichframework rulesincludes area mergedScriptRule intoclass providing services to to the actual translation script. <Command Condition="condition"> elements Command elements are children of a ScriptRule that specify the content that should be merged into the translation script template. The following types of Command elements are currently supported: Option Inserts commands that replace the <ScriptRule> tag in the merged transcript, typically Select, Reference, and Registry commandsintegrate ScriptRule file content with other gmAPI services. ScriptRule File Syntax A ScriptRule file is an XML document that may contain one or more ScriptRule elements. These elements and their attributes are described below. <ScriptRule id="name" Condition="condition" > elements ScriptRule elements contain named script command collections The id attribute is the name of the ScriptRule and is also used in your translation script to activate the rule. The Condition attribute is used to control which rules are merged into Compile to the actual Insertstranslation commandsscript. as children of the Compile block. Typically <Command Condition="condition"> elements Command elements are children of a ScriptRule that specify the content Select, Reference, Fix, and Refactor commandsthat should be merged into the translation script template. The following types of Command elements are currently supported: Analyse Option Inserts commands asthat children ofreplace the Analyse<ScriptRule> block tag in the PreAnalyse Inserts commands before the Analysemerged blocktranscript, typically Select, refactorReference, commandsand Registry commands. PostAnalyse Inserts commands after the Analyse block, typically refactor commands Load Author InsertsInsert commands as children of the AuthorLoad block,. typicallyTypically FixFixcommands. commands PostAuthor Compile Inserts commands after the Author block,Inserts typicallycommands topas levelchildren gmPLof commandsthe Compile block. Typically The Condition attribute is used to control which commands are merged into Select, toReference, theFix, actualand translationRefactor scriptcommands. Condition attributes A Condition attributeAnalyse may be applied to any Inserts othercommands element.as Itchildren specifiesof the Analyse block condition underPreAnalyse which the elementInserts andcommands itsbefore childrenthe willAnalyse beblock, mergedtypically withrefactor thecommands PostAnalyse template scriptInserts tocommands createafter the actualAnalyse script.block, typically refactor commands Syntax Author Inserts commands as %variable_expression%children op 'value_expression' of the Author block, typically Fix commands where PostAuthor Inserts commands after the variable_expressionAuthor block, typically alltop scriptlevel variablesgmPL andcommands other characters The Condition attribute opis used to control which commands are merged into to the actual translation script. Condition ==attributes true if %variable_expression% == value_expressionA Condition attribute may be applied to any other element. It specifies the condition under which the element and its children will !=be truemerged ifwith %variable_expression%the != value_expression template script to create the actual script. Syntax =~ true if %variable_expression% matchesop regex 'value_expression' where variable_expression all script variables and other characters !~ true if %variable_expression%op does not match regex value_expression == true if %variable_expression% == value_expression value_expression a constant string or regex pattern != true Comparisons are case insensitive using trimmed strings.if %variable_expression% != value_expression =~ true if %variable_expression% matches regex value_expression Relational operators are not supported, but you can use Condition="var1.var2=='val1.val2'" to simulate locical AND !~ true if %variable_expression% does Condition="var=~'val1|val2'" not match regex value_expression to simulate logical OR For example Condition="%SrcName%=='ScanToolUI'" indicates that the associated value_expression a element will only be merged for upgrade tasks having SrcName equal constant string or regex pattern Comparisons are case insensitive using trimmed strings. to the string "ScanToolUI". Relational operators are <ForEach>,not <Iterator>supported, andbut <Each>you elementscan use ForEach elements are children of the ScriptRule. They allow repeating Command elements for each file in the source project folder that meet certain criteria. This element may also be used to copy files from the source project folder to the .NET project folder. The set of files to iterate over is defined by a <Iterator/FileInfo> element according to its attributes: Condition="var1.var2=='val1.val2'" to simulate locical AND Condition="var=~'val1|val2'" to simulate logical OR For example Condition="%SrcName%=='ScanToolUI'" indicates that the associated element will only be merged for upgrade tasks having SrcName equal to the string "ScanToolUI". The FileInfo Criteria attribute is a search pattern (e.g. *.wav) used to <ForEach>, <Iterator>, and <Each> elements get filesForEach fromelements theare sourcechildren folder.of the ScriptRule. They allow repeating Command elements for Theeach FileInfofile Filesin attributea mayspecified befolder "All"that ormeets "Top". The default iscertain "All"criteria. This element may also If Files="All", the root of the source folder and all of its sub-folders are be used to copy files from the specified folder to the .NET project folder. searched; if Files="Top", only theThe rootset of thefiles to sourceiterate folderover is searched.defined by a <Iterator/FileInfo> element The CopyFilesaccording attribute may be "On" or "Off".to its attributes: The defaultFileInfo@Criteria attribute is "On". If a search pattern (e.g. *.wav) used to CopyFiles="on", the get files found infrom the source project folder. will be copied toThe theFileInfo@Folder correspondingattribute .NETspecifies projectthe folder withto directorysearch structurefor preservedfiles. The foldersdefault andis filesthe aresource copiedfolder priorassociated towith the translationupgrade processtask. %SrcFolder%, %UserFolder%, and %ProjFolder% Withinscript thevariables <Each>may block, the notation %FileInfo.member% may also be used. to refer The FileInfo@Recurse toattribute informationmay aboutbe the"All" files found in the source folder: or "Top". The default is "All". %FileInfo.RelativeName%: path relative toIf Files="All", the root of the source projectfolder rootand all of %FileInfo.Name%: file nameits sub-folders are %FileInfo.FullName%: full path %FileInfo.DirectoryName%: parent folder name Activating a ScriptRulesearched; if Files="Top", only the root of the source folder is searched. AddingThe aFileInfo@CopyFiles <ScriptRule>attribute tagmay tobe the"On" script requests the merging of the named script collection. or "Off". The default is "On". If <ScriptRule idCopyFiles="nameon", attributeListthe />files found in the source project Thefolder idwill attributebe specifiescopied the command collection to addthe corresponding .NET project folder with directory Thestructure attributeListpreserved. specifies variables that mayThe befolders referencedand elsewherefiles are copied prior to inthe thetranslation ScriptRuleprocess. Variable references are case insensitive. Within the <Each> Forblock, example the followingnotation ScriptRule tag: <ScriptRule id="IncludeResources" Criteria="*.wav" /> requests loading the command collection named IncludeResouces and creates a ScriptRule variable named %Criteria% with value = "*.wav" Specifying the ScriptRule file By default, the ScriptRule XML is located in a file called ScriptRule.xml and is typically kept in the workspace\usr folder. If desired, you may specify an alternate location using a FileName attribute%FileInfo.member% may be used to refer to information about the files found in the source folder: %FileInfo.RelativeName%: path relative to the source project root %FileInfo.Name%: file name %FileInfo.FullName%: full path %FileInfo.DirectoryName%: parent folder name Activating a ScriptRule Adding a <ScriptRule> tag to the script requests the merging of the named script collection. <ScriptRule id="name" attributeList /> The id attribute specifies the command collection to add. The attributeList specifies variables that may be referenced elsewhere in the ScriptRule. Variable references are case insensitive. For example the following ScriptRule tag: <ScriptRule id="IncludeResources" Criteria="*.wav" /> requests loading the command collection named IncludeResouces and creates a ScriptRule variable named %Criteria% with value = "*.wav" Specifying the ScriptRule file By default, the ScriptRule XML is located in a file called ScriptRule.xml and is typically kept in the workspace\usr folder. If desired, you may specify an alternate location using a FileName attribute for example: <ScriptRule id="ADODBUpgrade" FileName="..\usr\ADODB.Rules.xml" /> The above loads the ScriptRule file named ..\usr\ADODB.Rules.xml (relative to the workspace log folder). And then merges in the ScriptRule element having id="ADODBUpgrade": <ScriptRule id="ADODBUpgrade" Condition="%TaskTag%=='upg'" > ... rules to perform ADODBUpgrade for tasks having TaskTag=='upg' ... </ScriptRule> Line Pragma The token %LN% placed in a ScriptRule file will expand to the form @ScriptRulePath@LineNumber@ in actual script. The expanded form may then be parsed by gmStudio to direct the text editor to that line of code. For example: <Replace status="active" name="%LN% Add Reference to dlls: gmRTL.Core and gmRTL.WPF" lang="vbp"> becomes <Replace status="active" name="=@C:\gmTestBed\WPFScanTool\proj_csh\usr\ScriptRules_csh.xml@105@ Add Reference to dlls: gmRTL.Core and gmRTL.WPF" lang="vbp"> This data will be placed into the Translation Log. If the log is viewed as a Grid in gmStudio, double clicking the grid line will take you to the original line in the Script Rule file. See Also: For more information, see the "Eval" VB6 Upgrade sample here https://portal.greatmigrations.com/display/GMG/Samples --> <ScriptRules> <!-- Here is a sample of the ScriptRule syntax --> <ScriptRule id="BasicRulesStandardUpgrade"> <Option> <!-- directories for configuration files --> <select Target="%UserFolder%" /> <Select Local="%IdfFromCodeFolder%" /> <Select System="%IdfFromIdlFolder%" /> <!-- translation options --> <Select Progress="1" /> <Select DevEnv="%DevEnv%" /> <Select Dialect="%Dialect%" /> <Select BuildFile="local" /> <!-- directories for deployment and external assemblies --> <select VirtualRoot="%VirtualRoot%" /> <Select DeployLocation="%NetProjFolder%" /> <Select Library="%RuntimeFolder%" /> <!-- custom processing commands --> </Option> <Compile Condition="%SrcName%=~'Project1|Project2'" > <!-- pre-edits --> <!-- compile refactors commands--> </Compile> <PreAnalyse> <!-- pre-analyse refactor commands --> </PreAnalyse> <PostAnalyse> <!-- post-analyse refactors commands--> </PostAnalyse> <Author Condition="%SrcName%=~'Project1|Project2'" > <!-- post-edits --> </Author> <PostAuthor> <!-- post-author refactors commands--> </PostAuthor> </ScriptRule> </ScriptRules> </ScriptRules> |