vontikov / sbe-gradle-plugin

Simple Binary Encoding plugin for Gradle Build Tool
MIT License
7 stars 4 forks source link

sbe.xinclude.aware set to true is invalid #8

Closed zxuanhong closed 3 months ago

zxuanhong commented 4 months ago

question

  1. sbe.xinclude.aware set to true is invalid

    image
  2. The same files can be used with custom JavaExec tasks without any problems

tasks.register('generateMessages', JavaExec) {
    mainClass = 'uk.co.real_logic.sbe.SbeTool'
    classpath = sourceSets.main.runtimeClasspath
    group = "sbe"
    systemProperties('sbe.output.dir': "build/generated/sources/sbe/main/java",
            'sbe.target.language': 'Java',
            'sbe.validation.stop.on.error': 'true',
            'sbe.xinclude.aware': 'true')
    args = [
            'src/main/resources/sbe/management-schema.xml',
            'src/main/resources/sbe/subscription-schema.xml'
    ]
}

tasks.register('generateCompile', JavaCompile) {
    dependsOn "generateMessages"
    group = "sbe"
    source = project.fileTree(dir: "build/generated/sources/sbe/main/java", include: '**/*.java')
    sourceCompatibility = JavaVersion.VERSION_21
    targetCompatibility = JavaVersion.VERSION_21
    destinationDirectory = project.file("build/generated/classes")
    classpath = sourceSets.main.runtimeClasspath
}

sourceSets {
    main {
        java {
            srcDir 'build/generated/sources/sbe/main/java'
        }
    }
}

test file

  1. common-types.xml

    
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <types>
    
    <composite name="messageHeader" description="Message identifiers and length of message root">
        <type name="blockLength" primitiveType="uint16"/>
        <type name="templateId" primitiveType="uint16"/>
        <type name="schemaId" primitiveType="uint16"/>
        <type name="version" primitiveType="uint16"/>
    </composite>
    
    <composite name="varDataEncoding">
        <type name="length" primitiveType="uint32" maxValue="2147483647"/>
        <type name="varData" primitiveType="uint8" length="0" characterEncoding="UTF-8"/>
    </composite>
    
    <composite name="groupSizeEncoding" description="Repeating group dimensions">
        <type name="blockLength" primitiveType="uint16"/>
        <type name="numInGroup" primitiveType="uint8" semanticType="NumInGroup"/>
    </composite>
    
    <enum name="BooleanType" encodingType="uint8" semanticType="Boolean">
        <validValue name="FALSE">0</validValue>
        <validValue name="TRUE">1</validValue>
    </enum>


2. management-schema.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <sbe:messageSchema xmlns:sbe="http://fixprotocol.io/2016/sbe" xmlns:xi="http://www.w3.org/2001/XInclude" package="clustering.management" id="0" version="1" semanticVersion="1.0.0" description="Kunpeng Cluster Management Protocol" byteOrder="littleEndian">

<xi:include href="common-types.xml"/>

<types>

    <!-- binary data -->
    <composite name="blob">
        <type name="length" primitiveType="uint32" maxValue="2147483647"/>
        <type name="varData" primitiveType="uint8" length="0"/>
    </composite>

    <enum name="errorResponseCode" encodingType="uint8" semanticType="String">
        <validValue name="PARTITION_NOT_FOUND">0</validValue>
        <validValue name="INVALID_PARAMETERS">1</validValue>
        <validValue name="READ_ERROR">2</validValue>
    </enum>

</types>

<sbe:message name="ErrorResponse" id="1">
    <field name="code" id="0" type="errorResponseCode"/>
    <data name="data" id="1" type="varDataEncoding"/>
</sbe:message>

<sbe:message name="PushDeploymentRequest" id="2">
    <field name="partitionId" id="0" type="uint16"/>
    <field name="deploymentKey" id="1" type="uint64"/>
    <data name="deployment" id="2" type="varDataEncoding"/>
</sbe:message>

<sbe:message name="PushDeploymentResponse" id="3">
    <field name="partitionId" id="0" type="uint16"/>
    <field name="deploymentKey" id="1" type="uint64"/>
