From 9875b0e0f8af5781a793fb93807641c9cebfb903 Mon Sep 17 00:00:00 2001 From: Romain Gilles Date: Tue, 7 Jun 2016 09:05:56 +0200 Subject: [PATCH 1/4] 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 From cc2b04ce1c0cdb96e6f9671f84e4cee5b94ffe46 Mon Sep 17 00:00:00 2001 From: Romain Gilles Date: Tue, 5 Jul 2016 11:38:17 +0200 Subject: [PATCH 2/4] Revert "Create a maven like project structure for java development. Make it OSGi compliant. Generate the flatbuffers code for testing (example)." This reverts commit 9875b0e0f8af5781a793fb93807641c9cebfb903. --- .gitignore | 4 +- .../com/google/flatbuffers/Constants.java | 0 .../google/flatbuffers/FlatBufferBuilder.java | 0 .../com/google/flatbuffers/Struct.java | 0 .../com/google/flatbuffers/Table.java | 0 java/flatbuffers/pom.xml | 65 ---------------- 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, 10 insertions(+), 233 deletions(-) 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%) delete mode 100644 java/flatbuffers/pom.xml delete mode 100644 java/flatbuffers/src/test/fbs/test.fbs delete mode 100644 java/flatbuffers/src/test/java/com/google/flatbuffers/test/DummyTest.java delete mode 100644 java/jmh/pom.xml diff --git a/.gitignore b/.gitignore index 1ba56a0e5..6f3894d06 100755 --- a/.gitignore +++ b/.gitignore @@ -54,8 +54,8 @@ build/Xcode/FlatBuffers.xcodeproj/project.xcworkspace/** build/Xcode/FlatBuffers.xcodeproj/xcuserdata/** FlatBuffers.xcodeproj/ java/.idea -*.iml -target +java/*.iml +java/target **/*.pyc .idea build/VS2010/FlatBuffers.sdf diff --git a/java/flatbuffers/src/main/java/com/google/flatbuffers/Constants.java b/java/com/google/flatbuffers/Constants.java similarity index 100% rename from java/flatbuffers/src/main/java/com/google/flatbuffers/Constants.java rename to java/com/google/flatbuffers/Constants.java diff --git a/java/flatbuffers/src/main/java/com/google/flatbuffers/FlatBufferBuilder.java b/java/com/google/flatbuffers/FlatBufferBuilder.java similarity index 100% rename from java/flatbuffers/src/main/java/com/google/flatbuffers/FlatBufferBuilder.java rename to java/com/google/flatbuffers/FlatBufferBuilder.java diff --git a/java/flatbuffers/src/main/java/com/google/flatbuffers/Struct.java b/java/com/google/flatbuffers/Struct.java similarity index 100% rename from java/flatbuffers/src/main/java/com/google/flatbuffers/Struct.java rename to java/com/google/flatbuffers/Struct.java diff --git a/java/flatbuffers/src/main/java/com/google/flatbuffers/Table.java b/java/com/google/flatbuffers/Table.java similarity index 100% rename from java/flatbuffers/src/main/java/com/google/flatbuffers/Table.java rename to java/com/google/flatbuffers/Table.java diff --git a/java/flatbuffers/pom.xml b/java/flatbuffers/pom.xml deleted file mode 100644 index 7b6ea7933..000000000 --- a/java/flatbuffers/pom.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - 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/flatbuffers/src/test/fbs/test.fbs b/java/flatbuffers/src/test/fbs/test.fbs deleted file mode 100644 index 695b94e43..000000000 --- a/java/flatbuffers/src/test/fbs/test.fbs +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100644 index 627050b5f..000000000 --- a/java/flatbuffers/src/test/java/com/google/flatbuffers/test/DummyTest.java +++ /dev/null @@ -1,25 +0,0 @@ -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 deleted file mode 100644 index 9be798421..000000000 --- a/java/jmh/pom.xml +++ /dev/null @@ -1,77 +0,0 @@ - - - - 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 2297dbe37..dd92b9d55 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 + flatbuffers-java 1.3.0-SNAPSHOT - pom - FlatBuffers + jar + FlatBuffers Java API Memory Efficient Serialization Library @@ -30,47 +30,10 @@ 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 From 7a955a09f43f271a5dec1221e2a74fa2da9825cd Mon Sep 17 00:00:00 2001 From: Romain Gilles Date: Tue, 5 Jul 2016 14:29:12 +0200 Subject: [PATCH 3/4] Move maven `pom.xml` from the java folder to the root folder. This avoid to put the pom.xml file into the source directory. Normally the pom file is in a parent (/parent) folder and it is not mixed with the java source code. An other thing is: this will make import of the project more easy from a IDE. The side effect is that the target folder where maven build artifacts will move from the /java/target to /target therefore the gitignore file has been updated in consequences. --- .gitignore | 5 +++-- java/pom.xml => pom.xml | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) rename java/pom.xml => pom.xml (98%) diff --git a/.gitignore b/.gitignore index 6f3894d06..c14aad97b 100755 --- a/.gitignore +++ b/.gitignore @@ -55,9 +55,10 @@ build/Xcode/FlatBuffers.xcodeproj/xcuserdata/** FlatBuffers.xcodeproj/ java/.idea java/*.iml -java/target -**/*.pyc .idea +*.iml +target +**/*.pyc build/VS2010/FlatBuffers.sdf build/VS2010/FlatBuffers.opensdf build/VS2010/ipch/**/*.ipch diff --git a/java/pom.xml b/pom.xml similarity index 98% rename from java/pom.xml rename to pom.xml index dd92b9d55..28d50d283 100644 --- a/java/pom.xml +++ b/pom.xml @@ -33,7 +33,7 @@ - ./ + java maven-compiler-plugin From 9605dc59812781f60e1f2e308c5d7284d8dd756d Mon Sep 17 00:00:00 2001 From: Romain Gilles Date: Fri, 15 Jul 2016 14:34:56 +0200 Subject: [PATCH 4/4] Added OSGi header generation for maven project. This allow jar generated with maven to be used in OSGi environment. --- pom.xml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 28d50d283..8e32feec3 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.google.flatbuffers flatbuffers-java 1.3.0-SNAPSHOT - jar + bundle FlatBuffers Java API Memory Efficient Serialization Library @@ -78,6 +78,12 @@ + + org.apache.felix + maven-bundle-plugin + 3.0.1 + true +