Files
maven-plugins/webserver/plugin.jelly
T
plynch de3d87ef7f o use define taglib to help isolate the main work of the goals
o improve user feedback
o be explicit with the variable retrieval to avoid jexl issues


git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@113206 13f79535-47bb-0310-9956-ffa450edef68
2003-03-27 17:29:25 +00:00

421 lines
17 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"
xmlns:webserver="http://www.maven.org/plugin/webserver">
<!--==================================================================-->
<!-- 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>
<j:if test="${context.getVariable('maven.webserver.started') == 'true' and context.getVariable('maven.webserver.installed') == 'true'}">
<j:set var="maven.webserver.installedandStarted" value="true" />
</j:if>
<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>
<!-- DEFINE CORE FUNCTIONALITY -->
<define:taglib uri="http://www.maven.org/plugin/webserver">
<define:tag name="clean">
<log:info trim="false">
<j:expr value="${maven.webserver.fullname}" />: Deleting 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}"/>
</define:tag>
<define:tag name="install">
<log:info trim="false">
<j:expr value="${maven.webserver.fullname}" />: Installing webserver instance ...
</log:info>
<attainGoal name="webserver:install-${maven.webserver.fullname}" />
</define:tag>
<define:tag name="reinstall">
<log:info trim="false">
<j:expr value="${maven.webserver.fullname}" />: Re-installing webserver instance ...
</log:info>
<attainGoal name="webserver:install-${maven.webserver.fullname}" />
</define:tag>
<define:tag name="restart">
<log:info trim="false">
<j:expr value="${maven.webserver.fullname}" />: Re-starting webserver instance ...
</log:info>
<attainGoal name="webserver:restart-${maven.webserver.fullname}" />
</define:tag>
<define:tag name="start">
<log:info trim="false">
<j:expr value="${maven.webserver.fullname}" />: Starting webserver instance ...
</log:info>
<attainGoal name="webserver:start-${maven.webserver.fullname}" />
</define:tag>
<define:tag name="stop">
<log:info trim="false">
<j:expr value="${maven.webserver.fullname}" />: Stopping webserver instance ...
</log:info>
<attainGoal name="webserver:stop-${maven.webserver.fullname}" />
</define:tag>
</define:taglib>
</goal>
<!--==================================================================-->
<!-- I S T A L L -->
<!--==================================================================-->
<goal name="webserver:install" prereqs="webserver:init"
description="Install or reinstall a webserver instance">
<!-- all goals will need a webserver dir -->
<ant:mkdir dir="${maven.webserver.dir}" />
<j:choose>
<!-- not installed - simply install -->
<j:when test="${context.getVariable('maven.webserver.installed') != 'true'}">
<webserver:install />
</j:when>
<!-- installed and stopped -->
<j:when test="${context.getVariable('maven.webserver.installed') == 'true' and context.getVariable('maven.webserver.started') != 'true'}">
<webserver:reinstall />
</j:when>
<!-- installed and started -->
<j:when test="${context.getVariable('maven.webserver.installedAndStarted') == 'true'}">
<attain>
<webserver:stop />
<webserver:reinstall />
<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 needed -->
<!-- by default we just call the install goal again -->
<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">
<j:choose>
<j:when test="${context.getVariable('maven.webserver.installed') != 'true'}">
<attain>
<webserver:install />
<webserver:start />
</attain>
</j:when>
<j:when test="${context.getVariable('maven.webserver.installedAndStarted') == 'true'}">
<webserver:restart />
</j:when>
<j:when test="${context.getVariable('maven.webserver.installed') == 'true'}">
<webserver:start />
</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:if test="${context.getVariable('maven.webserver.installedAndStarted') == 'true'}">
<webserver:stop />
</j:if>
</goal>
<!--==================================================================-->
<!-- C L E A N -->
<!--==================================================================-->
<goal name="webserver:clean" prereqs="webserver:init"
description="Safely delete an installed webserver instance">
<j:choose>
<!-- started and installed -->
<j:when test="${context.getVariable('maven.webserver.installedAndStarted') == 'true'}">
<webserver:stop />
<webserver:clean />
</j:when>
<!-- installed not started -->
<j:when test="${context.getVariable('maven.webserver.installed') == 'true'}">
<webserver:clean />
</j:when>
<!-- already cleaned -->
<j:otherwise>
<log:info trim="false">
<j:expr value="${maven.webserver.fullname}"/>: Already cleaned!
</log:info>
</j:otherwise>
</j:choose>
</goal>
</project>