</sbe:message>

<sbe:message name="SnapshotChunk" id="4">
    <field name="totalCount" id="0" type="int32"/>
    <field name="checksum" id="1" type="uint64"/>
    <data name="snapshotId" id="2" type="varDataEncoding"/>
    <data name="chunkName" id="3" type="varDataEncoding"/>
    <data name="content" id="4" type="blob"/>
</sbe:message>

<sbe:message name="LogReplicationRequest" id="5">
    <field name="fromPosition" id="0" type="uint64"/>
    <field name="toPosition" id="1" type="uint64"/>
    <field name="includeFromPosition" id="2" type="BooleanType"/>
</sbe:message>

<sbe:message name="LogReplicationResponse" id="6">
    <field name="toPosition" id="0" type="uint64"/>
    <field name="moreAvailable" id="1" type="BooleanType"/>
    <data name="serializedEvents" id="2" type="blob"/>
</sbe:message>

<sbe:message name="RestoreInfoRequest" id="7">
    <field name="latestLocalPosition" id="0" type="uint64"/>
    <field name="backupPosition" id="1" type="uint64"/>
</sbe:message>

<sbe:message name="RestoreInfoResponse" id="8">
    <field name="replicationTarget" id="0" type="uint8"/>
    <field name="snapshotId" id="1" type="uint64"/>
    <field name="numChunks" id="2" type="uint16"/>
</sbe:message>

<sbe:message name="SnapshotRestoreRequest" id="9">
    <field name="snapshotId" id="0" type="uint64"/>
    <field name="chunkIdx" id="1" type="uint16"/>
</sbe:message>

<sbe:message name="SnapshotRestoreResponse" id="10">
    <field name="success" id="0" type="BooleanType"/>
    <data name="snapshotChunk" id="1" type="blob"/>
</sbe:message>

</sbe:messageSchema>

4. subscription-schema.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <sbe:messageSchema xmlns:sbe="http://fixprotocol.io/2016/sbe" xmlns:xi="http://www.w3.org/2001/XInclude" package="command" id="2" version="1" semanticVersion="1.0.0" description="Kunpeng Subscription Protocol" byteOrder="littleEndian">

<xi:include href="common-types.xml"/>

<sbe:message name="OpenMessageSubscription" id="0">
    <field name="subscriptionPartitionId" id="0" type="uint16"/>
    <field name="workflowInstanceKey" id="1" type="uint64"/>
    <field name="elementInstanceKey" id="2" type="uint64"/>
    <field name="closeOnCorrelate" id="3" type="BooleanType"/>
    <data name="messageName" id="4" type="varDataEncoding"/>
    <data name="correlationKey" id="5" type="varDataEncoding"/>
    <data name="bpmnProcessId" id="6" type="varDataEncoding"/>
</sbe:message>

<sbe:message name="OpenWorkflowInstanceSubscription" id="1">
    <field name="subscriptionPartitionId" id="0" type="uint16"/>
    <field name="workflowInstanceKey" id="1" type="uint64"/>
    <field name="elementInstanceKey" id="2" type="uint64"/>
    <field name="closeOnCorrelate" id="3" type="BooleanType"/>
    <data name="messageName" id="4" type="varDataEncoding"/>
</sbe:message>

<sbe:message name="CorrelateWorkflowInstanceSubscription" id="2">
    <field name="subscriptionPartitionId" id="0" type="uint16"/>
    <field name="workflowInstanceKey" id="1" type="uint64"/>
    <field name="elementInstanceKey" id="2" type="uint64"/>
    <field name="messageKey" id="3" type="uint64"/>
    <data name="messageName" id="4" type="varDataEncoding"/>
    <data name="variables" id="5" type="varDataEncoding"/>
    <data name="bpmnProcessId" id="6" type="varDataEncoding"/>
    <data name="correlationKey" id="7" type="varDataEncoding"/>
</sbe:message>

