2011/08/05 - Jakarta Cactus has been retired.

For more information, please explore the Attic.

View Javadoc

1   /* 
2    * ========================================================================
3    * 
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements.  See the NOTICE file distributed with
6    * this work for additional information regarding copyright ownership.
7    * The ASF licenses this file to You under the Apache License, Version 2.0
8    * (the "License"); you may not use this file except in compliance with
9    * the License.  You may obtain a copy of the License at
10   * 
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * 
19   * ========================================================================
20   */
21  package org.apache.cactus.integration.ant;
22  
23  import org.apache.tools.ant.BuildException;
24  import org.codehaus.cargo.ant.CargoTask;
25  import org.codehaus.cargo.container.Container;
26  import org.codehaus.cargo.container.ContainerType;
27  import org.codehaus.cargo.container.InstalledLocalContainer;
28  /**
29   * This is the element in the cactus task that holds 
30   * the cargo properties, and in which the configuration for 
31   * the cargo container is hold.
32   * @version $Id: CactusWar.java 239162 2005-04-26 09:57:59Z paranoiabla $
33   */
34  public class CargoElement extends CargoTask
35  {
36      /**
37       * The container to create.
38       */
39      private Container container = null;
40      
41      
42     /**
43      * Creates, verifies and initializes the container.
44      *  
45      * @return Container
46      */
47      protected Container getCargoContainer()
48      {
49          container = makeContainer();
50          
51          // Verify that the task is correctly set up.
52          verify();
53  
54          // Setup all attributes and nested elements
55  
56          setupLogger();
57  
58          if (getContainer().getType().isLocal())
59          {
60              setupOutput();
61              setupTimeout();
62  
63              if (getContainer().getType() == ContainerType.INSTALLED)
64              {
65                  setupHome();
66                  setupExtraClasspath();
67                  setupSystemProperties();
68              }
69          }
70  
71          // Save the reference id if specified
72          if (getId() != null)
73          {
74              getProject().addReference(getId(), getContainer());
75          }
76          return container;
77      }
78  
79      
80     /**
81      * Checks if the task is correctly initialized and that the container
82      * is ready to be used.
83      */
84      private void verify()
85      {
86          if ((getId() != null) && (getRefid() != null))
87          {
88              throw new BuildException("You must use either [id]"
89                  + " or [refid] but not both");
90          }
91  
92          if ((getContainerId() == null) && (getRefid() == null))
93          {
94              throw new BuildException("You must specify a [containerId]"
95                  + " attribute or use a [refid] "
96                  + "attribute");
97          }
98  
99          if ((getHome() == null) && (getZipURLInstaller() == null))
100         {
101             boolean doFail = false;
102 
103             if (getRefid() == null)
104             {
105                 doFail = true;
106             }
107             else if ((getContainer().getType() == ContainerType.INSTALLED)
108                 && (((InstalledLocalContainer) getContainer())
109                     .getHome() == null))
110             {
111                 doFail = true;
112             }
113 
114             if (doFail)
115             {
116                 throw new BuildException("You must specify either"
117                     + " a [home] attribute pointing "
118                     + "to the location where the " + getContainer().getName()
119                     + " is installed, or a nested [zipurlinstaller] element");
120             }
121         }
122     }
123     
124     /**
125      * Override the method so that we use our container.
126      * @return Container - the current container being used
127      */
128     public Container getContainer() 
129     {
130     	return this.container;
131     }
132 }