diff --git a/AGENTS.md b/AGENTS.md --- a/AGENTS.md +++ b/AGENTS.md @@ -10,6 +10,8 @@ - `find*` рассматривается как синоним legacy `get*` (поиск без `fail-fast`). - `require*` это `find*` + `fail-fast` с понятной ошибкой в месте вызова. - Для нового API предпочтительны формы `find/require`; новые `get*` по возможности не добавлять. +- Интерфейсы и классы, описывающие модели DSL должны иметь суффикс `Spec` у моделей описывающих уровень сервисов и состояние сценария сборки такого суффикса не должно быть. +- Модель расширения на уровне проекта должна иметь суффикс `Extension`. ### Документация diff --git a/variants/src/main/java/org/implab/gradle/variants/VariantArtifactsPlugin.java b/variants/src/main/java/org/implab/gradle/variants/VariantArtifactsPlugin.java new file mode 100644 --- /dev/null +++ b/variants/src/main/java/org/implab/gradle/variants/VariantArtifactsPlugin.java @@ -0,0 +1,29 @@ +package org.implab.gradle.variants; + +import org.gradle.api.Plugin; +import org.gradle.api.Project; +import org.implab.gradle.common.core.lang.Deferred; +import org.implab.gradle.variants.artifacts.VariantArtifactsContext; +import org.implab.gradle.variants.core.VariantsExtension; + +public abstract class VariantArtifactsPlugin implements Plugin { + + @Override + public void apply(Project target) { + var extensions = target.getExtensions(); + + // Apply the main VariantsPlugin to ensure the core variant model is available. + target.getPlugins().apply(VariantsPlugin.class); + // Access the VariantsExtension to configure variant sources. + var variantsExtension = extensions.getByType(VariantsExtension.class); + + var deferred = new Deferred(); + + variantsExtension.whenFinalized(variants -> { + + }); + + + } + +} diff --git a/variants/src/main/java/org/implab/gradle/variants/artifacts/ArtifactAssemblies.java b/variants/src/main/java/org/implab/gradle/variants/artifacts/ArtifactAssemblies.java new file mode 100644 --- /dev/null +++ b/variants/src/main/java/org/implab/gradle/variants/artifacts/ArtifactAssemblies.java @@ -0,0 +1,22 @@ +package org.implab.gradle.variants.artifacts; + +import org.eclipse.jdt.annotation.NonNullByDefault; + +/** + * Resolves stateful slot assemblies from cheap slot identities. + * + *

