javacc / javaccPlugin

A JavaCC plugin for Gradle
MIT License
33 stars 16 forks source link

abnormal outputdirectory processing for compileJavacc #32

Closed zosrothko closed 7 years ago

zosrothko commented 7 years ago

Hi

the option outputDirectory from the DSL compileJavaCC does not work properly. Working on building JTB with gradle, one gets this issue.

The javacc file jtb.out.jj is located in src/EDU/purdue/jtb and has the option OUTPUT_DIRECTORY = "parser"; This means that javacc without any command line option will generate the Java classes in the directory src/EDU/purdue/jtb/parser

With the script below

plugins {
  id "ca.coglinc.javacc" version "2.3.1"
}

apply plugin: "ca.coglinc.javacc"
apply plugin: 'java'

compileJavacc {
  inputDirectory = file('src')
  outputDirectory = file('src')
}

javaccPlugin generates the classes in src/EDU/purdue/jtb which is wrong

With the script below

plugins {
  id "ca.coglinc.javacc" version "2.3.1"
}

apply plugin: "ca.coglinc.javacc"
apply plugin: 'java'

compileJavacc {
  inputDirectory = file('src')
  outputDirectory = file('src/EDU/purdue/jtb/parser')
}

javaccPlugin generates the classes in src/EDU/purdue/jtb/parser/EDU/purdue/jtb which is wrong

johnmartel commented 7 years ago

Have you tried not to set the outputDirectorydirective at all? Generating files in the inputDirectory is not likely to give good results. The plugin uses the OUTPUT_DIRECTORY option to generate the files in the correct location. I recommend using the package directive of the jj file to set the package to EDU.purdue.jtb.parser, which will generate the files in the correct location under build/generated/javacc. Please note that this directory is automatically added by the plugin as a source for the compile task.

zosrothko commented 7 years ago

It seems you are missing a key functionnality of the output_directory option. Javacc is generating the javacc classes in the output directory specified by the -output_directory option whatever is specified the package in the jj file. As exemple taking this Parser.jj file

options { STATIC=false; }

PARSER_BEGIN(Parser)
package foo;
public class Parser {
  public static void main(String args[]) throws Exception {
    Parser t = new Parser(System.in);
    t.CompilationUnit();
    System.out.println("Parser ran sucessfully");
  }
}
PARSER_END(Parser)
TOKEN : {  < A: "A"> | < B: "B"> | < C: "C"> | < D: "D"> }
void CompilationUnit() : {} {   ("A" | "B" )*   <EOF> }

let say the Parser.jj is located in the directory tmp. the command line

Z:\git\javacc\tmp>java -classpath ../target/javacc.jar javacc -output_directory=bar/toy/acme Parser.jj

will generate the classes in the directory tmp/bar/toy/acmewhatever is the package definition in the Parser.jj. Thus, the javaccPlugin should do the same when the outputDirectory is specified in the gradle script. The resulting generated classes must be located in the specified directory.

johnmartel commented 7 years ago

I understand this clearly, but what I'm missing is why you want to generate a java class in a directory that does not correspond to its package?

Envoyé de mon iPhone

Le 20 nov. 2016 à 12:43, zosrothko notifications@github.com a écrit :

It seems you are missing a key functionnality of the output_directory option. Javacc is generating the javacc classes in the output directory specified by the -output_directory option whatever is specified the package in the jj file. As exemple taking this Parser.jj file

options { STATIC=false; }

PARSER_BEGIN(Parser) package foo; public class Parser { public static void main(String args[]) throws Exception { Parser t = new Parser(System.in); t.CompilationUnit(); System.out.println("Parser ran sucessfully"); } } PARSER_END(Parser) TOKEN : { < A: "A"> | < B: "B"> | < C: "C"> | < D: "D"> } void CompilationUnit() : {} { ("A" | "B" )* }

let say the Parser.jj is located in the directory tmp. the command line

Z:\git\javacc\tmp>java -classpath ../target/javacc.jar javacc -output_directory=bar/toy/acme Parser.jj will generate the classes in the directory tmp/bar/toy/acmewhatever is the package definition in the Parser.jj. Thus, the javaccPlugin should do the same when the outputDirectory is specified in the gradle script. The resulting generated classes must be located in the specified directory.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

zosrothko commented 7 years ago

because that's the way javacc itself is build and also because that's the way jtb is build also. If I want to build JavaCC itself and JTB itself with gradle and your javaccPlugin, the organization of the files and the content of the *.jj files must not be changed otherwise all builder with ant will fail.

zosrothko commented 7 years ago

Moreover and as a better argument, that's the way javacc is working.

johnmartel commented 7 years ago

Closing this issue as it is basically a duplicate of Issue #31 .