##// END OF EJS Templates
variants: enforce source configuration policies
cin -
r54:3469331e3c4b default
parent child
Show More
@@ -54,6 +54,7 public abstract class VariantSourcesPlug
54 54
55 55 // create registries
56 56 var sourceSetRegistry = new SourceSetRegistry(objectFactory);
57 lateConfigurationPolicy.finalizePolicy();
57 58 var sourceSetConfiguration = new SourceSetConfigurationRegistry(lateConfigurationPolicy::mode);
58 59
59 60 // build compile unit namer
@@ -131,14 +132,14 public abstract class VariantSourcesPlug
131 132 return variants.getLayers().stream()
132 133 .filter(named(name))
133 134 .findAny()
134 .orElseThrow(() -> new IllegalArgumentException("Layer '" + name + "' isn't declared"));
135 .orElseThrow(() -> new InvalidUserDataException("Layer '" + name + "' isn't declared"));
135 136 }
136 137
137 138 private static Variant resolveVariant(VariantsView variants, String name) {
138 139 return variants.getVariants().stream()
139 140 .filter(named(name))
140 141 .findAny()
141 .orElseThrow(() -> new IllegalArgumentException("Variant '" + name + "' is't declared"));
142 .orElseThrow(() -> new InvalidUserDataException("Variant '" + name + "' isn't declared"));
142 143 }
143 144
144 145 private static CompileUnit resolveCompileUnit(VariantSourcesContext ctx, String variantName, String layerName) {
@@ -17,7 +17,10 public interface VariantSourcesExtension
17 17 * <li>it must be selected before the first selector rule is registered via
18 18 * {@link #variant(String, Action)}, {@link #layer(String, Action)} or
19 19 * {@link #unit(String, String, Action)};</li>
20 * <li>once selected, it cannot be changed later;</li>
20 * <li>it must be selected before the finalized context becomes observable via
21 * {@link #whenFinalized(Action)};</li>
22 * <li>once selected or once the finalized context is being created, it cannot
23 * be changed later;</li>
21 24 * <li>the policy controls both diagnostics and late-application semantics.</li>
22 25 * </ul>
23 26 *
@@ -8,6 +8,7 public class DefaultLateConfigurationPol
8 8 private boolean policyApplied = false;
9 9
10 10 public LateConfigurationMode mode() {
11 finalizePolicy();
11 12 return policyMode;
12 13 }
13 14
@@ -356,7 +356,7 class VariantSourcesPluginFunctionalTest
356 356 }
357 357 """);
358 358
359 assertBuildFails("Variant 'missing' is't declared", "help");
359 assertBuildFails("Variant 'missing' isn't declared", "help");
360 360 }
361 361
362 362 @Test
@@ -428,4 +428,27 class VariantSourcesPluginFunctionalTest
428 428
429 429 assertBuildFails("Naming policy already applied", "help");
430 430 }
431
432 @Test
433 void rejectsChangingLateConfigurationPolicyAfterContextBecomesObservable() throws Exception {
434 writeSettings("variant-sources-late-policy-context-fixed");
435 writeBuildFile("""
436 apply plugin: org.implab.gradle.variants.VariantSourcesPlugin
437
438 def variantsExt = extensions.getByType(org.implab.gradle.variants.core.VariantsExtension)
439 variantsExt.layers.create('main')
440 variantsExt.roles.create('production')
441 variantsExt.variant('browser') {
442 role('production') { layers('main') }
443 }
444
445 variantSources.whenFinalized {
446 variantSources.lateConfigurationPolicy {
447 allowLateConfiguration()
448 }
449 }
450 """);
451
452 assertBuildFails("Lazy configuration policy already applied", "help");
453 }
431 454 }
General Comments 0
You need to be logged in to leave comments. Login now