From 43acf083958fd53174ca457fbc57a6aaea7b3ec0 Mon Sep 17 00:00:00 2001 From: Armin Date: Wed, 26 May 2021 16:28:29 +0200 Subject: [PATCH 1/3] Use Gradle Plugin to generate proto files automatically --- .gitignore | 3 --- README.adoc | 6 ++++++ build.gradle | 20 +++++++++++++++++-- .../de/cyface/protos/model/measurement.proto | 0 4 files changed, 24 insertions(+), 5 deletions(-) rename src/main/{protos => proto}/de/cyface/protos/model/measurement.proto (100%) diff --git a/.gitignore b/.gitignore index a8de083..98544c8 100644 --- a/.gitignore +++ b/.gitignore @@ -48,9 +48,6 @@ gradle.properties **/secrets *.json -# Generated java classes from proto files -src/main/java/ - # Temporary Git Files **/*.orig diff --git a/README.adoc b/README.adoc index 096e9a7..5405bb4 100644 --- a/README.adoc +++ b/README.adoc @@ -56,6 +56,12 @@ However, the pre-compiled `JARs` are also published to the link:https://github.c - how to use with link:https://github.com/protocolbuffers/protobuf/tree/master/java#gradle[Gradle] - how to use with link:https://github.com/protocolbuffers/protobuf/tree/master/java#use-java-protocol-buffers-on-android[Android] + Instead of using the pre-compiled `java` classes (published `JAR`s) it's recommended to use `javalite` for Android. These classes can either be manually generated with: + + protoc --java_out=lite:./src/main/java/ src/main/protos/de/cyface/protos/model/measurement.proto + +Or you can download the `proto` link:protoc --java_out=./src/main/java/ src/main/protos/de/cyface/protos/model/measurement.proto[files] from this repository and then generate the classes using the link:https://github.com/google/protobuf-gradle-plugin[Gradle Plugin]. This is done in the link:https://github.com/cyface-de/android-backend[Cyface Android SDK] - check it out if you need an example. + The serializers encode the data in an efficient way, the decision process is documented link:https://cyface.atlassian.net/wiki/spaces/IM/pages/1535148033/Datenformat+bertragungsprotokoll+2021[internally]. diff --git a/build.gradle b/build.gradle index 1a9747b..c1be518 100644 --- a/build.gradle +++ b/build.gradle @@ -35,6 +35,7 @@ plugins { id 'maven-publish' //noinspection SpellCheckingInspection id 'com.github.johnrengelman.shadow' version '6.1.0' + id 'com.google.protobuf' version '0.8.16' } group = 'de.cyface' @@ -69,7 +70,7 @@ repositories { // Code Quality Checker dependencies { - // Protobuf generated java files + // Generate java files from the Protobuf files implementation "com.google.protobuf:protobuf-java:$protobufVersion" // Utility @@ -85,6 +86,21 @@ dependencies { testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine" } +// See https://github.com/google/protobuf-gradle-plugin +protobuf { + protoc { + artifact = "com.google.protobuf:protoc:$protobufVersion" + } + generateProtoTasks { + //noinspection GroovyAssignabilityCheck + all().each { task -> + task.builtins { + java {} + } + } + } +} + test { useJUnitPlatform() testLogging { @@ -113,7 +129,7 @@ publishing { publications { //noinspection GroovyAssignabilityCheck publishExecutable(MavenPublication) { - //noinspection GroovyAssignabilityCheckssssssss + //noinspection GroovyAssignabilityCheck from components.java } } diff --git a/src/main/protos/de/cyface/protos/model/measurement.proto b/src/main/proto/de/cyface/protos/model/measurement.proto similarity index 100% rename from src/main/protos/de/cyface/protos/model/measurement.proto rename to src/main/proto/de/cyface/protos/model/measurement.proto From d143005b4a88ab90da06831a5427f3a6903c9625 Mon Sep 17 00:00:00 2001 From: Armin Date: Wed, 26 May 2021 17:35:45 +0200 Subject: [PATCH 2/3] Task/dat 638 prepare for use with android (#4) * Remove manual steps from github workflows * Generate protobuf java files using the Gradle Plugin --- .github/workflows/build.yml | 12 ------------ .github/workflows/publish-jar.yml | 12 ------------ build.gradle | 18 +++++++++++++++++- .../de/cyface/protos/model/measurement.proto | 0 4 files changed, 17 insertions(+), 25 deletions(-) rename src/main/{protos => proto}/de/cyface/protos/model/measurement.proto (100%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0a93004..0f3d53c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,18 +19,6 @@ jobs: with: java-version: 11 - - name: Download & unzip protoc - run: | - wget https://github.com/protocolbuffers/protobuf/releases/download/v3.17.0/protoc-3.17.0-linux-x86_64.zip \ - -O protoc-3.zip - unzip protoc-3.zip -d protoc-3 - mv protoc-3/bin/protoc protoc - - - name: Compile java files from `proto` file - run: | - mkdir -p src/main/java - ./protoc --java_out=./src/main/java/ src/main/protos/de/cyface/protos/model/measurement.proto - - name: Build with Gradle run: ./gradlew build env: diff --git a/.github/workflows/publish-jar.yml b/.github/workflows/publish-jar.yml index 808aff1..1f530a5 100644 --- a/.github/workflows/publish-jar.yml +++ b/.github/workflows/publish-jar.yml @@ -14,18 +14,6 @@ jobs: with: java-version: 11 - - name: Download & unzip protoc - run: | - wget https://github.com/protocolbuffers/protobuf/releases/download/v3.17.0/protoc-3.17.0-linux-x86_64.zip \ - -O protoc-3.zip - unzip protoc-3.zip -d protoc-3 - mv protoc-3/bin/protoc protoc - - - name: Compile java files from `proto` file - run: | - mkdir -p src/main/java - ./protoc --java_out=./src/main/java/ src/main/protos/de/cyface/protos/model/measurement.proto - # Publish slim JARS to Github Package Registry - name: Publish package run: ./gradlew publish diff --git a/build.gradle b/build.gradle index 1a9747b..2e5131a 100644 --- a/build.gradle +++ b/build.gradle @@ -35,6 +35,7 @@ plugins { id 'maven-publish' //noinspection SpellCheckingInspection id 'com.github.johnrengelman.shadow' version '6.1.0' + id 'com.google.protobuf' version '0.8.16' } group = 'de.cyface' @@ -85,6 +86,21 @@ dependencies { testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine" } +// See https://github.com/google/protobuf-gradle-plugin +protobuf { + protoc { + artifact = "com.google.protobuf:protoc:$protobufVersion" + } + generateProtoTasks { + //noinspection GroovyAssignabilityCheck + all().each { task -> + task.builtins { + java {} + } + } + } +} + test { useJUnitPlatform() testLogging { @@ -113,7 +129,7 @@ publishing { publications { //noinspection GroovyAssignabilityCheck publishExecutable(MavenPublication) { - //noinspection GroovyAssignabilityCheckssssssss + //noinspection GroovyAssignabilityCheck from components.java } } diff --git a/src/main/protos/de/cyface/protos/model/measurement.proto b/src/main/proto/de/cyface/protos/model/measurement.proto similarity index 100% rename from src/main/protos/de/cyface/protos/model/measurement.proto rename to src/main/proto/de/cyface/protos/model/measurement.proto From c6eeb8eea3a6de73fea45d383cdaf2b8b7bc7d8e Mon Sep 17 00:00:00 2001 From: Armin Date: Wed, 26 May 2021 17:36:30 +0200 Subject: [PATCH 3/3] Set version to 0.0.2 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 2e5131a..9f20f29 100644 --- a/build.gradle +++ b/build.gradle @@ -39,7 +39,7 @@ plugins { } group = 'de.cyface' -version = '0.0.1' +version = '0.0.2' tasks.withType(JavaCompile) { options.encoding = 'UTF-8'