/*
 * 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.cli.compiler;

import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.control.CompilationFailedException;
import org.codehaus.groovy.control.customizers.ImportCustomizer;
import org.springframework.boot.cli.compiler.AstUtils;
import org.springframework.boot.cli.compiler.CompilerAutoConfiguration;
import org.springframework.boot.cli.compiler.DependencyCustomizer;

/**
 * @author Dave Syer
 *
 */
public class OAuth2SsoCompilerAutoConfiguration extends CompilerAutoConfiguration {

	@Override
	public boolean matches(ClassNode classNode) {
		return AstUtils.hasAtLeastOneAnnotation(classNode, "EnableOAuth2Sso","EnableCloudfoundrySso");
	}

	@Override
	public void applyDependencies(DependencyCustomizer dependencies) {
		dependencies
				.ifAnyMissingClasses(
						"org.springframework.cloud.cloudfoundry.sso.EnableOAuth2Sso")
				.add("spring-cloud-starter-cloudfoundry")
				.add("org.springframework.security.oauth:spring-security-oauth2:2.0.3.RELEASE");
	}

	@Override
	public void applyImports(ImportCustomizer imports) throws CompilationFailedException {
		imports.addImports(
				"org.springframework.cloud.cloudfoundry.sso.EnableCloudfoundrySso",
				"org.springframework.cloud.cloudfoundry.sso.EnableOAuth2Sso",
				"org.springframework.cloud.cloudfoundry.sso.OAuth2SsoConfigurerAdapter");
	}

}

@@ -1277,35 +1277,11 @@
 Sso%22
-,%22EnableCloudfoundrySso%22
 );%0A
+
 %09%7D%0A%0A
@@ -1528,43 +1528,8 @@
 dd(%22
-org.springframework.security.oauth:
 spri
@@ -1550,22 +1550,8 @@
 uth2
-:2.0.3.RELEASE
 %22);%0A
@@ -1653,16 +1653,16 @@
 ption %7B%0A
+
 %09%09import
@@ -1679,80 +1679,8 @@
 ts(%0A
-%09%09%09%09%22org.springframework.cloud.cloudfoundry.sso.EnableCloudfoundrySso%22,%0A
 %09%09%09%09

Break up hystrix dashboard