KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > publishers > AntPublisher


1 /********************************************************************************
2  * CruiseControl, a Continuous Integration Toolkit
3  * Copyright (c) 2001, ThoughtWorks, Inc.
4  * 651 W Washington Ave. Suite 600
5  * Chicago, IL 60661 USA
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * + Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * + Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  *
20  * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
21  * names of its contributors may be used to endorse or promote
22  * products derived from this software without specific prior
23  * written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  ********************************************************************************/

37 package net.sourceforge.cruisecontrol.publishers;
38
39 import java.util.HashMap JavaDoc;
40 import java.util.Iterator JavaDoc;
41 import java.util.Map JavaDoc;
42
43 import org.apache.log4j.Logger;
44 import org.jdom.Attribute;
45 import org.jdom.Element;
46
47 import net.sourceforge.cruisecontrol.CruiseControlException;
48 import net.sourceforge.cruisecontrol.Publisher;
49 import net.sourceforge.cruisecontrol.builders.AntBuilder;
50 import net.sourceforge.cruisecontrol.builders.Property;
51 import net.sourceforge.cruisecontrol.util.XMLLogHelper;
52
53 /**
54  * A thin wrapper around the AntBuilder class, this class allows you to call an
55  * Ant script as a publisher.
56  * <p>
57  * All properties set by CC and passed to the builder will be available as
58  * properties within Ant.
59  *
60  * @author <a HREF="mailto:rjmpsmith@hotmail.com">Robert J. Smith </a>
61  */

62 public class AntPublisher implements Publisher {
63     
64     private static final Logger LOG = Logger.getLogger(AntPublisher.class);
65
66     private AntBuilder delegate = new AntBuilder();
67     
68     /* (non-Javadoc)
69      * @see net.sourceforge.cruisecontrol.Publisher#publish(org.jdom.Element)
70      */

71     public void publish(Element log) throws CruiseControlException {
72         
73         Map JavaDoc properties = new HashMap JavaDoc();
74
75         populatePropertesForAntBuilder(log, properties);
76         
77         // Run Ant
78
Element result = delegate.build(properties);
79         if (result == null) {
80             LOG.error("Publisher failed.\n\n");
81         } else {
82             Attribute error = result.getAttribute("error");
83             if (error == null) {
84                 LOG.info("Publisher successful.");
85             } else {
86                 LOG.error("Publisher failed.\n\n"
87                         + error.getValue()
88                         + "\n");
89             }
90         }
91     }
92
93     public void validate() throws CruiseControlException {
94         delegate.validate();
95     }
96
97     /**
98      * @see net.sourceforge.cruisecontrol.builders.AntBuilder#setSaveLogDir(String)
99      */

100     public void setSaveLogDir(String JavaDoc dir) {
101         delegate.setSaveLogDir(dir);
102     }
103
104     /**
105      * @see net.sourceforge.cruisecontrol.builders.AntBuilder#setAntWorkingDir(String)
106      */

107     public void setAntWorkingDir(String JavaDoc dir) {
108         delegate.setAntWorkingDir(dir);
109     }
110
111     /**
112      * @see net.sourceforge.cruisecontrol.builders.AntBuilder#setAntScript(String)
113      */

114     public void setAntScript(String JavaDoc antScript) {
115         delegate.setAntScript(antScript);
116     }
117
118     /**
119      * @see net.sourceforge.cruisecontrol.builders.AntBuilder#setAntHome(String)
120      */

121     public void setAntHome(String JavaDoc antHome) {
122         delegate.setAntHome(antHome);
123     }
124
125     /**
126      * @see net.sourceforge.cruisecontrol.builders.AntBuilder#setTempFile(String)
127      */

128     public void setTempFile(String JavaDoc tempFileName) {
129         delegate.setTempFile(tempFileName);
130     }
131
132     /**
133      * @see net.sourceforge.cruisecontrol.builders.AntBuilder#setTarget(String)
134      */

135     public void setTarget(String JavaDoc target) {
136         delegate.setTarget(target);
137     }
138
139     /**
140      * @see net.sourceforge.cruisecontrol.builders.AntBuilder#setBuildFile(String)
141      */

142     public void setBuildFile(String JavaDoc buildFile) {
143         delegate.setBuildFile(buildFile);
144     }
145
146     /**
147      * @see net.sourceforge.cruisecontrol.builders.AntBuilder#setUseLogger(boolean)
148      */

149     public void setUseLogger(boolean useLogger) {
150         delegate.setUseLogger(useLogger);
151     }
152
153     /**
154      * @see net.sourceforge.cruisecontrol.builders.AntBuilder#createJVMArg()
155      */

156     public Object JavaDoc createJVMArg() {
157         return delegate.createJVMArg();
158     }
159
160     /**
161      * @see net.sourceforge.cruisecontrol.builders.AntBuilder#createProperty()
162      */

163     public Property createProperty() {
164         return delegate.createProperty();
165     }
166
167     /**
168      * @see net.sourceforge.cruisecontrol.builders.AntBuilder#setUseDebug(boolean)
169      */

170     public void setUseDebug(boolean debug) {
171         delegate.setUseDebug(debug);
172     }
173
174     /**
175      * @see net.sourceforge.cruisecontrol.builders.AntBuilder#setUseQuiet(boolean)
176      */

177     public void setUseQuiet(boolean quiet) {
178         delegate.setUseQuiet(quiet);
179     }
180
181     /**
182      * @see net.sourceforge.cruisecontrol.builders.AntBuilder#getLoggerClassName()
183      */

184     public String JavaDoc getLoggerClassName() {
185         return delegate.getLoggerClassName();
186     }
187
188     /**
189      * @see net.sourceforge.cruisecontrol.builders.AntBuilder#setLoggerClassName(String)
190      */

191     public void setLoggerClassName(String JavaDoc string) {
192         delegate.setLoggerClassName(string);
193     }
194
195     /**
196      * @see net.sourceforge.cruisecontrol.builders.AntBuilder#setTimeout(long)
197      */

198     public void setTimeout(long timeout) {
199         delegate.setTimeout(timeout);
200     }
201
202     void populatePropertesForAntBuilder(Element log, Map JavaDoc properties) {
203         XMLLogHelper helper = new XMLLogHelper(log);
204         if (helper.isBuildSuccessful()) {
205             properties.put("thisbuildsuccessful", "true");
206         } else {
207             properties.put("thisbuildsuccessful", "false");
208         }
209
210         Iterator JavaDoc propertyIterator = log.getChild("info").getChildren("property").iterator();
211         while (propertyIterator.hasNext()) {
212             Element property = (Element) propertyIterator.next();
213             properties.put(property.getAttributeValue("name"),
214                     property.getAttributeValue("value"));
215         }
216     }
217 }
218
Popular Tags