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.

ModuleTests.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*******************************************************************************
  2. * Copyright (c) 2017 Contributors
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v 2.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  7. *******************************************************************************/
  8. package org.aspectj.systemtest.ajc190;
  9. import junit.framework.Test;
  10. import org.aspectj.apache.bcel.classfile.Attribute;
  11. import org.aspectj.apache.bcel.classfile.Code;
  12. import org.aspectj.apache.bcel.classfile.JavaClass;
  13. import org.aspectj.apache.bcel.classfile.Method;
  14. import org.aspectj.testing.JavaVersionSpecificXMLBasedAjcTestCase;
  15. import org.aspectj.testing.XMLBasedAjcTestCase;
  16. import org.aspectj.util.LangUtil;
  17. /**
  18. * Building and weaving with modules in the picture.
  19. *
  20. * Module options from https://openjdk.java.net/jeps/261
  21. *
  22. * @author Andy Clement
  23. *
  24. */
  25. public class ModuleTests extends JavaVersionSpecificXMLBasedAjcTestCase {
  26. public ModuleTests() {
  27. super(9);
  28. }
  29. public void testBuildAModule() {
  30. runTest("build a module");
  31. }
  32. public void testRunModuleClassPath() {
  33. runTest("run a module - classpath");
  34. }
  35. public void testRunModuleModulePath() {
  36. runTest("run a module - modulepath");
  37. }
  38. public void testPackageAndRunModuleFromModulePath() {
  39. runTest("package and run a module - modulepath");
  40. }
  41. public void testBuildModuleIncludingAspects() {
  42. runTest("compile module including aspects");
  43. }
  44. public void testBuildModuleAndApplyAspectsFromAspectPath() {
  45. runTest("compile module and apply aspects via aspectpath");
  46. }
  47. public void testBinaryWeavingAModuleJar() {
  48. // Pass a module on inpath, does it weave ok with a source aspect, does it run afterwards?
  49. runTest("binary weaving module");
  50. }
  51. public void testModulepathClasspathResolution1() {
  52. runTest("module path vs classpath 1");
  53. }
  54. // public void testModulepathClasspathResolution2() {
  55. // runTest("module path vs classpath 2");
  56. // }
  57. // --add-modules
  58. // This tests that when using --add-modules with one of the JDK modules (in the jmods subfolder of the JDK)
  59. // that it can be found without needing to set --module-path (this seems to be implicitly included by javac too)
  60. public void testAddModules1() {
  61. if (LangUtil.isVMGreaterOrEqual(11)) {
  62. // java.xml.bind is gone in Java11
  63. return;
  64. }
  65. runTest("compile use of java.xml.bind");
  66. }
  67. // This tests that we can use add-modules to pull in something from the JDK jmods package and that
  68. // when subsequently weaving we can see types from those modules
  69. public void testWovenAfterAddModules() {
  70. if (LangUtil.isVMGreaterOrEqual(11)) {
  71. // java.xml.bind is gone in Java11
  72. return;
  73. }
  74. runTest("weave use of java.xml.bind");
  75. }
  76. // --limit-modules
  77. public void testLimitModules1() {
  78. if (LangUtil.isVMGreaterOrEqual(11)) {
  79. // java.xml.bind is gone in Java11
  80. return;
  81. }
  82. runTest("limit modules 1");
  83. }
  84. // --add-reads
  85. public void testAddReads1() {
  86. if (LangUtil.isVMGreaterOrEqual(11)) {
  87. // java.xml.bind is gone in Java11
  88. return;
  89. }
  90. runTest("add reads 1");
  91. }
  92. // ---
  93. /* For the specified class, check that each method has a stackmap attribute */
  94. private void checkStackMapExistence(String classname, String toIgnore) throws ClassNotFoundException {
  95. toIgnore = "_" + (toIgnore == null ? "" : toIgnore) + "_";
  96. JavaClass jc = getClassFrom(ajc.getSandboxDirectory(), classname);
  97. Method[] methods = jc.getMethods();
  98. for (Method method : methods) {
  99. if (toIgnore.contains("_" + method.getName() + "_")) {
  100. continue;
  101. }
  102. boolean hasStackMapAttribute = findAttribute(method.getAttributes(), "StackMapTable");
  103. if (!hasStackMapAttribute) {
  104. fail("Could not find StackMap attribute for method " + method.getName());
  105. }
  106. }
  107. }
  108. private boolean findAttribute(Attribute[] attrs, String attributeName) {
  109. if (attrs == null) {
  110. return false;
  111. }
  112. for (Attribute attribute : attrs) {
  113. if (attribute.getName().equals(attributeName)) {
  114. return true;
  115. }
  116. // System.out.println(attribute.getName());
  117. if (attribute.getName().equals("Code")) {
  118. Code c = (Code) attribute;
  119. Attribute[] codeAttributes = c.getAttributes();
  120. for (Attribute codeAttribute : codeAttributes) {
  121. if (codeAttribute.getName().equals(attributeName)) {
  122. return true;
  123. // System.out.println(codeAttribute.getName());
  124. }
  125. }
  126. }
  127. }
  128. return false;
  129. }
  130. // Check the stackmap stuff is removed when a method gets woven (for now...)
  131. // public void testStackMapAttributesDeletedInWovenCode() {
  132. // fail("Not implemented");
  133. // }
  134. // ///////////////////////////////////////
  135. public static Test suite() {
  136. return XMLBasedAjcTestCase.loadSuite(ModuleTests.class);
  137. }
  138. @Override
  139. protected java.net.URL getSpecFile() {
  140. return getClassResource("ajc190.xml");
  141. }
  142. }