Esempio n. 1
0
  private void parseLexFile(File lexFile) throws MojoFailureException, MojoExecutionException {
    assert lexFile.isAbsolute() : lexFile;

    getLog().debug("Generating Java code from " + lexFile.getName());
    ClassInfo classInfo;
    try {
      classInfo = LexSimpleAnalyzer.guessPackageAndClass(lexFile);
    } catch (FileNotFoundException e) {
      throw new MojoFailureException(e.getMessage(), e);
    } catch (IOException e) {
      classInfo = new ClassInfo();
      classInfo.className = LexSimpleAnalyzer.DEFAULT_NAME;
      classInfo.packageName = null; // NOPMD
    }

    checkParameters(lexFile);

    /* set destination directory */
    File generatedFile = new File(outputDirectory, classInfo.getOutputFilename());

    /* Generate only if needs to */
    if (lexFile.lastModified() - generatedFile.lastModified() <= this.staleMillis) {
      getLog().info("  " + generatedFile.getName() + " is up to date.");
      getLog().debug("StaleMillis = " + staleMillis + "ms");
      return;
    }

    /*
     * set options. Very strange that JFlex expects this in a static way.
     */
    Options.setDefaults();
    Options.setDir(generatedFile.getParentFile());
    Options.dump = dump;
    Options.verbose = verbose;
    Options.unused_warning = unusedWarning;
    Options.dot = dot;
    Options.legacy_dot = legacyDot;
    Options.emitInputStreamCtor = inputStreamCtor;
    if (skeleton != null) {
      Options.setSkeleton(skeleton);
    }
    Options.jlex = jlex;

    Options.no_minimize = !minimize; // NOPMD
    Options.no_backup = !backup; // NOPMD
    if ("pack".equals(generationMethod)) {
      /* no-op - there is only one generation method */
    } else {
      throw new MojoExecutionException("Illegal generation method: " + generationMethod);
    }

    try {
      Main.generate(lexFile);
      getLog().info("  generated " + generatedFile);
    } catch (Exception e) {
      throw new MojoExecutionException(e.getMessage(), e);
    }
  }
Esempio n. 2
0
 public static void generarLexer(String path) {
   File file = new File(path);
   jflex.Main.generate(file);
 }