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: TopMakefileAmTemplateGenerator.java,v $
33 *
34 * Author: Jose San Leandro Armend?riz
35 *
36 * Description: Is able to generate top-level Makefile.am 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: TopMakefileAmTemplateGenerator.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.TopMakefileAmTemplate;
54 import org.acmsl.antmake.TopMakefileAmTemplateFactory;
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 top-level <i>Makefile.am</i> templates.
78 * @author <a href="mailto:jsanleandro@yahoo.es"
79 >Jose San Leandro</a>
80 * @version $Revision: 1.2 $
81 */
82 public class TopMakefileAmTemplateGenerator
83 implements TopMakefileAmTemplateFactory
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 TopMakefileAmTemplateGenerator() {};
94
95 /***
96 * Specifies a new weak reference.
97 * @param generator the generator instance to use.
98 */
99 protected static void setReference(
100 TopMakefileAmTemplateGenerator 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 TopMakefileAmTemplateGenerator instance.
116 * @return such instance.
117 */
118 public static TopMakefileAmTemplateGenerator getInstance()
119 {
120 TopMakefileAmTemplateGenerator result = null;
121
122 WeakReference reference = getReference();
123
124 if (reference != null)
125 {
126 result = (TopMakefileAmTemplateGenerator) reference.get();
127 }
128
129 if (result == null)
130 {
131 result = new TopMakefileAmTemplateGenerator() {};
132
133 setReference(result);
134 }
135
136 return result;
137 }
138
139 /***
140 * Generates a top-level <i>Makefile.am</i> template.
141 * @param projectName the project name.
142 * @return a template of such kind.
143 */
144 public TopMakefileAmTemplate createTopMakefileAmTemplate(
145 String projectName)
146 {
147 TopMakefileAmTemplate result = null;
148
149 if (projectName != null)
150 {
151 result = new TopMakefileAmTemplate(projectName) {};
152 }
153
154 return result;
155 }
156
157 /***
158 * Writes a top-level <i>Makefile.am</i> file to disk.
159 * @param template the template to write.
160 * @param outputDir the output folder.
161 * @param task the task (for logging purposes).
162 * @throws AntMakeException if the file cannot be created.
163 */
164 public void write(
165 TopMakefileAmTemplate template,
166 File outputDir,
167 Task task)
168 throws AntMakeException
169 {
170 if ( (template != null)
171 && (outputDir != null))
172 {
173 FileUtils t_FileUtils =
174 FileUtils.getInstance();
175
176 if (t_FileUtils != null)
177 {
178 try
179 {
180 AntMakeUtils.getInstance().log(
181 task,
182 "Writing "
183 + outputDir.getAbsolutePath()
184 + File.separator
185 + "Makefile.am",
186 Project.MSG_VERBOSE);
187
188 t_FileUtils.writeFile(
189 outputDir.getAbsolutePath()
190 + File.separator
191 + "Makefile.am",
192 template.toString());
193 }
194 catch (FileNotFoundException fileNotFoundException)
195 {
196 throw new AntMakeException(
197 "cannot write Makefile.am",
198 fileNotFoundException);
199 }
200 catch (SecurityException securityException)
201 {
202 throw new AntMakeException(
203 "cannot write Makefile.am",
204 securityException);
205 }
206 catch (IOException ioException)
207 {
208 throw new AntMakeException(
209 "cannot write Makefile.am",
210 ioException);
211 }
212 }
213 }
214 }
215 }
This page was automatically generated by Maven