Merge branch '3.2.x'

Closes gh-40539
This commit is contained in:
Andy Wilkinson 2024-04-26 15:58:55 +01:00
commit 7d1c244ba1
2 changed files with 23 additions and 20 deletions

View File

@ -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");
* 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.IOException;
import java.util.Properties;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;
import org.gradle.api.DefaultTask;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ResolvedArtifact;
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.Input;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;
@ -39,17 +42,22 @@ import org.springframework.core.CollectionFactory;
*
* @author Andy Wilkinson
*/
public class StarterMetadata extends DefaultTask {
public abstract class StarterMetadata extends DefaultTask {
private Configuration dependencies;
private File destination;
public StarterMetadata() {
getInputs().property("name", (Callable<String>) () -> getProject().getName());
getInputs().property("description", (Callable<String>) () -> getProject().getDescription());
Project project = getProject();
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
public FileCollection getDependencies() {
return this.dependencies;
@ -60,19 +68,13 @@ public class StarterMetadata extends DefaultTask {
}
@OutputFile
public File getDestination() {
return this.destination;
}
public void setDestination(File destination) {
this.destination = destination;
}
public abstract RegularFileProperty getDestination();
@TaskAction
void generateMetadata() throws IOException {
Properties properties = CollectionFactory.createSortedProperties(true);
properties.setProperty("name", getProject().getName());
properties.setProperty("description", getProject().getDescription());
properties.setProperty("name", getStarterName().get());
properties.setProperty("description", getStarterDescription().get());
properties.setProperty("dependencies",
String.join(",",
this.dependencies.getResolvedConfiguration()
@ -80,8 +82,9 @@ public class StarterMetadata extends DefaultTask {
.stream()
.map(ResolvedArtifact::getName)
.collect(Collectors.toSet())));
this.destination.getParentFile().mkdirs();
try (FileWriter writer = new FileWriter(this.destination)) {
File destination = getDestination().getAsFile().get();
destination.getParentFile().mkdirs();
try (FileWriter writer = new FileWriter(destination)) {
properties.store(writer, null);
}
}

View File

@ -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");
* 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);
starterMetadata.setDependencies(runtimeClasspath);
File destination = new File(project.getBuildDir(), "starter-metadata.properties");
starterMetadata.setDestination(destination);
starterMetadata.getDestination().set(destination);
configurations.create("starterMetadata");
project.getArtifacts()
.add("starterMetadata", project.provider(starterMetadata::getDestination),