Skip to content
Permalink
Browse files

Import Misk from Square

  • Loading branch information...
swankjesse committed Dec 5, 2017
0 parents commit b09c9e05a09e29e9d25e2a47919338031d0ec9e7
Showing with 2,146 additions and 0 deletions.
  1. +6 −0 .gitignore
  2. +7 −0 README.md
  3. +45 −0 build.gradle
  4. +39 −0 exemplar/build.gradle
  5. +25 −0 exemplar/src/main/java/com/squareup/exemplar/ExemplarJavaApp.java
  6. +8 −0 exemplar/src/main/java/com/squareup/exemplar/ExemplarJavaConfig.java
  7. +10 −0 exemplar/src/main/java/com/squareup/exemplar/ExemplarJavaConfigModule.java
  8. +14 −0 exemplar/src/main/java/com/squareup/exemplar/ExemplarJavaModule.java
  9. +30 −0 exemplar/src/main/java/com/squareup/exemplar/HelloJavaAction.java
  10. +6 −0 exemplar/src/main/kotlin/com/squareup/exemplar/ExemplarConfig.kt
  11. +10 −0 exemplar/src/main/kotlin/com/squareup/exemplar/ExemplarConfigModule.kt
  12. +15 −0 exemplar/src/main/kotlin/com/squareup/exemplar/ExemplarModule.kt
  13. +22 −0 exemplar/src/main/kotlin/com/squareup/exemplar/ExemplarService.kt
  14. +22 −0 exemplar/src/main/kotlin/com/squareup/exemplar/HelloWebAction.kt
  15. +23 −0 exemplar/src/main/kotlin/com/squareup/exemplar/HelloWebPostAction.kt
  16. +3 −0 exemplar/src/main/resources/exemplar.yaml
  17. +21 −0 exemplar/src/test/kotlin/com/squareup/exemplar/HelloWebActionTest.kt
  18. +2 −0 gradle.properties
  19. BIN gradle/wrapper/gradle-wrapper.jar
  20. +6 −0 gradle/wrapper/gradle-wrapper.properties
  21. +172 −0 gradlew
  22. +84 −0 gradlew.bat
  23. +39 −0 misk/build.gradle
  24. +10 −0 misk/src/main/kotlin/misk/Action.kt
  25. +13 −0 misk/src/main/kotlin/misk/Actions.kt
  26. +11 −0 misk/src/main/kotlin/misk/Chain.kt
  27. +9 −0 misk/src/main/kotlin/misk/Interceptor.kt
  28. +25 −0 misk/src/main/kotlin/misk/MiskApplication.kt
  29. +18 −0 misk/src/main/kotlin/misk/MiskModule.kt
  30. +3 −0 misk/src/main/kotlin/misk/config/Config.kt
  31. +79 −0 misk/src/main/kotlin/misk/config/ConfigModule.kt
  32. +12 −0 misk/src/main/kotlin/misk/hibernate/HibernateModule.kt
  33. +16 −0 misk/src/main/kotlin/misk/hibernate/HibernateService.kt
  34. +35 −0 misk/src/main/kotlin/misk/inject/Guice.kt
  35. +8 −0 misk/src/main/kotlin/misk/logging/Logging.kt
  36. +16 −0 misk/src/main/kotlin/misk/moshi/MoshiModule.kt
  37. +38 −0 misk/src/main/kotlin/misk/resources/ResourceLoader.kt
  38. +24 −0 misk/src/main/kotlin/misk/testing/MiskTestRule.kt
  39. +133 −0 misk/src/main/kotlin/misk/web/BoundAction.kt
  40. +26 −0 misk/src/main/kotlin/misk/web/Http.kt
  41. +55 −0 misk/src/main/kotlin/misk/web/PathPattern.kt
  42. +30 −0 misk/src/main/kotlin/misk/web/RealChain.kt
  43. +13 −0 misk/src/main/kotlin/misk/web/Request.kt
  44. +33 −0 misk/src/main/kotlin/misk/web/Response.kt
  45. +86 −0 misk/src/main/kotlin/misk/web/WebActionModule.kt
  46. +28 −0 misk/src/main/kotlin/misk/web/WebActionsModule.kt
  47. +5 −0 misk/src/main/kotlin/misk/web/WebConfig.kt
  48. +12 −0 misk/src/main/kotlin/misk/web/actions/InternalErrorAction.kt
  49. +18 −0 misk/src/main/kotlin/misk/web/actions/NotFoundAction.kt
  50. +3 −0 misk/src/main/kotlin/misk/web/actions/WebAction.kt
  51. +21 −0 misk/src/main/kotlin/misk/web/actions/WebActions.kt
  52. +23 −0 misk/src/main/kotlin/misk/web/extractors/HeadersParameterExtractorFactory.kt
  53. +28 −0 misk/src/main/kotlin/misk/web/extractors/JsonBodyParameterExtractorFactory.kt
  54. +15 −0 misk/src/main/kotlin/misk/web/extractors/ParameterExtractor.kt
  55. +24 −0 misk/src/main/kotlin/misk/web/extractors/PathPatternParameterExtractor.kt
  56. +26 −0 misk/src/main/kotlin/misk/web/interceptors/BoxResponseInterceptor.kt
  57. +41 −0 misk/src/main/kotlin/misk/web/interceptors/InternalErrorInterceptorFactory.kt
  58. +53 −0 misk/src/main/kotlin/misk/web/interceptors/JsonInterceptorFactory.kt
  59. +40 −0 misk/src/main/kotlin/misk/web/interceptors/PlaintextInterceptorFactory.kt
  60. +45 −0 misk/src/main/kotlin/misk/web/interceptors/ProtobufInterceptorFactory.kt
  61. +31 −0 misk/src/main/kotlin/misk/web/interceptors/RequestLoggingInterceptor.kt
  62. +12 −0 misk/src/main/kotlin/misk/web/jetty/JettyModule.kt
  63. +52 −0 misk/src/main/kotlin/misk/web/jetty/JettyService.kt
  64. +31 −0 misk/src/main/kotlin/misk/web/jetty/WebActionsServlet.kt
  65. +17 −0 misk/src/main/resources/log4j2.yaml
  66. +113 −0 misk/src/test/java/helpers/protos/Dinosaur.java
  67. +36 −0 misk/src/test/kotlin/misk/config/ConfigTest.kt
  68. +12 −0 misk/src/test/kotlin/misk/config/TestConfig.kt
  69. +13 −0 misk/src/test/kotlin/misk/logging/LoggingTest.kt
  70. +17 −0 misk/src/test/kotlin/misk/resources/ResourceLoaderTest.kt
  71. +25 −0 misk/src/test/kotlin/misk/web/PathPatternTest.kt
  72. +21 −0 misk/src/test/kotlin/misk/web/actions/NotFoundActionTest.kt
  73. +67 −0 misk/src/test/kotlin/misk/web/interceptors/ProtobufInterceptorFactoryTest.kt
  74. +1 −0 misk/src/test/resources/misk/resources/ResourceLoaderTest.txt
  75. +11 −0 misk/src/test/resources/test-config.yaml
  76. +3 −0 settings.gradle
