1616import org .elasticsearch .core .Booleans ;
1717import org .elasticsearch .core .PathUtils ;
1818import org .elasticsearch .jdk .JarHell ;
19+ import org .elasticsearch .xcontent .ConstructingObjectParser ;
20+ import org .elasticsearch .xcontent .ParseField ;
21+ import org .elasticsearch .xcontent .XContentParser ;
22+ import org .elasticsearch .xcontent .XContentParserConfiguration ;
23+ import org .elasticsearch .xcontent .json .JsonXContent ;
1924
25+ import java .io .BufferedReader ;
2026import java .io .IOException ;
27+ import java .io .InputStream ;
28+ import java .io .UncheckedIOException ;
29+ import java .net .URL ;
2130import java .nio .file .Files ;
2231import java .nio .file .Path ;
32+ import java .util .Enumeration ;
33+ import java .util .List ;
2334import java .util .Objects ;
2435
2536/**
@@ -35,7 +46,18 @@ public class BootstrapForTesting {
3546 // TODO: can we share more code with the non-test side here
3647 // without making things complex???
3748
49+ private static final ConstructingObjectParser <TestBuildInfoLocation , Void > TEST_BUILD_INFO_LOCATION_PARSER =
50+ new ConstructingObjectParser <>("test_build_info_location" , values -> new TestBuildInfoLocation ((String )values [0 ], (String )values [1 ]));
51+ @ SuppressWarnings ("unchecked" )
52+ private static final ConstructingObjectParser <TestBuildInfo , Void > TEST_BUILD_INFO_PARSER =
53+ new ConstructingObjectParser <>("test_build_info" , values -> new TestBuildInfo ((String )values [0 ], (List <TestBuildInfoLocation >)values [1 ]));
54+
3855 static {
56+ TEST_BUILD_INFO_LOCATION_PARSER .declareString (ConstructingObjectParser .constructorArg (), new ParseField ("module" ));
57+ TEST_BUILD_INFO_LOCATION_PARSER .declareString (ConstructingObjectParser .constructorArg (), new ParseField ("representative_class" ));
58+
59+ TEST_BUILD_INFO_PARSER .declareString (ConstructingObjectParser .constructorArg (), new ParseField ("component" ));
60+ TEST_BUILD_INFO_PARSER .declareObjectArray (ConstructingObjectParser .constructorArg (), TEST_BUILD_INFO_LOCATION_PARSER ::apply , new ParseField ("locations" ));
3961
4062 // make sure java.io.tmpdir exists always (in case code uses it in a static initializer)
4163 Path javaTmpDir = PathUtils .get (
@@ -71,6 +93,24 @@ public class BootstrapForTesting {
7193
7294 // Log ifconfig output before SecurityManager is installed
7395 IfConfig .logIfNecessary ();
96+
97+ try {
98+ Enumeration <URL > urls = BootstrapForTesting .class .getClassLoader ().getResources ("META-INF/plugin-test-build-info.json" );
99+ System .out .println ("HERE0: " + urls .hasMoreElements ());
100+ while (urls .hasMoreElements ()) {
101+ try (XContentParser parser = JsonXContent .jsonXContent .createParser (XContentParserConfiguration .EMPTY , urls .nextElement ().openStream ())) {
102+ TestBuildInfo testBuildInfo = TEST_BUILD_INFO_PARSER .parse (parser , null );
103+ System .out .println ("HERE1: " + testBuildInfo );
104+ }
105+ }
106+ System .out .println (
107+ "HERE2: " + BootstrapForTesting .class .getClassLoader ().getResource ("META-INF/plugin-test-build-info.json" ));
108+ System .out .println (
109+ "HERE3: " + BootstrapForTesting .class .getResource ("/META-INF/plugin-test-build-info.json" ));
110+ System .out .println ("HERE4: " + BootstrapForTesting .class .getProtectionDomain ().getCodeSource ().getLocation ());
111+ } catch (IOException ioe ) {
112+ throw new UncheckedIOException (ioe );
113+ }
74114 }
75115
76116 // does nothing, just easy way to make sure the class is loaded.
0 commit comments