From d193636f8bcca7ca95d0d9bca2b73ad6cd1eee75 Mon Sep 17 00:00:00 2001 From: Yuri Sergiichuk Date: Wed, 30 Jan 2019 16:08:03 +0200 Subject: [PATCH 01/16] Drop `(enrichment)` option --- .../code/proto/ref/EnrichmentOption.java | 59 ------------------- base/src/main/proto/spine/options.proto | 49 +-------------- .../enrichment/EnrichmentMapBuilder.java | 16 ----- .../tools/compiler/enrichment/TypeRefs.java | 35 +++-------- .../compiler/enrichment/TypeRefsTest.java | 2 +- 5 files changed, 11 insertions(+), 150 deletions(-) delete mode 100644 base/src/main/java/io/spine/code/proto/ref/EnrichmentOption.java diff --git a/base/src/main/java/io/spine/code/proto/ref/EnrichmentOption.java b/base/src/main/java/io/spine/code/proto/ref/EnrichmentOption.java deleted file mode 100644 index 5d4b2a3b2d..0000000000 --- a/base/src/main/java/io/spine/code/proto/ref/EnrichmentOption.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2019, TeamDev. All rights reserved. - * - * Redistribution and use in source and/or binary forms, with or without - * modification, must retain the above copyright notice and the following - * disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package io.spine.code.proto.ref; - -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableList; -import com.google.protobuf.DescriptorProtos.DescriptorProto; - -import java.util.Optional; - -import static io.spine.option.Options.option; -import static io.spine.option.OptionsProto.enrichment; - -/** - * Parses {@code (enrichment)} option value of a message type which can reference its expected - * enrichments. - * - * @deprecated use {@code (enrichment_for)} option for defining enrichments instead - */ -@Deprecated -public class EnrichmentOption { - - private static final Splitter splitter = Splitter.on(','); - - /** Prevents instantiation of this utility class. */ - private EnrichmentOption() { - } - - /** - * Parses the option, which may have comman-separated values. - */ - public static ImmutableList parse(DescriptorProto message) { - Optional value = option(message, enrichment); - if (!value.isPresent()) { - return ImmutableList.of(); - } - - Iterable parts = splitter.split(value.get()); - return ImmutableList.copyOf(parts); - } -} diff --git a/base/src/main/proto/spine/options.proto b/base/src/main/proto/spine/options.proto index b573a3135a..b6051047fb 100644 --- a/base/src/main/proto/spine/options.proto +++ b/base/src/main/proto/spine/options.proto @@ -187,12 +187,6 @@ extend google.protobuf.FieldOptions { // // message MyEvent { // spine.base.UserId user_id = 1; - // ... - // message Enrichment { - // spine.people.PersonName name = 1 [(by) = "user_id"]; - // - // string time = 2 [(by) = "context.timestamp"]; - // } // } // // message MyEventEnrichment { @@ -208,23 +202,9 @@ extend google.protobuf.FieldOptions { // string username = 1 [(by) = "*.user_id"]; // } // - // message EventOne { - // option (enrichment) = "EnrichmentForSeveralEvents"; - // - // int32 user_id = 1; - // } - // - // message EventTwo { - // option (enrichment) = "EnrichmentForSeveralEvents"; - // - // int32 user_id = 1; - // } - // // Also, the multiple arguments are supported. The syntax is: // // message EnrichmentForSeveralEvents { - // option (enrichment) = "EnrichmentForSeveralEvents"; - // // int32 user_id = 1 [(by) = "qualifier.One.target_field | qualifier.Two.alternate_target_field"]; // } // @@ -394,34 +374,7 @@ extend google.protobuf.MessageOptions { // string enrichment_for = 73922; - // An instruction to enrich an event with one or more enrichments. - // - // This option is defined in event messages. - // If more than one enrichment should be added, their type names should be separated with - // the comma. For example: - // - // message MyEvent { - // option (enrichment) = "EnrichmentOne," - // "EnrichmentTwo"; - // ... - // } - // - // Fields of the referenced enrichment types refer to the fields of the event message via - // `by` option. Therefore, if `enrichment` option is used in more than event message, the fields - // participating in the enrichment process must have the same names. - // - // In the enrichment message a wildcard `by` option syntax may be used to reference more than - // a single target events to enrich. - // - // For example: - // - // message EnrichmentForSeveralEvents { - // string username = 1 [(by) = "*.user_id"]; - // } - // - string enrichment = 73923; - - // reserved 73924 to 73939 for future options. + // reserved 73923 to 73939 for future options. // Command Options //------------------- diff --git a/tools/model-compiler/src/main/java/io/spine/tools/compiler/enrichment/EnrichmentMapBuilder.java b/tools/model-compiler/src/main/java/io/spine/tools/compiler/enrichment/EnrichmentMapBuilder.java index 9f0e40be9e..f932f623b5 100644 --- a/tools/model-compiler/src/main/java/io/spine/tools/compiler/enrichment/EnrichmentMapBuilder.java +++ b/tools/model-compiler/src/main/java/io/spine/tools/compiler/enrichment/EnrichmentMapBuilder.java @@ -37,8 +37,6 @@ import java.util.Set; import static io.spine.tools.compiler.enrichment.TypeRefs.enrichmentForOption; -import static io.spine.tools.compiler.enrichment.TypeRefs.enrichmentOption; - /** * Composes enrichment map for multiple message declarations. */ @@ -51,7 +49,6 @@ final class EnrichmentMapBuilder implements Logging { private final String packagePrefix; private final TypeRefs enrichmentForOption; - private final TypeRefs enrichmentOption; /** Multimap for storing intermediate results. */ private final HashMultimap multimap = HashMultimap.create(); @@ -59,7 +56,6 @@ final class EnrichmentMapBuilder implements Logging { EnrichmentMapBuilder(String packagePrefix) { this.packagePrefix = packagePrefix; this.enrichmentForOption = enrichmentForOption(packagePrefix); - this.enrichmentOption = enrichmentOption(packagePrefix); } /** @@ -163,18 +159,6 @@ private Map scanMsg(DescriptorProto msg) { _debug("No target events found"); } - // Treating current {@code msg} as a target for enrichment (e.g. Spine event). - _debug("Scanning message {} for the enrichment target annotations", messageName); - Collection enrichmentTypes = enrichmentOption.parse(msg); - if (!enrichmentTypes.isEmpty()) { - _debug("Found enrichments for event {}: {}", messageName, enrichmentTypes); - for (String enrichmentType : enrichmentTypes) { - result.put(enrichmentType, messageName); - } - } else { - _debug("No enrichments for event {} found", messageName); - } - return result.build(); } diff --git a/tools/model-compiler/src/main/java/io/spine/tools/compiler/enrichment/TypeRefs.java b/tools/model-compiler/src/main/java/io/spine/tools/compiler/enrichment/TypeRefs.java index 5e8ba41ba7..a4a6376be2 100644 --- a/tools/model-compiler/src/main/java/io/spine/tools/compiler/enrichment/TypeRefs.java +++ b/tools/model-compiler/src/main/java/io/spine/tools/compiler/enrichment/TypeRefs.java @@ -25,7 +25,6 @@ import com.google.protobuf.DescriptorProtos.DescriptorProto; import io.spine.code.proto.ref.DirectTypeRef; import io.spine.code.proto.ref.EnrichmentForOption; -import io.spine.code.proto.ref.EnrichmentOption; import io.spine.code.proto.ref.TypeRef; import io.spine.option.OptionsProto; @@ -39,13 +38,6 @@ */ final class TypeRefs { - /** - * If {@code true} the parses would analyze {@code (enrichment_for)}, - * otherwise the {@code (enrichment)} option. Please not that the latter is deprecated - * and this field and the related code should be eliminated. - */ - private final boolean forOption; - /** * The prefix to be added to a reference if it's not a fully-qualified one. */ @@ -55,18 +47,10 @@ final class TypeRefs { * Obtains the parser for the {@link OptionsProto#enrichmentFor} option values. */ static TypeRefs enrichmentForOption(String packagePrefix) { - return new TypeRefs(true, packagePrefix); - } - - /** - * Obtains the instance for the {@link OptionsProto#enrichment} option values. - */ - static TypeRefs enrichmentOption(String packagePrefix) { - return new TypeRefs(false, packagePrefix); + return new TypeRefs(packagePrefix); } - private TypeRefs(boolean forOption, String packagePrefix) { - this.forOption = forOption; + private TypeRefs(String packagePrefix) { this.packagePrefix = packagePrefix; } @@ -75,18 +59,17 @@ private TypeRefs(boolean forOption, String packagePrefix) { * *

If a type name is not fully-qualified, the {@code packagePrefix} is added to it. * - * @param descriptor the descriptor to parse + * @param descriptor + * the descriptor to parse * @return the list of parsed type references or an empty list if the option is absent or empty */ ImmutableList parse(DescriptorProto descriptor) { - List parts = forOption - ? EnrichmentForOption.parse(descriptor) - : EnrichmentOption.parse(descriptor); + List parts = EnrichmentForOption.parse(descriptor); ImmutableList result = - parts .stream() - .map(this::toQualified) - .sorted(naturalOrder()) - .collect(toImmutableList()); + parts.stream() + .map(this::toQualified) + .sorted(naturalOrder()) + .collect(toImmutableList()); return result; } diff --git a/tools/model-compiler/src/test/java/io/spine/tools/compiler/enrichment/TypeRefsTest.java b/tools/model-compiler/src/test/java/io/spine/tools/compiler/enrichment/TypeRefsTest.java index 826923d980..ea1941e910 100644 --- a/tools/model-compiler/src/test/java/io/spine/tools/compiler/enrichment/TypeRefsTest.java +++ b/tools/model-compiler/src/test/java/io/spine/tools/compiler/enrichment/TypeRefsTest.java @@ -36,7 +36,7 @@ class TypeRefsTest { private static final String PACKAGE_PREFIX = "foo.bar."; private static final String MESSAGE_NAME = "AMessage"; - private final TypeRefs parser = TypeRefs.enrichmentOption(PACKAGE_PREFIX); + private final TypeRefs parser = TypeRefs.enrichmentForOption(PACKAGE_PREFIX); @Test @DisplayName("add package prefix to unqualified type") From e7775d716c94a6848eb799bdf097829969bdd77b Mon Sep 17 00:00:00 2001 From: Yuri Sergiichuk Date: Mon, 4 Feb 2019 12:26:17 +0200 Subject: [PATCH 02/16] Upgrade config sub-module version --- .idea/inspectionProfiles/Project_Default.xml | 11 +++++++---- .idea/misc.xml | 8 ++------ config | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index 8e7366802d..e0d0680058 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -401,13 +401,13 @@