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

refactor: update sbt-by-example #1153

Merged
merged 3 commits into from
Aug 12, 2023
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
262 changes: 127 additions & 135 deletions src/reference/00-Getting-Started/02-sbt-by-example.md

Large diffs are not rendered by default.

271 changes: 132 additions & 139 deletions src/reference/es/00-Getting-Started/02-sbt-by-example.md

Large diffs are not rendered by default.

287 changes: 140 additions & 147 deletions src/reference/ja/00-Getting-Started/02-sbt-by-example.md

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions src/sbt-test/ref/example-library/build.sbt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
ThisBuild / scalaVersion := "2.13.6"
ThisBuild / scalaVersion := "2.13.11"
ThisBuild / organization := "com.example"

lazy val hello = (project in file("."))
lazy val hello = project
.in(file("."))
.settings(
name := "Hello",
libraryDependencies += "com.typesafe.play" %% "play-json" % "2.9.2",
libraryDependencies += "com.eed3si9n" %% "gigahorse-okhttp" % "0.5.0",
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.7" % Test,
libraryDependencies ++= Seq(
"org.scala-lang" %% "toolkit" % "0.1.7",
"org.scala-lang" %% "toolkit-test" % "0.1.7" % Test
)
)
2 changes: 1 addition & 1 deletion src/sbt-test/ref/example-name/build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ThisBuild / scalaVersion := "2.13.6"
ThisBuild / scalaVersion := "2.13.11"
ThisBuild / organization := "com.example"

lazy val hello = (project in file("."))
Expand Down
8 changes: 0 additions & 8 deletions src/sbt-test/ref/example-scalatest/build.sbt

This file was deleted.

8 changes: 0 additions & 8 deletions src/sbt-test/ref/example-scalatest/changes/HelloSpec.scala

This file was deleted.

4 changes: 0 additions & 4 deletions src/sbt-test/ref/example-scalatest/test

This file was deleted.

16 changes: 10 additions & 6 deletions src/sbt-test/ref/example-sub1/build.sbt
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
ThisBuild / scalaVersion := "2.13.6"
ThisBuild / scalaVersion := "2.13.11"
ThisBuild / organization := "com.example"

lazy val hello = (project in file("."))
lazy val hello = project
.in(file("."))
.settings(
name := "Hello",
libraryDependencies += "com.eed3si9n" %% "gigahorse-okhttp" % "0.5.0",
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.7" % Test,
libraryDependencies ++= Seq(
"org.scala-lang" %% "toolkit" % "0.1.7",
"org.scala-lang" %% "toolkit-test" % "0.1.7" % Test
)
)

lazy val helloCore = (project in file("core"))
lazy val helloCore = project
.in(file("core"))
.settings(
name := "Hello Core",
name := "Hello Core"
)
18 changes: 11 additions & 7 deletions src/sbt-test/ref/example-sub2/build.sbt
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
ThisBuild / scalaVersion := "2.13.6"
ThisBuild / scalaVersion := "2.13.11"
ThisBuild / organization := "com.example"

val scalaTest = "org.scalatest" %% "scalatest" % "3.2.7"
val toolkitTest = "org.scala-lang" %% "toolkit-test" % "0.1.7"

lazy val hello = (project in file("."))
lazy val hello = project
.in(file("."))
.settings(
name := "Hello",
libraryDependencies += "com.eed3si9n" %% "gigahorse-okhttp" % "0.5.0",
libraryDependencies += scalaTest % Test,
libraryDependencies ++= Seq(
"org.scala-lang" %% "toolkit" % "0.1.7",
toolkitTest % Test
)
)

lazy val helloCore = (project in file("core"))
lazy val helloCore = project
.in(file("core"))
.settings(
name := "Hello Core",
libraryDependencies += scalaTest % Test,
libraryDependencies += toolkitTest % Test
)
18 changes: 11 additions & 7 deletions src/sbt-test/ref/example-sub3/build.sbt
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
ThisBuild / scalaVersion := "2.13.6"
ThisBuild / scalaVersion := "2.13.11"
ThisBuild / organization := "com.example"

val scalaTest = "org.scalatest" %% "scalatest" % "3.2.7"
val toolkitTest = "org.scala-lang" %% "toolkit-test" % "0.1.7"

