use of com.spotify.protoman.descriptor.DescriptorSet in project protoman by spotify.
the class SemverSchemaVersioner method hasMinorVersionChange.
/**
* File additions, removals and renames are considered minor version changes. As are any
* formatting/comment changes to proto files. I.e. adding a type, adding a field, etc. are
* considered minor version changes.
*/
private static boolean hasMinorVersionChange(final String protoPackage, final DescriptorSet current, final DescriptorSet candidate) {
final Predicate<FileDescriptor> predicate = fileDescriptor -> Objects.equals(fileDescriptor.protoPackage(), protoPackage);
final ImmutableMap<String, FileDescriptor> currentFileDescriptors = current.fileDescriptors().stream().filter(predicate).collect(toImmutableMap(FileDescriptor::fullName, Function.identity()));
final ImmutableMap<String, FileDescriptor> candidateFileDescriptors = candidate.fileDescriptors().stream().filter(predicate).collect(toImmutableMap(FileDescriptor::fullName, Function.identity()));
if (!Objects.equals(currentFileDescriptors.keySet(), candidateFileDescriptors.keySet())) {
// .proto files were added or removed
return true;
}
// descriptors. I.e. formatting changes are usually not considered minor version changes.
return currentFileDescriptors.keySet().stream().anyMatch(key -> {
// No files were added or removed, thus currentFd and candidateFd should always be
// non-null
final FileDescriptor currentFd = currentFileDescriptors.get(key);
final FileDescriptor candidateFd = candidateFileDescriptors.get(key);
assert currentFd != null && candidateFd != null;
final DescriptorProtos.FileDescriptorProto currentFdProto = currentFd.toProto().toBuilder().clearSourceCodeInfo().build();
final DescriptorProtos.FileDescriptorProto candidateFdProto = candidateFd.toProto().toBuilder().clearSourceCodeInfo().build();
return !Objects.equals(currentFdProto, candidateFdProto);
});
}
use of com.spotify.protoman.descriptor.DescriptorSet in project protoman by spotify.
the class SemverSchemaVersioner method hasPatchVersionChange.
private static boolean hasPatchVersionChange(final String protoPackage, final DescriptorSet current, final DescriptorSet candidate) {
final Predicate<FileDescriptor> predicate = fileDescriptor -> Objects.equals(fileDescriptor.protoPackage(), protoPackage);
final ImmutableMap<String, FileDescriptor> currentFileDescriptors = current.fileDescriptors().stream().filter(predicate).collect(toImmutableMap(FileDescriptor::fullName, Function.identity()));
final ImmutableMap<String, FileDescriptor> candidateFileDescriptors = candidate.fileDescriptors().stream().filter(predicate).collect(toImmutableMap(FileDescriptor::fullName, Function.identity()));
return currentFileDescriptors.keySet().stream().anyMatch(key -> {
final FileDescriptor currentFd = currentFileDescriptors.get(key);
final FileDescriptor candidateFd = candidateFileDescriptors.get(key);
assert currentFd != null && candidateFd != null;
return !Objects.equals(currentFd.toProto(), candidateFd.toProto());
});
}
use of com.spotify.protoman.descriptor.DescriptorSet in project protoman by spotify.
the class EnumDefaultValueTest method testAllowedName.
@Parameters(method = "allowedNames")
@Test
public void testAllowedName(final String name) throws Exception {
final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("a.proto", String.format(TEMPLATE, name));
final ImmutableList<ValidationViolation> violations = schemaValidator.validate(DescriptorSet.empty(), candidate);
assertThat(violations, is(empty()));
}
use of com.spotify.protoman.descriptor.DescriptorSet in project protoman by spotify.
the class EnumNamingRuleTest method testAllowedName_existing.
@Parameters(method = "allowedNames")
@Test
public void testAllowedName_existing(final String name) throws Exception {
final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("a.proto", String.format(TEMPLATE, name));
final ImmutableList<ValidationViolation> violations = schemaValidator.validate(candidate, candidate);
assertThat(violations, is(empty()));
}
use of com.spotify.protoman.descriptor.DescriptorSet in project protoman by spotify.
the class EnumNamingRuleTest method testDisallowedName_new.
@Parameters(method = "disallowedNames")
@Test
public void testDisallowedName_new(final String name) throws Exception {
final DescriptorSet current = DescriptorSet.empty();
final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("a.proto", String.format(TEMPLATE, name));
final ImmutableList<ValidationViolation> violations = schemaValidator.validate(current, candidate);
assertThat(violations, contains(validationViolation().description(equalTo("enum name should be UpperCamelCase")).type(equalTo(ViolationType.STYLE_GUIDE_VIOLATION)).current(nullValue(GenericDescriptor.class)).candidate(genericDescriptor().sourceCodeInfo(optionalWithValue(sourceCodeInfo().start(filePosition().line(2).column(1)))))));
}
Aggregations