From 586eb8c2b5f70fc3256c88f4eda96af7d457ce4c Mon Sep 17 00:00:00 2001
From: Tommy Olofsson <tommy.olofsson.90@gmail.com>
Date: Fri, 6 Feb 2015 02:19:24 +0100
Subject: [PATCH] Made the maven plugin better.

---
 labcomm-compiler-plugin/pom.xml               |  6 ++
 labcomm-compiler-plugin/readme.md             | 66 +++++++++++++++++++
 .../src/main/java/se/lth/control/App.java     | 26 +++++---
 3 files changed, 88 insertions(+), 10 deletions(-)
 create mode 100644 labcomm-compiler-plugin/readme.md

diff --git a/labcomm-compiler-plugin/pom.xml b/labcomm-compiler-plugin/pom.xml
index 53cf683..2dd205e 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 0000000..55064d1
--- /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 e9a11b5..3bc2b98 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,
+		});
 	}
 }
-- 
GitLab