Git Product home page Git Product logo

fsm-packagetype's Introduction

Maven Package Type For FSMs Build Status Coverage Status Maven Central

This is a basic approach to create a Maven package type for FirstSpirit modules (FSM) with a fully working Maven lifecycle inclung install and deploy. Additionally there is support to crate the FSM deployment descriptor called module.xml. For information please consult the official documentations.

How to use

In your pom.xml add this:

<project>

    <groupId>my-group</groupId>
    <artifactId>my-fsm-artifact</artifactId>
    <version>1.2.3</version>
    
    <!-- NEW: make a FSM file -->
    <packaging>fsm</packaging>

    ...
    <build>
    
        <plugins>
            
            <!-- make new FSM package type available to Maven -->
            <plugin>
                <groupId>com.github.zaplatynski</groupId>
                <artifactId>fsm-packagetype</artifactId>
                <version>2.3.0</version>
                <!-- this is important when extending core Maven functionality: -->
                <extensions>true</extensions>
            </plugin>
            
            <!-- define how the FSM file look like -->
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <attach>false</attach>
                    <appendAssemblyId>false</appendAssemblyId>
                    <descriptors>
                        <descriptor>src/assembly/fsm.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            
        </plugins>    
        ...
    </build>
</project>

To create the module.xml (FirstSpirit module deployment descriptor) you must provide a module .vm (Apache Velocity macro) in the path src/main/fsm with content:

#defaultModuleXml($project)