@@ -0,0 +1,6 @@
.gradle
**/out/
build
.idea
*.iml

@@ -0,0 +1,7 @@
# Misk (Microservice Kontainer)

Misk is a new open source application container from Square.

Misk is not ready for use. The API is not stable.


@@ -0,0 +1,45 @@
ext {
kotlinVersion = '1.1.51'

dep = [
kotlinStdLib: "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlinVersion",
kotlinReflect: "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion",
kotlinGradlePlugin: "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion",
kotlinReflection: "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion",
junit: 'junit:junit:4.12',
truth: 'com.google.truth:truth:0.30',
guava: 'com.google.guava:guava:23.3-jre',
guice: 'com.google.inject:guice:4.1.0',
guiceMultibindings: 'com.google.inject.extensions:guice-multibindings:4.1.0',
guiceServlet: 'com.google.inject.extensions:guice-servlet:4.1.0',
jettyServer: 'org.eclipse.jetty:jetty-server:9.4.7.v20170914',
jettyServlet: 'org.eclipse.jetty:jetty-servlet:9.4.7.v20170914',
okHttp: 'com.squareup.okhttp3:okhttp:3.9.0',
moshi: 'com.squareup.moshi:moshi-kotlin:1.5.0',
loggingApi: 'io.github.microutils:kotlin-logging:1.4.6',
wireRuntime: 'com.squareup.wire:wire-runtime:2.2.0',
loggingImpl: 'org.apache.logging.log4j:log4j-slf4j-impl:2.9.1',
jacksonDatabind: 'com.fasterxml.jackson.core:jackson-databind:2.9.2',
jacksonDataformatYaml: 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.9.2',
jacksonKotlin: 'com.fasterxml.jackson.module:jackson-module-kotlin:2.9.2'
]

isCi = "true".equals(System.getenv('CI'))
}

