|
21 | 21 |
|
22 | 22 | // Copied verbatim from https://github.com/elastic/jvm-languages-sniffer
|
23 | 23 |
|
| 24 | +import javax.annotation.Nullable; |
24 | 25 | import java.lang.reflect.Field;
|
25 | 26 | import java.lang.reflect.Method;
|
| 27 | +import java.util.Properties; |
26 | 28 |
|
27 | 29 | public class LanguageRuntimeVersions {
|
28 | 30 |
|
@@ -59,6 +61,11 @@ public static String getRuntimeMetadata() {
|
59 | 61 | s.append(",jrb=").append(version);
|
60 | 62 | }
|
61 | 63 |
|
| 64 | + version = springDataVersion(); |
| 65 | + if (version != null) { |
| 66 | + s.append(",sd-es=").append(version); |
| 67 | + } |
| 68 | + |
62 | 69 | return s.toString();
|
63 | 70 | }
|
64 | 71 |
|
@@ -89,6 +96,18 @@ public static String jRubyVersion() {
|
89 | 96 | return keepMajorMinor(getStaticField("org.jruby.runtime.Constants", "VERSION"));
|
90 | 97 | }
|
91 | 98 |
|
| 99 | + public static String springDataVersion() { |
| 100 | + // org.springframework.data.elasticsearch.support.VersionInfo.versionProperties() |
| 101 | + Properties springProp = (Properties) callStaticMethodObject( |
| 102 | + "org.springframework.data.elasticsearch.support.VersionInfo", |
| 103 | + "versionProperties"); |
| 104 | + if (springProp != null) { |
| 105 | + return keepMajorMinor(springProp.getProperty("version.spring-data-elasticsearch")); |
| 106 | + } |
| 107 | + return ""; |
| 108 | + |
| 109 | + } |
| 110 | + |
92 | 111 | private static String getStaticField(String className, String fieldName) {
|
93 | 112 | Class<?> clazz;
|
94 | 113 | try {
|
@@ -121,6 +140,22 @@ private static String callStaticMethod(String className, String methodName) {
|
121 | 140 | }
|
122 | 141 | }
|
123 | 142 |
|
| 143 | + private static Object callStaticMethodObject(String className, String methodName) { |
| 144 | + Class<?> clazz; |
| 145 | + try { |
| 146 | + clazz = Class.forName(className); |
| 147 | + } catch (ClassNotFoundException e) { |
| 148 | + return null; |
| 149 | + } |
| 150 | + |
| 151 | + try { |
| 152 | + Method m = clazz.getMethod(methodName); |
| 153 | + return m.invoke(null); |
| 154 | + } catch (Exception e) { |
| 155 | + return null; // can't get version information |
| 156 | + } |
| 157 | + } |
| 158 | + |
124 | 159 | static String keepMajorMinor(String version) {
|
125 | 160 | if (version == null) {
|
126 | 161 | return null;
|
|
0 commit comments