plynch      2004/04/25 13:19:51

  Modified:    appserver plugin.jelly
  Log:
  o instead of Ant conditions to test socket connections and http connections, use 
Jelly so that properties can be reset each time init is called.
  
  Issue ID: MPAPPSERVER-7
  
  Revision  Changes    Path
  1.9       +48 -20    maven-plugins/appserver/plugin.jelly
  
  Index: plugin.jelly
  ===================================================================
  RCS file: /home/cvs/maven-plugins/appserver/plugin.jelly,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- plugin.jelly      17 Apr 2004 01:09:51 -0000      1.8
  +++ plugin.jelly      25 Apr 2004 20:19:51 -0000      1.9
  @@ -1,14 +1,14 @@
   <?xml version="1.0"?>
  -<!-- 
  +<!--
   /*
    * Copyright 2001-2004 The Apache Software Foundation.
  - * 
  + *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
  - * 
  + *
    *      http://www.apache.org/licenses/LICENSE-2.0
  - * 
  + *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  @@ -284,25 +284,53 @@
   
       <!-- a flag to see if the appserver is started -->
       <j:remove var="maven.appserver.started" />
  -    <ant:condition property="maven.appserver.started">
  -      <ant:and>
  -        <ant:socket server="${maven.appserver.host}"
  -          port="${maven.appserver.test.socket}" />
  -        <!-- only use the test url if defined, else just use the socket -->
  -        <j:if test="${context.getVariable('maven.appserver.test.url') != null}">
  -          <ant:http url="${maven.appserver.test.url}" />
  +    <j:remove var="failedSocket" />
  +    <j:set var="canHttpConnect" value="true" /><!-- default -->
  +    <j:if test="${context.getVariable('maven.appserver.test.url') != null}">
  +      <!-- override default true above because test url is optional -->
  +      <j:set var="canHttpConnect" value="false" />
  +      <!-- test url connection -->
  +      <j:catch var="httpConnectException" >
  +        <j:new className="java.net.URL" var="testURL" >
  +          <j:arg type="java.lang.String"
  +            value="${context.getVariable('maven.appserver.test.url')}" />
  +        </j:new>
  +        <j:invoke on="${testURL}" method="openConnection" var="testConnection"/>
  +        <j:invoke on="${testConnection}" method="getResponseCode" 
var="testResponse" />
  +        <j:if test="${testResponse gt 0 and testResponse lt 400}">
  +          <j:set var="canHttpConnect" value="true" />
           </j:if>
  -      </ant:and>
  -    </ant:condition>
  +      </j:catch>
  +      <j:if 
test="${httpConnectException.getCause().getCause().toString().indexOf('MalformedURLException')
 ge 0}">
  +        <exception:appserverTestURLInvalid
  +          propname="maven.appserver.test.url"
  +          propvalue="${context.getVariable('maven.appserver.test.url')}"
  +          cause="${httpConnectException}"/>
  +      </j:if>
  +      <!-- clean up the objects to prevent leak in long sessions -->
  +      <j:remove var="testURL" />
  +      <j:remove var="testConnection" />
  +      <j:remove var="testResponse" />
  +    </j:if>
  +    <!-- always test socket -->
  +    <j:catch var="failedSocket">
  +      <j:new className="java.net.Socket" var="dummy">
  +        <j:arg type="java.lang.String"
  +          value="${context.getVariable('maven.appserver.host')}" />
  +        <j:arg type="int"
  +          value="${context.getVariable('maven.appserver.test.socket')}" />
  +      </j:new>
  +    </j:catch>
  +    <j:if test="${failedSocket.getCause() == null and canHttpConnect == 'true'}">
  +      <j:set var="maven.appserver.started" value="true" />
  +    </j:if>
   
  -    <!-- a flag to see if the appserver is installed -->
       <j:remove var="maven.appserver.installed" />
  -    <ant:condition property="maven.appserver.installed">
  -      <ant:and>
  -        <ant:available file="${maven.appserver.root}" type="dir" />
  -        <ant:available file="${maven.appserver.dir}" type="dir" />
  -      </ant:and>
  -    </ant:condition>
  +    <util:available file="${maven.appserver.root}" >
  +      <util:available file="${maven.appserver.dir}" >
  +        <j:set var="maven.appserver.installed" value="true" />
  +      </util:available>
  +    </util:available>
   
       <j:if test="${context.getVariable('maven.appserver.started') == 'true' and 
context.getVariable('maven.appserver.installed') == 'true'}">
         <j:set var="maven.appserver.installedAndStarted" value="true" />
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to