subprojects {
buildscript {
repositories {
mavenCentral()
jcenter()
}

dependencies {
classpath dep.kotlinGradlePlugin
}
}
repositories {
mavenCentral()
jcenter()
}
}
@@ -0,0 +1,39 @@
apply plugin: 'kotlin'

compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}

dependencies {
compile dep.kotlinStdLib
compile dep.guava
compile dep.guice

compile project(':misk')

testCompile dep.junit
testCompile dep.truth
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin/'
test.java.srcDirs += 'src/test/kotlin/'
}

jar {
manifest {
attributes 'Main-Class': 'com.squareup.exemplar.ExemplarServiceKt'
}

// This line of code recursively collects and copies all of a project's files
// and adds them to the JAR itself. One can extend this task, to skip certain
// files or particular types at will
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}
@@ -0,0 +1,25 @@
package com.squareup.exemplar;

import misk.MiskApplication;
import misk.MiskModule;
import misk.hibernate.HibernateModule;
import misk.moshi.MoshiModule;
import misk.web.WebActionsModule;
import misk.web.jetty.JettyModule;

public class ExemplarJavaApp {
public static void main(String[] args) {
new MiskApplication(
new MiskModule(),
new WebActionsModule(),

new JettyModule(),

new HibernateModule(),

new ExemplarJavaModule(),
new ExemplarJavaConfigModule(),
new MoshiModule()
).startAndAwaitStopped();
}
}
@@ -0,0 +1,8 @@
package com.squareup.exemplar;

import misk.config.Config;
import misk.web.WebConfig;

public class ExemplarJavaConfig implements Config {
public WebConfig web_config;
}
@@ -0,0 +1,10 @@
package com.squareup.exemplar;

import com.google.inject.AbstractModule;
import misk.config.ConfigModule;

public class ExemplarJavaConfigModule extends AbstractModule {
@Override protected void configure() {
install(new ConfigModule(ExemplarJavaConfig.class, "exemplar.yaml"));
}
}
@@ -0,0 +1,14 @@
package com.squareup.exemplar;

import com.google.inject.AbstractModule;
import misk.web.WebActionModule;
import misk.web.actions.InternalErrorAction;
import misk.web.actions.NotFoundAction;

public class ExemplarJavaModule extends AbstractModule {
@Override protected void configure() {
install(WebActionModule.create(HelloJavaAction.class));
install(WebActionModule.create(InternalErrorAction.class));
install(WebActionModule.create(NotFoundAction.class));
}
}
@@ -0,0 +1,30 @@
package com.squareup.exemplar;

import misk.web.Get;
import misk.web.JsonResponseBody;
import misk.web.PathParam;
import misk.web.RequestHeaders;
import misk.web.actions.WebAction;
import javax.inject.Singleton;
import okhttp3.Headers;

@Singleton
public class HelloJavaAction implements WebAction {
@Get(pathPattern = "/hello/java/{name}")
@JsonResponseBody
public HelloJavaResponse hello(
@PathParam("name") String name,
@RequestHeaders Headers headers) {
return new HelloJavaResponse("YO", name.toUpperCase());
}

static class HelloJavaResponse {
private final String greeting;
private final String name;

HelloJavaResponse(String greeting, String name) {
this.greeting = greeting;
this.name = name;
}
}
}
@@ -0,0 +1,6 @@
package com.squareup.exemplar