lazy val hello = (project in file("."))
lazy val hello = project
.in(file("."))
.aggregate(helloCore)
.settings(
name := "Hello",
libraryDependencies += "com.eed3si9n" %% "gigahorse-okhttp" % "0.5.0",
libraryDependencies += scalaTest % Test,
libraryDependencies ++= Seq(
"org.scala-lang" %% "toolkit" % "0.1.7",
toolkitTest % Test
)
)

lazy val helloCore = (project in file("core"))
lazy val helloCore = project
.in(file("core"))
.settings(
name := "Hello Core",
libraryDependencies += scalaTest % Test,
libraryDependencies += toolkitTest % Test
)
16 changes: 9 additions & 7 deletions src/sbt-test/ref/example-sub4/build.sbt
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
ThisBuild / scalaVersion := "2.13.6"
ThisBuild / scalaVersion := "2.13.11"
ThisBuild / organization := "com.example"

val scalaTest = "org.scalatest" %% "scalatest" % "3.2.7"
val toolkitTest = "org.scala-lang" %% "toolkit-test" % "0.1.7"

lazy val hello = (project in file("."))
lazy val hello = project
.in(file("."))
.aggregate(helloCore)
.dependsOn(helloCore)
.settings(
name := "Hello",
libraryDependencies += scalaTest % Test,
libraryDependencies += toolkitTest % Test
)

lazy val helloCore = (project in file("core"))
lazy val helloCore = project
.in(file("core"))
.settings(
name := "Hello Core",
libraryDependencies += "com.eed3si9n" %% "gigahorse-okhttp" % "0.5.0",
libraryDependencies += scalaTest % Test,
libraryDependencies += "org.scala-lang" %% "toolkit" % "0.1.7",
libraryDependencies += toolkitTest % Test
)
9 changes: 9 additions & 0 deletions src/sbt-test/ref/example-test/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ThisBuild / scalaVersion := "2.13.11"
ThisBuild / organization := "com.example"

lazy val hello = project
.in(file("."))
.settings(
name := "Hello",
libraryDependencies += "org.scala-lang" %% "toolkit-test" % "0.1.7" % Test
)
6 changes: 6 additions & 0 deletions src/sbt-test/ref/example-test/changes/HelloSuite.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

