Executing a javacc compilation to generate java file to be used in the compile task.

134 views
Skip to first unread message

Maatary Okouya

unread,
Aug 11, 2014, 3:54:49 AM8/11/14
to simple-b...@googlegroups.com

As far as my knowledge of sbt goes,

sounds like to execute a task like describe above, one has to run it in a Process object apply method. val = Process("""), where val would be defined as a taskKey. 

To solve the dependency i intent to put that class in resourceGenerators in compile. My intent here is that this files are generated before the compile process.


I have wrote the following test code in my sbt: 

lazy val jjParse = taskKey[Stream[String]]("compile JJ file with JavaCC ")

jjParse := Process("java -classpath ./lib/javacc.jar javacc ./src/main/java/ACLParser.jj").lines


I'll have to use javacc as an unmanaged Jar.  This will not be the exact le location of ACLParser.jj. this is just a hook for now. 

1 - My first interrogation here is, how can I actually control where the file will be outputted. As of now, the file are generated in ".".  ?


(My task actually return a string coming from JavaCC that specifies what happens.I have not access to the files written  from that tasks. ) Can be annoying to verify that the process actually worked. 


Is the approach flawed, is there other way to do that ?


Maatary Okouya

unread,
Aug 11, 2014, 5:30:43 AM8/11/14
to simple-b...@googlegroups.com
I have change the compilation line to 

lazy val jjParse = taskKey[Stream[String]]("compile JJ file with JavaCC ")

jjParse := Process("""cd ./src/main/java/ && java -classpath ../../../../lib/javacc.jar javacc ACLParser.jj && cd -""").lines


As you can see it is not that pretty. changing directory to do the computation is not my prefered solution. But it seem the only one given the javacc option that i know so far.  

Moreover, I would like to have a way to know when the task succeed or not, and to ensure that this happens before the compilation. resourceGenerators takes task that actual produce Io.File while i don't. So don't see what can i use to ensure that this computation happens before compilation.

Any guidance would be much appreciated 
Reply all
Reply to author
Forward
0 new messages