Create a maven like project structure for java development. Make it OSGi compliant. Generate the flatbuffers code for testing (example).

Java developer are mostly comfortable with maven project structure. One one the main concept behind maven is convention. If you follow the maven project convention then your development team will get more effective as they now this project structure and can easily find the production code versus the test code.
 In this pull request I have structured the java project around 2 main parts:
  * the `flatbuffers` project. This project is the api / lib project and contains the test code structure + an example of code generation for testing. This avoid to commit generated code. Pre-configure JUnit for test driven development and make this project OSGi compliant.
  * the `jmh` project. This project aims to provide a placeholder for micro-benchmarking. JMH is a 'de facto' standard for micro benchmarking you can find more details here: http://openjdk.java.net/projects/code-tools/jmh/

For now I didn't move the JavaTest class but it could be a next step with a migration to the JUnit framework.
The only impacts are the move of the class and the project structure => no code change.
This commit is contained in:
Romain Gilles 2016-06-07 09:05:56 +02:00
parent e92ae5199d
commit 9875b0e0f8
10 changed files with 233 additions and 10 deletions

4
.gitignore vendored
View File

@ -54,8 +54,8 @@ build/Xcode/FlatBuffers.xcodeproj/project.xcworkspace/**
build/Xcode/FlatBuffers.xcodeproj/xcuserdata/**
FlatBuffers.xcodeproj/
java/.idea
java/*.iml
java/target
*.iml
target
**/*.pyc
.idea
build/VS2010/FlatBuffers.sdf

65
java/flatbuffers/pom.xml Normal file
View File

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<groupId>com.google.flatbuffers</groupId>
<artifactId>flatbuffers</artifactId>
<version>1.3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>flatbuffers-java</artifactId>
<packaging>bundle</packaging>
<name>FlatBuffers Java API</name>
<description>
Memory Efficient Serialization Library
</description>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<flatbuffers.root.dir>${basedir}/../..</flatbuffers.root.dir>
<generated.test.sources.directory>${project.build.directory}/generated-test-sources/flatbuffers
</generated.test.sources.directory>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${flatbuffers.root.dir}/flatc</executable>
<arguments>
<argument>--java</argument>
<argument>-o</argument>
<argument>${generated.test.sources.directory}</argument>
<argument>${basedir}/src/test/fbs/test.fbs</argument>
</arguments>
<testSourceRoot>${generated.test.sources.directory}</testSourceRoot>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,19 @@
namespace com.google.flatbuffer.test;
table MyTable
{
foo:int;
}
enum MyEnum:byte
{
A, B, C
}
struct MyStruct
{
a:int;
b:int;
}
root_type MyTable;

View File

@ -0,0 +1,25 @@
package com.google.flatbuffers.test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Test;
import com.google.flatbuffer.test.MyTable;
import com.google.flatbuffers.FlatBufferBuilder;
/**
* Dummy Test to demo JUnit usage.
*/
public class DummyTest {
@Test
public void testDummy() {
FlatBufferBuilder builder = new FlatBufferBuilder();
int tableOffSet = MyTable.createMyTable(builder, 42);
MyTable.finishMyTableBuffer(builder, tableOffSet);
MyTable myTable = MyTable.getRootAsMyTable(builder.dataBuffer());
assertThat(myTable.foo(), is(42));
}
}

77
java/jmh/pom.xml Normal file
View File

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<groupId>com.google.flatbuffers</groupId>
<artifactId>flatbuffers</artifactId>
<version>1.3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>flatbuffers-jmh</artifactId>
<packaging>jar</packaging>
<name>FlatBuffers JMH micro-benchmark</name>
<description>
Micro benchmark to help in technical design decisions.
</description>
<properties>
<jmh.version>1.12</jmh.version>
<uberjar.name>benchmarks</uberjar.name>
</properties>
<dependencies>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${jmh.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>${uberjar.name}</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.openjdk.jmh.Main</mainClass>
</transformer>
</transformers>
<filters>
<filter>
<!--
Shading signed JARs will fail without this.
http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar
-->
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
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>com.google.flatbuffers</groupId>
<artifactId>flatbuffers-java</artifactId>
<artifactId>flatbuffers</artifactId>
<version>1.3.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>FlatBuffers Java API</name>
<packaging>pom</packaging>
<name>FlatBuffers</name>
<description>
Memory Efficient Serialization Library
</description>
@ -30,10 +30,47 @@
scm:git:https://github.com/google/flatbuffers.git
</connection>
</scm>
<dependencies>
</dependencies>
<prerequisites>
<maven>3.0</maven>
</prerequisites>
<modules>
<module>flatbuffers</module>
<module>jmh</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<sourceDirectory>./</sourceDirectory>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.0.1</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>