Skip to content

Commit 6555be6

Browse files
committed
WIP
1 parent 5f256cc commit 6555be6

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.bootstrap;
11+
12+
import org.elasticsearch.entitlement.runtime.policy.PolicyManager;
13+
14+
import java.security.CodeSource;
15+
import java.util.List;
16+
import java.util.Map;
17+
import java.util.function.Function;
18+
19+
record TestBuildInfoLocations(String className, String moduleName) { }
20+
21+
record TestBuildInfo(String componentName, List<TestBuildInfoLocations> locations) {
22+
23+
private static class TestScopeResolver {
24+
25+
private final Map<CodeSource, PolicyManager.PolicyScope> scopeMap;
26+
27+
PolicyManager.PolicyScope getScope(Class<?> callerClass) {
28+
CodeSource callerCodeSource = callerClass.getProtectionDomain().getCodeSource();
29+
return scopeMap.getOrDefault(callerCodeSource, PolicyManager.PolicyScope.unknown(null));
30+
}
31+
32+
}
33+
34+
Function<Class<?>, PolicyManager.PolicyScope> toScopeResolver() {
35+
36+
for (var location: locations) {
37+
location.className()
38+
}
39+
40+
var testScopeResolver = new TestScopeResolver();
41+
return testScopeResolver::getScope;
42+
}
43+
44+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.bootstrap;
11+
12+
import org.elasticsearch.xcontent.ObjectParser;
13+
import org.elasticsearch.xcontent.ParseField;
14+
import org.elasticsearch.xcontent.XContentParser;
15+
16+
import java.io.IOException;
17+
import java.util.List;
18+
19+
public class TestBuildInfoParser {
20+
21+
private static final String NAME_KEY = "name";
22+
private static final String LOCATIONS_KEY = "locations";
23+
24+
private static final ObjectParser<Builder, Void> PARSER = new ObjectParser<>("test_build_info", Builder::new);
25+
private static final ObjectParser<Location, Void> LOCATION_PARSER = new ObjectParser<>("location", Location::new);
26+
static {
27+
LOCATION_PARSER.declareString(Location::className, new ParseField("class"));
28+
LOCATION_PARSER.declareString(Location::moduleName, new ParseField("module"));
29+
30+
PARSER.declareString(Builder::name, new ParseField("name"));
31+
PARSER.declareObjectArray(Builder::locations, LOCATION_PARSER, new ParseField("locations"));
32+
}
33+
34+
private static class Location {
35+
private String className;
36+
private String moduleName;
37+
38+
public void moduleName(final String moduleName) {
39+
this.moduleName = moduleName;
40+
}
41+
public void className(final String className) {
42+
this.className = className;
43+
}
44+
}
45+
46+
private static final class Builder {
47+
private String name;
48+
private List<Location> locations;
49+
50+
public void name(final String name) {
51+
this.name = name;
52+
}
53+
54+
public void locations(final List<Location> locations) {
55+
this.locations = locations;
56+
}
57+
58+
TestBuildInfo build() {
59+
return new TestBuildInfo(name);
60+
}
61+
}
62+
63+
64+
public static TestBuildInfo fromXContent(final XContentParser parser) throws IOException {
65+
return PARSER.parse(parser, null).build();
66+
}
67+
}

0 commit comments

Comments
 (0)