maven-plugins/webserver/plugin.jelly

396 lines
16 KiB
XML

<?xml version="1.0"?>
<!-- ================================================================== -->
<!-- W E B S E R V E R P L U G I N -->
<!-- ================================================================== -->
<project xmlns:j="jelly:core" xmlns:ant="jelly:ant" xmlns:log="jelly:log"
xmlns:exception="exception" xmlns:define="jelly:define">
<!--==================================================================-->
<!-- S U P P O R T E D W E B S E R V E R S -->
<!--==================================================================-->
<j:import inherit="true" file="${plugin.resources}/apache-2.x.jelly" />
<!--==================================================================-->
<!-- B E G I N C O R E P R O C E S S I N G -->
<!--==================================================================-->
<!-- tell the user what Maven thinks about their webserver instance -->
<goal name="webserver:init"
description="Initialize resources needed for the plugin">
<!--
1. First check that name and version properties have values
2. Check the webserver name and version is supported by this plugin
3. Check the home dir to make sure we can find the install
4. Check the rest of the required properties
5. Check the ports to make sure they are numbers only
-->
<define:taglib uri="exception">
<define:tag name="requiredPropertyMissing">
<ant:fail message=" ">
--------------------------------------------------------------------------
| Plugin Configuration Error |
--------------------------------------------------------------------------
A required property is missing a value.
Property name: ${propname}
Errors must be corrected before using this plugin.
--------------------------------------------------------------------------
</ant:fail>
</define:tag>
<define:tag name="invalidPropertyDirectory">
<ant:fail message=" ">
--------------------------------------------------------------------------
| Plugin Configuration Error |
--------------------------------------------------------------------------
A required property is pointing to an invalid directory.
Property name: ${propname}
Invalid value: ${propvalue}
Errors must be corrected before using this plugin.
--------------------------------------------------------------------------
</ant:fail>
</define:tag>
<define:tag name="webserverNameNotSupported">
<ant:fail message=" ">
--------------------------------------------------------------------------
| Plugin Configuration Error |
--------------------------------------------------------------------------
The specified webserver name is currently not supported.
Property name: ${propname}
Property value: ${propvalue}
For supported ${propname} values, please see the help docs.
--------------------------------------------------------------------------
</ant:fail>
</define:tag>
<define:tag name="webserverVersionNotSupported">
<ant:fail message=" ">
--------------------------------------------------------------------------
| Plugin Configuration Error |
--------------------------------------------------------------------------
The specified version for the ${webserver} webserver is currently
not supported.
Property name: ${propname}
Property value: ${propvalue}
For supported ${propname} values, please see the help docs.
--------------------------------------------------------------------------
</ant:fail>
</define:tag>
</define:taglib>
<!-- Check required properties for a name and version first -->
<j:if test="${context.getVariable('maven.webserver.name') == null}">
<exception:requiredPropertyMissing propname="maven.webserver.name" />
</j:if>
<j:if test="${context.getVariable('maven.webserver.version') == null}">
<exception:requiredPropertyMissing propname="maven.webserver.version" />
</j:if>
<!-- Check if the webserver name and version are supported -->
<j:choose>
<j:when test="${context.getVariable('maven.webserver.name') == 'apache'}">
<j:choose>
<j:when test="${context.getVariable('maven.webserver.version') == '2.x'}" />
<j:otherwise>
<exception:webserverVersionNotSupported
webserver="${maven.webserver.name}"
propname="maven.webserver.version"
propvalue="${maven.webserver.version}" />
</j:otherwise>
</j:choose>
</j:when>
<j:otherwise>
<exception:webserverNameNotSupported propname="maven.webserver.name"
propvalue="${maven.webserver.name}" />
</j:otherwise>
</j:choose>
<!-- Check the home dir to see if it exists -->
<ant:condition property="maven.webserver.home.exists">
<ant:available file="${maven.webserver.home}" type="dir" />
</ant:condition>
<j:if test="${!context.getVariable('maven.webserver.home.exists')}">
<exception:invalidPropertyDirectory propname="maven.webserver.home"
propvalue="${maven.webserver.home}" />
</j:if>
<!-- Check the rest of the required properties -->
<j:if test="${context.getVariable('maven.webserver.dir') == null}">
<exception:requiredPropertyMissing propname="maven.webserver.dir" />
</j:if>
<j:if test="${context.getVariable('maven.webserver.test.socket') == null}">
<exception:requiredPropertyMissing propname="maven.webserver.test.socket" />
</j:if>
<j:if test="${context.getVariable('maven.webserver.test.url') == null}">
<exception:requiredPropertyMissing propname="maven.webserver.test.url" />
</j:if>
<j:if test="${context.getVariable('maven.webserver.root') == null}">
<exception:requiredPropertyMissing propname="maven.webserver.root" />
</j:if>
<!-- These are special cases where the user should not override -->
<j:if test="${context.getVariable('maven.webserver.fullname') == null}">
<exception:requiredPropertyMissing propname="maven.webserver.fullname" />
</j:if>
<ant:condition property="maven.webserver.conf.dir.exists">
<ant:available file="${maven.webserver.conf.dir}" type="dir" />
</ant:condition>
<j:if test="${!context.getVariable('maven.webserver.conf.dir.exists')}">
<exception:invalidPropertyDirectory propname="maven.webserver.conf.dir"
propvalue="${maven.webserver.conf.dir}" />
</j:if>
<!-- a flag to see if the webserver is started -->
<ant:condition property="maven.webserver.started">
<ant:and>
<ant:socket server="${maven.webserver.host}"
port="${maven.webserver.test.socket}" />
<ant:http url="${maven.webserver.test.url}" />
</ant:and>
</ant:condition>
<!-- a flag to see if the webserver is installed -->
<ant:condition property="maven.webserver.installed">
<ant:and>
<ant:available file="${maven.webserver.root}" type="dir" />
<ant:available file="${maven.webserver.dir}" type="dir" />
</ant:and>
</ant:condition>
<!-- convert all path related properties to their os equivalent -->
<ant:property name="maven.webserver.home.path"
location="${maven.webserver.home}" />
<ant:property name="maven.webserver.conf.dir.path"
location="${maven.webserver.conf.dir}" />
<ant:property name="maven.webserver.root.path"
location="${maven.webserver.root}" />
<ant:property name="maven.webserver.dir.path"
location="${maven.webserver.dir}" />
<!-- create the filterset to be available to copy tasks that want it -->
<ant:filterset id="maven.webserver.filterset.default">
<ant:filter token="maven.webserver.home"
value="${maven.webserver.home.path}" />
<ant:filter token="maven.webserver.name"
value="${maven.webserver.name}" />
<ant:filter token="maven.webserver.version"
value="${maven.webserver.version}" />
<ant:filter token="maven.webserver.port.http"
value="${maven.webserver.port.http}" />
<ant:filter token="maven.webserver.port.https"
value="${maven.webserver.port.https}" />
<ant:filter token="maven.webserver.port.one"
value="${maven.webserver.port.one}" />
<ant:filter token="maven.webserver.port.two"
value="${maven.webserver.port.two}" />
<ant:filter token="maven.webserver.port.three"
value="${maven.webserver.port.three}" />
<ant:filter token="maven.webserver.conf.dir"
value="${maven.webserver.conf.dir.path}" />
<ant:filter token="maven.webserver.host"
value="${maven.webserver.host}" />
<ant:filter token="maven.webserver.dir"
value="${maven.webserver.dir.path}" />
<ant:filter token="maven.webserver.root"
value="${maven.webserver.root.path}" />
</ant:filterset>
<j:set var="maven.webserver.installed.msg">
<j:choose>
<j:when test="${maven.webserver.installed}">installed</j:when>
<j:otherwise>not installed</j:otherwise>
</j:choose>
</j:set>
<j:set var="maven.webserver.started.msg">
<j:choose>
<j:when test="${maven.webserver.started}">started</j:when>
<j:otherwise>not started</j:otherwise>
</j:choose>
</j:set>
<log:info trim="false">
Maven has determined your <j:expr value="${maven.webserver.fullname}"/> webserver instance is <j:expr value="${maven.webserver.installed.msg}"/> in directory [ <j:expr value="${maven.webserver.dir}"/> ] and <j:expr value="${maven.webserver.started.msg}"/> on <j:expr value="${maven.webserver.test.url}"/>
</log:info>
</goal>
<!--==================================================================-->
<!-- I S T A L L -->
<!--==================================================================-->
<goal name="webserver:install" prereqs="webserver:init"
description="Install or reinstall a webserver instance">
<ant:mkdir dir="${maven.webserver.dir}" />
<j:choose>
<!-- not installed - simply install -->
<j:when test="${!maven.webserver.installed}">
<attainGoal name="webserver:install-${maven.webserver.fullname}" />
</j:when>
<!-- installed and stopped -->
<j:when
test="${maven.webserver.installed} and ${!maven.webserver.started}">
<attainGoal name="webserver:reinstall" />
</j:when>
<!-- installed and started -->
<j:when test="${maven.webserver.installed} and ${!maven.webserver.started}">
<attain>
<attainGoal name="webserver:stop" />
<attainGoal name="webserver:reinstall" />
<attainGoal name="webserver:start" />
</attain>
</j:when>
<!-- one of those 'things' that should never happen -->
<j:otherwise>
<ant:fail message=" ">
--------------------------------------------------------------------------
| Plugin Runtime Error |
--------------------------------------------------------------------------
Maven could not determine the current status for your <j:expr value="${maven.webserver.fullname}"/>
instance. This was an unexpected runtime error that should be reported.
--------------------------------------------------------------------------
</ant:fail>
</j:otherwise>
</j:choose>
</goal>
<!--==================================================================-->
<!-- R E I N S T A L L -->
<!--==================================================================-->
<!-- the purpose of this target is to allow the user to be very -->
<!-- specific when using pre and post goals and sometimes there may -->
<!-- be custom implementations of reinstall -->
<goal name="webserver:reinstall"
prereqs="webserver:init, webserver:install-${maven.webserver.fullname}"
description="Reinstall a webserver instance" >
</goal>
<!--==================================================================-->
<!-- S T A R T -->
<!--==================================================================-->
<goal name="webserver:start" prereqs="webserver:init"
description="Start or restart a webserver instance">
<!-- property to remember what goal the user first called -->
<ant:property name="webserver.goal.start.called" value="true" />
<!-- must install before starting -->
<j:if test="${!maven.webserver.installed}">
<log:info trim="false">
Installing the <j:expr value="${maven.webserver.fullname}" /> webserver instance before starting it ...
</log:info>
<attainGoal name="webserver:install" />
</j:if>
<j:choose>
<j:when test="${maven.webserver.started}">
<attain>
<attainGoal name="webserver:stop" />
<log:info trim="false">
Restarting the <j:expr value="${maven.webserver.fullname}"/> webserver instance ...
</log:info>
<attainGoal name="webserver:restart" />
</attain>
</j:when>
<j:when test="${!maven.webserver.installed}">
<log:info trim="false">
Installing the <j:expr value="${maven.webserver.fullname}"/> webserver instance before starting it ...
</log:info>
<attainGoal name="webserver:install" />
<attainGoal name="webserver:start-${maven.webserver.fullname}"/>
</j:when>
</j:choose>
</goal>
<!--==================================================================-->
<!-- R E S T A R T -->
<!--==================================================================-->
<!-- the purpose of this target is to allow the user to be very -->
<!-- specific when using pre and post goals -->
<goal name="webserver:restart"
prereqs="webserver:init,webserver:restart-${maven.webserver.fullname}"
description="Restart the web server instance">
</goal>
<!--==================================================================-->
<!-- S T O P -->
<!--==================================================================-->
<goal name="webserver:stop" prereqs="webserver:init"
description="Stop a webserver instance if started">
<j:choose>
<j:when test="${maven.webserver.started and maven.webserver.installed}">
<log:info trim="false">
Stopping the webserver ...
</log:info>
<attainGoal name="webserver:stop-${maven.webserver.fullname}" />
</j:when>
<j:otherwise>
<j:if test="${webserver.goal.clean.called != 'true'}">
<log:info trim="false">
The <j:expr value="${maven.webserver.fullname}"/> is already stopped!
</log:info>
</j:if>
</j:otherwise>
</j:choose>
</goal>
<!--==================================================================-->
<!-- C L E A N -->
<!--==================================================================-->
<goal name="webserver:clean" prereqs="webserver:init"
description="Safely delete an installed webserver instance">
<!-- property to remember what goal the user first called -->
<j:set var="webserver.goal.clean.called" value="true" />
<j:if test="${maven.webserver.started}">
<log:info trim="false">
Stopping the <j:expr value="${maven.webserver.fullname}" /> webserver instance before deleting it ...
</log:info>
<attainGoal name="webserver:stop" />
</j:if>
<j:choose>
<j:when test="${maven.webserver.installed}">
<log:info trim="false">
Deleting the <j:expr value="${maven.webserver.fullname}" /> webserver instance ...
</log:info>
<!-- allow webservers to have their own cleanup -->
<attainGoal name="webserver:clean-${maven.webserver.fullname}" />
<!-- all clean calls should cleanup the server dir -->
<ant:delete dir="${maven.webserver.dir}"/>
</j:when>
<j:otherwise>
<log:info trim="false">
The <j:expr value="${maven.webserver.fullname}"/> webserver instance is already cleaned!
</log:info>
</j:otherwise>
</j:choose>
</goal>
</project>