diff --git a/config b/config index 17e0dbb819..0bca88448a 160000 --- a/config +++ b/config @@ -1 +1 @@ -Subproject commit 17e0dbb819839d9b65b711efb085b38bcbb5eae9 +Subproject commit 0bca88448a18cde81f83ead25dfbd36a364aa7c0 diff --git a/dependencies.md b/dependencies.md index cb14dd4906..c5ca424b08 100644 --- a/dependencies.md +++ b/dependencies.md @@ -1,6 +1,6 @@ -# Dependencies of `io.spine.tools:validation-context:2.0.0-SNAPSHOT.402` +# Dependencies of `io.spine.tools:validation-context:2.0.0-SNAPSHOT.403` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.20.0. @@ -1139,14 +1139,14 @@ The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Mar 10 16:36:37 WET 2026** using +This report was generated on **Wed Mar 11 21:28:46 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:validation-context-tests:2.0.0-SNAPSHOT.402` +# Dependencies of `io.spine.tools:validation-context-tests:2.0.0-SNAPSHOT.403` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.20.0. @@ -1743,7 +1743,7 @@ This report was generated on **Tue Mar 10 16:36:37 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Mar 10 16:36:37 WET 2026** using +This report was generated on **Wed Mar 11 21:28:46 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). @@ -1764,7 +1764,7 @@ This report was generated on **Fri Mar 06 18:16:01 WET 2026** using -# Dependencies of `io.spine.tools:validation-gradle-plugin:2.0.0-SNAPSHOT.402` +# Dependencies of `io.spine.tools:validation-gradle-plugin:2.0.0-SNAPSHOT.403` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.20.0. @@ -2853,14 +2853,14 @@ This report was generated on **Fri Mar 06 18:16:01 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Mar 10 16:36:37 WET 2026** using +This report was generated on **Wed Mar 11 21:28:46 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:validation-java:2.0.0-SNAPSHOT.402` +# Dependencies of `io.spine.tools:validation-java:2.0.0-SNAPSHOT.403` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.20.0. @@ -3939,14 +3939,14 @@ This report was generated on **Tue Mar 10 16:36:37 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Mar 10 16:36:37 WET 2026** using +This report was generated on **Wed Mar 11 21:28:46 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:validation-java-bundle:2.0.0-SNAPSHOT.402` +# Dependencies of `io.spine.tools:validation-java-bundle:2.0.0-SNAPSHOT.403` ## Runtime 1. **Group** : org.jetbrains. **Name** : annotations. **Version** : 13.0. @@ -3993,14 +3993,14 @@ This report was generated on **Tue Mar 10 16:36:37 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Mar 10 16:36:36 WET 2026** using +This report was generated on **Wed Mar 11 21:28:45 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine:validation-jvm-runtime:2.0.0-SNAPSHOT.402` +# Dependencies of `io.spine:validation-jvm-runtime:2.0.0-SNAPSHOT.403` ## Runtime 1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2. @@ -4833,14 +4833,14 @@ This report was generated on **Tue Mar 10 16:36:36 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Mar 10 16:36:37 WET 2026** using +This report was generated on **Wed Mar 11 21:28:46 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:validation-consumer:2.0.0-SNAPSHOT.402` +# Dependencies of `io.spine.tools:validation-consumer:2.0.0-SNAPSHOT.403` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.20.0. @@ -5423,14 +5423,14 @@ This report was generated on **Tue Mar 10 16:36:37 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Mar 10 16:36:37 WET 2026** using +This report was generated on **Wed Mar 11 21:28:46 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:validation-consumer-dependency:2.0.0-SNAPSHOT.402` +# Dependencies of `io.spine.tools:validation-consumer-dependency:2.0.0-SNAPSHOT.403` ## Runtime 1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2. @@ -5941,14 +5941,14 @@ This report was generated on **Tue Mar 10 16:36:37 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Mar 10 16:36:37 WET 2026** using +This report was generated on **Wed Mar 11 21:28:46 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:validation-extensions:2.0.0-SNAPSHOT.402` +# Dependencies of `io.spine.tools:validation-extensions:2.0.0-SNAPSHOT.403` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.20.0. @@ -6628,14 +6628,14 @@ This report was generated on **Tue Mar 10 16:36:37 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Mar 10 16:36:37 WET 2026** using +This report was generated on **Wed Mar 11 21:28:46 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:validation-runtime:2.0.0-SNAPSHOT.402` +# Dependencies of `io.spine.tools:validation-runtime:2.0.0-SNAPSHOT.403` ## Runtime 1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2. @@ -7257,14 +7257,14 @@ This report was generated on **Tue Mar 10 16:36:37 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Mar 10 16:36:37 WET 2026** using +This report was generated on **Wed Mar 11 21:28:46 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:validation-validating:2.0.0-SNAPSHOT.402` +# Dependencies of `io.spine.tools:validation-validating:2.0.0-SNAPSHOT.403` ## Runtime 1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2. @@ -7929,14 +7929,14 @@ This report was generated on **Tue Mar 10 16:36:37 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Mar 10 16:36:37 WET 2026** using +This report was generated on **Wed Mar 11 21:28:46 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:validation-validator:2.0.0-SNAPSHOT.402` +# Dependencies of `io.spine.tools:validation-validator:2.0.0-SNAPSHOT.403` ## Runtime 1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.20.0. @@ -8719,14 +8719,14 @@ This report was generated on **Tue Mar 10 16:36:37 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Mar 10 16:36:37 WET 2026** using +This report was generated on **Wed Mar 11 21:28:46 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:validation-validator-dependency:2.0.0-SNAPSHOT.402` +# Dependencies of `io.spine.tools:validation-validator-dependency:2.0.0-SNAPSHOT.403` ## Runtime 1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2. @@ -8996,14 +8996,14 @@ This report was generated on **Tue Mar 10 16:36:37 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Mar 10 16:36:37 WET 2026** using +This report was generated on **Wed Mar 11 21:28:46 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine.tools:validation-vanilla:2.0.0-SNAPSHOT.402` +# Dependencies of `io.spine.tools:validation-vanilla:2.0.0-SNAPSHOT.403` ## Runtime 1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2. @@ -9346,6 +9346,6 @@ This report was generated on **Tue Mar 10 16:36:37 WET 2026** using The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Tue Mar 10 16:36:37 WET 2026** using +This report was generated on **Wed Mar 11 21:28:46 WET 2026** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). \ No newline at end of file diff --git a/jvm-runtime/src/main/java/io/spine/validation/option/AlwaysRequired.java b/jvm-runtime/src/main/java/io/spine/validation/option/AlwaysRequired.java new file mode 100644 index 0000000000..8034d28279 --- /dev/null +++ b/jvm-runtime/src/main/java/io/spine/validation/option/AlwaysRequired.java @@ -0,0 +1,59 @@ +/* + * Copyright 2025, TeamDev. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.validation.option; + +import com.google.errorprone.annotations.Immutable; +import io.spine.code.proto.FieldContext; + +/** + * A special case of {@code Required} option that assumes that the option is present regardless + * of the actual field declaration. + * + * @deprecated Please use generated validation code. + */ +@Immutable +@Deprecated(forRemoval = true) +final class AlwaysRequired extends Required { + + /** + * Creates a new instance of this option. + */ + AlwaysRequired() { + super(); + } + + /** + * {@inheritDoc} + * + *
For {@code AlwaysRequired}, validation happens every time. + */ + @Override + public boolean shouldValidate(FieldContext context) { + checkUsage(context.targetDeclaration()); + return true; + } +} diff --git a/jvm-runtime/src/main/java/io/spine/validation/option/FieldValidatingOption.java b/jvm-runtime/src/main/java/io/spine/validation/option/FieldValidatingOption.java new file mode 100644 index 0000000000..42fd830498 --- /dev/null +++ b/jvm-runtime/src/main/java/io/spine/validation/option/FieldValidatingOption.java @@ -0,0 +1,116 @@ +/* + * Copyright 2025, TeamDev. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * 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.validation.option; + +import com.google.errorprone.annotations.Immutable; +import com.google.errorprone.annotations.ImmutableTypeParameter; +import com.google.protobuf.DescriptorProtos.FieldOptions; +import com.google.protobuf.Descriptors.FieldDescriptor; +import com.google.protobuf.GeneratedMessage.GeneratedExtension; +import io.spine.code.proto.FieldContext; +import io.spine.code.proto.FieldOption; + +import java.util.Optional; + +import static java.lang.String.format; + +/** + * An option that validates a field. + * + *
Validating options impose constraint on fields that they are applied to.
+ *
+ * @param If a {@code required} field is missing, an error is produced.
+ *
+ * @deprecated Please use generated validation code.
+ */
+@Immutable
+@Deprecated(forRemoval = true)
+public class Required extends FieldValidatingOption If the specified parameter is {@code true}, a returned option always assumes a field to
+ * be {@code required}, regardless of the field value.
+ * If the specified parameter is {@code false}, a returned option checks the actual value.
+ *
+ * @param strict
+ * specifies if a field is assumed to be a required one regardless of the actual
+ * Protobuf option value
+ * @return a new instance of the {@code Required} option
+ */
+ public static Required create(boolean strict) {
+ return strict
+ ? new AlwaysRequired()
+ : new Required();
+ }
+
+ private boolean notAssumingRequired(FieldContext context) {
+ var defaultValue = context.targetDeclaration().isId();
+ return valueFrom(context.target())
+ .orElse(defaultValue);
+ }
+
+ @Override
+ public boolean shouldValidate(FieldContext context) {
+ return notAssumingRequired(context);
+ }
+
+ /**
+ * Produces warnings if the {@code required} option was applied incorrectly.
+ *
+ * Examples of incorrect application include attempting to apply the option to a numeric
+ * field.
+ *
+ * @param field
+ * a value that the option is applied to
+ */
+ @SuppressWarnings("UseOfSystemOutOrSystemErr") /* We're migrating off runtime validation
+ AND we do not want dependency of Validation Runtime on Spine Logging.
+ So we use `System.err` for the warnings. */
+ void checkUsage(FieldDeclaration field) {
+ var type = field.javaType();
+ if (!CAN_BE_REQUIRED.contains(type) && field.isNotCollection()) {
+ var isTheFirstField = field.descriptor().getIndex() == 0;
+ if (isTheFirstField) {
+ // The first field declared in a message type could be assumed as required
+ // because by convention it is an ID field of the message.
+ // If so, do not log the warning message for this field because ID fields
+ // could be of any reasonable type.
+ var messageClass = field.declaringType().javaClass();
+ if (CommandMessage.class.isAssignableFrom(messageClass)
+ || EntityState.class.isAssignableFrom(messageClass)) {
+ return;
+ }
+ }
+ var typeName = field.descriptor().getType().name();
+ System.err.printf(
+ "The field `%s.%s` has the type %s and" +
+ " should not be declared as `(required)`.%n",
+ field.declaringType().name(), field.name(), typeName);
+ }
+ }
+}
diff --git a/jvm-runtime/src/main/java/io/spine/validation/option/ValidatingOption.java b/jvm-runtime/src/main/java/io/spine/validation/option/ValidatingOption.java
new file mode 100644
index 0000000000..e67cccedb0
--- /dev/null
+++ b/jvm-runtime/src/main/java/io/spine/validation/option/ValidatingOption.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2025, TeamDev. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.validation.option;
+
+import com.google.errorprone.annotations.Immutable;
+import com.google.errorprone.annotations.ImmutableTypeParameter;
+import com.google.protobuf.Descriptors.GenericDescriptor;
+import io.spine.code.proto.Option;
+
+/**
+ * The interface common to all standard validation options.
+ *
+ * @param