Skip to content

Commit ccf6c86

Browse files
committed
Merge pull request #29090 from jonatan-ivanov
* pr/29090: Polish "Add vendor version to JavaInfo" Add vendor version to JavaInfo Closes gh-29090
2 parents 9ff4ea5 + 605ec2f commit ccf6c86

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/info/JavaInfo.java

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,29 +25,29 @@
2525
*/
2626
public class JavaInfo {
2727

28-
private final String vendor;
29-
3028
private final String version;
3129

30+
private final JavaVendorInfo vendor;
31+
3232
private final JavaRuntimeEnvironmentInfo runtime;
3333

3434
private final JavaVirtualMachineInfo jvm;
3535

3636
public JavaInfo() {
37-
this.vendor = System.getProperty("java.vendor");
3837
this.version = System.getProperty("java.version");
38+
this.vendor = new JavaVendorInfo();
3939
this.runtime = new JavaRuntimeEnvironmentInfo();
4040
this.jvm = new JavaVirtualMachineInfo();
4141
}
4242

43-
public String getVendor() {
44-
return this.vendor;
45-
}
46-
4743
public String getVersion() {
4844
return this.version;
4945
}
5046

47+
public JavaVendorInfo getVendor() {
48+
return this.vendor;
49+
}
50+
5151
public JavaRuntimeEnvironmentInfo getRuntime() {
5252
return this.runtime;
5353
}
@@ -56,6 +56,33 @@ public JavaVirtualMachineInfo getJvm() {
5656
return this.jvm;
5757
}
5858

59+
/**
60+
* Information about the Java Vendor of the Java Runtime the application is running
61+
* in.
62+
*
63+
* @since 2.7.0
64+
*/
65+
public static class JavaVendorInfo {
66+
67+
private final String name;
68+
69+
private final String version;
70+
71+
public JavaVendorInfo() {
72+
this.name = System.getProperty("java.vendor");
73+
this.version = System.getProperty("java.vendor.version");
74+
}
75+
76+
public String getName() {
77+
return this.name;
78+
}
79+
80+
public String getVersion() {
81+
return this.version;
82+
}
83+
84+
}
85+
5986
/**
6087
* Information about the Java Runtime Environment the application is running in.
6188
*/

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/info/JavaInfoTests.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,8 +31,11 @@ class JavaInfoTests {
3131
@Test
3232
void javaInfoIsAvailable() {
3333
JavaInfo javaInfo = new JavaInfo();
34-
assertThat(javaInfo.getVendor()).isEqualTo(System.getProperty("java.vendor"));
3534
assertThat(javaInfo.getVersion()).isEqualTo(System.getProperty("java.version"));
35+
assertThat(javaInfo.getVendor()).satisfies((vendorInfo) -> {
36+
assertThat(vendorInfo.getName()).isEqualTo(System.getProperty("java.vendor"));
37+
assertThat(vendorInfo.getVersion()).isEqualTo(System.getProperty("java.vendor.version"));
38+
});
3639
assertThat(javaInfo.getRuntime()).satisfies((jreInfo) -> {
3740
assertThat(jreInfo.getName()).isEqualTo(System.getProperty("java.runtime.name"));
3841
assertThat(jreInfo.getVersion()).isEqualTo(System.getProperty("java.runtime.version"));

0 commit comments

Comments
 (0)