/*
 * Copyright 2012-2019 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.autoconfigure.orm.jpa;

import java.util.Arrays;

import javax.persistence.EntityManager;

import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
import org.springframework.boot.autoconfigure.condition.ConditionMessage.Style;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration.HibernateEntityManagerCondition;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.util.ClassUtils;

/**
 * {@link EnableAutoConfiguration Auto-configuration} for Hibernate JPA.
 *
 * @author Phillip Webb
 * @author Josh Long
 * @author Manuel Doninger
 * @author Andy Wilkinson
 */
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ LocalContainerEntityManagerFactoryBean.class, EntityManager.class })
@Conditional(HibernateEntityManagerCondition.class)
@EnableConfigurationProperties(JpaProperties.class)
@AutoConfigureAfter({ DataSourceAutoConfiguration.class })
@Import(HibernateJpaConfiguration.class)
public class HibernateJpaAutoConfiguration {

	@Order(Ordered.HIGHEST_PRECEDENCE + 20)
	static class HibernateEntityManagerCondition extends SpringBootCondition {

		private static final String[] CLASS_NAMES = { "org.hibernate.ejb.HibernateEntityManager",
				"org.hibernate.jpa.HibernateEntityManager" };

		@Override
		public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
			ConditionMessage.Builder message = ConditionMessage.forCondition("HibernateEntityManager");
			for (String className : CLASS_NAMES) {
				if (ClassUtils.isPresent(className, context.getClassLoader())) {
					return ConditionOutcome.match(message.found("class").items(Style.QUOTE, className));
				}
			}
			return ConditionOutcome
					.noMatch(message.didNotFind("class", "classes").items(Style.QUOTE, Arrays.asList(CLASS_NAMES)));
		}

	}

}

@@ -688,34 +688,8 @@
 java
-.util.Arrays;%0A%0Aimport java
 x.pe
@@ -710,16 +710,69 @@
 tyManage
+r;%0A%0Aimport org.hibernate.engine.spi.SessionImplemento
 r;%0A%0Aimpo
@@ -973,990 +973,294 @@
 tion
-Message;%0Aimport org.springframework.boot.autoconfigure.condition.ConditionMessage.Style;%0Aimport org.springframework.boot.autoconfigure.condition.ConditionOutcome;%0Aimport org.springframework.boot.autoconfigure.condition.ConditionalOnClass;%0Aimport org.springframework.boot.autoconfigure.condition.SpringBootCondition;%0Aimport org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;%0Aimport org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration.HibernateEntityManagerCondition;%0Aimport org.springframework.boot.context.properties.EnableConfigurationProperties;%0Aimport org.springframework.context.annotation.ConditionContext;%0Aimport org.springframework.context.annotation.Conditional;%0Aimport org.springframework.context.annotation.Configuration;%0Aimport org.springframework.context.annotation.Import;%0Aimport org.springframework.core.Ordered;%0Aimport org.springframework.core.annotation.Order;%0Aimport org.springframework.core.type.AnnotatedTypeMetadata
+alOnClass;%0Aimport org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;%0Aimport org.springframework.boot.context.properties.EnableConfigurationProperties;%0Aimport org.springframework.context.annotation.Configuration;%0Aimport org.springframework.context.annotation.Import
 ;%0Aim
@@ -1335,52 +1335,8 @@
 ean;
-%0Aimport org.springframework.util.ClassUtils;
 %0A%0A/*
@@ -1647,62 +1647,36 @@
 lass
- %7D)%0A@Conditional(HibernateEntityManagerCondition
+, SessionImplementor
 .class
+ %7D
 )%0A@E
@@ -1875,826 +1875,6 @@
  %7B%0A%0A
-%09@Order(Ordered.HIGHEST_PRECEDENCE + 20)%0A%09static class HibernateEntityManagerCondition extends SpringBootCondition %7B%0A%0A%09%09private static final String%5B%5D CLASS_NAMES = %7B %22org.hibernate.ejb.HibernateEntityManager%22,%0A%09%09%09%09%22org.hibernate.jpa.HibernateEntityManager%22 %7D;%0A%0A%09%09@Override%0A%09%09public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) %7B%0A%09%09%09ConditionMessage.Builder message = ConditionMessage.forCondition(%22HibernateEntityManager%22);%0A%09%09%09for (String className : CLASS_NAMES) %7B%0A%09%09%09%09if (ClassUtils.isPresent(className, context.getClassLoader())) %7B%0A%09%09%09%09%09return ConditionOutcome.match(message.found(%22class%22).items(Style.QUOTE, className));%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%09return ConditionOutcome%0A%09%09%09%09%09.noMatch(message.didNotFind(%22class%22, %22classes%22).items(Style.QUOTE, Arrays.asList(CLASS_NAMES)));%0A%09%09%7D%0A%0A%09%7D%0A%0A
 %7D%0A

Simplify HibernateJpaAutoConfiguration classes check