11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.lang.annotation.Annotation;
27 import java.lang.module.Configuration;
28 import java.lang.module.ModuleFinder;
29 import java.nio.file.Files;
30 import java.nio.file.Path;
31
32 import java.util.ArrayList;
33 import java.util.List;
34 import java.util.Set;
35
36 import jdk.internal.module.ClassFileAttributes;
37 import jdk.internal.org.objectweb.asm.AnnotationVisitor;
38 import jdk.internal.org.objectweb.asm.Attribute;
39 import jdk.internal.org.objectweb.asm.ClassReader;
40 import jdk.internal.org.objectweb.asm.ClassVisitor;
41 import jdk.internal.org.objectweb.asm.ClassWriter;
42 import jdk.internal.org.objectweb.asm.Opcodes;
43
44 import org.testng.annotations.Test;
45 import static org.testng.Assert.*;
46
47 /**
48 * @test
49 * @modules java.base/jdk.internal.org.objectweb.asm
50 * java.base/jdk.internal.module
57
58 /**
59 * Test that there are no annotations on an unnamed module.
60 */
61 @Test
62 public void testUnnamedModule() {
63 Module module = this.getClass().getModule();
64 assertTrue(module.getAnnotations().length == 0);
65 assertTrue(module.getDeclaredAnnotations().length == 0);
66 }
67
68 /**
69 * Test loading a module with a RuntimeVisibleAnnotation attribute.
70 * The test copies the module-info.class for java.xml, adds the attribute,
71 * and then loads the updated module.
72 */
73 @Test
74 public void testNamedModule() throws IOException {
75
76 // "deprecate" java.xml
77 Path dir = Files.createTempDirectory("mods");
78 deprecateModule("java.xml", true, "9", dir);
79
80 // "load" the cloned java.xml
81 Module module = loadModule(dir, "java.xml");
82
83 // check the annotation is present
84 assertTrue(module.isAnnotationPresent(Deprecated.class));
85 Deprecated d = module.getAnnotation(Deprecated.class);
86 assertNotNull(d, "@Deprecated not found");
87 assertTrue(d.forRemoval());
88 assertEquals(d.since(), "9");
89 Annotation[] a = module.getAnnotations();
90 assertTrue(a.length == 1);
91 assertTrue(a[0] instanceof Deprecated);
92 assertEquals(module.getDeclaredAnnotations(), a);
93 }
94
95
96 /**
97 * Copy the module-info.class for the given module, add the
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.lang.annotation.Annotation;
27 import java.lang.module.Configuration;
28 import java.lang.module.ModuleFinder;
29 import java.nio.file.Files;
30 import java.nio.file.Path;
31 import java.nio.file.Paths;
32
33 import java.util.ArrayList;
34 import java.util.List;
35 import java.util.Set;
36
37 import jdk.internal.module.ClassFileAttributes;
38 import jdk.internal.org.objectweb.asm.AnnotationVisitor;
39 import jdk.internal.org.objectweb.asm.Attribute;
40 import jdk.internal.org.objectweb.asm.ClassReader;
41 import jdk.internal.org.objectweb.asm.ClassVisitor;
42 import jdk.internal.org.objectweb.asm.ClassWriter;
43 import jdk.internal.org.objectweb.asm.Opcodes;
44
45 import org.testng.annotations.Test;
46 import static org.testng.Assert.*;
47
48 /**
49 * @test
50 * @modules java.base/jdk.internal.org.objectweb.asm
51 * java.base/jdk.internal.module
58
59 /**
60 * Test that there are no annotations on an unnamed module.
61 */
62 @Test
63 public void testUnnamedModule() {
64 Module module = this.getClass().getModule();
65 assertTrue(module.getAnnotations().length == 0);
66 assertTrue(module.getDeclaredAnnotations().length == 0);
67 }
68
69 /**
70 * Test loading a module with a RuntimeVisibleAnnotation attribute.
71 * The test copies the module-info.class for java.xml, adds the attribute,
72 * and then loads the updated module.
73 */
74 @Test
75 public void testNamedModule() throws IOException {
76
77 // "deprecate" java.xml
78 Path dir = Files.createTempDirectory(Paths.get(""), "mods");
79 deprecateModule("java.xml", true, "9", dir);
80
81 // "load" the cloned java.xml
82 Module module = loadModule(dir, "java.xml");
83
84 // check the annotation is present
85 assertTrue(module.isAnnotationPresent(Deprecated.class));
86 Deprecated d = module.getAnnotation(Deprecated.class);
87 assertNotNull(d, "@Deprecated not found");
88 assertTrue(d.forRemoval());
89 assertEquals(d.since(), "9");
90 Annotation[] a = module.getAnnotations();
91 assertTrue(a.length == 1);
92 assertTrue(a[0] instanceof Deprecated);
93 assertEquals(module.getDeclaredAnnotations(), a);
94 }
95
96
97 /**
98 * Copy the module-info.class for the given module, add the
|