/*
 * Copyright 2016-2018 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.cloud.dataflow.server.cloudfoundry.config;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.PostConstruct;

import reactor.core.publisher.Hooks;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.dataflow.server.cloudfoundry.config.security.CloudFoundryOAuthSecurityConfiguration;
import org.springframework.cloud.deployer.resource.docker.DockerResource;
import org.springframework.cloud.deployer.resource.docker.DockerResourceLoader;
import org.springframework.cloud.deployer.resource.maven.MavenProperties;
import org.springframework.cloud.deployer.resource.maven.MavenResource;
import org.springframework.cloud.deployer.resource.maven.MavenResourceLoader;
import org.springframework.cloud.deployer.resource.support.DelegatingResourceLoader;
import org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryConnectionProperties;
import org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryDeploymentProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.io.ResourceLoader;

/**
 * Configuration class for customizing Cloud Foundry deployer.
 *
 * @author Eric Bottard
 */
@Configuration
@Import(CloudFoundryOAuthSecurityConfiguration.class)
public class CloudFoundryDataFlowServerConfiguration {

	@Bean
	@ConfigurationProperties(prefix = CloudFoundryConnectionProperties.CLOUDFOUNDRY_PROPERTIES + ".stream")
	public CloudFoundryDeploymentProperties appDeploymentProperties() {
		return new CloudFoundryDeploymentProperties();
	}

	@Bean
	@ConfigurationProperties(prefix = CloudFoundryConnectionProperties.CLOUDFOUNDRY_PROPERTIES + ".task")
	public CloudFoundryDeploymentProperties taskDeploymentProperties() {
		return new CloudFoundryDeploymentProperties();
	}

	@Bean
	@ConfigurationProperties(prefix = CloudFoundryServerConfigurationProperties.PREFIX)
	public CloudFoundryServerConfigurationProperties cloudFoundryServerConfigurationProperties() {
		return new CloudFoundryServerConfigurationProperties();
	}

	@Bean
	public DelegatingResourceLoader delegatingResourceLoader(MavenProperties mavenProperties) {
		Map<String, ResourceLoader> loaders = new HashMap<>();
		loaders.put(DockerResource.URI_SCHEME, new DockerResourceLoader());
		loaders.put(MavenResource.URI_SCHEME, new MavenResourceLoader(mavenProperties));
		return new DelegatingResourceLoader(loaders);
	}

	@PostConstruct
	public void afterPropertiesSet() {
		if (cloudFoundryServerConfigurationProperties().isDebugReactor()) {
			Hooks.onOperatorDebug();
		}
	}

}

@@ -691,57 +691,8 @@
 g;%0A%0A
-import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 impo
@@ -765,16 +765,83 @@
 Hooks;%0A%0A
+import org.springframework.boot.autoconfigure.AutoConfigureBefore;%0A
 import o
@@ -1018,32 +1018,131 @@
 yConfiguration;%0A
+import org.springframework.cloud.deployer.autoconfigure.DelegatingResourceLoaderBuilderCustomizer;%0A
 import org.sprin
@@ -1325,273 +1325,57 @@
 yer.
-resource.maven.MavenProperties;%0Aimport org.springframework.cloud.deployer.resource.maven.MavenResource;%0Aimport org.springframework.cloud.deployer.resource.maven.MavenResourceLoader;%0Aimport org.springframework.cloud.deployer.resource.support.DelegatingResourceLoader
+spi.cloudfoundry.CloudFoundryConnectionProperties
 ;%0Aim
@@ -1443,36 +1443,41 @@
 dFoundry
-ConnectionProperties
+DeployerAutoConfiguration
 ;%0Aimport
@@ -1733,59 +1733,8 @@
 ort;
-%0Aimport org.springframework.core.io.ResourceLoader;
 %0A%0A/*
@@ -1898,16 +1898,82 @@
 .class)%0A
+@AutoConfigureBefore(CloudFoundryDeployerAutoConfiguration.class)%0A
 public c
@@ -2780,139 +2780,118 @@
 ader
- delegatingResourceLoader(MavenProperties mavenProperties) %7B%0A%09%09Map%3CString, ResourceLoader%3E loaders = new HashMap%3C%3E();%0A%09%09
+BuilderCustomizer dockerDelegatingResourceLoaderBuilderCustomizer() %7B%0A%09%09return customizer -%3E customizer.
 loader
-s.put
 (Doc
@@ -2947,139 +2947,8 @@
 ));%0A
-%09%09loaders.put(MavenResource.URI_SCHEME, new MavenResourceLoader(mavenProperties));%0A%09%09return new DelegatingResourceLoader(loaders);%0A
 %09%7D%0A%0A

Fix boot 2.1 upgrade issues