Skip to content

Commit 854df10

Browse files
committed
Tweaks
1 parent dd56d50 commit 854df10

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

build-tools/src/main/java/org/elasticsearch/gradle/plugin/GenerateTestBuildInfoTask.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.nio.charset.StandardCharsets;
3535
import java.nio.file.Files;
3636
import java.nio.file.Path;
37+
import java.security.CodeSource;
3738
import java.util.ArrayList;
3839
import java.util.Arrays;
3940
import java.util.List;
@@ -84,11 +85,25 @@ public void generatePropertiesFile() throws IOException {
8485
}
8586

8687
/**
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
8891
*/
8992
record OutputFileContents(String component, List<Location> locations) {}
9093

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) {}
92107

93108
/**
94109
* 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
120135

121136
if (className.isPresent()) {
122137
String moduleName = extractModuleNameFromJar(file, jarFile);
123-
locations.add(new Location(className.get(), moduleName));
138+
locations.add(new Location(moduleName, className.get()));
124139
}
125140
}
126141
}
@@ -166,7 +181,7 @@ private String extractModuleNameFromJar(File file, JarFile jarFile) throws IOExc
166181
versions = new ArrayList<>(versions);
167182
versions.sort(Integer::compareTo);
168183
versions = versions.reversed();
169-
int major = Runtime.version().version().get(0);
184+
int major = Runtime.version().feature();
170185
StringBuilder path = new StringBuilder("META-INF/versions/");
171186
for (int version : versions) {
172187
if (version <= major) {
@@ -234,7 +249,7 @@ private void extractLocationsFromDirectory(File dir, List<Location> locations) t
234249
String moduleName = extractModuleNameFromDirectory(dir);
235250

236251
if (className != null && moduleName != null) {
237-
locations.add(new Location(className, moduleName));
252+
locations.add(new Location(moduleName, className));
238253
}
239254
}
240255

0 commit comments

Comments
 (0)