Search in sources :

Example 1 with FileDescriptor

use of org.infinispan.protostream.descriptors.FileDescriptor in project infinispan by infinispan.

the class ProtobufMetadataManagerInterceptor method computeErrorUpdatesAfterRemove.

private List<KeyValuePair<String, String>> computeErrorUpdatesAfterRemove(String key) {
    // List of proto schemas and their errors
    // Proto schemas with no errors have a null value
    List<KeyValuePair<String, String>> errorUpdates = new ArrayList<>();
    errorUpdates.add(KeyValuePair.of(key, null));
    StringBuilder sb = new StringBuilder();
    for (FileDescriptor fd : serializationContext.getFileDescriptors().values()) {
        String fdName = fd.getName();
        if (fd.isResolved()) {
            errorUpdates.add(KeyValuePair.of(fdName, null));
        } else {
            if (sb.length() > 0) {
                sb.append('\n');
            }
            sb.append(fdName);
            errorUpdates.add(KeyValuePair.of(fdName, "One of the imported files is missing or has errors"));
        }
    }
    errorUpdates.add(KeyValuePair.of("", sb.length() > 0 ? sb.toString() : null));
    return errorUpdates;
}
Also used : KeyValuePair(org.infinispan.util.KeyValuePair) ArrayList(java.util.ArrayList) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor)

Example 2 with FileDescriptor

use of org.infinispan.protostream.descriptors.FileDescriptor in project protostream by infinispan.

the class DescriptorsTest method testDocComment.

@Test
public void testDocComment() {
    String file1 = "package test1;\n" + "/**  \n" + " *    some doc text \n" + "  *    some more doc text \n" + "      **/\n\n" + "message X {\n" + " /**\n" + "  * field doc text  \n\n" + "  */\n" + "  optional int32 field1 = 1;\n" + "}\n";
    FileDescriptorSource fileDescriptorSource = new FileDescriptorSource();
    fileDescriptorSource.addProtoFile("file1.proto", file1);
    Map<String, FileDescriptor> descriptors = parseAndResolve(fileDescriptorSource);
    assertEquals(1, descriptors.size());
    assertTrue(descriptors.containsKey("file1.proto"));
    Map<String, GenericDescriptor> types = descriptors.get("file1.proto").getTypes();
    Descriptor typeX = (Descriptor) types.get("test1.X");
    assertNotNull(typeX);
    assertEquals(1, typeX.getFields().size());
    FieldDescriptor field1 = typeX.getFields().get(0);
    assertEquals("some doc text \n   some more doc text", typeX.getDocumentation());
    assertEquals("field doc text", field1.getDocumentation());
}
Also used : GenericDescriptor(org.infinispan.protostream.descriptors.GenericDescriptor) Descriptor(org.infinispan.protostream.descriptors.Descriptor) EnumDescriptor(org.infinispan.protostream.descriptors.EnumDescriptor) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) ExtendDescriptor(org.infinispan.protostream.descriptors.ExtendDescriptor) FieldDescriptor(org.infinispan.protostream.descriptors.FieldDescriptor) GenericDescriptor(org.infinispan.protostream.descriptors.GenericDescriptor) FileDescriptorSource(org.infinispan.protostream.FileDescriptorSource) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) FieldDescriptor(org.infinispan.protostream.descriptors.FieldDescriptor) Test(org.junit.Test)

Example 3 with FileDescriptor

use of org.infinispan.protostream.descriptors.FileDescriptor in project protostream by infinispan.

the class DescriptorsTest method testArrayAnnotationAttributeNormalizing.

@Test
public void testArrayAnnotationAttributeNormalizing() {
    Configuration config = Configuration.builder().annotationsConfig().annotation("Xyz", AnnotationElement.AnnotationTarget.MESSAGE).attribute("elem1").type(AnnotationElement.AttributeType.BOOLEAN).defaultValue(true).multiple(true).build();
    String testProto = "/** @Xyz(elem1 = true) */\n" + "message M {\n" + "  optional int32 field1 = 1; \n" + "}\n";
    FileDescriptorSource fileDescriptorSource = FileDescriptorSource.fromString("test.proto", testProto);
    Map<String, FileDescriptor> descriptors = parseAndResolve(fileDescriptorSource, config);
    FileDescriptor fileDescriptor = descriptors.get("test.proto");
    List<Descriptor> messageTypes = fileDescriptor.getMessageTypes();
    Descriptor messageType = messageTypes.get(0);
    assertEquals("M", messageType.getFullName());
    AnnotationElement.Annotation annotation = messageType.getAnnotations().get("Xyz");
    assertNotNull(annotation);
    AnnotationElement.Value attr = annotation.getAttributeValue("elem1");
    assertTrue(attr instanceof AnnotationElement.Array);
    assertTrue(attr.getValue() instanceof List);
    List values = (List) attr.getValue();
    assertEquals(1, values.size());
    assertEquals(true, values.get(0));
}
Also used : Configuration(org.infinispan.protostream.config.Configuration) AnnotationElement(org.infinispan.protostream.descriptors.AnnotationElement) Descriptor(org.infinispan.protostream.descriptors.Descriptor) EnumDescriptor(org.infinispan.protostream.descriptors.EnumDescriptor) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) ExtendDescriptor(org.infinispan.protostream.descriptors.ExtendDescriptor) FieldDescriptor(org.infinispan.protostream.descriptors.FieldDescriptor) GenericDescriptor(org.infinispan.protostream.descriptors.GenericDescriptor) List(java.util.List) FileDescriptorSource(org.infinispan.protostream.FileDescriptorSource) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) Test(org.junit.Test)

