in tools/code-generation/generator/src/main/java/com/amazonaws/util/awsclientgenerator/main.java [49:197]
public static void main(String[] args) throws IOException {
if (args.length == 0 || getOptionName(args[0]).equals("help")) {
printHelp();
return;
}
Map<String, String> argPairs = getArgOptionPairs(args);
//At this point we want to read the c2j from std in.
//e.g. cat /home/henso/someC2jFile.normal.json | AWSClientGenerator --service myService --language-binding cpp or
//AWSClientGenerator --service myService --language-binding cpp < /home/henso/someC2jFile.normal.json
if (argPairs.containsKey(ARBITRARY_OPTION) || argPairs.containsKey(INPUT_FILE_NAME)) {
if (!argPairs.containsKey(LANGUAGE_BINDING_OPTION) || argPairs.get(LANGUAGE_BINDING_OPTION).isEmpty()) {
argPairs.put(LANGUAGE_BINDING_OPTION, "cpp"); // legacy argument and in fact always cpp in this project
}
final Set<String> ALLOWED_OPTIONS = new HashSet<>(Arrays.asList(SERVICE_OPTION, DEFAULTS_OPTION, PARTITIONS_OPTION));
Set<String> selectedOptions = ALLOWED_OPTIONS;
selectedOptions.retainAll(argPairs.keySet());
if (selectedOptions.size() != 1) {
System.err.println(String.format("Error: one and only one option from {%s} must be specified to the generator, found: {%s}",
ALLOWED_OPTIONS, selectedOptions));
System.exit(-1);
return;
}
final String selectedOption = selectedOptions.iterator().next();
String namespace = "Aws";
if (argPairs.containsKey(NAMESPACE) && !argPairs.get(NAMESPACE).isEmpty()) {
namespace = argPairs.get(NAMESPACE);
}
String licenseText = "";
if (argPairs.containsKey(LICENSE_TEXT) && !argPairs.get(LICENSE_TEXT).isEmpty()) {
licenseText = argPairs.get(LICENSE_TEXT);
}
boolean generateStandalonePackage = argPairs.containsKey(STANDALONE_OPTION);
boolean generateTests = argPairs.containsKey(GENERATE_TESTS_OPTION);
String languageBinding = argPairs.get(LANGUAGE_BINDING_OPTION);
String serviceName = argPairs.get(SERVICE_OPTION);
boolean enableVirtualOperations = argPairs.containsKey(ENABLE_VIRTUAL_OPERATIONS);
String arbitraryJson = readFile(argPairs.getOrDefault(INPUT_FILE_NAME, ""));
String endpointRules = null;
if (argPairs.containsKey(ENDPOINT_RULE_SET)) {
endpointRules = readFile(argPairs.get(ENDPOINT_RULE_SET));
}
String endpointRuleTests = null;
if (argPairs.containsKey(ENDPOINT_TESTS)) {
endpointRuleTests = readFile(argPairs.get(ENDPOINT_TESTS));
}
String protocolTests = null;
if (argPairs.containsKey(PROTOCOL_TESTS)) {
protocolTests = readFile(argPairs.get(PROTOCOL_TESTS));
}
String protocolTestsType = "";
if (argPairs.containsKey(PROTOCOL_TESTS_TYPE) && !argPairs.get(PROTOCOL_TESTS_TYPE).isEmpty()) {
protocolTestsType = argPairs.get(PROTOCOL_TESTS_TYPE);
}
String protocolTestsName = "";
if (argPairs.containsKey(PROTOCOL_TESTS_NAME) && !argPairs.get(PROTOCOL_TESTS_NAME).isEmpty()) {
protocolTestsName = argPairs.get(PROTOCOL_TESTS_NAME);
}
String outputFileName = null;
if (argPairs.containsKey(OUTPUT_FILE_NAME) && !argPairs.get(OUTPUT_FILE_NAME).isEmpty()) {
outputFileName = argPairs.get(OUTPUT_FILE_NAME);
}
boolean useSmithyClient = argPairs.containsKey(USE_SMITHY_CLIENT);
if (arbitraryJson != null && arbitraryJson.length() > 0) {
try {
ByteArrayOutputStream generated;
String componentOutputName;
if (serviceName != null && !serviceName.isEmpty()) {
if (!generateTests) {
generated = generateService(arbitraryJson, endpointRules, endpointRuleTests, languageBinding, serviceName, namespace,
licenseText, generateStandalonePackage, enableVirtualOperations, useSmithyClient);
componentOutputName = String.format("aws-cpp-sdk-%s", serviceName);
} else if (argPairs.containsKey(ENDPOINT_TESTS)) {
generated = generateServiceTest(arbitraryJson, endpointRules, endpointRuleTests, languageBinding, serviceName, namespace,
licenseText);
componentOutputName = String.format("%s-gen-tests", serviceName);
} else if (argPairs.containsKey(PROTOCOL_TESTS)) {
generated = generateProtocolTest(arbitraryJson, protocolTests, protocolTestsType, protocolTestsName, serviceName);
componentOutputName = String.format("%s", serviceName);
} else {
generated = new ByteArrayOutputStream();
componentOutputName = "";
System.out.println("Unknown component to generate!");
System.exit(-1);
}
} else {
if (generateTests) {
System.out.println("Test generation for defaults is not supported by the generator.");
System.exit(-1);
}
if (selectedOption.equalsIgnoreCase(DEFAULTS_OPTION)) {
generated = generateDefaults(arbitraryJson, languageBinding, serviceName, namespace,
licenseText, generateStandalonePackage, enableVirtualOperations);
} else if (selectedOption.equalsIgnoreCase(PARTITIONS_OPTION)) {
generated = generatePartitions(arbitraryJson, languageBinding, serviceName, namespace,
licenseText, generateStandalonePackage, enableVirtualOperations);
} else {
System.err.println(String.format("Unsupported core component %s requested for generation", selectedOption));
System.exit(-1);
return;
}
componentOutputName = String.format("aws-cpp-sdk-core");
}
if (outputFileName != null && outputFileName.equals("STDOUT")) {
generated.writeTo(System.out);
} else {
File finalOutputFile;
if (outputFileName != null) {
finalOutputFile = new File(outputFileName);
} else {
finalOutputFile = File.createTempFile(componentOutputName, ".zip");
}
FileOutputStream fileOutputStream = new FileOutputStream(finalOutputFile);
generated.writeTo(fileOutputStream);
System.out.println(finalOutputFile.getAbsolutePath());
}
} catch (GeneratorNotImplementedException e) {
System.err.println(e.getMessage());
e.printStackTrace();
System.exit(-1);
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
System.exit(-1);
}
} else {
System.err.println("You must supply standard input if you specify the --arbitrary option.");
System.exit(-1);
}
return;
}
printHelp();
}