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

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