forked from facebook/flipper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:facebook/flipper
- Loading branch information
Showing
317 changed files
with
5,643 additions
and
3,185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
apply plugin: 'kotlin-android-extensions' | ||
apply plugin: 'kotlin-kapt' | ||
apply plugin: 'maven' | ||
|
||
android { | ||
compileSdkVersion rootProject.compileSdkVersion | ||
buildToolsVersion rootProject.buildToolsVersion | ||
|
||
defaultConfig { | ||
minSdkVersion rootProject.minSdkVersion | ||
targetSdkVersion rootProject.targetSdkVersion | ||
} | ||
|
||
dependencies { | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$KOTLIN_VERSION" | ||
implementation project(':android') | ||
implementation project(':network-plugin') | ||
implementation deps.protobuf | ||
implementation "com.squareup.retrofit2:retrofit:2.9.0" | ||
implementation "com.github.hbmartin:protobuf_java_to_protobufjs:0.0.1" | ||
compileOnly deps.jsr305 | ||
} | ||
} | ||
|
||
apply plugin: 'com.vanniktech.maven.publish' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# | ||
# Copyright (c) Facebook, Inc. and its affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the LICENSE | ||
# file in the root directory of this source tree. | ||
# | ||
|
||
POM_NAME=Retrofit2 Protobuf Adapter | ||
POM_DESCRIPTION=Flipper plugin to automate Retrofit2 sending Protobuf definitions | ||
POM_ARTIFACT_ID=flipper-retrofit2-protobuf-plugin | ||
POM_PACKAGING=aar | ||
|
11 changes: 11 additions & 0 deletions
11
android/plugins/retrofit2-protobuf/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
~ Copyright (c) Facebook, Inc. and its affiliates. | ||
~ | ||
~ This source code is licensed under the MIT license found in the LICENSE | ||
~ file in the root directory of this source tree. | ||
--> | ||
|
||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.facebook.flipper.plugins.retrofit2protobuf"> | ||
</manifest> |
52 changes: 52 additions & 0 deletions
52
.../java/com/facebook/flipper/plugins/retrofit2protobuf/SendProtobufToFlipperFromRetrofit.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.flipper.plugins.retrofit2protobuf | ||
|
||
import com.facebook.flipper.android.AndroidFlipperClient | ||
import com.facebook.flipper.core.FlipperArray | ||
import com.facebook.flipper.core.FlipperObject | ||
import com.facebook.flipper.core.FlipperValue | ||
import com.facebook.flipper.plugins.network.NetworkFlipperPlugin | ||
import com.facebook.flipper.plugins.retrofit2protobuf.adapter.GenericCallDefinitionsToMessageDefinitionsIfProtobuf | ||
import com.facebook.flipper.plugins.retrofit2protobuf.adapter.RetrofitServiceToGenericCallDefinitions | ||
import com.facebook.flipper.plugins.retrofit2protobuf.model.CallNestedMessagesPayload | ||
import me.haroldmartin.protobufjavatoprotobufjs.adapter.FullNamedMessagesToNestedMessages | ||
|
||
object SendProtobufToFlipperFromRetrofit { | ||
operator fun invoke(baseUrl: String, service: Class<*>) { | ||
AndroidFlipperClient.getInstanceIfInitialized()?.let { client -> | ||
(client.getPlugin(NetworkFlipperPlugin.ID) as? NetworkFlipperPlugin) | ||
?.send( | ||
"addProtobufDefinitions", | ||
FlipperObject.Builder().put( | ||
baseUrl, generateProtobufDefinitions(service).toFlipperArray() | ||
).build() | ||
) | ||
} | ||
} | ||
|
||
private fun generateProtobufDefinitions(service: Class<*>): List<CallNestedMessagesPayload> { | ||
return RetrofitServiceToGenericCallDefinitions(service).let { definitions -> | ||
GenericCallDefinitionsToMessageDefinitionsIfProtobuf(definitions) | ||
}.let { messages -> | ||
messages.map { | ||
CallNestedMessagesPayload( | ||
path = it.path, | ||
method = it.method, | ||
requestMessageFullName = it.requestMessageFullName, | ||
requestDefinitions = FullNamedMessagesToNestedMessages(it.requestModel), | ||
responseMessageFullName = it.responseMessageFullName, | ||
responseDefinitions = FullNamedMessagesToNestedMessages(it.responseModel) | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun Iterable<FlipperValue>.toFlipperArray(): FlipperArray = | ||
fold(FlipperArray.Builder()) { builder, call -> builder.put(call) }.build() |
34 changes: 34 additions & 0 deletions
34
...plugins/retrofit2protobuf/adapter/GenericCallDefinitionsToMessageDefinitionsIfProtobuf.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.flipper.plugins.retrofit2protobuf.adapter | ||
|
||
import com.facebook.flipper.plugins.retrofit2protobuf.model.FullNamedMessagesCallDefinition | ||
import com.facebook.flipper.plugins.retrofit2protobuf.model.GenericCallDefinition | ||
import me.haroldmartin.protobufjavatoprotobufjs.ProtobufGeneratedJavaToProtobufJs | ||
|
||
internal object GenericCallDefinitionsToMessageDefinitionsIfProtobuf { | ||
operator fun invoke(callDefinitions: List<GenericCallDefinition>): List<FullNamedMessagesCallDefinition> { | ||
return callDefinitions.mapNotNull { definition -> | ||
val responseRootAndMessages = definition.responseType?.let { | ||
ProtobufGeneratedJavaToProtobufJs(it) | ||
} | ||
val requestRootAndMessages = definition.requestType?.let { | ||
ProtobufGeneratedJavaToProtobufJs(it) | ||
} | ||
|
||
FullNamedMessagesCallDefinition( | ||
path = definition.path, | ||
method = definition.method, | ||
responseMessageFullName = responseRootAndMessages?.rootFullName, | ||
responseModel = responseRootAndMessages?.messages, | ||
requestMessageFullName = requestRootAndMessages?.rootFullName, | ||
requestModel = requestRootAndMessages?.messages | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.