Class SmcMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- net.sf.smc.plugin.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.AbstractMojoResponsible for executing the state machine compiler against one or more.smfiles found in the configuredsetSourceDirectory(java.io.File)using the configuredSMCparameters. The generated file(s) are placed insetTargetDirectory(java.io.File).This mojo has the side effect of adding the
targetDirectoryto 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 StringDEFAULT_GRAPH_LEVELThe default graph detail level is zero (least detail).static StringNO_DEBUG_OUTPUTSetdebugLevelto "-1" to silence SMC debug output.static StringSM_SUFFIXSMC target file names must end with ".sm".
-
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 voidexecute()Firstly validates the mojo settings.voidsetAccess(String access)Access identifier for generated classes.voidsetCast(String cast)When generating C++ code, use this cast type (dynamic_cast,static_cast, orreinterpret_cast).voidsetCrtp(boolean crtp)Iftrueuser supplied class must be derives from state machine.voidsetDebugLevel(int debugLevel)Adds SMC debug output to generated code.voidsetGeneric(boolean generic)Iftrue, use aMap<String, Integer>for reflection map.voidsetGeneric7(boolean generic7)Use Java 7 generic collections for reflection map.voidsetGraphLevel(int glevel)Specifies the Graphviz output detail level.voidsetHeaderd(File dir)Places generated header files into this directory.voidsetHsuffix(String headerSuffix)Appends generated header target file(s) with this suffix.voidsetNocatch(boolean nocatch)Iftrue, do not generatetry/catch/rethrowcode.voidsetNoex(boolean noex)Iftrue, do not generate C++ exception throws.voidsetNostreams(boolean nostreams)Iftrue, do not use C++ iostreams for debugging.voidsetProject(org.apache.maven.project.MavenProject project)Maven uses this method to set the target project.voidsetProtocol(boolean protocol)User-defined FSM context class extends@protocol.voidsetReflection(boolean reflection)Iftrue, generategetTransitions()method for each state, allowing the state to be interrogated about its supported transition.voidsetSerial(boolean serial)Iftrue, generate unique integer identifiers for each state.voidsetSourceDirectory(File dir)Source directory containing the.smfiles.voidsetSources(String[] sources)Compiles the following target files.voidsetStateStackSize(int stateStackSize)If > zero, state stack has a fixed size defined by this setting.voidsetSuffix(String suffix)Append generated target file(s) with this suffix.voidsetSync(boolean sync)Iftruegenerates thread-safe code.voidsetTargetDirectory(File dir)Place generated files into this directory.voidsetTargetLanguage(String language)Output the generated finite state machine in this target language.voidsetVerbose(boolean verbose)Iftrue,execute()outputs more detailed messages.voidsetVverbose(boolean vverbose)Iftrue,execute()outputs even more detailed messages.
-
-
-
Field Detail
-
SM_SUFFIX
public static final String SM_SUFFIX
SMC target file names must end with ".sm".- See Also:
- Constant Field Values
-
NO_DEBUG_OUTPUT
public static final String NO_DEBUG_OUTPUT
SetdebugLevelto "-1" to silence SMC debug output.- See Also:
- Constant Field Values
-
DEFAULT_GRAPH_LEVEL
public static final String DEFAULT_GRAPH_LEVEL
The default graph detail level is zero (least detail).- See Also:
- Constant Field Values
-
-
Method Detail
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureExceptionFirstly 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)
- Parameters:
language- target language name.
-
setSourceDirectory
public void setSourceDirectory(File dir)
Source directory containing the.smfiles. 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.
-
setSources
public void setSources(String[] sources)
Compiles the following target files. If this array is empty, then it is filled with all.smfiles found insetSourceDirectory(java.io.File). Specified target files names must be relative tosetSourceDirectory(java.io.File).- Parameters:
sources- source file names.
-
setSuffix
public void setSuffix(String suffix)
Append generated target file(s) with this suffix. If not specified, then the default suffix forsetTargetLanguage(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 forsetTargetLanguage(java.lang.String)is used. This parameter is ignored ifsetTargetLanguage(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.
- Parameters:
debugLevel- SMC debug output level.
-
setNostreams
public void setNostreams(boolean nostreams)
Iftrue, do not use C++ iostreams for debugging. Application code must provide aTRACEmacro to output debug messages. Default setting isfalse.Available for c++ only.
- Parameters:
nostreams- flag to turn C++ iostreams output on or off.
-
setCrtp
public void setCrtp(boolean crtp)
Iftrueuser supplied class must be derives from state machine. The default isfalse.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)
Iftruegenerates thread-safe code. This is not necessary if application guarantees FSM access is thread-safe. Default setting isfalse.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)
Iftrue, do not generate C++ exception throws. Default setting isfalse.Available for c++ only.
- Parameters:
noex- turn C++ exception throw code generation on or off.
-
setNocatch
public void setNocatch(boolean nocatch)
Iftrue, do not generatetry/catch/rethrowcode. Thetry/catchis used to guarantee that the current state is set before allowing the exception throw to continue. If current FSM state is leftnull, then the FSM is broken and ceases to function. Default setting isfalse.Setting this property to
trueis not recommended.- Parameters:
nocatch- turnstry/catchblock 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)
Iftrue, generate unique integer identifiers for each state. These identifiers are used to efficiently serialize the current state stack. Default setting isfalse.- Parameters:
serial- turns state identifier generation on or off.
-
setReflection
public void setReflection(boolean reflection)
Iftrue, generategetTransitions()method for each state, allowing the state to be interrogated about its supported transition. Default setting isfalse.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)
Iftrue, use aMap<String, Integer>for reflection map. Default setting isfalse.Available for csharp, java, or vb only when
reflectproperty is set totrue.- 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
reflectproperty is set totrue.- Parameters:
generic7- turns Java 7 generic collections on or off.
-
setVerbose
public void setVerbose(boolean verbose)
- Parameters:
verbose- turn verbose execution output on or off.
-
setVverbose
public void setVverbose(boolean vverbose)
- 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, orreinterpret_cast). Default setting isdynamic_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 isfalse.Available for objc only.
- Parameters:
protocol- turns Objective-C@protocolsupport 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.
-
-