mavenmaven-pluginsablecc

How does Maven know where input files come from and where output files go during the generate-sources phase?


I am new to Maven. I have a project which includes a grammar definition file that is read by SableCC, which is a parser generator. SableCC reads a grammar file and generates Java source code that, once compiled, creates a parser. The parser is used by the rest of my project.

I don't think my question is a SableCC question, as I've seen similar POM.XML files that use Antlr (another parser generator that is comparable to SableCC) and the <plugin> section of that POM.XML looks nearly the same as my <plugin> section in my POM.XML file.

Here is my project's file structure, identifying those parts that are used by SableCC:

enter image description here

Here is my complete POM.XML file, which I've cobbled together based on the plugin examples I've seen so far (and in particular, the one for SableCC):

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mbm</groupId>
    <artifactId>properties</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Properties</name>
    <description>Define and process program arguments</description>
    <dependencies>
    </dependencies>
    <build>
        <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>sablecc-maven-plugin</artifactId>
                <version>2.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        </pluginManagement>
    </build>
</project>

My question is how does the SableCC plugin know where the input file is and where the 4 categories of generated output Java source files (analysis, lexer, node and parser) should go? I suspect I need to add more Maven "stuff" to my POM file, but I don't know what.


Solution

  • You can see the plugin configurations here: https://github.com/tychobrailleur/sablecc-maven-plugin

    More specifically:

    sourceDirectory: Directory containing grammar files. By default, ${basedir}/src/main/sablecc

    outputDirectory: Directory containing the generated sources. By default, ${project.build.directory}/generated-sources/sablecc

    You can also extract the JAR and see these configurations in the plugin.xml file:

    <configuration>
      <outputDirectory implementation="java.lang.String">${project.build.directory}/generated-sources/sablecc</outputDirectory>
      <timestampDirectory implementation="java.lang.String">${basedir}/target</timestampDirectory>
      <sourceDirectory implementation="java.lang.String">${basedir}/src/main/sablecc</sourceDirectory>
      <project implementation="org.apache.maven.project.MavenProject">${project}</project>
      <staleMillis implementation="int" default-value="0">${lastModGranularityMs}</staleMillis>
    </configuration>