spring-graphql FormattingConventionsPlugin 源码

  • 2022-08-16
  • 浏览 (662)

spring-graphql FormattingConventionsPlugin 代码

文件路径:/buildSrc/src/main/java/org/springframework/graphql/build/format/FormattingConventionsPlugin.java

/*
 * Copyright 2020-2021 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
 *
 *      https://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.graphql.build.format;

import io.spring.javaformat.gradle.FormatTask;
import io.spring.javaformat.gradle.SpringJavaFormatPlugin;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.DependencySet;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.plugins.quality.CheckstyleExtension;
import org.gradle.api.plugins.quality.CheckstylePlugin;

/**
 * Conventions that are applied in the presence of the {@link JavaBasePlugin}. When the
 * plugin is applied, the {@link SpringJavaFormatPlugin Spring Java Format} and
 * {@link CheckstylePlugin Checkstyle}.
 *
 * @author Brian Clozel
 */
public class FormattingConventionsPlugin implements Plugin<Project> {

	@Override
	public void apply(Project project) {
		project.getPlugins().withType(JavaBasePlugin.class, (java) -> applySpringJavaFormat(project));
	}

	private void applySpringJavaFormat(Project project) {
		project.getPlugins().apply(SpringJavaFormatPlugin.class);
		project.getTasks().withType(FormatTask.class, (formatTask) -> formatTask.setEncoding("UTF-8"));
		project.getPlugins().apply(CheckstylePlugin.class);
		CheckstyleExtension checkstyle = project.getExtensions().getByType(CheckstyleExtension.class);
		checkstyle.setToolVersion("8.43");
		checkstyle.getConfigDirectory().set(project.getRootProject().file("src/checkstyle"));
		String version = SpringJavaFormatPlugin.class.getPackage().getImplementationVersion();
		DependencySet checkstyleDependencies = project.getConfigurations().getByName("checkstyle").getDependencies();
		checkstyleDependencies
				.add(project.getDependencies().create("io.spring.javaformat:spring-javaformat-checkstyle:" + version));
	}

}

相关信息

spring-graphql 源码目录

相关文章

spring-graphql CompilerConventionsPlugin 源码

spring-graphql Employee 源码

spring-graphql EmployeeService 源码

spring-graphql SalaryController 源码

spring-graphql SalaryInput 源码

spring-graphql SalaryService 源码

spring-graphql SampleApplication 源码

spring-graphql SecurityConfig 源码

spring-graphql DataRepository 源码

spring-graphql SampleApplication 源码

0  赞