import misk.config.Config
import misk.web.WebConfig

data class ExemplarConfig(val web_config: WebConfig) : Config
@@ -0,0 +1,10 @@
package com.squareup.exemplar

import com.google.inject.AbstractModule
import misk.config.ConfigModule

class ExemplarConfigModule : AbstractModule() {
override fun configure() {
install(ConfigModule.create<ExemplarConfig>("exemplar.yaml"))
}
}
@@ -0,0 +1,15 @@
package com.squareup.exemplar

import com.google.inject.AbstractModule
import misk.web.WebActionModule
import misk.web.actions.InternalErrorAction
import misk.web.actions.NotFoundAction

class ExemplarModule : AbstractModule() {
override fun configure() {
install(WebActionModule.create<HelloWebAction>())
install(WebActionModule.create<HelloWebPostAction>())
install(WebActionModule.create<InternalErrorAction>())
install(WebActionModule.create<NotFoundAction>())
}
}
@@ -0,0 +1,22 @@
package com.squareup.exemplar

import misk.MiskApplication
import misk.MiskModule
import misk.hibernate.HibernateModule
import misk.moshi.MoshiModule
import misk.web.WebActionsModule
import misk.web.jetty.JettyModule

fun main(args: Array<String>) {
MiskApplication(
MiskModule(),
WebActionsModule(),

JettyModule(),

HibernateModule(),
ExemplarModule(),
ExemplarConfigModule(),
MoshiModule()
).startAndAwaitStopped()
}
@@ -0,0 +1,22 @@
package com.squareup.exemplar

import misk.web.Get
import misk.web.JsonResponseBody
import misk.web.RequestHeaders
import misk.web.actions.WebAction
import okhttp3.Headers
import javax.inject.Singleton

@Singleton
class HelloWebAction : WebAction {
@Get("/hello/{name}")
@JsonResponseBody
fun hello(
name: String,
@RequestHeaders headers: Headers
): HelloResponse {
return HelloResponse("YO", name.toUpperCase())
}
}

data class HelloResponse(val greeting: String, val name: String)
@@ -0,0 +1,23 @@
package com.squareup.exemplar

import misk.web.JsonRequestBody
import misk.web.JsonResponseBody
import misk.web.Post
import misk.web.actions.WebAction
import javax.inject.Singleton

@Singleton
class HelloWebPostAction : WebAction {
@Post("/hello/{name}")
@JsonResponseBody
fun hello(
name: String,
@JsonRequestBody body: PostBody
): HelloPostResponse {
return HelloPostResponse(body.greeting, name.toUpperCase())
}
}

data class HelloPostResponse(val greeting: String, val name: String)

data class PostBody(val greeting: String)
@@ -0,0 +1,3 @@
web_config:
port: 8080
idle_timeout: 30000
@@ -0,0 +1,21 @@
package com.squareup.exemplar

import com.google.common.truth.Truth.assertThat
import misk.testing.MiskTestRule
import okhttp3.Headers
import org.junit.Rule
import org.junit.Test
import javax.inject.Inject

class HelloWebActionTest {
@Rule
@JvmField
val miskTestRule = MiskTestRule()

@Inject lateinit var helloWebAction: HelloWebAction

@Test
fun test() {
assertThat(helloWebAction.hello("sandy", Headers.of())).isEqualTo(HelloResponse("YO", "SANDY"))
}
}
@@ -0,0 +1,2 @@
GROUP=com.squareup.cloud-exemplar
VERSION_NAME=0.1.0-SNAPSHOT
Binary file not shown.
@@ -0,0 +1,6 @@
#Fri Nov 03 15:21:33 EDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-rc-2-bin.zip
Oops, something went wrong.

0 comments on commit b09c9e0

Please sign in to comment.
You can’t perform that action at this time.