/*
 * Copyright 2013-2014 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.aws.context.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.cloud.aws.core.env.ec2.AmazonEc2InstanceDataPropertySource;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.Ordered;
import org.springframework.core.PriorityOrdered;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;

/**
 * @author Agim Emruli
 */
public class AmazonEc2InstanceDataPropertySourcePostProcessor implements PriorityOrdered, EnvironmentAware, BeanFactoryPostProcessor {

	static final String INSTANCE_DATA_PROPERTY_SOURCE_NAME = "InstanceData";
	private static final Logger LOGGER = LoggerFactory.getLogger(AmazonEc2InstanceDataPropertySourcePostProcessor.class);

	private Environment environment;
	private String valueSeparator;
	private String attributeSeparator;

	@Override
	public void setEnvironment(Environment environment) {
		this.environment = environment;
	}

	@Override
	public int getOrder() {
		return Ordered.HIGHEST_PRECEDENCE;
	}

	public void setValueSeparator(String valueSeparator) {
		this.valueSeparator = valueSeparator;
	}

	public void setAttributeSeparator(String attributeSeparator) {
		this.attributeSeparator = attributeSeparator;
	}

	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		if (this.environment instanceof ConfigurableEnvironment) {
			AmazonEc2InstanceDataPropertySource propertySource = new AmazonEc2InstanceDataPropertySource(INSTANCE_DATA_PROPERTY_SOURCE_NAME);

			if (this.valueSeparator != null) {
				propertySource.setUserDataValueSeparator(this.valueSeparator);
			}

			if (this.attributeSeparator != null) {
				propertySource.setUserDataAttributeSeparator(this.attributeSeparator);
			}

			((ConfigurableEnvironment) this.environment).getPropertySources().addLast(propertySource);
		} else {
			LOGGER.warn("Environment is not of type '{}' property source with instance data is not available", ConfigurableEnvironment.class.getName());
		}
	}
}
@@ -1270,16 +1270,61 @@
 ronment;
+%0Aimport org.springframework.util.StringUtils;
 %0A%0A/**%0A *
@@ -2491,24 +2491,44 @@
 ME);%0A%0A%09%09%09if 
+(StringUtils.hasText
 (this.valueS
@@ -2531,32 +2531,25 @@
 lueSeparator
- != null
+)
 ) %7B%0A%09%09%09%09prop
@@ -2615,24 +2615,44 @@
 %09%09%09%7D%0A%0A%09%09%09if 
+(StringUtils.hasText
 (this.attrib
@@ -2667,16 +2667,9 @@
 ator
- != null
+)
 ) %7B%0A

Check if string has text for attribute and value separator