mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Merge branch '3.1.x' into 3.2.x
Closes gh-40538
This commit is contained in:
commit
cfdb89fe0b
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2023 the original author or authors.
|
* Copyright 2012-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -20,15 +20,18 @@ import java.io.File;
|
|||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.gradle.api.DefaultTask;
|
import org.gradle.api.DefaultTask;
|
||||||
|
import org.gradle.api.Project;
|
||||||
import org.gradle.api.Task;
|
import org.gradle.api.Task;
|
||||||
import org.gradle.api.artifacts.Configuration;
|
import org.gradle.api.artifacts.Configuration;
|
||||||
import org.gradle.api.artifacts.ResolvedArtifact;
|
import org.gradle.api.artifacts.ResolvedArtifact;
|
||||||
import org.gradle.api.file.FileCollection;
|
import org.gradle.api.file.FileCollection;
|
||||||
|
import org.gradle.api.file.RegularFileProperty;
|
||||||
|
import org.gradle.api.provider.Property;
|
||||||
import org.gradle.api.tasks.Classpath;
|
import org.gradle.api.tasks.Classpath;
|
||||||
|
import org.gradle.api.tasks.Input;
|
||||||
import org.gradle.api.tasks.OutputFile;
|
import org.gradle.api.tasks.OutputFile;
|
||||||
import org.gradle.api.tasks.TaskAction;
|
import org.gradle.api.tasks.TaskAction;
|
||||||
|
|
||||||
@ -39,17 +42,22 @@ import org.springframework.core.CollectionFactory;
|
|||||||
*
|
*
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
*/
|
*/
|
||||||
public class StarterMetadata extends DefaultTask {
|
public abstract class StarterMetadata extends DefaultTask {
|
||||||
|
|
||||||
private Configuration dependencies;
|
private Configuration dependencies;
|
||||||
|
|
||||||
private File destination;
|
|
||||||
|
|
||||||
public StarterMetadata() {
|
public StarterMetadata() {
|
||||||
getInputs().property("name", (Callable<String>) () -> getProject().getName());
|
Project project = getProject();
|
||||||
getInputs().property("description", (Callable<String>) () -> getProject().getDescription());
|
getStarterName().convention(project.provider(project::getName));
|
||||||
|
getStarterDescription().convention(project.provider(project::getDescription));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Input
|
||||||
|
public abstract Property<String> getStarterName();
|
||||||
|
|
||||||
|
@Input
|
||||||
|
public abstract Property<String> getStarterDescription();
|
||||||
|
|
||||||
@Classpath
|
@Classpath
|
||||||
public FileCollection getDependencies() {
|
public FileCollection getDependencies() {
|
||||||
return this.dependencies;
|
return this.dependencies;
|
||||||
@ -60,19 +68,13 @@ public class StarterMetadata extends DefaultTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OutputFile
|
@OutputFile
|
||||||
public File getDestination() {
|
public abstract RegularFileProperty getDestination();
|
||||||
return this.destination;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDestination(File destination) {
|
|
||||||
this.destination = destination;
|
|
||||||
}
|
|
||||||
|
|
||||||
@TaskAction
|
@TaskAction
|
||||||
void generateMetadata() throws IOException {
|
void generateMetadata() throws IOException {
|
||||||
Properties properties = CollectionFactory.createSortedProperties(true);
|
Properties properties = CollectionFactory.createSortedProperties(true);
|
||||||
properties.setProperty("name", getProject().getName());
|
properties.setProperty("name", getStarterName().get());
|
||||||
properties.setProperty("description", getProject().getDescription());
|
properties.setProperty("description", getStarterDescription().get());
|
||||||
properties.setProperty("dependencies",
|
properties.setProperty("dependencies",
|
||||||
String.join(",",
|
String.join(",",
|
||||||
this.dependencies.getResolvedConfiguration()
|
this.dependencies.getResolvedConfiguration()
|
||||||
@ -80,8 +82,9 @@ public class StarterMetadata extends DefaultTask {
|
|||||||
.stream()
|
.stream()
|
||||||
.map(ResolvedArtifact::getName)
|
.map(ResolvedArtifact::getName)
|
||||||
.collect(Collectors.toSet())));
|
.collect(Collectors.toSet())));
|
||||||
this.destination.getParentFile().mkdirs();
|
File destination = getDestination().getAsFile().get();
|
||||||
try (FileWriter writer = new FileWriter(this.destination)) {
|
destination.getParentFile().mkdirs();
|
||||||
|
try (FileWriter writer = new FileWriter(destination)) {
|
||||||
properties.store(writer, null);
|
properties.store(writer, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2023 the original author or authors.
|
* Copyright 2012-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -57,7 +57,7 @@ public class StarterPlugin implements Plugin<Project> {
|
|||||||
Configuration runtimeClasspath = configurations.getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME);
|
Configuration runtimeClasspath = configurations.getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME);
|
||||||
starterMetadata.setDependencies(runtimeClasspath);
|
starterMetadata.setDependencies(runtimeClasspath);
|
||||||
File destination = new File(project.getBuildDir(), "starter-metadata.properties");
|
File destination = new File(project.getBuildDir(), "starter-metadata.properties");
|
||||||
starterMetadata.setDestination(destination);
|
starterMetadata.getDestination().set(destination);
|
||||||
configurations.create("starterMetadata");
|
configurations.create("starterMetadata");
|
||||||
project.getArtifacts()
|
project.getArtifacts()
|
||||||
.add("starterMetadata", project.provider(starterMetadata::getDestination),
|
.add("starterMetadata", project.provider(starterMetadata::getDestination),
|
||||||
|
Loading…
Reference in New Issue
Block a user