spring security GitHubChangelogPlugin 源码

  • 2022-08-13
  • 浏览 (642)

spring security GitHubChangelogPlugin 代码

文件路径:/buildSrc/src/main/java/org/springframework/gradle/github/changelog/GitHubChangelogPlugin.java

/*
 * Copyright 2019-2020 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.gradle.github.changelog;

import java.io.File;
import java.nio.file.Paths;

import org.gradle.api.Action;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.DependencySet;
import org.gradle.api.artifacts.repositories.ExclusiveContentRepository;
import org.gradle.api.artifacts.repositories.InclusiveRepositoryContentDescriptor;
import org.gradle.api.artifacts.repositories.IvyArtifactRepository;
import org.gradle.api.artifacts.repositories.IvyPatternRepositoryLayout;
import org.gradle.api.tasks.JavaExec;

public class GitHubChangelogPlugin implements Plugin<Project> {

	public static final String CHANGELOG_GENERATOR_CONFIGURATION_NAME = "changelogGenerator";
	public static final String RELEASE_NOTES_PATH = "changelog/release-notes.md";

	@Override
	public void apply(Project project) {
		createRepository(project);
		createChangelogGeneratorConfiguration(project);
		project.getTasks().register("generateChangelog", JavaExec.class, new Action<JavaExec>() {
			@Override
			public void execute(JavaExec generateChangelog) {
				File outputFile = project.file(Paths.get(project.getBuildDir().getPath(), RELEASE_NOTES_PATH));
				outputFile.getParentFile().mkdirs();
				generateChangelog.setGroup("Release");
				generateChangelog.setDescription("Generates the changelog");
				generateChangelog.setWorkingDir(project.getRootDir());
				generateChangelog.classpath(project.getConfigurations().getAt(CHANGELOG_GENERATOR_CONFIGURATION_NAME));
				generateChangelog.doFirst(new Action<Task>() {
					@Override
					public void execute(Task task) {
						generateChangelog.args("--spring.config.location=scripts/release/release-notes-sections.yml", project.property("nextVersion"), outputFile.toString());
					}
				});
			}
		});
	}

	private void createChangelogGeneratorConfiguration(Project project) {
		project.getConfigurations().create(CHANGELOG_GENERATOR_CONFIGURATION_NAME, new Action<Configuration>() {
			@Override
			public void execute(Configuration configuration) {
				configuration.defaultDependencies(new Action<DependencySet>() {
					@Override
					public void execute(DependencySet dependencies) {
						dependencies.add(project.getDependencies().create("spring-io:github-changelog-generator:0.0.6"));
					}
				});
			}
		});
	}

	private void createRepository(Project project) {
		IvyArtifactRepository repository = project.getRepositories().ivy(new Action<IvyArtifactRepository>() {
			@Override
			public void execute(IvyArtifactRepository repository) {
				repository.setUrl("https://github.com/");
				repository.patternLayout(new Action<IvyPatternRepositoryLayout>() {
					@Override
					public void execute(IvyPatternRepositoryLayout layout) {
						layout.artifact("[organization]/[artifact]/releases/download/v[revision]/[artifact].[ext]");
					}
				});
				repository.getMetadataSources().artifact();
			}
		});
		project.getRepositories().exclusiveContent(new Action<ExclusiveContentRepository>() {
			@Override
			public void execute(ExclusiveContentRepository exclusiveContentRepository) {
				exclusiveContentRepository.forRepositories(repository);
				exclusiveContentRepository.filter(new Action<InclusiveRepositoryContentDescriptor>() {
					@Override
					public void execute(InclusiveRepositoryContentDescriptor descriptor) {
						descriptor.includeGroup("spring-io");
					}
				});
			}
		});
	}
}

相关信息

spring security 源码目录

相关文章

spring security AclEntryVoter 源码

spring security AclPermissionCacheOptimizer 源码

spring security AclPermissionEvaluator 源码

spring security AbstractAclProvider 源码

spring security AclEntryAfterInvocationCollectionFilteringProvider 源码

spring security AclEntryAfterInvocationProvider 源码

spring security ArrayFilterer 源码

spring security CollectionFilterer 源码

spring security Filterer 源码

spring security package-info 源码

0  赞