1 28 29 package com.idaremedia.antx.flowcontrol; 30 31 import java.lang.reflect.Constructor ; 32 33 import org.apache.tools.ant.BuildException; 34 import org.apache.tools.ant.Location; 35 import org.apache.tools.ant.Project; 36 37 import com.idaremedia.antx.AntX; 38 import com.idaremedia.antx.NoiseLevel; 39 import com.idaremedia.antx.apis.BuildError; 40 import com.idaremedia.antx.helpers.InnerString; 41 import com.idaremedia.antx.helpers.Tk; 42 import com.idaremedia.antx.ownhelpers.LocalTk; 43 import com.idaremedia.antx.starters.MsgTask; 44 45 69 70 public class StopTask extends MsgTask 71 { 72 75 public StopTask() 76 { 77 super(AntX.flow+"stop"); 78 } 79 80 81 85 public StopTask(String iam) 86 { 87 super(iam); 88 } 89 90 91 97 public void init() 98 { 99 super.init(); 100 101 Location loc = getLocation(); 102 103 if (loc!=Location.UNKNOWN_LOCATION) { 104 if (Tk.isWhitespace(getDefaultMsg())) { 105 String locationString = uistrs().get 106 ("stop.defaultmsg",getTaskName(),LocalTk.purtyLocation(loc)); 107 addConfiguredDefaultMsg(new InnerString(locationString)); 108 } 109 } 110 } 111 112 113 114 118 public NoiseLevel getDefaultMsgLevel() 119 { 120 return isFatal() ? NoiseLevel.FATAL : NoiseLevel.ERROR; 121 } 122 123 124 125 129 public void setFatal(boolean fatal) 130 { 131 m_tryFatal = fatal; 132 } 133 134 135 139 public final boolean isFatal() 140 { 141 return m_tryFatal; 142 } 143 144 145 152 public void setWith(Class claz) 153 { 154 require_(claz!=null,"setWith- nonzro clas"); 155 if (!BuildException.class.isAssignableFrom(claz)) { 156 String ermsg = uistrs().get("stop.bad.throwclass",claz.getName()); 157 log(ermsg,Project.MSG_ERR); 158 throw new BuildException(ermsg,getLocation()); 159 } 160 m_throwClass = claz; 161 } 162 163 164 168 public final Class getWith() 169 { 170 return m_throwClass; 171 } 172 173 174 180 public void execute() 181 { 182 verifyCanExecute_("execute"); 183 184 if (testIfCondition() && testUnlessCondition()) { 185 String ermsg = getMsg(); 186 aboutToStop(ermsg); 187 if (isFatal()) { 188 throw new BuildError(ermsg,getLocation()); 189 } 190 throw new_BuildException(ermsg,getLocation()); 191 } 192 } 193 194 195 200 protected void aboutToStop(String ermsg) 201 { 202 log(ermsg, getMsgLevel().getNativeIndex()); 203 } 204 205 206 209 private BuildException new_BuildException(String ermsg, Location theLocation) 210 { 211 BuildException tbt=null; 212 213 if (getWith()!=null) { 214 Class claz= getWith(); 215 try { 216 Constructor ctor= claz.getConstructor(DFLT_SIGNATURE); 217 Object [] params = new Object []{ermsg,theLocation}; 218 tbt = (BuildException)ctor.newInstance(params); 219 } catch(Exception anyX) { 220 log(uistrs().get("stop.cant.make.custom.reason",claz.getName(), 221 anyX.getMessage()), Project.MSG_WARN); 222 } 223 } 224 if (tbt==null) { 225 tbt= new BuildException(ermsg,theLocation); 226 } 227 return tbt; 228 } 229 230 231 232 private boolean m_tryFatal; private Class m_throwClass; 234 235 236 237 protected static final Class [] DFLT_SIGNATURE= new Class [] { 238 String .class, Location.class 239 }; 240 } 241 242 243 | Popular Tags |