Skip to content

Commit c2b3246

Browse files
authored
Merge pull request #1219 from SpineEventEngine/compile-time-validation
Integrate validation code generation
2 parents a288697 + 1493834 commit c2b3246

File tree

22 files changed

+80
-301
lines changed

22 files changed

+80
-301
lines changed

build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ ext {
6666
}
6767

6868
allprojects {
69-
apply plugin: 'maven'
7069
apply plugin: 'jacoco'
7170
apply plugin: 'idea'
7271
apply plugin: 'project-report'
@@ -105,6 +104,10 @@ subprojects {
105104
apply from: deps.scripts.modelCompiler
106105
apply from: deps.scripts.projectLicenseReport
107106

107+
modelCompiler {
108+
generateValidation = true
109+
}
110+
108111
// Specific setup for a Travis build,
109112
// which prevents appearing of warning messages in build logs.
110113
//

core/src/test/proto/spine/test/core/events.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ message TaskAssigned {
4343

4444
ProjectId project_id = 2 [(required) = true];
4545

46-
string user_name = 3 [(pattern).regex = ".{3,}"];
46+
string user_name = 3 [(required) = true, (pattern).regex = ".{3,}"];
4747
}

license-report.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22

3-
# Dependencies of `io.spine:spine-client:1.3.1`
3+
# Dependencies of `io.spine:spine-client:1.3.2`
44

55
## Runtime
66
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -401,12 +401,12 @@
401401
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
402402

403403

404-
This report was generated on **Tue Dec 24 15:51:56 EET 2019** 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).
404+
This report was generated on **Sun Jan 05 13:26:34 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).
405405

406406

407407

408408

409-
# Dependencies of `io.spine:spine-core:1.3.1`
409+
# Dependencies of `io.spine:spine-core:1.3.2`
410410

411411
## Runtime
412412
1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2
@@ -763,12 +763,12 @@ This report was generated on **Tue Dec 24 15:51:56 EET 2019** using [Gradle-Lice
763763
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
764764

765765

766-
This report was generated on **Tue Dec 24 15:51:57 EET 2019** 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).
766+
This report was generated on **Sun Jan 05 13:26:35 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).
767767

768768

769769

770770

771-
# Dependencies of `io.spine.tools:spine-model-assembler:1.3.1`
771+
# Dependencies of `io.spine.tools:spine-model-assembler:1.3.2`
772772

773773
## Runtime
774774
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -1164,12 +1164,12 @@ This report was generated on **Tue Dec 24 15:51:57 EET 2019** using [Gradle-Lice
11641164
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
11651165

11661166

1167-
This report was generated on **Tue Dec 24 15:51:57 EET 2019** 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).
1167+
This report was generated on **Sun Jan 05 13:26:36 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).
11681168

11691169

11701170

11711171

1172-
# Dependencies of `io.spine.tools:spine-model-verifier:1.3.1`
1172+
# Dependencies of `io.spine.tools:spine-model-verifier:1.3.2`
11731173

11741174
## Runtime
11751175
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -1625,12 +1625,12 @@ This report was generated on **Tue Dec 24 15:51:57 EET 2019** using [Gradle-Lice
16251625
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
16261626

16271627

1628-
This report was generated on **Tue Dec 24 15:51:57 EET 2019** 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).
1628+
This report was generated on **Sun Jan 05 13:26:37 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).
16291629

16301630

16311631

16321632

1633-
# Dependencies of `io.spine:spine-server:1.3.1`
1633+
# Dependencies of `io.spine:spine-server:1.3.2`
16341634

16351635
## Runtime
16361636
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -2043,12 +2043,12 @@ This report was generated on **Tue Dec 24 15:51:57 EET 2019** using [Gradle-Lice
20432043
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
20442044

20452045

2046-
This report was generated on **Tue Dec 24 15:51:58 EET 2019** 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).
2046+
This report was generated on **Sun Jan 05 13:26:37 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).
20472047

20482048

20492049

20502050

2051-
# Dependencies of `io.spine:spine-testutil-client:1.3.1`
2051+
# Dependencies of `io.spine:spine-testutil-client:1.3.2`
20522052

20532053
## Runtime
20542054
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -2502,12 +2502,12 @@ This report was generated on **Tue Dec 24 15:51:58 EET 2019** using [Gradle-Lice
25022502
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
25032503

25042504

2505-
This report was generated on **Tue Dec 24 15:51:58 EET 2019** 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).
2505+
This report was generated on **Sun Jan 05 13:26:40 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).
25062506

25072507

25082508

25092509

2510-
# Dependencies of `io.spine:spine-testutil-core:1.3.1`
2510+
# Dependencies of `io.spine:spine-testutil-core:1.3.2`
25112511

