Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

tools-intro.adoc 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. [[tools-intro]]
  2. == Introduction to the AspectJ tools
  3. [[eclipse-aspectj]]
  4. === The Eclipse AspectJ implementation
  5. The xref:../progguide/index.html[AspectJ Programming Guide] describes
  6. the AspectJ language. This guide describes the AspectJ tools produced by
  7. the AspectJ team on https://eclipse.org/aspectj. The AspectJ tools
  8. include - ajc, the compiler/weaver; ajdoc, a documentation tool;
  9. Ant support for ajc; and load-time weaving support.
  10. These tools are delivered in the library
  11. folder of the AspectJ tools installation, mainly in `aspectjtools.jar`
  12. (tools) and `aspectjrt.jar` (runtime). This guide does not describe the
  13. Eclipse AspectJ development tools (AJDT). That is produced by another
  14. team (sharing some members) on
  15. https://eclipse.org/aspectj[https://eclipse.org/ajdt]. AJDT is delivered
  16. as an Eclipse plugin, incorporating the classes in the AspectJ tools
  17. libraries along with the Eclipse plugin interface classes.
  18. Since AspectJ 1.1, the tools have implemented the AspectJ language using
  19. bytecode weaving, which combines aspects and classes to produce .class
  20. files that run in a Java VM. There are other ways to implement the
  21. language (e.g., compiler preprocessor, VM support); the AspectJ team has
  22. always tried to distinguish the language and the implementation so other
  23. groups could build alternative implementations of AspectJ. To that end,
  24. xref:../progguide/implementation.html[The AspectJ Programming Guide,
  25. Implementation Notes] describes how the Java bytecode form affects
  26. language semantics. VM- or source-based implementations may be free of
  27. these limits or impose limits of their own, but most should be fairly
  28. close to what's possible in Java bytecode.
  29. Please be careful not to confuse any description of weaving or of this
  30. implementation of the AspectJ language with the AspectJ language
  31. semantics. If you do, you might find yourself writing code that doesn't
  32. work as expected when you compile or run it on other systems. More
  33. importantly, if you think about aspects in terms of weaving or of
  34. inserting or merging code, then you can lose many of the design benefits
  35. of thinking about an aspect as a single crosscutting module. When the
  36. text below introduces an implementation detail, it will warn if users
  37. make mistakes by applying it in lieu of the language semantics.
  38. [[bytecode-concepts]]
  39. === Bytecode weaving, incremental compilation, and memory usage
  40. Bytecode weaving takes classes and aspects in .class form and weaves
  41. them together to produce binary-compatible .class files that run in any
  42. Java VM and implement the AspectJ semantics. This process supports not
  43. only the compiler but also IDE's. The compiler, given an aspect in
  44. source form, produces a binary aspect and runs the weaver. IDE's can get
  45. information about crosscutting in the program by subscribing to
  46. information produced by weaver as a side-effect of weaving.
  47. Incremental compilation involves recompiling only what is necessary to
  48. bring the binary form of a program up-to-date with the source form in
  49. the shortest time possible. Incremental weaving supports this by weaving
  50. on a per-class basis. (Some implementations of AOP (including AspectJ
  51. 1.0) make use of whole-program analysis that can't be done in
  52. incremental mode.) Weaving per-class means that if the source for a pure
  53. Java class is updated, only that class needs to be produced. However, if
  54. some crosscutting specification may have been updated, then all code
  55. potentially affected by it may need to be woven. The AspectJ tools are
  56. getting better at minimizing this effect, but it is to some degree
  57. unavoidable due to the crosscutting semantics.
  58. Memory usage can seem higher with AspectJ tools. Some aspects are
  59. written to potentially affect many classes, so each class must be
  60. checked during the process of weaving. Programmers can minimize this by
  61. writing the crosscutting specifications as narrowly as possible while
  62. maintaining correctness. (While it may seem like more memory, the proper
  63. comparison would with with a Java program that had the same
  64. crosscutting, with changes made to each code segment. That would likely
  65. require more memory and more time to recompile than the corresponding
  66. AspectJ program.)
  67. [[classpathInpathAndAspectpath]]
  68. ==== Classpath, inpath, and aspectpath
  69. AspectJ introduces two new paths for the binary input to the weaver
  70. which you'll find referenced in xref:ajc.adoc[`ajc`, the AspectJ compiler/weaver],
  71. xref:antsupport.adoc[AspectJ Ant Tasks], and xref:ltw.adoc#ltw[Load-Time Weaving].
  72. As in Java, the `classpath` is where the AspectJ tools resolve types
  73. specified in the program. When running an AspectJ program, the classpath
  74. should contain the classes and aspects along with the AspectJ runtime
  75. library, `aspectjrt.jar`.
  76. In AspectJ tools, the `aspectpath` is where to find binary aspects. Like
  77. the classpath, it can include archives (.jar and .zip files) and
  78. directories containing .class files in a package layout (since binary
  79. aspects are in .class files). These aspects affect other classes in
  80. exactly the same way as source-level aspects, but are themselves not
  81. affected. When deploying programs, the original aspects must be included
  82. on the runtime classpath.
  83. In AspectJ tools, the `inpath` is where to find binary input - aspects
  84. and classes that weave and may be woven. Like the classpath, it can
  85. include archives and class directories. Like the aspectpath, it can
  86. include aspects that affect other classes and aspects. However, unlike
  87. the aspectpath, an aspect on the inpath may itself be affected by
  88. aspects, as if the source were all compiled together. When deploying
  89. aspects that were put on the inpath, only the woven output should be on
  90. the runtime classpath.
  91. Although types in the inpath and the aspectpath need to be resolved by
  92. the AspectJ tools, you usually do not need to place them on the
  93. classpath because this is done automatically by the compiler/weaver. But
  94. when using the `WeavingURLClassLoader`, your code must explicitly add
  95. the aspects to the classpath so they can be resolved (as you'll see in
  96. the sample code and the `aj.bat` script).
  97. The most common mistake is failing to add `aspectjrt.jar` to the
  98. classpath. Also, when weaving with binary aspects, users forget to
  99. deploy the aspect itself along with any classes it requires. A more
  100. subtle mistake is putting a binary aspect (BA) on the inpath instead of
  101. the aspectpath. In this case the aspect BA might be affected by an
  102. aspect, even itself; this can cause the program to fail, e.g., when an
  103. aspect uses exclusion to avoid infinite recursion but fails to exclude
  104. advice in aspect BA.
  105. The latter is one of many ways that mistakes in the build process can
  106. affect aspects that are written poorly. Aspects should never rely on the
  107. boundaries of the build specification to narrow the scope of their
  108. crosscutting, since the build can be changed without notice to the
  109. aspect developer. Careful users might even avoid relying on the
  110. implementation scope, to ensure their AspectJ code will run on other
  111. implementations.