diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/info/InfoContributorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/info/InfoContributorAutoConfiguration.java index f50f73f56cd7..cde1f0cf8475 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/info/InfoContributorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/info/InfoContributorAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-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. @@ -20,7 +20,7 @@ import org.springframework.boot.actuate.info.EnvironmentInfoContributor; import org.springframework.boot.actuate.info.GitInfoContributor; import org.springframework.boot.actuate.info.InfoContributor; -import org.springframework.boot.actuate.info.java.JavaInfoContributor; +import org.springframework.boot.actuate.info.JavaInfoContributor; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -82,7 +82,7 @@ public InfoContributor buildInfoContributor(BuildProperties buildProperties) { @Bean @ConditionalOnEnabledInfoContributor("java") @Order(DEFAULT_ORDER) - public InfoContributor javaInfoContributor() { + public JavaInfoContributor javaInfoContributor() { return new JavaInfoContributor(); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/info/InfoContributorAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/info/InfoContributorAutoConfigurationTests.java index 40b7390d4042..87b7bab8c583 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/info/InfoContributorAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/info/InfoContributorAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-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. @@ -27,10 +27,10 @@ import org.springframework.boot.actuate.info.GitInfoContributor; import org.springframework.boot.actuate.info.Info; import org.springframework.boot.actuate.info.InfoContributor; -import org.springframework.boot.actuate.info.java.JavaInfo; -import org.springframework.boot.actuate.info.java.JavaInfoContributor; +import org.springframework.boot.actuate.info.JavaInfoContributor; import org.springframework.boot.info.BuildProperties; import org.springframework.boot.info.GitProperties; +import org.springframework.boot.info.JavaInfo; import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/java/JavaInfoContributor.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/JavaInfoContributor.java similarity index 85% rename from spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/java/JavaInfoContributor.java rename to spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/JavaInfoContributor.java index 5c44d9380cbb..480f05ff3e51 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/java/JavaInfoContributor.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/JavaInfoContributor.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2021 the original author or authors. + * Copyright 2012-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. @@ -14,10 +14,10 @@ * limitations under the License. */ -package org.springframework.boot.actuate.info.java; +package org.springframework.boot.actuate.info; import org.springframework.boot.actuate.info.Info.Builder; -import org.springframework.boot.actuate.info.InfoContributor; +import org.springframework.boot.info.JavaInfo; /** * An {@link InfoContributor} that exposes {@link JavaInfo}. diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/java/JavaInfo.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/java/JavaInfo.java deleted file mode 100644 index b9898f155ba5..000000000000 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/java/JavaInfo.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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; - } - -} diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/java/JreInfo.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/java/JreInfo.java deleted file mode 100644 index 1f8dd8132090..000000000000 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/java/JreInfo.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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; - } - -} diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/java/VmInfo.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/java/VmInfo.java deleted file mode 100644 index 76be01f4c37e..000000000000 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/java/VmInfo.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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; - } - -} diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/java/package-info.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/java/package-info.java deleted file mode 100644 index 3d53a37834d9..000000000000 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/java/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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; diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/java/JavaInfoContributorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/JavaInfoContributorTests.java similarity index 50% rename from spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/java/JavaInfoContributorTests.java rename to spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/JavaInfoContributorTests.java index f17638817cb3..f431ccd90e12 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/java/JavaInfoContributorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/JavaInfoContributorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2021 the original author or authors. + * Copyright 2012-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. @@ -14,11 +14,11 @@ * limitations under the License. */ -package org.springframework.boot.actuate.info.java; +package org.springframework.boot.actuate.info; import org.junit.jupiter.api.Test; -import org.springframework.boot.actuate.info.Info; +import org.springframework.boot.info.JavaInfo; import static org.assertj.core.api.Assertions.assertThat; @@ -34,17 +34,8 @@ 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")); + Info info = builder.build(); + assertThat(info.getDetails().get("java")).isInstanceOf(JavaInfo.class); } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/info/JavaInfo.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/info/JavaInfo.java new file mode 100644 index 000000000000..dcf5ec93357e --- /dev/null +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/info/JavaInfo.java @@ -0,0 +1,115 @@ +/* + * Copyright 2012-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.info; + +/** + * Provide information about the Java environment the application is running in. + * + * @author Jonatan Ivanov + * @author Stephane Nicoll + * @since 2.6.0 + */ +public class JavaInfo { + + private final String vendor; + + private final String version; + + private final JavaRuntimeEnvironmentInfo runtime; + + private final JavaVirtualMachineInfo jvm; + + public JavaInfo() { + this.vendor = System.getProperty("java.vendor"); + this.version = System.getProperty("java.version"); + this.runtime = new JavaRuntimeEnvironmentInfo(); + this.jvm = new JavaVirtualMachineInfo(); + } + + public String getVendor() { + return this.vendor; + } + + public String getVersion() { + return this.version; + } + + public JavaRuntimeEnvironmentInfo getRuntime() { + return this.runtime; + } + + public JavaVirtualMachineInfo getJvm() { + return this.jvm; + } + + /** + * Provide information about the Java Runtime Environment the application is running + * in. + */ + public static class JavaRuntimeEnvironmentInfo { + + private final String name; + + private final String version; + + public JavaRuntimeEnvironmentInfo() { + 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; + } + + } + + /** + * Provide information about the Java Virtual Machine) the application is running in. + */ + public static class JavaVirtualMachineInfo { + + private final String name; + + private final String vendor; + + private final String version; + + public JavaVirtualMachineInfo() { + 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; + } + + } + +} diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/info/JavaInfoTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/info/JavaInfoTests.java new file mode 100644 index 000000000000..d0ebdbc68b35 --- /dev/null +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/info/JavaInfoTests.java @@ -0,0 +1,55 @@ +/* + * Copyright 2012-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.info; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link JavaInfo}. + * + * @author Jonatan Ivanov + * @author Stephane Nicoll + */ +class JavaInfoTests { + + @Test + void javaInfoIsAvailable() { + JavaInfo javaInfo = new JavaInfo(); + assertThat(javaInfo.getVendor()).isEqualTo(System.getProperty("java.vendor")); + assertThat(javaInfo.getVersion()).isEqualTo(System.getProperty("java.version")); + assertThat(javaInfo.getRuntime()).isNotNull(); + assertThat(javaInfo.getJvm()).isNotNull(); + } + + @Test + void javaRuntimeEnvironmentInfoIsAvailable() { + JavaInfo.JavaRuntimeEnvironmentInfo jreInfo = new JavaInfo().getRuntime(); + assertThat(jreInfo.getName()).isEqualTo(System.getProperty("java.runtime.name")); + assertThat(jreInfo.getVersion()).isEqualTo(System.getProperty("java.runtime.version")); + } + + @Test + void javaVirtualMachineInfoIsAvailable() { + JavaInfo.JavaVirtualMachineInfo jvmInfo = new JavaInfo().getJvm(); + assertThat(jvmInfo.getName()).isEqualTo(System.getProperty("java.vm.name")); + assertThat(jvmInfo.getVendor()).isEqualTo(System.getProperty("java.vm.vendor")); + assertThat(jvmInfo.getVersion()).isEqualTo(System.getProperty("java.vm.version")); + } + +}