summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorRomain Gilles <rgilles@github>2016-06-07 09:05:56 +0200
committerRomain Gilles <rgilles@github>2016-06-07 09:05:56 +0200
commit9875b0e0f8af5781a793fb93807641c9cebfb903 (patch)
tree3184c6e819a56e518852ae86e3b456ebbc0c0e44 /java
parente92ae5199d52fd59540a800bec7eef46cd778257 (diff)
downloadflatbuffers-9875b0e0f8af5781a793fb93807641c9cebfb903.tar.gz
flatbuffers-9875b0e0f8af5781a793fb93807641c9cebfb903.tar.bz2
flatbuffers-9875b0e0f8af5781a793fb93807641c9cebfb903.zip
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.
Diffstat (limited to 'java')
-rw-r--r--java/flatbuffers/pom.xml65
-rw-r--r--java/flatbuffers/src/main/java/com/google/flatbuffers/Constants.java (renamed from java/com/google/flatbuffers/Constants.java)0
-rw-r--r--java/flatbuffers/src/main/java/com/google/flatbuffers/FlatBufferBuilder.java (renamed from java/com/google/flatbuffers/FlatBufferBuilder.java)0
-rw-r--r--java/flatbuffers/src/main/java/com/google/flatbuffers/Struct.java (renamed from java/com/google/flatbuffers/Struct.java)0
-rw-r--r--java/flatbuffers/src/main/java/com/google/flatbuffers/Table.java (renamed from java/com/google/flatbuffers/Table.java)0
-rw-r--r--java/flatbuffers/src/test/fbs/test.fbs19
-rw-r--r--java/flatbuffers/src/test/java/com/google/flatbuffers/test/DummyTest.java25
-rw-r--r--java/jmh/pom.xml77
-rw-r--r--java/pom.xml53
9 files changed, 231 insertions, 8 deletions
diff --git a/java/flatbuffers/pom.xml b/java/flatbuffers/pom.xml
new file mode 100644
index 00000000..7b6ea793
--- /dev/null
+++ b/java/flatbuffers/pom.xml
@@ -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>
+
diff --git a/java/com/google/flatbuffers/Constants.java b/java/flatbuffers/src/main/java/com/google/flatbuffers/Constants.java
index ac0593ae..ac0593ae 100644
--- a/java/com/google/flatbuffers/Constants.java
+++ b/java/flatbuffers/src/main/java/com/google/flatbuffers/Constants.java
diff --git a/java/com/google/flatbuffers/FlatBufferBuilder.java b/java/flatbuffers/src/main/java/com/google/flatbuffers/FlatBufferBuilder.java
index fecb213f..fecb213f 100644
--- a/java/com/google/flatbuffers/FlatBufferBuilder.java
+++ b/java/flatbuffers/src/main/java/com/google/flatbuffers/FlatBufferBuilder.java
diff --git a/java/com/google/flatbuffers/Struct.java b/java/flatbuffers/src/main/java/com/google/flatbuffers/Struct.java
index ae315531..ae315531 100644
--- a/java/com/google/flatbuffers/Struct.java
+++ b/java/flatbuffers/src/main/java/com/google/flatbuffers/Struct.java
diff --git a/java/com/google/flatbuffers/Table.java b/java/flatbuffers/src/main/java/com/google/flatbuffers/Table.java
index 40876542..40876542 100644
--- a/java/com/google/flatbuffers/Table.java
+++ b/java/flatbuffers/src/main/java/com/google/flatbuffers/Table.java
diff --git a/java/flatbuffers/src/test/fbs/test.fbs b/java/flatbuffers/src/test/fbs/test.fbs
new file mode 100644
index 00000000..695b94e4
--- /dev/null
+++ b/java/flatbuffers/src/test/fbs/test.fbs
@@ -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; \ No newline at end of file
diff --git a/java/flatbuffers/src/test/java/com/google/flatbuffers/test/DummyTest.java b/java/flatbuffers/src/test/java/com/google/flatbuffers/test/DummyTest.java
new file mode 100644
index 00000000..627050b5
--- /dev/null
+++ b/java/flatbuffers/src/test/java/com/google/flatbuffers/test/DummyTest.java
@@ -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));
+ }
+}
diff --git a/java/jmh/pom.xml b/java/jmh/pom.xml
new file mode 100644
index 00000000..9be79842
--- /dev/null
+++ b/java/jmh/pom.xml
@@ -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>
+
diff --git a/java/pom.xml b/java/pom.xml
index dd92b9d5..2297dbe3 100644
--- a/java/pom.xml
+++ b/java/pom.xml
@@ -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>