From 9875b0e0f8af5781a793fb93807641c9cebfb903 Mon Sep 17 00:00:00 2001 From: Romain Gilles Date: Tue, 7 Jun 2016 09:05:56 +0200 Subject: [PATCH] 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. --- .gitignore | 4 +- java/flatbuffers/pom.xml | 65 ++++++++++++++++ .../com/google/flatbuffers/Constants.java | 0 .../google/flatbuffers/FlatBufferBuilder.java | 0 .../java}/com/google/flatbuffers/Struct.java | 0 .../java}/com/google/flatbuffers/Table.java | 0 java/flatbuffers/src/test/fbs/test.fbs | 19 +++++ .../google/flatbuffers/test/DummyTest.java | 25 ++++++ java/jmh/pom.xml | 77 +++++++++++++++++++ java/pom.xml | 53 +++++++++++-- 10 files changed, 233 insertions(+), 10 deletions(-) create mode 100644 java/flatbuffers/pom.xml rename java/{ => flatbuffers/src/main/java}/com/google/flatbuffers/Constants.java (100%) rename java/{ => flatbuffers/src/main/java}/com/google/flatbuffers/FlatBufferBuilder.java (100%) rename java/{ => flatbuffers/src/main/java}/com/google/flatbuffers/Struct.java (100%) rename java/{ => flatbuffers/src/main/java}/com/google/flatbuffers/Table.java (100%) create mode 100644 java/flatbuffers/src/test/fbs/test.fbs create mode 100644 java/flatbuffers/src/test/java/com/google/flatbuffers/test/DummyTest.java create mode 100644 java/jmh/pom.xml diff --git a/.gitignore b/.gitignore index 6f3894d06..1ba56a0e5 100755 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/java/flatbuffers/pom.xml b/java/flatbuffers/pom.xml new file mode 100644 index 000000000..7b6ea7933 --- /dev/null +++ b/java/flatbuffers/pom.xml @@ -0,0 +1,65 @@ + + + + com.google.flatbuffers + flatbuffers + 1.3.0-SNAPSHOT + + + 4.0.0 + flatbuffers-java + bundle + FlatBuffers Java API + + Memory Efficient Serialization Library + + + + + junit + junit + test + + + + ${basedir}/../.. + ${project.build.directory}/generated-test-sources/flatbuffers + + + + + + + org.apache.felix + maven-bundle-plugin + true + + + org.codehaus.mojo + exec-maven-plugin + + + generate-test-sources + generate-test-sources + + exec + + + ${flatbuffers.root.dir}/flatc + + --java + -o + ${generated.test.sources.directory} + ${basedir}/src/test/fbs/test.fbs + + ${generated.test.sources.directory} + + + + + + + + diff --git a/java/com/google/flatbuffers/Constants.java b/java/flatbuffers/src/main/java/com/google/flatbuffers/Constants.java similarity index 100% rename from java/com/google/flatbuffers/Constants.java rename to 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 similarity index 100% rename from java/com/google/flatbuffers/FlatBufferBuilder.java rename to 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 similarity index 100% rename from java/com/google/flatbuffers/Struct.java rename to 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 similarity index 100% rename from java/com/google/flatbuffers/Table.java rename to 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 000000000..695b94e43 --- /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 000000000..627050b5f --- /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 000000000..9be798421 --- /dev/null +++ b/java/jmh/pom.xml @@ -0,0 +1,77 @@ + + + + com.google.flatbuffers + flatbuffers + 1.3.0-SNAPSHOT + + + 4.0.0 + flatbuffers-jmh + jar + FlatBuffers JMH micro-benchmark + + Micro benchmark to help in technical design decisions. + + + + 1.12 + benchmarks + + + + + org.openjdk.jmh + jmh-core + ${jmh.version} + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh.version} + provided + + + + + + + org.apache.maven.plugins + maven-shade-plugin + + + package + + shade + + + ${uberjar.name} + + + org.openjdk.jmh.Main + + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + + + + + diff --git a/java/pom.xml b/java/pom.xml index dd92b9d55..2297dbe37 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -1,13 +1,13 @@ + 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"> 4.0.0 com.google.flatbuffers - flatbuffers-java + flatbuffers 1.3.0-SNAPSHOT - jar - FlatBuffers Java API + pom + FlatBuffers Memory Efficient Serialization Library @@ -30,10 +30,47 @@ scm:git:https://github.com/google/flatbuffers.git - - + + + 3.0 + + + + + flatbuffers + jmh + + + + + + junit + junit + 4.12 + + + + - ./ + + + + org.apache.maven.plugins + maven-shade-plugin + 2.2 + + + org.codehaus.mojo + exec-maven-plugin + 1.5.0 + + + org.apache.felix + maven-bundle-plugin + 3.0.1 + + + maven-compiler-plugin