/*
 *  Copyright 2017 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.gcp.core;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.util.StringUtils;

/**
 * Determine whether this is running inside of an App Engine environment by looking into
 * the System properties {@value APPENGINE_RUNTIME_PROPERTY}.
 *
 * @author Ray Tsang
 */
public class AppEngineCondition implements Condition {
	public static final String APPENGINE_RUNTIME_PROPERTY = "com.google.appengine.runtime.version";

	public static final String APPENGINE_RUNTIME_PREFIX = "Google App Engine/";

	@Override
	public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
		String appEngineVersion = System.getProperty(APPENGINE_RUNTIME_PROPERTY);
		return !StringUtils.isEmpty(appEngineVersion)
				&& appEngineVersion.startsWith(APPENGINE_RUNTIME_PREFIX);

	}
}

@@ -688,35 +688,129 @@
 amework.
-context.annotation.
+boot.autoconfigure.condition.ConditionOutcome;%0Aimport org.springframework.boot.autoconfigure.condition.SpringBoot
 Conditio
@@ -1161,16 +1161,46 @@
 y Tsang%0A
+ * @author Jo%C3%A3o Andr%C3%A9 Martins%0A
  */%0Apubl
@@ -1231,19 +1231,26 @@
 ion 
-implement
+extend
 s 
+SpringBoot
 Cond
@@ -1456,23 +1456,40 @@
 lic 
-boolean matches
+ConditionOutcome getMatchOutcome
 (Con
@@ -1505,25 +1505,16 @@
 text con
-ditionCon
 text, An
@@ -1537,22 +1537,9 @@
 ata 
-annotatedTypeM
+m
 etad
@@ -1627,14 +1627,23 @@
 ;%0A%09%09
-return
+boolean match =
  !St
@@ -1681,13 +1681,9 @@
 ion)
-%0A%09%09%09%09
+ 
 && a
@@ -1736,14 +1736,405 @@
 REFIX);%0A
+%09%09String message = match%0A%09%09%09%09? %22Your app is running on Google App Engine. %22 + APPENGINE_RUNTIME_PROPERTY + %22 property is set to %22%0A%09%09%09%09+ appEngineVersion + %22.%22%0A%09%09%09%09: %22App not running on Google App Engine. Property %22 + APPENGINE_RUNTIME_PROPERTY + %22 isn't present, or%22%0A%09%09%09%09+ %22 it doesn't start with the %22 + APPENGINE_RUNTIME_PREFIX + %22 prefix.%22;%0A%0A%09%09return new ConditionOutcome(match, message);
 %0A%09%7D%0A%7D%0A

Make AppEngineCondition extend SpringBootCondition (#298)