<sbe:message name="CorrelateMessageSubscription" id="3">
    <field name="subscriptionPartitionId" id="0" type="uint16"/>
    <field name="workflowInstanceKey" id="1" type="uint64"/>
    <field name="elementInstanceKey" id="2" type="uint64"/>
    <data name="messageName" id="3" type="varDataEncoding"/>
    <data name="bpmnProcessId" id="4" type="varDataEncoding"/>
</sbe:message>

<sbe:message name="CloseMessageSubscription" id="4">
    <field name="subscriptionPartitionId" id="0" type="uint16"/>
    <field name="workflowInstanceKey" id="1" type="uint64"/>
    <field name="elementInstanceKey" id="2" type="uint64"/>
    <data name="messageName" id="3" type="varDataEncoding"/>
</sbe:message>

<sbe:message name="CloseWorkflowInstanceSubscription" id="5">
    <field name="subscriptionPartitionId" id="0" type="uint16"/>
    <field name="workflowInstanceKey" id="1" type="uint64"/>
    <field name="elementInstanceKey" id="2" type="uint64"/>
    <data name="messageName" id="3" type="varDataEncoding"/>
</sbe:message>

<sbe:message name="RejectCorrelateMessageSubscription" id="6">
    <field name="subscriptionPartitionId" id="0" type="uint16"/>
    <field name="workflowInstanceKey" id="1" type="uint64"/>
    <field name="messageKey" id="2" type="uint64"/>
    <data name="messageName" id="3" type="varDataEncoding"/>
    <data name="correlationKey" id="4" type="varDataEncoding"/>
    <data name="bpmnProcessId" id="5" type="varDataEncoding"/>
</sbe:message>

</sbe:messageSchema>

vontikov commented 4 months ago

Hi, I'll take a look in a couple of days. Regards, Vladimir Ontikov

пн, 6 мая 2024 г., 20:58 xuanhong @.***>:

question

  1. sbe.xinclude.aware set to true is invalid

image.png (view on web) https://github.com/vontikov/sbe-gradle-plugin/assets/62740686/0f9c8223-8fe2-4c74-ae46-fb8cd27579a6

  1. The same files can be used with custom JavaExec tasks without any problems ``` tasks.register('generateMessages', JavaExec) { mainClass = 'uk.co.real_logic.sbe.SbeTool' classpath = sourceSets.main.runtimeClasspath group = "sbe" systemProperties('sbe.output.dir': "build/generated/sources/sbe/main/java", 'sbe.target.language': 'Java', 'sbe.validation.stop.on.error': 'true', 'sbe.xinclude.aware': 'true') args = [ 'src/main/resources/sbe/management-schema.xml', 'src/main/resources/sbe/subscription-schema.xml' ] }

tasks.register('generateCompile', JavaCompile) { dependsOn "generateMessages" group = "sbe" source = project.fileTree(dir: "build/generated/sources/sbe/main/java", include: '*/.java') sourceCompatibility = JavaVersion.VERSION_21 targetCompatibility = JavaVersion.VERSION_21 destinationDirectory = project.file("build/generated/classes") classpath = sourceSets.main.runtimeClasspath }

sourceSets { main { java { srcDir 'build/generated/sources/sbe/main/java' } } }

test file

  1. common-types.xml
0 1
  1. management-schema.xml

<sbe:messageSchema xmlns:sbe="http://fixprotocol.io/2016/sbe" xmlns:xi="http://www.w3.org/2001/XInclude" package="clustering.management" id="0" version="1" semanticVersion="1.0.0" description="Kunpeng Cluster Management Protocol" byteOrder="littleEndian">

0 1 2 3. subscription-schema.xml — Reply to this email directly, view it on GitHub , or unsubscribe . You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
vontikov commented 3 months ago

XML validation which was enabled by default is not compatible with XInclude.
I've published a new release (https://github.com/vontikov/sbe-gradle-plugin/releases/tag/v0.0.9, https://plugins.gradle.org/plugin/com.github.vontikov.sbe-generator-plugin) where XML validation is disabled by default for convenience. I also updated the example to demonstrate XInclude usage: https://github.com/vontikov/sbe-example/blob/master/src/main/resources/schemas/schema.xml

zxuanhong commented 3 months ago

@vontikov Thank you very much!