1 package org.tigris.scarab.util.build; 2 3 48 49 import java.io.FileNotFoundException ; 50 import java.io.IOException ; 51 52 import org.apache.tools.ant.BuildException; 53 import org.apache.tools.ant.Task; 54 55 62 63 public class AntPropertyFileGenerator extends Task implements PropertyGetter 64 { 65 66 71 72 75 private PropertyFileGenerator generator = new PropertyFileGenerator(); 76 77 public void setTemplate(String theTemplatePath) 78 { 79 boolean status = generator.setTemplate(theTemplatePath); 80 if(!status) 81 { 82 throw new BuildException("the template[" 83 + theTemplatePath 84 + "] does not exist."); 85 } 86 } 87 88 94 public void setCustom(String theCustomPath) 95 { 96 boolean status = generator.setCustom(theCustomPath); 97 if(!status) 98 { 99 throw new BuildException("custom file [" 100 + generator.getCustom() 101 + "] is not writable."); 102 103 } 104 } 105 106 112 public void setProperties(String thePropertyFilePathes) 113 { 114 boolean status = generator.setProperties(thePropertyFilePathes); 115 if(!status) 116 { 117 throw new BuildException("problem with the propretyFilePathlist[" 118 + thePropertyFilePathes 119 + "] one file is not readable."); 120 121 } 122 } 123 124 125 143 public void execute() { 144 log("Create custom file: '" + generator.getCustom() + "'."); 145 log("Using template : '" + generator.getTemplate() ); 146 147 try { 148 generator.execute(this); 149 } 150 catch (FileNotFoundException e) 151 { 152 throw new BuildException( "File not found: " + e.getMessage() ); 153 } 154 catch (IOException e) 155 { 156 throw new BuildException("Error during read from [" 157 + generator.getTemplate() 158 + "]: "+e.getMessage()); 159 } 160 161 } 162 163 169 public Object getProperty(String name, Object def) 170 { 171 String result = null; 172 173 String value = (String ) def; 174 if (value==null || !value.startsWith("$")) 175 { 176 result = getProject().getProperty(name); 177 } 178 if(result == null) 179 { 180 result = value; 181 } 182 return result; 183 } 184 } 185 | Popular Tags |