Skip to content

Commit

Permalink
Pronto Initial Public Release
Browse files Browse the repository at this point in the history
  • Loading branch information
gravypod committed Aug 21, 2020
0 parents commit 74ddb17
Show file tree
Hide file tree
Showing 47 changed files with 2,850 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# These are explicitly windows files and should use crlf
*.bat text eol=crlf

79 changes: 79 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
build


# Below taken from https://github.com/github/gitignore/blob/master/Global/JetBrains.gitignore
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
25 changes: 25 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions .idea/runConfigurations/All_Tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright 2020 SBOT TECHNOLOGIES INC.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
89 changes: 89 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Proto + Mongo == Pronto

Pronto is a MongoDB Codec Provider that serializes protos to and from bson documents to be saved
and loaded from MongoDB. This library will allow you to avoid writing code that manually transforms
a proto into a pojo or BsonDocument and then inserting that into Mongo.

# Hiring

Caper is always looking for talented software engineers. We're currently looking for Backend and
Android Frontend engineers. If you want to talk Caper please feel free to shoot an email to any
of the authors of this library. You can find our emails in the commit log.

# License

All code from `src/main/java/caper/...` and `src/test/...` are covered by `LICENSE.md`. The code within
`src/main/java/com/google/api/gax/protobuf/` and `src/main/resources/licenses/GAX_PROTOBUF_LICENSE`
are licensed under the terms within `src/main/resources/licenses/GAX_PROTOBUF_LICENSE`. This license
file is also packed into the jar under `/licenses/GAX_PROTOBUF_LICENSE`, if you are packaging this
for distribution please remember to include this file in your build.

# TODO

1. Create a QueryBuilder?
2. Annotations for choosing/altering field names?
3. Automation of proto migrations?
4. Support other data storage backends?

# Usage

// TODO(josh): Publish to maven registry or document jitpack?

Now you will be able to register the `ProtoCodecProvider` in your MongoDB client. It will look
something like this:

```java
import com.mongodb.MongoClient;
import org.bson.codecs.configuration.CodecRegistry;
import com.mongodb.client.MongoCollection;

class Example {
private final static CodecRegistry registry = fromRegistries(
fromProviders(
// Create a provider for the codec.
new ProtoCodecProvider(),
PojoCodecProvider.builder().automatic(true).build()
)
);

private MongoDatabase database(MongoClient client, String name) {
return client.getDatabase(name)
// Register it as the codec for your client.
.withCodecRegistry(registry)
.withWriteConcern(WriteConcern.ACKNOWLEDGED);
}
}
```

You can now insert protos using the following APIs:

```java
import com.mongodb.client.MongoCollection;
class Repository {
private final MongoCollection<BasicMessage> collection = database("basic_messages")
.getCollection("enums_basic_proto", BasicMessage.class);

public void saveThings() {
collection.insertMany(Arrays.asList(
BasicMessage.newBuilder()
.setBasicEnum(BasicEnum.A)
.build(),
BasicMessage.newBuilder()
.setBasicEnum(BasicEnum.B)
.build()
));
}
}
```

# Usage (caper internal)

The only thing that is different between our public and private
release of pronto is how you include it into our build chain.
Just add the following to your `build.gradle`:

```groovy
dependencies {
include project(':pronto')
}
```
76 changes: 76 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
apply plugin: 'java-library'
apply plugin: 'com.google.protobuf'
apply plugin: 'idea'

repositories {
maven { url "https://plugins.gradle.org/m2/" }
}

buildscript {
repositories {
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.8'
}
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
jcenter()
}

dependencies {
implementation 'org.mongodb:mongo-java-driver:3.12.6'
// Mock MongoDB instance for tests
testImplementation 'de.bwaldvogel:mongo-java-server:1.34.0'

// Utilities for interacting with google common protos. TODO(josh): Remove this dep
implementation 'com.google.api:gax:1.44.0', 'com.google.api:gax-grpc:1.44.0'

testImplementation 'junit:junit:4.12'
testImplementation 'com.google.guava:guava:28.0-jre'


// Protobuf libraries
api 'com.google.api.grpc:proto-google-common-protos:1.18.0'
api 'com.google.protobuf:protobuf-java:3.0.0'
if (JavaVersion.current().isJava9Compatible()) {
// Workaround for @javax.annotation.Generated
// see: https://github.com/grpc/grpc-java/issues/3633
implementation 'javax.annotation:javax.annotation-api:1.3.1'
}

}

protobuf {
protoc {
// The artifact spec for the Protobuf Compiler
artifact = 'com.google.protobuf:protoc:3.0.0'
}
plugins {
// Optional: an artifact spec for a protoc plugin, with "grpc" as
// the identifier, which can be referred to in the "plugins"
// container of the "generateProtoTasks" closure.
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:1.0.0-pre2'
}
}
generateProtoTasks {
ofSourceSet('main')*.plugins {
// Apply the "grpc" plugin whose spec is defined above, without
// options. Note the braces cannot be omitted, otherwise the
// plugin will not be added. This is because of the implicit way
// NamedDomainObjectContainer binds the methods.
grpc {}
}
}
}


test {
useJUnit()
maxHeapSize = '1G'
}
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Thu Aug 20 21:43:01 EDT 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Loading

0 comments on commit 74ddb17

Please sign in to comment.