You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MegaZipTestCase.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.bcel;
  13. import java.io.File;
  14. import java.io.IOException;
  15. import java.lang.reflect.Modifier;
  16. import java.util.ArrayList;
  17. import java.util.List;
  18. import org.aspectj.weaver.AdviceKind;
  19. import org.aspectj.weaver.Member;
  20. import org.aspectj.weaver.MemberImpl;
  21. import org.aspectj.weaver.Shadow;
  22. import org.aspectj.weaver.ShadowMunger;
  23. import org.aspectj.weaver.UnresolvedType;
  24. import org.aspectj.weaver.WeaverTestCase;
  25. public class MegaZipTestCase extends WeaveTestCase {
  26. private File outDir;
  27. public MegaZipTestCase(String arg0) {
  28. super(arg0);
  29. }
  30. public void setUp() throws Exception {
  31. super.setUp();
  32. outDir = WeaverTestCase.getOutdir();
  33. }
  34. public void tearDown() throws Exception {
  35. super.tearDown();
  36. WeaverTestCase.removeOutDir();
  37. outDir = null;
  38. }
  39. private BcelAdvice makeAroundMunger(final boolean matchOnlyPrintln) {
  40. // BcelWorld world = new BcelWorld();
  41. final Member sig = MemberImpl.method(UnresolvedType.forName("fluffy.Aspect"), Modifier.STATIC, "aroundFun",
  42. "(Lorg/aspectj/runtime/internal/AroundClosure;)Ljava/lang/Object;");
  43. return new BcelAdvice(AdviceKind.stringToKind("around"), matchOnlyPrintln ? makePointcutPrintln() : makePointcutAll(), sig,
  44. 0, -1, -1, null, null) {
  45. public void specializeOn(Shadow s) {
  46. super.specializeOn(s);
  47. ((BcelShadow) s).initializeForAroundClosure();
  48. }
  49. };
  50. }
  51. public List<ShadowMunger> getShadowMungers() {
  52. List<ShadowMunger> ret = new ArrayList<ShadowMunger>();
  53. ret.add(makeConcreteAdvice("before" + "(): call(* *.println(..)) -> static void fluffy.Aspect.before_method_call()"));
  54. ret.add(makeConcreteAdvice("afterReturning"
  55. + "(): call(* *.println(..)) -> static void fluffy.Aspect.afterReturning_method_call()"));
  56. ret.add(makeConcreteAdvice("before" + "(): execution(* *.*(..)) -> static void fluffy.Aspect.ignoreMe()"));
  57. ret.add(makeConcreteAdvice("afterReturning" + "(): execution(* *.*(..)) -> static void fluffy.Aspect.ignoreMe()"));
  58. ret.add(makeConcreteAdvice("afterThrowing"
  59. + "(): execution(* *.*(..)) -> static void fluffy.Aspect.afterThrowing_method_execution(java.lang.Throwable)", 1));
  60. ret.add(makeConcreteAdvice("after" + "(): execution(* *.*(..)) -> static void fluffy.Aspect.ignoreMe()"));
  61. ret.add(makeAroundMunger(true));
  62. return ret;
  63. }
  64. public void zipTest(String fileName) throws IOException {
  65. long startTime = System.currentTimeMillis();
  66. File inFile = new File(WeaverTestCase.TESTDATA_PATH, fileName);
  67. File outFile = new File(outDir, fileName);
  68. outFile.delete();
  69. world = new BcelWorld("c:/apps/java-1.3.1_04/lib/tools.jar");
  70. BcelWeaver weaver1 = new BcelWeaver(world);
  71. ZipFileWeaver weaver = new ZipFileWeaver(inFile);
  72. weaver1.setShadowMungers(getShadowMungers());
  73. weaver.weave(weaver1, outFile);
  74. assertTrue(outFile.lastModified() > startTime);
  75. }
  76. public void testEmptyForAntJUnit() {
  77. }
  78. // this is something we test every now and again.
  79. // to try, rename as testBig and put aspectjtools.jar in testdata
  80. public void trytestBig() throws IOException {
  81. System.out.println("could take 80 seconds...");
  82. zipTest("aspectjtools.jar");
  83. }
  84. }