use of com.spotify.protoman.descriptor.FileDescriptor 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.FileDescriptor 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());
});
}
Aggregations