Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SbeTool.main -> provide additional method SbeTool.mainWithProperties to aid build tools #1002

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 32 additions & 25 deletions sbe-tool/src/main/java/uk/co/real_logic/sbe/SbeTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,18 @@ public class SbeTool
*/
public static void main(final String[] args) throws Exception
{
if (args.length == 0)
{
mainWithProperties(args, System.getProperties());
}

/**
* Main entry point for the SBE Tool.
*
* @param args command line arguments. A single filename is expected.
* @param properties Used to pass in system properties.
* @throws Exception if an error occurs during process of the message schema.
*/
public static void mainWithProperties(final String[] args, java.util.Properties properties) throws Exception {
if (args.length == 0) {
System.err.format("Usage: %s <filenames>...%n", SbeTool.class.getName());
System.exit(-1);
}
Expand All @@ -254,12 +264,12 @@ public static void main(final String[] args) throws Exception
final String xsdFilename = System.getProperty(SbeTool.VALIDATION_XSD);
if (xsdFilename != null)
{
validateAgainstSchema(fileName, xsdFilename);
validateAgainstSchema(fileName, xsdFilename, properties);
}

final MessageSchema schema = parseSchema(fileName);
final MessageSchema schema = parseSchema(fileName, properties);
final SchemaTransformer transformer = new SchemaTransformerFactory(
System.getProperty(SCHEMA_TRANSFORM_VERSION));
properties.getProperty(SCHEMA_TRANSFORM_VERSION));
ir = new IrGenerator().generate(transformer.transform(schema), System.getProperty(TARGET_NAMESPACE));
}
else if (fileName.endsWith(".sbeir"))
Expand All @@ -276,16 +286,14 @@ else if (fileName.endsWith(".sbeir"))
return;
}

final String outputDirName = System.getProperty(OUTPUT_DIR, ".");
if (Boolean.parseBoolean(System.getProperty(GENERATE_STUBS, "true")))
{
final String targetLanguage = System.getProperty(TARGET_LANGUAGE, "Java");
final String outputDirName = properties.getProperty(OUTPUT_DIR, ".");
if (Boolean.parseBoolean(properties.getProperty(GENERATE_STUBS, "true"))) {
final String targetLanguage = properties.getProperty(TARGET_LANGUAGE, "Java");

generate(ir, outputDirName, targetLanguage);
}

if (Boolean.parseBoolean(System.getProperty(GENERATE_IR, "false")))
{
if (Boolean.parseBoolean(properties.getProperty(GENERATE_IR, "false"))) {
final File inputFile = new File(fileName);
final String inputFilename = inputFile.getName();
final int nameEnd = inputFilename.lastIndexOf('.');
Expand All @@ -307,15 +315,14 @@ else if (fileName.endsWith(".sbeir"))
* @param xsdFilename XSD against which to validate.
* @throws Exception if an error occurs while validating.
*/
public static void validateAgainstSchema(final String sbeSchemaFilename, final String xsdFilename)
throws Exception
{
public static void validateAgainstSchema(final String sbeSchemaFilename, final String xsdFilename, java.util.Properties properties)
throws Exception {
final ParserOptions.Builder optionsBuilder = ParserOptions.builder()
.xsdFilename(System.getProperty(VALIDATION_XSD))
.xIncludeAware(Boolean.parseBoolean(System.getProperty(XINCLUDE_AWARE)))
.stopOnError(Boolean.parseBoolean(System.getProperty(VALIDATION_STOP_ON_ERROR)))
.warningsFatal(Boolean.parseBoolean(System.getProperty(VALIDATION_WARNINGS_FATAL)))
.suppressOutput(Boolean.parseBoolean(System.getProperty(VALIDATION_SUPPRESS_OUTPUT)));
.xsdFilename(properties.getProperty(VALIDATION_XSD))
.xIncludeAware(Boolean.parseBoolean(properties.getProperty(XINCLUDE_AWARE)))
.stopOnError(Boolean.parseBoolean(properties.getProperty(VALIDATION_STOP_ON_ERROR)))
.warningsFatal(Boolean.parseBoolean(properties.getProperty(VALIDATION_WARNINGS_FATAL)))
.suppressOutput(Boolean.parseBoolean(properties.getProperty(VALIDATION_SUPPRESS_OUTPUT)));

final Path path = Paths.get(sbeSchemaFilename);
try (InputStream in = new BufferedInputStream(Files.newInputStream(path)))
Expand All @@ -337,15 +344,15 @@ public static void validateAgainstSchema(final String sbeSchemaFilename, final S
* @return the parsed {@link MessageSchema} for the specification found in the file.
* @throws Exception if an error occurs when parsing the specification.
*/
public static MessageSchema parseSchema(final String sbeSchemaFilename)
public static MessageSchema parseSchema(final String sbeSchemaFilename, java.util.Properties properties)
throws Exception
{
final ParserOptions.Builder optionsBuilder = ParserOptions.builder()
.xsdFilename(System.getProperty(VALIDATION_XSD))
.xIncludeAware(Boolean.parseBoolean(System.getProperty(XINCLUDE_AWARE)))
.stopOnError(Boolean.parseBoolean(System.getProperty(VALIDATION_STOP_ON_ERROR)))
.warningsFatal(Boolean.parseBoolean(System.getProperty(VALIDATION_WARNINGS_FATAL)))
.suppressOutput(Boolean.parseBoolean(System.getProperty(VALIDATION_SUPPRESS_OUTPUT)));
.xsdFilename(properties.getProperty(VALIDATION_XSD))
.xIncludeAware(Boolean.parseBoolean(properties.getProperty(XINCLUDE_AWARE)))
.stopOnError(Boolean.parseBoolean(properties.getProperty(VALIDATION_STOP_ON_ERROR)))
.warningsFatal(Boolean.parseBoolean(properties.getProperty(VALIDATION_WARNINGS_FATAL)))
.suppressOutput(Boolean.parseBoolean(properties.getProperty(VALIDATION_SUPPRESS_OUTPUT)));

final Path path = Paths.get(sbeSchemaFilename);
try (InputStream in = new BufferedInputStream(Files.newInputStream(path)))
Expand Down
Loading