Skip to content

Commit 8a40526

Browse files
committed
updated to reflect changes to elastic#127486
1 parent 78d8737 commit 8a40526

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

test/framework/src/main/java/org/elasticsearch/bootstrap/TestBuildInfoParser.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626
class TestBuildInfoParser {
2727

28-
private static final String NAME_KEY = "name";
29-
private static final String LOCATIONS_KEY = "locations";
28+
private static final String PLUGIN_TEST_BUILD_INFO_RESOURCES = "META-INF/plugin-test-build-info.json";
29+
private static final String SERVER_TEST_BUILD_INFO_RESOURCE = "META-INF/server-test-build-info.json";
3030

3131
private static final ObjectParser<Builder, Void> PARSER = new ObjectParser<>("test_build_info", Builder::new);
3232
private static final ObjectParser<Location, Void> LOCATION_PARSER = new ObjectParser<>("location", Location::new);
@@ -72,12 +72,10 @@ static TestBuildInfo fromXContent(final XContentParser parser) throws IOExceptio
7272
return PARSER.parse(parser, null).build();
7373
}
7474

75-
// TODO: possibly move it to whoever is calling/using this
76-
// TODO: server test build info
7775
static List<TestBuildInfo> parseAllPluginTestBuildInfo() throws IOException {
7876
var xContent = XContentFactory.xContent(XContentType.JSON);
7977
List<TestBuildInfo> pluginsTestBuildInfos = new ArrayList<>();
80-
var resources = TestBuildInfoParser.class.getClassLoader().getResources("/META-INF/es-plugins/");
78+
var resources = TestBuildInfoParser.class.getClassLoader().getResources(PLUGIN_TEST_BUILD_INFO_RESOURCES);
8179
URL resource;
8280
while ((resource = resources.nextElement()) != null) {
8381
try (var stream = getStream(resource); var parser = xContent.createParser(XContentParserConfiguration.EMPTY, stream)) {
@@ -87,6 +85,18 @@ static List<TestBuildInfo> parseAllPluginTestBuildInfo() throws IOException {
8785
return pluginsTestBuildInfos;
8886
}
8987

88+
static TestBuildInfo parseServerTestBuildInfo() throws IOException {
89+
var xContent = XContentFactory.xContent(XContentType.JSON);
90+
var resource = TestBuildInfoParser.class.getClassLoader().getResource(SERVER_TEST_BUILD_INFO_RESOURCE);
91+
// No test-build-info for server: this might be a non-gradle build. Proceed without TestBuildInfo
92+
if (resource == null) {
93+
return null;
94+
}
95+
try (var stream = getStream(resource); var parser = xContent.createParser(XContentParserConfiguration.EMPTY, stream)) {
96+
return fromXContent(parser);
97+
}
98+
}
99+
90100
@SuppressForbidden(reason = "URLs from class loader")
91101
private static InputStream getStream(URL resource) throws IOException {
92102
return resource.openStream();

test/framework/src/main/java/org/elasticsearch/bootstrap/TestScopeResolver.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
import org.elasticsearch.core.SuppressForbidden;
1313
import org.elasticsearch.entitlement.runtime.policy.PolicyManager;
14+
import org.elasticsearch.logging.LogManager;
15+
import org.elasticsearch.logging.Logger;
1416

1517
import java.net.MalformedURLException;
1618
import java.net.URL;
@@ -20,9 +22,20 @@
2022
import java.util.function.Function;
2123

2224
record TestScopeResolver(Map<String, PolicyManager.PolicyScope> scopeMap) {
25+
26+
private static final Logger logger = LogManager.getLogger(TestScopeResolver.class);
27+
2328
PolicyManager.PolicyScope getScope(Class<?> callerClass) {
24-
var callerCodeSource = callerClass.getProtectionDomain().getCodeSource().getLocation().toString();
25-
return scopeMap.getOrDefault(callerCodeSource, PolicyManager.PolicyScope.unknown(callerCodeSource));
29+
var callerCodeSource = callerClass.getProtectionDomain().getCodeSource();
30+
assert callerCodeSource != null;
31+
32+
var location = callerCodeSource.getLocation().toString();
33+
var scope = scopeMap.get(location);
34+
if (scope == null) {
35+
logger.warn("Cannot identify a scope for class [{}], location [{}]", callerClass.getName(), location);
36+
return PolicyManager.PolicyScope.unknown(location);
37+
}
38+
return scope;
2639
}
2740

2841
static Function<Class<?>, PolicyManager.PolicyScope> createScopeResolver(

0 commit comments

Comments
 (0)