The returned assembly is a materialized build-model handle. It may expose lazy Gradle providers, but + * it is no longer an identity object suitable for replayable discovery. + */ +@NonNullByDefault +public interface ArtifactAssemblies { + /** + * Resolves the assembly for the given slot. + * + *

This call materializes the build-facing body of the slot from its identity. + * + * @param slot slot identity inside a variant outgoing contract + * @return assembly handle for the slot + */ + ArtifactAssembly resolveSlot(ArtifactSlot slot); +} diff --git a/variants/src/main/java/org/implab/gradle/variants/artifacts/ArtifactAssembly.java b/variants/src/main/java/org/implab/gradle/variants/artifacts/ArtifactAssembly.java new file mode 100644 --- /dev/null +++ b/variants/src/main/java/org/implab/gradle/variants/artifacts/ArtifactAssembly.java @@ -0,0 +1,32 @@ +package org.implab.gradle.variants.artifacts; + +import org.gradle.api.Task; +import org.gradle.api.file.FileSystemLocation; +import org.gradle.api.provider.Provider; +import org.gradle.api.tasks.TaskProvider; + +/** + * Materialized body of an {@link ArtifactSlot}. + * + *

An assembly is a stateful build object obtained on demand from + * {@link ArtifactAssemblies#resolveSlot(ArtifactSlot)}. It describes how the slot artifact is produced and + * where that single published artifact will appear. + */ +public interface ArtifactAssembly { + + /** + * Returns the published artifact produced for the slot. + * + *

A slot is expected to produce exactly one artifact represented by one file or one directory. + * + * @return provider of the produced artifact location + */ + Provider getArtifact(); + + /** + * Returns the task that assembles the slot artifact. + * + * @return provider of the assembly task + */ + TaskProvider getAssemblyTask(); +} diff --git a/variants/src/main/java/org/implab/gradle/variants/artifacts/ArtifactAssemblySpec.java b/variants/src/main/java/org/implab/gradle/variants/artifacts/ArtifactAssemblySpec.java new file mode 100644 --- /dev/null +++ b/variants/src/main/java/org/implab/gradle/variants/artifacts/ArtifactAssemblySpec.java @@ -0,0 +1,60 @@ +package org.implab.gradle.variants.artifacts; + +import org.gradle.api.Action; +import groovy.lang.Closure; +import org.implab.gradle.common.core.lang.Closures; + +/** + * DSL model describing how a slot artifact is assembled. + * + *

Selection rules declared here may refer to internal build topology such as roles, layers or units. + * Those selectors influence slot assembly only and do not become part of published artifact identity. + * + *

Regardless of the number of declared inputs, a slot is expected to materialize to a single published + * artifact. + */ +public interface ArtifactAssemblySpec { + /** + * Contributes direct input material to the slot assembly. + * + *

The resulting slot still represents one published artifact. + * + * @param artifact direct input notation understood by the implementation + */ + void from(Object artifact); + + /** + * Selects outputs from the whole variant scope. + * + * @param action output selection rule + */ + void fromVariant(Action action); + + default void fromVariant(Closure closure) { + fromVariant(Closures.action(closure)); + } + + /** + * Selects outputs from a role inside the current variant. + * + * @param roleName role name used only for assembly-time selection + * @param action output selection rule + */ + void fromRole(String roleName, Action action); + + default void fromRole(String roleName, Closure closure) { + fromRole(roleName, Closures.action(closure)); + } + + /** + * Selects outputs from a layer inside the current variant. + * + * @param layerName layer name used only for assembly-time selection + * @param action output selection rule + */ + void fromLayer(String layerName, Action action); + + default void fromLayer(String layerName, Closure closure) { + fromLayer(layerName, Closures.action(closure)); + } +} diff --git a/variants/src/main/java/org/implab/gradle/variants/artifacts/ArtifactSlot.java b/variants/src/main/java/org/implab/gradle/variants/artifacts/ArtifactSlot.java new file mode 100644 --- /dev/null +++ b/variants/src/main/java/org/implab/gradle/variants/artifacts/ArtifactSlot.java @@ -0,0 +1,14 @@ +package org.implab.gradle.variants.artifacts; + +import org.implab.gradle.variants.core.Variant; + +/** + * Identity of a published artifact slot inside a variant outgoing contract. + * + *

This is a cheap immutable identity object suitable for discovery and selection. Heavy build state is + * obtained separately through {@link ArtifactAssemblies}. + * + * @param variant variant owning the outgoing contract + * @param slot slot identity inside the variant + */ +public record ArtifactSlot(Variant variant, Slot slot) {} diff --git a/variants/src/main/java/org/implab/gradle/variants/artifacts/ArtifactSlotsView.java b/variants/src/main/java/org/implab/gradle/variants/artifacts/ArtifactSlotsView.java new file mode 100644 --- /dev/null +++ b/variants/src/main/java/org/implab/gradle/variants/artifacts/ArtifactSlotsView.java @@ -0,0 +1,48 @@ +package org.implab.gradle.variants.artifacts; + +import java.util.Optional; +import java.util.Set; + +import org.implab.gradle.variants.core.Variant; + +/** + * Finalized view of artifact slot identities. + * + *

This view exposes only cheap slot identities. Assemblies and publication state are resolved + * separately. + */ +public interface ArtifactSlotsView { + /** + * Returns all declared slot identities. + * + * @return all slots known to the finalized model + */ + Set getSlots(); + + /** + * Returns all slots declared for the given variant. + * + * @param variant variant identity + * @return slots declared for the variant + */ + Set getSlotsForVariant(Variant variant); + + /** + * Finds a slot by typed identities. + * + * @param variant variant identity + * @param slot slot identity inside the variant + * @return matching slot when present + */ + Optional findSlot(Variant variant, Slot slot); + + /** + * Requires a slot by typed identities. + * + * @param variant variant identity + * @param slot slot identity inside the variant + * @return matching slot + */ + ArtifactSlot requireSlot(Variant variant, Slot slot); + +} diff --git a/variants/src/main/java/org/implab/gradle/variants/artifacts/OutgoingArtifactSlotSpec.java b/variants/src/main/java/org/implab/gradle/variants/artifacts/OutgoingArtifactSlotSpec.java new file mode 100644 --- /dev/null +++ b/variants/src/main/java/org/implab/gradle/variants/artifacts/OutgoingArtifactSlotSpec.java @@ -0,0 +1,59 @@ +package org.implab.gradle.variants.artifacts; + +import org.gradle.api.Action; +import org.gradle.api.Task; +import org.gradle.api.attributes.AttributeContainer; +import groovy.lang.Closure; +import org.implab.gradle.common.core.lang.Closures; + +/** + * Materialized outgoing publication state of a single slot. + * + *

This type is a DSL facade to represent already created publication-facing state. Slot-specific + * publication tweaks should be applied here rather than through {@link OutgoingVariantSpec}, which + * is limited to the root outgoing configuration of the variant. + */ +public interface OutgoingArtifactSlotSpec { + /** + * Returns the published slot identity. + * + * @return slot identity + */ + ArtifactSlot getArtifactSlot(); + + /** + * Returns the assembly backing the published slot. + * + * @return slot assembly + */ + ArtifactAssembly getAssembly(); + + /** + * Returns whether this slot is the primary outgoing artifact set of the variant. + * + * @return {@code true} for the primary slot + */ + boolean isPrimary(); + + /** + * Configures the task producing the slot artifact. + * + * @param action task configuration action + */ + void assemblyTask(Action action); + + default void assemblyTask(Closure closure) { + assemblyTask(Closures.action(closure)); + } + + /** + * Configures attributes of this slot publication. + * + * @param action artifact attribute configuration action + */ + void artifactAttributes(Action action); + + default void artifactAttributes(Closure closure) { + artifactAttributes(Closures.action(closure)); + } +} diff --git a/variants/src/main/java/org/implab/gradle/variants/artifacts/OutgoingVariantSpec.java b/variants/src/main/java/org/implab/gradle/variants/artifacts/OutgoingVariantSpec.java new file mode 100644 --- /dev/null +++ b/variants/src/main/java/org/implab/gradle/variants/artifacts/OutgoingVariantSpec.java @@ -0,0 +1,43 @@ +package org.implab.gradle.variants.artifacts; + +import org.gradle.api.Action; +import org.gradle.api.artifacts.Configuration; +import org.implab.gradle.common.core.lang.Closures; +import org.implab.gradle.variants.core.Variant; + +import groovy.lang.Closure; + +/** + * Materialized root outgoing configuration of a variant. + * + *

This is a variant-level publication hook. Slot-specific publication state is exposed separately via + * {@link OutgoingArtifactSlotSpec}. + */ +public interface OutgoingVariantSpec { + /** + * Returns the variant whose outgoing configuration is represented here. + * + * @return variant identity + */ + Variant getVariant(); + + /** + * Returns the root consumable outgoing configuration of the variant. + * + * @return outgoing configuration + */ + Configuration getConfiguration(); + + /** + * Applies a configuration action to the root outgoing configuration. + * + * @param action configuration action + */ + default void configuration(Action action) { + action.execute(getConfiguration()); + } + + default void configuration(Closure closure) { + configuration(Closures.action(closure)); + } +} diff --git a/variants/src/main/java/org/implab/gradle/variants/artifacts/OutputSelectionSpec.java b/variants/src/main/java/org/implab/gradle/variants/artifacts/OutputSelectionSpec.java new file mode 100644 --- /dev/null +++ b/variants/src/main/java/org/implab/gradle/variants/artifacts/OutputSelectionSpec.java @@ -0,0 +1,24 @@ +package org.implab.gradle.variants.artifacts; + +/** + * DSL model for selecting named outputs from a chosen source scope. + * + *

The selected outputs are inputs to slot assembly. They do not create additional outgoing slots or + * affect slot identity. + */ +public interface OutputSelectionSpec { + /** + * Selects one named output. + * + * @param name output name + */ + void output(String name); + + /** + * Selects several named outputs. + * + * @param name first output name + * @param extra additional output names + */ + void output(String name, String... extra); +} diff --git a/variants/src/main/java/org/implab/gradle/variants/artifacts/Slot.java b/variants/src/main/java/org/implab/gradle/variants/artifacts/Slot.java new file mode 100644 --- /dev/null +++ b/variants/src/main/java/org/implab/gradle/variants/artifacts/Slot.java @@ -0,0 +1,12 @@ +package org.implab.gradle.variants.artifacts; + +import org.gradle.api.Named; + +/** + * Named identity of a slot inside a variant outgoing contract. + * + *

A slot does not identify a published artifact on its own. Combine it with a variant to obtain an + * {@link ArtifactSlot}. + */ +public interface Slot extends Named { +} diff --git a/variants/src/main/java/org/implab/gradle/variants/artifacts/VariantArtifactsConfiguration.java b/variants/src/main/java/org/implab/gradle/variants/artifacts/VariantArtifactsConfiguration.java new file mode 100644 --- /dev/null +++ b/variants/src/main/java/org/implab/gradle/variants/artifacts/VariantArtifactsConfiguration.java @@ -0,0 +1,28 @@ +package org.implab.gradle.variants.artifacts; + +import org.gradle.api.NamedDomainObjectContainer; +import org.gradle.api.NamedDomainObjectProvider; +import org.gradle.api.artifacts.Configuration; +import org.implab.gradle.variants.core.Variant; + +/** Описывает конфигурация варианта исходящей конфигурации */ +public interface VariantArtifactsConfiguration { + /** + * Исходный вариант для которого строится Outgoing конфигурация + */ + Variant getVariant(); + + /** + * Провайдер зарегистрированной конфигурации + */ + NamedDomainObjectProvider getOutgoingConfiguration(); + + /** + * Слоты конфигурации, данная коллекция живая, используется для + * получения информации об объявленных слотах, но эти слоты не + * обязаны быть сконфигурированы, т.е. это только Identity. + * + * @see {@link ArtifactSlot} + */ + NamedDomainObjectContainer getSlots(); +} diff --git a/variants/src/main/java/org/implab/gradle/variants/artifacts/VariantArtifactsContext.java b/variants/src/main/java/org/implab/gradle/variants/artifacts/VariantArtifactsContext.java new file mode 100644 --- /dev/null +++ b/variants/src/main/java/org/implab/gradle/variants/artifacts/VariantArtifactsContext.java @@ -0,0 +1,27 @@ +package org.implab.gradle.variants.artifacts; + +import java.util.Optional; + +import org.gradle.api.Action; +import org.implab.gradle.variants.core.Variant; +import org.implab.gradle.variants.core.VariantsView; + +/** + * Контекст работы с вариантами публикации, становится доступным после + * финализации модели вариантов. Фактически является живой моделью + */ +public interface VariantArtifactsContext { + + /** + * Зафиксированное представление о вариантах на основе которого адаптеры могут + * конфигурировать артефакты и исходящие конфигурации + */ + VariantsView getVariants(); + + void all(Action action); + + Optional findArtifacts(Variant variant); + + VariantArtifactsConfiguration requireArtifacts(Variant variant); + +} diff --git a/variants/src/main/java/org/implab/gradle/variants/artifacts/VariantArtifactsExtension.java b/variants/src/main/java/org/implab/gradle/variants/artifacts/VariantArtifactsExtension.java new file mode 100644 --- /dev/null +++ b/variants/src/main/java/org/implab/gradle/variants/artifacts/VariantArtifactsExtension.java @@ -0,0 +1,59 @@ +package org.implab.gradle.variants.artifacts; + +import org.gradle.api.Action; +import org.implab.gradle.common.core.lang.Closures; + +import groovy.lang.Closure; + +/** + * Project-level DSL entry point for declaring outgoing artifacts per variant. + * + *

A variant represents one external outgoing contract. Slots declared inside a variant represent + * artifact sets within that contract. One slot is expected to materialize to one published artifact. + */ +public interface VariantArtifactsExtension { + /** + * Configures artifact slots of the named variant. + * + * @param variantName variant name + * @param action variant artifact declaration + */ + void variant(String variantName, Action action); + + default void variant(String variantName, Closure closure) { + variant(variantName, Closures.action(closure)); + } + + /** + * Registers a callback invoked with the finalized artifact model. + * + * @param action finalized-model callback + */ + void whenFinalized(Action action); + + default void whenFinalized(Closure closure) { + whenFinalized(Closures.action(closure)); + } + + /** + * Registers a callback invoked for each materialized root outgoing configuration. + * + * @param action variant-level outgoing configuration callback + */ + void whenOutgoingVariant(Action action); + + default void whenOutgoingVariant(Closure closure) { + whenOutgoingVariant(Closures.action(closure)); + } + + /** + * Registers a callback invoked for each materialized outgoing slot publication. + * + * @param action slot-level outgoing publication callback + */ + void whenOutgoingSlot(Action action); + + default void whenOutgoingSlot(Closure closure) { + whenOutgoingSlot(Closures.action(closure)); + } +} diff --git a/variants/src/main/java/org/implab/gradle/variants/artifacts/VariantArtifactsSpec.java b/variants/src/main/java/org/implab/gradle/variants/artifacts/VariantArtifactsSpec.java new file mode 100644 --- /dev/null +++ b/variants/src/main/java/org/implab/gradle/variants/artifacts/VariantArtifactsSpec.java @@ -0,0 +1,40 @@ +package org.implab.gradle.variants.artifacts; + +import org.gradle.api.Action; +import groovy.lang.Closure; +import org.implab.gradle.common.core.lang.Closures; + +/** + * DSL model for declaring slots of a single variant. + * + *

The surrounding variant defines the external outgoing contract. Slots declared here define artifact + * sets within that contract. If a variant exposes more than one slot, one of them is expected to be the + * primary slot. + */ +public interface VariantArtifactsSpec { + /** + * Declares a non-primary slot of the current variant. + * + * @param name slot name + * @param action slot declaration + * @return slot identity + */ + Slot slot(String name, Action action); + + default Slot slot(String name, Closure closure) { + return slot(name, Closures.action(closure)); + } + + /** + * Declares the primary slot of the current variant. + * + * @param name slot name + * @param action slot declaration + * @return slot identity + */ + Slot primarySlot(String name, Action action); + + default Slot primarySlot(String name, Closure closure) { + return primarySlot(name, Closures.action(closure)); + } +} diff --git a/variants/src/main/java/org/implab/gradle/variants/artifacts/internal/DefaultVariantArtifactsContext.java b/variants/src/main/java/org/implab/gradle/variants/artifacts/internal/DefaultVariantArtifactsContext.java new file mode 100644 --- /dev/null +++ b/variants/src/main/java/org/implab/gradle/variants/artifacts/internal/DefaultVariantArtifactsContext.java @@ -0,0 +1,37 @@ +package org.implab.gradle.variants.artifacts.internal; + +import java.util.Optional; + +import org.gradle.api.Action; +import org.implab.gradle.variants.artifacts.VariantArtifactsConfiguration; +import org.implab.gradle.variants.artifacts.VariantArtifactsContext; +import org.implab.gradle.variants.core.Variant; +import org.implab.gradle.variants.core.VariantsView; + +public class DefaultVariantArtifactsContext implements VariantArtifactsContext { + + @Override + public VariantsView getVariants() { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'getVariants'"); + } + + @Override + public void all(Action action) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'all'"); + } + + @Override + public Optional findArtifacts(Variant variant) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'findArtifacts'"); + } + + @Override + public VariantArtifactsConfiguration requireArtifacts(Variant variant) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'requireArtifacts'"); + } + +} diff --git a/variants/src/main/java/org/implab/gradle/variants/artifacts/internal/VariantArtifactsRegistry.java b/variants/src/main/java/org/implab/gradle/variants/artifacts/internal/VariantArtifactsRegistry.java new file mode 100644 --- /dev/null +++ b/variants/src/main/java/org/implab/gradle/variants/artifacts/internal/VariantArtifactsRegistry.java @@ -0,0 +1,11 @@ +package org.implab.gradle.variants.artifacts.internal; + +import org.gradle.api.Action; +import org.implab.gradle.variants.artifacts.VariantArtifactsSpec; +import org.implab.gradle.variants.core.Variant; + +public class VariantArtifactsRegistry { + public void configureVariant(Variant variant, Action action) { + + } +} diff --git a/variants/src/main/java/org/implab/gradle/variants/artifacts/package-info.java b/variants/src/main/java/org/implab/gradle/variants/artifacts/package-info.java new file mode 100644 --- /dev/null +++ b/variants/src/main/java/org/implab/gradle/variants/artifacts/package-info.java @@ -0,0 +1,41 @@ +/** + * Variant-scoped outgoing artifacts. + * + *

This package models the external artifact contract of a project in terms of variant-local slots. + * A variant represents one outgoing contract, while a slot represents one artifact set inside that + * contract. + * + *

The model intentionally separates cheap identity objects from stateful build objects: + * + *

+ * + *

Each slot is expected to materialize to exactly one published artifact: either one file or one + * directory. Internal build topology such as roles may participate in slot assembly rules, but does not + * belong to external artifact identity. + * + *

Typical usage: + * + *

{@code
+ * variantArtifacts {
+ *     variant("browser") {
+ *         primarySlot("runtime") {
+ *             fromRole("main") { output("js") }
+ *         }
+ *         slot("sources") {
+ *             fromLayer("main") { output("sources") }
+ *         }
+ *     }
+ * }
+ * }
+ * + *

After finalization, slot identities can be observed through + * {@link org.implab.gradle.variants.artifacts.VariantArtifactsContext#getSlots()}, while slot bodies are + * obtained on demand through + * {@link org.implab.gradle.variants.artifacts.VariantArtifactsContext#getAssemblies()}. + */ +package org.implab.gradle.variants.artifacts; diff --git a/variants/src/main/java/org/implab/gradle/variants/sources/CompileUnitsView.java b/variants/src/main/java/org/implab/gradle/variants/sources/CompileUnitsView.java --- a/variants/src/main/java/org/implab/gradle/variants/sources/CompileUnitsView.java +++ b/variants/src/main/java/org/implab/gradle/variants/sources/CompileUnitsView.java @@ -64,7 +64,7 @@ public final class CompileUnitsView { .collect(Collectors.toUnmodifiableSet()); } - public CompileUnit getUnit(Variant variant, Layer layer) { + public CompileUnit requireUnit(Variant variant, Layer layer) { return findUnit(variant, layer) .orElseThrow(() -> new IllegalArgumentException( "Compile unit for variant '" + variant.getName() diff --git a/variants/src/test/java/org/implab/gradle/variants/VariantSourcesPluginFunctionalTest.java b/variants/src/test/java/org/implab/gradle/variants/VariantSourcesPluginFunctionalTest.java --- a/variants/src/test/java/org/implab/gradle/variants/VariantSourcesPluginFunctionalTest.java +++ b/variants/src/test/java/org/implab/gradle/variants/VariantSourcesPluginFunctionalTest.java @@ -36,7 +36,7 @@ class VariantSourcesPluginFunctionalTest def production = ctx.variants.roles.find { it.name == 'production' } def mainLayer = ctx.variants.layers.find { it.name == 'main' } def projection = ctx.roleProjections.getProjection(browser, production) - def unit = ctx.compileUnits.getUnit(browser, mainLayer) + def unit = ctx.compileUnits.requireUnit(browser, mainLayer) def left = ctx.sourceSets.getSourceSet(unit) def right = ctx.sourceSets.getSourceSet(unit) @@ -113,9 +113,9 @@ class VariantSourcesPluginFunctionalTest def mainLayer = ctx.variants.layers.find { it.name == 'main' } def testLayer = ctx.variants.layers.find { it.name == 'test' } - def browserMain = ctx.sourceSets.getSourceSet(ctx.compileUnits.getUnit(browser, mainLayer)).get() - def browserTest = ctx.sourceSets.getSourceSet(ctx.compileUnits.getUnit(browser, testLayer)).get() - def nodeMain = ctx.sourceSets.getSourceSet(ctx.compileUnits.getUnit(node, mainLayer)).get() + def browserMain = ctx.sourceSets.getSourceSet(ctx.compileUnits.requireUnit(browser, mainLayer)).get() + def browserTest = ctx.sourceSets.getSourceSet(ctx.compileUnits.requireUnit(browser, testLayer)).get() + def nodeMain = ctx.sourceSets.getSourceSet(ctx.compileUnits.requireUnit(node, mainLayer)).get() def bySourceSet = events.groupBy { it.split(':', 2)[1] } println("browserMain=" + bySourceSet[browserMain.name].collect { it.split(':', 2)[0] }.join(',')) @@ -149,7 +149,7 @@ class VariantSourcesPluginFunctionalTest variantSources.whenFinalized { ctx -> def browser = ctx.variants.variants.find { it.name == 'browser' } def mainLayer = ctx.variants.layers.find { it.name == 'main' } - def unit = ctx.compileUnits.getUnit(browser, mainLayer) + def unit = ctx.compileUnits.requireUnit(browser, mainLayer) ctx.sourceSets.getSourceSet(unit).get() variantSources.layer('main') { @@ -185,7 +185,7 @@ class VariantSourcesPluginFunctionalTest variantSources.whenFinalized { ctx -> def browser = ctx.variants.variants.find { it.name == 'browser' } def mainLayer = ctx.variants.layers.find { it.name == 'main' } - def unit = ctx.compileUnits.getUnit(browser, mainLayer) + def unit = ctx.compileUnits.requireUnit(browser, mainLayer) def sourceSet = ctx.sourceSets.getSourceSet(unit).get() variantSources.layer('main') { @@ -224,7 +224,7 @@ class VariantSourcesPluginFunctionalTest variantSources.whenFinalized { ctx -> def browser = ctx.variants.variants.find { it.name == 'browser' } def mainLayer = ctx.variants.layers.find { it.name == 'main' } - def unit = ctx.compileUnits.getUnit(browser, mainLayer) + def unit = ctx.compileUnits.requireUnit(browser, mainLayer) def sourceSet = ctx.sourceSets.getSourceSet(unit).get() variantSources.layer('main') { @@ -321,8 +321,8 @@ class VariantSourcesPluginFunctionalTest def variantBar = ctx.variants.layers.find { it.name == 'variantBar' } def bar = ctx.variants.layers.find { it.name == 'bar' } - def later = ctx.compileUnits.getUnit(fooVariant, bar) - def earlier = ctx.compileUnits.getUnit(foo, variantBar) + def later = ctx.compileUnits.requireUnit(fooVariant, bar) + def earlier = ctx.compileUnits.requireUnit(foo, variantBar) println("map1=" + later.variant().name + ":" + later.layer().name + "->" + ctx.sourceSets.getSourceSet(later).name) println("map2=" + earlier.variant().name + ":" + earlier.layer().name + "->" + ctx.sourceSets.getSourceSet(earlier).name) diff --git a/variants/src/test/java/org/implab/gradle/variants/sources/CompileUnitsViewTest.java b/variants/src/test/java/org/implab/gradle/variants/sources/CompileUnitsViewTest.java --- a/variants/src/test/java/org/implab/gradle/variants/sources/CompileUnitsViewTest.java +++ b/variants/src/test/java/org/implab/gradle/variants/sources/CompileUnitsViewTest.java @@ -33,8 +33,8 @@ class CompileUnitsViewTest { new VariantRoleLayer(browser, qa, test))); var units = CompileUnitsView.of(view); - var browserMain = units.getUnit(browser, main); - var browserTest = units.getUnit(browser, test); + var browserMain = units.requireUnit(browser, main); + var browserTest = units.requireUnit(browser, test); assertEquals(2, units.getUnits().size()); assertEquals(Set.of(browserMain, browserTest), units.getUnitsForVariant(browser)); @@ -59,7 +59,7 @@ class CompileUnitsViewTest { var units = CompileUnitsView.of(view); - var ex = assertThrows(IllegalArgumentException.class, () -> units.getUnit(browser, missing)); + var ex = assertThrows(IllegalArgumentException.class, () -> units.requireUnit(browser, missing)); assertTrue(ex.getMessage().contains("Compile unit for variant 'browser' and layer 'missing' not found")); }