|
34 | 34 | import java.nio.charset.StandardCharsets; |
35 | 35 | import java.nio.file.Files; |
36 | 36 | import java.nio.file.Path; |
| 37 | +import java.security.CodeSource; |
37 | 38 | import java.util.ArrayList; |
38 | 39 | import java.util.Arrays; |
39 | 40 | import java.util.List; |
@@ -84,11 +85,25 @@ public void generatePropertiesFile() throws IOException { |
84 | 85 | } |
85 | 86 |
|
86 | 87 | /** |
87 | | - * The output of this task is a JSON file formatted according to this record |
| 88 | + * The output of this task is a JSON file formatted according to this record. |
| 89 | + * @param component the entitlements <em>component</em> name of the artifact we're describing |
| 90 | + * @param locations a {@link Location} for each code directory/jar in this artifact |
88 | 91 | */ |
89 | 92 | record OutputFileContents(String component, List<Location> locations) {} |
90 | 93 |
|
91 | | - record Location(String representativeClass, String module) {} |
| 94 | + /** |
| 95 | + * Our analog of a single {@link CodeSource#getLocation()}. |
| 96 | + * All classes in any single <em>location</em> (a directory or jar) |
| 97 | + * are considered to be part of the same Java module for entitlements purposes. |
| 98 | + * Since tests run without Java modules, and entitlements are all predicated on modules, |
| 99 | + * this info lets us determine what the module <em>would have been</em> |
| 100 | + * so we can look up the appropriate entitlements. |
| 101 | + * |
| 102 | + * @param module the name of the Java module corresponding to this {@code Location}. |
| 103 | + * @param representativeClass an example of any <code>.class</code> file within this {@code Location} |
| 104 | + * whose name will be unique within its {@link ClassLoader} at run time. |
| 105 | + */ |
| 106 | + record Location(String module, String representativeClass) {} |
92 | 107 |
|
93 | 108 | /** |
94 | 109 | * Build the list of {@link Location}s for all {@link #getCodeLocations() code locations}. |
@@ -120,7 +135,7 @@ private void extractLocationsFromJar(File file, List<Location> locations) throws |
120 | 135 |
|
121 | 136 | if (className.isPresent()) { |
122 | 137 | String moduleName = extractModuleNameFromJar(file, jarFile); |
123 | | - locations.add(new Location(className.get(), moduleName)); |
| 138 | + locations.add(new Location(moduleName, className.get())); |
124 | 139 | } |
125 | 140 | } |
126 | 141 | } |
@@ -166,7 +181,7 @@ private String extractModuleNameFromJar(File file, JarFile jarFile) throws IOExc |
166 | 181 | versions = new ArrayList<>(versions); |
167 | 182 | versions.sort(Integer::compareTo); |
168 | 183 | versions = versions.reversed(); |
169 | | - int major = Runtime.version().version().get(0); |
| 184 | + int major = Runtime.version().feature(); |
170 | 185 | StringBuilder path = new StringBuilder("META-INF/versions/"); |
171 | 186 | for (int version : versions) { |
172 | 187 | if (version <= major) { |
@@ -234,7 +249,7 @@ private void extractLocationsFromDirectory(File dir, List<Location> locations) t |
234 | 249 | String moduleName = extractModuleNameFromDirectory(dir); |
235 | 250 |
|
236 | 251 | if (className != null && moduleName != null) { |
237 | | - locations.add(new Location(className, moduleName)); |
| 252 | + locations.add(new Location(moduleName, className)); |
238 | 253 | } |
239 | 254 | } |
240 | 255 |
|
|
0 commit comments