class HelloSuite extends munit.FunSuite {
test("Hello should start with H") {
assert("Hello".startsWith("H"))
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import org.scalatest.funsuite._

class HelloSpec extends AnyFunSuite {
class HelloSuite extends munit.FunSuite {
test("Hello should start with H") {
assert("hello".startsWith("H"))
}
Expand Down
4 changes: 4 additions & 0 deletions src/sbt-test/ref/example-test/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
> compile
-> testQuick
$copy-file changes/HelloSuite.scala src/test/scala/example/HelloSuite.scala
> testQuick
18 changes: 9 additions & 9 deletions src/sbt-test/ref/example-weather/build.sbt
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
ThisBuild / scalaVersion := "2.13.6"
ThisBuild / scalaVersion := "2.13.11"
ThisBuild / organization := "com.example"

val scalaTest = "org.scalatest" %% "scalatest" % "3.2.7"
val gigahorse = "com.eed3si9n" %% "gigahorse-okhttp" % "0.5.0"
val playJson = "com.typesafe.play" %% "play-json" % "2.9.2"
val toolkitTest = "org.scala-lang" %% "toolkit-test" % "0.1.7"

lazy val hello = (project in file("."))
lazy val hello = project
.in(file("."))
.aggregate(helloCore)
.dependsOn(helloCore)
.settings(
name := "Hello",
libraryDependencies += scalaTest % Test,
libraryDependencies += toolkitTest % Test
)

lazy val helloCore = (project in file("core"))
lazy val helloCore = project
.in(file("core"))
.settings(
name := "Hello Core",
libraryDependencies ++= Seq(gigahorse, playJson),
libraryDependencies += scalaTest % Test,
libraryDependencies += "org.scala-lang" %% "toolkit" % "0.1.7",
libraryDependencies += toolkitTest % Test
)
19 changes: 10 additions & 9 deletions src/sbt-test/ref/example-weather/changes/build.sbt
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
ThisBuild / scalaVersion := "2.13.6"
ThisBuild / scalaVersion := "2.13.11"
ThisBuild / organization := "com.example"

val scalaTest = "org.scalatest" %% "scalatest" % "3.2.7"
val gigahorse = "com.eed3si9n" %% "gigahorse-okhttp" % "0.5.0"
val playJson = "com.typesafe.play" %% "play-json" % "2.9.2"
val toolkitTest = "org.scala-lang" %% "toolkit-test" % "0.1.7"

lazy val hello = (project in file("."))
lazy val hello = project
.in(file("."))
.aggregate(helloCore)
.dependsOn(helloCore)
.enablePlugins(JavaAppPackaging)
.settings(
name := "Hello",
libraryDependencies += scalaTest % Test,
libraryDependencies += toolkitTest % Test,
maintainer := "A Scala Dev!"
)

lazy val helloCore = (project in file("core"))
lazy val helloCore = project
.in(file("core"))
.settings(
name := "Hello Core",
libraryDependencies ++= Seq(gigahorse, playJson),
libraryDependencies += scalaTest % Test,
libraryDependencies += "org.scala-lang" %% "toolkit" % "0.1.7",
libraryDependencies += toolkitTest % Test
)
21 changes: 11 additions & 10 deletions src/sbt-test/ref/example-weather/changes/build3.sbt
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
ThisBuild / version := "0.1.0"
ThisBuild / scalaVersion := "2.13.6"
ThisBuild / version := "0.1.0"
ThisBuild / scalaVersion := "2.13.11"
ThisBuild / organization := "com.example"

val scalaTest = "org.scalatest" %% "scalatest" % "3.2.7"
val gigahorse = "com.eed3si9n" %% "gigahorse-okhttp" % "0.5.0"
val playJson = "com.typesafe.play" %% "play-json" % "2.9.2"
val toolkitTest = "org.scala-lang" %% "toolkit-test" % "0.1.7"

lazy val hello = (project in file("."))
lazy val hello = project
.in(file("."))
.aggregate(helloCore)
.dependsOn(helloCore)
.enablePlugins(JavaAppPackaging)
.settings(
name := "Hello",
libraryDependencies += scalaTest % Test,
libraryDependencies += toolkitTest % Test,
maintainer := "A Scala Dev!"
)

lazy val helloCore = (project in file("core"))
lazy val helloCore = project
.in(file("core"))
.settings(
name := "Hello Core",
libraryDependencies ++= Seq(gigahorse, playJson),
libraryDependencies += scalaTest % Test,
libraryDependencies += "org.scala-lang" %% "toolkit" % "0.1.7",
libraryDependencies += toolkitTest % Test
)
2 changes: 1 addition & 1 deletion src/sbt-test/ref/example-weather/changes/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.4")
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.4")
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
package example.core

import gigahorse._, support.okhttp.Gigahorse
import scala.concurrent._, duration._
import play.api.libs.json._
import sttp.client4.quick._
import sttp.client4.Response

object Weather {
lazy val http = Gigahorse.http(Gigahorse.config)

def weather: Future[String] = {
val baseUrl = "https://www.metaweather.com/api/location"
val locUrl = baseUrl + "/search/"
val weatherUrl = baseUrl + "/%s/"
val rLoc = Gigahorse.url(locUrl).get.
addQueryString("query" -> "New York")
import ExecutionContext.Implicits.global
for {
loc <- http.run(rLoc, parse)
woeid = (loc \ 0 \ "woeid").get
rWeather = Gigahorse.url(weatherUrl format woeid).get
weather <- http.run(rWeather, parse)
} yield (weather \\ "weather_state_name")(0).as[String].toLowerCase
def weather() = {
val response: Response[String] = quickRequest
.get(
uri"https://api.open-meteo.com/v1/forecast?latitude=$newYorkLatitude&longitude=$newYorkLongitude&current_weather=true"
)
.send()
val json = ujson.read(response.body)
json.obj("current_weather")("temperature").num
}

private def parse = Gigahorse.asString andThen Json.parse
private val newYorkLatitude: Double = 40.7143
private val newYorkLongitude: Double = -74.006
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package example

import scala.concurrent._, duration._
import core.Weather
import example.core.Weather

object Hello {
def main(args: Array[String]): Unit = {
val w = Await.result(Weather.weather, 10.seconds)
println(s"Hello! The weather in New York is $w.")
Weather.http.close()
val temp = Weather.weather()
println(s"Hello! The current temperature in New York is $temp C.")
}
}