1 /*
2 AntMake
3
4 Copyright (C) 2004 Jose San Leandro Armend?riz
5 jsanleandro@yahoo.es
6 chousz@yahoo.com
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 You should have received a copy of the GNU General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22 Thanks to ACM S.L. for distributing this library under the GPL license.
23 Contact info: jsanleandro@yahoo.es
24 Postal Address: c/Playa de Lagoa, 1
25 Urb. Valdecaba?as
26 Boadilla del monte
27 28660 Madrid
28 Spain
29
30 ******************************************************************************
31 *
32 * Filename: $RCSfile: ConfigureInTemplateGenerator.java,v $
33 *
34 * Author: Jose San Leandro Armend?riz
35 *
36 * Description: Is able to generate configure.in templates.
37 *
38 * Last modified by: $Author: chous $ at $Date: 2004/01/25 20:20:15 $
39 *
40 * File version: $Revision: 1.2 $
41 *
42 * Project version: $Name: $
43 *
44 * $Id: ConfigureInTemplateGenerator.java,v 1.2 2004/01/25 20:20:15 chous Exp $
45 *
46 */
47 package org.acmsl.antmake;
48
49 /*
50 * Importing some project-specific classes.
51 */
52 import org.acmsl.antmake.AntMakeUtils;
53 import org.acmsl.antmake.ConfigureInTemplate;
54 import org.acmsl.antmake.ConfigureInTemplateFactory;
55
56 /*
57 * Importing some ACM-SL Commons classes.
58 */
59 import org.acmsl.commons.utils.io.FileUtils;
60
61 /*
62 * Importing some Ant classes.
63 */
64 import org.apache.tools.ant.Project;
65 import org.apache.tools.ant.Task;
66
67 /*
68 * Importing some JDK classes.
69 */
70 import java.io.File;
71 import java.io.FileNotFoundException;
72 import java.io.IOException;
73 import java.lang.ref.WeakReference;
74 import java.lang.SecurityException;
75
76 /***
77 * Is able to generate <i>configure.in</i> templates.
78 * @author <a href="mailto:jsanleandro@yahoo.es"
79 >Jose San Leandro</a>
80 * @version $Revision: 1.2 $
81 */
82 public class ConfigureInTemplateGenerator
83 implements ConfigureInTemplateFactory
84 {
85 /***
86 * Singleton implemented as a weak reference.
87 */
88 private static WeakReference singleton;
89
90 /***
91 * Protected constructor to avoid accidental instantiation.
92 */
93 protected ConfigureInTemplateGenerator() {};
94
95 /***
96 * Specifies a new weak reference.
97 * @param generator the generator instance to use.
98 */
99 protected static void setReference(
100 ConfigureInTemplateGenerator generator)
101 {
102 singleton = new WeakReference(generator);
103 }
104
105 /***
106 * Retrieves the weak reference.
107 * @return such reference.
108 */
109 protected static WeakReference getReference()
110 {
111 return singleton;
112 }
113
114 /***
115 * Retrieves a ConfigureInTemplateGenerator instance.
116 * @return such instance.
117 */
118 public static ConfigureInTemplateGenerator getInstance()
119 {
120 ConfigureInTemplateGenerator result = null;
121
122 WeakReference reference = getReference();
123
124 if (reference != null)
125 {
126 result = (ConfigureInTemplateGenerator) reference.get();
127 }
128
129 if (result == null)
130 {
131 result = new ConfigureInTemplateGenerator() {};
132
133 setReference(result);
134 }
135
136 return result;
137 }
138
139 /***
140 * Generates a <i>configure.in</i> template.
141 * @param projectName the project name.
142 * @param projectVersion the project version.
143 * @return a template of such kind.
144 */
145 public ConfigureInTemplate createConfigureInTemplate(
146 String projectName, String projectVersion)
147 {
148 ConfigureInTemplate result = null;
149
150 if (projectName != null)
151 {
152 result =
153 new ConfigureInTemplate(
154 projectName, projectVersion) {};
155 }
156
157 return result;
158 }
159
160 /***
161 * Writes a <i>configure.in</i> file to disk.
162 * @param template the template to write.
163 * @param outputDir the output folder.
164 * @param task the task (for logging purposes).
165 * @throws AntMakeException if the file cannot be created.
166 */
167 public void write(
168 ConfigureInTemplate template,
169 File outputDir,
170 Task task)
171 throws AntMakeException
172 {
173 if ( (template != null)
174 && (outputDir != null))
175 {
176 FileUtils t_FileUtils =
177 FileUtils.getInstance();
178
179 if (t_FileUtils != null)
180 {
181 try
182 {
183 AntMakeUtils.getInstance().log(
184 task,
185 "Writing "
186 + outputDir.getAbsolutePath()
187 + File.separator
188 + "configure.in",
189 Project.MSG_VERBOSE);
190
191 t_FileUtils.writeFile(
192 outputDir.getAbsolutePath()
193 + File.separator
194 + "configure.in",
195 template.toString());
196 }
197 catch (FileNotFoundException fileNotFoundException)
198 {
199 throw new AntMakeException(
200 "cannot write configure.in",
201 fileNotFoundException);
202 }
203 catch (SecurityException securityException)
204 {
205 throw new AntMakeException(
206 "cannot write configure.in",
207 securityException);
208 }
209 catch (IOException ioException)
210 {
211 throw new AntMakeException(
212 "cannot write configure.in",
213 ioException);
214 }
215 }
216 }
217 }
218 }
This page was automatically generated by Maven