1 21 package proguard.ant; 22 23 import proguard.*; 24 25 import org.apache.tools.ant.*; 26 27 import java.io.*; 28 import java.util.*; 29 30 35 public class ConfigurationTask extends Task 36 { 37 protected Configuration configuration = new Configuration(); 38 39 40 44 public void appendTo(Configuration configuration) 45 { 46 configuration.programJars = extendClassPath(configuration.programJars, 48 this.configuration.programJars); 49 50 configuration.libraryJars = extendClassPath(configuration.libraryJars, 51 this.configuration.libraryJars); 52 53 configuration.keep = extendClassSpecifications(configuration.keep, 54 this.configuration.keep); 55 56 configuration.whyAreYouKeeping = extendClassSpecifications(configuration.whyAreYouKeeping, 57 this.configuration.whyAreYouKeeping); 58 59 configuration.assumeNoSideEffects = extendClassSpecifications(configuration.assumeNoSideEffects, 60 this.configuration.assumeNoSideEffects); 61 62 configuration.keepAttributes = extendList(configuration.keepAttributes, 63 this.configuration.keepAttributes); 64 } 65 66 67 69 public void addConfiguredInjar(ClassPathElement classPathElement) 70 { 71 configuration.programJars = extendClassPath(configuration.programJars, 72 classPathElement, 73 false); 74 } 75 76 77 public void addConfiguredOutjar(ClassPathElement classPathElement) 78 { 79 configuration.programJars = extendClassPath(configuration.programJars, 80 classPathElement, 81 true); 82 } 83 84 85 public void addConfiguredLibraryjar(ClassPathElement classPathElement) 86 { 87 configuration.libraryJars = extendClassPath(configuration.libraryJars, 88 classPathElement, 89 false); 90 } 91 92 93 public void addConfiguredKeep(KeepSpecificationElement keepSpecificationElement) 94 { 95 configuration.keep = extendKeepSpecifications(configuration.keep, 96 keepSpecificationElement, 97 true, 98 false); 99 } 100 101 102 public void addConfiguredKeepclassmembers(KeepSpecificationElement keepSpecificationElement) 103 { 104 configuration.keep = extendKeepSpecifications(configuration.keep, 105 keepSpecificationElement, 106 false, 107 false); 108 } 109 110 111 public void addConfiguredKeepclasseswithmembers(KeepSpecificationElement keepSpecificationElement) 112 { 113 configuration.keep = extendKeepSpecifications(configuration.keep, 114 keepSpecificationElement, 115 true, 116 true); 117 } 118 119 120 public void addConfiguredKeepnames(KeepSpecificationElement keepSpecificationElement) 121 { 122 keepSpecificationElement.setAllowshrinking(true); 124 125 configuration.keep = extendKeepSpecifications(configuration.keep, 126 keepSpecificationElement, 127 true, 128 false); 129 } 130 131 132 public void addConfiguredKeepclassmembernames(KeepSpecificationElement keepSpecificationElement) 133 { 134 keepSpecificationElement.setAllowshrinking(true); 136 137 configuration.keep = extendKeepSpecifications(configuration.keep, 138 keepSpecificationElement, 139 false, 140 false); 141 } 142 143 144 public void addConfiguredKeepclasseswithmembernames(KeepSpecificationElement keepSpecificationElement) 145 { 146 keepSpecificationElement.setAllowshrinking(true); 148 149 configuration.keep = extendKeepSpecifications(configuration.keep, 150 keepSpecificationElement, 151 true, 152 true); 153 } 154 155 156 public void addConfiguredWhyareyoukeeping(ClassSpecificationElement classSpecificationElement) 157 { 158 configuration.whyAreYouKeeping = extendClassSpecifications(configuration.whyAreYouKeeping, 159 classSpecificationElement); 160 } 161 162 163 public void addConfiguredAssumenosideeffects(ClassSpecificationElement classSpecificationElement) 164 { 165 configuration.assumeNoSideEffects = extendClassSpecifications(configuration.assumeNoSideEffects, 166 classSpecificationElement); 167 } 168 169 170 public void addConfiguredKeepattribute(KeepAttributeElement keepAttributeElement) 171 { 172 configuration.keepAttributes = extendAttributes(configuration.keepAttributes, 173 keepAttributeElement); 174 } 175 176 177 public void addConfiguredAdaptResourceFileNames(FilterElement filterElement) 178 { 179 configuration.adaptResourceFileNames = extendFilter(configuration.adaptResourceFileNames, 180 filterElement); 181 } 182 183 184 public void addConfiguredAdaptResourceFileContents(FilterElement filterElement) 185 { 186 configuration.adaptResourceFileContents = extendFilter(configuration.adaptResourceFileContents, 187 filterElement); 188 } 189 190 191 public void addConfiguredConfiguration(ConfigurationElement configurationElement) 192 { 193 configurationElement.appendTo(configuration); 194 } 195 196 197 199 public void addText(String text) throws BuildException 200 { 201 try 202 { 203 String arg = getProject().replaceProperties(text); 204 205 ConfigurationParser parser = new ConfigurationParser(new String [] { arg }, 206 getProject().getBaseDir()); 207 208 try 209 { 210 parser.parse(configuration); 211 } 212 catch (ParseException ex) 213 { 214 throw new BuildException(ex.getMessage()); 215 } 216 finally 217 { 218 parser.close(); 219 } 220 } 221 catch (IOException ex) 222 { 223 throw new BuildException(ex.getMessage()); 224 } 225 } 226 227 228 230 private ClassPath extendClassPath(ClassPath classPath, 231 ClassPathElement classPathElement, 232 boolean output) 233 { 234 if (classPath == null) 235 { 236 classPath = new ClassPath(); 237 } 238 239 classPathElement.appendClassPathEntriesTo(classPath, 240 output); 241 242 return classPath; 243 } 244 245 246 private ClassPath extendClassPath(ClassPath classPath, 247 ClassPath additionalClassPath) 248 { 249 if (additionalClassPath != null) 250 { 251 if (classPath == null) 252 { 253 classPath = new ClassPath(); 254 } 255 256 classPath.addAll(additionalClassPath); 257 } 258 259 return classPath; 260 } 261 262 263 private List extendKeepSpecifications(List keepSpecifications, 264 KeepSpecificationElement keepSpecificationElement, 265 boolean markClasses, 266 boolean markClassesConditionally) 267 { 268 if (keepSpecifications == null) 269 { 270 keepSpecifications = new ArrayList(); 271 } 272 273 keepSpecificationElement.appendTo(keepSpecifications, 274 markClasses, 275 markClassesConditionally); 276 277 return keepSpecifications; 278 } 279 280 281 private List extendClassSpecifications(List classSpecifications, 282 ClassSpecificationElement classSpecificationElement) 283 { 284 if (classSpecifications == null) 285 { 286 classSpecifications = new ArrayList(); 287 } 288 289 classSpecificationElement.appendTo(classSpecifications); 290 291 return classSpecifications; 292 } 293 294 295 private List extendClassSpecifications(List classSpecifications, 296 List additionalClassSpecifications) 297 { 298 if (additionalClassSpecifications != null) 299 { 300 if (classSpecifications == null) 301 { 302 classSpecifications = new ArrayList(); 303 } 304 305 classSpecifications.addAll(additionalClassSpecifications); 306 } 307 308 return classSpecifications; 309 } 310 311 312 private List extendAttributes(List attributes, 313 KeepAttributeElement keepAttributeElement) 314 { 315 if (attributes == null) 316 { 317 attributes = new ArrayList(); 318 } 319 320 keepAttributeElement.appendTo(attributes); 321 322 return attributes; 323 } 324 325 326 private List extendFilter(List filter, 327 FilterElement filterElement) 328 { 329 if (filter == null) 330 { 331 filter = new ArrayList(); 332 } 333 334 filterElement.appendTo(filter); 335 336 return filter; 337 } 338 339 340 private List extendList(List list, 341 List additionalList) 342 { 343 if (additionalList != null) 344 { 345 if (list == null) 346 { 347 list = new ArrayList(); 348 } 349 350 list.addAll(additionalList); 351 } 352 353 return list; 354 } 355 } 356 | Popular Tags |