From 20efc51365db1b4c050a8da75a9f6a95571a0330 Mon Sep 17 00:00:00 2001 From: ratcash Date: Tue, 5 Jul 2022 21:59:45 +0200 Subject: [PATCH 01/11] Adding support for the package attribute on the types element. --- .../java/uk/co/real_logic/sbe/SbeTool.java | 8 ++ .../generation/MultiPackageOutputManager.java | 30 +++++ .../generation/TargetCodeGeneratorLoader.java | 5 +- .../sbe/generation/java/JavaGenerator.java | 83 +++++++++++-- .../generation/java/JavaOutputManager.java | 79 +++++++++++++ .../java/uk/co/real_logic/sbe/ir/Token.java | 28 +++++ .../real_logic/sbe/xml/EncodedDataType.java | 27 ++++- .../uk/co/real_logic/sbe/xml/IrGenerator.java | 7 +- .../java/uk/co/real_logic/sbe/xml/Type.java | 40 ++++++- .../real_logic/sbe/xml/XmlSchemaParser.java | 12 ++ .../java/CharacterEncodingTest.java | 1 - .../java/ConstantCharArrayTest.java | 1 - .../java/FixedSizeDataGeneratorTest.java | 1 - .../java/GenerateFixBinaryTest.java | 1 - .../java/GenerateIlinkBinaryTest.java | 1 - .../generation/java/JavaGeneratorTest.java | 65 ++++++++++- .../java/JavaOutputManagerTest.java | 65 +++++++++++ .../generation/java/NullEnumTypedTest.java | 1 - .../generation/java/SchemaExtensionTest.java | 1 - .../java/StringWriterOutputManager.java | 110 ++++++++++++++++++ .../explicit-package-test-schema.xml | 45 +++++++ 21 files changed, 589 insertions(+), 22 deletions(-) create mode 100644 sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/MultiPackageOutputManager.java create mode 100644 sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaOutputManager.java create mode 100644 sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/JavaOutputManagerTest.java create mode 100644 sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/StringWriterOutputManager.java create mode 100644 sbe-tool/src/test/resources/explicit-package-test-schema.xml diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/SbeTool.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/SbeTool.java index f954685139..13315c4ebc 100644 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/SbeTool.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/SbeTool.java @@ -60,6 +60,8 @@ *
  • sbe.keyword.append.token: Token to be appended to keywords.
  • *
  • sbe.decode.unknown.enum.values: Support unknown decoded enum values. Defaults to false.
  • *
  • sbe.xinclude.aware: Is XInclude supported for the schema. Defaults to false.
  • + *
  • sbe.type.package.override: Is a package attribute for types element supported (only for JAVA). Defaults to + * false.
  • * */ public class SbeTool @@ -109,6 +111,12 @@ public class SbeTool */ public static final String XINCLUDE_AWARE = "sbe.xinclude.aware"; + /** + * Boolean system property to control the support of package names in {@code } elements. + * Part of SBE v2-rc2. Defaults to false. + */ + public static final String TYPE_PACKAGE_OVERRIDE = "sbe.type.package.override"; + /** * Target language for generated code. */ diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/MultiPackageOutputManager.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/MultiPackageOutputManager.java new file mode 100644 index 0000000000..4b01b8017c --- /dev/null +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/MultiPackageOutputManager.java @@ -0,0 +1,30 @@ +/* + * Copyright 2013-2022 Real Logic Limited. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package uk.co.real_logic.sbe.generation; + +import org.agrona.generation.OutputManager; + +/** + * Extended version of the OutputManager allowing to set the java package. To be moved to agrona. + */ +public interface MultiPackageOutputManager extends OutputManager +{ + /** + * Sets the current package name. + * @param packageName the packageName + */ + void setPackageName(String packageName); +} diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/TargetCodeGeneratorLoader.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/TargetCodeGeneratorLoader.java index 07065da1ac..6f1e68f08c 100644 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/TargetCodeGeneratorLoader.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/TargetCodeGeneratorLoader.java @@ -15,7 +15,7 @@ */ package uk.co.real_logic.sbe.generation; -import org.agrona.generation.PackageOutputManager; +import uk.co.real_logic.sbe.generation.java.JavaOutputManager; import uk.co.real_logic.sbe.generation.c.CGenerator; import uk.co.real_logic.sbe.generation.c.COutputManager; import uk.co.real_logic.sbe.generation.cpp.CppGenerator; @@ -52,7 +52,8 @@ public CodeGenerator newInstance(final Ir ir, final String outputDir) "true".equals(System.getProperty(JAVA_GROUP_ORDER_ANNOTATION)), "true".equals(System.getProperty(JAVA_GENERATE_INTERFACES)), "true".equals(System.getProperty(DECODE_UNKNOWN_ENUM_VALUES)), - new PackageOutputManager(outputDir, ir.applicableNamespace())); + "true".equals(System.getProperty(TYPE_PACKAGE_OVERRIDE)), + new JavaOutputManager(outputDir, ir.applicableNamespace())); } }, diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaGenerator.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaGenerator.java index d9ed796c4c..408a129ad2 100644 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaGenerator.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaGenerator.java @@ -19,7 +19,6 @@ import org.agrona.MutableDirectBuffer; import org.agrona.Strings; import org.agrona.Verify; -import org.agrona.generation.OutputManager; import org.agrona.sbe.*; import uk.co.real_logic.sbe.PrimitiveType; import uk.co.real_logic.sbe.generation.CodeGenerator; @@ -30,7 +29,9 @@ import java.io.Writer; import java.util.ArrayList; import java.util.Formatter; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.function.Function; import static uk.co.real_logic.sbe.SbeTool.JAVA_INTERFACE_PACKAGE; @@ -38,6 +39,7 @@ import static uk.co.real_logic.sbe.generation.java.JavaGenerator.CodecType.ENCODER; import static uk.co.real_logic.sbe.generation.java.JavaUtil.*; import static uk.co.real_logic.sbe.ir.GenerationUtil.*; +import uk.co.real_logic.sbe.generation.MultiPackageOutputManager; /** * Generate codecs for the Java 8 programming language. @@ -60,7 +62,7 @@ enum CodecType private static final String INDENT = " "; private final Ir ir; - private final OutputManager outputManager; + private final MultiPackageOutputManager outputManager; private final String fqMutableBuffer; private final String mutableBuffer; private final String fqReadOnlyBuffer; @@ -68,6 +70,32 @@ enum CodecType private final boolean shouldGenerateGroupOrderAnnotation; private final boolean shouldGenerateInterfaces; private final boolean shouldDecodeUnknownEnumValues; + private final boolean shouldSupportTypePackages; + private final Set typePackages = new HashSet<>(); + + /** + * Create a new Java language {@link CodeGenerator}. Generator support for types in their own package is disabled. + * + * @param ir for the messages and types. + * @param mutableBuffer implementation used for mutating underlying buffers. + * @param readOnlyBuffer implementation used for reading underlying buffers. + * @param shouldGenerateGroupOrderAnnotation in the codecs. + * @param shouldGenerateInterfaces for common methods. + * @param shouldDecodeUnknownEnumValues generate support for unknown enum values when decoding. + * @param outputManager for generating the codecs to. + */ + public JavaGenerator( + final Ir ir, + final String mutableBuffer, + final String readOnlyBuffer, + final boolean shouldGenerateGroupOrderAnnotation, + final boolean shouldGenerateInterfaces, + final boolean shouldDecodeUnknownEnumValues, + final MultiPackageOutputManager outputManager) + { + this(ir, mutableBuffer, readOnlyBuffer, shouldGenerateGroupOrderAnnotation, shouldGenerateInterfaces, + shouldDecodeUnknownEnumValues, false, outputManager); + } /** * Create a new Java language {@link CodeGenerator}. @@ -78,6 +106,7 @@ enum CodecType * @param shouldGenerateGroupOrderAnnotation in the codecs. * @param shouldGenerateInterfaces for common methods. * @param shouldDecodeUnknownEnumValues generate support for unknown enum values when decoding. + * @param shouldSupportTypePackages generator support for types in their own package * @param outputManager for generating the codecs to. */ public JavaGenerator( @@ -87,12 +116,14 @@ public JavaGenerator( final boolean shouldGenerateGroupOrderAnnotation, final boolean shouldGenerateInterfaces, final boolean shouldDecodeUnknownEnumValues, - final OutputManager outputManager) + final boolean shouldSupportTypePackages, + final MultiPackageOutputManager outputManager) { Verify.notNull(ir, "ir"); Verify.notNull(outputManager, "outputManager"); this.ir = ir; + this.shouldSupportTypePackages = shouldSupportTypePackages; this.outputManager = outputManager; this.mutableBuffer = validateBufferImplementation(mutableBuffer, MutableDirectBuffer.class); @@ -144,11 +175,30 @@ public void generateTypeStubs() throws IOException } } + /** + * Register the the type's explicit package - if it's set and should be supported. + * + * @param token the 0-th token of the type + * @param ir the intermediate representation + * @return the overriden package name of the type if set and supported, or {@link Ir#applicableNamespace() } + */ + private String registerTypePackage(final Token token, final Ir ir) + { + if (shouldSupportTypePackages && token.packageName() != null) + { + typePackages.add(token.packageName()); + outputManager.setPackageName(token.packageName()); + return token.packageName(); + } + return ir.applicableNamespace(); + } + /** * {@inheritDoc} */ public void generate() throws IOException { + typePackages.clear(); generatePackageInfo(); generateTypeStubs(); generateMessageHeaderStub(); @@ -1188,6 +1238,7 @@ private void generateBitSet(final List tokens) throws IOException final List messageBody = getMessageBody(tokens); final String implementsString = implementsInterface(Flyweight.class.getSimpleName()); + registerTypePackage(token, ir); try (Writer out = outputManager.createOutput(decoderName)) { generateFixedFlyweightHeader(out, token, decoderName, implementsString, readOnlyBuffer, fqReadOnlyBuffer); @@ -1197,6 +1248,7 @@ private void generateBitSet(final List tokens) throws IOException out.append("}\n"); } + registerTypePackage(token, ir); try (Writer out = outputManager.createOutput(encoderName)) { generateFixedFlyweightHeader(out, token, encoderName, implementsString, mutableBuffer, fqMutableBuffer); @@ -1214,7 +1266,8 @@ private void generateFixedFlyweightHeader( final String buffer, final String fqBuffer) throws IOException { - out.append(generateFileHeader(ir.applicableNamespace(), fqBuffer)); + final String packageName = registerTypePackage(token, ir); + out.append(generateFileHeader(packageName, fqBuffer)); out.append(generateDeclaration(typeName, implementsString, token)); out.append(generateFixedFlyweightCode(typeName, token.encodedLength(), buffer)); } @@ -1227,7 +1280,8 @@ private void generateCompositeFlyweightHeader( final String fqBuffer, final String implementsString) throws IOException { - out.append(generateFileHeader(ir.applicableNamespace(), fqBuffer)); + final String packageName = registerTypePackage(token, ir); + out.append(generateFileHeader(packageName, fqBuffer)); out.append(generateDeclaration(typeName, implementsString, token)); out.append(generateFixedFlyweightCode(typeName, token.encodedLength(), buffer)); } @@ -1239,9 +1293,10 @@ private void generateEnum(final List tokens) throws IOException final Encoding encoding = enumToken.encoding(); final String nullVal = encoding.applicableNullValue().toString(); + final String packageName = registerTypePackage(enumToken, ir); try (Writer out = outputManager.createOutput(enumName)) { - out.append(generateEnumFileHeader(ir.applicableNamespace())); + out.append(generateEnumFileHeader(packageName)); out.append(generateEnumDeclaration(enumName, enumToken)); out.append(generateEnumValues(getMessageBody(tokens), generateLiteral(encoding.primitiveType(), nullVal))); @@ -1260,6 +1315,7 @@ private void generateComposite(final List tokens) throws IOException final String decoderName = decoderName(compositeName); final String encoderName = encoderName(compositeName); + registerTypePackage(token, ir); try (Writer out = outputManager.createOutput(decoderName)) { final String implementsString = implementsInterface(CompositeDecoderFlyweight.class.getSimpleName()); @@ -1308,6 +1364,7 @@ private void generateComposite(final List tokens) throws IOException out.append("}\n"); } + registerTypePackage(token, ir); try (Writer out = outputManager.createOutput(encoderName)) { final String implementsString = implementsInterface(CompositeEncoderFlyweight.class.getSimpleName()); @@ -1560,13 +1617,22 @@ private CharSequence generateFileHeader(final String packageName, final String f private CharSequence generateMainHeader( final String packageName, final CodecType codecType, final boolean hasVarData) { + final StringBuffer packageImports = new StringBuffer(); + for (final String typePackage : typePackages) + { + packageImports.append("import "); + packageImports.append(typePackage); + packageImports.append(".*;\n"); + } + if (fqMutableBuffer.equals(fqReadOnlyBuffer)) { return "/* Generated SBE (Simple Binary Encoding) message codec. */\n" + "package " + packageName + ";\n\n" + "import " + fqMutableBuffer + ";\n" + - interfaceImportLine(); + interfaceImportLine() + + packageImports.toString(); } else { @@ -1578,7 +1644,8 @@ private CharSequence generateMainHeader( "package " + packageName + ";\n\n" + (hasMutableBuffer ? "import " + fqMutableBuffer + ";\n" : "") + (hasReadOnlyBuffer ? "import " + fqReadOnlyBuffer + ";\n" : "") + - interfaceImportLine(); + interfaceImportLine() + + packageImports.toString(); } } diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaOutputManager.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaOutputManager.java new file mode 100644 index 0000000000..2ac0de0ffa --- /dev/null +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaOutputManager.java @@ -0,0 +1,79 @@ +/* + * Copyright 2013-2022 Real Logic Limited. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package uk.co.real_logic.sbe.generation.java; + +import java.io.FilterWriter; +import java.io.IOException; +import java.io.Writer; +import org.agrona.collections.Object2NullableObjectHashMap; +import org.agrona.collections.Object2ObjectHashMap; +import org.agrona.generation.PackageOutputManager; +import uk.co.real_logic.sbe.generation.MultiPackageOutputManager; + +/** + * Implementation of {@link MultiPackageOutputManager} for Java. + */ +public class JavaOutputManager implements MultiPackageOutputManager +{ + + private final String baseDirName; + private final PackageOutputManager global; + private PackageOutputManager acting; + private final Object2ObjectHashMap outputManagerCache + = new Object2NullableObjectHashMap<>(); + + /** + * Constructor. + * @param baseDirName the target directory + * @param packageName the initial package name + */ + public JavaOutputManager(final String baseDirName, final String packageName) + { + global = new PackageOutputManager(baseDirName, packageName); + acting = global; + this.baseDirName = baseDirName; + } + + @Override + public void setPackageName(final String packageName) + { + acting = outputManagerCache.get(packageName); + if (acting == null) + { + acting = new PackageOutputManager(baseDirName, packageName); + outputManagerCache.put(packageName, acting); + } + } + + private void resetPackage() + { + acting = global; + } + + @Override + public Writer createOutput(final String name) throws IOException + { + return new FilterWriter(acting.createOutput(name)) + { + @Override + public void close() throws IOException + { + super.close(); + resetPackage(); + } + }; + } +} diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/Token.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/Token.java index d9a09966f2..252418cfc1 100644 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/Token.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/Token.java @@ -77,6 +77,7 @@ public class Token private final Signal signal; private final String name; + private final String packageName; private final String referencedName; private final String description; private final int id; @@ -92,6 +93,7 @@ public class Token * * @param signal for the token role. * @param name of the token in the message. + * @param packageName of the token in the message. * @param referencedName of the type when created from a ref in a composite. * @param description of what the token is for. * @param id as the identifier in the message declaration. @@ -105,6 +107,7 @@ public class Token public Token( final Signal signal, final String name, + final String packageName, final String referencedName, final String description, final int id, @@ -130,6 +133,7 @@ public Token( this.offset = offset; this.componentTokenCount = componentTokenCount; this.encoding = encoding; + this.packageName = packageName; } /** @@ -152,6 +156,16 @@ public String name() return name; } + /** + * Return the packageName of the token + * + * @return packageName of the token + */ + public String packageName() + { + return packageName; + } + /** * Get the name of the type when this is from a reference. * @@ -361,6 +375,7 @@ public static class Builder { private Signal signal; private String name; + private String packageName; private String referencedName; private String description; private int id = INVALID_ID; @@ -395,6 +410,18 @@ public Builder name(final String name) return this; } + /** + * Name for the Token. + * + * @param packageName for the Token. + * @return this for a fluent API. + */ + public Builder packageName(final String packageName) + { + this.packageName = packageName; + return this; + } + /** * Referenced type name for the Token. * @@ -513,6 +540,7 @@ public Token build() return new Token( signal, name, + packageName, referencedName, description, id, diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/EncodedDataType.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/EncodedDataType.java index fc26d9cbdc..064b5358e6 100644 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/EncodedDataType.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/EncodedDataType.java @@ -218,7 +218,32 @@ public EncodedDataType( final int length, final boolean varLen) { - super(name, presence, description, 0, 0, semanticType); + this(name, null, presence, description, semanticType, primitiveType, length, varLen); + } + + /** + * Construct a new EncodedDataType with direct values.Does not handle constant values. + * + * @param name of the type + * @param packageName of the type + * @param presence of the type + * @param description of the type or null + * @param semanticType of the type or null + * @param primitiveType of the EncodedDataType + * @param length of the EncodedDataType + * @param varLen of the EncodedDataType + */ + public EncodedDataType( + final String name, + final String packageName, + final Presence presence, + final String description, + final String semanticType, + final PrimitiveType primitiveType, + final int length, + final boolean varLen) + { + super(name, packageName, presence, description, 0, 0, semanticType); this.primitiveType = primitiveType; this.length = length; diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/IrGenerator.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/IrGenerator.java index 87e3e4717d..74a97f5d91 100644 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/IrGenerator.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/IrGenerator.java @@ -211,6 +211,7 @@ private void add(final CompositeType type, final int currOffset, final Field fie final Token.Builder builder = new Token.Builder() .signal(Signal.BEGIN_COMPOSITE) .name(type.name()) + .packageName(type.packageName()) .referencedName(type.referencedName()) .offset(currOffset) .size(type.encodedLength()) @@ -269,6 +270,7 @@ private void add(final EnumType type, final int offset, final Field field) final Token.Builder builder = new Token.Builder() .signal(Signal.BEGIN_ENUM) .name(type.name()) + .packageName(type.packageName()) .referencedName(type.referencedName()) .size(encodingType.size()) .offset(offset) @@ -325,6 +327,7 @@ private void add(final SetType type, final int offset, final Field field) final Token.Builder builder = new Token.Builder() .signal(Signal.BEGIN_SET) .name(type.name()) + .packageName(type.packageName()) .referencedName(type.referencedName()) .size(encodingType.size()) .offset(offset) @@ -379,6 +382,7 @@ private void add(final EncodedDataType type, final int offset) final Token.Builder tokenBuilder = new Token.Builder() .signal(Signal.ENCODING) .name(type.name()) + .packageName(type.packageName()) .referencedName(type.referencedName()) .size(type.encodedLength()) .description(type.description()) @@ -428,6 +432,7 @@ private void add(final EncodedDataType type, final int offset, final Field field final Token.Builder tokenBuilder = new Token.Builder() .signal(Signal.ENCODING) .name(type.name()) + .packageName(type.packageName()) .referencedName(type.referencedName()) .size(type.encodedLength()) .description(type.description()) @@ -514,4 +519,4 @@ private Encoding.Presence mapPresence(final Presence presence) return encodingPresence; } -} \ No newline at end of file +} diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/Type.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/Type.java index 8a1e491ff4..e6bec463a0 100644 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/Type.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/Type.java @@ -19,6 +19,7 @@ import static uk.co.real_logic.sbe.xml.XmlSchemaParser.getAttributeValue; import static uk.co.real_logic.sbe.xml.XmlSchemaParser.getAttributeValueOrNull; +import static uk.co.real_logic.sbe.xml.XmlSchemaParser.getTypesPackageAttribute; /** * An SBE type. One of encodedDataType, compositeType, enumType, or setType per the SBE spec. @@ -26,6 +27,7 @@ public abstract class Type { private final String name; + private final String packageName; private final Presence presence; private final String description; private final int deprecated; @@ -36,7 +38,7 @@ public abstract class Type private int sinceVersion; /** - * Construct a new Type from XML Schema. Called by subclasses to mostly set common fields + * Construct a new Type from XML Schema.Called by subclasses to mostly set common fields * * @param node from the XML Schema Parsing * @param givenName of this node, if null then the attributed name will be used. @@ -54,7 +56,7 @@ public Type(final Node node, final String givenName, final String referencedName } this.referencedName = referencedName; - + packageName = getTypesPackageAttribute(node); presence = Presence.get(getAttributeValue(node, "presence", "required")); description = getAttributeValueOrNull(node, "description"); sinceVersion = Integer.parseInt(getAttributeValue(node, "sinceVersion", "0")); @@ -63,10 +65,32 @@ public Type(final Node node, final String givenName, final String referencedName offsetAttribute = Integer.parseInt(getAttributeValue(node, "offset", "-1")); } + /** + * Construct a new Type from direct values. + * + * @param name of the type + * @param presence of the type + * @param description of the type or null + * @param sinceVersion for the type + * @param deprecated version in which this was deprecated. + * @param semanticType of the type or null + */ + public Type( + final String name, + final Presence presence, + final String description, + final int sinceVersion, + final int deprecated, + final String semanticType) + { + this(name, null, presence, description, sinceVersion, deprecated, semanticType); + } + /** * Construct a new Type from direct values. * * @param name of the type + * @param packageName of the type * @param presence of the type * @param description of the type or null * @param sinceVersion for the type @@ -75,6 +99,7 @@ public Type(final Node node, final String givenName, final String referencedName */ public Type( final String name, + final String packageName, final Presence presence, final String description, final int sinceVersion, @@ -82,6 +107,7 @@ public Type( final String semanticType) { this.name = name; + this.packageName = packageName; this.presence = presence; this.description = description; this.sinceVersion = sinceVersion; @@ -206,4 +232,14 @@ public void offsetAttribute(final int offsetAttribute) { this.offsetAttribute = offsetAttribute; } + + /** + * Return the packageName attribute of the {@link Type} from the schema + * + * @return the packageName attribute value or null, if not explicitely defined by the schema + */ + public String packageName() + { + return packageName; + } } diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/XmlSchemaParser.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/XmlSchemaParser.java index fbc66f9888..455278d707 100644 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/XmlSchemaParser.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/XmlSchemaParser.java @@ -326,6 +326,18 @@ public static String getAttributeValue(final Node elementNode, final String attr return attrNode.getNodeValue(); } + /** + * To be used with child elements of {@code } elements. Returns the package attribute as + * defined on the parent {@code } element + * + * @param elementNode the node inside the types element + * @return the package name, or null if not defined + */ + public static String getTypesPackageAttribute(final Node elementNode) + { + return getAttributeValue(elementNode.getParentNode(), "package", null); + } + /** * Helper function that hides the null return from {@link org.w3c.dom.NamedNodeMap#getNamedItem(String)}. * diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/CharacterEncodingTest.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/CharacterEncodingTest.java index bc380a4665..729b36eebd 100644 --- a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/CharacterEncodingTest.java +++ b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/CharacterEncodingTest.java @@ -17,7 +17,6 @@ import org.agrona.DirectBuffer; import org.agrona.MutableDirectBuffer; -import org.agrona.generation.StringWriterOutputManager; import org.junit.jupiter.api.Test; import uk.co.real_logic.sbe.ir.Ir; import uk.co.real_logic.sbe.xml.IrGenerator; diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/ConstantCharArrayTest.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/ConstantCharArrayTest.java index 1141e5c983..d31e95aecd 100644 --- a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/ConstantCharArrayTest.java +++ b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/ConstantCharArrayTest.java @@ -17,7 +17,6 @@ import org.agrona.DirectBuffer; import org.agrona.MutableDirectBuffer; -import org.agrona.generation.StringWriterOutputManager; import org.junit.jupiter.api.Test; import uk.co.real_logic.sbe.Tests; import uk.co.real_logic.sbe.ir.Ir; diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/FixedSizeDataGeneratorTest.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/FixedSizeDataGeneratorTest.java index 8edb42474c..c7d0400e47 100644 --- a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/FixedSizeDataGeneratorTest.java +++ b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/FixedSizeDataGeneratorTest.java @@ -19,7 +19,6 @@ import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; import org.agrona.generation.CompilerUtil; -import org.agrona.generation.StringWriterOutputManager; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import uk.co.real_logic.sbe.Tests; diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/GenerateFixBinaryTest.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/GenerateFixBinaryTest.java index 09274ec5f7..4a1f45d66e 100644 --- a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/GenerateFixBinaryTest.java +++ b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/GenerateFixBinaryTest.java @@ -18,7 +18,6 @@ import org.agrona.DirectBuffer; import org.agrona.MutableDirectBuffer; import org.agrona.generation.CompilerUtil; -import org.agrona.generation.StringWriterOutputManager; import org.junit.jupiter.api.Test; import uk.co.real_logic.sbe.SbeTool; import uk.co.real_logic.sbe.Tests; diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/GenerateIlinkBinaryTest.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/GenerateIlinkBinaryTest.java index a8c9e2676a..d202ee0c46 100644 --- a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/GenerateIlinkBinaryTest.java +++ b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/GenerateIlinkBinaryTest.java @@ -18,7 +18,6 @@ import org.agrona.DirectBuffer; import org.agrona.MutableDirectBuffer; import org.agrona.generation.CompilerUtil; -import org.agrona.generation.StringWriterOutputManager; import org.junit.jupiter.api.Test; import uk.co.real_logic.sbe.SbeTool; import uk.co.real_logic.sbe.Tests; diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/JavaGeneratorTest.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/JavaGeneratorTest.java index 6ad49097bd..4044a0bf26 100644 --- a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/JavaGeneratorTest.java +++ b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/JavaGeneratorTest.java @@ -19,7 +19,6 @@ import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; import org.agrona.generation.CompilerUtil; -import org.agrona.generation.StringWriterOutputManager; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import uk.co.real_logic.sbe.Tests; @@ -481,6 +480,70 @@ void shouldMarkDeprecatedClasses() throws Exception assertTrue(decoderClazz.isAnnotationPresent(Deprecated.class)); } + @Test + void shouldCreateTypesInDifferentPackages() throws Exception + { + final ParserOptions options = ParserOptions.builder().stopOnError(true).build(); + final MessageSchema schema = parse(Tests.getLocalResource("explicit-package-test-schema.xml"), options); + final IrGenerator irg = new IrGenerator(); + ir = irg.generate(schema); + + outputManager.clear(); + outputManager.setPackageName(ir.applicableNamespace()); + + JavaGenerator generator = new JavaGenerator(ir, BUFFER_NAME, READ_ONLY_BUFFER_NAME, false, false, false, true, + outputManager); + + generator.generate(); + final String encoderFqcn = ir.applicableNamespace() + ".TestMessageEncoder"; + final Class encoderClazz = compile(encoderFqcn); + assertNotNull(encoderClazz); + + final String decoderFqcn = ir.applicableNamespace() + ".TestMessageDecoder"; + final Class decoderClazz = compile(decoderFqcn); + assertNotNull(decoderClazz); + + final Map sources = outputManager.getSources(); + assertNotNull(sources.get("test.message.schema.common.CarEncoder")); + assertNotNull(sources.get("test.message.schema.common.CarDecoder")); + assertNotNull(sources.get("outside.schema.BooleanType")); + assertNotNull(sources.get("outside.schema.DaysEncoder")); + assertNotNull(sources.get("outside.schema.DaysDecoder")); + assertNotNull(sources.get(ir.applicableNamespace() + ".MessageHeaderEncoder")); + } + + @Test + void shouldCreateTypesInSamePackageIfSupportDisabled() throws Exception + { + final ParserOptions options = ParserOptions.builder().stopOnError(true).build(); + final MessageSchema schema = parse(Tests.getLocalResource("explicit-package-test-schema.xml"), options); + final IrGenerator irg = new IrGenerator(); + ir = irg.generate(schema); + + outputManager.clear(); + outputManager.setPackageName(ir.applicableNamespace()); + + JavaGenerator generator = new JavaGenerator(ir, BUFFER_NAME, READ_ONLY_BUFFER_NAME, false, false, false, false, + outputManager); + + generator.generate(); + final String encoderFqcn = ir.applicableNamespace() + ".TestMessageEncoder"; + final Class encoderClazz = compile(encoderFqcn); + assertNotNull(encoderClazz); + + final String decoderFqcn = ir.applicableNamespace() + ".TestMessageDecoder"; + final Class decoderClazz = compile(decoderFqcn); + assertNotNull(decoderClazz); + + final Map sources = outputManager.getSources(); + assertNotNull(sources.get(ir.applicableNamespace() + ".CarEncoder")); + assertNotNull(sources.get(ir.applicableNamespace() + ".CarDecoder")); + assertNotNull(sources.get(ir.applicableNamespace() + ".BooleanType")); + assertNotNull(sources.get(ir.applicableNamespace() + ".DaysEncoder")); + assertNotNull(sources.get(ir.applicableNamespace() + ".DaysDecoder")); + assertNotNull(sources.get(ir.applicableNamespace() + ".MessageHeaderEncoder")); + } + private Class getModelClass(final Object encoder) throws ClassNotFoundException { final String className = "Model"; diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/JavaOutputManagerTest.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/JavaOutputManagerTest.java new file mode 100644 index 0000000000..aeb6516b28 --- /dev/null +++ b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/JavaOutputManagerTest.java @@ -0,0 +1,65 @@ +package uk.co.real_logic.sbe.generation.java; + +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; + +public class JavaOutputManagerTest +{ + + private final String tempDirName = System.getProperty("java.io.tmpdir"); + + @Test + void shouldCreateFileWithinPackage() throws Exception + { + final String packageName = "uk.co.real_logic.test"; + final String exampleClassName = "ExampleClassName"; + + final JavaOutputManager cut = new JavaOutputManager(tempDirName, packageName); + final Writer out = cut.createOutput(exampleClassName); + out.close(); + + final String typePackageName = "uk.co.real_logic.common"; + final String typeClassName = "CompositeBigDecimal"; + cut.setPackageName(typePackageName); + final Writer typeOut = cut.createOutput(typeClassName); + typeOut.close(); + + final String typePackageName2 = "uk.co.real_logic.common2"; + final String typeClassName2 = "CompositeBigInteger"; + cut.setPackageName(typePackageName2); + final Writer typeOut2 = cut.createOutput(typeClassName2); + typeOut2.close(); + + final String exampleClassName2 = "ExampleClassName2"; + + final Writer out2 = cut.createOutput(exampleClassName2); + out2.close(); + + assertFileExists(packageName, exampleClassName); + assertFileExists(packageName, exampleClassName2); + assertFileExists(typePackageName, typeClassName); + assertFileExists(typePackageName2, typeClassName2); + } + + private void assertFileExists(final String packageName, final String exampleClassName) throws IOException + { + final String baseDirName = tempDirName.endsWith("" + File.separatorChar) + ? tempDirName : tempDirName + File.separatorChar; + + final String fullyQualifiedFilename = baseDirName + packageName.replace('.', File.separatorChar) + + File.separatorChar + exampleClassName + ".java"; + + final Path path = FileSystems.getDefault().getPath(fullyQualifiedFilename); + final boolean exists = Files.exists(path); + Files.delete(path); + + assertTrue(exists); + } + +} diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/NullEnumTypedTest.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/NullEnumTypedTest.java index 9c930485cb..ba1f5263a5 100644 --- a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/NullEnumTypedTest.java +++ b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/NullEnumTypedTest.java @@ -17,7 +17,6 @@ import org.agrona.DirectBuffer; import org.agrona.MutableDirectBuffer; -import org.agrona.generation.StringWriterOutputManager; import org.junit.jupiter.api.Test; import uk.co.real_logic.sbe.Tests; import uk.co.real_logic.sbe.ir.Ir; diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/SchemaExtensionTest.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/SchemaExtensionTest.java index 78c6e2d5de..4b3bd142d1 100644 --- a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/SchemaExtensionTest.java +++ b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/SchemaExtensionTest.java @@ -19,7 +19,6 @@ import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; import org.agrona.generation.CompilerUtil; -import org.agrona.generation.StringWriterOutputManager; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import uk.co.real_logic.sbe.Tests; diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/StringWriterOutputManager.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/StringWriterOutputManager.java new file mode 100644 index 0000000000..379cb48368 --- /dev/null +++ b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/StringWriterOutputManager.java @@ -0,0 +1,110 @@ +/* + * Copyright 2014-2022 Real Logic Limited. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package uk.co.real_logic.sbe.generation.java; + +import java.io.FilterWriter; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.util.HashMap; +import java.util.Map; +import uk.co.real_logic.sbe.generation.MultiPackageOutputManager; + +/** + * Temporary class, until Agrona's version is updated. + */ +public class StringWriterOutputManager implements MultiPackageOutputManager +{ + private String basePackageName; + private String packageName; + private final HashMap sourceFileByName = new HashMap<>(); + + /** + * {@inheritDoc} + */ + public Writer createOutput(final String name) + { + final StringWriter stringWriter = new StringWriter(); + sourceFileByName.put(packageName + "." + name, stringWriter); + + return new FilterWriter(stringWriter) { + @Override + public void close() throws IOException + { + super.close(); + packageName = basePackageName; + } + + }; + } + + /** + * Set the package name to be used for source files. + * + * @param packageName to be used for source files. + */ + public void setPackageName(final String packageName) + { + this.packageName = packageName; + if (basePackageName == null) + { + basePackageName = packageName; + } + } + + /** + * Get a {@link CharSequence} which represents the source file. + * + * @param name of the source file. + * @return {@link CharSequence} which represents the source file. + */ + public CharSequence getSource(final String name) + { + final StringWriter stringWriter = sourceFileByName.get(name); + if (null == stringWriter) + { + throw new IllegalArgumentException("unknown source file name: " + name); + } + + return stringWriter.toString(); + } + + /** + * Get a {@link Map} of all source files. + * + * @return a {@link Map} of all source files. + */ + public Map getSources() + { + final HashMap sources = new HashMap<>(); + for (final Map.Entry entry : sourceFileByName.entrySet()) + { + sources.put(entry.getKey(), entry.getValue().toString()); + } + + return sources; + } + + /** + * Clear all source files in this {@link OutputManager}. + */ + public void clear() + { + packageName = ""; + basePackageName = null; + sourceFileByName.clear(); + } +} diff --git a/sbe-tool/src/test/resources/explicit-package-test-schema.xml b/sbe-tool/src/test/resources/explicit-package-test-schema.xml new file mode 100644 index 0000000000..a0e02791b1 --- /dev/null +++ b/sbe-tool/src/test/resources/explicit-package-test-schema.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + 0 + 1 + + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + + + + + + + + + + From 2ac9ee312f1e9d6b5d1b06b0e9b01c8e54036447 Mon Sep 17 00:00:00 2001 From: ratcash Date: Tue, 5 Jul 2022 22:53:06 +0200 Subject: [PATCH 02/11] checkstyle. --- .../generation/java/JavaGeneratorTest.java | 8 +++---- .../java/JavaOutputManagerTest.java | 23 +++++++++++++++---- .../java/StringWriterOutputManager.java | 5 ++-- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/JavaGeneratorTest.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/JavaGeneratorTest.java index 4044a0bf26..2f33161b8a 100644 --- a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/JavaGeneratorTest.java +++ b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/JavaGeneratorTest.java @@ -491,8 +491,8 @@ void shouldCreateTypesInDifferentPackages() throws Exception outputManager.clear(); outputManager.setPackageName(ir.applicableNamespace()); - JavaGenerator generator = new JavaGenerator(ir, BUFFER_NAME, READ_ONLY_BUFFER_NAME, false, false, false, true, - outputManager); + final JavaGenerator generator = new JavaGenerator(ir, BUFFER_NAME, READ_ONLY_BUFFER_NAME, false, false, false, + true, outputManager); generator.generate(); final String encoderFqcn = ir.applicableNamespace() + ".TestMessageEncoder"; @@ -523,8 +523,8 @@ void shouldCreateTypesInSamePackageIfSupportDisabled() throws Exception outputManager.clear(); outputManager.setPackageName(ir.applicableNamespace()); - JavaGenerator generator = new JavaGenerator(ir, BUFFER_NAME, READ_ONLY_BUFFER_NAME, false, false, false, false, - outputManager); + final JavaGenerator generator = new JavaGenerator(ir, BUFFER_NAME, READ_ONLY_BUFFER_NAME, false, false, false, + false, outputManager); generator.generate(); final String encoderFqcn = ir.applicableNamespace() + ".TestMessageEncoder"; diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/JavaOutputManagerTest.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/JavaOutputManagerTest.java index aeb6516b28..3bbd7e4fb9 100644 --- a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/JavaOutputManagerTest.java +++ b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/JavaOutputManagerTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013-2022 Real Logic Limited. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package uk.co.real_logic.sbe.generation.java; import java.io.File; @@ -49,11 +64,11 @@ void shouldCreateFileWithinPackage() throws Exception private void assertFileExists(final String packageName, final String exampleClassName) throws IOException { - final String baseDirName = tempDirName.endsWith("" + File.separatorChar) - ? tempDirName : tempDirName + File.separatorChar; + final String baseDirName = tempDirName.endsWith("" + File.separatorChar) ? tempDirName : tempDirName + + File.separatorChar; - final String fullyQualifiedFilename = baseDirName + packageName.replace('.', File.separatorChar) - + File.separatorChar + exampleClassName + ".java"; + final String fullyQualifiedFilename = baseDirName + packageName.replace('.', File.separatorChar) + + File.separatorChar + exampleClassName + ".java"; final Path path = FileSystems.getDefault().getPath(fullyQualifiedFilename); final boolean exists = Files.exists(path); diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/StringWriterOutputManager.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/StringWriterOutputManager.java index 379cb48368..b8e97d4641 100644 --- a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/StringWriterOutputManager.java +++ b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/StringWriterOutputManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2022 Real Logic Limited. + * Copyright 2013-2022 Real Logic Limited. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,7 +40,8 @@ public Writer createOutput(final String name) final StringWriter stringWriter = new StringWriter(); sourceFileByName.put(packageName + "." + name, stringWriter); - return new FilterWriter(stringWriter) { + return new FilterWriter(stringWriter) + { @Override public void close() throws IOException { From 7280689359bb32c487f1a94571039a0da9be2c07 Mon Sep 17 00:00:00 2001 From: ratcash Date: Wed, 10 Aug 2022 10:37:37 +0200 Subject: [PATCH 03/11] Revert accidental delete. --- sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/Type.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/Type.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/Type.java index e6bec463a0..dba276f95f 100644 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/Type.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/Type.java @@ -38,7 +38,7 @@ public abstract class Type private int sinceVersion; /** - * Construct a new Type from XML Schema.Called by subclasses to mostly set common fields + * Construct a new Type from XML Schema. Called by subclasses to mostly set common fields * * @param node from the XML Schema Parsing * @param givenName of this node, if null then the attributed name will be used. From 81eb134a4fce6daf0eac835bc841764c0eee7899 Mon Sep 17 00:00:00 2001 From: ratcash Date: Wed, 10 Aug 2022 10:45:25 +0200 Subject: [PATCH 04/11] Change parameter order for Token. Add Javadoc. --- .../java/uk/co/real_logic/sbe/ir/Token.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/Token.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/Token.java index 252418cfc1..3fdfb32674 100644 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/Token.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/Token.java @@ -77,9 +77,9 @@ public class Token private final Signal signal; private final String name; - private final String packageName; private final String referencedName; private final String description; + private final String packageName; private final int id; private final int version; private final int deprecated; @@ -93,9 +93,10 @@ public class Token * * @param signal for the token role. * @param name of the token in the message. - * @param packageName of the token in the message. * @param referencedName of the type when created from a ref in a composite. * @param description of what the token is for. + * @param packageName of the token in the message. Use null, except for BEGIN_MESSAGE tokens for types that + * require an explicit package. * @param id as the identifier in the message declaration. * @param version application within the template. * @param deprecated as of this version. @@ -107,9 +108,9 @@ public class Token public Token( final Signal signal, final String name, - final String packageName, final String referencedName, final String description, + final String packageName, final int id, final int version, final int deprecated, @@ -126,6 +127,7 @@ public Token( this.name = name; this.referencedName = referencedName; this.description = description; + this.packageName = packageName; this.id = id; this.version = version; this.deprecated = deprecated; @@ -133,7 +135,6 @@ public Token( this.offset = offset; this.componentTokenCount = componentTokenCount; this.encoding = encoding; - this.packageName = packageName; } /** @@ -159,7 +160,7 @@ public String name() /** * Return the packageName of the token * - * @return packageName of the token + * @return packageName of the token or null, if it was not set explicitly. */ public String packageName() { @@ -358,6 +359,7 @@ public String toString() ", name='" + name + '\'' + ", referencedName='" + referencedName + '\'' + ", description='" + description + '\'' + + ", packageName='" + packageName + '\'' + ", id=" + id + ", version=" + version + ", deprecated=" + deprecated + @@ -375,7 +377,7 @@ public static class Builder { private Signal signal; private String name; - private String packageName; + private String packageName = null; private String referencedName; private String description; private int id = INVALID_ID; @@ -411,7 +413,8 @@ public Builder name(final String name) } /** - * Name for the Token. + * Package name for the Token. Default is null. Use for BEGIN_MESSAGE tokens for types that require an explicit + * package. * * @param packageName for the Token. * @return this for a fluent API. @@ -540,9 +543,9 @@ public Token build() return new Token( signal, name, - packageName, referencedName, description, + packageName, id, version, deprecated, From e9b4134a6c6a2246e6ea4eb0f9188b688378e8c2 Mon Sep 17 00:00:00 2001 From: ratcash Date: Wed, 10 Aug 2022 10:45:38 +0200 Subject: [PATCH 05/11] Code style fixes. --- .../generation/java/JavaOutputManager.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaOutputManager.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaOutputManager.java index 2ac0de0ffa..4c1d5c39ed 100644 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaOutputManager.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaOutputManager.java @@ -28,10 +28,9 @@ */ public class JavaOutputManager implements MultiPackageOutputManager { - private final String baseDirName; - private final PackageOutputManager global; - private PackageOutputManager acting; + private final PackageOutputManager basePackageOutputManager; + private PackageOutputManager actingPackageOutputManager; private final Object2ObjectHashMap outputManagerCache = new Object2NullableObjectHashMap<>(); @@ -42,33 +41,32 @@ public class JavaOutputManager implements MultiPackageOutputManager */ public JavaOutputManager(final String baseDirName, final String packageName) { - global = new PackageOutputManager(baseDirName, packageName); - acting = global; + basePackageOutputManager = new PackageOutputManager(baseDirName, packageName); + actingPackageOutputManager = basePackageOutputManager; this.baseDirName = baseDirName; } @Override public void setPackageName(final String packageName) { - acting = outputManagerCache.get(packageName); - if (acting == null) + actingPackageOutputManager = outputManagerCache.get(packageName); + if (actingPackageOutputManager == null) { - acting = new PackageOutputManager(baseDirName, packageName); - outputManagerCache.put(packageName, acting); + actingPackageOutputManager = new PackageOutputManager(baseDirName, packageName); + outputManagerCache.put(packageName, actingPackageOutputManager); } } private void resetPackage() { - acting = global; + actingPackageOutputManager = basePackageOutputManager; } @Override public Writer createOutput(final String name) throws IOException { - return new FilterWriter(acting.createOutput(name)) + return new FilterWriter(actingPackageOutputManager.createOutput(name)) { - @Override public void close() throws IOException { super.close(); From f1eff141f835169f46b4a1100274e9a3fd2dd72a Mon Sep 17 00:00:00 2001 From: ratcash Date: Wed, 10 Aug 2022 11:02:38 +0200 Subject: [PATCH 06/11] Make QualifiedYieldTest use the new constructor. --- .../co/real_logic/sbe/generation/java/QualifiedYieldTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/QualifiedYieldTest.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/QualifiedYieldTest.java index 8f895f6a5d..78702828ee 100644 --- a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/QualifiedYieldTest.java +++ b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/QualifiedYieldTest.java @@ -20,7 +20,6 @@ import org.agrona.DirectBuffer; import org.agrona.MutableDirectBuffer; import org.agrona.generation.CompilerUtil; -import org.agrona.generation.StringWriterOutputManager; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledForJreRange; import org.junit.jupiter.api.condition.JRE; @@ -54,7 +53,7 @@ void shouldGenerateValidJava() throws Exception final IrGenerator irg = new IrGenerator(); final Ir ir = irg.generate(schema); final JavaGenerator generator = new JavaGenerator( - ir, BUFFER_NAME, READ_ONLY_BUFFER_NAME, false, false, false, outputManager); + ir, BUFFER_NAME, READ_ONLY_BUFFER_NAME, false, false, false, false, outputManager); outputManager.setPackageName(ir.applicableNamespace()); generator.generateMessageHeaderStub(); From b021a02032fda3eb5234e0d801fe58dee30aae40 Mon Sep 17 00:00:00 2001 From: ratcash Date: Fri, 9 Sep 2022 11:58:55 +0200 Subject: [PATCH 07/11] Revert changes to test files (using custom version of StringWriterOutputManager). Should be replaced with a new version of Agrona. --- .../generation/MultiPackageOutputManager.java | 30 ----- .../java/CharacterEncodingTest.java | 1 + .../java/ConstantCharArrayTest.java | 1 + .../java/FixedSizeDataGeneratorTest.java | 1 + .../java/GenerateFixBinaryTest.java | 1 + .../java/GenerateIlinkBinaryTest.java | 1 + .../generation/java/JavaGeneratorTest.java | 1 + .../generation/java/NullEnumTypedTest.java | 1 + .../generation/java/SchemaExtensionTest.java | 1 + .../java/StringWriterOutputManager.java | 111 ------------------ 10 files changed, 8 insertions(+), 141 deletions(-) delete mode 100644 sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/MultiPackageOutputManager.java delete mode 100644 sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/StringWriterOutputManager.java diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/MultiPackageOutputManager.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/MultiPackageOutputManager.java deleted file mode 100644 index 4b01b8017c..0000000000 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/MultiPackageOutputManager.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2013-2022 Real Logic Limited. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package uk.co.real_logic.sbe.generation; - -import org.agrona.generation.OutputManager; - -/** - * Extended version of the OutputManager allowing to set the java package. To be moved to agrona. - */ -public interface MultiPackageOutputManager extends OutputManager -{ - /** - * Sets the current package name. - * @param packageName the packageName - */ - void setPackageName(String packageName); -} diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/CharacterEncodingTest.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/CharacterEncodingTest.java index 729b36eebd..bc380a4665 100644 --- a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/CharacterEncodingTest.java +++ b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/CharacterEncodingTest.java @@ -17,6 +17,7 @@ import org.agrona.DirectBuffer; import org.agrona.MutableDirectBuffer; +import org.agrona.generation.StringWriterOutputManager; import org.junit.jupiter.api.Test; import uk.co.real_logic.sbe.ir.Ir; import uk.co.real_logic.sbe.xml.IrGenerator; diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/ConstantCharArrayTest.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/ConstantCharArrayTest.java index d31e95aecd..1141e5c983 100644 --- a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/ConstantCharArrayTest.java +++ b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/ConstantCharArrayTest.java @@ -17,6 +17,7 @@ import org.agrona.DirectBuffer; import org.agrona.MutableDirectBuffer; +import org.agrona.generation.StringWriterOutputManager; import org.junit.jupiter.api.Test; import uk.co.real_logic.sbe.Tests; import uk.co.real_logic.sbe.ir.Ir; diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/FixedSizeDataGeneratorTest.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/FixedSizeDataGeneratorTest.java index c7d0400e47..8edb42474c 100644 --- a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/FixedSizeDataGeneratorTest.java +++ b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/FixedSizeDataGeneratorTest.java @@ -19,6 +19,7 @@ import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; import org.agrona.generation.CompilerUtil; +import org.agrona.generation.StringWriterOutputManager; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import uk.co.real_logic.sbe.Tests; diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/GenerateFixBinaryTest.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/GenerateFixBinaryTest.java index 4a1f45d66e..09274ec5f7 100644 --- a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/GenerateFixBinaryTest.java +++ b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/GenerateFixBinaryTest.java @@ -18,6 +18,7 @@ import org.agrona.DirectBuffer; import org.agrona.MutableDirectBuffer; import org.agrona.generation.CompilerUtil; +import org.agrona.generation.StringWriterOutputManager; import org.junit.jupiter.api.Test; import uk.co.real_logic.sbe.SbeTool; import uk.co.real_logic.sbe.Tests; diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/GenerateIlinkBinaryTest.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/GenerateIlinkBinaryTest.java index d202ee0c46..a8c9e2676a 100644 --- a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/GenerateIlinkBinaryTest.java +++ b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/GenerateIlinkBinaryTest.java @@ -18,6 +18,7 @@ import org.agrona.DirectBuffer; import org.agrona.MutableDirectBuffer; import org.agrona.generation.CompilerUtil; +import org.agrona.generation.StringWriterOutputManager; import org.junit.jupiter.api.Test; import uk.co.real_logic.sbe.SbeTool; import uk.co.real_logic.sbe.Tests; diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/JavaGeneratorTest.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/JavaGeneratorTest.java index 2f33161b8a..297fc02ec0 100644 --- a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/JavaGeneratorTest.java +++ b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/JavaGeneratorTest.java @@ -19,6 +19,7 @@ import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; import org.agrona.generation.CompilerUtil; +import org.agrona.generation.StringWriterOutputManager; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import uk.co.real_logic.sbe.Tests; diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/NullEnumTypedTest.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/NullEnumTypedTest.java index ba1f5263a5..9c930485cb 100644 --- a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/NullEnumTypedTest.java +++ b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/NullEnumTypedTest.java @@ -17,6 +17,7 @@ import org.agrona.DirectBuffer; import org.agrona.MutableDirectBuffer; +import org.agrona.generation.StringWriterOutputManager; import org.junit.jupiter.api.Test; import uk.co.real_logic.sbe.Tests; import uk.co.real_logic.sbe.ir.Ir; diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/SchemaExtensionTest.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/SchemaExtensionTest.java index 4b3bd142d1..78c6e2d5de 100644 --- a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/SchemaExtensionTest.java +++ b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/SchemaExtensionTest.java @@ -19,6 +19,7 @@ import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; import org.agrona.generation.CompilerUtil; +import org.agrona.generation.StringWriterOutputManager; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import uk.co.real_logic.sbe.Tests; diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/StringWriterOutputManager.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/StringWriterOutputManager.java deleted file mode 100644 index b8e97d4641..0000000000 --- a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/StringWriterOutputManager.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2013-2022 Real Logic Limited. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package uk.co.real_logic.sbe.generation.java; - -import java.io.FilterWriter; -import java.io.IOException; -import java.io.StringWriter; -import java.io.Writer; -import java.util.HashMap; -import java.util.Map; -import uk.co.real_logic.sbe.generation.MultiPackageOutputManager; - -/** - * Temporary class, until Agrona's version is updated. - */ -public class StringWriterOutputManager implements MultiPackageOutputManager -{ - private String basePackageName; - private String packageName; - private final HashMap sourceFileByName = new HashMap<>(); - - /** - * {@inheritDoc} - */ - public Writer createOutput(final String name) - { - final StringWriter stringWriter = new StringWriter(); - sourceFileByName.put(packageName + "." + name, stringWriter); - - return new FilterWriter(stringWriter) - { - @Override - public void close() throws IOException - { - super.close(); - packageName = basePackageName; - } - - }; - } - - /** - * Set the package name to be used for source files. - * - * @param packageName to be used for source files. - */ - public void setPackageName(final String packageName) - { - this.packageName = packageName; - if (basePackageName == null) - { - basePackageName = packageName; - } - } - - /** - * Get a {@link CharSequence} which represents the source file. - * - * @param name of the source file. - * @return {@link CharSequence} which represents the source file. - */ - public CharSequence getSource(final String name) - { - final StringWriter stringWriter = sourceFileByName.get(name); - if (null == stringWriter) - { - throw new IllegalArgumentException("unknown source file name: " + name); - } - - return stringWriter.toString(); - } - - /** - * Get a {@link Map} of all source files. - * - * @return a {@link Map} of all source files. - */ - public Map getSources() - { - final HashMap sources = new HashMap<>(); - for (final Map.Entry entry : sourceFileByName.entrySet()) - { - sources.put(entry.getKey(), entry.getValue().toString()); - } - - return sources; - } - - /** - * Clear all source files in this {@link OutputManager}. - */ - public void clear() - { - packageName = ""; - basePackageName = null; - sourceFileByName.clear(); - } -} From b29daa12da8af1ace4c5fe69e484eebe9d0eb196 Mon Sep 17 00:00:00 2001 From: ratcash Date: Wed, 14 Sep 2022 20:19:51 +0200 Subject: [PATCH 08/11] Use agrone 1.17.1 --- build.gradle | 2 +- .../co/real_logic/sbe/generation/java/JavaGenerator.java | 8 ++++---- .../real_logic/sbe/generation/java/JavaOutputManager.java | 6 +++--- .../sbe/generation/java/QualifiedYieldTest.java | 1 + 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index 60938e413c..0ccc6d9b8e 100644 --- a/build.gradle +++ b/build.gradle @@ -47,7 +47,7 @@ def hamcrestVersion = '2.2' def mockitoVersion = '4.8.0' def junitVersion = '5.9.0' def jmhVersion = '1.35' -def agronaVersion = '1.17.0' +def agronaVersion = '1.17.1' def agronaVersionRange = '[1.15.2,2.0[' // allow any release >= 1.15.2 and < 2.0.0 def sbeGroup = 'uk.co.real-logic' diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaGenerator.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaGenerator.java index c3fb083cd1..f8fa753d7f 100644 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaGenerator.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaGenerator.java @@ -19,6 +19,7 @@ import org.agrona.MutableDirectBuffer; import org.agrona.Strings; import org.agrona.Verify; +import org.agrona.generation.DynamicPackageOutputManager; import org.agrona.sbe.*; import uk.co.real_logic.sbe.PrimitiveType; import uk.co.real_logic.sbe.generation.CodeGenerator; @@ -39,7 +40,6 @@ import static uk.co.real_logic.sbe.generation.java.JavaGenerator.CodecType.ENCODER; import static uk.co.real_logic.sbe.generation.java.JavaUtil.*; import static uk.co.real_logic.sbe.ir.GenerationUtil.*; -import uk.co.real_logic.sbe.generation.MultiPackageOutputManager; /** * Generate codecs for the Java 8 programming language. @@ -62,7 +62,7 @@ enum CodecType private static final String INDENT = " "; private final Ir ir; - private final MultiPackageOutputManager outputManager; + private final DynamicPackageOutputManager outputManager; private final String fqMutableBuffer; private final String mutableBuffer; private final String fqReadOnlyBuffer; @@ -91,7 +91,7 @@ public JavaGenerator( final boolean shouldGenerateGroupOrderAnnotation, final boolean shouldGenerateInterfaces, final boolean shouldDecodeUnknownEnumValues, - final MultiPackageOutputManager outputManager) + final DynamicPackageOutputManager outputManager) { this(ir, mutableBuffer, readOnlyBuffer, shouldGenerateGroupOrderAnnotation, shouldGenerateInterfaces, shouldDecodeUnknownEnumValues, false, outputManager); @@ -117,7 +117,7 @@ public JavaGenerator( final boolean shouldGenerateInterfaces, final boolean shouldDecodeUnknownEnumValues, final boolean shouldSupportTypePackages, - final MultiPackageOutputManager outputManager) + final DynamicPackageOutputManager outputManager) { Verify.notNull(ir, "ir"); Verify.notNull(outputManager, "outputManager"); diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaOutputManager.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaOutputManager.java index 4c1d5c39ed..2e16d4d11a 100644 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaOutputManager.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaOutputManager.java @@ -20,13 +20,13 @@ import java.io.Writer; import org.agrona.collections.Object2NullableObjectHashMap; import org.agrona.collections.Object2ObjectHashMap; +import org.agrona.generation.DynamicPackageOutputManager; import org.agrona.generation.PackageOutputManager; -import uk.co.real_logic.sbe.generation.MultiPackageOutputManager; /** - * Implementation of {@link MultiPackageOutputManager} for Java. + * Implementation of {@link DynamicPackageOutputManager} for Java. */ -public class JavaOutputManager implements MultiPackageOutputManager +public class JavaOutputManager implements DynamicPackageOutputManager { private final String baseDirName; private final PackageOutputManager basePackageOutputManager; diff --git a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/QualifiedYieldTest.java b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/QualifiedYieldTest.java index 78702828ee..701d50057a 100644 --- a/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/QualifiedYieldTest.java +++ b/sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/QualifiedYieldTest.java @@ -20,6 +20,7 @@ import org.agrona.DirectBuffer; import org.agrona.MutableDirectBuffer; import org.agrona.generation.CompilerUtil; +import org.agrona.generation.StringWriterOutputManager; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledForJreRange; import org.junit.jupiter.api.condition.JRE; From 6ddce5a950dd26ba14392d05d4d0e486f0048cab Mon Sep 17 00:00:00 2001 From: ratcash Date: Fri, 23 Sep 2022 16:43:51 +0200 Subject: [PATCH 09/11] Remove @Override --- .../uk/co/real_logic/sbe/generation/java/JavaOutputManager.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaOutputManager.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaOutputManager.java index 2e16d4d11a..1dc6317ccb 100644 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaOutputManager.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaOutputManager.java @@ -46,7 +46,6 @@ public JavaOutputManager(final String baseDirName, final String packageName) this.baseDirName = baseDirName; } - @Override public void setPackageName(final String packageName) { actingPackageOutputManager = outputManagerCache.get(packageName); @@ -62,7 +61,6 @@ private void resetPackage() actingPackageOutputManager = basePackageOutputManager; } - @Override public Writer createOutput(final String name) throws IOException { return new FilterWriter(actingPackageOutputManager.createOutput(name)) From f876441d889b9bd1bd4bc3a86538d1e477d801e8 Mon Sep 17 00:00:00 2001 From: ratcash Date: Fri, 23 Sep 2022 17:37:26 +0200 Subject: [PATCH 10/11] make checkstyle happy. --- .../real_logic/sbe/generation/java/JavaOutputManager.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaOutputManager.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaOutputManager.java index 1dc6317ccb..03918fc54b 100644 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaOutputManager.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaOutputManager.java @@ -46,6 +46,9 @@ public JavaOutputManager(final String baseDirName, final String packageName) this.baseDirName = baseDirName; } + /** + * @inherit + */ public void setPackageName(final String packageName) { actingPackageOutputManager = outputManagerCache.get(packageName); @@ -61,6 +64,9 @@ private void resetPackage() actingPackageOutputManager = basePackageOutputManager; } + /** + * @inherit + */ public Writer createOutput(final String name) throws IOException { return new FilterWriter(actingPackageOutputManager.createOutput(name)) From 6c0a263e89c0e5239e60824b549bf99ce02cbf7b Mon Sep 17 00:00:00 2001 From: ratcash Date: Fri, 23 Sep 2022 17:43:44 +0200 Subject: [PATCH 11/11] Correct inherit directive. --- .../co/real_logic/sbe/generation/java/JavaOutputManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaOutputManager.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaOutputManager.java index 03918fc54b..9dcd568c1f 100644 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaOutputManager.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaOutputManager.java @@ -47,7 +47,7 @@ public JavaOutputManager(final String baseDirName, final String packageName) } /** - * @inherit + * {@inheritDoc} */ public void setPackageName(final String packageName) { @@ -65,7 +65,7 @@ private void resetPackage() } /** - * @inherit + * {@inheritDoc} */ public Writer createOutput(final String name) throws IOException {