The example (see macros.vm) above will add the common tags for name, version etc. (sub macro #addHeader) and collect module fragment xml if avaiable (sub macro #addModuleXmlFragments). Besides those three macros the variable $project give access to the whole Maven project. In addition all user defined Maven properties are available too. Since Velocity can not deal with dots in variable names please name them accordingly.

FirstSpirit Mode Isolated

To enable FirstSpirit upcoming mode insolated inside the module deployment descriptor simply add this property to your pom.xml:

<project>
    ...
    <properties>
        ...
        <fsmode>isolated</fsmode>
        ...
    </properties>
    ...
</project>

The default Velocity macros will recognized it and create the the following attribute inside resource tags:

<module>
    ...
    <components>
    ...
    <resources>
        ...
        <resource mode="isolated" ... />
        ...
    </resources>
    ...
    </components>
    ...
</module>

Module Deployment Descriptor Fragment

To create an module fragment xml in any other jar Maven module just this to the pom.xml:

</project>
...
    <build>
        ...
        <plugins>
            ...
            <plugin>
                <groupId>com.github.zaplatynski</groupId>
                <artifactId>fsm-packagetype</artifactId>
                <version>2.3.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>fragmentModuleXml</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            ...
        </plugins>
    </build>
...
</project>

Again in the src/main/fsm there must be an in the path module-fragment.vm in which you can define e.g. an FirstSpirit Executable or Service.

FSM Layout

Inside the above mentioned fsm.xml you need to specify the Maven assembly plugin descriptor to create a typical FSM file layout:

<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
    <id>fsm</id>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <files>
        <file>
            <source>target/module.xml</source>
            <outputDirectory>META-INF</outputDirectory>
            <filtered>false</filtered>
        </file>
        <file>
            <source>target/${project.artifactId}-${project.version}.jar</source>
            <outputDirectory>lib</outputDirectory>
            <filtered>false</filtered>
        </file>
    </files>
    <dependencySets>
        <dependencySet>
            <outputDirectory>lib</outputDirectory>
            <useTransitiveFiltering>true</useTransitiveFiltering>
            <useProjectArtifact>false</useProjectArtifact>
        </dependencySet>
    </dependencySets>
</assembly>

The FSM Maven package type will take care to rename the zip file to a FSM file. In the dependency set you specify yourself.

If you want to have a kind of real world example then have a look at my Second-Hand Log project or my FSM Libray Creator project here on GitHub.

Build command

Maven is used to compile and assemble this project:

mvn clean install

Help, bugs and feature requests

Please file any request for help, bug or feature request at github.com/zaplatynski/fsm-packagetype/issues.

Disclaimer

By using it you agree to the license stated in the file LICENSE. FirstSpirit is a trade mark by the e-Spirit AG.

fsm-packagetype's People

Contributors

zaplatynski avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fsm-packagetype's Issues

Add tighter validation to XML check

At the moment the FSM package type validates only well-formedness of the XML. The presence of name and version should be enforced. Because there is no DTD or Schema this could be accomplished by XPath expressions.

Naming bug in version 2.2.0

While adding Maven style naming in version 2.2.0 to resources this can not be applied to names of components.

Bug in Velocity macro which collects module-xml-fragements

There are cases in which the module-xml includes itself again what results in a broken xml structure. Temporal fix: Configure the module-xml-fragment-goal to produce a module-fragment.xml and use this macro instead of the system macro:

#macro(addModuleXmlFragmentsFixed $mavenProject)
#foreach( $childModule in $project.getParent().getModules() )
    #set($importFile = "../../../../$childModule/target/module-fragment.xml")
    #include($importFile)
#end
#end

Dont't use #defaultModuleXml($project) but this:

<module>

    #addHeader($project)

    <components>

        #addModuleXmlFragmentsFixed($project)

    </components>

</module>

Bug in dependency resolution

In version 2.1.1 there were some dependencies updated which causes in the Velocity macros the wrong source of dependencies. Instead of MavenProject::getDependencyArtifacts() which is deprecated in Maven 3.3.9 it is recommended to use MavenProject::getArtifacts().

unable to find resource module.vm in flat project structure

Hi,

i have a multi module project with flat project structure. In this case the module.vm file is found but velocity has problems loading the file as a resource.

In the attachment is a sample project which demonstrates the problem.

Here is the Stacktrace:
[ERROR] Failed to execute goal com.github.zaplatynski:fsm-packagetype:2.3.0:moduleXml (default-moduleXml) on project fsm: Unable to find resource 'fsm/src/main/fsm/module.vm' -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.github.zaplatynski:fsm-packagetype:2.3.0:moduleXml (default-moduleXml) on project fsm: Unable to find resource 'fsm/src/main/fsm/module.vm' at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288) at org.apache.maven.cli.MavenCli.main(MavenCli.java:199) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) at org.codehaus.classworlds.Launcher.main(Launcher.java:47) Caused by: org.apache.maven.plugin.MojoExecutionException: Unable to find resource 'fsm/src/main/fsm/module.vm' at com.github.zaplatynski.firstspirit.modules.fsm.velocity.ModuleXmlParser.parseModuleVm(ModuleXmlParser.java:68) at com.github.zaplatynski.firstspirit.modules.fsm.ModuleXmlMojo.execute(ModuleXmlMojo.java:57) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207) ... 21 more Caused by: org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'fsm/src/main/fsm/module.vm' at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:474) at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:352) at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1533) at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1514) at org.apache.velocity.app.VelocityEngine.getTemplate(VelocityEngine.java:373) at com.github.zaplatynski.firstspirit.modules.fsm.velocity.VelocityManager.renderModuleXml(VelocityManager.java:43) at com.github.zaplatynski.firstspirit.modules.fsm.velocity.ModuleXmlParser.parseModuleVm(ModuleXmlParser.java:66)
fsm.zip

Add support for FirstSpirit server scope libraries

Add a configuration to tell the Maven plugin which Maven dependency should be on server scope (global classpath) instead of scope module (local classpath). This is important if we want to build server services in FirstSpirit which must have an API jar with the service interface and interfaces classes such as a data model.

compile is not executed in a single module project

Hi,

in a single module project the compile task is not executed when the packaging type is fsm.
If the packaging type is jar, then the compile task is executed and a jar will be generated.
If i change the packaging to fsm, then the compile task will be ignored/skipped.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.