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 2f2e53970b..a0be516bf9 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 @@ -68,7 +68,7 @@ *
  • 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 + *
  • sbe.type.package.override: Is package attribute for types element supported (only for JAVA). Defaults to * false.
  • * */ @@ -121,9 +121,9 @@ public class SbeTool /** * Boolean system property to control the support of package names in {@code } elements. - * Part of SBE v2-rc2. Defaults to false. + * Part of SBE v2-rc3. Defaults to false. */ - public static final String TYPE_PACKAGE_OVERRIDE = "sbe.type.package.override"; + public static final String TYPES_PACKAGE_OVERRIDE = "sbe.types.package.override"; /** * Target language for generated code. 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 6f1e68f08c..2dade346dd 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 @@ -52,7 +52,7 @@ 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)), - "true".equals(System.getProperty(TYPE_PACKAGE_OVERRIDE)), + "true".equals(System.getProperty(TYPES_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 f8fa753d7f..f02cfc419d 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 @@ -70,8 +70,8 @@ enum CodecType private final boolean shouldGenerateGroupOrderAnnotation; private final boolean shouldGenerateInterfaces; private final boolean shouldDecodeUnknownEnumValues; - private final boolean shouldSupportTypePackages; - private final Set typePackages = new HashSet<>(); + private final boolean shouldSupportTypesPackageNames; + private final Set packageNameByTypes = new HashSet<>(); /** * Create a new Java language {@link CodeGenerator}. Generator support for types in their own package is disabled. @@ -106,7 +106,7 @@ public JavaGenerator( * @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 shouldSupportTypesPackageNames generator support for types in their own package. * @param outputManager for generating the codecs to. */ public JavaGenerator( @@ -116,14 +116,14 @@ public JavaGenerator( final boolean shouldGenerateGroupOrderAnnotation, final boolean shouldGenerateInterfaces, final boolean shouldDecodeUnknownEnumValues, - final boolean shouldSupportTypePackages, + final boolean shouldSupportTypesPackageNames, final DynamicPackageOutputManager outputManager) { Verify.notNull(ir, "ir"); Verify.notNull(outputManager, "outputManager"); this.ir = ir; - this.shouldSupportTypePackages = shouldSupportTypePackages; + this.shouldSupportTypesPackageNames = shouldSupportTypesPackageNames; this.outputManager = outputManager; this.mutableBuffer = validateBufferImplementation(mutableBuffer, MutableDirectBuffer.class); @@ -176,18 +176,19 @@ public void generateTypeStubs() throws IOException } /** - * Register the the type's explicit package - if it's set and should be supported. + * Register the types 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() } + * @param token the 0-th token of the type. + * @param ir the intermediate representation. + * @return the overridden package name of the type if set and supported, or {@link Ir#applicableNamespace()}. */ - private String registerTypePackage(final Token token, final Ir ir) + private String registerTypesPackageName(final Token token, final Ir ir) { - if (shouldSupportTypePackages && token.packageName() != null) + if (shouldSupportTypesPackageNames && token.packageName() != null) { - typePackages.add(token.packageName()); + packageNameByTypes.add(token.packageName()); outputManager.setPackageName(token.packageName()); + return token.packageName(); } return ir.applicableNamespace(); @@ -198,7 +199,7 @@ private String registerTypePackage(final Token token, final Ir ir) */ public void generate() throws IOException { - typePackages.clear(); + packageNameByTypes.clear(); generatePackageInfo(); generateTypeStubs(); generateMessageHeaderStub(); @@ -1238,7 +1239,7 @@ private void generateBitSet(final List tokens) throws IOException final List choiceList = tokens.subList(1, tokens.size() - 1); final String implementsString = implementsInterface(Flyweight.class.getSimpleName()); - registerTypePackage(token, ir); + registerTypesPackageName(token, ir); try (Writer out = outputManager.createOutput(decoderName)) { final Encoding encoding = token.encoding(); @@ -1259,7 +1260,7 @@ private void generateBitSet(final List tokens) throws IOException out.append("}\n"); } - registerTypePackage(token, ir); + registerTypesPackageName(token, ir); try (Writer out = outputManager.createOutput(encoderName)) { generateFixedFlyweightHeader(out, token, encoderName, implementsString, mutableBuffer, fqMutableBuffer); @@ -1277,7 +1278,7 @@ private void generateFixedFlyweightHeader( final String buffer, final String fqBuffer) throws IOException { - final String packageName = registerTypePackage(token, ir); + final String packageName = registerTypesPackageName(token, ir); out.append(generateFileHeader(packageName, fqBuffer)); out.append(generateDeclaration(typeName, implementsString, token)); out.append(generateFixedFlyweightCode(typeName, token.encodedLength(), buffer)); @@ -1291,7 +1292,7 @@ private void generateCompositeFlyweightHeader( final String fqBuffer, final String implementsString) throws IOException { - final String packageName = registerTypePackage(token, ir); + final String packageName = registerTypesPackageName(token, ir); out.append(generateFileHeader(packageName, fqBuffer)); out.append(generateDeclaration(typeName, implementsString, token)); out.append(generateFixedFlyweightCode(typeName, token.encodedLength(), buffer)); @@ -1304,7 +1305,7 @@ 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); + final String packageName = registerTypesPackageName(enumToken, ir); try (Writer out = outputManager.createOutput(enumName)) { out.append(generateEnumFileHeader(packageName)); @@ -1327,7 +1328,7 @@ private void generateComposite(final List tokens) throws IOException final String decoderName = decoderName(compositeName); final String encoderName = encoderName(compositeName); - registerTypePackage(token, ir); + registerTypesPackageName(token, ir); try (Writer out = outputManager.createOutput(decoderName)) { final String implementsString = implementsInterface(CompositeDecoderFlyweight.class.getSimpleName()); @@ -1376,7 +1377,7 @@ private void generateComposite(final List tokens) throws IOException out.append("}\n"); } - registerTypePackage(token, ir); + registerTypesPackageName(token, ir); try (Writer out = outputManager.createOutput(encoderName)) { final String implementsString = implementsInterface(CompositeEncoderFlyweight.class.getSimpleName()); @@ -1629,8 +1630,8 @@ 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) + final StringBuilder packageImports = new StringBuilder(); + for (final String typePackage : packageNameByTypes) { packageImports.append("import "); packageImports.append(typePackage); @@ -1644,7 +1645,7 @@ private CharSequence generateMainHeader( "package " + packageName + ";\n\n" + "import " + fqMutableBuffer + ";\n" + interfaceImportLine() + - packageImports.toString(); + packageImports; } else { @@ -1657,7 +1658,7 @@ private CharSequence generateMainHeader( (hasMutableBuffer ? "import " + fqMutableBuffer + ";\n" : "") + (hasReadOnlyBuffer ? "import " + fqReadOnlyBuffer + ";\n" : "") + interfaceImportLine() + - packageImports.toString(); + packageImports; } } 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 9dcd568c1f..9d34d89a81 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 @@ -15,34 +15,36 @@ */ 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.DynamicPackageOutputManager; import org.agrona.generation.PackageOutputManager; +import java.io.FilterWriter; +import java.io.IOException; +import java.io.Writer; + /** * Implementation of {@link DynamicPackageOutputManager} for Java. */ public class JavaOutputManager implements DynamicPackageOutputManager { private final String baseDirName; - private final PackageOutputManager basePackageOutputManager; + private final PackageOutputManager initialPackageOutputManager; private PackageOutputManager actingPackageOutputManager; - private final Object2ObjectHashMap outputManagerCache + private final Object2ObjectHashMap outputManagerByPackageName = new Object2NullableObjectHashMap<>(); /** * Constructor. + * * @param baseDirName the target directory * @param packageName the initial package name */ public JavaOutputManager(final String baseDirName, final String packageName) { - basePackageOutputManager = new PackageOutputManager(baseDirName, packageName); - actingPackageOutputManager = basePackageOutputManager; + initialPackageOutputManager = new PackageOutputManager(baseDirName, packageName); + actingPackageOutputManager = initialPackageOutputManager; this.baseDirName = baseDirName; } @@ -51,17 +53,17 @@ public JavaOutputManager(final String baseDirName, final String packageName) */ public void setPackageName(final String packageName) { - actingPackageOutputManager = outputManagerCache.get(packageName); + actingPackageOutputManager = outputManagerByPackageName.get(packageName); if (actingPackageOutputManager == null) { actingPackageOutputManager = new PackageOutputManager(baseDirName, packageName); - outputManagerCache.put(packageName, actingPackageOutputManager); + outputManagerByPackageName.put(packageName, actingPackageOutputManager); } } private void resetPackage() { - actingPackageOutputManager = basePackageOutputManager; + actingPackageOutputManager = initialPackageOutputManager; } /** 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 3fdfb32674..7d42b02599 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 @@ -377,7 +377,7 @@ public static class Builder { private Signal signal; private String name; - private String packageName = null; + private String packageName; private String referencedName; private String description; private int id = INVALID_ID; @@ -413,7 +413,7 @@ public Builder name(final String name) } /** - * Package name for the Token. Default is null. Use for BEGIN_MESSAGE tokens for types that require an explicit + * 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. 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 064b5358e6..ca81a4edc3 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 @@ -65,7 +65,7 @@ public EncodedDataType(final Node node) /** * Construct a new encodedDataType from XML Schema. * - * @param node from the XML Schema Parsing + * @param node from the XML Schema Parsing. * @param givenName for this node. * @param referencedName of the type when created from a ref in a composite. */ @@ -201,13 +201,13 @@ private PrimitiveValue lookupValueRef(final Node node) /** * Construct a new EncodedDataType with direct values. Does not handle constant values. * - * @param name 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 + * @param name 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, @@ -222,16 +222,16 @@ public EncodedDataType( } /** - * Construct a new EncodedDataType with direct values.Does not handle constant values. + * 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 + * @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, 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 dba276f95f..67a09d3152 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 @@ -40,7 +40,7 @@ public abstract class Type /** * Construct a new Type from XML Schema. Called by subclasses to mostly set common fields * - * @param node from the XML Schema Parsing + * @param node from the XML Schema Parsing. * @param givenName of this node, if null then the attributed name will be used. * @param referencedName of the type when created from a ref in a composite. */ @@ -68,12 +68,12 @@ public Type(final Node node, final String givenName, final String referencedName /** * 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 + * @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, @@ -89,13 +89,13 @@ public Type( /** * 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 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 - * @param deprecated version in which this was deprecated. - * @param semanticType of the type or null + * @param deprecated version in which this wa.s deprecated. + * @param semanticType of the type or null. */ public Type( final String name, @@ -118,9 +118,9 @@ public Type( } /** - * Return the name of the type + * The name of the type. * - * @return name of the Type + * @return name of the Type. */ public String name() { @@ -138,9 +138,9 @@ public String referencedName() } /** - * Return the presence of the type + * The {@link Presence} of the type. * - * @return presence of the Type + * @return {@link Presence} of the type. */ public Presence presence() { @@ -157,9 +157,9 @@ public Presence presence() public abstract int encodedLength(); /** - * The description of the Type (if set) or null + * The description of the Type (if set) or null. * - * @return description set by the type or null + * @return description set by the type or null. */ public String description() { @@ -197,9 +197,9 @@ public int deprecated() } /** - * The semanticType of the Type + * The FIX semanticType of the Type. * - * @return semanticType of the Type if set or null if not set + * @return FIX semanticType of the Type if set or null if not set. */ public String semanticType() { @@ -214,9 +214,9 @@ public String semanticType() public abstract boolean isVariableLength(); /** - * Return the offset attribute of the {@link Type} from the schema + * The offset attribute of the {@link Type} from the schema. * - * @return the offset attribute value or -1 to indicate not set by the schema + * @return the offset attribute value or -1 to indicate not set by the schema. */ public int offsetAttribute() { @@ -224,9 +224,9 @@ public int offsetAttribute() } /** - * Set the offset attribute of the {@link Type} from the schema + * Set the offset attribute of the {@link Type} from the schema. * - * @param offsetAttribute to set + * @param offsetAttribute to set. */ public void offsetAttribute(final int offsetAttribute) { @@ -234,9 +234,9 @@ public void offsetAttribute(final int offsetAttribute) } /** - * Return the packageName attribute of the {@link Type} from the schema + * The packageName attribute of the {@link Type} from the schema. * - * @return the packageName attribute value or null, if not explicitely defined by the schema + * @return the packageName attribute value or null, if not explicitly defined by the schema. */ public String packageName() { 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 3bbd7e4fb9..97bab7f9ff 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 @@ -15,26 +15,27 @@ */ package uk.co.real_logic.sbe.generation.java; +import org.agrona.SystemUtil; +import org.junit.jupiter.api.Test; + 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 +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 String tempDirName = SystemUtil.tmpDirName(); final JavaOutputManager cut = new JavaOutputManager(tempDirName, packageName); final Writer out = cut.createOutput(exampleClassName); out.close(); @@ -64,8 +65,9 @@ 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 tempDirName = SystemUtil.tmpDirName(); + final String baseDirName = tempDirName.endsWith("" + File.separatorChar) ? + tempDirName : tempDirName + File.separatorChar; final String fullyQualifiedFilename = baseDirName + packageName.replace('.', File.separatorChar) + File.separatorChar + exampleClassName + ".java"; @@ -76,5 +78,4 @@ private void assertFileExists(final String packageName, final String exampleClas assertTrue(exists); } - } diff --git a/version.txt b/version.txt index 28509b3918..8503140e97 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.26.1-SNAPSHOT +1.27.0-SNAPSHOT