|
| 1 | +/* |
| 2 | + * Copyright 2012-2015 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.boot.gradle; |
| 18 | + |
| 19 | +import org.gradle.api.Action; |
| 20 | +import org.gradle.api.Plugin; |
| 21 | +import org.gradle.api.Project; |
| 22 | +import org.gradle.api.Task; |
| 23 | +import org.gradle.api.plugins.ApplicationPlugin; |
| 24 | +import org.gradle.api.plugins.BasePlugin; |
| 25 | +import org.gradle.api.plugins.JavaPlugin; |
| 26 | +import org.gradle.api.tasks.compile.JavaCompile; |
| 27 | +import org.springframework.boot.gradle.agent.AgentPluginFeatures; |
| 28 | +import org.springframework.boot.gradle.exclude.ExcludePluginFeatures; |
| 29 | +import org.springframework.boot.gradle.repackage.RepackagePluginFeatures; |
| 30 | +import org.springframework.boot.gradle.resolve.ResolvePluginFeatures; |
| 31 | +import org.springframework.boot.gradle.run.RunPluginFeatures; |
| 32 | + |
| 33 | +/** |
| 34 | + * Gradle 'Spring Boot' {@link Plugin}. |
| 35 | + * |
| 36 | + * @author Phillip Webb |
| 37 | + * @author Dave Syer |
| 38 | + */ |
| 39 | +class SpringBootPlugin implements Plugin<Project> { |
| 40 | + |
| 41 | + @Override |
| 42 | + public void apply(Project project) { |
| 43 | + project.getPlugins().apply(BasePlugin.class); |
| 44 | + project.getExtensions().create("springBoot", SpringBootPluginExtension.class); |
| 45 | + project.getConfigurations().create(VersionManagedDependencies.CONFIGURATION); |
| 46 | + project.getPlugins().apply(JavaPlugin.class); |
| 47 | + project.getPlugins().apply(ApplicationPlugin.class); |
| 48 | + new AgentPluginFeatures().apply(project); |
| 49 | + new RepackagePluginFeatures().apply(project); |
| 50 | + new RunPluginFeatures().apply(project); |
| 51 | + new ResolvePluginFeatures().apply(project); |
| 52 | + new ExcludePluginFeatures().apply(project); |
| 53 | + project.getTasks().withType(JavaCompile.class).all(new SetUtf8EncodingAction()); |
| 54 | + } |
| 55 | + |
| 56 | + private static class SetUtf8EncodingAction implements Action<JavaCompile> { |
| 57 | + |
| 58 | + @Override |
| 59 | + public void execute(final JavaCompile compile) { |
| 60 | + compile.doFirst(new Action<Task>() { |
| 61 | + |
| 62 | + @Override |
| 63 | + @SuppressWarnings("deprecation") |
| 64 | + public void execute(Task t) { |
| 65 | + if (compile.getOptions().getEncoding() == null) { |
| 66 | + compile.getOptions().setEncoding("UTF-8"); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + }); |
| 71 | + } |
| 72 | + |
| 73 | + } |
| 74 | + |
| 75 | +} |
0 commit comments