Skip to content

Commit 578ac13

Browse files
committed
[Java] Generate package-info.java for codecs. Issue #703.
1 parent 67b3f3b commit 578ac13

File tree

10 files changed

+47
-11
lines changed

10 files changed

+47
-11
lines changed

build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ project(':sbe-samples') {
409409
classpath = sourceSets.main.runtimeClasspath
410410
main = 'uk.co.real_logic.sbe.examples.OtfExample'
411411
workingDir = 'src/main/resources'
412-
systemProperties System.getProperties()
413412
}
414413

415414
task runJavaExamples {

sbe-samples/src/main/resources/example-extension-schema.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
id="1"
66
version="1"
77
semanticVersion="5.2"
8-
description="Example schema with extension"
8+
description="Example schema which extends baseline schema."
99
byteOrder="littleEndian">
1010
<xi:include href="common-types.xml"/>
1111
<types>

sbe-samples/src/main/resources/example-schema.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
id="1"
66
version="0"
77
semanticVersion="5.2"
8-
description="Example schema"
8+
description="Example base schema which can be extended."
99
byteOrder="littleEndian">
1010
<xi:include href="common-types.xml"/>
1111
<types>

sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaGenerator.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ enum CodecType
4646
}
4747

4848
private static final String META_ATTRIBUTE_ENUM = "MetaAttribute";
49+
private static final String PACKAGE_INFO = "package-info";
4950
private static final String BASE_INDENT = "";
5051
private static final String INDENT = " ";
5152
private static final String FLYWEIGHT = "Flyweight";
@@ -165,6 +166,7 @@ public void generateTypeStubs() throws IOException
165166

166167
public void generate() throws IOException
167168
{
169+
generatePackageInfo();
168170
generateTypeStubs();
169171
generateMessageHeaderStub();
170172

@@ -1652,13 +1654,28 @@ private static CharSequence generateDeclaration(
16521654
implementsString);
16531655
}
16541656

1657+
private void generatePackageInfo() throws IOException
1658+
{
1659+
try (Writer out = outputManager.createOutput(PACKAGE_INFO))
1660+
{
1661+
out.append(
1662+
"/* Generated SBE (Simple Binary Encoding) message codecs.*/\n" +
1663+
"/**\n" +
1664+
" * ").append(ir.description()).append("\n")
1665+
.append(
1666+
" */\n" +
1667+
"package ").append(ir.applicableNamespace()).append(";\n");
1668+
}
1669+
}
1670+
16551671
private void generateMetaAttributeEnum() throws IOException
16561672
{
16571673
try (Writer out = outputManager.createOutput(META_ATTRIBUTE_ENUM))
16581674
{
1659-
out.append(String.format(
1675+
out.append(
16601676
"/* Generated SBE (Simple Binary Encoding) message codec. */\n" +
1661-
"package %s;\n\n" +
1677+
"package ").append(ir.applicableNamespace()).append(";\n\n")
1678+
.append(
16621679
"/**\n" +
16631680
" * Meta attribute enum for selecting a particular meta attribute value.\n" +
16641681
" */\n" +
@@ -1680,8 +1697,7 @@ private void generateMetaAttributeEnum() throws IOException
16801697
" * Field presence indication. Can be optional, required, or constant.\n" +
16811698
" */\n" +
16821699
" PRESENCE\n" +
1683-
"}\n",
1684-
ir.applicableNamespace()));
1700+
"}\n");
16851701
}
16861702
}
16871703

sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/Ir.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class Ir
3333
private final String namespaceName;
3434
private final int id;
3535
private final int version;
36+
private final String description;
3637
private final String semanticVersion;
3738
private final ByteOrder byteOrder;
3839

@@ -48,7 +49,8 @@ public class Ir
4849
* @param packageName that should be applied to generated code.
4950
* @param namespaceName that should be applied to generated code.
5051
* @param id identifier for the schema.
51-
* @param version of the schema
52+
* @param version of the schema.
53+
* @param description of the schema.
5254
* @param semanticVersion semantic version for mapping to the application domain.
5355
* @param byteOrder byte order for all types in the schema.
5456
* @param headerTokens representing the message headerStructure.
@@ -58,6 +60,7 @@ public Ir(
5860
final String namespaceName,
5961
final int id,
6062
final int version,
63+
final String description,
6164
final String semanticVersion,
6265
final ByteOrder byteOrder,
6366
final List<Token> headerTokens)
@@ -69,6 +72,7 @@ public Ir(
6972
this.namespaceName = namespaceName;
7073
this.id = id;
7174
this.version = version;
75+
this.description = description;
7276
this.semanticVersion = semanticVersion;
7377
this.byteOrder = byteOrder;
7478
this.headerStructure = new HeaderStructure(new ArrayList<>(headerTokens));
@@ -203,6 +207,16 @@ public int version()
203207
return version;
204208
}
205209

210+
/**
211+
* Get the description for the schema.
212+
*
213+
* @return the description for the schema.
214+
*/
215+
public String description()
216+
{
217+
return description;
218+
}
219+
206220
/**
207221
* Get the semantic version of the schema.
208222
*

sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/IrDecoder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ public Ir decode()
121121
}
122122

123123
final ByteOrder byteOrder = tokens.size() > 0 ? tokens.get(0).encoding().byteOrder() : null;
124-
final Ir ir = new Ir(irPackageName, irNamespaceName, irId, irVersion, semanticVersion, byteOrder, irHeader);
124+
final Ir ir = new Ir(
125+
irPackageName, irNamespaceName, irId, irVersion, null, semanticVersion, byteOrder, irHeader);
125126

126127
for (int size = tokens.size(); i < size; i++)
127128
{
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* Generated SBE (Simple Binary Encoding) message codecs.*/
2+
/**
3+
* SBE IR Serialization Codecs.
4+
*/
5+
package uk.co.real_logic.sbe.ir.generated;

sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/IrGenerator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public Ir generate(final MessageSchema schema, final String namespace)
5050
namespace,
5151
schema.id(),
5252
schema.version(),
53+
schema.description(),
5354
schema.semanticVersion(),
5455
schema.byteOrder(),
5556
headerTokens);

sbe-tool/src/main/resources/sbe-ir.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
id="1"
55
version="0"
66
byteOrder="littleEndian"
7-
description="SBE IR Serialization">
7+
description="SBE IR Serialization Codecs.">
88
<types>
99
<composite name="messageHeader" description="Message identifiers and length of message root">
1010
<type name="blockLength" primitiveType="uint16"/>

sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/rust/RustTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void happyPathRustGeneratorThatThrowsNoExceptions() throws IOException
4343

4444
static Ir minimalDummyIr()
4545
{
46-
return new Ir("a", "b", 0, 1, "2", ByteOrder.BIG_ENDIAN,
46+
return new Ir("a", "b", 0, 1, null, "2", ByteOrder.BIG_ENDIAN,
4747
Arrays.asList(
4848
dummyToken(Signal.ENCODING, HeaderStructure.BLOCK_LENGTH),
4949
dummyToken(Signal.ENCODING, HeaderStructure.SCHEMA_ID),

0 commit comments

Comments
 (0)