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