diff --git a/.travis.yml b/.travis.yml index 94d7ccf..5a6d7ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: scala scala: - 2.11.11 - - 2.12.2 + - 2.12.6 # These directories are cached to S3 at the end of the build cache: diff --git a/README.md b/README.md index 43d3782..2a5473f 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Prerequisites: Open a console and run the following command to apply this template: ``` -sbt -Dsbt.version=0.13.15 new akka/akka-quickstart-scala.g8 +sbt -Dsbt.version=0.13.17 new akka/akka-quickstart-scala.g8 ``` This template will prompt for the name of the project. Press `Enter` if the default values suit you. @@ -26,16 +26,6 @@ Once inside the project folder, run the application with: sbt run ``` -This template also provides build descriptors for maven and gradle. You can use any of the following commands to run -the application: -``` -mvn exec:exec -``` -or -``` -gradle run -``` - ## Template license Written in 2017 by Lightbend, Inc. diff --git a/build.sbt b/build.sbt index bccb967..defabd7 100644 --- a/build.sbt +++ b/build.sbt @@ -7,7 +7,7 @@ lazy val root = (project in file(".")) test in Test := { val _ = (g8Test in Test).toTask("").value }, - scriptedLaunchOpts ++= List("-Xms1024m", "-Xmx1024m", "-XX:ReservedCodeCacheSize=128m", "-XX:MaxPermSize=256m", "-Xss2m", "-Dfile.encoding=UTF-8"), + scriptedLaunchOpts ++= List("-Xms1024m", "-Xmx1024m", "-XX:ReservedCodeCacheSize=128m", "-XX:MaxMetaspaceSize=256m", "-Xss2m", "-Dfile.encoding=UTF-8"), resolvers += Resolver.url("typesafe", url("http://repo.typesafe.com/typesafe/ivy-releases/"))(Resolver.ivyStylePatterns) ) diff --git a/docs/build.sbt b/docs/build.sbt index 7222d72..67d4d8d 100644 --- a/docs/build.sbt +++ b/docs/build.sbt @@ -1,7 +1,7 @@ // Uses the out of the box generic theme. paradoxTheme := Some(builtinParadoxTheme("generic")) -scalaVersion := "2.12.2" +scalaVersion := "2.12.6" paradoxProperties in Compile ++= Map( "snip.g8root.base_dir" -> "../../../../src/main/g8", diff --git a/docs/src/main/paradox/communicate-with-actors.md b/docs/src/main/paradox/communicate-with-actors.md index de0b24c..fbb2164 100644 --- a/docs/src/main/paradox/communicate-with-actors.md +++ b/docs/src/main/paradox/communicate-with-actors.md @@ -8,10 +8,10 @@ You might be wondering what the Actor is doing when it is not processing message To put a message into an Actor's mailbox, use the `!` (bang) method on the `ActorRef`. For example, the main class of Hello World sends messages to the `Greeter` Actor like this: -@@snip [AkkaQuickstart.scala]($g8src$/scala/com/lightbend/akka/sample/AkkaQuickstart.scala) { #main-send-messages } +@@snip [AkkaQuickstart.scala]($g8src$/scala/$package$/AkkaQuickstart.scala) { #main-send-messages } The `Greeter` Actor also sends a message to the `Printer` Actor: -@@snip [AkkaQuickstart.scala]($g8src$/scala/com/lightbend/akka/sample/AkkaQuickstart.scala) { #greeter-send-message } +@@snip [AkkaQuickstart.scala]($g8src$/scala/$package$/AkkaQuickstart.scala) { #greeter-send-message } We've looked at how to create actors and send messages. Now, let's review by looking at the `Main` class in its entirety. \ No newline at end of file diff --git a/docs/src/main/paradox/create-actors.md b/docs/src/main/paradox/create-actors.md index 8e83997..2b5a898 100644 --- a/docs/src/main/paradox/create-actors.md +++ b/docs/src/main/paradox/create-actors.md @@ -16,7 +16,7 @@ Actor and `ActorSystem` names are important in Akka. For example, you use them f The previous topic reviewed the definition of Hello World Actors. Let's look at the code in the `AkkaQuickstart.scala` file that creates `Greeter` and `Printer` Actor instances: -@@snip [AkkaQuickstart.scala]($g8src$/scala/com/lightbend/akka/sample/AkkaQuickstart.scala) { #create-actors } +@@snip [AkkaQuickstart.scala]($g8src$/scala/$package$/AkkaQuickstart.scala) { #create-actors } Notice the following: diff --git a/docs/src/main/paradox/define-actors.md b/docs/src/main/paradox/define-actors.md index bdea1d2..61011d0 100644 --- a/docs/src/main/paradox/define-actors.md +++ b/docs/src/main/paradox/define-actors.md @@ -24,11 +24,11 @@ Lets see how the companion objects and Actor implementations for `Greeter` and ` The following code snippet in the `AkkaQuickstart.scala` file for the companion object defines the messages handled by the `Greeter` Actor: -@@snip [AkkaQuickstart.scala]($g8src$/scala/com/lightbend/akka/sample/AkkaQuickstart.scala) { #greeter-messages } +@@snip [AkkaQuickstart.scala]($g8src$/scala/$package$/AkkaQuickstart.scala) { #greeter-messages } The following snippet defines the `props` method. -@@snip [AkkaQuickstart.scala]($g8src$/scala/com/lightbend/akka/sample/AkkaQuickstart.scala) { #greeter-companion } +@@snip [AkkaQuickstart.scala]($g8src$/scala/$package$/AkkaQuickstart.scala) { #greeter-companion } The `props` method creates and returns a `Props` instance. `Props` is a configuration class to specify options for the creation of actors, think of it as an immutable and thus freely shareable recipe for creating an actor that can include associated deployment information. This example simply passes the parameters that the Actor requires when being constructed. We will see the `props` method in action later in this tutorial. @@ -36,7 +36,7 @@ The `props` method creates and returns a `Props` instance. `Props` is a configur The following snippet from the `AkkaQuickstart.scala` implements the `Greeter` Actor: -@@snip [AkkaQuickstart.scala]($g8src$/scala/com/lightbend/akka/sample/AkkaQuickstart.scala) { #greeter-actor } +@@snip [AkkaQuickstart.scala]($g8src$/scala/$package$/AkkaQuickstart.scala) { #greeter-actor } Let's break down the functionality: @@ -49,11 +49,11 @@ Let's break down the functionality: Similar to 'Greeter', the companion object defines the messages handled by the `Printer` Actor: -@@snip [AkkaQuickstart.scala]($g8src$/scala/com/lightbend/akka/sample/AkkaQuickstart.scala) { #printer-messages } +@@snip [AkkaQuickstart.scala]($g8src$/scala/$package$/AkkaQuickstart.scala) { #printer-messages } And, the companion object of `Printer` defines a `props` method and the message that the Actor expects: -@@snip [AkkaQuickstart.scala]($g8src$/scala/com/lightbend/akka/sample/AkkaQuickstart.scala) { #printer-companion } +@@snip [AkkaQuickstart.scala]($g8src$/scala/$package$/AkkaQuickstart.scala) { #printer-companion } ### Printer Actor implementation @@ -62,4 +62,4 @@ The `Printer` implementation is very simple: * It extends `akka.actor.ActorLogging` to automatically get a reference to a logger. By doing this we can write `log.info()` in the Actor without any additional importing or wiring. * It just handles one type of message, `Greeting`, and logs the content of that message. -@@snip [AkkaQuickstart.scala]($g8src$/scala/com/lightbend/akka/sample/AkkaQuickstart.scala) { #printer-actor } +@@snip [AkkaQuickstart.scala]($g8src$/scala/$package$/AkkaQuickstart.scala) { #printer-actor } diff --git a/docs/src/main/paradox/full-example.md b/docs/src/main/paradox/full-example.md index 3c9806d..ead1080 100644 --- a/docs/src/main/paradox/full-example.md +++ b/docs/src/main/paradox/full-example.md @@ -2,6 +2,6 @@ Take a look at the definition of Actors, their companion objects, and Messages: -@@snip [AkkaQuickstart.scala]($g8src$/scala/com/lightbend/akka/sample/AkkaQuickstart.scala) +@@snip [AkkaQuickstart.scala]($g8src$/scala/$package$/AkkaQuickstart.scala) As another best practice we should provide some test coverage. \ No newline at end of file diff --git a/docs/src/main/paradox/intellij-idea.md b/docs/src/main/paradox/intellij-idea.md index 6a721b0..5697f75 100644 --- a/docs/src/main/paradox/intellij-idea.md +++ b/docs/src/main/paradox/intellij-idea.md @@ -12,15 +12,15 @@ Fill out the settings according to the above and press `OK` to import the projec ### Inspecting project code -If we open up the file `src/main/scala/com/lightbend/akka/sample/AkkaQuickstart.scala` we will see a lot of lines beginning with `//# ...`. These lines are used as directives for this documentation. To get rid of these lines from the source code we can utilize the awesome Find/Replace functionality in IntelliJ. Select `Edit -> Find -> Replace in Path...`. Check the `Regex` box and add the following regex `[//#].*` and click on `Replace in Find Window...`. Select to replace all occurrences and voila the lines are gone! +If we open up the file `src/main/scala/$package$/AkkaQuickstart.scala` we will see a lot of lines beginning with `//# ...`. These lines are used as directives for this documentation. To get rid of these lines from the source code we can utilize the awesome Find/Replace functionality in IntelliJ. Select `Edit -> Find -> Replace in Path...`. Check the `Regex` box and add the following regex `[//#].*` and click on `Replace in Find Window...`. Select to replace all occurrences and voila the lines are gone! ### Testing and running -For testing we simply right click on the file `src/test/scala/com/lightbend/akka/sample/AkkaQuickstartSpec.scala` and select `Run 'AkkaQuickstartSpec'`: +For testing we simply right click on the file `src/test/scala/$package$/AkkaQuickstartSpec.scala` and select `Run 'AkkaQuickstartSpec'`: ![IntelliJ](images/intellij-test-output.png) -Similarly to run the application we right click on the file `src/main/scala/com/lightbend/akka/sample/AkkaQuickstart.scala` and select `Run 'AkkaQuickstart'`: +Similarly to run the application we right click on the file `src/main/scala/$package$/AkkaQuickstart.scala` and select `Run 'AkkaQuickstart'`: ![IntelliJ](images/intellij-run-output.png) diff --git a/docs/src/main/paradox/main-class.md b/docs/src/main/paradox/main-class.md index 60e68d1..c0861b2 100644 --- a/docs/src/main/paradox/main-class.md +++ b/docs/src/main/paradox/main-class.md @@ -2,7 +2,7 @@ The `Main` class in Hello World creates and controls the actors. Notice the use of an `ActorSystem` as a container and the `actorOf` method to create the Actors. Finally, the class creates the messages to send to the Actors. -@@snip [AkkaQuickstart.scala]($g8src$/scala/com/lightbend/akka/sample/AkkaQuickstart.scala) { #main-class } +@@snip [AkkaQuickstart.scala]($g8src$/scala/$package$/AkkaQuickstart.scala) { #main-class } Similarly, let's look again at the full source code that defines the Actors and the Messages they accept. diff --git a/docs/src/main/paradox/running-the-application.md b/docs/src/main/paradox/running-the-application.md index e9525ad..b992732 100644 --- a/docs/src/main/paradox/running-the-application.md +++ b/docs/src/main/paradox/running-the-application.md @@ -44,7 +44,7 @@ Remember that the test implementation set the `Printer` Actor to use Akka logger This is the result of our code that sends messages to the `Greeter` Actor: -@@snip [AkkaQuickstart.scala]($g8src$/scala/com/lightbend/akka/sample/AkkaQuickstart.scala) { #main-send-messages } +@@snip [AkkaQuickstart.scala]($g8src$/scala/$package$/AkkaQuickstart.scala) { #main-send-messages } To run the tests, enter `test` at the sbt prompt. diff --git a/docs/src/main/paradox/testing-actors.md b/docs/src/main/paradox/testing-actors.md index 87ef1a1..694e933 100644 --- a/docs/src/main/paradox/testing-actors.md +++ b/docs/src/main/paradox/testing-actors.md @@ -6,11 +6,11 @@ The tests in the Hello World example illustrates use of the [ScalaTest](http://w Let's start by looking at the test class definition in the `AkkaQuickstartSpec.scala` source file: -@@snip [AkkaQuickstartSpec.scala]($g8srctest$/scala/com/lightbend/akka/sample/AkkaQuickstartSpec.scala) { #test-classes } +@@snip [AkkaQuickstartSpec.scala]($g8srctest$/scala/$package$/AkkaQuickstartSpec.scala) { #test-classes } The test class extends `akka.test.TestKit`, which is a module for integration testing of actors and actor systems. This class only uses a fraction of the functionality provided by [TestKit](http://doc.akka.io/docs/akka/current/scala/testing.html). The other extended classes are from `ScalaTest`. They provide syntax and functionality for the Hello World test cases. For example, by extending `FlatSpecLike`, we can write test specifications in the format of "X should Y", like this for example: -@@snip [AkkaQuickstartSpec.scala]($g8srctest$/scala/com/lightbend/akka/sample/AkkaQuickstartSpec.scala) { #specification-example } +@@snip [AkkaQuickstartSpec.scala]($g8srctest$/scala/$package$/AkkaQuickstartSpec.scala) { #specification-example } ### Test methods @@ -18,7 +18,7 @@ Now that we know some of the basic concepts, let's look at the implemented test Integration testing can help us ensure that Actors are behaving asynchronously. This first test uses `TestProbe` to interrogate and verify the expected behavior. Let's look at a source code snippet: -@@snip [AkkaQuickstartSpec.scala]($g8srctest$/scala/com/lightbend/akka/sample/AkkaQuickstartSpec.scala) { #first-test } +@@snip [AkkaQuickstartSpec.scala]($g8srctest$/scala/$package$/AkkaQuickstartSpec.scala) { #first-test } Once we have a reference to `TestProbe` we pass it to `Greeter` as part of the constructor arguments. We thereafter send two messages to `Greeter`; one to set the greeting person to greet and another to trigger the sending of a `Greeting`. The `expectMsg` method on the `TestProbe` verifies whether the message got sent. @@ -26,7 +26,7 @@ Once we have a reference to `TestProbe` we pass it to `Greeter` as part of the And, here is the complete code: -@@snip [AkkaQuickstartSpec.scala]($g8srctest$/scala/com/lightbend/akka/sample/AkkaQuickstartSpec.scala) { #full-example } +@@snip [AkkaQuickstartSpec.scala]($g8srctest$/scala/$package$/AkkaQuickstartSpec.scala) { #full-example } The example code just scratches the surface of the functionality available in `TestKit`. A complete overview can be found [here](http://doc.akka.io/docs/akka/current/scala/testing.html). diff --git a/project/build.properties b/project/build.properties index 64317fd..133a8f1 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.15 +sbt.version=0.13.17 diff --git a/project/default.properties b/project/default.properties deleted file mode 100644 index b31c2d9..0000000 --- a/project/default.properties +++ /dev/null @@ -1,2 +0,0 @@ -name=akka-quickstart-scala -description=Akka is a toolkit and runtime for building highly concurrent, distributed, and fault tolerant event-driven apps. This simple application will get you started building Actor based systems with Scala. diff --git a/project/giter8.sbt b/project/giter8.sbt index 8c18342..70a8882 100644 --- a/project/giter8.sbt +++ b/project/giter8.sbt @@ -1 +1 @@ -addSbtPlugin("org.foundweekends.giter8" %% "sbt-giter8" % "0.7.2") +addSbtPlugin("org.foundweekends.giter8" %% "sbt-giter8" % "0.10.0") diff --git a/project/paradox.sbt b/project/paradox.sbt index 01bcc5c..cf17b0d 100644 --- a/project/paradox.sbt +++ b/project/paradox.sbt @@ -1,2 +1,2 @@ // sbt-paradox, used for documentation -addSbtPlugin("com.lightbend.paradox" % "sbt-paradox" % "0.2.11") +addSbtPlugin("com.lightbend.paradox" % "sbt-paradox" % "0.3.2") diff --git a/src/main/g8/build.sbt b/src/main/g8/build.sbt index b3f81cf..68d6b58 100644 --- a/src/main/g8/build.sbt +++ b/src/main/g8/build.sbt @@ -2,12 +2,12 @@ name := "akka-quickstart-scala" version := "1.0" -scalaVersion := "2.12.2" +scalaVersion := "2.12.6" -lazy val akkaVersion = "2.5.12" +lazy val akkaVersion = "$akka_version$" libraryDependencies ++= Seq( "com.typesafe.akka" %% "akka-actor" % akkaVersion, "com.typesafe.akka" %% "akka-testkit" % akkaVersion, - "org.scalatest" %% "scalatest" % "3.0.1" % "test" + "org.scalatest" %% "scalatest" % "3.0.5" % "test" ) diff --git a/src/main/g8/default.properties b/src/main/g8/default.properties index 392d0bb..85e63fd 100644 --- a/src/main/g8/default.properties +++ b/src/main/g8/default.properties @@ -1,3 +1,4 @@ name = akka-quickstart-scala description = Akka is a toolkit and runtime for building highly concurrent, distributed, and fault tolerant event-driven apps. This simple application will get you started building Actor based systems with Scala. This app uses Akka, Scala, and ScalaTest. -verbatim = *.scala +akka_version=2.5.12 +package=com.example diff --git a/src/main/g8/project/build.properties b/src/main/g8/project/build.properties index 64317fd..133a8f1 100644 --- a/src/main/g8/project/build.properties +++ b/src/main/g8/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.15 +sbt.version=0.13.17 diff --git a/src/main/g8/project/plugins.sbt b/src/main/g8/project/plugins.sbt index 8682fad..d4312f7 100644 --- a/src/main/g8/project/plugins.sbt +++ b/src/main/g8/project/plugins.sbt @@ -1 +1 @@ -addSbtPlugin("io.spray" % "sbt-revolver" % "0.8.0") +addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1") diff --git a/src/main/g8/src/main/scala/com/lightbend/akka/sample/AkkaQuickstart.scala b/src/main/g8/src/main/scala/$package$/AkkaQuickstart.scala similarity index 93% rename from src/main/g8/src/main/scala/com/lightbend/akka/sample/AkkaQuickstart.scala rename to src/main/g8/src/main/scala/$package$/AkkaQuickstart.scala index 9eb72c6..842d777 100644 --- a/src/main/g8/src/main/scala/com/lightbend/akka/sample/AkkaQuickstart.scala +++ b/src/main/g8/src/main/scala/$package$/AkkaQuickstart.scala @@ -1,5 +1,5 @@ //#full-example -package com.lightbend.akka.sample +package $package$ import akka.actor.{ Actor, ActorLogging, ActorRef, ActorSystem, Props } @@ -24,7 +24,7 @@ class Greeter(message: String, printerActor: ActorRef) extends Actor { def receive = { case WhoToGreet(who) => - greeting = s"$message, $who" + greeting = message + ", " + who case Greet => //#greeter-send-message printerActor ! Greeting(greeting) @@ -50,7 +50,7 @@ class Printer extends Actor with ActorLogging { def receive = { case Greeting(greeting) => - log.info(s"Greeting received (from ${sender()}): $greeting") + log.info("Greeting received (from " + sender() + "): " + greeting) } } //#printer-actor diff --git a/src/main/g8/src/test/scala/com/lightbend/akka/sample/AkkaQuickstartSpec.scala b/src/main/g8/src/test/scala/$package$/AkkaQuickstartSpec.scala similarity index 79% rename from src/main/g8/src/test/scala/com/lightbend/akka/sample/AkkaQuickstartSpec.scala rename to src/main/g8/src/test/scala/$package$/AkkaQuickstartSpec.scala index 8db2f8c..f66f35c 100644 --- a/src/main/g8/src/test/scala/com/lightbend/akka/sample/AkkaQuickstartSpec.scala +++ b/src/main/g8/src/test/scala/$package$/AkkaQuickstartSpec.scala @@ -1,10 +1,11 @@ //#full-example -package com.lightbend.akka.sample +package $package$ import org.scalatest.{ BeforeAndAfterAll, WordSpecLike, Matchers } -import akka.actor.{ Actor, Props, ActorSystem } -import akka.testkit.{ ImplicitSender, TestKit, TestActorRef, TestProbe } +import akka.actor.ActorSystem +import akka.testkit.{ TestKit, TestProbe } import scala.concurrent.duration._ +import scala.language.postfixOps import Greeter._ import Printer._ @@ -33,7 +34,7 @@ class AkkaQuickstartSpec(_system: ActorSystem) val greetPerson = "Akka" helloGreeter ! WhoToGreet(greetPerson) helloGreeter ! Greet - testProbe.expectMsg(500 millis, Greeting(s"$helloGreetingMessage, $greetPerson")) + testProbe.expectMsg(500 millis, Greeting(helloGreetingMessage + ", " + greetPerson)) } } //#first-test