25122512
## Runtime
25132513
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -2969,12 +2969,12 @@ This report was generated on **Tue Dec 24 15:51:58 EET 2019** using [Gradle-Lice
29692969
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
29702970

29712971

2972-
This report was generated on **Tue Dec 24 15:51:58 EET 2019** 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).
2972+
This report was generated on **Sun Jan 05 13:26:41 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).
29732973

29742974

29752975

29762976

2977-
# Dependencies of `io.spine:spine-testutil-server:1.3.1`
2977+
# Dependencies of `io.spine:spine-testutil-server:1.3.2`
29782978

29792979
## Runtime
29802980
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -3472,4 +3472,4 @@ This report was generated on **Tue Dec 24 15:51:58 EET 2019** using [Gradle-Lice
34723472
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
34733473

34743474

3475-
This report was generated on **Tue Dec 24 15:51:59 EET 2019** 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).
3475+
This report was generated on **Sun Jan 05 13:26:44 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).

pom.xml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ all modules and does not describe the project structure per-subproject.
1212

1313
<groupId>io.spine</groupId>
1414
<artifactId>spine-core-java</artifactId>
15-
<version>1.3.1</version>
15+
<version>1.3.2</version>
1616

1717
<inceptionYear>2015</inceptionYear>
1818

@@ -70,25 +70,25 @@ all modules and does not describe the project structure per-subproject.
7070
<dependency>
7171
<groupId>io.spine</groupId>
7272
<artifactId>spine-base</artifactId>
73-
<version>1.3.0</version>
73+
<version>1.3.2</version>
7474
<scope>compile</scope>
7575
</dependency>
7676
<dependency>
7777
<groupId>io.spine</groupId>
7878
<artifactId>spine-time</artifactId>
79-
<version>1.3.0</version>
79+
<version>1.3.2</version>
8080
<scope>compile</scope>
8181
</dependency>
8282
<dependency>
8383
<groupId>io.spine.tools</groupId>
8484
<artifactId>spine-model-compiler</artifactId>
85-
<version>1.3.0</version>
85+
<version>1.3.2</version>
8686
<scope>compile</scope>
8787
</dependency>
8888
<dependency>
8989
<groupId>io.spine.tools</groupId>
9090
<artifactId>spine-plugin-base</artifactId>
91-
<version>1.3.0</version>
91+
<version>1.3.2</version>
9292
<scope>compile</scope>
9393
</dependency>
9494
<dependency>
@@ -130,25 +130,25 @@ all modules and does not describe the project structure per-subproject.
130130
<dependency>
131131
<groupId>io.spine</groupId>
132132
<artifactId>spine-testlib</artifactId>
133-
<version>1.3.0</version>
133+
<version>1.3.2</version>
134134
<scope>test</scope>
135135
</dependency>
136136
<dependency>
137137
<groupId>io.spine</groupId>
138138
<artifactId>spine-testutil-time</artifactId>
139-
<version>1.3.0</version>
139+
<version>1.3.2</version>
140140
<scope>test</scope>
141141
</dependency>
142142
<dependency>
143143
<groupId>io.spine.tools</groupId>
144144
<artifactId>spine-mute-logging</artifactId>
145-
<version>1.3.0</version>
145+
<version>1.3.2</version>
146146
<scope>test</scope>
147147
</dependency>
148148
<dependency>
149149
<groupId>io.spine.tools</groupId>
150150
<artifactId>spine-plugin-testlib</artifactId>
151-
<version>1.3.0</version>
151+
<version>1.3.2</version>
152152
<scope>test</scope>
153153
</dependency>
154154
<dependency>
@@ -210,12 +210,12 @@ all modules and does not describe the project structure per-subproject.
210210
<dependency>
211211
<groupId>io.spine.tools</groupId>
212212
<artifactId>spine-javadoc-filter</artifactId>
213-
<version>1.3.0</version>
213+
<version>1.3.2</version>
214214
</dependency>
215215
<dependency>
216216
<groupId>io.spine.tools</groupId>
217217
<artifactId>spine-protoc-plugin</artifactId>
218-
<version>1.3.0</version>
218+
<version>1.3.2</version>
219219
</dependency>
220220
<dependency>
221221
<groupId>net.sourceforge.pmd</groupId>

server/src/main/java/io/spine/server/aggregate/ImportValidator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import io.spine.server.bus.EnvelopeValidator;
2626
import io.spine.server.type.EventEnvelope;
2727
import io.spine.validate.ConstraintViolation;
28-
import io.spine.validate.MessageValidator;
28+
import io.spine.validate.Validate;
2929

3030
import java.util.List;
3131
import java.util.Optional;
@@ -42,7 +42,7 @@ final class ImportValidator implements EnvelopeValidator<EventEnvelope> {
4242
public Optional<MessageInvalid> validate(EventEnvelope event) {
4343
checkNotNull(event);
4444
EventMessage eventMessage = event.message();
45-
List<ConstraintViolation> violations = MessageValidator.validate(eventMessage);
45+
List<ConstraintViolation> violations = Validate.violationsOf(eventMessage);
4646
if (violations.isEmpty()) {
4747
return Optional.empty();
4848
}

server/src/main/java/io/spine/server/commandbus/CommandValidator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import io.spine.server.route.DefaultCommandRoute;
3535
import io.spine.server.type.CommandEnvelope;
3636
import io.spine.validate.ConstraintViolation;
37-
import io.spine.validate.MessageValidator;
37+
import io.spine.validate.Validate;
3838

3939
import java.util.List;
4040
import java.util.Optional;
@@ -139,7 +139,7 @@ private ViolationCheck(CommandEnvelope commandEnvelope) {
139139
*/
140140
@Internal
141141
private static List<ConstraintViolation> validateId(CommandId id) {
142-
List<ConstraintViolation> violations = MessageValidator.validate(id);
142+
List<ConstraintViolation> violations = Validate.violationsOf(id);
143143
if (id.getUuid().isEmpty()) {
144144
return ImmutableList.<ConstraintViolation>builder()
145145
.addAll(violations)
@@ -172,7 +172,7 @@ private void validateMessage() {
172172
if (isDefault(message)) {
173173
addViolation("Non-default command message must be set.");
174174
}
175-
List<ConstraintViolation> messageViolations = MessageValidator.validate(message);
175+
List<ConstraintViolation> messageViolations = Validate.violationsOf(message);
176176
result.addAll(messageViolations);
177177
}
178178

server/src/main/java/io/spine/server/entity/AbstractEntity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import io.spine.server.entity.rejection.CannotModifyDeletedEntity;
3737
import io.spine.string.Stringifiers;
3838
import io.spine.validate.ConstraintViolation;
39-
import io.spine.validate.MessageValidator;
39+
import io.spine.validate.Validate;
4040
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
4141

4242
import java.util.List;
@@ -246,7 +246,7 @@ final void updateState(S state) {
246246
/**
247247
* Verifies the new entity state and returns {@link ConstraintViolation}s, if any.
248248
*
249-
* <p>Default implementation uses the {@linkplain MessageValidator#validate(Message) message
249+
* <p>Default implementation uses the {@linkplain Validate#violationsOf(Message) message
250250
* validation}.
251251
*
252252
* @param newState
@@ -255,7 +255,7 @@ final void updateState(S state) {
255255
*/
256256
protected final List<ConstraintViolation> checkEntityState(S newState) {
257257
checkNotNull(newState);
258-
return MessageValidator.validate(newState);
258+
return Validate.violationsOf(newState);
259259
}
260260

261261
/**

server/src/main/java/io/spine/server/entity/IdField.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void initBuilder(B builder, I id) {
8787
}
8888
FieldDescriptor idField = declaration.descriptor();
8989
@SuppressWarnings("Immutable") // all supported types of IDs are immutable.
90-
Required<I> required = Required.create(false);
90+
Required required = Required.create(false);
9191
boolean isRequired = required.valueFrom(idField)
9292
.orElse(true); // assume required, if not set to false
9393
if (isRequired) {

server/src/main/java/io/spine/server/entity/Repository.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import org.checkerframework.checker.nullness.qual.Nullable;
4848
import org.checkerframework.dataflow.qual.Pure;
4949

50-
import java.util.Collection;
5150
import java.util.Iterator;
5251
import java.util.Optional;
5352
import java.util.function.Predicate;
@@ -384,13 +383,12 @@ public final boolean isOpen() {
384383
* <p>An {@code IllegalStateException} is thrown otherwise.
385384
*
386385
* @param result the result of routing
387-
* @param <R> the type of the result
388386
*/
389-
private <R> void checkMatchesIdType(R result) {
387+
private void checkMatchesIdType(Object result) {
390388
Class routingResultType = null;
391-
if (result instanceof Collection) {
392-
Collection<?> asCollection = (Collection) result;
393-
Object element = getFirst(asCollection, null);
389+
if (result instanceof Iterable) {
390+
Iterable<?> asIterable = (Iterable<?>) result;
391+
Object element = getFirst(asIterable, null);
394392
if (element != null) {
395393
routingResultType = element.getClass();
396394
}
@@ -477,7 +475,7 @@ public EventFilter eventFilter() {
477475
/**
478476
* Enumeration of generic type parameters of this class.
479477
*/
480-
enum GenericParameter implements GenericTypeIndex<Repository> {
478+
private enum GenericParameter implements GenericTypeIndex<Repository> {
481479

482480
/** The index of the generic type {@code <I>}. */
483481
ID(0),

0 commit comments

Comments
 (0)