Search in sources :

Example 1 with CliParameter

use of org.openmuc.jasn1.compiler.cli.CliParameter in project jasn1 by openmuc.

the class Compiler method main.

public static void main(String[] args) throws Exception {
    StringCliParameter outputBaseDir = new CliParameterBuilder("-o").setDescription("The base directory for the generated Java classes. The class files will be saved in subfolders of the base directory corresponding to the name of the defined modules.").buildStringParameter("output_base_dir", "./");
    StringCliParameter basePackageName = new CliParameterBuilder("-p").setDescription("The base package name. Added to this will be a name generated from the module name.").buildStringParameter("package_base_name", "");
    FlagCliParameter supportIndefiniteLength = new CliParameterBuilder("-il").setDescription("Add support for decoding indefinite length in generated classes. This feature is not yet fully implemented and should be used with caution.").buildFlagParameter();
    FlagCliParameter disableBerTypeInterface = new CliParameterBuilder("-di").setDescription("By default generated classes implement the BerType interface. Using this flag this behavior can be disabled.").buildFlagParameter();
    FlagCliParameter legacyMode = new CliParameterBuilder("-l").setDescription("Enable legacy mode. Earlier versions of the jASN1 compiler generated classes that had public member variables instead of getters and setters. This flag enables the old kind of classes.").buildFlagParameter();
    StringListCliParameter asn1Files = new CliParameterBuilder("-f").setMandatory().setDescription("ASN.1 files defining one or more modules.").buildStringListParameter("file");
    List<CliParameter> cliParameters = new ArrayList<>();
    cliParameters.add(asn1Files);
    cliParameters.add(outputBaseDir);
    cliParameters.add(basePackageName);
    cliParameters.add(supportIndefiniteLength);
    cliParameters.add(disableBerTypeInterface);
    cliParameters.add(legacyMode);
    CliParser cliParser = new CliParser("jasn1-compiler", "The compiler reads the ASN.1 definitions from the given files and generates corresponding Java classes that can be used to conveniently encode and decode BER data. v" + VERSION);
    cliParser.addParameters(cliParameters);
    try {
        cliParser.parseArguments(args);
    } catch (CliParseException e1) {
        System.err.println("Error parsing command line parameters: " + e1.getMessage());
        System.out.println(cliParser.getUsageString());
        System.exit(1);
    }
    System.out.println("Generated code will be saved in " + outputBaseDir.getValue());
    if (supportIndefiniteLength.isSelected()) {
        System.out.println("Java classes will support decoding indefinite length.");
    }
    HashMap<String, AsnModule> modulesByName = new HashMap<>();
    for (String asn1File : asn1Files.getValue()) {
        System.out.println("Parsing \"" + asn1File + "\"");
        AsnModel model = getJavaModelFromAsn1File(asn1File);
        modulesByName.putAll(model.modulesByName);
    }
    BerClassWriter classWriter = new BerClassWriter(modulesByName, outputBaseDir.getValue(), basePackageName.getValue(), !legacyMode.isSelected(), supportIndefiniteLength.isSelected(), disableBerTypeInterface.isSelected());
    classWriter.translate();
    System.out.println("done");
}
Also used : StringListCliParameter(org.openmuc.jasn1.compiler.cli.StringListCliParameter) StringCliParameter(org.openmuc.jasn1.compiler.cli.StringCliParameter) FlagCliParameter(org.openmuc.jasn1.compiler.cli.FlagCliParameter) CliParameter(org.openmuc.jasn1.compiler.cli.CliParameter) StringListCliParameter(org.openmuc.jasn1.compiler.cli.StringListCliParameter) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CliParameterBuilder(org.openmuc.jasn1.compiler.cli.CliParameterBuilder) FlagCliParameter(org.openmuc.jasn1.compiler.cli.FlagCliParameter) AsnModule(org.openmuc.jasn1.compiler.model.AsnModule) AsnModel(org.openmuc.jasn1.compiler.model.AsnModel) CliParser(org.openmuc.jasn1.compiler.cli.CliParser) CliParseException(org.openmuc.jasn1.compiler.cli.CliParseException) StringCliParameter(org.openmuc.jasn1.compiler.cli.StringCliParameter)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 CliParameter (org.openmuc.jasn1.compiler.cli.CliParameter)1 CliParameterBuilder (org.openmuc.jasn1.compiler.cli.CliParameterBuilder)1 CliParseException (org.openmuc.jasn1.compiler.cli.CliParseException)1 CliParser (org.openmuc.jasn1.compiler.cli.CliParser)1 FlagCliParameter (org.openmuc.jasn1.compiler.cli.FlagCliParameter)1 StringCliParameter (org.openmuc.jasn1.compiler.cli.StringCliParameter)1 StringListCliParameter (org.openmuc.jasn1.compiler.cli.StringListCliParameter)1 AsnModel (org.openmuc.jasn1.compiler.model.AsnModel)1 AsnModule (org.openmuc.jasn1.compiler.model.AsnModule)1