diff --git a/labcomm-compiler-plugin/pom.xml b/labcomm-compiler-plugin/pom.xml index 53cf683cba17a36cfb2e684c805e84087190711c..2dd205ecb8b171640baf7e535829a2859b756584 100644 --- a/labcomm-compiler-plugin/pom.xml +++ b/labcomm-compiler-plugin/pom.xml @@ -29,6 +29,12 @@ <scope>provided</scope> </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-project</artifactId> + <version>2.2.1</version> + </dependency> + <dependency> <groupId>se.lth.control</groupId> <artifactId>labcomm_compiler</artifactId> diff --git a/labcomm-compiler-plugin/readme.md b/labcomm-compiler-plugin/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..55064d159f3bdf6ad52393cb4bb4229221a2e9a9 --- /dev/null +++ b/labcomm-compiler-plugin/readme.md @@ -0,0 +1,66 @@ +# labcomm-compiler-plugin + +Compiles labcomm files during the maven build lifecycle. + + +## Example + +To use the plugin to compile the file `my_types.lc` put the following +in your maven build file (pom.xml). You can then use the types as +`import labcomm_gen.sample` where `sample` is the name of the +sample(s) in the my_types.lc. + +```xml +<project> + <!-- ... --> + <dependencies> + <!-- ... --> + <!-- labcomm lib --> + <dependency> + <groupId>se.lth.control</groupId> + <artifactId>labcomm</artifactId> + <version>2014.3.0-SNAPSHOT</version> + </dependency> + </dependencies> + + <build> + <plugins> + <!-- ... --> + <plugin> + <!-- labcomm compiler --> + <groupId>se.lth.control</groupId> + <artifactId>labcomm-compiler-plugin</artifactId> + <version>2014.3.0-SNAPSHOT</version> + <configuration> + <lc>path/to/my_types.lc</lc> + </configuration> + <executions> + <execution> + <phase>generate-sources</phase> + <goals> + <goal>genjava</goal> + </goals> + </execution> + </executions> + </plugin> + <build> + <plugins> + + <repositories> + <repository> + <!-- source of dep/plugin --> + <id>CSLTH</id> + <name>CS LTH maven repo</name> + <url>http://maven.cs.lth.se/content/repositories/public/</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>true</enabled> + <updatePolicy>always</updatePolicy> + </snapshots> + </repository> + </repositories> + +</project> +``` diff --git a/labcomm-compiler-plugin/src/main/java/se/lth/control/App.java b/labcomm-compiler-plugin/src/main/java/se/lth/control/App.java index e9a11b5b222d72f2efcf3a1ad5d9d603ada558ea..3bc2b98167422c184b01ac9f7ee3d7de41c1a56f 100644 --- a/labcomm-compiler-plugin/src/main/java/se/lth/control/App.java +++ b/labcomm-compiler-plugin/src/main/java/se/lth/control/App.java @@ -3,6 +3,7 @@ package se.lth.control; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.project.MavenProject; import se.lth.control.labcomm2014.compiler.LabComm; /** @@ -12,26 +13,31 @@ import se.lth.control.labcomm2014.compiler.LabComm; public class App extends AbstractMojo { /** - * @parameter default-value="notafile.lc" + * @parameter default-value="path_to_file.lc" */ private String lc; /** - * @parameter default-value="/tmp" + * @parameter default-value="${project.build.directory}/labcomm_gen" */ private String dir; /** - * @parameter default-value="generated_sources" + * @parameter default-value="labcomm_gen" */ private String pkg; - public void execute() throws MojoExecutionException { - getLog().info("Does not do anything!"); - String[] args = new String[3]; - args[0] = "--java=" + dir; - args[1] = "--javapackage=" + pkg; - args[2] = lc; - LabComm.main(args); + /** + * @parameter default-value="${project}" + */ + private MavenProject project; + + public void execute() throws MojoExecutionException { + project.addCompileSourceRoot(dir); + LabComm.main(new String[] { + "--java=" + dir, + "--javapackage=" + pkg, + lc, + }); } }