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

This page was automatically generated by Maven