This Maven plugin provides the capability to transform Sophora Groovy scripts into Sophora XML, which can be imported into Sophora using the Sophora Importer or the Sophora DeskClient. Additional features include:
- Setting metadata such as the script name or External ID using special comments in the Groovy script source
- Publishing a script after import
- Combining several Groovy script classes into a single script. This allows sharing common code between multiple Sophora scripts.
Example usage
<build>
<plugins>
<plugin>
<groupId>com.subshell.maven</groupId>
<artifactId>sophora-script-maven-plugin</artifactId>
<version>2.1.0</version>
<executions>
<execution>
<goals>
<goal>convert-scripts</goal>
</goals>
</execution>
</executions>
<configuration>
<conversions>
<conversion>
<scriptType>CLIENT</scriptType>
<lifecycleActivity>RESTORE</lifecycleActivity>
</conversion>
</conversions>
<zip>true</zip>
</configuration>
</plugin>
</plugins>
</build>
Supported Sophora script types
To configure Sophora script types, utilize the <scriptType
> tag in the conversion
section of the pom.xml
file. The supported Sophora script types are:
CLIENT
(DeskClient scripts)DOCUMENT_CHANGING
(Document Changing scripts)EVENT
(Event scripts)FORM_FIELD_CHANGE
(Form Field Changing scripts)INDEX_FIELD
(Solr Index field scripts)INDEX_CONFIG
(Solr Index configuration scripts)TIMING
(Timing Action scripts)VALIDATION
(Validation scripts)
SERVER
is deprecated, use DOCUMENT_CHANGING
instead.Supported life cycle activities
To configure life cycle activities, use the <lifecycleActivities
> tag in the conversion
section of the pom.xml
file. The supported life cycle activities are:
CREATE_VERSION
DELETE
DELETE_PERMANENTLY
FINISH_PRE_PUBLISHING
KEEP_STATE
NONE
(lifecycleActivity
will not be displayed in the Sophora-XML)PUBLISH
RELEASE
RESTORE
SET_OFFLINE
lifecycleActivity
is set at the script level, it overrrides the lifeActivity
set in the conversion
section of the pom.xml
file.Settings per Sophora script
Define variables within the script for XML document building:
- lines with variables must be prefixed with
// SOPHORAXML:
- each variable on a separate line
- define variables using the syntax: variable-name -> variable-value
Available variables:
- externalId: External ID of the script document
- scriptName: Name of the script document
- idstem: ID Stem of the script document
- structureNode: Location of the script document in the system site
- lifecycleActivity: State of the Sophora-XML document. Find the possible values in the section "Supported life cycle activities" above. Any value set per script overrides the one set in the section
conversion
in the filepom.xml
- skipXmlGeneration: Whether the script is skipped during transformation (default is "false")
Additionally, Client Scripts support the following variables:
- icon: Path to an image file or base64-encoded image data
- iconMimeType: Mime-type of the icon.
- sophora:XXX: Arbitrary Sophora-XML properties. More than one value can be defined. Values have to be written in square brackets and separated by comma, e.g. /
/ SOPHORAXML: sophora:documentSources -> [searchresult,selection]
Additionally, Solr Index Field Scripts support the following variable:
- fieldName: Name of the Solr index field
// SOPHORAXML:
)Example for defining a script name in the script code:
// SOPHORAXML: scriptName -> my script name
Import of external script classes
If a script imports Groovy classes found in the same source folder or sources JAR of a direct Maven dependency, the import statement is removed, and the source is appended to the script source. This allows sharing common code between multiple Sophora scripts. There are a few limitations:
- The class must be referenced by an import statement (static or non-static). Non-static star-imports are not supported
- Referenced classes must not reference other script classes