##// END OF EJS Templates
variants: expose compile unit source set specs...
cin -
r58:a4138749793f default
parent child
Show More
@@ -0,0 +1,69
1 package org.implab.gradle.variants.sources;
2
3 import org.gradle.api.Action;
4 import org.implab.gradle.common.core.lang.Closures;
5 import org.implab.gradle.variants.core.Layer;
6 import org.implab.gradle.variants.core.Variant;
7
8 import groovy.lang.Closure;
9
10 /**
11 * Source-set materialization context for one compile unit.
12 *
13 * <p>This type keeps compile-unit identity next to the materialized
14 * {@link GenericSourceSet} without turning the selector DSL into a second
15 * source-set API. Use {@link #getCompileUnit()} for selection metadata and
16 * {@link #sourceSet(Action)} when the underlying source set body must be
17 * configured.
18 */
19 public interface CompileUnitSourceSetSpec {
20 /**
21 * Returns the compile unit represented by this source set.
22 *
23 * @return compile-unit identity
24 */
25 CompileUnit getCompileUnit();
26
27 /**
28 * Returns the variant part of the compile-unit identity.
29 *
30 * @return variant identity
31 */
32 default Variant getVariant() {
33 return getCompileUnit().variant();
34 }
35
36 /**
37 * Returns the layer part of the compile-unit identity.
38 *
39 * @return layer identity
40 */
41 default Layer getLayer() {
42 return getCompileUnit().layer();
43 }
44
45 /**
46 * Returns the materialized source set body.
47 *
48 * @return source set body
49 */
50 GenericSourceSet getSourceSet();
51
52 /**
53 * Configures the materialized source set body.
54 *
55 * @param action source set configuration action
56 */
57 default void sourceSet(Action<? super GenericSourceSet> action) {
58 action.execute(getSourceSet());
59 }
60
61 /**
62 * Configures the materialized source set body.
63 *
64 * @param closure source set configuration closure
65 */
66 default void sourceSet(Closure<?> closure) {
67 sourceSet(Closures.action(closure));
68 }
69 }
@@ -0,0 +1,25
1 package org.implab.gradle.variants.sources.internal;
2
3 import org.implab.gradle.variants.sources.CompileUnit;
4 import org.implab.gradle.variants.sources.CompileUnitSourceSetSpec;
5 import org.implab.gradle.variants.sources.GenericSourceSet;
6
7 class DefaultCompileUnitSourceSetSpec implements CompileUnitSourceSetSpec {
8 private final CompileUnit compileUnit;
9 private final GenericSourceSet sourceSet;
10
11 DefaultCompileUnitSourceSetSpec(CompileUnit compileUnit, GenericSourceSet sourceSet) {
12 this.compileUnit = compileUnit;
13 this.sourceSet = sourceSet;
14 }
15
16 @Override
17 public CompileUnit getCompileUnit() {
18 return compileUnit;
19 }
20
21 @Override
22 public GenericSourceSet getSourceSet() {
23 return sourceSet;
24 }
25 }
@@ -16,8 +16,8 import org.implab.gradle.variants.core.V
16 import org.implab.gradle.variants.core.VariantsExtension;
16 import org.implab.gradle.variants.core.VariantsExtension;
17 import org.implab.gradle.variants.core.VariantsView;
17 import org.implab.gradle.variants.core.VariantsView;
18 import org.implab.gradle.variants.sources.CompileUnit;
18 import org.implab.gradle.variants.sources.CompileUnit;
19 import org.implab.gradle.variants.sources.CompileUnitSourceSetSpec;
19 import org.implab.gradle.variants.sources.CompileUnitsView;
20 import org.implab.gradle.variants.sources.CompileUnitsView;
20 import org.implab.gradle.variants.sources.GenericSourceSet;
21 import org.implab.gradle.variants.sources.RoleProjectionsView;
21 import org.implab.gradle.variants.sources.RoleProjectionsView;
22 import org.implab.gradle.variants.sources.VariantSourcesContext;
22 import org.implab.gradle.variants.sources.VariantSourcesContext;
23 import org.implab.gradle.variants.sources.VariantSourcesExtension;
23 import org.implab.gradle.variants.sources.VariantSourcesExtension;
@@ -92,7 +92,7 public abstract class VariantSourcesPlug
92 }
92 }
93
93
94 @Override
94 @Override
95 public void variant(String variantName, Action<? super GenericSourceSet> action) {
95 public void variant(String variantName, Action<? super CompileUnitSourceSetSpec> action) {
96 Strings.argumentNotNullOrBlank(variantName, "variantName");
96 Strings.argumentNotNullOrBlank(variantName, "variantName");
97 Objects.requireNonNull(action, "action can't be null");
97 Objects.requireNonNull(action, "action can't be null");
98
98
@@ -102,7 +102,7 public abstract class VariantSourcesPlug
102 }
102 }
103
103
104 @Override
104 @Override
105 public void layer(String layerName, Action<? super GenericSourceSet> action) {
105 public void layer(String layerName, Action<? super CompileUnitSourceSetSpec> action) {
106 // protect external DSL
106 // protect external DSL
107 Strings.argumentNotNullOrBlank(layerName, "layerName");
107 Strings.argumentNotNullOrBlank(layerName, "layerName");
108 Objects.requireNonNull(action, "action can't be null");
108 Objects.requireNonNull(action, "action can't be null");
@@ -113,7 +113,7 public abstract class VariantSourcesPlug
113 }
113 }
114
114
115 @Override
115 @Override
116 public void unit(String variantName, String layerName, Action<? super GenericSourceSet> action) {
116 public void unit(String variantName, String layerName, Action<? super CompileUnitSourceSetSpec> action) {
117 Strings.argumentNotNullOrBlank(layerName, "layerName");
117 Strings.argumentNotNullOrBlank(layerName, "layerName");
118 Strings.argumentNotNullOrBlank(variantName, "variantName");
118 Strings.argumentNotNullOrBlank(variantName, "variantName");
119 Objects.requireNonNull(action, "action can't be null");
119 Objects.requireNonNull(action, "action can't be null");
@@ -122,6 +122,15 public abstract class VariantSourcesPlug
122
122
123 whenAvailable(ctx -> ctx.configureUnit(resolveCompileUnit(ctx, variantName, layerName), action));
123 whenAvailable(ctx -> ctx.configureUnit(resolveCompileUnit(ctx, variantName, layerName), action));
124 }
124 }
125
126 @Override
127 public void configureEach(Action<? super CompileUnitSourceSetSpec> action) {
128 Objects.requireNonNull(action, "action can't be null");
129
130 lateConfigurationPolicy.finalizePolicy();
131
132 whenAvailable(ctx -> ctx.configureEach(action));
133 }
125 };
134 };
126
135
127 extensions.add(VariantSourcesExtension.class, VARIANT_SOURCES_EXTENSION, variantSourcesExtension);
136 extensions.add(VariantSourcesExtension.class, VARIANT_SOURCES_EXTENSION, variantSourcesExtension);
@@ -26,10 +26,6 import org.gradle.api.file.ProjectLayout
26 import org.gradle.api.file.SourceDirectorySet;
26 import org.gradle.api.file.SourceDirectorySet;
27 import org.gradle.api.model.ObjectFactory;
27 import org.gradle.api.model.ObjectFactory;
28 import org.gradle.api.tasks.TaskProvider;
28 import org.gradle.api.tasks.TaskProvider;
29 import org.gradle.util.Configurable;
30 import org.implab.gradle.common.core.lang.Closures;
31
32 import groovy.lang.Closure;
33
29
34 /**
30 /**
35 * A configurable source set abstraction with named outputs.
31 * A configurable source set abstraction with named outputs.
@@ -50,8 +46,7 import groovy.lang.Closure;
50 * {@link InvalidUserDataException}.
46 * {@link InvalidUserDataException}.
51 * </p>
47 * </p>
52 */
48 */
53 public abstract class GenericSourceSet
49 public abstract class GenericSourceSet implements Named {
54 implements Named, Configurable<GenericSourceSet> {
55 private final String name;
50 private final String name;
56
51
57 private final NamedDomainObjectContainer<SourceDirectorySet> sourceDirectorySets;
52 private final NamedDomainObjectContainer<SourceDirectorySet> sourceDirectorySets;
@@ -172,16 +167,6 public abstract class GenericSourceSet
172 .builtBy(task);
167 .builtBy(task);
173 }
168 }
174
169
175 /**
176 * Applies a Groovy closure to this source set, enabling DSL-style
177 * configuration.
178 */
179 @Override
180 public GenericSourceSet configure(Closure configure) {
181 Closures.apply(configure, this);
182 return this;
183 }
184
185 private SourceDirectorySet createSourceDirectorySet(String name) {
170 private SourceDirectorySet createSourceDirectorySet(String name) {
186 return objects.sourceDirectorySet(name, name);
171 return objects.sourceDirectorySet(name, name);
187 }
172 }
@@ -35,7 +35,7 public interface VariantSourcesContext {
35 SourceSetMaterializer getSourceSets();
35 SourceSetMaterializer getSourceSets();
36
36
37 /**
37 /**
38 * Configures all GenericSourceSets produced from the given layer.
38 * Configures all source sets produced from the given layer.
39 *
39 *
40 * The action is applied:
40 * The action is applied:
41 * - to already materialized source sets of this layer
41 * - to already materialized source sets of this layer
@@ -52,10 +52,10 public interface VariantSourcesContext {
52 * @throws org.gradle.api.InvalidUserDataException if the layer is not part of
52 * @throws org.gradle.api.InvalidUserDataException if the layer is not part of
53 * the finalized variant model
53 * the finalized variant model
54 */
54 */
55 void configureLayer(Layer layer, Action<? super GenericSourceSet> action);
55 void configureLayer(Layer layer, Action<? super CompileUnitSourceSetSpec> action);
56
56
57 /**
57 /**
58 * Configures all GenericSourceSets produced from the given variant.
58 * Configures all source sets produced from the given variant.
59 *
59 *
60 * <p>Late application semantics for already materialized source sets are
60 * <p>Late application semantics for already materialized source sets are
61 * governed by
61 * governed by
@@ -64,10 +64,10 public interface VariantSourcesContext {
64 * @throws org.gradle.api.InvalidUserDataException if the variant is not part
64 * @throws org.gradle.api.InvalidUserDataException if the variant is not part
65 * of the finalized variant model
65 * of the finalized variant model
66 */
66 */
67 void configureVariant(Variant variant, Action<? super GenericSourceSet> action);
67 void configureVariant(Variant variant, Action<? super CompileUnitSourceSetSpec> action);
68
68
69 /**
69 /**
70 * Configures the GenericSourceSet produced from the given compile unit.
70 * Configures the source set produced from the given compile unit.
71 *
71 *
72 * <p>Late application semantics for already materialized source sets are
72 * <p>Late application semantics for already materialized source sets are
73 * governed by
73 * governed by
@@ -76,6 +76,18 public interface VariantSourcesContext {
76 * @throws org.gradle.api.InvalidUserDataException if the compile unit is not
76 * @throws org.gradle.api.InvalidUserDataException if the compile unit is not
77 * part of the finalized variant model
77 * part of the finalized variant model
78 */
78 */
79 void configureUnit(CompileUnit unit, Action<? super GenericSourceSet> action);
79 void configureUnit(CompileUnit unit, Action<? super CompileUnitSourceSetSpec> action);
80
81 /**
82 * Configures every source set materialized from the finalized compile-unit
83 * model.
84 *
85 * <p>This selector is applied before variant-, layer-, and unit-specific
86 * selectors.
87 *
88 * @throws org.gradle.api.InvalidUserDataException if late configuration is
89 * rejected by the selected policy
90 */
91 void configureEach(Action<? super CompileUnitSourceSetSpec> action);
80
92
81 }
93 }
@@ -10,7 +10,7 public interface VariantSourcesExtension
10
10
11 /**
11 /**
12 * Selects how selector rules behave when they target an already materialized
12 * Selects how selector rules behave when they target an already materialized
13 * {@link GenericSourceSet}.
13 * source set.
14 *
14 *
15 * <p>This policy is single-valued:
15 * <p>This policy is single-valued:
16 * <ul>
16 * <ul>
@@ -64,7 +64,7 public interface VariantSourcesExtension
64 * {@link #lateConfigurationPolicy(Action)} for the remaining extension
64 * {@link #lateConfigurationPolicy(Action)} for the remaining extension
65 * lifecycle.
65 * lifecycle.
66 */
66 */
67 void layer(String layerName, Action<? super GenericSourceSet> action);
67 void layer(String layerName, Action<? super CompileUnitSourceSetSpec> action);
68
68
69 default void layer(String layerName, Closure<?> closure) {
69 default void layer(String layerName, Closure<?> closure) {
70 layer(layerName, Closures.action(closure));
70 layer(layerName, Closures.action(closure));
@@ -77,7 +77,7 public interface VariantSourcesExtension
77 * {@link #lateConfigurationPolicy(Action)} for the remaining extension
77 * {@link #lateConfigurationPolicy(Action)} for the remaining extension
78 * lifecycle.
78 * lifecycle.
79 */
79 */
80 void variant(String variantName, Action<? super GenericSourceSet> action);
80 void variant(String variantName, Action<? super CompileUnitSourceSetSpec> action);
81
81
82 default void variant(String variantName, Closure<?> closure) {
82 default void variant(String variantName, Closure<?> closure) {
83 variant(variantName, Closures.action(closure));
83 variant(variantName, Closures.action(closure));
@@ -90,13 +90,27 public interface VariantSourcesExtension
90 * {@link #lateConfigurationPolicy(Action)} for the remaining extension
90 * {@link #lateConfigurationPolicy(Action)} for the remaining extension
91 * lifecycle.
91 * lifecycle.
92 */
92 */
93 void unit(String variantName, String layerName, Action<? super GenericSourceSet> action);
93 void unit(String variantName, String layerName, Action<? super CompileUnitSourceSetSpec> action);
94
94
95 default void unit(String variantName, String layerName, Closure<?> closure) {
95 default void unit(String variantName, String layerName, Closure<?> closure) {
96 unit(variantName, layerName, Closures.action(closure));
96 unit(variantName, layerName, Closures.action(closure));
97 }
97 }
98
98
99 /**
99 /**
100 * Registers a selector rule for every materialized compile-unit source set.
101 *
102 * <p>Registering the first selector rule fixes the selected
103 * {@link #lateConfigurationPolicy(Action)} for the remaining extension
104 * lifecycle. This selector is applied before variant-, layer-, and unit-specific
105 * selectors.
106 */
107 void configureEach(Action<? super CompileUnitSourceSetSpec> action);
108
109 default void configureEach(Closure<?> closure) {
110 configureEach(Closures.action(closure));
111 }
112
113 /**
100 * Invoked when the variants-derived source context becomes available.
114 * Invoked when the variants-derived source context becomes available.
101 *
115 *
102 * Replayable:
116 * Replayable:
@@ -9,6 +9,7 import org.implab.gradle.variants.core.L
9 import org.implab.gradle.variants.core.Variant;
9 import org.implab.gradle.variants.core.Variant;
10 import org.implab.gradle.variants.core.VariantsView;
10 import org.implab.gradle.variants.core.VariantsView;
11 import org.implab.gradle.variants.sources.CompileUnit;
11 import org.implab.gradle.variants.sources.CompileUnit;
12 import org.implab.gradle.variants.sources.CompileUnitSourceSetSpec;
12 import org.implab.gradle.variants.sources.CompileUnitsView;
13 import org.implab.gradle.variants.sources.CompileUnitsView;
13 import org.implab.gradle.variants.sources.GenericSourceSet;
14 import org.implab.gradle.variants.sources.GenericSourceSet;
14 import org.implab.gradle.variants.sources.RoleProjectionsView;
15 import org.implab.gradle.variants.sources.RoleProjectionsView;
@@ -62,26 +63,32 public class DefaultVariantSourcesContex
62 }
63 }
63
64
64 @Override
65 @Override
65 public void configureLayer(Layer layer, Action<? super GenericSourceSet> action) {
66 public void configureLayer(Layer layer, Action<? super CompileUnitSourceSetSpec> action) {
66 variantsView.assertLayer(layer);
67 variantsView.assertLayer(layer);
67 Objects.requireNonNull(action, "action can't be null");
68 Objects.requireNonNull(action, "action can't be null");
68 sourceSetConfigurationRegistry.addLayerAction(layer, action);
69 sourceSetConfigurationRegistry.addLayerAction(layer, action);
69 }
70 }
70
71
71 @Override
72 @Override
72 public void configureVariant(Variant variant, Action<? super GenericSourceSet> action) {
73 public void configureVariant(Variant variant, Action<? super CompileUnitSourceSetSpec> action) {
73 variantsView.assertVariant(variant);
74 variantsView.assertVariant(variant);
74 Objects.requireNonNull(action, "action can't be null");
75 Objects.requireNonNull(action, "action can't be null");
75 sourceSetConfigurationRegistry.addVariantAction(variant, action);
76 sourceSetConfigurationRegistry.addVariantAction(variant, action);
76 }
77 }
77
78
78 @Override
79 @Override
79 public void configureUnit(CompileUnit unit, Action<? super GenericSourceSet> action) {
80 public void configureUnit(CompileUnit unit, Action<? super CompileUnitSourceSetSpec> action) {
80 assertCompileUnit(unit);
81 assertCompileUnit(unit);
81 Objects.requireNonNull(action, "action can't be null");
82 Objects.requireNonNull(action, "action can't be null");
82 sourceSetConfigurationRegistry.addCompileUnitAction(unit, action);
83 sourceSetConfigurationRegistry.addCompileUnitAction(unit, action);
83 }
84 }
84
85
86 @Override
87 public void configureEach(Action<? super CompileUnitSourceSetSpec> action) {
88 Objects.requireNonNull(action, "action can't be null");
89 sourceSetConfigurationRegistry.addAction(action);
90 }
91
85 private void assertCompileUnit(CompileUnit unit) {
92 private void assertCompileUnit(CompileUnit unit) {
86 Objects.requireNonNull(unit, "unit can't be null");
93 Objects.requireNonNull(unit, "unit can't be null");
87 variantsView.assertVariant(unit.variant());
94 variantsView.assertVariant(unit.variant());
@@ -17,15 +17,17 import org.implab.gradle.common.core.lan
17 import org.implab.gradle.variants.core.Layer;
17 import org.implab.gradle.variants.core.Layer;
18 import org.implab.gradle.variants.core.Variant;
18 import org.implab.gradle.variants.core.Variant;
19 import org.implab.gradle.variants.sources.CompileUnit;
19 import org.implab.gradle.variants.sources.CompileUnit;
20 import org.implab.gradle.variants.sources.CompileUnitSourceSetSpec;
20 import org.implab.gradle.variants.sources.GenericSourceSet;
21 import org.implab.gradle.variants.sources.GenericSourceSet;
21
22
22 @NonNullByDefault
23 @NonNullByDefault
23 public class SourceSetConfigurationRegistry {
24 public class SourceSetConfigurationRegistry {
24 private static final Logger logger = Logging.getLogger(SourceSetConfigurationRegistry.class);
25 private static final Logger logger = Logging.getLogger(SourceSetConfigurationRegistry.class);
25
26
26 private final Map<Layer, ReplayableQueue<GenericSourceSet>> sourcesByLayer = new LinkedHashMap<>();
27 private final ReplayableQueue<CompileUnitSourceSetSpec> sources = new ReplayableQueue<>();
27 private final Map<Variant, ReplayableQueue<GenericSourceSet>> sourcesByVariant = new LinkedHashMap<>();
28 private final Map<Layer, ReplayableQueue<CompileUnitSourceSetSpec>> sourcesByLayer = new LinkedHashMap<>();
28 private final Map<CompileUnit, ReplayableQueue<GenericSourceSet>> sourcesByUnit = new LinkedHashMap<>();
29 private final Map<Variant, ReplayableQueue<CompileUnitSourceSetSpec>> sourcesByVariant = new LinkedHashMap<>();
30 private final Map<CompileUnit, ReplayableQueue<CompileUnitSourceSetSpec>> sourcesByUnit = new LinkedHashMap<>();
29
31
30 private final Supplier<LateConfigurationMode> lateConfigurationMode;
32 private final Supplier<LateConfigurationMode> lateConfigurationMode;
31
33
@@ -33,7 +35,14 public class SourceSetConfigurationRegis
33 this.lateConfigurationMode = lateConfigurationMode;
35 this.lateConfigurationMode = lateConfigurationMode;
34 }
36 }
35
37
36 public void addLayerAction(Layer layer, Action<? super GenericSourceSet> action) {
38 public void addAction(Action<? super CompileUnitSourceSetSpec> action) {
39 addToActions(
40 sources,
41 action,
42 "Source sets already materialized");
43 }
44
45 public void addLayerAction(Layer layer, Action<? super CompileUnitSourceSetSpec> action) {
37 addToActions(
46 addToActions(
38 sourcesByLayer.computeIfAbsent(layer, key -> new ReplayableQueue<>()),
47 sourcesByLayer.computeIfAbsent(layer, key -> new ReplayableQueue<>()),
39 action,
48 action,
@@ -42,7 +51,7 public class SourceSetConfigurationRegis
42 layer.getName()));
51 layer.getName()));
43 }
52 }
44
53
45 public void addVariantAction(Variant variant, Action<? super GenericSourceSet> action) {
54 public void addVariantAction(Variant variant, Action<? super CompileUnitSourceSetSpec> action) {
46 addToActions(
55 addToActions(
47 sourcesByVariant.computeIfAbsent(variant, key -> new ReplayableQueue<>()),
56 sourcesByVariant.computeIfAbsent(variant, key -> new ReplayableQueue<>()),
48 action,
57 action,
@@ -52,7 +61,7 public class SourceSetConfigurationRegis
52
61
53 }
62 }
54
63
55 public void addCompileUnitAction(CompileUnit unit, Action<? super GenericSourceSet> action) {
64 public void addCompileUnitAction(CompileUnit unit, Action<? super CompileUnitSourceSetSpec> action) {
56 addToActions(
65 addToActions(
57 sourcesByUnit.computeIfAbsent(unit, key -> new ReplayableQueue<>()),
66 sourcesByUnit.computeIfAbsent(unit, key -> new ReplayableQueue<>()),
58 action,
67 action,
@@ -63,18 +72,21 public class SourceSetConfigurationRegis
63 }
72 }
64
73
65 private void addToActions(
74 private void addToActions(
66 ReplayableQueue<GenericSourceSet> actions,
75 ReplayableQueue<CompileUnitSourceSetSpec> actions,
67 Action<? super GenericSourceSet> action,
76 Action<? super CompileUnitSourceSetSpec> action,
68 String assertMessage) {
77 String assertMessage) {
69 assertLazyConfiguration(actions.values(), assertMessage);
78 assertLazyConfiguration(actions.values(), assertMessage);
70 actions.forEach(action::execute);
79 actions.forEach(action::execute);
71 }
80 }
72
81
73 void assertLazyConfiguration(List<GenericSourceSet> sets, String message) {
82 void assertLazyConfiguration(List<CompileUnitSourceSetSpec> sets, String message) {
74 if (sets.size() == 0)
83 if (sets.size() == 0)
75 return;
84 return;
76
85
77 var names = sets.stream().map(Named::getName).collect(Collectors.joining(", "));
86 var names = sets.stream()
87 .map(CompileUnitSourceSetSpec::getSourceSet)
88 .map(Named::getName)
89 .collect(Collectors.joining(", "));
78
90
79 switch (lateConfigurationMode.get()) {
91 switch (lateConfigurationMode.get()) {
80 case FAIL:
92 case FAIL:
@@ -88,8 +100,10 public class SourceSetConfigurationRegis
88 }
100 }
89
101
90 public void applyConfiguration(CompileUnit unit, GenericSourceSet sourceSet) {
102 public void applyConfiguration(CompileUnit unit, GenericSourceSet sourceSet) {
91 sourcesByVariant.computeIfAbsent(unit.variant(), key -> new ReplayableQueue<>()).add(sourceSet);
103 var spec = new DefaultCompileUnitSourceSetSpec(unit, sourceSet);
92 sourcesByLayer.computeIfAbsent(unit.layer(), key -> new ReplayableQueue<>()).add(sourceSet);
104 sources.add(spec);
93 sourcesByUnit.computeIfAbsent(unit, key -> new ReplayableQueue<>()).add(sourceSet);
105 sourcesByVariant.computeIfAbsent(unit.variant(), key -> new ReplayableQueue<>()).add(spec);
106 sourcesByLayer.computeIfAbsent(unit.layer(), key -> new ReplayableQueue<>()).add(spec);
107 sourcesByUnit.computeIfAbsent(unit, key -> new ReplayableQueue<>()).add(spec);
94 }
108 }
95 }
109 }
@@ -197,12 +197,16 class VariantArtifactsPluginFunctionalTe
197
197
198 variantSources {
198 variantSources {
199 layer('mainBase') {
199 layer('mainBase') {
200 declareOutputs('js')
200 sourceSet {
201 registerOutput('js', layout.projectDirectory.file('inputs/base.js'))
201 declareOutputs('js')
202 registerOutput('js', layout.projectDirectory.file('inputs/base.js'))
203 }
202 }
204 }
203 layer('mainAmd') {
205 layer('mainAmd') {
204 declareOutputs('js')
206 sourceSet {
205 registerOutput('js', layout.projectDirectory.file('inputs/amd.js'))
207 declareOutputs('js')
208 registerOutput('js', layout.projectDirectory.file('inputs/amd.js'))
209 }
206 }
210 }
207 }
211 }
208
212
@@ -349,7 +353,9 class VariantArtifactsPluginFunctionalTe
349 }
353 }
350
354
351 variantSources.layer('main') {
355 variantSources.layer('main') {
352 declareOutputs('types')
356 sourceSet {
357 declareOutputs('types')
358 }
353 }
359 }
354
360
355 variantArtifacts {
361 variantArtifacts {
@@ -432,8 +438,10 class VariantArtifactsPluginFunctionalTe
432 }
438 }
433
439
434 variantSources.layer('main') {
440 variantSources.layer('main') {
435 declareOutputs('js')
441 sourceSet {
436 registerOutput('js', layout.projectDirectory.file('inputs/base.js'))
442 declareOutputs('js')
443 registerOutput('js', layout.projectDirectory.file('inputs/base.js'))
444 }
437 }
445 }
438
446
439 variantArtifacts {
447 variantArtifacts {
@@ -528,7 +536,9 class VariantArtifactsPluginFunctionalTe
528 }
536 }
529
537
530 variantSources.layer('main') {
538 variantSources.layer('main') {
531 declareOutputs('types', 'js')
539 sourceSet {
540 declareOutputs('types', 'js')
541 }
532 }
542 }
533
543
534 variantArtifacts {
544 variantArtifacts {
@@ -616,9 +626,11 class VariantArtifactsPluginFunctionalTe
616 }
626 }
617
627
618 variantSources.layer('main') {
628 variantSources.layer('main') {
619 declareOutputs('types', 'js')
629 sourceSet {
620 registerOutput('types', layout.projectDirectory.file('inputs/types.d.ts'))
630 declareOutputs('types', 'js')
621 registerOutput('js', layout.projectDirectory.file('inputs/index.js'))
631 registerOutput('types', layout.projectDirectory.file('inputs/types.d.ts'))
632 registerOutput('js', layout.projectDirectory.file('inputs/index.js'))
633 }
622 }
634 }
623
635
624 variantArtifacts {
636 variantArtifacts {
@@ -95,14 +95,18 class VariantSourcesPluginFunctionalTest
95 def events = []
95 def events = []
96
96
97 variantSources {
97 variantSources {
98 configureEach {
99 events << "all:" + sourceSet.name
100 events << "context:" + sourceSet.name + ":" + variant.name + ":" + layer.name
101 }
98 variant('browser') {
102 variant('browser') {
99 events << "variant:" + name
103 events << "variant:" + sourceSet.name
100 }
104 }
101 layer('main') {
105 layer('main') {
102 events << "layer:" + name
106 events << "layer:" + sourceSet.name
103 }
107 }
104 unit('browser', 'main') {
108 unit('browser', 'main') {
105 events << "unit:" + name
109 events << "unit:" + sourceSet.name
106 }
110 }
107 }
111 }
108
112
@@ -121,15 +125,17 class VariantSourcesPluginFunctionalTest
121 println("browserMain=" + bySourceSet[browserMain.name].collect { it.split(':', 2)[0] }.join(','))
125 println("browserMain=" + bySourceSet[browserMain.name].collect { it.split(':', 2)[0] }.join(','))
122 println("browserTest=" + bySourceSet[browserTest.name].collect { it.split(':', 2)[0] }.join(','))
126 println("browserTest=" + bySourceSet[browserTest.name].collect { it.split(':', 2)[0] }.join(','))
123 println("nodeMain=" + bySourceSet[nodeMain.name].collect { it.split(':', 2)[0] }.join(','))
127 println("nodeMain=" + bySourceSet[nodeMain.name].collect { it.split(':', 2)[0] }.join(','))
128 println("context=" + events.find { it.startsWith("context:" + browserMain.name + ":") })
124 }
129 }
125 }
130 }
126 """);
131 """);
127
132
128 BuildResult result = runner("help").build();
133 BuildResult result = runner("help").build();
129
134
130 assertTrue(result.getOutput().contains("browserMain=variant,layer,unit"));
135 assertTrue(result.getOutput().contains("browserMain=all,variant,layer,unit"));
131 assertTrue(result.getOutput().contains("browserTest=variant"));
136 assertTrue(result.getOutput().contains("browserTest=all,variant"));
132 assertTrue(result.getOutput().contains("nodeMain=layer"));
137 assertTrue(result.getOutput().contains("nodeMain=all,layer"));
138 assertTrue(result.getOutput().contains("context=context:browserMain:browser:main"));
133 }
139 }
134
140
135 @Test
141 @Test
@@ -153,7 +159,9 class VariantSourcesPluginFunctionalTest
153
159
154 ctx.sourceSets.getSourceSet(unit).get()
160 ctx.sourceSets.getSourceSet(unit).get()
155 variantSources.layer('main') {
161 variantSources.layer('main') {
156 declareOutputs('late')
162 sourceSet {
163 declareOutputs('late')
164 }
157 }
165 }
158 }
166 }
159 }
167 }
@@ -187,11 +195,13 class VariantSourcesPluginFunctionalTest
187 def mainLayer = ctx.variants.layers.find { it.name == 'main' }
195 def mainLayer = ctx.variants.layers.find { it.name == 'main' }
188 def unit = ctx.compileUnits.requireUnit(browser, mainLayer)
196 def unit = ctx.compileUnits.requireUnit(browser, mainLayer)
189
197
190 def sourceSet = ctx.sourceSets.getSourceSet(unit).get()
198 def unitSourceSet = ctx.sourceSets.getSourceSet(unit).get()
191 variantSources.layer('main') {
199 variantSources.layer('main') {
192 declareOutputs('late')
200 sourceSet {
201 declareOutputs('late')
202 }
193 }
203 }
194 sourceSet.output('late')
204 unitSourceSet.output('late')
195 println('lateAllowed=ok')
205 println('lateAllowed=ok')
196 }
206 }
197 }
207 }
@@ -226,11 +236,13 class VariantSourcesPluginFunctionalTest
226 def mainLayer = ctx.variants.layers.find { it.name == 'main' }
236 def mainLayer = ctx.variants.layers.find { it.name == 'main' }
227 def unit = ctx.compileUnits.requireUnit(browser, mainLayer)
237 def unit = ctx.compileUnits.requireUnit(browser, mainLayer)
228
238
229 def sourceSet = ctx.sourceSets.getSourceSet(unit).get()
239 def unitSourceSet = ctx.sourceSets.getSourceSet(unit).get()
230 variantSources.layer('main') {
240 variantSources.layer('main') {
231 declareOutputs('late')
241 sourceSet {
242 declareOutputs('late')
243 }
232 }
244 }
233 sourceSet.output('late')
245 unitSourceSet.output('late')
234 println('lateWarn=ok')
246 println('lateWarn=ok')
235 }
247 }
236 }
248 }
@@ -257,7 +269,9 class VariantSourcesPluginFunctionalTest
257
269
258 variantSources {
270 variantSources {
259 variant('browser') {
271 variant('browser') {
260 declareOutputs('js')
272 sourceSet {
273 declareOutputs('js')
274 }
261 }
275 }
262 lateConfigurationPolicy {
276 lateConfigurationPolicy {
263 allowLateConfiguration()
277 allowLateConfiguration()
@@ -351,7 +365,9 class VariantSourcesPluginFunctionalTest
351
365
352 variantSources {
366 variantSources {
353 variant('missing') {
367 variant('missing') {
354 declareOutputs('js')
368 sourceSet {
369 declareOutputs('js')
370 }
355 }
371 }
356 }
372 }
357 """);
373 """);
@@ -375,7 +391,9 class VariantSourcesPluginFunctionalTest
375 variantSources.whenAvailable { ctx ->
391 variantSources.whenAvailable { ctx ->
376 def missing = objects.named(org.implab.gradle.variants.core.Variant, 'missing')
392 def missing = objects.named(org.implab.gradle.variants.core.Variant, 'missing')
377 ctx.configureVariant(missing) {
393 ctx.configureVariant(missing) {
378 declareOutputs('js')
394 sourceSet {
395 declareOutputs('js')
396 }
379 }
397 }
380 }
398 }
381 """);
399 """);
@@ -398,7 +416,9 class VariantSourcesPluginFunctionalTest
398
416
399 variantSources {
417 variantSources {
400 layer('missing') {
418 layer('missing') {
401 declareOutputs('js')
419 sourceSet {
420 declareOutputs('js')
421 }
402 }
422 }
403 }
423 }
404 """);
424 """);
@@ -422,7 +442,9 class VariantSourcesPluginFunctionalTest
422 variantSources.whenAvailable { ctx ->
442 variantSources.whenAvailable { ctx ->
423 def missing = objects.named(org.implab.gradle.variants.core.Layer, 'missing')
443 def missing = objects.named(org.implab.gradle.variants.core.Layer, 'missing')
424 ctx.configureLayer(missing) {
444 ctx.configureLayer(missing) {
425 declareOutputs('js')
445 sourceSet {
446 declareOutputs('js')
447 }
426 }
448 }
427 }
449 }
428 """);
450 """);
@@ -446,7 +468,9 class VariantSourcesPluginFunctionalTest
446
468
447 variantSources {
469 variantSources {
448 unit('browser', 'test') {
470 unit('browser', 'test') {
449 declareOutputs('js')
471 sourceSet {
472 declareOutputs('js')
473 }
450 }
474 }
451 }
475 }
452 """);
476 """);
@@ -473,7 +497,9 class VariantSourcesPluginFunctionalTest
473 def testLayer = ctx.variants.layers.find { it.name == 'test' }
497 def testLayer = ctx.variants.layers.find { it.name == 'test' }
474 def unit = new org.implab.gradle.variants.sources.CompileUnit(browser, testLayer)
498 def unit = new org.implab.gradle.variants.sources.CompileUnit(browser, testLayer)
475 ctx.configureUnit(unit) {
499 ctx.configureUnit(unit) {
476 declareOutputs('js')
500 sourceSet {
501 declareOutputs('js')
502 }
477 }
503 }
478 }
504 }
479 """);
505 """);
General Comments 0
You need to be logged in to leave comments. Login now