1 /*
2 * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
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 */
51 System.err.println("Skipping test since " + imagePath + " is absent");
52 return;
53 }
54 System.out.println("Running test against image " + imagePath);
55 final String integersParentResource = "/modules/java.base/java/lang";
56 final String integerResource = integersParentResource + "/Integer.class";
57 try (final ImageReader reader = ImageReader.open(imagePath)) {
58 // find the child node/resource first
59 final ImageReader.Node integerNode = reader.findNode(integerResource);
60 if (integerNode == null) {
61 throw new RuntimeException("ImageReader could not locate " + integerResource
62 + " in " + imagePath);
63 }
64 // now find the parent node (which will represent a directory)
65 final ImageReader.Node parent = reader.findNode(integersParentResource);
66 if (parent == null) {
67 throw new RuntimeException("ImageReader could not locate " + integersParentResource
68 + " in " + imagePath);
69 }
70 // now verify that the parent node which is a directory, doesn't have duplicate children
71 final List<ImageReader.Node> children = parent.getChildren();
72 if (children == null || children.isEmpty()) {
73 throw new RuntimeException("ImageReader did not return any child resources under "
74 + integersParentResource + " in " + imagePath);
75 }
76 final Set<ImageReader.Node> uniqueChildren = new HashSet<>();
77 for (final ImageReader.Node child : children) {
78 final boolean unique = uniqueChildren.add(child);
79 if (!unique) {
80 throw new RuntimeException("ImageReader returned duplicate child resource "
81 + child + " under " + parent + " from image " + imagePath);
82 }
83 }
84 }
85 }
86 }
|
1 /*
2 * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
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 */
51 System.err.println("Skipping test since " + imagePath + " is absent");
52 return;
53 }
54 System.out.println("Running test against image " + imagePath);
55 final String integersParentResource = "/modules/java.base/java/lang";
56 final String integerResource = integersParentResource + "/Integer.class";
57 try (final ImageReader reader = ImageReader.open(imagePath)) {
58 // find the child node/resource first
59 final ImageReader.Node integerNode = reader.findNode(integerResource);
60 if (integerNode == null) {
61 throw new RuntimeException("ImageReader could not locate " + integerResource
62 + " in " + imagePath);
63 }
64 // now find the parent node (which will represent a directory)
65 final ImageReader.Node parent = reader.findNode(integersParentResource);
66 if (parent == null) {
67 throw new RuntimeException("ImageReader could not locate " + integersParentResource
68 + " in " + imagePath);
69 }
70 // now verify that the parent node which is a directory, doesn't have duplicate children
71 final List<String> childNames = parent.getChildNames().toList();
72 if (childNames.isEmpty()) {
73 throw new RuntimeException("ImageReader did not return any child resources under "
74 + integersParentResource + " in " + imagePath);
75 }
76 final Set<ImageReader.Node> uniqueChildren = new HashSet<>();
77 for (final String childName : childNames) {
78 final boolean unique = uniqueChildren.add(reader.findNode(childName));
79 if (!unique) {
80 throw new RuntimeException("ImageReader returned duplicate child resource "
81 + childName + " under " + parent + " from image " + imagePath);
82 }
83 }
84 }
85 }
86 }
|