-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Remove set current app when allow global false #8462
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
Remove set current app when allow global false #8462
Conversation
There is no `@deprecated` tag in scaladocs since we have the `@deprecated` annotation.
|
|
||
| // Set the current app if the global application is enabled | ||
| // Also set it if the current app is null, in order to display more useful errors if we try to use the app | ||
| if (globalApp || _currentApp == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the main purpose of the PR.
This will then have an impact on privateMaybeApplication that now returns a Try[Application] since it can fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also have the check above globalApp && _currentApp != null && _currentApp.globalApplicationEnabled to decide whether to stop the current app. I think that can be globalApp && _currentApp != null, since the current app will only be set if the global app is enabled.
|
|
||
| private[play] def privateMaybeApplication: Try[Application] = { | ||
| if (_currentApp != null) { | ||
| logger.warn( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is warn level too noise?
@richdougherty @gmethvin @schmitch what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we can make sure this only prints once when the app starts up it's fine, but it'd be pretty annoying to have this on every access (which could be every request). I think the deprecation is good enough. We're already making users opt in to having the global app.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well we could create a dummy variable and initialize it here:
private lazy val nonEmptyCurrentApp = {
logger.warn(...)
true
}
private[play] def privateMaybeApplication: Try[Application] = {
Option(_currentApp) match {
if (_currentApp != null) {
val _ = nonEmptyCurrentApp
}
guess this would memoize the logging and only print the warning once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the simplest solution is to move the log to where we set the current app (in Play.start).
| /** | ||
| * A lazy HTTP error handler, that looks up the error handler from the current application | ||
| */ | ||
| @deprecated("Access the global state. Inject a HttpErrorHandler instead", "2.7.0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was not deprecated before, but it should.
| import scala.util.{ Failure, Success } | ||
|
|
||
| // Keep Crypto around to manage global state for now... | ||
| @deprecated("Access global state. Inject a CookieSigner instead", "2.7.0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a private API, but adding deprecated here to help us to find it later.
ignasi35
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (with small comment wrt logs/exceptionMessage)
| |You are accessing the application using deprecated methods that exists only to access | ||
| |global state. If you need an instance of Application, use Dependency Injection. | ||
| """.stripMargin) | ||
| Success(_currentApp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this be a multiline trace?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
But of course, users can silence this via Logback configuration. It shouldn't happen a lot though since it is quite unusual to access the current application for each request. Do you think it would be better to have a single line here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ignasi35 I'm moving this to Play.start to ensure the log will happen only once.
|
|
||
| private[play] def privateMaybeApplication: Try[Application] = { | ||
| if (_currentApp != null) { | ||
| logger.warn( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we can make sure this only prints once when the app starts up it's fine, but it'd be pretty annoying to have this on every access (which could be every request). I think the deprecation is good enough. We're already making users opt in to having the global app.
| |The global application is disabled. Set $GlobalAppConfigKey to allow global state here. | ||
| |If $GlobalAppConfigKey is already configured to allow global state, then you need to start | ||
| |the application too. | ||
| """.stripMargin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This message would be a good place to recommend using dependency injection and warn that Play.current will be removed in the future, something like:
The global application reference is disabled. Play's global state is deprecated and will be removed in a future release. You should use dependency injection instead. To enable the global application anyway, set
$GlobalAppConfigKey = true
|
|
||
| // Set the current app if the global application is enabled | ||
| // Also set it if the current app is null, in order to display more useful errors if we try to use the app | ||
| if (globalApp || _currentApp == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also have the check above globalApp && _currentApp != null && _currentApp.globalApplicationEnabled to decide whether to stop the current app. I think that can be globalApp && _currentApp != null, since the current app will only be set if the global app is enabled.
* remove apache commons libs (playframework#8455) * remove apache commons libs currently play added a lot of "helper" libraries in the past, however with recent JVM upgrades and more and more stuff inside the JVM itself these got more and more unnecessary. Actually this imports some Classes from apache commons lang3, however only a really small subset of the library is imported. The subset itself barly changed over the recent years and Play mostly used just the reflect stuff of commons lang3 * Remove set current app when allow global false (playframework#8462) * Remove imports to current app * Add missing deprecation notes * Remove invalid scaladoc tags There is no `@deprecated` tag in scaladocs since we have the `@deprecated` annotation. * Do not set current app when global state is disabled * Configure mima filter * Clear warn messages when using global state * Just stop the current app if global state is enabled * logback graceful shutdown (playframework#8407) * add shutdown hook to logback-play-default.xml playframework#8277 * update SettingsLogger.md documentation playframework#8277 * delete an unnecessary line playframework#8277. * add shutdown hook to logback-play-logSql.xml playframework#8277 * add line playframework#8277 * update SettingsLogger.md playframework#8277 * update SettingsLogger.md playframework#8277
* Update Play, interplay and other dependencies * Remove access to global state and deprecated APIs The main change is to remove any access to `Play.maybeApplication` which Play does not set by default anymore. See playframework/playframework#8462. This implies changing tests that also access the global state when using the `Action` object. So now all the tests are instead using `appRoutes` instead of `routes` since the later does not provides a way to access an ActionBuilder. Finally, some minor deprecated calls were replaced with the new APIs. * Travis configuration tweaks Avoid generating too much log when running the tests. It was also necessary to use `sudo: required` to workaround a Travis problem when using Google Chrome: See travis-ci/travis-ci#8836 Moreover, Scala versions were updated. * Deprecate PhantomJS support Selenium had deprecated PhantomJS support since it is no longer actively developed. Support will be dropped in Selenium so we should deprecated it here too. * Enable users to better customize FirefoxDriver creation It was possible to customize the FirefoxProfile, but not FirefoxOptions. Now both are available across all the APIs. * Enable users to better customize ChromeDriver creation * Remove ehcache dependencies * Remove code duplication
Purpose
The current app was still being initialized even with the global state disabled. This removes that and adds some more warnings to instruct users to move away from
Play.currentand similars.Background Context
See discussion in our Gitter channel: https://gitter.im/playframework/contributors?at=5b106c1d52e35117cdf94838
References
This can be considered a follow up of #8183.