-
Notifications
You must be signed in to change notification settings - Fork 40.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
311 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...ring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/java/JavaInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2021-2021 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.actuate.info.java; | ||
|
||
/** | ||
* A simple DTO that holds information about the Java environment the application is | ||
* running in. | ||
* | ||
* @author Jonatan Ivanov | ||
* @since 2.6.0 | ||
*/ | ||
public class JavaInfo { | ||
|
||
private final String vendor; | ||
|
||
private final String version; | ||
|
||
private final JreInfo runtime; | ||
|
||
private final VmInfo vm; | ||
|
||
public JavaInfo() { | ||
this.vendor = System.getProperty("java.vendor"); | ||
this.version = System.getProperty("java.version"); | ||
this.runtime = new JreInfo(); | ||
this.vm = new VmInfo(); | ||
} | ||
|
||
public String getVendor() { | ||
return this.vendor; | ||
} | ||
|
||
public String getVersion() { | ||
return this.version; | ||
} | ||
|
||
public JreInfo getRuntime() { | ||
return this.runtime; | ||
} | ||
|
||
public VmInfo getVm() { | ||
return this.vm; | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...ctuator/src/main/java/org/springframework/boot/actuate/info/java/JavaInfoContributor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2021-2021 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.actuate.info.java; | ||
|
||
import org.springframework.boot.actuate.info.Info.Builder; | ||
import org.springframework.boot.actuate.info.InfoContributor; | ||
|
||
/** | ||
* An {@link InfoContributor} that exposes {@link JavaInfo}. | ||
* | ||
* @author Jonatan Ivanov | ||
* @since 2.6.0 | ||
*/ | ||
public class JavaInfoContributor implements InfoContributor { | ||
|
||
private final JavaInfo javaInfo; | ||
|
||
public JavaInfoContributor() { | ||
this.javaInfo = new JavaInfo(); | ||
} | ||
|
||
@Override | ||
public void contribute(Builder builder) { | ||
builder.withDetail("java", this.javaInfo); | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
...pring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/java/JreInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2021-2021 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.actuate.info.java; | ||
|
||
/** | ||
* A simple DTO that holds information about the JRE (Java Runtime Environment) the | ||
* application is running in. | ||
* | ||
* @author Jonatan Ivanov | ||
* @since 2.6.0 | ||
*/ | ||
public class JreInfo { | ||
|
||
private final String name; | ||
|
||
private final String version; | ||
|
||
public JreInfo() { | ||
this.name = System.getProperty("java.runtime.name"); | ||
this.version = System.getProperty("java.runtime.version"); | ||
} | ||
|
||
public String getName() { | ||
return this.name; | ||
} | ||
|
||
public String getVersion() { | ||
return this.version; | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
...spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/java/VmInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2021-2021 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.actuate.info.java; | ||
|
||
/** | ||
* A simple DTO that holds information about the JVM (Java Virtual Machine) the | ||
* application is running in. | ||
* | ||
* @author Jonatan Ivanov | ||
* @since 2.6.0 | ||
*/ | ||
public class VmInfo { | ||
|
||
private final String name; | ||
|
||
private final String vendor; | ||
|
||
private final String version; | ||
|
||
public VmInfo() { | ||
this.name = System.getProperty("java.vm.name"); | ||
this.vendor = System.getProperty("java.vm.vendor"); | ||
this.version = System.getProperty("java.vm.version"); | ||
} | ||
|
||
public String getName() { | ||
return this.name; | ||
} | ||
|
||
public String getVendor() { | ||
return this.vendor; | ||
} | ||
|
||
public String getVersion() { | ||
return this.version; | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...-boot-actuator/src/main/java/org/springframework/boot/actuate/info/java/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright 2021-2021 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* Classes for java info. | ||
*/ | ||
package org.springframework.boot.actuate.info.java; |
50 changes: 50 additions & 0 deletions
50
...or/src/test/java/org/springframework/boot/actuate/info/java/JavaInfoContributorTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2021-2021 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.actuate.info.java; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import org.springframework.boot.actuate.info.Info; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Tests for {@link JavaInfoContributor} | ||
* | ||
* @author Jonatan Ivanov | ||
*/ | ||
class JavaInfoContributorTests { | ||
|
||
@Test | ||
void javaInfoShouldBeAdded() { | ||
JavaInfoContributor javaInfoContributor = new JavaInfoContributor(); | ||
Info.Builder builder = new Info.Builder(); | ||
javaInfoContributor.contribute(builder); | ||
|
||
assertThat(builder.build().getDetails().get("java")).isInstanceOf(JavaInfo.class); | ||
JavaInfo javaInfo = (JavaInfo) builder.build().getDetails().get("java"); | ||
|
||
assertThat(javaInfo.getVendor()).isEqualTo(System.getProperty("java.vendor")); | ||
assertThat(javaInfo.getVersion()).isEqualTo(System.getProperty("java.version")); | ||
assertThat(javaInfo.getRuntime().getName()).isEqualTo(System.getProperty("java.runtime.name")); | ||
assertThat(javaInfo.getRuntime().getVersion()).isEqualTo(System.getProperty("java.runtime.version")); | ||
assertThat(javaInfo.getVm().getName()).isEqualTo(System.getProperty("java.vm.name")); | ||
assertThat(javaInfo.getVm().getVendor()).isEqualTo(System.getProperty("java.vm.vendor")); | ||
assertThat(javaInfo.getVm().getVersion()).isEqualTo(System.getProperty("java.vm.version")); | ||
} | ||
|
||
} |