Skip to content

Commit

Permalink
Gradle support for play-java-chatroom-example
Browse files Browse the repository at this point in the history
  • Loading branch information
ihostage authored and mkurz committed Jan 24, 2024
1 parent 37ce9d0 commit c8a9413
Show file tree
Hide file tree
Showing 14 changed files with 468 additions and 7 deletions.
9 changes: 9 additions & 0 deletions play-java-chatroom-example/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Linux start script should use lf
/gradlew text eol=lf

# These are Windows script files and should use crlf
*.bat text eol=crlf

5 changes: 5 additions & 0 deletions play-java-chatroom-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
build
4 changes: 4 additions & 0 deletions play-java-chatroom-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ You will need [JDK 11](https://adoptopenjdk.net/) and [sbt](http://www.scala-sbt
```bash
sbt run
```
or
```bash
./gradlew playRun
```

Go to <http://localhost:9000> and open it in two different browsers. Typing into one browser will cause it to show up in another browser.

Expand Down
18 changes: 14 additions & 4 deletions play-java-chatroom-example/app/controllers/HomeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,24 @@
import org.apache.pekko.japi.Pair;
import org.apache.pekko.japi.pf.PFBuilder;
import org.apache.pekko.stream.Materializer;
import org.apache.pekko.stream.javadsl.*;
import org.apache.pekko.stream.javadsl.BroadcastHub;
import org.apache.pekko.stream.javadsl.Flow;
import org.apache.pekko.stream.javadsl.Keep;
import org.apache.pekko.stream.javadsl.MergeHub;
import org.apache.pekko.stream.javadsl.Sink;
import org.apache.pekko.stream.javadsl.Source;
import org.webjars.play.WebJarsUtil;
import play.libs.F;
import play.mvc.*;
import play.mvc.Controller;
import play.mvc.Http;
import play.mvc.Result;
import play.mvc.Results;
import play.mvc.WebSocket;

import javax.inject.Inject;
import java.net.URI;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import javax.inject.Inject;

/**
* A very simple chat client using websockets.
Expand All @@ -27,6 +36,7 @@ public class HomeController extends Controller {


@Inject
@SuppressWarnings({"unchecked", "rawtypes"})
public HomeController(ActorSystem actorSystem,
Materializer mat,
WebJarsUtil webJarsUtil) {
Expand Down Expand Up @@ -70,7 +80,7 @@ public WebSocket chat() {
* http://blog.dewhurstsecurity.com/2013/08/30/security-testing-html5-websockets.html
*/
private boolean sameOriginCheck(Http.RequestHeader request) {
List<String> origins = request.getHeaders().getAll("Origin");
List<String> origins = request.headers().getAll("Origin");
if (origins.size() > 1) {
// more than one origin found
return false;
Expand Down
43 changes: 43 additions & 0 deletions play-java-chatroom-example/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import play.gradle.plugin.PlayPlugin

plugins {
alias(libs.plugins.twirl)
alias(libs.plugins.play)
}

val scalaVersion = System.getProperty("scala.version", PlayPlugin.DEFAULT_SCALA_VERSION).trimEnd { !it.isDigit() }

dependencies {
implementation(platform("org.playframework:play-bom_$scalaVersion:${libs.versions.play.get()}"))

implementation("org.playframework:play-java-forms_$scalaVersion")
implementation("org.playframework:play-pekko-http-server_$scalaVersion")
implementation("org.playframework:play-ahc-ws_$scalaVersion")
implementation("org.playframework:play-guice_$scalaVersion")
implementation("org.playframework:play-logback_$scalaVersion")
implementation("org.webjars:webjars-play_$scalaVersion:${libs.versions.webjars.play.get()}")
implementation(libs.flot)
implementation(libs.bootstrap)

testImplementation(libs.junit)
testImplementation("org.playframework:play-test_$scalaVersion")
testImplementation(libs.assertj)
testImplementation(libs.awaitility)
}

tasks.test {
systemProperty("testserver.port", "19001")
}

tasks.withType<ScalaCompile>().configureEach {
options.compilerArgs.addAll(listOf("-Xlint:unchecked", "-Xlint:deprecation", "-Werror"))
}

// TODO: Remove after release Play Gradle Plugin
repositories {
mavenCentral()
maven {
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
}
mavenLocal()
}
4 changes: 2 additions & 2 deletions play-java-chatroom-example/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ lazy val root = (project in file("."))
"org.webjars" % "bootstrap" % "3.4.1",
guice,
ws,
"org.assertj" % "assertj-core" % "3.12.2" % Test,
"org.awaitility" % "awaitility" % "3.1.6" % Test
"org.assertj" % "assertj-core" % "3.24.2" % Test,
"org.awaitility" % "awaitility" % "4.2.0" % Test
),
(Test / javaOptions) += "-Dtestserver.port=19001",
// Needed to make JUnit report the tests being run
Expand Down
20 changes: 20 additions & 0 deletions play-java-chatroom-example/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[versions]
twirl = "2.0.3"
play = "3.0.2-522fdae8-SNAPSHOT"
junit = "4.13.1"
webjars-play = "3.0.0"
flot = "0.8.3"
bootstrap = "3.4.1"
assertj = "3.24.2"
awaitility = "4.2.0"

[libraries]
junit = { group = "junit", name = "junit", version.ref = "junit" }
flot = { group = "org.webjars", name = "flot", version.ref = "flot" }
bootstrap = { group = "org.webjars", name = "bootstrap", version.ref = "bootstrap" }
assertj = { group = "org.assertj", name = "assertj-core", version.ref = "assertj" }
awaitility = { group = "org.awaitility", name = "awaitility", version.ref = "awaitility" }

[plugins]
twirl = { id = "org.playframework.twirl", version.ref = "twirl" }
play = { id = "org.playframework.play", version.ref = "play" }
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=9d926787066a081739e8200858338b4a69e837c3a821a33aca9db09dd4a41026
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit c8a9413

Please sign in to comment.