public static void main(String[] args) throws ParseException, IOException {

    OptionsHelper optionsHelper = new OptionsHelper();

    Options options = new Options();
    options.addOption(OPTION_FIX);
    options.addOption(OPTION_DST_CFG_URI);
    options.addOption(OPTION_CUBE);

    boolean ifFix = false;
    String dstCfgUri;
    String cubeName;
    logger.info("jobs args: " + Arrays.toString(args));
    try {

      optionsHelper.parseOptions(options, args);

      logger.info("options: '" + options.toString() + "'");
      logger.info("option value 'fix': '" + optionsHelper.getOptionValue(OPTION_FIX) + "'");
      ifFix = Boolean.parseBoolean(optionsHelper.getOptionValue(OPTION_FIX));

      logger.info(
          "option value 'dstCfgUri': '" + optionsHelper.getOptionValue(OPTION_DST_CFG_URI) + "'");
      dstCfgUri = optionsHelper.getOptionValue(OPTION_DST_CFG_URI);

      logger.info("option value 'cube': '" + optionsHelper.getOptionValue(OPTION_CUBE) + "'");
      cubeName = optionsHelper.getOptionValue(OPTION_CUBE);

    } catch (ParseException e) {
      optionsHelper.printUsage(CubeMigrationCheckCLI.class.getName(), options);
      throw e;
    }

    KylinConfig kylinConfig;
    if (dstCfgUri == null) {
      kylinConfig = KylinConfig.getInstanceFromEnv();
    } else {
      kylinConfig = KylinConfig.createInstanceFromUri(dstCfgUri);
    }

    CubeMigrationCheckCLI checkCLI = new CubeMigrationCheckCLI(kylinConfig, ifFix);
    checkCLI.execute(cubeName);
  }
Example #2
0
  public static void main(String[] args) {
    Options options = new Options();
    options.addOption("l", true, "Language to generate");
    options.addOption("o", true, "Output root folder for kernel files");
    options.addOption("a", true, "Output root folder for api files");
    options.addOption("d", true, "Template dir to use (use either this or 't')");
    options.addOption("t", true, "Template file to use (use either this or 'd')");
    options.addOption(
        "g", true, "The type of grammar to generate, current options are 'SDK' or 'API'");
    options.addOption("mainApiFile", true, "FileName specifying the api");
    options.addOption(
        "codeSamplesJava", true, "A path to search for files that have Java code samples");
    options.addOption(
        "codeSamplesPython", true, "A path to search for files that have Python code samples");

    CommandLineParser cparser = new PosixParser();
    try {
      CommandLine cmd = cparser.parse(options, args);
      String mainApiFile = cmd.getOptionValue("mainApiFile");
      String outputKernelFolder = cmd.getOptionValue('o');
      String outputApiFolder = cmd.getOptionValue('a');
      String codeSamplesJava = cmd.getOptionValue("codeSamplesJava");
      String codeSamplesPython = cmd.getOptionValue("codeSamplesPython");

      GenType genType = GenType.valueOf(cmd.getOptionValue('g'));

      // The language will ultimately choose the walker class
      String language = cmd.getOptionValue('l');
      if (cmd.hasOption('d') && cmd.hasOption('t')) {
        throw new IllegalArgumentException(
            "Cannot define both a template folder ('d') and file ('t'). Please use one OR the other.");
      }

      // And off we go

      TLexer lexer = new TLexer();
      ResourceBasedApiReader apiReader = new ResourceBasedApiReader();
      lexer.setApiReader(apiReader);
      lexer.setCharStream(apiReader.read(mainApiFile));

      // Using the lexer as the token source, we create a token
      // stream to be consumed by the parser
      //
      CommonTokenStream tokens = new CommonTokenStream(lexer);

      // Now we need an instance of our parser
      //
      TParser parser = new TParser(tokens);

      hmxdef_return psrReturn = parser.hmxdef();

      // load in T.stg template group, put in templates variable
      StringTemplateGroup templates = null;

      if (!isSlateMd(language)) {
        templates = TemplateRepo.getTemplates(language, genType);
      }
      Tree t = psrReturn.getTree();

      CommonTreeNodeStream ns = new CommonTreeNodeStream(t);
      ns.setTokenStream(tokens);
      if (templates != null) {
        templates.registerRenderer(String.class, new UpCaseRenderer());
      }
      AbstractTTree walker = TreeFactory.createTreeWalker(ns, templates, language);
      System.out.println("Generating files with a " + walker.getClass().getName());
      if (walker instanceof TTree) {
        if (genType.equals(GenType.API)) {
          ((TTree) walker).apiGen();
        } else {
          ((TTree) walker).sdkGen();
        }
      } else if (walker instanceof TTreeRuby) {
        System.out.println("Running for Ruby");
        /* TTreeRuby.hmxdef_return out = */
        ((TTreeRuby) walker).hmxdef();
      } else if (walker instanceof TTreeJS) {
        System.out.println("Running for JavaScript");
        /* TTreeJS.hmxdef_return out = */
        ((TTreeJS) walker).hmxdef();
      } else if (walker instanceof TTreeDoc) {
        System.out.println("Running for Documentation");
        /* TTreeDoc.hmxdef_return out = */
        ((TTreeDoc) walker).hmxdef();
      } else if (walker instanceof TTreeVB) {
        System.out.println("Running for VB");
        /* TTreeVB.hmxdef_return out = */
        ((TTreeVB) walker).hmxdef();
      } else if (walker instanceof TTreeGo) {
        System.out.println("Running for Go");
        /* TTreeGo.hmxdef_return out = */
        ((TTreeGo) walker).hmxdef();
      } else if (walker instanceof TTreePython) {
        System.out.println("Running for Python");
        /* TTreePython.hmxdef_return out = */
        ((TTreePython) walker).hmxdef();
      } else if (walker instanceof TTreeSlateMd) {
        System.out.println("Running for Slate Markdown");
        TTreeSlateMd slateMdWalker = (TTreeSlateMd) walker;
        slateMdWalker.setupCodeParser(codeSamplesJava, codeSamplesPython);
        slateMdWalker.hmxdef();
      } else if (walker instanceof TTreeDotNet) {
        System.out.println("Running for DotNet");
        ((TTreeDotNet) walker).apiGen();
      } else if (walker instanceof TTreeCurtisDoc) {
        System.out.println("Running for CurtisDoc");
        ((TTreeCurtisDoc) walker).apiGen();
      }
      // Now dump the files out
      System.out.println("Dumping files to " + outputKernelFolder + " and " + outputApiFolder);
      walker.dumpFiles(outputKernelFolder, outputApiFolder);

    } catch (ParseException e) {
      System.err.println("Error parsing command line - " + e.getMessage());
      System.out.println("Usage: " + options.toString());
    } catch (IOException | RecognitionException e) {
      System.err.println("Error running GenApi: " + ExceptionToString.format(e));
    }
  }