| @@ -1,53 +1,19 | |||||
| 1 | package org.implab.gradle.common.sources; |
|
1 | package org.implab.gradle.common.sources; | |
| 2 |
|
2 | |||
| 3 | import org.eclipse.jdt.annotation.NonNullByDefault; |
|
3 | import org.eclipse.jdt.annotation.NonNullByDefault; | |
| 4 |
import org.gradle.api. |
|
4 | import org.gradle.api.Task; | |
| 5 | import org.gradle.api.file.ConfigurableFileCollection; |
|
5 | import org.gradle.api.file.ConfigurableFileCollection; | |
| 6 | import org.gradle.api.file.Directory; |
|
6 | import org.gradle.api.file.Directory; | |
| 7 | import org.gradle.api.file.FileCollection; |
|
|||
| 8 | import org.gradle.api.provider.Provider; |
|
7 | import org.gradle.api.provider.Provider; | |
| 9 | import org.gradle.api.tasks.Copy; |
|
|||
| 10 | import org.gradle.api.tasks.TaskProvider; |
|
8 | import org.gradle.api.tasks.TaskProvider; | |
| 11 |
|
9 | |||
| 12 | @NonNullByDefault |
|
10 | @NonNullByDefault | |
| 13 |
public final |
|
11 | public final record ArtifactAssembly( | |
| 14 | private final String name; |
|
|||
| 15 | private final ConfigurableFileCollection sources; |
|
|||
| 16 | private final ConfigurableFileCollection output; |
|
|||
| 17 | private final Provider<Directory> outputDirectory; |
|
|||
| 18 | private final TaskProvider<Copy> task; |
|
|||
| 19 |
|
||||
| 20 | ArtifactAssembly( |
|
|||
| 21 |
|
|
12 | String name, | |
| 22 | ConfigurableFileCollection sources, |
|
|||
| 23 |
|
|
13 | Provider<Directory> outputDirectory, | |
| 24 |
|
|
14 | TaskProvider<? extends Task> task, | |
| 25 |
|
|
15 | ConfigurableFileCollection output | |
| 26 | this.name = name; |
|
16 | ) { | |
| 27 | this.sources = sources; |
|
|||
| 28 | this.outputDirectory = outputDirectory; |
|
|||
| 29 | this.task = task; |
|
|||
| 30 | this.output = output; |
|
|||
| 31 | } |
|
|||
| 32 |
|
17 | |||
| 33 | @Override |
|
18 | }; | |
| 34 | public String getName() { |
|
|||
| 35 | return name; |
|
|||
| 36 | } |
|
|||
| 37 |
|
||||
| 38 | public ConfigurableFileCollection getSources() { |
|
|||
| 39 | return sources; |
|
|||
| 40 | } |
|
|||
| 41 |
|
19 | |||
| 42 | public FileCollection getOutput() { |
|
|||
| 43 | return output; |
|
|||
| 44 | } |
|
|||
| 45 |
|
||||
| 46 | public Provider<Directory> getOutputDirectory() { |
|
|||
| 47 | return outputDirectory; |
|
|||
| 48 | } |
|
|||
| 49 |
|
||||
| 50 | public TaskProvider<Copy> getTask() { |
|
|||
| 51 | return task; |
|
|||
| 52 | } |
|
|||
| 53 | } |
|
|||
| @@ -3,16 +3,19 package org.implab.gradle.common.sources | |||||
| 3 | import java.util.LinkedHashMap; |
|
3 | import java.util.LinkedHashMap; | |
| 4 | import java.util.Map; |
|
4 | import java.util.Map; | |
| 5 | import java.util.Optional; |
|
5 | import java.util.Optional; | |
|
|
6 | import java.util.function.Function; | |||
| 6 |
|
7 | |||
| 7 | import org.eclipse.jdt.annotation.NonNullByDefault; |
|
8 | import org.eclipse.jdt.annotation.NonNullByDefault; | |
| 8 | import org.gradle.api.Action; |
|
9 | import org.gradle.api.Action; | |
| 9 | import org.gradle.api.InvalidUserDataException; |
|
10 | import org.gradle.api.InvalidUserDataException; | |
|
|
11 | import org.gradle.api.Task; | |||
| 10 | import org.gradle.api.file.ConfigurableFileCollection; |
|
12 | import org.gradle.api.file.ConfigurableFileCollection; | |
| 11 | import org.gradle.api.file.Directory; |
|
13 | import org.gradle.api.file.Directory; | |
| 12 | import org.gradle.api.model.ObjectFactory; |
|
14 | import org.gradle.api.model.ObjectFactory; | |
| 13 | import org.gradle.api.provider.Provider; |
|
15 | import org.gradle.api.provider.Provider; | |
| 14 | import org.gradle.api.tasks.Copy; |
|
16 | import org.gradle.api.tasks.Copy; | |
| 15 | import org.gradle.api.tasks.TaskContainer; |
|
17 | import org.gradle.api.tasks.TaskContainer; | |
|
|
18 | import org.gradle.api.tasks.TaskProvider; | |||
| 16 | import org.gradle.language.base.plugins.LifecycleBasePlugin; |
|
19 | import org.gradle.language.base.plugins.LifecycleBasePlugin; | |
| 17 |
|
20 | |||
| 18 | @NonNullByDefault |
|
21 | @NonNullByDefault | |
| @@ -31,9 +34,6 public final class ArtifactAssemblyRegis | |||||
| 31 | String taskName, |
|
34 | String taskName, | |
| 32 | Provider<Directory> outputDirectory, |
|
35 | Provider<Directory> outputDirectory, | |
| 33 | Action<? super ConfigurableFileCollection> configureSources) { |
|
36 | Action<? super ConfigurableFileCollection> configureSources) { | |
| 34 | if (assemblies.containsKey(name)) { |
|
|||
| 35 | throw new InvalidUserDataException("Artifact assembly '" + name + "' is already registered"); |
|
|||
| 36 | } |
|
|||
| 37 |
|
37 | |||
| 38 | var sources = objects.fileCollection(); |
|
38 | var sources = objects.fileCollection(); | |
| 39 | configureSources.execute(sources); |
|
39 | configureSources.execute(sources); | |
| @@ -44,11 +44,23 public final class ArtifactAssemblyRegis | |||||
| 44 | copy.from(sources); |
|
44 | copy.from(sources); | |
| 45 | }); |
|
45 | }); | |
| 46 |
|
46 | |||
|
|
47 | return register(name, task, t -> outputDirectory); | |||
|
|
48 | } | |||
|
|
49 | ||||
|
|
50 | public <T extends Task> ArtifactAssembly register( | |||
|
|
51 | String name, | |||
|
|
52 | TaskProvider<T> task, | |||
|
|
53 | Function<? super T, ? extends Provider<Directory>> mapOutputDirectory) { | |||
|
|
54 | if (assemblies.containsKey(name)) { | |||
|
|
55 | throw new InvalidUserDataException("Artifact assembly '" + name + "' is already registered"); | |||
|
|
56 | } | |||
|
|
57 | var outputDirectory = task.flatMap(t -> mapOutputDirectory.apply(t)); | |||
|
|
58 | ||||
| 47 | var output = objects.fileCollection() |
|
59 | var output = objects.fileCollection() | |
| 48 | .from(outputDirectory) |
|
60 | .from(outputDirectory) | |
| 49 | .builtBy(task); |
|
61 | .builtBy(task); | |
| 50 |
|
62 | |||
| 51 |
var assembly = new ArtifactAssembly(name, |
|
63 | var assembly = new ArtifactAssembly(name, outputDirectory, task, output); | |
| 52 | assemblies.put(name, assembly); |
|
64 | assemblies.put(name, assembly); | |
| 53 | return assembly; |
|
65 | return assembly; | |
| 54 | } |
|
66 | } | |
| @@ -11,6 +11,7 import java.util.Set; | |||||
| 11 | import java.util.concurrent.Callable; |
|
11 | import java.util.concurrent.Callable; | |
| 12 | import java.util.function.Function; |
|
12 | import java.util.function.Function; | |
| 13 | import java.util.stream.Collectors; |
|
13 | import java.util.stream.Collectors; | |
|
|
14 | import java.util.stream.Stream; | |||
| 14 |
|
15 | |||
| 15 | import javax.inject.Inject; |
|
16 | import javax.inject.Inject; | |
| 16 |
|
17 | |||
| @@ -148,9 +149,9 public abstract class GenericSourceSet | |||||
| 148 | * files under them. |
|
149 | * files under them. | |
| 149 | */ |
|
150 | */ | |
| 150 | public void declareOutputs(String name, String... extra) { |
|
151 | public void declareOutputs(String name, String... extra) { | |
| 151 | declaredOutputs.add(Objects.requireNonNull(name, "declareOutputs: The output name cannot be null")); |
|
152 | Stream.concat(Stream.of(name), Stream.of(extra)) | |
| 152 | for (var x : extra) |
|
153 | .map(Objects::requireNonNull) | |
| 153 | declaredOutputs.add(Objects.requireNonNull(x, "declareOutputs: The output name cannot be null")); |
|
154 | .forEach(declaredOutputs::add); | |
| 154 | } |
|
155 | } | |
| 155 |
|
156 | |||
| 156 | /** |
|
157 | /** | |
| @@ -2,6 +2,7 package org.implab.gradle.common.sources | |||||
| 2 |
|
2 | |||
| 3 | import org.eclipse.jdt.annotation.NonNullByDefault; |
|
3 | import org.eclipse.jdt.annotation.NonNullByDefault; | |
| 4 | import org.gradle.api.Action; |
|
4 | import org.gradle.api.Action; | |
|
|
5 | import org.gradle.api.Task; | |||
| 5 | import org.gradle.api.attributes.AttributeContainer; |
|
6 | import org.gradle.api.attributes.AttributeContainer; | |
| 6 | import org.gradle.api.attributes.HasConfigurableAttributes; |
|
7 | import org.gradle.api.attributes.HasConfigurableAttributes; | |
| 7 | import org.implab.gradle.common.core.lang.Closures; |
|
8 | import org.implab.gradle.common.core.lang.Closures; | |
| @@ -42,17 +43,13 public final class OutgoingArtifactSlotP | |||||
| 42 | return slot; |
|
43 | return slot; | |
| 43 | } |
|
44 | } | |
| 44 |
|
45 | |||
| 45 | public ArtifactAssembly assembly() { |
|
46 | public void configureTask(Action<? super Task> action) { | |
| 46 | return assembly; |
|
47 | assembly.task().configure(action::execute); | |
| 47 | } |
|
48 | } | |
| 48 |
|
49 | |||
| 49 | public void configureAssembly(Action<? super ArtifactAssembly> action) { |
|
50 | public void configureTask( | |
| 50 | action.execute(assembly); |
|
51 | @DelegatesTo(value = Task.class, strategy = Closure.DELEGATE_FIRST) Closure<?> action) { | |
| 51 | } |
|
52 | configureTask(Closures.action(action)); | |
| 52 |
|
||||
| 53 | public void configureAssembly( |
|
|||
| 54 | @DelegatesTo(value = ArtifactAssembly.class, strategy = Closure.DELEGATE_FIRST) Closure<?> action) { |
|
|||
| 55 | configureAssembly(Closures.action(action)); |
|
|||
| 56 | } |
|
53 | } | |
| 57 |
|
54 | |||
| 58 | public void configureArtifactAttributes(Action<? super AttributeContainer> action) { |
|
55 | public void configureArtifactAttributes(Action<? super AttributeContainer> action) { | |
| @@ -165,14 +165,14 public abstract class VariantArtifactsPl | |||||
| 165 | } |
|
165 | } | |
| 166 |
|
166 | |||
| 167 | private static void publishArtifact(ConfigurationPublications outgoing, ArtifactAssembly assembly) { |
|
167 | private static void publishArtifact(ConfigurationPublications outgoing, ArtifactAssembly assembly) { | |
| 168 |
outgoing.artifact(assembly. |
|
168 | outgoing.artifact(assembly.output().getSingleFile(), published -> { | |
| 169 |
published.builtBy(assembly. |
|
169 | published.builtBy(assembly.output().getBuildDependencies()); | |
| 170 | }); |
|
170 | }); | |
| 171 | } |
|
171 | } | |
| 172 |
|
172 | |||
| 173 | private static void publishArtifact(ConfigurationVariant variant, ArtifactAssembly assembly) { |
|
173 | private static void publishArtifact(ConfigurationVariant variant, ArtifactAssembly assembly) { | |
| 174 |
variant.artifact(assembly. |
|
174 | variant.artifact(assembly.output().getSingleFile(), published -> { | |
| 175 |
published.builtBy(assembly. |
|
175 | published.builtBy(assembly.output().getBuildDependencies()); | |
| 176 | }); |
|
176 | }); | |
| 177 | } |
|
177 | } | |
| 178 |
|
178 | |||
| @@ -96,8 +96,8 class VariantsArtifactsPluginFunctionalT | |||||
| 96 |
|
96 | |||
| 97 | whenOutgoingVariant { publication -> |
|
97 | whenOutgoingVariant { publication -> | |
| 98 | publication.slots().each { slotPublication -> |
|
98 | publication.slots().each { slotPublication -> | |
| 99 |
slotPublication.configure |
|
99 | slotPublication.configureTask { | |
| 100 |
|
|
100 | from(layout.projectDirectory.file("inputs/${slotPublication.slotName()}.txt")) | |
| 101 | } |
|
101 | } | |
| 102 |
|
102 | |||
| 103 | slotPublication.configureArtifactAttributes { |
|
103 | slotPublication.configureArtifactAttributes { | |
General Comments 0
You need to be logged in to leave comments.
Login now
