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

Create minimal sbt plugin for Play services #8011

Merged
merged 1 commit into from Nov 22, 2017

Conversation

gmethvin
Copy link
Member

@gmethvin gmethvin commented Nov 15, 2017

Fixes #7991.

Splits the current Play plugin into a PlayService and PlayWeb plugin.

PlayService uses the standard maven layout and doesn't automatically add template support, sbt-web, or routes file support. Support for routes can be easily added using the RoutesCompiler sbt plugin. The old Play layout can be added by adding PlayLayoutPlugin.

Eventually the PlayService plugin could also be the base plugin for Lagom services.

@gmethvin gmethvin force-pushed the play-minimal branch 2 times, most recently from 3c3b67d to 0b44a09 Compare November 15, 2017 08:44
)
override def projectSettings = PlaySettings.defaultSettings ++ Seq(
scalacOptions ++= Seq("-deprecation", "-unchecked", "-encoding", "utf8"),
javacOptions in Compile ++= Seq("-encoding", "utf8", "-g")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this change, but perhaps we could make these values overridable by users instead of hardcoded.

E.g.

playScalacOptions := Seq("-deprecation", "-unchecked", "-encoding", "utf8")
scalacOptions ++= playScalacOptions

*
* Declares common settings for both Java and Scala based web projects, as well as sbt-web and assets settings.
*/
object PlayWeb extends AutoPlugin {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this provide the same behaviour as the old Play plugin? What's the impact of changing the name to PlayWeb?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmethvin has told me on another channel that most people will be using the PlayJava and PlayScala plugins, not the Play plugin.

@@ -79,7 +95,7 @@ object PlayScala extends AutoPlugin {
* This plugin enables the Play netty http server
*/
object PlayNettyServer extends AutoPlugin {
override def requires = Play
override def requires = PlayService
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

/**
* Play layout plugin to switch to the classic Play layout instead of the standard Maven layout.
*
* This is enabled automatically with the PlayWeb plugin but not with the PlayService plugin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment reads to me like PlayWeb depends on PlayLayoutPlugin, but the requres = PlayWeb below seems to show that PlayLayoutPlugin depends on PlayWeb. Or am I just confused? :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an AutoPlugin, whose trigger is allDependencies. So it's automatically applied when all dependencies are satisfied. Perhaps it would be better to just make it a dependency of PlayWeb, but I was just going along with the way it was already done.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it probably would make more sense for it to be a dependency of PlayWeb. That also means you could apply it to a non-Play project which would make sense.

val ReadTimeout = 10000

@tailrec
def verifyResourceContains(path: String, status: Int, assertions: Seq[String], attempts: Int): Unit = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really part of this PR, but it feels like this common code should be in a library somewhere…

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1.

This could be side by side with MediatorWorkaroundPlugin.

@gmethvin gmethvin force-pushed the play-minimal branch 3 times, most recently from 9e6a48a to 2380783 Compare November 16, 2017 04:04
@@ -16,7 +16,7 @@ import sbt._
* }}}
*/
object PlayFilters extends AutoPlugin {
override def requires = Play
override def requires = PlayWeb
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand we need to do this so that we can have better compatibility but to me, this plugin (and also PlayAkkaHttpServer and PlayNettyServer) should just add some settings and requires only sbt.plugins.JvmPlugin. Moreover, I expect people to be doing something like .enablePlugins(PlayScala).enablePlugins(PlayFilters) instead of just doing enablePlugins(PlayFilters) so that they will get PlayWeb through PlayScala or PlayJava.

Is there any reason these plugins needs PlayWeb or PlayService?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same for PlayLogback.

Copy link
Member Author

@gmethvin gmethvin Nov 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dependency is there because this is an AutoPlugin that's triggered on AllRequirements.

Copy link
Member Author

@gmethvin gmethvin Nov 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think we should have it added by default for PlayWeb though, to provide the secure-by-default experience. I guess that's sort of the point of this plugin.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think we should have it added by default for PlayWeb though, to provide the secure-by-default experience. I guess that's sort of the point of this plugin.

I like that we do this by using a plugin:

  1. It is enabled by default (since it is an AutoPlugin)
  2. Being a plugin make it easy to disable it if necessary.

My main point here is that if it needs to requires PlayWeb.

Copy link
Member Author

@gmethvin gmethvin Nov 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the filters are designed to help with web-oriented issues, or at least things that generally affect public-facing apps. With a service you don't often need those things, and I think PlayService should by default give you a minimal service.

The only point of requires = PlayWeb is for the AllRequirements trigger.

# Build the distribution and ensure that the files we expect are indeed there
> stage
$ exists target/universal/stage/README
$ exists target/universal/stage/bin/root
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should test routes generation too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe you can run and have a task to make a request to /.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, you already have verifyResourceContains. It just needs to be added to the tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a second thought, and based on the basic-service tests, it could be good to check for the generated/compiled route files. That is because we can have routers without the router compiler (like in basic-service).

# Build the distribution and ensure that the files we expect are indeed there
> stage
$ exists target/universal/stage/README
$ exists target/universal/stage/bin/root
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs tests to add verifyResourceContains test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the verifyResourceContains test.

@gmethvin gmethvin force-pushed the play-minimal branch 4 times, most recently from 7d057f6 to 5d8dda6 Compare November 16, 2017 21:57

> run

> verifyResourceContains / 200 Hello
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing playStop as the last line.

@gmethvin gmethvin force-pushed the play-minimal branch 3 times, most recently from 7250d1d to a6da4d4 Compare November 19, 2017 00:26
@gmethvin gmethvin changed the title [wip] Create minimal sbt plugin for Play services Create minimal sbt plugin for Play services Nov 19, 2017
@gmethvin
Copy link
Member Author

I think this is good to merge. I'd like to add some examples as well, so I'll do that and then update the documentation in another PR.

@godenji
Copy link
Contributor

godenji commented Nov 19, 2017

Fantastic, thanks for getting this in place @gmethvin

Looking forward to working with a leaner version of Play 😄

Copy link
Member

@marcospereira marcospereira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@gmethvin we can add Highlights27 for this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants