Skip to content

Commit cd2701d

Browse files
authored
Merge branch 'main' into sayers/disable_lazy
2 parents 77aa865 + 45271ab commit cd2701d

File tree

5 files changed

+141
-15
lines changed

5 files changed

+141
-15
lines changed

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ lintfix: ## Applies the lint changes.
4949
$(GRADLE) spotlessApply
5050

5151
.PHONY: release
52-
release: ## Upload artifacts to Sonatype Nexus.
53-
$(GRADLE) --info publish --stacktrace --no-daemon --no-parallel
54-
$(GRADLE) --info releaseRepository
52+
release: ## Upload artifacts to Maven Central.
53+
$(GRADLE) --info publishAndReleaseToMavenCentral --stacktrace --no-daemon --no-parallel --no-configuration-cache
5554

5655
.PHONY: releaselocal
5756
releaselocal: ## Release artifacts to local maven repository.

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ allprojects {
219219

220220
mavenPublishing {
221221
val isAutoReleased = project.hasProperty("signingInMemoryKey")
222-
publishToMavenCentral(SonatypeHost.S01)
222+
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, automaticRelease = true)
223223
if (isAutoReleased) {
224224
signAllPublications()
225225
}

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[versions]
22
assertj = "3.27.3"
33
buf = "1.53.0"
4-
cel = "0.5.1"
4+
cel = "0.5.3"
55
error-prone = "2.38.0"
66
junit = "5.12.2"
77
maven-publish = "0.31.0"
@@ -22,7 +22,7 @@ errorprone-core = { module = "com.google.errorprone:error_prone_core", version.r
2222
jspecify = { module ="org.jspecify:jspecify", version = "1.0.0" }
2323
junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" }
2424
maven-plugin = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "maven-publish" }
25-
nullaway = { module = "com.uber.nullaway:nullaway", version = "0.12.6" }
25+
nullaway = { module = "com.uber.nullaway:nullaway", version = "0.12.7" }
2626
protobuf-java = { module = "com.google.protobuf:protobuf-java", version.ref = "protobuf" }
2727
spotless = { module = "com.diffplug.spotless:spotless-plugin-gradle", version = "7.0.3" }
2828

src/main/java/build/buf/protovalidate/ValidationResult.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,20 @@ public List<Violation> getViolations() {
6868
@Override
6969
public String toString() {
7070
StringBuilder builder = new StringBuilder();
71-
builder.append("Validation error:");
72-
for (Violation violation : violations) {
73-
builder.append("\n - ");
74-
if (!violation.toProto().hasField()) {
75-
builder.append(FieldPathUtils.fieldPathString(violation.toProto().getField()));
76-
builder.append(": ");
71+
if (isSuccess()) {
72+
builder.append("Validation OK");
73+
} else {
74+
builder.append("Validation error:");
75+
for (Violation violation : violations) {
76+
builder.append("\n - ");
77+
if (violation.toProto().hasField()) {
78+
builder.append(FieldPathUtils.fieldPathString(violation.toProto().getField()));
79+
builder.append(": ");
80+
}
81+
builder.append(
82+
String.format(
83+
"%s [%s]", violation.toProto().getMessage(), violation.toProto().getRuleId()));
7784
}
78-
builder.append(
79-
String.format(
80-
"%s [%s]", violation.toProto().getMessage(), violation.toProto().getRuleId()));
8185
}
8286
return builder.toString();
8387
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// Copyright 2023-2024 Buf Technologies, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package build.buf.protovalidate;
16+
17+
import static org.assertj.core.api.Assertions.assertThat;
18+
19+
import build.buf.validate.FieldPathElement;
20+
import java.util.ArrayList;
21+
import java.util.List;
22+
import org.junit.jupiter.api.Test;
23+
24+
class ValidationResultTest {
25+
@Test
26+
void testToStringNoViolations() {
27+
28+
List<Violation> violations = new ArrayList<Violation>();
29+
ValidationResult result = new ValidationResult(violations);
30+
31+
assertThat(result.toString()).isEqualTo("Validation OK");
32+
assertThat(result.isSuccess()).isTrue();
33+
}
34+
35+
@Test
36+
void testToStringSingleViolation() {
37+
FieldPathElement elem =
38+
FieldPathElement.newBuilder().setFieldNumber(5).setFieldName("test_field_name").build();
39+
40+
RuleViolation violation =
41+
RuleViolation.newBuilder()
42+
.setRuleId("int32.const")
43+
.setMessage("value must equal 42")
44+
.addFirstFieldPathElement(elem)
45+
.build();
46+
List<Violation> violations = new ArrayList<Violation>();
47+
violations.add(violation);
48+
ValidationResult result = new ValidationResult(violations);
49+
50+
assertThat(result.toString())
51+
.isEqualTo("Validation error:\n - test_field_name: value must equal 42 [int32.const]");
52+
}
53+
54+
@Test
55+
void testToStringMultipleViolations() {
56+
FieldPathElement elem =
57+
FieldPathElement.newBuilder().setFieldNumber(5).setFieldName("test_field_name").build();
58+
59+
RuleViolation violation1 =
60+
RuleViolation.newBuilder()
61+
.setRuleId("int32.const")
62+
.setMessage("value must equal 42")
63+
.addFirstFieldPathElement(elem)
64+
.build();
65+
66+
RuleViolation violation2 =
67+
RuleViolation.newBuilder()
68+
.setRuleId("int32.required")
69+
.setMessage("value is required")
70+
.addFirstFieldPathElement(elem)
71+
.build();
72+
List<Violation> violations = new ArrayList<Violation>();
73+
violations.add(violation1);
74+
violations.add(violation2);
75+
ValidationResult result = new ValidationResult(violations);
76+
77+
assertThat(result.toString())
78+
.isEqualTo(
79+
"Validation error:\n - test_field_name: value must equal 42 [int32.const]\n - test_field_name: value is required [int32.required]");
80+
}
81+
82+
@Test
83+
void testToStringSingleViolationMultipleFieldPathElements() {
84+
FieldPathElement elem1 =
85+
FieldPathElement.newBuilder().setFieldNumber(5).setFieldName("test_field_name").build();
86+
FieldPathElement elem2 =
87+
FieldPathElement.newBuilder().setFieldNumber(5).setFieldName("nested_name").build();
88+
89+
List<FieldPathElement> elems = new ArrayList<FieldPathElement>();
90+
elems.add(elem1);
91+
elems.add(elem2);
92+
93+
RuleViolation violation1 =
94+
RuleViolation.newBuilder()
95+
.setRuleId("int32.const")
96+
.setMessage("value must equal 42")
97+
.addAllFieldPathElements(elems)
98+
.build();
99+
100+
List<Violation> violations = new ArrayList<Violation>();
101+
violations.add(violation1);
102+
ValidationResult result = new ValidationResult(violations);
103+
104+
assertThat(result.toString())
105+
.isEqualTo(
106+
"Validation error:\n - test_field_name.nested_name: value must equal 42 [int32.const]");
107+
}
108+
109+
@Test
110+
void testToStringSingleViolationNoFieldPathElements() {
111+
RuleViolation violation =
112+
RuleViolation.newBuilder()
113+
.setRuleId("int32.const")
114+
.setMessage("value must equal 42")
115+
.build();
116+
List<Violation> violations = new ArrayList<Violation>();
117+
violations.add(violation);
118+
ValidationResult result = new ValidationResult(violations);
119+
120+
assertThat(result.toString())
121+
.isEqualTo("Validation error:\n - value must equal 42 [int32.const]");
122+
}
123+
}

0 commit comments

Comments
 (0)