Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
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
- Loading branch information
Showing
4 changed files
with
243 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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> |