1 28 29 package com.idaremedia.antx; 30 31 import java.util.Iterator ; 32 import java.util.List ; 33 import java.util.Map ; 34 35 import org.apache.tools.ant.Project; 36 import org.apache.tools.ant.util.FileUtils; 37 38 import com.idaremedia.apis.FixtureStarter; 39 40 import com.idaremedia.antx.apis.BuildError; 41 import com.idaremedia.antx.apis.ProblemHandler; 42 import com.idaremedia.antx.helpers.Empties; 43 44 64 65 public final class AntXFixture extends FixtureStarter implements FixtureCore 66 { 67 private static final String IAM_= "AntX.Fixture:"; 68 69 70 71 76 public static FileUtils fileUtils() 77 { 78 return FileUtils.getFileUtils(); 79 } 80 81 82 83 87 static KillMethod getKillMethod(String target) 88 { 89 return (KillMethod)m_killMethods.get(target); 90 } 91 92 93 94 101 public static void setKillMethod(String component, KillMethod method) 102 { 103 setKillMethod(component, Empties.EMPTY_STRING_ARRAY, method); 104 } 105 106 107 108 118 public static void setKillMethod(String component, String [] aliases, 119 KillMethod method) 120 { 121 AntX.require_(component!=null,IAM_,"setKillMeth- nonzro id"); 122 AntX.require_(method!=null,IAM_,"setKillMeth- nonzro method"); 123 AntX.require_(aliases!=null,IAM_,"setKillMeth- nonzro aliases"); 124 125 KillMethod method0 = getKillMethod(component); 126 if (method0!=null) { 127 throw new BuildError 128 (AntX.uistrs().get("fixture.cleanup.instald",component)); 129 } 130 131 m_killMethods.put(component,method); 132 133 for (int i=0;i<aliases.length;i++) { 134 AntX.require_(m_killMethods.put(aliases[i],method)==null, IAM_, 135 "setKillMeth- unique component alias("+aliases[i]+")"); 136 } 137 138 m_FXIDs.add(component); 139 } 140 141 142 143 152 public static boolean reset(String component, String aspect, 153 ProblemHandler from) 154 { 155 AntX.require_(from!=null,IAM_,"reset- nonzro source"); 156 AntX.require_(component!=null,IAM_,"reset- nonzro id"); 157 158 KillMethod method0 = getKillMethod(component); 159 if (method0!=null) { 160 boolean ok = method0.kill(aspect, from); 161 if (!ok) { 162 String warning = AntX.uistrs().get 163 ("fixture.errs.killin.comp.aspect", component,aspect); 164 from.problem(warning, Project.MSG_WARN); 165 } 166 return ok; 167 } 168 return true; 169 } 170 171 172 173 183 public static boolean reset(String component, String aspect, 184 KillMethod fallback, ProblemHandler from) 185 { 186 AntX.require_(from!=null,IAM_,"reset- nonzro source"); 187 AntX.require_(component!=null,IAM_,"reset- nonzro id"); 188 AntX.require_(fallback!=null,IAM_,"reset- nonzro fallback"); 189 190 KillMethod method0 = getKillMethod(component); 191 if (method0==null) { 192 method0= fallback; 193 } 194 boolean ok = method0.kill(aspect, from); 195 if (!ok) { 196 String warning = AntX.uistrs().get 197 ("fixture.errs.killin.comp.aspect", component,aspect); 198 from.problem(warning, Project.MSG_WARN); 199 } 200 return ok; 201 } 202 203 204 205 212 public static void reset(ProblemHandler from) 213 { 214 AntX.require_(from!=null,IAM_,"reset- nonzro source"); 215 216 List l= FixtureStarter.newListCopy(m_FXIDs); 217 218 Iterator itr= l.iterator(); 219 while (itr.hasNext()) { 220 String component = itr.next().toString(); 221 KillMethod method = getKillMethod(component); 222 if (!method.kill(from)) { 223 String warning = AntX.uistrs().get 224 ("fixture.errs.killin.comp", component); 225 from.problem(warning, Project.MSG_WARN); 226 } 227 } 228 229 l=null; 230 } 231 232 233 234 237 private AntXFixture() 238 { 239 } 240 241 242 private static final List m_FXIDs= FixtureStarter.newSynchronizedList(); 243 private static final Map m_killMethods= FixtureStarter.newSynchronizedMap(); 244 } 245 246 247 | Popular Tags |