Example 4 with FileDescriptor

use of org.infinispan.protostream.descriptors.FileDescriptor in project protostream by infinispan.

the class DescriptorsTest method testRepeatedAnnotation.

@Test
public void testRepeatedAnnotation() {
    Configuration config = Configuration.builder().annotationsConfig().annotation("Field", AnnotationElement.AnnotationTarget.FIELD).repeatable("Fields").attribute(AnnotationElement.Annotation.VALUE_DEFAULT_ATTRIBUTE).type(AnnotationElement.AttributeType.BOOLEAN).defaultValue(true).build();
    String testProto = "message M {\n" + "  /** @Field @Field */\n" + "  optional int32 field1 = 1; \n" + "}";
    FileDescriptorSource fileDescriptorSource = FileDescriptorSource.fromString("test.proto", testProto);
    Map<String, FileDescriptor> descriptors = parseAndResolve(fileDescriptorSource, config);
    Map<String, AnnotationElement.Annotation> annotations = descriptors.get("test.proto").getMessageTypes().get(0).getFields().get(0).getAnnotations();
    assertFalse(annotations.containsKey("Field"));
    assertTrue(annotations.containsKey("Fields"));
    List<AnnotationElement.Annotation> innerAnnotations = (List<AnnotationElement.Annotation>) annotations.get("Fields").getDefaultAttributeValue().getValue();
    assertEquals(2, innerAnnotations.size());
}
Also used : Configuration(org.infinispan.protostream.config.Configuration) AnnotationElement(org.infinispan.protostream.descriptors.AnnotationElement) List(java.util.List) FileDescriptorSource(org.infinispan.protostream.FileDescriptorSource) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) Test(org.junit.Test)

Example 5 with FileDescriptor

use of org.infinispan.protostream.descriptors.FileDescriptor in project protostream by infinispan.

the class DescriptorsTest method testDuplicateUndefinedAnnotation.

@Test
public void testDuplicateUndefinedAnnotation() {
    Configuration config = Configuration.builder().annotationsConfig().annotation("Field", AnnotationElement.AnnotationTarget.FIELD).attribute(AnnotationElement.Annotation.VALUE_DEFAULT_ATTRIBUTE).type(AnnotationElement.AttributeType.BOOLEAN).defaultValue(true).build();
    String testProto = "message M {\n" + "  /** @SomeAnnotation @SomeAnnotation @Field */\n" + "  optional int32 field1 = 1; \n" + "}";
    FileDescriptorSource fileDescriptorSource = FileDescriptorSource.fromString("test.proto", testProto);
    Map<String, FileDescriptor> descriptors = parseAndResolve(fileDescriptorSource, config);
    // todo [anistor] The processing of annotations is waaay too lazy
    AnnotationElement.Annotation someAnnotation = descriptors.get("test.proto").getMessageTypes().get(0).getFields().get(0).getAnnotations().get("SomeAnnotation");
    // 'SomeAnnotation' annotation is not defined, but we accept it silently
    assertNull(someAnnotation);
    AnnotationElement.Annotation fieldAnnotation = descriptors.get("test.proto").getMessageTypes().get(0).getFields().get(0).getAnnotations().get("Field");
    assertNotNull(fieldAnnotation);
    assertEquals("Field", fieldAnnotation.getName());
}
Also used : Configuration(org.infinispan.protostream.config.Configuration) AnnotationElement(org.infinispan.protostream.descriptors.AnnotationElement) FileDescriptorSource(org.infinispan.protostream.FileDescriptorSource) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) Test(org.junit.Test)

Aggregations

FileDescriptor (org.infinispan.protostream.descriptors.FileDescriptor)43 FileDescriptorSource (org.infinispan.protostream.FileDescriptorSource)24 Test (org.junit.Test)23 Descriptor (org.infinispan.protostream.descriptors.Descriptor)12 Configuration (org.infinispan.protostream.config.Configuration)11 EnumDescriptor (org.infinispan.protostream.descriptors.EnumDescriptor)11 FieldDescriptor (org.infinispan.protostream.descriptors.FieldDescriptor)11 List (java.util.List)8 SerializationContext (org.infinispan.protostream.SerializationContext)8 AnnotationElement (org.infinispan.protostream.descriptors.AnnotationElement)8 GenericDescriptor (org.infinispan.protostream.descriptors.GenericDescriptor)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 DescriptorParserException (org.infinispan.protostream.DescriptorParserException)5 ExtendDescriptor (org.infinispan.protostream.descriptors.ExtendDescriptor)5 EntityIndexDescriptor (org.kie.kogito.persistence.api.schema.EntityIndexDescriptor)4 HashMap (java.util.HashMap)3 ResolutionContext (org.infinispan.protostream.descriptors.ResolutionContext)3 Ignore (org.junit.Ignore)3 Test (org.junit.jupiter.api.Test)3