Class BuildlangExecution

    • Field Detail

      • PARAM_SOURCE

        public static final java.lang.String PARAM_SOURCE
        The default source project parameter (called "source").
        See Also:
        Constant Field Values
      • PARAM_TARGET

        public static final java.lang.String PARAM_TARGET
        The default target project parameter (called "target").
        See Also:
        Constant Field Values
      • PARAM_CONFIG

        public static final java.lang.String PARAM_CONFIG
        The default configuration parameter (called "config").
        See Also:
        Constant Field Values
      • DEFAULT_MAIN_RULE

        public static final java.lang.String DEFAULT_MAIN_RULE
        The name of the default main rule (called "main").
        See Also:
        Constant Field Values
      • base

        private java.io.File base
      • startRuleName

        private java.lang.String startRuleName
      • failed

        private java.util.List<Rule> failed
      • enableRuleElementFailed

        private boolean enableRuleElementFailed
      • stop

        private boolean stop
      • terminatables

        private java.util.Set<ITerminatable> terminatables
    • Constructor Detail

      • BuildlangExecution

        public BuildlangExecution​(ITracer tracer,
                                  java.io.File base,
                                  java.util.Map<java.lang.String,​java.lang.Object> parameter)
        Creates a new execution environment.
        Parameters:
        tracer - the tracer
        base - the base directory for making files absolute
        parameter - the top-level parameter for the script to be executed
      • BuildlangExecution

        public BuildlangExecution​(ITracer tracer,
                                  java.io.File base,
                                  java.lang.String startRuleName,
                                  java.util.Map<java.lang.String,​java.lang.Object> parameter)
        Creates a new execution environment.
        Parameters:
        tracer - the tracer
        base - the base directory for making files absolute
        startRuleName - the name of the start rule; if multiple source projects are given, as a convention the first one shall the top-level project that needs to be executed.
        parameter - the top-level parameter for the script to be executed
      • BuildlangExecution

        protected BuildlangExecution​(RuntimeEnvironment environment)
        Creates a new execution visitor for import expression evaluation.
        Parameters:
        environment - the runtime environment to be used for expression evaluation
    • Method Detail

      • stop

        public void stop()
        Stops the execution, e.g., within endless loops constructed by the user.
      • setEnableRuleElementFailed

        protected boolean setEnableRuleElementFailed​(boolean enableRuleElementFailed)
        Enables / disables failed rule elements in some situations.
        Parameters:
        enableRuleElementFailed - whether rule elements shall be enabled
        Returns:
        the old state
      • createRuntimeEnvironment

        protected RuntimeEnvironment createRuntimeEnvironment()
        Creates the initial runtime environment.
        Returns:
        the initial runtime environment
      • peekRuleStack

        protected RuleExecutionContext peekRuleStack()
        Returns the top element on the rule stack.
        Returns:
        the top element
      • getRuleStackSize

        protected int getRuleStackSize()
        Returns the size of the rule stack.
        Returns:
        the size of the rule stack
      • initialize

        private void initialize()
        Does common initializations based on already set values (requires {@link #environment) to be set properly).
      • createExecutableRulesInstance

        protected ExecutableRules createExecutableRulesInstance()
        Creates an executable rules instance.
        Returns:
        the created instance
      • absolute

        private static java.io.File absolute​(java.lang.String path,
                                             java.io.File base)
        Makes path absolute with respect to base if necessary.
        Parameters:
        path - the file to be made absolute
        base - the base path
        Returns:
        the absolute file
      • getFailedCount

        public int getFailedCount()
        Returns the number of failed rules.
        Returns:
        the number of failed rules
      • getFailed

        public Rule getFailed​(int index)
        Returns the specified failed rule.
        Parameters:
        index - the index of the failed rule
        Returns:
        the failed rule
        Throws:
        java.lang.IndexOutOfBoundsException - if index < 0 || index >= getFailedCount()
      • visitScript

        public java.lang.Object visitScript​(Script script)
                                     throws VilException
        Description copied from interface: IVisitor
        Visits a script.
        Specified by:
        visitScript in interface IVisitor
        Parameters:
        script - the project instance
        Returns:
        the result of visiting the given statement (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • executeScript

        private java.lang.Object executeScript​(Script script,
                                               RuleCallExpression start)
                                        throws VilException
        Executes the given script starting at start.
        Parameters:
        script - the script to be executed
        start - the start rule (may be null to determine main)
        Returns:
        the result of the execution
        Throws:
        VilException - if the execution fails
      • release

        public void release​(boolean releaseDefault)
        Description copied from class: ExecutionVisitor
        Releases the resources allocated by this execution.
        Overrides:
        release in class ExecutionVisitor<Script,​AbstractRule,​VariableDeclaration,​Resolver>
        Parameters:
        releaseDefault - shall also default artifacts, i.e., artifacts that cannot be assigned to a source / target artifact model be released? May affect execution of other VIL models.
      • executeDefault

        protected java.lang.Object executeDefault​(Script script)
                                           throws VilException
        Executes the given script via its default entry point.
        Parameters:
        script - the script to be executed
        Returns:
        the execution result
        Throws:
        VilException - if execution fails
      • getTargetPath

        private java.io.File getTargetPath​(Script script,
                                           java.util.Map<java.lang.String,​java.lang.Object> scriptParam)
        Returns the target path or base.
        Parameters:
        script - the script to obtain the target path from
        scriptParam - the script parameters to consider (additional, may be null)
        Returns:
        the path to the target project or base if not found
      • processProperties

        protected void processProperties​(Script script,
                                         java.io.File base)
                                  throws VilException
        Processes the LoadProperties.
        Parameters:
        script - the script to process the properties for
        base - the base path to make relative paths absolute
        Throws:
        VilException - in case that something goes wrong
      • loadProperties

        private void loadProperties​(java.io.File file,
                                    java.util.Properties prop,
                                    java.lang.String os)
                             throws VilException
        Loads properties from file into prop possibly overriding existing properties.
        Parameters:
        file - the file name
        prop - the loaded properties (to be modified as a side effect)
        os - if not null to be inserted after the last "." with a following ".". If file not exists, no exception will be thrown.
        Throws:
        VilException - in case of loading problems
      • evaluateExternalValue

        private java.lang.Object evaluateExternalValue​(VariableDeclaration var,
                                                       java.lang.String value)
                                                throws VilException
        Evaluates an external value for a given var.
        Parameters:
        var - the variable to evaluate the value for
        value - the external value
        Returns:
        the actual value for var
        Throws:
        VilException - in case that conversion does not work
      • checkConstants

        private void checkConstants​(Script script)
                             throws VilException
        Checks the constant values for proper initialization.
        Parameters:
        script - the project to process the properties for
        Throws:
        VilException - in case that something goes wrong
      • postprocessSystemCallArgument

        private java.lang.String postprocessSystemCallArgument​(java.lang.String argument)
        Post processes system call arguments, e.g., by removing line separators.
        Parameters:
        argument - the argument to be processed
        Returns:
        the processed argument
      • visitStrategyCallExpressionImpl

        public java.lang.Object visitStrategyCallExpressionImpl​(StrategyCallExpression call)
                                                         throws VilException
        Implements the strategy call execution of an executable call.
        Parameters:
        call - the call to execute
        Returns:
        the execution result
        Throws:
        VilException - in case of execution problems
      • addImplicitParamters

        protected void addImplicitParamters​(java.util.Map<java.lang.String,​java.lang.Object> named)
        Adds additional implicit named parameters.
        Overrides:
        addImplicitParamters in class EvaluationVisitor
        Parameters:
        named - the named parameters
      • visitLoadProperties

        public java.lang.Object visitLoadProperties​(LoadProperties properties)
                                             throws VilException
        Description copied from interface: IVisitor
        Visits a load properties directive.
        Specified by:
        visitLoadProperties in interface IVisitor
        Parameters:
        properties - the load properties representation
        Returns:
        the result of visiting the given statement (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • registerParameter

        private void registerParameter​(AbstractRule rule)
                                throws VilException
        Registers the parameter of rule.
        Parameters:
        rule - the rule to register the parameter for
        Throws:
        VilException - in case of any execution error
      • addVariablesToFinder

        private void addVariablesToFinder​(Rule rule,
                                          Rule.Side side,
                                          boolean matchVariables)
        Adds the variables of rule at the given side to the variableFinder.
        Parameters:
        rule - the rule to take the variables from
        side - the side to consider
        matchVariables - shall match variables (entire expression) or related loop variables be added
      • applyRuleBody

        protected java.lang.Object applyRuleBody​(Rule rule,
                                                 java.lang.Object[] rhsValues,
                                                 RuleExecutionContext context)
                                          throws VilException
        Determines pre- and postcondition matches and, if enabled, assigns RHS/LHS variables and executes the rule body. Actually, this method has two purposes, namely, testing for enabling pre- and post-condition matches as well as executing the rule body, in case of RHS/LHS matches in iterative fashion. We combined both functionalities as they are closely related and modifications to the matching would otherwise need modifications to multple algorithms. This also prevents storing the matching (outdated/non-existing) pairs in memory.
        Parameters:
        rule - the rule to be executed (contains the rule body)
        rhsValues - the evaluated RHS conditions (values, determined by visiting the RHS matching expressions and therefore are Objects)
        context - the rule execution context, may be null if actually no execution of the rule body shall be performed and just pre-postcondition matches shall be tested
        Returns:
        depending on Rule.returnActualValue(), the actual body evaluation result or the execution status
        Throws:
        VilException - in case of serious execution problems
      • ruleElementFailed

        protected boolean ruleElementFailed​(IRuleElement elt,
                                            RuleExecutionContext context)
                                     throws VilException
        Is called when elt failed in execution, e.g., to put further information about failing into the rule execution context.
        Parameters:
        elt - the failing element
        context - the rule execution context
        Returns:
        true if the failure shall be recorded, false if the failure shall be ignored
        Throws:
        VilException - in case that the evaluation of the failed element fails
      • resolveMatches

        void resolveMatches​(AbstractRule rule,
                            Rule.Side side)
                     throws VilException
        Resolves rule condition matches.
        Parameters:
        rule - the rule to consider
        side - the side of the rule
        Throws:
        VilException - in case of resolution problems
      • isOnStack

        boolean isOnStack​(AbstractRule rule)
        Returns whether the given rule is on the execution stack.
        Parameters:
        rule - the rule to be tested
        Returns:
        true if it is on the actual execution stack, false else
      • visitRule

        public java.lang.Object visitRule​(Rule rule)
                                   throws VilException
        Description copied from interface: IVisitor
        Visits a rule.
        Specified by:
        visitRule in interface IVisitor
        Parameters:
        rule - the rule
        Returns:
        the result of visiting the given statement (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • visitRule

        public java.lang.Object visitRule​(VtlRule rule)
                                   throws VilException
        Description copied from interface: IVisitor
        Visits a VTL mapping rule.
        Specified by:
        visitRule in interface IVisitor
        Parameters:
        rule - the rule
        Returns:
        the result of visiting the given statement (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • cleanupRuleExecution

        protected void cleanupRuleExecution​(RuleExecutionContext context)
                                     throws VilException
        Cleans up the rule execution.
        Parameters:
        context - the execution context
        Throws:
        VilException - in case of execution problems
      • visitRuleCallExpression

        public java.lang.Object visitRuleCallExpression​(RuleCallExpression ex)
                                                 throws VilException
        Description copied from interface: IVisitor
        Visits a rule call expression.
        Specified by:
        visitRuleCallExpression in interface IVisitor
        Parameters:
        ex - the expression
        Returns:
        the result of visiting the given statement (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • visitJoinExpression

        public java.lang.Object visitJoinExpression​(JoinExpression ex)
                                             throws VilException
        Description copied from interface: IVisitor
        Visits a join expression.
        Specified by:
        visitJoinExpression in interface IVisitor
        Parameters:
        ex - the join expression
        Returns:
        the result of visiting the given statement (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • evaluate

        private Collection<java.lang.Object> evaluate​(JoinVariableDeclaration var)
                                               throws VilException
        Evaluates the condition for a variable.
        Parameters:
        var - the variable to be evaluated
        Returns:
        the evaluation result
        Throws:
        VilException - in case of expression evaluation errors
      • createCollectionArray

        private static Collection<java.lang.Object>[] createCollectionArray​(int length)
        Creates an empty array of collections.
        Parameters:
        length - the length of the array to be created
        Returns:
        the array instance
      • createIteratorArray

        private static java.util.Iterator<java.lang.Object>[] createIteratorArray​(int length)
        Creates an empty array of iterators.
        Parameters:
        length - the length of the array to be created
        Returns:
        the array instance
      • join

        private java.lang.Object join​(JoinExpression join)
                               throws VilException
        Performs the join operation.
        Parameters:
        join - the join expression to be evaluated
        Returns:
        the join result
        Throws:
        VilException - in case of execution problems
      • setJoinVariableValue

        private void setJoinVariableValue​(JoinExpression join,
                                          int index,
                                          java.lang.Object value)
                                   throws VilException
        Sets the specified join variable.
        Parameters:
        join - the join expression
        index - the index of the variable
        value - the value
        Throws:
        VilException - in case that setting the variable fails
      • evaluateJoinCombination

        private void evaluateJoinCombination​(JoinExpression join,
                                             java.util.List<IVilType> simpleResult,
                                             java.util.List<IVilType[]> complexResult)
                                      throws VilException
        Evaluates a join combination.
        Parameters:
        join - the join to be evaluated
        simpleResult - modified in case of 1-sided joins
        complexResult - modified in case of multi-sided joins
        Throws:
        VilException - in case that the evaluation fails
      • types

        private static java.lang.Class<?>[] types​(JoinExpression join)
        Returns the types to be used to parameterize the return type.
        Parameters:
        join - the join expression
        Returns:
        the types
      • visitJoinVariableDeclaration

        public java.lang.Object visitJoinVariableDeclaration​(JoinVariableDeclaration decl)
                                                      throws VilException
        Description copied from interface: IVisitor
        Visits a join variable declaration.
        Specified by:
        visitJoinVariableDeclaration in interface IVisitor
        Parameters:
        decl - the declaration
        Returns:
        the result of visiting the given statement (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • visitMapExpression

        public java.lang.Object visitMapExpression​(MapExpression map)
                                            throws VilException
        Description copied from interface: IVisitor
        Visits a map expression.
        Specified by:
        visitMapExpression in interface IVisitor
        Parameters:
        map - the expression to be visited
        Returns:
        the result of visiting the given expression (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • executeLoop

        private java.lang.Object executeLoop​(IEnumeratingLoop loop,
                                             boolean parallelize,
                                             java.util.List<java.lang.Object> result)
                                      throws VilException
        Executes a loop.
        Parameters:
        loop - the loop to be executed
        parallelize - whether execution may happen in parallel
        result - the result collector (may be null for no collection)
        Returns:
        the last statement execution result
        Throws:
        VilException - in case that expression evaluation fails
      • mapResult

        private static java.lang.Object mapResult​(TypeDescriptor<?> mapType,
                                                  java.util.List<java.lang.Object> result,
                                                  boolean failed)
        Creates the actual result of executing a MapExpression.
        Parameters:
        mapType - the type of the map expression
        result - the collected results (may be null if type is TypeDescriptor#VOID)
        failed - whether the actual execution failed
        Returns:
        the return object for the map
      • dynamicDispatch

        protected AbstractRule dynamicDispatch​(AbstractRule operation,
                                               java.lang.Object[] args,
                                               IArgumentProvider argumentProvider,
                                               boolean enableParentScope)
        Description copied from class: ExecutionVisitor
        Performs the dynamic dispatch on the operation type.
        Specified by:
        dynamicDispatch in class ExecutionVisitor<Script,​AbstractRule,​VariableDeclaration,​Resolver>
        Parameters:
        operation - the operation to be dispatched
        args - the actual arguments
        argumentProvider - access to the argument expressions
        enableParentScope - enable the parent declaration scopes for dynamic dispatch, shall not be done in case of explicit super calls due to potential endless recursion
        Returns:
        operation or the more actual operation
      • setModelArgument

        private void setModelArgument​(IResolvableModel<VariableDeclaration,​Script> srcModel,
                                      int index,
                                      java.lang.String name)
                               throws VilException
        Sets a model argument.
        Parameters:
        srcModel - the model to take the parameter from
        index - the index of the parameter to modify (for sequence-based assignment)
        name - the name of the parameter to modify (to retrieve the value, but also for name-based assignment)
        Throws:
        VilException - in case that assigning the parameter fails
      • resolveScript

        private Script resolveScript​(Project project,
                                     IVersionRestriction restrictions)
                              throws VilException
        Resolves the script for an instantiation expression.
        Parameters:
        project - the project to resolve the script on
        restrictions - the version restrictions (may be null)
        Returns:
        the resolved script
        Throws:
        VilException - in case that the version is not valid or that the script cannot be found
      • visitInstantiateExpression

        public java.lang.Object visitInstantiateExpression​(InstantiateExpression inst)
                                                    throws VilException
        Description copied from interface: IVisitor
        Visits an instantiate expression.
        Specified by:
        visitInstantiateExpression in interface IVisitor
        Parameters:
        inst - the instantiation expression
        Returns:
        the result of visiting the given expression (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • visitTypedef

        public java.lang.Object visitTypedef​(Typedef typedef)
                                      throws VilException
        Description copied from interface: IVisitor
        Visits a typedef.
        Specified by:
        visitTypedef in interface IVisitor
        Parameters:
        typedef - the typedef
        Returns:
        the result of visiting (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • visitWhileStatement

        public java.lang.Object visitWhileStatement​(WhileStatement stmt)
                                             throws VilException
        Description copied from interface: IVisitor
        Visits a while statement.
        Specified by:
        visitWhileStatement in interface IVisitor
        Parameters:
        stmt - the statement to be visited
        Returns:
        the result of visiting the given expression (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • visitForStatement

        public java.lang.Object visitForStatement​(ForStatement stmt)
                                           throws VilException
        Description copied from interface: IVisitor
        Visits a for statement.
        Specified by:
        visitForStatement in interface IVisitor
        Parameters:
        stmt - the statement to be visited
        Returns:
        the result of visiting the given expression (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • register

        public void register​(ITerminatable terminatable)
        Description copied from interface: ITerminator
        Registers a terminatable.
        Specified by:
        register in interface ITerminator
        Parameters:
        terminatable - the terminatable
      • unregister

        public void unregister​(ITerminatable terminatable)
        Description copied from interface: ITerminator
        Unregisters a terminatable.
        Specified by:
        unregister in interface ITerminator
        Parameters:
        terminatable - the terminatable
      • visitCompound

        public java.lang.Object visitCompound​(Compound compound)
                                       throws VilException
        Description copied from interface: IVisitor
        Visits a compound.
        Specified by:
        visitCompound in interface IVisitor
        Parameters:
        compound - the compound
        Returns:
        the result of visiting (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)