Chapter 7. Module Support

Table of Contents

7.1. Different module types
7.1.1. Resources within library JARs
7.1.2. Resources placed in modules/ directory
7.2. Actions applied on module resources after unpacking
7.3. Creating new modules using the Maven archetype

Modules allow you to share functionality, configuration options and view elements between different Pustefix installations.

7.1. Different module types

Pustefix supports two ways for providing resources (include parts, images, stylesheets, etc.) used by different projects.

7.1.1. Resources within library JARs

The first (preferred) way is to place a JAR archive somewhere in the library path (usually lib/) that contains a special deployment descriptor. This deployment descriptor has to be named META-INF/pustefix-module.xml in order to be recognized by the Pustefix build system. This deployment descriptor is a XML file with the following format:

<module-descriptor
  xsi:schemaLocation="http://pustefix.sourceforge.net/moduledescriptor200702 http://pustefix.sourceforge.net/moduledescriptor200702.xsd"
  xmlns="http://pustefix.sourceforge.net/moduledescriptor200702"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  
  <!--
    The module name is used to construct the path the resources will be extracted to.
    In this example the path would be projects/modules/mytest/.
  -->  
  <module-name>mytest</module-name>
  <resources>
    <!--
      The srcpath attributes the directory within the JAR archive that contains the
      resources. The targetpath attribute is optional and specifies the path the
      resources are copied to (relative to the module directory). An empty targetpath
      (the default) specifies the module directory itself
      (e.g. projects/modules/mymodule) as the target directory.
    -->
    <resource-mapping srcpath="resources/txt" targetpath="txt"/>
    <resource-mapping srcpath="resources/images" targetpath="img"/>
  </resources>

  <!--
    Here you can configure which resources from which other module should be
    overridden by your module (see "Dynamic resource resolution").
  -->
  <override-modules>
    <module name="modulename">
      <resource path="path/to/resource"/>
      ...
    </module>
    ...
  </override-modules>

</module-descriptor>

While future Pustefix versions will be able to load any kind of resource directly from the module jar file, currently it's required that certain resources, like configuration files or images, are extracted by the build process (using the resource-mapping configuration).

XML and XSL files used for rendering (TargetGenerator) meanwhile can be loaded directly from the jar file (if located in the PUSTEFIX-INF folder). For details on how to reference module resources and how to override modules, see Section 6.3, “Dynamic resource inclusion”.

Besides those two variants of using resources from module jars, Pustefix supports the automatic merging of statusmessage files. Statusmessages placed under dyntxt/statusmessages.xml within a module jar are automatically merged to projects/modules-override/MODULENAME/dyntxt/statusmessages-merged.xml. In contrast to resource-mappings the merged files aren't readonly, but are intended to be used to change (e.g. localize) the default messages provided by the module (see Section 5.5, “StatusCodes”).

7.1.2. Resources placed in modules/ directory

The old way is to place a JAR file in the modules/ directory of the Pustefix environment. In this case no deplyoment descriptor is needed (and even if present it is not read). However you have to ensure that all files within the JAR file are in a properly named directory as the archive will be directly extracted to the projects/modules/ directory.

[Warning]Deprecated

It is not recommended to use these types of modules in Pustefix 0.12.x or higher. The the new way (see Section 7.1.1, “Resources within library JARs”) is much more powerful, we will drop support for the modules directory in a future Pustefix release.

7.2. Actions applied on module resources after unpacking

If your module contains an ant build file, Pustefix can execute this build file after unpacking. If you want to deploy a build file, that is run automatically, place a buildfile called build.xml in the folder projects/modules/<module-name>/.

7.3. Creating new modules using the Maven archetype

Pustefix provides a Maven archetype, which can be used to create new modules. It sets up a maven project with pre-configured POM, deployment descriptor and statusmessage support.

mvn archetype:create \
-DarchetypeGroupId=org.pustefixframework.maven.archetypes \
-DarchetypeArtifactId=pustefix-module-archetype \
-DarchetypeVersion=0.1 \
-DgroupId=mytld.myorg.myapp.mysection \
-DartifactId=mymodule \
-Dversion=1.0  
      

You have to supply your own values for the groupId, artifactId and version parameters. The chosen artifactId will be used as default module and target folder name, the groupId as Java package name. Executing the above command creates the following directory structure and artifacts:

mymodule/
mymodule/pom.xml
mymodule/src
mymodule/src/main
mymodule/src/main/resources
mymodule/src/main/resources/dyntxt
mymodule/src/main/resources/dyntxt/statusmessages.xml
mymodule/src/main/resources/dyntxt/statuscodeinfo.xml
mymodule/src/main/resources/META-INF
mymodule/src/main/resources/META-INF/pustefix-module.xml
      

Building with mvn clean package creates a deployable Pustfix module. At the moment the only addition to the Maven standard build is the generation of StatusCode constant classes.