Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds new Sbt plugins #11

Merged
merged 3 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[comment]: <> (Don't edit this file!)
[comment]: <> (It is automatically updated after every release of https://github.com/47degrees/.github)
[comment]: <> (If you want to suggest a change, please open a PR or issue in that repository)

# Authors

## Maintainers

The maintainers of the project are:

- [![naree](https://avatars0.githubusercontent.com/u/4437502?v=4&s=20) **naree**](https://github.com/naree)
- [![cb372](https://avatars1.githubusercontent.com/u/106760?v=4&s=20) **Chris Birchall (cb372)**](https://github.com/cb372)
- [![juanpedromoreno](https://avatars2.githubusercontent.com/u/4879373?v=4&s=20) **Juan Pedro Moreno (juanpedromoreno)**](https://github.com/juanpedromoreno)

## Contributors

These are the people that have contributed to the _sbt-mu-srcgen_ project:

- [![juanpedromoreno](https://avatars2.githubusercontent.com/u/4879373?v=4&s=20) **juanpedromoreno**](https://github.com/juanpedromoreno)
- [![cb372](https://avatars1.githubusercontent.com/u/106760?v=4&s=20) **cb372**](https://github.com/cb372)
- [![developer47deg](https://avatars1.githubusercontent.com/u/24799081?v=4&s=20) **developer47deg**](https://github.com/developer47deg)
- [![naree](https://avatars0.githubusercontent.com/u/4437502?v=4&s=20) **naree**](https://github.com/naree)
22 changes: 22 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[comment]: <> (Don't edit this file!)
[comment]: <> (It is automatically updated after every release of https://github.com/47degrees/.github)
[comment]: <> (If you want to suggest a change, please open a PR or issue in that repository)

# Code of Conduct

We are committed to providing a friendly, safe and welcoming
environment for all, regardless of level of experience, gender, gender
identity and expression, sexual orientation, disability, personal
appearance, body size, race, ethnicity, age, religion, nationality, or
other such characteristics.

Everyone is expected to follow the
[Scala Code of Conduct](https://typelevel.org/code-of-conduct.html) when
discussing the project on the available communication channels. If you
are being harassed, please contact us immediately so that we can
support you.

## Moderation

For any questions, concerns, or moderation requests please contact a
[member of the project](AUTHORS.md#maintainers).
16 changes: 10 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
[comment]: <> (Don't edit this file!)
[comment]: <> (It is automatically updated after every release of https://github.com/47degrees/.github)
[comment]: <> (If you want to suggest a change, please open a PR or issue in that repository)

# Contributing

Discussion around mu-scala happens in the [Gitter channel](https://gitter.im/47deg/mu-scala) as well as on
[GitHub issues](https://github.com/47deg/mu-scala/issues) and [pull requests](https://github.com/47deg/mu-scala/pulls).
Discussion around _sbt-mu-srcgen_ happens in the [GitHub issues](https://github.com/higherkindness/sbt-mu-srcgen/issues) and [pull requests](https://github.com/higherkindness/sbt-mu-srcgen/pulls).

Feel free to open an issue if you notice a bug, have an idea for a feature, or have a question about
the code. Pull requests are also welcome.

People are expected to follow the [Scala Code of Conduct](https://typelevel.org/code-of-conduct.html) when discussing mu-scala on the Github page, Gitter channel, or other venues.
People are expected to follow the [Code of Conduct](CODE_OF_CONDUCT.md) when discussing _sbt-mu-srcgen_ on the Github page or other venues.

If you are being harassed, please contact one of [us](AUTHORS.md#maintainers) immediately so that we can support you. In case you cannot get in touch with us please write an email to [47 Degrees](mailto:hello@47deg.com).
If you are being harassed, please contact one of [us](AUTHORS.md#maintainers) immediately so that we can support you. In case you cannot get in touch with us please write an email to [47 Degrees](mailto:contact@higherkindness.io).

## How can I help?

mu-scala follows a standard [fork and pull](https://help.github.com/articles/using-pull-requests/) model for contributions via GitHub pull requests.
_sbt-mu-srcgen_ follows a standard [fork and pull](https://help.github.com/articles/using-pull-requests/) model for contributions via GitHub pull requests.

The process is simple:

1. Find something you want to work on
2. Let us know you are working on it via the Gitter channel or GitHub issues/pull requests
2. Let us know you are working on it via GitHub issues/pull requests
3. Implement your contribution
4. Write tests
5. Update the documentation
6. Submit pull request

You will be automatically included in the [AUTHORS.md](AUTHORS.md#contributors) file as contributor in the next release.

If you encounter any confusion or frustration during the contribution process, please create a GitHub issue and we'll do our best to improve the process.
4 changes: 2 additions & 2 deletions LICENSE → LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@
APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright (C) 2017-2020 47 Degrees. <http://47deg.com>
Copyright (C) 2020 47 Degrees <http://47deg.com>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
9 changes: 9 additions & 0 deletions NOTICE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[comment]: <> (Don't edit this file!)
[comment]: <> (It is automatically updated after every release of https://github.com/47degrees/.github)
[comment]: <> (If you want to suggest a change, please open a PR or issue in that repository)

sbt-mu-srcgen

Copyright (c) 2020 47 Degrees. All rights reserved.

Licensed under Apache-2.0. See [LICENSE](LICENSE.md) for terms.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

[comment]: # (Start Badges)

[![Maven Central](https://img.shields.io/badge/maven%20central-0.21.3-green.svg)](https://oss.sonatype.org/#nexus-search;gav~io.higherkindness~mu-scala*) [![License](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://raw.githubusercontent.com/higherkindness/mu-scala/master/LICENSE) [![Join the chat at https://gitter.im/47deg/mu](https://badges.gitter.im/47deg/mu.svg)](https://gitter.im/47deg/mu?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![License](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://raw.githubusercontent.com/higherkindness/mu-scala/master/LICENSE) [![Join the chat at https://gitter.im/47deg/mu](https://badges.gitter.im/47deg/mu.svg)](https://gitter.im/47deg/mu?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

[comment]: # (End Badges)

Expand Down
16 changes: 13 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,22 @@ lazy val plugin = project
.settings(buildInfoPackage := "mu.rpc.srcgen")
.enablePlugins(SbtPlugin)

lazy val `docs` = project
.in(file("sbt-mu-srcgen-docs"))
.enablePlugins(MdocPlugin)
.settings(mdocVariables += "NAME" -> "sbt-mu-srcgen")
.settings(mdocOut := file("."))
.settings(skip in publish := true)
.dependsOn(allProjects.map(ClasspathDependency(_, None)): _*)

lazy val root = project
.in(file("."))
.settings(moduleName := "sbt-mu-srcgen-root")
.settings(noPublishSettings)
.aggregate(core, plugin)
.dependsOn(core, plugin)
.aggregate(allProjects: _*)
.dependsOn(allProjects.map(ClasspathDependency(_, None)): _*)

addCommandAlias("ci-test", "scalafmtCheck; scalafmtSbtCheck; test; scripted")
addCommandAlias("ci-docs", "compile")
addCommandAlias("ci-docs", "docs/mdoc; headerCreateAll")

lazy val allProjects: Seq[ProjectReference] = Seq(core, plugin)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 47 Degrees, LLC. <http://www.47deg.com>
* Copyright 2020 47 Degrees <http://47deg.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 47 Degrees, LLC. <http://www.47deg.com>
* Copyright 2020 47 Degrees <http://47deg.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,10 +16,11 @@

package higherkindness.mu.rpc.srcgen

import higherkindness.mu.rpc.internal.util.FileUtil._
import java.io.File
import org.log4s.getLogger

import higherkindness.mu.rpc.internal.util.FileUtil._
import higherkindness.mu.rpc.srcgen.Model.{IdlType, SerializationType}
import org.log4s.getLogger

class GeneratorApplication[T <: Generator](generators: T*) {
// Code covered by plugin tests
Expand Down
28 changes: 20 additions & 8 deletions core/src/main/scala/higherkindness/mu/rpc/srcgen/Model.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 47 Degrees, LLC. <http://www.47deg.com>
* Copyright 2020 47 Degrees <http://47deg.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,21 +24,22 @@ object Model {

import Toolbox.u._

private implicit class StringOps(val s: String) extends AnyVal {
implicit private class StringOps(private val s: String) extends AnyVal {
def trimAll: String = s.replaceAll("\\s", "")
}

case class RpcDefinitions(
final case class RpcDefinitions(
outputName: String,
outputPackage: Option[String],
options: Seq[RpcOption],
messages: Seq[RpcMessage],
services: Seq[RpcService]
)

case class RpcOption(name: String, value: String)
final case class RpcOption(name: String, value: String)

final case class RpcMessage(name: String, params: Seq[ValDef]) {

case class RpcMessage(name: String, params: Seq[ValDef]) {
// Workaround for `Term.Param` using referential equality; needed mostly for unit testing
override def equals(other: Any): Boolean = other match {
case that: RpcMessage =>
Expand All @@ -49,18 +50,19 @@ object Model {
}
}

case class RpcService(
final case class RpcService(
serializationType: SerType,
name: String,
requests: Seq[RpcRequest]
)

case class RpcRequest(
final case class RpcRequest(
name: String,
requestType: Tree,
responseType: Tree,
streamingType: Option[StreamingType] = None
) {

// Workaround for `Type` using referential equality; needed mostly for unit testing
override def equals(other: Any): Boolean = other match {
case that: RpcRequest =>
Expand All @@ -73,6 +75,7 @@ object Model {
}

sealed trait IdlType extends Product with Serializable

object IdlType {
case object Proto extends IdlType
case object Avro extends IdlType
Expand All @@ -81,6 +84,7 @@ object Model {
}

sealed trait SerializationType extends Product with Serializable

object SerializationType {
case object Protobuf extends SerializationType
case object Avro extends SerializationType
Expand All @@ -92,19 +96,26 @@ object Model {
extends Product
with Serializable

case class CustomMarshallersImport(mi: String) extends MarshallersImport(mi)
final case class CustomMarshallersImport(mi: String) extends MarshallersImport(mi)

case object BigDecimalAvroMarshallers
extends MarshallersImport("higherkindness.mu.rpc.internal.encoders.avro.bigdecimal._")

case object BigDecimalTaggedAvroMarshallers
extends MarshallersImport("higherkindness.mu.rpc.internal.encoders.avro.bigDecimalTagged._")

case object JavaTimeDateAvroMarshallers
extends MarshallersImport("higherkindness.mu.rpc.internal.encoders.avro.javatime._")

case object JodaDateTimeAvroMarshallers
extends MarshallersImport("higherkindness.mu.rpc.marshallers.jodaTimeEncoders.avro._")

case object BigDecimalProtobufMarshallers
extends MarshallersImport("higherkindness.mu.rpc.internal.encoders.pbd.bigdecimal._")

case object JavaTimeDateProtobufMarshallers
extends MarshallersImport("higherkindness.mu.rpc.internal.encoders.pbd.javatime._")

case object JodaDateTimeProtobufMarshallers
extends MarshallersImport("higherkindness.mu.rpc.marshallers.jodaTimeEncoders.pbd._")

Expand All @@ -118,6 +129,7 @@ object Model {

trait UseIdiomaticEndpointsTag
type UseIdiomaticEndpoints = Boolean @@ UseIdiomaticEndpointsTag

object UseIdiomaticEndpoints {
val trueV = UseIdiomaticEndpoints(true)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 47 Degrees, LLC. <http://www.47deg.com>
* Copyright 2020 47 Degrees <http://47deg.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
package higherkindness.mu.rpc.srcgen

import java.io.File
import java.nio.file.Path

import higherkindness.mu.rpc.srcgen.Model.{
BigDecimalTypeGen,
Expand All @@ -26,12 +27,12 @@ import higherkindness.mu.rpc.srcgen.Model.{
UseIdiomaticEndpoints
}
import higherkindness.mu.rpc.srcgen.avro.AvroSrcGenerator
import higherkindness.mu.rpc.srcgen.proto.ProtoSrcGenerator
import higherkindness.mu.rpc.srcgen.openapi.OpenApiSrcGenerator
import higherkindness.mu.rpc.srcgen.openapi.OpenApiSrcGenerator.HttpImpl
import java.nio.file.Path
import higherkindness.mu.rpc.srcgen.proto.ProtoSrcGenerator

object SrcGenApplication {

def apply(
marshallersImports: List[MarshallersImport],
bigDecimalTypeGen: BigDecimalTypeGen,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 47 Degrees, LLC. <http://www.47deg.com>
* Copyright 2020 47 Degrees <http://47deg.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 47 Degrees, LLC. <http://www.47deg.com>
* Copyright 2020 47 Degrees <http://47deg.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
package higherkindness.mu.rpc.srcgen.avro

import java.io.File

import scala.annotation.tailrec
import scala.io.Source

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 47 Degrees, LLC. <http://www.47deg.com>
* Copyright 2020 47 Degrees <http://47deg.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,18 +18,18 @@ package higherkindness.mu.rpc.srcgen.avro

import java.io.File

import scala.collection.JavaConverters._
import scala.util.Right

import avrohugger.Generator
import avrohugger.format.Standard
import avrohugger.types._
import higherkindness.mu.rpc.srcgen._
import higherkindness.mu.rpc.srcgen.Model._
import higherkindness.mu.rpc.srcgen._
import org.apache.avro._
import org.log4s._

import scala.collection.JavaConverters._
import scala.util.Right

case class AvroSrcGenerator(
final case class AvroSrcGenerator(
marshallersImports: List[MarshallersImport],
bigDecimalTypeGen: BigDecimalTypeGen,
compressionTypeGen: CompressionTypeGen,
Expand All @@ -44,6 +44,7 @@ case class AvroSrcGenerator(
}
private val avroScalaCustomTypes = Standard.defaultTypes.copy(decimal = avroBigDecimal)
private val mainGenerator = Generator(Standard, avroScalaCustomTypes = Some(avroScalaCustomTypes))

private val adtGenerator = mainGenerator.copy(avroScalaCustomTypes =
Some(mainGenerator.avroScalaTypes.copy(protocol = ScalaADT))
) // ScalaADT: sealed trait hierarchies
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 47 Degrees, LLC. <http://www.47deg.com>
* Copyright 2020 47 Degrees <http://47deg.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Loading