Search in sources :

Example 1 with JSAPException

use of com.martiansoftware.jsap.JSAPException in project spoon by INRIA.

the class Launcher method defineArgs.

/**
 * Defines the common arguments for sub-launchers.
 *
 * @return the JSAP arguments
 */
protected static JSAP defineArgs() {
    try {
        // Verbose output
        JSAP jsap = new JSAP();
        // help
        Switch sw1 = new Switch("help");
        sw1.setShortFlag('h');
        sw1.setLongFlag("help");
        sw1.setDefault("false");
        jsap.registerParameter(sw1);
        // Tabs
        sw1 = new Switch("tabs");
        sw1.setLongFlag("tabs");
        sw1.setDefault("false");
        sw1.setHelp("Use tabulations instead of spaces in the generated code (use spaces by default).");
        jsap.registerParameter(sw1);
        // Tab size
        FlaggedOption opt2 = new FlaggedOption("tabsize");
        opt2.setLongFlag("tabsize");
        opt2.setStringParser(JSAP.INTEGER_PARSER);
        opt2.setDefault("4");
        opt2.setHelp("Define tabulation size.");
        jsap.registerParameter(opt2);
        // Level logging.
        opt2 = new FlaggedOption("level");
        opt2.setLongFlag("level");
        opt2.setHelp("Level of the ouput messages about what spoon is doing.");
        opt2.setStringParser(JSAP.STRING_PARSER);
        opt2.setDefault(Level.ERROR.toString());
        jsap.registerParameter(opt2);
        // Auto-import
        sw1 = new Switch("imports");
        sw1.setLongFlag("with-imports");
        sw1.setDefault("false");
        sw1.setHelp("Enable imports in generated files.");
        jsap.registerParameter(sw1);
        // java compliance
        opt2 = new FlaggedOption("compliance");
        opt2.setLongFlag("compliance");
        opt2.setHelp("Java source code compliance level (1,2,3,4,5, 6, 7 or 8).");
        opt2.setStringParser(JSAP.INTEGER_PARSER);
        opt2.setDefault(DEFAULT_CODE_COMPLIANCE_LEVEL + "");
        jsap.registerParameter(opt2);
        // compiler's encoding
        opt2 = new FlaggedOption("encoding");
        opt2.setLongFlag("encoding");
        opt2.setStringParser(JSAP.STRING_PARSER);
        opt2.setRequired(false);
        opt2.setDefault("UTF-8");
        opt2.setHelp("Forces the compiler to use a specific encoding (UTF-8, UTF-16, ...).");
        jsap.registerParameter(opt2);
        // setting Input files & Directory
        opt2 = new FlaggedOption("input");
        opt2.setShortFlag('i');
        opt2.setLongFlag("input");
        opt2.setStringParser(JSAP.STRING_PARSER);
        opt2.setRequired(false);
        opt2.setHelp("List of path to sources files.");
        jsap.registerParameter(opt2);
        // Processor qualified name
        opt2 = new FlaggedOption("processors");
        opt2.setShortFlag('p');
        opt2.setLongFlag("processors");
        opt2.setHelp("List of processor's qualified name to be used.");
        opt2.setStringParser(JSAP.STRING_PARSER);
        opt2.setRequired(false);
        jsap.registerParameter(opt2);
        // setting input template
        opt2 = new FlaggedOption("template");
        opt2.setShortFlag('t');
        opt2.setLongFlag("template");
        opt2.setHelp("List of source templates.");
        opt2.setStringParser(JSAP.STRING_PARSER);
        opt2.setRequired(false);
        opt2.setHelp("List of path to templates java files.");
        jsap.registerParameter(opt2);
        // Spooned output directory
        opt2 = new FlaggedOption("output");
        opt2.setShortFlag('o');
        opt2.setLongFlag("output");
        opt2.setDefault(OUTPUTDIR);
        opt2.setHelp("Specify where to place generated java files.");
        opt2.setStringParser(FileStringParser.getParser());
        opt2.setRequired(false);
        jsap.registerParameter(opt2);
        // Source classpath
        opt2 = new FlaggedOption("source-classpath");
        opt2.setLongFlag("source-classpath");
        opt2.setHelp("An optional classpath to be passed to the internal " + "Java compiler when building or compiling the " + "input sources.");
        opt2.setStringParser(JSAP.STRING_PARSER);
        opt2.setRequired(false);
        jsap.registerParameter(opt2);
        // Template classpath
        opt2 = new FlaggedOption("template-classpath");
        opt2.setLongFlag("template-classpath");
        opt2.setHelp("An optional classpath to be passed to the " + "internal Java compiler when building " + "the template sources.");
        opt2.setStringParser(JSAP.STRING_PARSER);
        opt2.setRequired(false);
        jsap.registerParameter(opt2);
        // Destination
        opt2 = new FlaggedOption("destination");
        opt2.setShortFlag('d');
        opt2.setLongFlag("destination");
        opt2.setDefault(SPOONED_CLASSES);
        opt2.setHelp("An optional destination directory for the generated class files.");
        opt2.setStringParser(FileStringParser.getParser());
        opt2.setRequired(false);
        jsap.registerParameter(opt2);
        // Sets output type generation
        opt2 = new FlaggedOption("output-type");
        opt2.setLongFlag(opt2.getID());
        String msg = "States how to print the processed source code: ";
        int i = 0;
        for (OutputType v : OutputType.values()) {
            i++;
            msg += v.toString();
            if (i != OutputType.values().length) {
                msg += "|";
            }
        }
        opt2.setStringParser(JSAP.STRING_PARSER);
        opt2.setHelp(msg);
        opt2.setDefault("classes");
        jsap.registerParameter(opt2);
        // Enable compilation
        sw1 = new Switch("compile");
        sw1.setLongFlag(sw1.getUsageName());
        sw1.setHelp("Compiles the resulting classes (after transformation) to bytecode.");
        sw1.setDefault("false");
        jsap.registerParameter(sw1);
        // Enable pre-compilation
        sw1 = new Switch("precompile");
        sw1.setLongFlag("precompile");
        sw1.setHelp("[experimental] Enable pre-compilation of input source files " + "before processing. The compiled classes " + "will be added to the classpath.");
        sw1.setDefault("false");
        jsap.registerParameter(sw1);
        sw1 = new Switch("lines");
        sw1.setLongFlag("lines");
        sw1.setHelp("Set Spoon to try to preserve the original line " + "numbers when generating the source " + "code (may lead to human-unfriendly " + "formatting).");
        sw1.setDefault("false");
        jsap.registerParameter(sw1);
        // nobinding
        sw1 = new Switch("noclasspath");
        sw1.setShortFlag('x');
        sw1.setLongFlag("noclasspath");
        sw1.setHelp("Does not assume a full classpath");
        jsap.registerParameter(sw1);
        // show GUI
        sw1 = new Switch("gui");
        sw1.setShortFlag('g');
        sw1.setLongFlag("gui");
        sw1.setHelp("Show spoon model after processing");
        jsap.registerParameter(sw1);
        // Disable copy of resources.
        sw1 = new Switch("no-copy-resources");
        sw1.setShortFlag('r');
        sw1.setLongFlag("no-copy-resources");
        sw1.setHelp("Disable the copy of resources from source to destination folder.");
        sw1.setDefault("false");
        jsap.registerParameter(sw1);
        // Enable generation of javadoc.
        sw1 = new Switch("enable-comments");
        sw1.setShortFlag('c');
        sw1.setLongFlag("enable-comments");
        sw1.setHelp("Adds all code comments in the Spoon AST (Javadoc, line-based comments), rewrites them when pretty-printing.");
        sw1.setDefault("false");
        jsap.registerParameter(sw1);
        // Generate only java files specified.
        opt2 = new FlaggedOption("generate-files");
        opt2.setShortFlag('f');
        opt2.setLongFlag("generate-files");
        opt2.setHelp("Only generate the given fully qualified java classes (separated by ':' if multiple are given).");
        opt2.setStringParser(JSAP.STRING_PARSER);
        opt2.setRequired(false);
        jsap.registerParameter(opt2);
        // Disable checks.
        sw1 = new Switch("disable-model-self-checks");
        sw1.setShortFlag('a');
        sw1.setLongFlag("disable-model-self-checks");
        sw1.setHelp("Disables checks made on the AST (hashcode violation, method's signature violation and parent violation). Default: false.");
        sw1.setDefault("false");
        jsap.registerParameter(sw1);
        return jsap;
    } catch (JSAPException e) {
        throw new SpoonException(e.getMessage(), e);
    }
}
Also used : Switch(com.martiansoftware.jsap.Switch) FlaggedOption(com.martiansoftware.jsap.FlaggedOption) JSAPException(com.martiansoftware.jsap.JSAPException) JSAP(com.martiansoftware.jsap.JSAP)

Aggregations

FlaggedOption (com.martiansoftware.jsap.FlaggedOption)1 JSAP (com.martiansoftware.jsap.JSAP)1 JSAPException (com.martiansoftware.jsap.JSAPException)1 Switch (com.martiansoftware.jsap.Switch)1