KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > builders > NantScript


1 /********************************************************************************
2  * CruiseControl, a Continuous Integration Toolkit
3  * Copyright (c) 2003, 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.builders;
38
39 import java.util.Iterator JavaDoc;
40 import java.util.List JavaDoc;
41 import java.util.Map JavaDoc;
42 import java.util.StringTokenizer JavaDoc;
43
44 import net.sourceforge.cruisecontrol.util.Commandline;
45
46 /**
47  * NAnt script class.
48  *
49  * Contains all the details related to running a NAnt based build.
50  * @author <a HREF="mailto:epugh@opensourceconnections.com">Eric Pugh</a>
51  */

52 public class NantScript implements Script {
53     private Map JavaDoc buildProperties;
54     private List JavaDoc nantProperties;
55
56     private String JavaDoc loggerClassName;
57     private String JavaDoc tempFileName = "log.xml";
58     private boolean useLogger;
59     private boolean useQuiet;
60     private boolean useDebug;
61     private String JavaDoc buildFile = "default.build";
62     private String JavaDoc target = "";
63     private String JavaDoc targetFramework;
64     private int exitCode;
65
66     /**
67      * construct the command that we're going to execute.
68      *
69      * @return Commandline holding command to be executed
70      */

71     public Commandline buildCommandline() {
72         Commandline cmdLine = getCommandLine();
73
74         cmdLine.setExecutable("NAnt.exe");
75         if (useLogger) {
76             cmdLine.createArgument().setValue("-logger:" + getLoggerClassName());
77             cmdLine.createArgument().setValue("-logfile:" + tempFileName);
78         } else {
79             cmdLine.createArgument().setValue("-listener:" + getLoggerClassName());
80             cmdLine.createArgument().setValue("-D:XmlLogger.file=" + tempFileName);
81         }
82         /*
83         if (useVerbose) {
84             cmdLine.createArgument().setValue("-verbose");
85         }
86         */

87         if (useDebug) {
88             cmdLine.createArgument().setValue("-debug+");
89         } else if (useQuiet) {
90             cmdLine.createArgument().setValue("-quiet+");
91         }
92         if (targetFramework != null) {
93             cmdLine.createArgument().setValue("-t:" + targetFramework);
94         }
95
96         for (Iterator JavaDoc propertiesIter = buildProperties.entrySet().iterator(); propertiesIter.hasNext();) {
97             Map.Entry JavaDoc property = (Map.Entry JavaDoc) propertiesIter.next();
98             String JavaDoc value = (String JavaDoc) property.getValue();
99             if (!"".equals(value)) {
100                 cmdLine.createArgument().setValue("-D:" + property.getKey() + "=" + value);
101             }
102         }
103         for (Iterator JavaDoc nantPropertiesIterator = nantProperties.iterator(); nantPropertiesIterator.hasNext(); ) {
104             Property property = (Property) nantPropertiesIterator.next();
105             cmdLine.createArgument().setValue("-D:" + property.getName() + "=" + property.getValue());
106         }
107
108         cmdLine.createArgument().setValue("-buildfile:" + buildFile);
109
110         StringTokenizer JavaDoc targets = new StringTokenizer JavaDoc(target);
111         while (targets.hasMoreTokens()) {
112             cmdLine.createArgument().setValue(targets.nextToken());
113         }
114         return cmdLine;
115     }
116
117     // factory method for mock...
118
protected Commandline getCommandLine() {
119         return new Commandline();
120     }
121
122     /**
123      * @param buildProperties The buildProperties to set.
124      */

125     public void setBuildProperties(Map JavaDoc buildProperties) {
126         this.buildProperties = buildProperties;
127     }
128     
129     public void setNantProperties(List JavaDoc properties) {
130         this.nantProperties = properties;
131     }
132
133     /**
134      * @return Returns the loggerClassName.
135      */

136     public String JavaDoc getLoggerClassName() {
137         return loggerClassName;
138     }
139     /**
140      * @param loggerClassName The loggerClassName to set.
141      */

142     public void setLoggerClassName(String JavaDoc loggerClassName) {
143         this.loggerClassName = loggerClassName;
144     }
145     /**
146      * @param buildFile The buildFile to set.
147      */

148     public void setBuildFile(String JavaDoc buildFile) {
149         this.buildFile = buildFile;
150     }
151     /**
152      * @param tempFileName The tempFileName to set.
153      */

154     public void setTempFileName(String JavaDoc tempFileName) {
155         this.tempFileName = tempFileName;
156     }
157     /**
158      * @param useDebug The useDebug to set.
159      */

160     public void setUseDebug(boolean useDebug) {
161         this.useDebug = useDebug;
162     }
163     /**
164      * @param useVerbose The useDebug to set.
165      */

166     /*
167     public void setUseVerbose(boolean useVerbose) {
168         this.useVerbose = useVerbose;
169     }
170     */

171     /**
172      * @param useLogger The useLogger to set.
173      */

174     public void setUseLogger(boolean useLogger) {
175         this.useLogger = useLogger;
176     }
177     /**
178      * @param useQuiet The useQuiet to set.
179      */

180     public void setUseQuiet(boolean useQuiet) {
181         this.useQuiet = useQuiet;
182     }
183     /**
184      * @param target The target to set.
185      */

186     public void setTarget(String JavaDoc target) {
187         this.target = target;
188     }
189     /**
190      * @param targetFramework The targetFramework to set.
191      */

192     public void setTargetFramework(String JavaDoc targetFramework) {
193         this.targetFramework = targetFramework;
194     }
195     /**
196      * @return Returns the exitCode.
197      */

198     public int getExitCode() {
199         return exitCode;
200     }
201     /**
202      * @param exitCode The exitCode to set.
203      */

204     public void setExitCode(int exitCode) {
205         this.exitCode = exitCode;
206     }
207 }
208
Popular Tags