diff --git a/base/src/main/java/io/spine/validate/MessageValidator.java b/base/src/main/java/io/spine/validate/MessageValidator.java index 9f19276c8c..9454aa8de5 100644 --- a/base/src/main/java/io/spine/validate/MessageValidator.java +++ b/base/src/main/java/io/spine/validate/MessageValidator.java @@ -28,7 +28,6 @@ import io.spine.code.proto.FieldContext; import io.spine.code.proto.FieldDeclaration; import io.spine.code.proto.FieldName; -import io.spine.option.PatternOption; import io.spine.type.MessageType; import io.spine.type.TypeName; import io.spine.validate.option.DistinctConstraint; @@ -45,6 +44,7 @@ import java.util.List; import java.util.Optional; import java.util.Set; +import java.util.regex.Matcher; import java.util.regex.Pattern; import static com.google.common.base.Preconditions.checkNotNull; @@ -106,11 +106,15 @@ public void visitRequired(RequiredConstraint constraint) { @Override public void visitPattern(PatternConstraint constraint) { FieldValue fieldValue = message.valueOf(constraint.field()); - PatternOption pattern = constraint.optionValue(); - String regex = pattern.getRegex(); - Pattern compiledPattern = Pattern.compile(regex); + String regex = constraint.regex(); + int flags = constraint.flagsMask(); + @SuppressWarnings("MagicConstant") + Pattern compiledPattern = Pattern.compile(regex, flags); + boolean partialMatch = constraint.allowsPartialMatch(); fieldValue.nonDefault() - .filter(value -> !compiledPattern.matcher((CharSequence) value).matches()) + .filter(value -> partialMatch + ? noPartialMatch(compiledPattern, (String) value) + : noCompleteMatch(compiledPattern, (String) value)) .map(value -> violation(constraint, fieldValue, value) .toBuilder() .addParam(regex) @@ -118,6 +122,16 @@ public void visitPattern(PatternConstraint constraint) { .forEach(violations::add); } + private static boolean noCompleteMatch(Pattern pattern, String value) { + Matcher matcher = pattern.matcher(value); + return !matcher.matches(); + } + + private static boolean noPartialMatch(Pattern pattern, String value) { + Matcher matcher = pattern.matcher(value); + return !matcher.find(); + } + @Override public void visitDistinct(DistinctConstraint constraint) { FieldValue fieldValue = message.valueOf(constraint.field()); diff --git a/base/src/main/java/io/spine/validate/option/PatternConstraint.java b/base/src/main/java/io/spine/validate/option/PatternConstraint.java index 5098effc39..691cf8dcba 100644 --- a/base/src/main/java/io/spine/validate/option/PatternConstraint.java +++ b/base/src/main/java/io/spine/validate/option/PatternConstraint.java @@ -24,9 +24,15 @@ import io.spine.code.proto.FieldContext; import io.spine.code.proto.FieldDeclaration; import io.spine.option.PatternOption; +import io.spine.option.PatternOption.Modifier; import io.spine.validate.ConstraintTranslator; import io.spine.validate.diags.ViolationText; +import static java.util.regex.Pattern.CASE_INSENSITIVE; +import static java.util.regex.Pattern.DOTALL; +import static java.util.regex.Pattern.MULTILINE; +import static java.util.regex.Pattern.UNICODE_CHARACTER_CLASS; + /** * A constraint, which when applied to a string field, checks whether that field matches the * specified pattern. @@ -48,4 +54,47 @@ public String errorMessage(FieldContext field) { public void accept(ConstraintTranslator visitor) { visitor.visitPattern(this); } + + /** + * Obtains the regular expression as a string. + */ + public String regex() { + return optionValue().getRegex(); + } + + /** + * Checks if the pattern allows a partial match. + * + *

If {@code true}, the whole string value does not have to match the regex, but only its + * substring. + */ + public boolean allowsPartialMatch() { + PatternOption option = optionValue(); + Modifier modifier = option.getModifier(); + return modifier.getPartialMatch(); + } + + /** + * Obtains the pattern modifiers as a bit mask for the {@link Pattern} flags. + * + *

If no modifiers are specified, returns {@code 0}. + */ + public int flagsMask() { + int result = 0; + PatternOption option = optionValue(); + Modifier modifier = option.getModifier(); + if (modifier.getDotAll()) { + result |= DOTALL; + } + if (modifier.getUnicode()) { + result |= UNICODE_CHARACTER_CLASS; + } + if (modifier.getCaseInsensitive()) { + result |= CASE_INSENSITIVE; + } + if (modifier.getMultiline()) { + result |= MULTILINE; + } + return result; + } } diff --git a/base/src/main/proto/spine/options.proto b/base/src/main/proto/spine/options.proto index 081743aea4..4324ed9127 100644 --- a/base/src/main/proto/spine/options.proto +++ b/base/src/main/proto/spine/options.proto @@ -615,10 +615,67 @@ message PatternOption { string regex = 1; // The regex flag. - int32 flag = 2; + // + // Has no effect. Use `modifier` instead. + // + int32 flag = 2 [deprecated = true]; + + // Modifiers for this pattern. + Modifier modifier = 4; // A user-defined validation error format message. string msg_format = 3; + + // Regular expression modifiers. + // + // These modifiers are specifically selected to be supported in many implementation platforms. + // + message Modifier { + + // Enables the dot (`.`) symbol to match all the characters. + // + // By default, the dot does not match line break characters. + // + // May also be known in some platforms as "single line" mode and be encoded with the `s` + // flag. + // + bool dot_all = 1; + + // Allows to ignore the case of the matched symbols. + // + // For example, this modifier is specified, string `ABC` would be a complete match for + // the regex `[a-z]+`. + // + // On some platforms may be represented by the `i` flag. + // + bool case_insensitive = 2; + + // Enables the `^` (caret) and `$` (dollar) signs to match a start and an end of a line + // instead of a start and an end of the whole expression. + // + // On some platforms may be represented by the `m` flag. + // + bool multiline = 3; + + // Enables matching the whole UTF-8 sequences, + // + // On some platforms may be represented by the `u` flag. + // + bool unicode = 4; + + // Allows the matched strings to contain a full match to the pattern and some other + // characters as well. + // + // By default, a string only matches a pattern if it is a full match, i.e. there are no + // unaccounted for leading and/or trailing characters. + // + // This modifier is usually not represented programming languages, as the control over + // weather to match an entire string or only its part is provided to the user by other + // language means. For example, in Java, this would be the difference between methods + // `matches()` and `find()` of the `java.util.regex.Matcher` class. + // + bool partial_match = 5; + } } // Specifies the message to show if a validated field happens to be invalid. diff --git a/base/src/test/java/io/spine/validate/ValidationOfConstraintTest.java b/base/src/test/java/io/spine/validate/ValidationOfConstraintTest.java index fc9b5694e1..9a833346d3 100644 --- a/base/src/test/java/io/spine/validate/ValidationOfConstraintTest.java +++ b/base/src/test/java/io/spine/validate/ValidationOfConstraintTest.java @@ -20,7 +20,6 @@ package io.spine.validate; -import com.google.common.truth.Truth; import com.google.protobuf.Message; import java.util.List; @@ -29,7 +28,6 @@ import static io.spine.validate.Validate.violationsOf; import static io.spine.validate.given.MessageValidatorTestEnv.assertFieldPathIs; import static java.lang.String.format; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; public abstract class ValidationOfConstraintTest { diff --git a/base/src/test/java/io/spine/validate/option/PatternTest.java b/base/src/test/java/io/spine/validate/option/PatternTest.java index 119727c8d1..b336ea5c46 100644 --- a/base/src/test/java/io/spine/validate/option/PatternTest.java +++ b/base/src/test/java/io/spine/validate/option/PatternTest.java @@ -21,6 +21,7 @@ package io.spine.validate.option; import com.google.protobuf.StringValue; +import io.spine.test.validate.AllThePatterns; import io.spine.test.validate.PatternStringFieldValue; import io.spine.test.validate.SimpleStringValue; import io.spine.test.validate.WithStringValue; @@ -84,6 +85,80 @@ void findOutThatStringDoesNotMatchExternalConstraint() { assertNotValid(msg); } + @Test + @DisplayName("validate with `case_insensitive` modifier") + void caseInsensitive() { + AllThePatterns message = AllThePatterns + .newBuilder() + .setLetters("AbC") + .buildPartial(); + assertValid(message); + + AllThePatterns invalid = AllThePatterns + .newBuilder() + .setLetters("12345") + .buildPartial(); + assertNotValid(invalid); + } + + @Test + @DisplayName("validate with `multiline` modifier") + void multiline() { + AllThePatterns message = AllThePatterns + .newBuilder() + .setManyLines("text" + System.lineSeparator() + "more text") + .buildPartial(); + assertValid(message); + + AllThePatterns invalid = AllThePatterns + .newBuilder() + .setManyLines("single line text") + .buildPartial(); + assertNotValid(invalid); + } + + @Test + @DisplayName("validate with `partial` modifier") + void partial() { + AllThePatterns message = AllThePatterns + .newBuilder() + .setPartial("Hello World!") + .buildPartial(); + assertValid(message); + + AllThePatterns invalid = AllThePatterns + .newBuilder() + .setPartial("123456") + .buildPartial(); + assertNotValid(invalid); + } + + @Test + @DisplayName("validate with `unicode` modifier") + void utf8() { + AllThePatterns message = AllThePatterns + .newBuilder() + .setUtf8("ґ") + .buildPartial(); + assertValid(message); + + AllThePatterns invalid = AllThePatterns + .newBuilder() + .setUtf8("\\\\") + .buildPartial(); + assertNotValid(invalid); + } + + @Test + @DisplayName("validate with `dot_all` modifier") + void dotAll() { + AllThePatterns message = AllThePatterns + .newBuilder() + .setDotAll("ab" + System.lineSeparator() + "cd") + .buildPartial(); + assertValid(message); + } + private static PatternStringFieldValue patternStringFor(String email) { return PatternStringFieldValue .newBuilder() diff --git a/base/src/test/proto/spine/test/validate/patterns.proto b/base/src/test/proto/spine/test/validate/patterns.proto new file mode 100644 index 0000000000..d679a1df77 --- /dev/null +++ b/base/src/test/proto/spine/test/validate/patterns.proto @@ -0,0 +1,38 @@ +syntax = "proto3"; + +package spine.test.validate; + +import "spine/options.proto"; + +option (type_url_prefix) = "type.spine.io"; +option java_package = "io.spine.test.validate"; +option java_outer_classname = "PatternsProto"; +option java_multiple_files = true; + +message AllThePatterns { + + string letters = 1 [ + (pattern).regex = "[a-z]+", + (pattern).modifier.case_insensitive = true + ]; + + string many_lines = 2 [ + (pattern).regex = ".+$\r?\n^.+", + (pattern).modifier.multiline = true + ]; + + string partial = 3 [ + (pattern).regex = "World", + (pattern).modifier.partial_match = true + ]; + + string utf8 = 4 [ + (pattern).regex = "[їґє]", + (pattern).modifier.unicode = true + ]; + + string dot_all = 5 [ + (pattern).regex = ".*", + (pattern).modifier.dot_all = true + ]; +} diff --git a/config b/config index 775a2ab45d..63701feb02 160000 --- a/config +++ b/config @@ -1 +1 @@ -Subproject commit 775a2ab45d841bee791aef56bddc773453feca7d +Subproject commit 63701feb02a70c6af1e50aa2f0ca812bdab3c233 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a2bf1313b8..a4b4429748 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/license-report.md b/license-report.md index 54c09913c9..45f7a4cd61 100644 --- a/license-report.md +++ b/license-report.md @@ -1,6 +1,6 @@ -# Dependencies of `io.spine:spine-base:1.5.1` +# Dependencies of `io.spine:spine-base:1.5.2` ## Runtime 1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2 @@ -330,12 +330,12 @@ The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Mar 12 11:36:50 EET 2020** 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). +This report was generated on **Thu Mar 26 14:09:23 EET 2020** 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:spine-errorprone-checks:1.5.1` +# Dependencies of `io.spine.tools:spine-errorprone-checks:1.5.2` ## Runtime 1. **Group:** com.github.ben-manes.caffeine **Name:** caffeine **Version:** 2.7.0 @@ -777,12 +777,12 @@ This report was generated on **Thu Mar 12 11:36:50 EET 2020** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Mar 12 11:36:51 EET 2020** 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). +This report was generated on **Thu Mar 26 14:09:24 EET 2020** 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:spine-javadoc-filter:1.5.1` +# Dependencies of `io.spine.tools:spine-javadoc-filter:1.5.2` ## Runtime 1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4 @@ -1170,12 +1170,12 @@ This report was generated on **Thu Mar 12 11:36:51 EET 2020** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Mar 12 11:36:51 EET 2020** 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). +This report was generated on **Thu Mar 26 14:09:25 EET 2020** 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:spine-javadoc-prettifier:1.5.1` +# Dependencies of `io.spine.tools:spine-javadoc-prettifier:1.5.2` ## Runtime 1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2 @@ -1537,12 +1537,12 @@ This report was generated on **Thu Mar 12 11:36:51 EET 2020** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Mar 12 11:36:52 EET 2020** 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). +This report was generated on **Thu Mar 26 14:09:25 EET 2020** 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:spine-model-compiler:1.5.1` +# Dependencies of `io.spine.tools:spine-model-compiler:1.5.2` ## Runtime 1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2 @@ -1920,12 +1920,12 @@ This report was generated on **Thu Mar 12 11:36:52 EET 2020** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Mar 12 11:36:52 EET 2020** 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). +This report was generated on **Thu Mar 26 14:09:26 EET 2020** 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:spine-mute-logging:1.5.1` +# Dependencies of `io.spine.tools:spine-mute-logging:1.5.2` ## Runtime 1. **Group:** com.google.auto.value **Name:** auto-value-annotations **Version:** 1.6.3 @@ -2305,12 +2305,12 @@ This report was generated on **Thu Mar 12 11:36:52 EET 2020** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Mar 12 11:36:52 EET 2020** 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). +This report was generated on **Thu Mar 26 14:09:27 EET 2020** 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:spine-plugin-base:1.5.1` +# Dependencies of `io.spine.tools:spine-plugin-base:1.5.2` ## Runtime 1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2 @@ -2672,12 +2672,12 @@ This report was generated on **Thu Mar 12 11:36:52 EET 2020** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Mar 12 11:36:53 EET 2020** 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). +This report was generated on **Thu Mar 26 14:09:27 EET 2020** 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:spine-plugin-testlib:1.5.1` +# Dependencies of `io.spine.tools:spine-plugin-testlib:1.5.2` ## Runtime 1. **Group:** com.google.auto.value **Name:** auto-value-annotations **Version:** 1.6.3 @@ -3097,12 +3097,12 @@ This report was generated on **Thu Mar 12 11:36:53 EET 2020** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Mar 12 11:36:53 EET 2020** 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). +This report was generated on **Thu Mar 26 14:09:28 EET 2020** 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:spine-proto-dart-plugin:1.5.1` +# Dependencies of `io.spine.tools:spine-proto-dart-plugin:1.5.2` ## Runtime 1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2 @@ -3464,12 +3464,12 @@ This report was generated on **Thu Mar 12 11:36:53 EET 2020** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Mar 12 11:36:53 EET 2020** 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). +This report was generated on **Thu Mar 26 14:09:28 EET 2020** 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:spine-proto-js-plugin:1.5.1` +# Dependencies of `io.spine.tools:spine-proto-js-plugin:1.5.2` ## Runtime 1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2 @@ -3831,12 +3831,12 @@ This report was generated on **Thu Mar 12 11:36:53 EET 2020** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Mar 12 11:36:54 EET 2020** 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). +This report was generated on **Thu Mar 26 14:09:29 EET 2020** 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:spine-protoc-api:1.5.1` +# Dependencies of `io.spine.tools:spine-protoc-api:1.5.2` ## Runtime 1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2 @@ -4158,12 +4158,12 @@ This report was generated on **Thu Mar 12 11:36:54 EET 2020** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Mar 12 11:36:54 EET 2020** 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). +This report was generated on **Thu Mar 26 14:09:29 EET 2020** 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:spine-protoc-plugin:1.5.1` +# Dependencies of `io.spine.tools:spine-protoc-plugin:1.5.2` ## Runtime 1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2 @@ -4493,12 +4493,12 @@ This report was generated on **Thu Mar 12 11:36:54 EET 2020** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Mar 12 11:36:54 EET 2020** 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). +This report was generated on **Thu Mar 26 14:09:30 EET 2020** 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:spine-testlib:1.5.1` +# Dependencies of `io.spine:spine-testlib:1.5.2` ## Runtime 1. **Group:** com.google.auto.value **Name:** auto-value-annotations **Version:** 1.6.3 @@ -4878,12 +4878,12 @@ This report was generated on **Thu Mar 12 11:36:54 EET 2020** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Mar 12 11:36:54 EET 2020** 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). +This report was generated on **Thu Mar 26 14:09:30 EET 2020** 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:spine-tool-base:1.5.1` +# Dependencies of `io.spine.tools:spine-tool-base:1.5.2` ## Runtime 1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2 @@ -5213,12 +5213,12 @@ This report was generated on **Thu Mar 12 11:36:54 EET 2020** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Mar 12 11:36:55 EET 2020** 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). +This report was generated on **Thu Mar 26 14:09:30 EET 2020** 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:spine-validation-generator:1.5.1` +# Dependencies of `io.spine.tools:spine-validation-generator:1.5.2` ## Runtime 1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2 @@ -5548,4 +5548,4 @@ This report was generated on **Thu Mar 12 11:36:55 EET 2020** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Thu Mar 12 11:36:55 EET 2020** 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 +This report was generated on **Thu Mar 26 14:09:31 EET 2020** 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/pom.xml b/pom.xml index dc02883fd6..e7e51490a1 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ all modules and does not describe the project structure per-subproject. io.spine spine-base -1.5.1 +1.5.2 2015 @@ -154,7 +154,7 @@ all modules and does not describe the project structure per-subproject. io.spine.tools spine-protoc-plugin - 1.5.1 + 1.5.2 test diff --git a/tools/model-compiler/src/main/java/io/spine/tools/gradle/compiler/ProtoModule.java b/tools/model-compiler/src/main/java/io/spine/tools/gradle/compiler/ProtoModule.java index fdf2f2ef68..2239a361bb 100644 --- a/tools/model-compiler/src/main/java/io/spine/tools/gradle/compiler/ProtoModule.java +++ b/tools/model-compiler/src/main/java/io/spine/tools/gradle/compiler/ProtoModule.java @@ -23,7 +23,6 @@ import io.spine.tools.gradle.SourceScope; import org.gradle.api.Project; import org.gradle.api.file.FileCollection; -import org.gradle.api.internal.file.collections.ImmutableFileCollection; import org.gradle.api.plugins.JavaPluginConvention; import org.gradle.api.tasks.SourceSet; @@ -88,7 +87,8 @@ FileCollection testProtoSource() { private FileCollection protoSource(SourceScope sourceScope) { SourceSet sourceSet = sourceSet(sourceScope); Optional files = protoSource(sourceSet); - return files.orElse(ImmutableFileCollection.of()); + FileCollection emptyCollection = project.getLayout().files(); + return files.orElse(emptyCollection); } private static Optional protoSource(SourceSet sourceSet) { diff --git a/tools/plugin-base/src/test/java/io/spine/tools/gradle/SpinePluginBuilderTest.java b/tools/plugin-base/src/test/java/io/spine/tools/gradle/SpinePluginBuilderTest.java index d762454a24..c5c8641a97 100644 --- a/tools/plugin-base/src/test/java/io/spine/tools/gradle/SpinePluginBuilderTest.java +++ b/tools/plugin-base/src/test/java/io/spine/tools/gradle/SpinePluginBuilderTest.java @@ -23,7 +23,7 @@ import io.spine.tools.gradle.testing.NoOp; import org.gradle.api.Project; import org.gradle.api.Task; -import org.gradle.api.internal.file.collections.ImmutableFileCollection; +import org.gradle.api.file.FileCollection; import org.gradle.api.tasks.TaskContainer; import org.gradle.testfixtures.ProjectBuilder; import org.junit.jupiter.api.BeforeEach; @@ -153,9 +153,10 @@ void returnBuildTaskDescription() { void createTaskWithGivenInputs() throws IOException { SpinePlugin plugin = TestPlugin.INSTANCE; File input = new File(".").getAbsoluteFile(); + FileCollection files = project.getLayout().files(input); plugin.newTask(preClean, NoOp.action()) .insertBeforeTask(clean) - .withInputFiles(ImmutableFileCollection.of(input)) + .withInputFiles(files) .applyNowTo(project); Task task = project.getTasks() .findByPath(preClean.name()); diff --git a/tools/smoke-tests/gradle/wrapper/gradle-wrapper.properties b/tools/smoke-tests/gradle/wrapper/gradle-wrapper.properties index 4a6ebceacd..a4b4429748 100644 --- a/tools/smoke-tests/gradle/wrapper/gradle-wrapper.properties +++ b/tools/smoke-tests/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/tools/validation-generator/src/main/java/io/spine/tools/validate/ValidationCodeGenerator.java b/tools/validation-generator/src/main/java/io/spine/tools/validate/ValidationCodeGenerator.java index 5b48c4a0cf..fba1158406 100644 --- a/tools/validation-generator/src/main/java/io/spine/tools/validate/ValidationCodeGenerator.java +++ b/tools/validation-generator/src/main/java/io/spine/tools/validate/ValidationCodeGenerator.java @@ -63,6 +63,7 @@ import java.util.List; import java.util.Set; import java.util.function.Function; +import java.util.regex.Pattern; import static com.google.common.base.Preconditions.checkNotNull; import static io.spine.tools.validate.ValidateMethod.VIOLATIONS; @@ -169,7 +170,13 @@ public void visitPattern(PatternConstraint constraint) { FieldDeclaration field = constraint.field(); String pattern = constraint.optionValue() .getRegex(); - Check check = fieldAccess -> fromCode("$L.matches($S)", fieldAccess, pattern).negate(); + String matcher = "$T.compile($S, $L).matcher($L)."; + String method = constraint.allowsPartialMatch() + ? "find()" + : "matches()"; + Check check = fieldAccess -> fromCode( + matcher + method, Pattern.class, pattern, constraint.flagsMask(), fieldAccess + ).negate(); CreateViolation violation = fieldAccess -> newViolation(field, constraint) .setFieldValue(fieldAccess) .addParam(pattern) diff --git a/version.gradle b/version.gradle index 02db104793..19cafac1f1 100644 --- a/version.gradle +++ b/version.gradle @@ -25,7 +25,7 @@ * as we want to manage the versions in a single source. */ -final def SPINE_VERSION = '1.5.1' +final def SPINE_VERSION = '1.5.2' ext { spineVersion = SPINE_VERSION