Class SmcMojo

  • All Implemented Interfaces:
    org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

    @Mojo(name="smc",
          defaultPhase=GENERATE_SOURCES)
    public final class SmcMojo
    extends org.apache.maven.plugin.AbstractMojo
    Responsible for executing the state machine compiler against one or more .sm files found in the configured setSourceDirectory(java.io.File) using the configured SMC parameters. The generated file(s) are placed in setTargetDirectory(java.io.File).

    This mojo has the side effect of adding the targetDirectory to the project compile source root. This allows application code to successfully reference the generated code.

    Author:
    Charles W. Rapp
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static String DEFAULT_GRAPH_LEVEL
      The default graph detail level is zero (least detail).
      static String NO_DEBUG_OUTPUT
      Set debugLevel to "-1" to silence SMC debug output.
      static String SM_SUFFIX
      SMC target file names must end with ".sm".
      • Fields inherited from interface org.apache.maven.plugin.Mojo

        ROLE
    • Constructor Summary

      Constructors 
      Constructor Description
      SmcMojo()
      Creates a new SMC maven mojo instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void execute()
      Firstly validates the mojo settings.
      void setAccess​(String access)
      Access identifier for generated classes.
      void setCast​(String cast)
      When generating C++ code, use this cast type (dynamic_cast, static_cast, or reinterpret_cast).
      void setCrtp​(boolean crtp)
      If true user supplied class must be derives from state machine.
      void setDebugLevel​(int debugLevel)
      Adds SMC debug output to generated code.
      void setGeneric​(boolean generic)
      If true, use a Map<String, Integer> for reflection map.
      void setGeneric7​(boolean generic7)
      Use Java 7 generic collections for reflection map.
      void setGraphLevel​(int glevel)
      Specifies the Graphviz output detail level.
      void setHeaderd​(File dir)
      Places generated header files into this directory.
      void setHsuffix​(String headerSuffix)
      Appends generated header target file(s) with this suffix.
      void setNocatch​(boolean nocatch)
      If true, do not generate try/catch/rethrow code.
      void setNoex​(boolean noex)
      If true, do not generate C++ exception throws.
      void setNostreams​(boolean nostreams)
      If true, do not use C++ iostreams for debugging.
      void setProject​(org.apache.maven.project.MavenProject project)
      Maven uses this method to set the target project.
      void setProtocol​(boolean protocol)
      User-defined FSM context class extends @protocol.
      void setReflection​(boolean reflection)
      If true, generate getTransitions() method for each state, allowing the state to be interrogated about its supported transition.
      void setSerial​(boolean serial)
      If true, generate unique integer identifiers for each state.
      void setSourceDirectory​(File dir)
      Source directory containing the .sm files.
      void setSources​(String[] sources)
      Compiles the following target files.
      void setStateStackSize​(int stateStackSize)
      If > zero, state stack has a fixed size defined by this setting.
      void setSuffix​(String suffix)
      Append generated target file(s) with this suffix.
      void setSync​(boolean sync)
      If true generates thread-safe code.
      void setTargetDirectory​(File dir)
      Place generated files into this directory.
      void setTargetLanguage​(String language)
      Output the generated finite state machine in this target language.
      void setVerbose​(boolean verbose)
      If true, execute() outputs more detailed messages.
      void setVverbose​(boolean vverbose)
      If true, execute() outputs even more detailed messages.
      • Methods inherited from class org.apache.maven.plugin.AbstractMojo

        getLog, getPluginContext, setLog, setPluginContext
    • Constructor Detail

      • SmcMojo

        public SmcMojo()
        Creates a new SMC maven mojo instance.
    • Method Detail

      • execute

        public void execute()
                     throws org.apache.maven.plugin.MojoExecutionException,
                            org.apache.maven.plugin.MojoFailureException
        Firstly validates the mojo settings. Secondly compiles the .sm files, validates the parsed code, and finally emits the target language code to the specified source file.

        Executing this mojo has the side effect of adding the target directory to the project compile source root. This allows application code to reference this generated source code.

        Throws:
        org.apache.maven.plugin.MojoExecutionException - if an invalid setting is detected or the FSM compilation fails. No target code is emitted.
        org.apache.maven.plugin.MojoFailureException - this exception is never thrown.
      • setTargetLanguage

        public void setTargetLanguage​(String language)
        Output the generated finite state machine in this target language. This setting is required.

        The defined target languages are:

        • c
        • c++
        • csharp (C#)
        • graph (Generates Graphviz DOT file)
        • groovy
        • java
        • java7 (generates Java code using transition table)
        • js (Javascript)
        • lua
        • objc (Objective-C)
        • perl
        • php
        • python
        • ruby
        • scala
        • tcl (as [incr Tcl])
        • vb (VB.Net)
        When selecting a target language, use the names as shown.
        Parameters:
        language - target language name.
      • setSourceDirectory

        public void setSourceDirectory​(File dir)
        Source directory containing the .sm files. This setting is optional and defaults to ${project.basedir}/src/main/smc.
        Parameters:
        dir - source directory.
      • setTargetDirectory

        public void setTargetDirectory​(File dir)
        Place generated files into this directory. This directory is automatically added to the project compile target root. This setting is optional and defaults to ${project.build.directory}/generated-sources/smc.
        Parameters:
        dir - target directory.
      • setSuffix

        public void setSuffix​(String suffix)
        Append generated target file(s) with this suffix. If not specified, then the default suffix for setTargetLanguage(java.lang.String) is used.
        Parameters:
        suffix - generated source file name suffix.
      • setHsuffix

        public void setHsuffix​(String headerSuffix)
        Appends generated header target file(s) with this suffix. If not specified, then the default header suffix for setTargetLanguage(java.lang.String) is used. This parameter is ignored if setTargetLanguage(java.lang.String) does not use header files.

        Available for c, c++, and objc only.

        Parameters:
        headerSuffix - generated header file name suffix.
      • setHeaderd

        public void setHeaderd​(File dir)
        Places generated header files into this directory. This directory is automatically added to the project compile target root.

        Available for c, c++, and objc only.

        Parameters:
        dir - target header file directory.
      • setDebugLevel

        public void setDebugLevel​(int debugLevel)
        Adds SMC debug output to generated code. There are two levels:
        • 0: state entry, exit, and transitions.
        • 1: level 0 output plus state entry, exit actions.
        This is turned off by default.
        Parameters:
        debugLevel - SMC debug output level.
      • setNostreams

        public void setNostreams​(boolean nostreams)
        If true, do not use C++ iostreams for debugging. Application code must provide a TRACE macro to output debug messages. Default setting is false.

        Available for c++ only.

        Parameters:
        nostreams - flag to turn C++ iostreams output on or off.
      • setCrtp

        public void setCrtp​(boolean crtp)
        If true user supplied class must be derives from state machine. The default is false.

        See CRTP ("curiously recurring template pattern").

        Available for c++ only.

        Parameters:
        crtp - turn CRTP code generation on or off.
      • setSync

        public void setSync​(boolean sync)
        If true generates thread-safe code. This is not necessary if application guarantees FSM access is thread-safe. Default setting is false.

        Available for csharp, java, java7, groovy, scala, and vb only because these languages provide thread synchronization constructs in the language.

        Parameters:
        sync - turns thread synchronization code generation on or off.
      • setNoex

        public void setNoex​(boolean noex)
        If true, do not generate C++ exception throws. Default setting is false.

        Available for c++ only.

        Parameters:
        noex - turn C++ exception throw code generation on or off.
      • setNocatch

        public void setNocatch​(boolean nocatch)
        If true, do not generate try/catch/rethrow code. The try/catch is used to guarantee that the current state is set before allowing the exception throw to continue. If current FSM state is left null, then the FSM is broken and ceases to function. Default setting is false.

        Setting this property to true is not recommended.

        Parameters:
        nocatch - turns try/catch block code generation on or off.
      • setStateStackSize

        public void setStateStackSize​(int stateStackSize)
        If > zero, state stack has a fixed size defined by this setting. Otherwise, state stack size is unlimited. This setting means that dynamic memory allocation is not used when setting the stack. Default setting is an unlimited stack size.

        Available for c++ only.

        Parameters:
        stateStackSize - state stack fixed size.
      • setSerial

        public void setSerial​(boolean serial)
        If true, generate unique integer identifiers for each state. These identifiers are used to efficiently serialize the current state stack. Default setting is false.
        Parameters:
        serial - turns state identifier generation on or off.
      • setReflection

        public void setReflection​(boolean reflection)
        If true, generate getTransitions() method for each state, allowing the state to be interrogated about its supported transition. Default setting is false.

        Available for csharp, groovy, java, java7, js, lua, perl, php, python, ruby, scala, tcl, and vb only.

        Parameters:
        reflection - turns state machine reflection on or off.
      • setGeneric

        public void setGeneric​(boolean generic)
        If true, use a Map<String, Integer> for reflection map. Default setting is false.

        Available for csharp, java, or vb only when reflect property is set to true.

        Parameters:
        generic - turn generic reflection code generation on or off.
      • setGeneric7

        public void setGeneric7​(boolean generic7)
        Use Java 7 generic collections for reflection map.

        Available for java, or java7 only when reflect property is set to true.

        Parameters:
        generic7 - turns Java 7 generic collections on or off.
      • setVerbose

        public void setVerbose​(boolean verbose)
        If true, execute() outputs more detailed messages. Default setting is false.
        Parameters:
        verbose - turn verbose execution output on or off.
      • setVverbose

        public void setVverbose​(boolean vverbose)
        If true, execute() outputs even more detailed messages. Default setting is false.
        Parameters:
        vverbose - turn very verbose execution output on or off.
      • setGraphLevel

        public void setGraphLevel​(int glevel)
        Specifies the Graphviz output detail level. Ranges from 0 (least detail) to 2 (most detail). See SMC Programmer's Manual, section 10 for an explanation on how to generate Graphviz-based FSM diagram. The default setting is 0 - least detail.

        Available for graph only.

        Parameters:
        glevel - Graphviz detail level.
      • setCast

        public void setCast​(String cast)
        When generating C++ code, use this cast type (dynamic_cast, static_cast, or reinterpret_cast). Default setting is dynamic_cast.

        Available for c++ only.

        Parameters:
        cast - generated C++ cast code.
      • setAccess

        public void setAccess​(String access)
        Access identifier for generated classes. Default setting is an empty string.

        Available for java, java7 only.

        Parameters:
        access - Java access level.
      • setProtocol

        public void setProtocol​(boolean protocol)
        User-defined FSM context class extends @protocol. Generated code references context class via protocol. Default setting is false.

        Available for objc only.

        Parameters:
        protocol - turns Objective-C @protocol support on or off.
      • setProject

        public void setProject​(org.apache.maven.project.MavenProject project)
        Maven uses this method to set the target project. Default setting is ${project}.
        Parameters:
        project - mojo is working for this maven project.