001/*
002 * Copyright 2012-2017 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.actuate.autoconfigure.info;
018
019import org.springframework.boot.actuate.info.BuildInfoContributor;
020import org.springframework.boot.actuate.info.EnvironmentInfoContributor;
021import org.springframework.boot.actuate.info.GitInfoContributor;
022import org.springframework.boot.actuate.info.InfoContributor;
023import org.springframework.boot.autoconfigure.AutoConfigureAfter;
024import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
025import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
026import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
027import org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration;
028import org.springframework.boot.context.properties.EnableConfigurationProperties;
029import org.springframework.boot.info.BuildProperties;
030import org.springframework.boot.info.GitProperties;
031import org.springframework.context.annotation.Bean;
032import org.springframework.context.annotation.Configuration;
033import org.springframework.core.Ordered;
034import org.springframework.core.annotation.Order;
035import org.springframework.core.env.ConfigurableEnvironment;
036
037/**
038 * {@link EnableAutoConfiguration Auto-configuration} for standard
039 * {@link InfoContributor}s.
040 *
041 * @author Meang Akira Tanaka
042 * @author Stephane Nicoll
043 * @since 2.0.0
044 */
045@Configuration
046@AutoConfigureAfter(ProjectInfoAutoConfiguration.class)
047@EnableConfigurationProperties(InfoContributorProperties.class)
048public class InfoContributorAutoConfiguration {
049
050        /**
051         * The default order for the core {@link InfoContributor} beans.
052         */
053        public static final int DEFAULT_ORDER = Ordered.HIGHEST_PRECEDENCE + 10;
054
055        private final InfoContributorProperties properties;
056
057        public InfoContributorAutoConfiguration(InfoContributorProperties properties) {
058                this.properties = properties;
059        }
060
061        @Bean
062        @ConditionalOnEnabledInfoContributor("env")
063        @Order(DEFAULT_ORDER)
064        public EnvironmentInfoContributor envInfoContributor(
065                        ConfigurableEnvironment environment) {
066                return new EnvironmentInfoContributor(environment);
067        }
068
069        @Bean
070        @ConditionalOnEnabledInfoContributor("git")
071        @ConditionalOnSingleCandidate(GitProperties.class)
072        @ConditionalOnMissingBean
073        @Order(DEFAULT_ORDER)
074        public GitInfoContributor gitInfoContributor(GitProperties gitProperties) {
075                return new GitInfoContributor(gitProperties, this.properties.getGit().getMode());
076        }
077
078        @Bean
079        @ConditionalOnEnabledInfoContributor("build")
080        @ConditionalOnSingleCandidate(BuildProperties.class)
081        @Order(DEFAULT_ORDER)
082        public InfoContributor buildInfoContributor(BuildProperties buildProperties) {
083                return new BuildInfoContributor(buildProperties);
084        }
085
086}