Made a maven mojo.. setting up a test module 


git-svn-id: https://svn.apache.org/repos/asf/activemq/sandbox/activemq-protobuf@690372 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/activemq-protobuf-test/pom.xml b/activemq-protobuf-test/pom.xml
new file mode 100644
index 0000000..a2910c5
--- /dev/null
+++ b/activemq-protobuf-test/pom.xml
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+  
+  http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<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 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.activemq.protobuf</groupId>
+    <artifactId>activemq-protobuf-pom</artifactId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+
+  <groupId>org.apache.activemq.protobuf</groupId>
+  <artifactId>activemq-protobuf-test</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  
+  <packaging>jar</packaging>
+  <name>ActiveMQ Protocol Buffers Tests</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.4</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.activemq.protobuf</groupId>
+      <artifactId>activemq-protobuf</artifactId>
+      <version>1.0-SNAPSHOT</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <source>1.5</source>
+          <target>1.5</target>
+        </configuration>
+      </plugin>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <includes>
+            <include>**/*Test.java</include>
+          </includes>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.activemq.protobuf</groupId>
+        <artifactId>activemq-protobuf</artifactId>
+        <version>1.0-SNAPSHOT</version>
+         <executions>
+          <execution>
+            <goals>
+              <goal>compile</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+  
+</project>
diff --git a/activemq-protobuf/pom.xml b/activemq-protobuf/pom.xml
index 348067f..454ddf4 100644
--- a/activemq-protobuf/pom.xml
+++ b/activemq-protobuf/pom.xml
@@ -18,29 +18,49 @@
 <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 http://maven.apache.org/maven-v4_0_0.xsd">
   
   <modelVersion>4.0.0</modelVersion>
-  
+  <parent>
+    <groupId>org.apache.activemq.protobuf</groupId>
+    <artifactId>activemq-protobuf-pom</artifactId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+
   <groupId>org.apache.activemq.protobuf</groupId>
   <artifactId>activemq-protobuf</artifactId>
   <version>1.0-SNAPSHOT</version>
-  <packaging>jar</packaging>
-  <name>A Simple Protocol Buffer Java API</name>
+  <packaging>maven-plugin</packaging>
+  
+  <name>ActiveMQ Protocol Buffers Implementation and Compiler</name>
 
   <description>
-    A Simpler Protocol Buffer Java API.  Comes with a built in proto file compiler and Java source code generator.
+    A Simpler Protocol Buffer Java API.  Includes a Proto to Java compiler.
   </description>
 
   <dependencies>
     <dependency>
+      <groupId>com.google.protobuf</groupId>
+      <artifactId>protobuf-java</artifactId>
+      <version>2.0.1rc1</version>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>2.0</version>
+      <optional>true</optional>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-project</artifactId>
+      <version>2.0</version>
+      <optional>true</optional>
+    </dependency>
+    
+    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>4.4</version>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>com.google.protobuf</groupId>
-      <artifactId>protobuf-java</artifactId>
-      <version>2.0.1rc1</version>
-    </dependency>
   </dependencies>
 
   <build>
diff --git a/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ProtoMojo.java b/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ProtoMojo.java
new file mode 100644
index 0000000..7d9614a
--- /dev/null
+++ b/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/ProtoMojo.java
@@ -0,0 +1,95 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.protobuf.compiler;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.activemq.protobuf.compiler.JavaGenerator.CompilerException;
+import org.apache.activemq.protobuf.compiler.parser.ParseException;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * A Maven Mojo so that the Proto compiler can be used with maven.
+ * 
+ * @goal compile
+ * @phase process-sources
+ */
+public class ProtoMojo extends AbstractMojo {
+
+    /**
+     * The maven project.
+     * 
+     * @parameter expression="${project}"
+     * @required
+     * @readonly
+     */
+    protected MavenProject project;
+
+    /**
+     * The directory where the proto files (<code>*.proto</code>) are
+     * located.
+     * 
+     * @parameter expression="${sourceDirectory}" default-value="${basedir}/src/main/proto"
+     */
+    private File sourceDirectory;
+
+    /**
+     * The directory where the output files will be located.
+     * 
+     * @parameter expression="${outputDirectory}" default-value="${project.build.directory}/generated-sources/proto"
+     */
+    private File outputDirectory;
+
+    public void execute() throws MojoExecutionException {
+
+        File[] files = sourceDirectory.listFiles(new FileFilter() {
+            public boolean accept(File pathname) {
+                return pathname.getName().endsWith(".proto");
+            }
+        });
+        
+        if (files==null || files.length==0) {
+            getLog().warn("No proto files found in directory: " + sourceDirectory.getPath());
+            return;
+        }
+        
+        List<File> recFiles = Arrays.asList(files);
+        for (File file : recFiles) {
+            try {
+                JavaGenerator generator = new JavaGenerator();
+                generator.setOutputDirectory(outputDirectory);
+                generator.compile(file);
+            } catch (ParseException e) {
+                throw new MojoExecutionException("Parse failed: " + e.getMessage(), e);
+            } catch (CompilerException e) {
+                throw new MojoExecutionException("Compile failed", e);
+            } catch (IOException e) {
+                throw new MojoExecutionException("IO Error occured: " + e.getMessage(), e);
+            }
+        }
+
+        this.project.addCompileSourceRoot(outputDirectory.getAbsolutePath());
+    }
+
+}
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..c6d6eb3
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+  
+  http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<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 http://maven.apache.org/maven-v4_0_0.xsd">
+  
+  <modelVersion>4.0.0</modelVersion>
+  
+  <groupId>org.apache.activemq.protobuf</groupId>
+  <artifactId>activemq-protobuf-pom</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  
+  <packaging>pom</packaging>
+  <name>ActiveMQ Protocol Buffers POM</name>
+
+  <description>
+    A Simpler Protocol Buffer Java API.  Comes with a built in proto file compiler and Java source code generator.
+  </description>
+
+  <modules>
+    <module>activemq-protobuf</module>
+    <module>activemq-protobuf-test</module>
+  </modules>
+
+  
+</project>