1 28 29 package com.idaremedia.antx.go; 30 31 import org.apache.tools.ant.Main; 32 import org.apache.tools.ant.Project; 33 import org.apache.tools.ant.util.regexp.RegexpMatcher; 34 import org.apache.tools.ant.util.regexp.RegexpMatcherFactory; 35 36 import com.idaremedia.antx.helpers.Tk; 37 38 53 54 public final class IffAnt 55 { 56 private static final RegexpMatcherFactory REMFactory = 57 new RegexpMatcherFactory(); 58 59 private static final String DFLT_VERSION_PROPERTY = 60 "ant.version"; 61 62 70 public static boolean pass(String pattern, String property, 71 Project P, boolean ifNot) 72 { 73 if (Tk.isWhitespace(pattern) || Tk.isWhitespace(property)) { 74 return false; 75 } 76 pattern = Tk.resolveString(P,pattern); 77 78 RegexpMatcher re = REMFactory.newRegexpMatcher(P); 79 re.setPattern(pattern); 80 81 String setting = null; 82 if (P!=null) { 83 setting = P.getProperty(property); 84 } 85 if (setting==null) { setting = Main.getAntVersion(); 87 } 88 89 boolean is = re.matches(setting); 90 re= null; 91 return ifNot ? !is : is; 92 } 93 94 95 102 public static boolean pass(String pattern, Project P, boolean ifNot) 103 { 104 return pass(pattern, DFLT_VERSION_PROPERTY, P, ifNot); 105 } 106 107 108 116 public static final class IsLike extends Go.TestSkeleton { 117 public IsLike() { 118 } 119 public IsLike(String pattern) { 120 super(pattern); 121 } 122 public boolean pass(Project P) { 123 verifyInited(); 124 return IffAnt.pass(getParameter(),P,false); 125 } 126 public String getParameterName() { 127 return "ifAntLike"; 128 } 129 } 130 131 132 140 public static final class IsNotLike extends Go.TestSkeleton { 141 public IsNotLike() { 142 } 143 public IsNotLike(String pattern) { 144 super(pattern); 145 } 146 public boolean pass(Project P) { 147 verifyInited(); 148 return IffAnt.pass(getParameter(),P,true); 149 } 150 public String getParameterName() { 151 return "unlessAntLike"; 152 } 153 } 154 155 156 164 public static final class IsLikeProperty extends Go.TestSkeleton { 165 public IsLikeProperty() { 166 } 167 public IsLikeProperty(String pattern, String property) { 168 super(pattern); 169 setSourceProperty(property); 170 } 171 public boolean pass(Project P) { 172 verifyInited(); 173 return IffAnt.pass(getParameter(),m_versionProperty,P,false); 174 } 175 public String getParameterName() { 176 return "ifAntLikeProperty"; 177 } 178 public void setSourceProperty(String property) 179 { 180 m_versionProperty = property; 181 } 182 private String m_versionProperty= DFLT_VERSION_PROPERTY; 183 } 184 185 186 189 private IffAnt() { 190 } 191 } 192 193 194 | Popular Tags |