/*
 * Copyright 2012-2016 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
 *
 *      http://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.integration;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.StandardAnnotationMetadata;
import org.springframework.integration.annotation.IntegrationComponentScan;
import org.springframework.integration.config.IntegrationComponentScanRegistrar;

/**
 * Variation of {@link IntegrationComponentScanRegistrar} the links
 * {@link AutoConfigurationPackages}.
 *
 * @author Artem Bilan
 * @author Phillip Webb
 */
class IntegrationAutoConfigurationScanRegistrar extends IntegrationComponentScanRegistrar
		implements BeanFactoryAware {

	private BeanFactory beanFactory;

	@Override
	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		this.beanFactory = beanFactory;
	}

	@Override
	public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
			final BeanDefinitionRegistry registry) {
		super.registerBeanDefinitions(
				new IntegrationComponentScanConfigurationMetaData(this.beanFactory),
				registry);
	}

	private static class IntegrationComponentScanConfigurationMetaData
			extends StandardAnnotationMetadata {

		private final BeanFactory beanFactory;

		IntegrationComponentScanConfigurationMetaData(BeanFactory beanFactory) {
			super(IntegrationComponentScanConfiguration.class, true);
			this.beanFactory = beanFactory;
		}

		@Override
		public Map<String, Object> getAnnotationAttributes(String annotationName) {
			Map<String, Object> attributes = super.getAnnotationAttributes(
					annotationName);
			if (IntegrationComponentScan.class.getName().equals(annotationName)
					&& AutoConfigurationPackages.has(this.beanFactory)) {
				List<String> packages = AutoConfigurationPackages.get(this.beanFactory);
				attributes = new LinkedHashMap<String, Object>(attributes);
				attributes.put("value", packages.toArray(new String[packages.size()]));
			}
			return attributes;
		}
	}

	@IntegrationComponentScan
	private static class IntegrationComponentScanConfiguration {

	}

}

@@ -21,9 +21,9 @@
 -201
-6
+7
  the
@@ -693,29 +693,26 @@
 va.util.
-LinkedHashMap
+Collection
 ;%0Aimport
@@ -726,34 +726,19 @@
 til.
-List;%0Aimport java.util.Map
+Collections
 ;%0A%0Ai
@@ -1943,336 +1943,44 @@
 ons(
-%0A%09%09%09%09new IntegrationComponentScanConfigurationMetaData(this.beanFactory),%0A%09%09%09%09registry);%0A%09%7D%0A%0A%09private static class IntegrationComponentScanConfigurationMetaData%0A%09%09%09extends StandardAnnotationMetadata %7B%0A%0A%09%09private final BeanFactory beanFactory;%0A%0A%09%09IntegrationComponentScanConfigurationMetaData(BeanFactory beanFactory) %7B%0A%09%09%09super(
+new StandardAnnotationMetadata(%0A%09%09%09%09
 Inte
@@ -2029,51 +2029,25 @@
 rue)
-;%0A%09%09%09this.beanFactory = beanFactory
+, registry)
 ;%0A
-%09
 %09%7D%0A%0A
-%09
 %09@Ov
@@ -2058,158 +2058,58 @@
 de%0A%09
-%09public Map%3CString, Object%3E getAnnotationAttributes(String annotationName) %7B%0A%09%09%09Map%3CString, Object%3E attributes = super.getAnnotationAttribut
+protected Collection%3CString%3E getBasePackag
 es(%0A%09%09%09
-%09%09a
+A
 nnot
@@ -2117,93 +2117,84 @@
 tion
-Name);%0A%09%09%09if (IntegrationComponentScan.class.getName().equals(annotationName)%0A%09%09%09%09%09&&
+Metadata importingClassMetadata, BeanDefinitionRegistry registry) %7B%0A%09%09return
  Aut
@@ -2241,39 +2241,14 @@
 ory)
-) %7B
 %0A%09%09%09%09
-List%3CString%3E packages =
+?
  Aut
@@ -2295,180 +2295,39 @@
 ory)
-;
 %0A%09%09%09%09
-attributes = new LinkedHashMap%3CString, Object%3E(attributes);%0A%09%09%09%09attributes.put(%22value%22, packages.toArray(new String%5Bpackages.size()%5D));%0A%09%09%09%7D%0A%09%09%09return attributes;%0A%09%09%7D
+: Collections.emptyList();
 %0A%09%7D%0A

Make use of new extensions point in IntegrationComponentScanRegistrar