Search in sources :

Example 1 with CliParser

use of com.beanit.asn1bean.compiler.cli.CliParser 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. Often this is the root folder for Java classes (e.g. src/main/java). The class files will be saved in subfolders of the base directory corresponding to the base package name and 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 disableWritingVersion = new CliParameterBuilder("-dv").setDescription("By default the ASN1bean version is written in the header of the generated classes. Using this flag this behavior can be disabled.").buildFlagParameter();
    FlagCliParameter accessExtended = new CliParameterBuilder("-e").setDescription("Enable access to extensions. This flag enables accessing and setting extension bytes of sequences of extensible modules.").buildFlagParameter();
    FlagCliParameter legacyMode = new CliParameterBuilder("-l").setDescription("Enable legacy mode. Earlier versions of the ASN1bean 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(disableWritingVersion);
    cliParameters.add(accessExtended);
    cliParameters.add(legacyMode);
    CliParser cliParser = new CliParser("asn1bean-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());
    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(), disableWritingVersion.isSelected(), accessExtended.isSelected());
    classWriter.translate();
    System.out.println("done");
}
Also used : FlagCliParameter(com.beanit.asn1bean.compiler.cli.FlagCliParameter) StringCliParameter(com.beanit.asn1bean.compiler.cli.StringCliParameter) StringListCliParameter(com.beanit.asn1bean.compiler.cli.StringListCliParameter) CliParameter(com.beanit.asn1bean.compiler.cli.CliParameter) StringListCliParameter(com.beanit.asn1bean.compiler.cli.StringListCliParameter) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CliParameterBuilder(com.beanit.asn1bean.compiler.cli.CliParameterBuilder) FlagCliParameter(com.beanit.asn1bean.compiler.cli.FlagCliParameter) AsnModule(com.beanit.asn1bean.compiler.model.AsnModule) AsnModel(com.beanit.asn1bean.compiler.model.AsnModel) CliParser(com.beanit.asn1bean.compiler.cli.CliParser) CliParseException(com.beanit.asn1bean.compiler.cli.CliParseException) StringCliParameter(com.beanit.asn1bean.compiler.cli.StringCliParameter)

Aggregations

CliParameter (com.beanit.asn1bean.compiler.cli.CliParameter)1 CliParameterBuilder (com.beanit.asn1bean.compiler.cli.CliParameterBuilder)1 CliParseException (com.beanit.asn1bean.compiler.cli.CliParseException)1 CliParser (com.beanit.asn1bean.compiler.cli.CliParser)1 FlagCliParameter (com.beanit.asn1bean.compiler.cli.FlagCliParameter)1 StringCliParameter (com.beanit.asn1bean.compiler.cli.StringCliParameter)1 StringListCliParameter (com.beanit.asn1bean.compiler.cli.StringListCliParameter)1 AsnModel (com.beanit.asn1bean.compiler.model.AsnModel)1 AsnModule (com.beanit.asn1bean.compiler.model.AsnModule)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1