Skip to content

Commit

Permalink
#204 Fix build Object with no native classes. (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
jemacineiras authored Apr 4, 2022
1 parent daa07f9 commit a8b2775
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ nb-configuration.xml

# OS
.DS_Store
/dependency-reduced-pom.xml
dependency-reduced-pom.*
.factorypath
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ public class ProtoBufProcessorHelper {
Descriptors.Descriptor buildDescriptor(ProtoFileElement schema) throws Descriptors.DescriptorValidationException, IOException {

DynamicSchema.Builder schemaBuilder = DynamicSchema.newBuilder();
var lines = new ArrayList<String>();
List<String> imports = schema.getImports();
for (String importedClass : imports) {
String schemaToString = new String(getClass().getClassLoader().getResourceAsStream(importedClass).readAllBytes());
lines.addAll(CollectionUtils.select(Arrays.asList(schemaToString.split("\\n")), isValid()));
var lines = new ArrayList<>(CollectionUtils.select(Arrays.asList(schemaToString.split("\\n")), isValid()));
if (!ProtobufHelper.NOT_ACCEPTED_IMPORTS.contains(importedClass)) {
var importedSchema = processImported(lines);
schemaBuilder.addDependency(importedSchema.getFileDescriptorSet().getFile(0).getName());
Expand Down Expand Up @@ -163,13 +162,16 @@ private DynamicSchema processImported(List<String> importedLines) throws Descrip

private MessageDefinition buildMessage(String messageName, ListIterator<String> messageLines) {

boolean exit = false;
MessageDefinition.Builder messageDefinition = MessageDefinition.newBuilder(messageName);
while (messageLines.hasNext()) {
while (messageLines.hasNext() && !exit) {
var field = messageLines.next().trim().split("\\s");
if (ProtobufHelper.isValidType(field[0])) {
messageDefinition.addField(OPTIONAL, field[0], field[1], Integer.parseInt(checkIfChoppable(field[3])));
} else if (ProtobufHelper.LABEL.contains(field[0])) {
messageDefinition.addField(field[0], field[1], field[2], Integer.parseInt(checkIfChoppable(field[4])));
} else if ("}".equalsIgnoreCase(field[0])) {
exit = true;
}
}

Expand Down

0 comments on commit a8b2775

Please sign in to comment.