1 28 29 package com.idaremedia.antx.solo; 30 31 import java.io.File ; 32 import java.io.IOException ; 33 import java.net.MalformedURLException ; 34 import java.net.URL ; 35 import java.util.Iterator ; 36 import java.util.List ; 37 import java.util.Map ; 38 39 import org.apache.tools.ant.DynamicAttribute; 40 import org.apache.tools.ant.Project; 41 42 import com.idaremedia.antx.AntX; 43 import com.idaremedia.antx.AntXFixture; 44 import com.idaremedia.antx.FixtureOverlay; 45 import com.idaremedia.antx.apis.Responses; 46 import com.idaremedia.antx.helpers.InputFileLoader; 47 import com.idaremedia.antx.helpers.Tk; 48 import com.idaremedia.antx.ownhelpers.LocalTk; 49 import com.idaremedia.antx.ownhelpers.ScopedProperties; 50 import com.idaremedia.antx.parameters.FlexSourceSupport; 51 import com.idaremedia.antx.starters.TaskSet; 52 53 97 98 public class LocalFixtureTaskSet extends TaskSet 99 implements DynamicAttribute, FixtureOverlay, FlexSourceSupport 100 { 101 107 public LocalFixtureTaskSet() 108 { 109 super(AntX.fixture+"Overlay:"); 110 } 111 112 113 114 118 public LocalFixtureTaskSet(String iam) 119 { 120 super(iam); 121 } 122 123 124 125 129 public final void setMeta(String notes) 130 { 131 m_metaList = notes==null ? "" : notes; 132 } 133 134 135 136 140 public final String getMeta() 141 { 142 return m_metaList; 143 } 144 145 146 147 153 public final Map getMetaMap() 154 { 155 Map map = AntXFixture.newMap(); 156 List l = Tk.splitList(getMeta()); 157 if (!l.isEmpty()) { 158 for (Iterator itr=l.iterator();itr.hasNext();) { 159 String s = itr.next().toString(); 160 int i= s.indexOf('='); 161 if (i>0) { 162 map.put(s.substring(0,i),s.substring(i+1)); 163 } else { 164 map.put(s,""); 165 } 166 } 167 } 168 l=null; 169 return map; 170 } 171 172 173 174 178 public final void setDynamicAttribute(String name, String value) 179 { 180 require_(name!=null,"setAttr- nonzro name"); 181 getOverridePropertiesNoNull().put(name,value); 182 } 183 184 185 186 192 private void setFromPropertiesURL(URL url, String from) 193 { 194 Map p=null; 195 try { 196 p= InputFileLoader.loadProperties(url,null); 197 } catch(IOException iox) { 198 String warning = uistrs().get("task.bad.configfile", 199 from,iox.getMessage()); 200 log(warning,Project.MSG_WARN); 201 } 202 if (p!=null) { 203 getOverridePropertiesNoNull().putAll(p); 204 p.clear(); 205 } 206 } 207 208 209 210 212 public void setFile(String filepath) 213 { 214 require_(filepath!=null,"setFile- nonzro path"); 215 216 File file = getProject().resolveFile(filepath); 217 try { 218 setFromPropertiesURL(AntXFixture.fileUtils().getFileURL(file),filepath); 219 } catch(MalformedURLException mux) { 220 String warning = uistrs().get("task.bad.configfile", 221 filepath,mux.getMessage()); 222 log(warning,Project.MSG_WARN); 223 } 224 } 225 226 227 228 230 public void setResource(String resource) 231 { 232 require_(resource!=null,"setRez- nonzro resource name"); 233 234 URL url = LocalTk.getSystemResource(resource, getProject()); 235 if (url!=null) { 236 setFromPropertiesURL(url,resource); 237 } else { 238 String warning = uistrs().get 239 ("task.bad.configfile", resource,"File Not Found"); 240 log(warning,Project.MSG_WARN); 241 } 242 } 243 244 245 247 public void setURL(String urlstr) 248 { 249 require_(urlstr!=null,"setURL- nonzro URL"); 250 URL url = null; 251 try { 252 url = new URL (urlstr); 253 } catch(MalformedURLException mux) { 254 String warning = uistrs().get("task.bad.configfile", 255 urlstr,mux.getMessage()); 256 log(warning,Project.MSG_WARN); 257 } 258 if (url!=null) { 259 setFromPropertiesURL(url,urlstr); 260 } 261 } 262 263 264 265 268 private void installLocalFixture() 269 { 270 verifyInProject_("install"); 271 if (m_localProperties!=null) { 272 m_localProperties.install(); 273 } 274 } 275 276 277 278 281 private void uninstallLocalFixture() 282 { 283 if (m_localProperties!=null) { 284 m_localProperties.uninstall(new Responses.LogUsing(this)); 285 } 286 } 287 288 289 290 291 297 protected void performNestedTasks() 298 { 299 installLocalFixture(); 300 try { 301 super.performNestedTasks(); 302 } finally { 303 uninstallLocalFixture(); 304 } 305 } 306 307 308 314 protected final Map getOverrideProperties() 315 { 316 return m_localProperties; 317 } 318 319 320 321 325 protected final Map getOverridePropertiesNoNull() 326 { 327 if (m_localProperties==null) { 328 m_localProperties = new ScopedProperties(getProject(),false); 329 } 330 return m_localProperties; 331 } 332 333 334 335 private ScopedProperties m_localProperties; private String m_metaList=""; 337 } 338 339 340 | Popular Tags |