From fc3e85997c75559f76c70991d317bfee307e5e24 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Thu, 7 Oct 2021 15:09:05 +0200 Subject: [PATCH 01/39] update README bump versions --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cca14a5..e075362 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,8 @@ This repo is used in this course *(in Swedish)*: http://cs.lth.se/pgk with cours You need to have [Scala Build Tool](https://www.scala-sbt.org/download.html) version 1.5.2 or later and put this text in a file called `build.sbt` ``` -scalaVersion := "3.0.1" -libraryDependencies += "se.lth.cs" %% "introprog" % "1.2.0" +scalaVersion := "3.0.2" +libraryDependencies += "se.lth.cs" %% "introprog" % "1.3.1" ``` When you run `sbt` in terminal the `introprog` package is automatically downloaded and made available on your classpath. From 61270f541a2ec624e143c986cf67d8d4ab34ec12 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Thu, 12 May 2022 14:42:41 +0200 Subject: [PATCH 02/39] add comment on backwards compatibility --- build.sbt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index afb2282..be6e267 100644 --- a/build.sbt +++ b/build.sbt @@ -1,7 +1,9 @@ lazy val Version = "1.3.1" lazy val Name = "introprog" //lazy val scala213 = "2.13.6" -lazy val scala3 = "3.0.2" +lazy val scala3 = "3.0.2" // stick to latest 3.0 for backward and forward compatibility + // when sbt 1.7 is released start using scalaOutputVersion + // https://scala-lang.org/blog/2022/04/12/scala-3.1.2-released.html //lazy val supportedScalaVersions = List(scala213, scala3) // to avoid strange warnings, these lines with excludeLintKeys are needed: From 04328a54f9fe3a281d757cbac2a940b95b579520 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Mon, 16 May 2022 15:00:26 +0200 Subject: [PATCH 03/39] add scala-cli help to readme --- README.md | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e075362..eff6ed2 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,40 @@ This repo is used in this course *(in Swedish)*: http://cs.lth.se/pgk with cours ## How to use introprog-scalalib + +### Using scala-cli + +You need [Scala Command Line Interface]() at least version 0.1.5. + +Add these magic comment lines starting with `//>` in the beginning of your Scala 3 file: + +``` +//> using scala "3" +//> using lib "se.lth.cs::introprog:1.3.1" +``` + +You run your code with `scala-cli run .` (note the ending dot, meaning "this dir") + +If your program looks like this: + +``` +//> using scala "3.1.2" +//> using lib "se.lth.cs::introprog:1.3.1" + +@main def run = + val w = introprog.PixelWindow() + w.drawText("Hello introprog.PixelWindow!", x = 100, y = 100) +``` +You should now see green text in a new window after executing: +``` +scala-cli run . +``` + ### Using sbt -You need to have [Scala Build Tool](https://www.scala-sbt.org/download.html) version 1.5.2 or later and put this text in a file called `build.sbt` +You need [Scala Build Tool](https://www.scala-sbt.org/download.html) at least version 1.5.2 (preferably 1.6.2 or later). + +Put this text in a file called `build.sbt` ``` scalaVersion := "3.0.2" libraryDependencies += "se.lth.cs" %% "introprog" % "1.3.1" From 6ac442b446ce4fa594ec030514680859797e1a3d Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Mon, 16 May 2022 15:01:52 +0200 Subject: [PATCH 04/39] fix wording --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eff6ed2..802cb2b 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ If your program looks like this: val w = introprog.PixelWindow() w.drawText("Hello introprog.PixelWindow!", x = 100, y = 100) ``` -You should now see green text in a new window after executing: +You should see green text in a new window after executing: ``` scala-cli run . ``` From 8be0a561d35a106c1b22f65423a761695749f938 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Mon, 16 May 2022 15:10:56 +0200 Subject: [PATCH 05/39] improve readme sbt info for old scala versions --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 802cb2b..478334e 100644 --- a/README.md +++ b/README.md @@ -64,15 +64,15 @@ scala> w.fill(100,100,100,100,java.awt.Color.red) ### Older Scala versions -If you want to use Scala 2.13 with 2.13.5 or later then use these special settings in `build.sbt`: +If you want to use Scala 2.13 with 2.13.5 or later then use these special settings in `build.sbt`, esp. note that you should use version 1.1.5 of introprog: ``` -scalaVersion := "2.13.6" +scalaVersion := "2.13.8" //2.13.5 or any later 2.13 version scalacOptions += "-Ytasty-reader" libraryDependencies += ("se.lth.cs" %% "introprog" % "1.1.5").cross(CrossVersion.for2_13Use3) ``` -For Scala 2.12.x and 2.13.4 and older you need to use the old version `"1.1.4"` of `introprog`. +For Scala 2.12.x and 2.13.4 and older you need to use version 1.1.4 of introprog or older. ### Manual download From 2dc96ead8f1d38bfd414edd00942541cf8c7f9f0 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Mon, 16 May 2022 15:13:59 +0200 Subject: [PATCH 06/39] add link to scala-cli --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 478334e..90ad15f 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ This repo is used in this course *(in Swedish)*: http://cs.lth.se/pgk with cours ### Using scala-cli -You need [Scala Command Line Interface]() at least version 0.1.5. +You need [Scala Command Line Interface](https://scala-cli.virtuslab.org/install) at least version 0.1.5. Add these magic comment lines starting with `//>` in the beginning of your Scala 3 file: From 58065e6bf8249d03669b40518ed057aa0e8c425d Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Mon, 16 May 2022 15:16:35 +0200 Subject: [PATCH 07/39] add link to api doc --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 90ad15f..dbb8967 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ You should see green text in a new window after executing: ``` scala-cli run . ``` +See: [api documentation for PixelWindow](https://fileadmin.cs.lth.se/pgk/api/api/introprog/PixelWindow.html) ### Using sbt @@ -61,7 +62,7 @@ sbt> console scala> val w = new introprog.PixelWindow() scala> w.fill(100,100,100,100,java.awt.Color.red) ``` - +See: [api documentation for PixelWindow](https://fileadmin.cs.lth.se/pgk/api/api/introprog/PixelWindow.html) ### Older Scala versions If you want to use Scala 2.13 with 2.13.5 or later then use these special settings in `build.sbt`, esp. note that you should use version 1.1.5 of introprog: From 94b96a810fce90fdd5671adc6c1516d4f4c0bb06 Mon Sep 17 00:00:00 2001 From: Bjorn Regnell Date: Thu, 14 Jul 2022 17:34:18 +0200 Subject: [PATCH 08/39] fix badges in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dbb8967..98c7e08 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![Build Status](https://github.com/lunduniversity/introprog-scalalib/actions/workflows/main.yml/badge.svg) -[](http://search.maven.org/#search%7Cga%7C1%7Cg%3Ase.lth.cs%20a%3Aintroprog_3) [](http://search.maven.org/#search%7Cga%7C1%7Cg%3Ase.lth.cs%20a%3Aintroprog_2.13) [](http://search.maven.org/#search%7Cga%7C1%7Cg%3Ase.lth.cs%20a%3Aintroprog_2.12) +[](http://search.maven.org/#search%7Cga%7C1%7Cg%3Ase.lth.cs%20a%3Aintroprog_3) [](http://search.maven.org/#search%7Cga%7C1%7Cg%3Ase.lth.cs%20a%3Aintroprog_2.13) [](http://search.maven.org/#search%7Cga%7C1%7Cg%3Ase.lth.cs%20a%3Aintroprog_2.12) This is a library with Scala utilities for Computer Science teaching. The library is maintained by Björn Regnell at Lund University, Sweden. Contributions are welcome! From cb9b1d04db2d39c1dc2c7fad32b32b574170f747 Mon Sep 17 00:00:00 2001 From: Bjorn Regnell Date: Thu, 14 Jul 2022 17:34:54 +0200 Subject: [PATCH 09/39] fix badges --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 98c7e08..f167e69 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![Build Status](https://github.com/lunduniversity/introprog-scalalib/actions/workflows/main.yml/badge.svg) -[](http://search.maven.org/#search%7Cga%7C1%7Cg%3Ase.lth.cs%20a%3Aintroprog_3) [](http://search.maven.org/#search%7Cga%7C1%7Cg%3Ase.lth.cs%20a%3Aintroprog_2.13) [](http://search.maven.org/#search%7Cga%7C1%7Cg%3Ase.lth.cs%20a%3Aintroprog_2.12) +[](http://search.maven.org/#search%7Cga%7C1%7Cg%3Ase.lth.cs%20a%3Aintroprog_3) [](http://search.maven.org/#search%7Cga%7C1%7Cg%3Ase.lth.cs%20a%3Aintroprog_2.13) [](http://search.maven.org/#search%7Cga%7C1%7Cg%3Ase.lth.cs%20a%3Aintroprog_2.12) This is a library with Scala utilities for Computer Science teaching. The library is maintained by Björn Regnell at Lund University, Sweden. Contributions are welcome! From 0e8381647b4a7c8d045a2b31b794acb8d33a5f44 Mon Sep 17 00:00:00 2001 From: Bjorn Regnell Date: Thu, 14 Jul 2022 17:36:42 +0200 Subject: [PATCH 10/39] bump scala versions in readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f167e69..f10ab3a 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ You run your code with `scala-cli run .` (note the ending dot, meaning "this dir If your program looks like this: ``` -//> using scala "3.1.2" +//> using scala "3" //> using lib "se.lth.cs::introprog:1.3.1" @main def run = @@ -50,7 +50,7 @@ You need [Scala Build Tool](https://www.scala-sbt.org/download.html) at least ve Put this text in a file called `build.sbt` ``` -scalaVersion := "3.0.2" +scalaVersion := "3.1.3" libraryDependencies += "se.lth.cs" %% "introprog" % "1.3.1" ``` From 54886cfecd2654ca90c1872d7a140f2d27dbb158 Mon Sep 17 00:00:00 2001 From: Bjorn Regnell Date: Sun, 7 Aug 2022 12:56:05 +0200 Subject: [PATCH 11/39] fix typos in readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f10ab3a..78c13ad 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ This repo includes utilities to empower learners to advance from basic to interm * Use as simple constructs as possible. * Follow Scala idioms with a pragmatic mix of imperative, functional and object-oriented programming. -* Don't use advanced functional programming concepts and magical implicit. +* Don't use advanced functional programming concepts and magical implicits. * Prefer a clean api with single-responsibility functions in simple modules. * Prefer immutability over mutable state, `Vector` for sequences and case classes for data. * Hide/avoid threading and complicated concurrency. @@ -113,4 +113,4 @@ Areas currently in scope of this library: * Simple pixel-based 2D graphics for single-threaded game programming with explicit game loop. * Simple blocking IO that hides the underlying complication of releasing resources etc. -* Simple modal GUI dialogs that blocks while waiting for user response. +* Simple modal GUI dialogs that block while waiting for user response. From b8b4d73473e53ef50a43dfca19da0b619feba016 Mon Sep 17 00:00:00 2001 From: Axel Date: Wed, 21 Sep 2022 15:24:52 +0200 Subject: [PATCH 12/39] added instructions for scala-cli --- docs/index.md | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 3d90bef..b45e0a4 100644 --- a/docs/index.md +++ b/docs/index.md @@ -18,7 +18,38 @@ The open source code is hosted at [[https://github.com/lunduniversity/introprog- - [[introprog.examples]] with code examples demonstrating how to use this library. -## How to use this library with `sbt` +## How to use introprog-scalalib + +### Using scala-cli + +You need [Scala Command Line Interface](https://scala-cli.virtuslab.org/install) at least version 0.1.5. + +Add these magic comment lines starting with `//>` in the beginning of your Scala 3 file: + +``` +//> using scala "3" +//> using lib "se.lth.cs::introprog:1.3.1" +``` + +You run your code with `scala-cli run .` (note the ending dot, meaning "this dir") + +If your program looks like this: + +``` +//> using scala "3" +//> using lib "se.lth.cs::introprog:1.3.1" + +@main def run = + val w = introprog.PixelWindow() + w.drawText("Hello introprog.PixelWindow!", x = 100, y = 100) +``` +You should see green text in a new window after executing: +``` +scala-cli run . +``` +See: [api documentation for PixelWindow](https://fileadmin.cs.lth.se/pgk/api/api/introprog/PixelWindow.html) + +### Using sbt If you have [sbt](https://www.scala-sbt.org/) installed then you can put this text in a file called `build.sbt` From 97a32d15697d17540d7d7b72e21c2437e6d21d86 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Mon, 26 Jun 2023 19:03:05 +0200 Subject: [PATCH 13/39] update readme, adapt to latest scala-cli --- README.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 78c13ad..1b2ddc1 100644 --- a/README.md +++ b/README.md @@ -17,13 +17,13 @@ This repo is used in this course *(in Swedish)*: http://cs.lth.se/pgk with cours ### Using scala-cli -You need [Scala Command Line Interface](https://scala-cli.virtuslab.org/install) at least version 0.1.5. +You need [Scala Command Line Interface](https://scala-cli.virtuslab.org/install) at least version 1.0.0. Add these magic comment lines starting with `//>` in the beginning of your Scala 3 file: ``` -//> using scala "3" -//> using lib "se.lth.cs::introprog:1.3.1" +//> using scala 3.3 +//> using lib se.lth.cs::introprog:1.3.1 ``` You run your code with `scala-cli run .` (note the ending dot, meaning "this dir") @@ -31,8 +31,8 @@ You run your code with `scala-cli run .` (note the ending dot, meaning "this dir If your program looks like this: ``` -//> using scala "3" -//> using lib "se.lth.cs::introprog:1.3.1" +//> using scala 3.3 +//> using lib se.lth.cs::introprog:1.3.1 @main def run = val w = introprog.PixelWindow() @@ -44,13 +44,18 @@ scala-cli run . ``` See: [api documentation for PixelWindow](https://fileadmin.cs.lth.se/pgk/api/api/introprog/PixelWindow.html) +You can also give the `introprog` dependency directly at the command line, instead of the `using lib` directive: +``` +scala-cli run . --dep se.lth.cs::introprog:1.3.1 +``` + ### Using sbt You need [Scala Build Tool](https://www.scala-sbt.org/download.html) at least version 1.5.2 (preferably 1.6.2 or later). Put this text in a file called `build.sbt` ``` -scalaVersion := "3.1.3" +scalaVersion := "3.3.0" libraryDependencies += "se.lth.cs" %% "introprog" % "1.3.1" ``` From cc24866ee0a2e8f00b89e79e566fa67ed962495d Mon Sep 17 00:00:00 2001 From: Tristan Farkas Date: Tue, 12 Dec 2023 14:27:01 +0100 Subject: [PATCH 14/39] introduce appendLines method in IO. Adds appendLines to the IO api, which lets users easily append a sequence of strings to a file that already exists. --- src/main/scala/introprog/IO.scala | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/scala/introprog/IO.scala b/src/main/scala/introprog/IO.scala index 5f382b9..1797c24 100644 --- a/src/main/scala/introprog/IO.scala +++ b/src/main/scala/introprog/IO.scala @@ -49,6 +49,17 @@ object IO: def saveLines(lines: Seq[String], fileName: String, enc: String = "UTF-8"): Unit = saveString(lines.mkString("\n"), fileName, enc) + /** + * Appends `lines` to the text file `fileName` using encoding `enc`. + * + * @param lines the lines to append to the file. + * @param fileName the path of the file. + * @param enc the encoding of the file. + * */ + def appendLines(lines: Seq[String], fileName: String, enc: String = "UTF-8"): Unit = + val newLines = loadLines(fileName, enc).appendedAll(lines) + saveLines(newLines, fileName, enc) + /** * Load a serialized object from a binary file called `fileName`. * From bb364144cd71e9284c0ee117da10bcfe680f4f5c Mon Sep 17 00:00:00 2001 From: Tristan Farkas Date: Thu, 8 Feb 2024 13:44:31 +0100 Subject: [PATCH 15/39] Added a method to append a string to a text file. Also refactors the appendLines method to use the newly introduced function. --- src/main/scala/introprog/IO.scala | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/scala/introprog/IO.scala b/src/main/scala/introprog/IO.scala index 1797c24..21df0db 100644 --- a/src/main/scala/introprog/IO.scala +++ b/src/main/scala/introprog/IO.scala @@ -1,5 +1,9 @@ package introprog +import java.io.BufferedWriter +import java.io.FileWriter +import java.nio.charset.Charset + /** A module with input/output operations from/to the underlying file system. */ object IO: /** @@ -49,6 +53,23 @@ object IO: def saveLines(lines: Seq[String], fileName: String, enc: String = "UTF-8"): Unit = saveString(lines.mkString("\n"), fileName, enc) + /** + * Appends `string` to the text file `fileName` using encoding `enc`. + * + * @param text the text to be appended to the file. + * @param fileName the path of the file. + * @param enc the encoding of the file. + * */ + def appendString(text: String, fileName: String, enc: String = "UTF-8"): Unit = + val f = new java.io.File(fileName); + require(!f.isDirectory(), "The file you're trying to write to can't be a directory.") + val w = + if f.exists() then + new BufferedWriter(new FileWriter(fileName, Charset.forName(enc), true)) + else + new java.io.PrintWriter(f, enc) + try w.write(text) finally w.close() + /** * Appends `lines` to the text file `fileName` using encoding `enc`. * @@ -57,8 +78,7 @@ object IO: * @param enc the encoding of the file. * */ def appendLines(lines: Seq[String], fileName: String, enc: String = "UTF-8"): Unit = - val newLines = loadLines(fileName, enc).appendedAll(lines) - saveLines(newLines, fileName, enc) + appendString(lines.mkString("\n"), fileName, enc) /** * Load a serialized object from a binary file called `fileName`. From b1481fae3fcad47b480f6716bcf4c271e37ca1ed Mon Sep 17 00:00:00 2001 From: Tristan Farkas Date: Thu, 6 Jun 2024 13:29:44 +0200 Subject: [PATCH 16/39] introduce trailing newline when writing lines --- src/main/scala/introprog/IO.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/introprog/IO.scala b/src/main/scala/introprog/IO.scala index 21df0db..e11148d 100644 --- a/src/main/scala/introprog/IO.scala +++ b/src/main/scala/introprog/IO.scala @@ -51,7 +51,7 @@ object IO: * @param enc the encoding of the file. * */ def saveLines(lines: Seq[String], fileName: String, enc: String = "UTF-8"): Unit = - saveString(lines.mkString("\n"), fileName, enc) + saveString(lines.mkString("\n") + "\n", fileName, enc) /** * Appends `string` to the text file `fileName` using encoding `enc`. From ac1f6bc0eff5490fb47e2d3d8aff0386e360bec4 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Tue, 11 Jun 2024 14:07:30 +0200 Subject: [PATCH 17/39] bump version --- build.sbt | 9 ++++----- project/build.properties | 2 +- project/plugins.sbt | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/build.sbt b/build.sbt index be6e267..5dbe031 100644 --- a/build.sbt +++ b/build.sbt @@ -1,9 +1,8 @@ -lazy val Version = "1.3.1" +lazy val Version = "1.4.0" lazy val Name = "introprog" //lazy val scala213 = "2.13.6" -lazy val scala3 = "3.0.2" // stick to latest 3.0 for backward and forward compatibility - // when sbt 1.7 is released start using scalaOutputVersion - // https://scala-lang.org/blog/2022/04/12/scala-3.1.2-released.html +lazy val scala3 = "3.3.3" + //lazy val supportedScalaVersions = List(scala213, scala3) // to avoid strange warnings, these lines with excludeLintKeys are needed: @@ -44,7 +43,7 @@ ThisBuild / scalacOptions ++= Seq( // "-Ywarn-unused" ) -ThisBuild / Compile / compile / javacOptions ++= Seq("-target", "1.8") +ThisBuild / Compile / compile / javacOptions ++= Seq("-target", "1.8") // for backward compat Compile / doc / scalacOptions ++= Seq( "-groups", diff --git a/project/build.properties b/project/build.properties index 10fd9ee..e8a1e24 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.5.5 +sbt.version=1.9.7 diff --git a/project/plugins.sbt b/project/plugins.sbt index 4092d54..b7a2210 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,2 +1,2 @@ // https://github.com/scalacenter/sbt-version-policy -addSbtPlugin("ch.epfl.scala" % "sbt-version-policy" % "1.2.1") \ No newline at end of file +addSbtPlugin("ch.epfl.scala" % "sbt-version-policy" % "3.2.1") \ No newline at end of file From 38715ebc1f4b8dc956400b91564f56f1296eb8b0 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Tue, 11 Jun 2024 14:17:31 +0200 Subject: [PATCH 18/39] bump version --- publish-doc.sh | 2 +- publish-jar.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/publish-doc.sh b/publish-doc.sh index 7185127..79245a7 100644 --- a/publish-doc.sh +++ b/publish-doc.sh @@ -1,7 +1,7 @@ echo "*** Generating docs and copy api to fileadmin then zip it for local download" set -x -SCALAVERSION=3.0.2 +SCALAVERSION=3.3.3 sbt doc ssh $LUCATID@fileadmin.cs.lth.se rm -r pgk/api diff --git a/publish-jar.sh b/publish-jar.sh index 8acc71b..8ffcd90 100644 --- a/publish-jar.sh +++ b/publish-jar.sh @@ -1,6 +1,6 @@ #VERSION="$(grep -m 1 -Po -e '\d+.\d+.\d+' build.sbt)" -VERSION=1.3.1 -SCALAVERSION=3.0.2 +VERSION=1.4.0 +SCALAVERSION=3.3.3 SCALACOMPAT=3 JARFILE="introprog_$SCALACOMPAT-$VERSION.jar" From 11ecb6761978011fdea568a1b4825464f57838cc Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Tue, 11 Jun 2024 14:26:25 +0200 Subject: [PATCH 19/39] update doc index, bump versions, add explanations --- docs/index.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/docs/index.md b/docs/index.md index b45e0a4..803e843 100644 --- a/docs/index.md +++ b/docs/index.md @@ -22,22 +22,23 @@ The open source code is hosted at [[https://github.com/lunduniversity/introprog- ### Using scala-cli -You need [Scala Command Line Interface](https://scala-cli.virtuslab.org/install) at least version 0.1.5. +You need [Scala Command Line Interface](https://scala-cli.virtuslab.org/install) Add these magic comment lines starting with `//>` in the beginning of your Scala 3 file: ``` -//> using scala "3" -//> using lib "se.lth.cs::introprog:1.3.1" +//> using scala 3 +//> using lib "se.lth.cs::introprog:1.4.0" ``` +You can choose a specific Scala 3 version of at least 3.3.3, for example: `3.4.2` You run your code with `scala-cli run .` (note the ending dot, meaning "this dir") If your program looks like this: ``` -//> using scala "3" -//> using lib "se.lth.cs::introprog:1.3.1" +//> using scala 3 +//> using lib "se.lth.cs::introprog:1.4.0" @main def run = val w = introprog.PixelWindow() @@ -54,8 +55,8 @@ See: [api documentation for PixelWindow](https://fileadmin.cs.lth.se/pgk/api/api If you have [sbt](https://www.scala-sbt.org/) installed then you can put this text in a file called `build.sbt` ``` -scalaVersion := "3.0.2" -libraryDependencies += "se.lth.cs" %% "introprog" % "1.3.1" +scalaVersion := "3.3.3" // or any newer released Scala version +libraryDependencies += "se.lth.cs" %% "introprog" % "1.4.0" ``` When you run `sbt` in a terminal, with the above in your `build.sbt`, the introprog lib is automatically downloaded and made available on your classpath. Then you can do things like: From 315e9a2da86ac117bb6b0d5c4628858177e6343b Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Tue, 11 Jun 2024 14:29:06 +0200 Subject: [PATCH 20/39] clean up de-commented cross build settings --- build.sbt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/build.sbt b/build.sbt index 5dbe031..11bd233 100644 --- a/build.sbt +++ b/build.sbt @@ -1,20 +1,15 @@ lazy val Version = "1.4.0" lazy val Name = "introprog" -//lazy val scala213 = "2.13.6" lazy val scala3 = "3.3.3" -//lazy val supportedScalaVersions = List(scala213, scala3) - // to avoid strange warnings, these lines with excludeLintKeys are needed: Global / excludeLintKeys += ThisBuild / Compile / console / fork - lazy val introprog = (project in file(".")) .settings( name := Name, version := Version, scalaVersion := scala3, - //crossScalaVersions := supportedScalaVersions, ) ThisBuild / Compile / console / fork := true @@ -24,7 +19,6 @@ ThisBuild / versionScheme := Some("early-semver") ThisBuild / versionPolicyIntention := Compatibility.None //ThisBuild / versionPolicyIntention := Compatibility.BinaryAndSourceCompatible //ThisBuild / versionPolicyIntention := Compatibility.BinaryCompatible - //In the sbt shell check version using: //sbt> versionCheck //sbt> versionPolicyCheck From 482dcceaa4395504f4b10d9551391874ac313264 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Tue, 11 Jun 2024 18:44:09 +0200 Subject: [PATCH 21/39] fix saveLines appendLines so that empty and trailing newline is correct --- src/main/scala/introprog/IO.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/scala/introprog/IO.scala b/src/main/scala/introprog/IO.scala index e11148d..dd4e32a 100644 --- a/src/main/scala/introprog/IO.scala +++ b/src/main/scala/introprog/IO.scala @@ -51,7 +51,7 @@ object IO: * @param enc the encoding of the file. * */ def saveLines(lines: Seq[String], fileName: String, enc: String = "UTF-8"): Unit = - saveString(lines.mkString("\n") + "\n", fileName, enc) + if lines.nonEmpty then saveString(lines.mkString("", "\n", "\n"), fileName, enc) /** * Appends `string` to the text file `fileName` using encoding `enc`. @@ -78,7 +78,7 @@ object IO: * @param enc the encoding of the file. * */ def appendLines(lines: Seq[String], fileName: String, enc: String = "UTF-8"): Unit = - appendString(lines.mkString("\n"), fileName, enc) + if lines.nonEmpty then appendString(lines.mkString("","\n","\n"), fileName, enc) /** * Load a serialized object from a binary file called `fileName`. From b81b16fe4f25e1a7f92a05fe561a300630dfaa2e Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Tue, 11 Jun 2024 18:51:18 +0200 Subject: [PATCH 22/39] add munit dependency to Test scope --- build.sbt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build.sbt b/build.sbt index 11bd233..03e5cd8 100644 --- a/build.sbt +++ b/build.sbt @@ -2,6 +2,8 @@ lazy val Version = "1.4.0" lazy val Name = "introprog" lazy val scala3 = "3.3.3" +Global / onChangedBuildSource := ReloadOnSourceChanges + // to avoid strange warnings, these lines with excludeLintKeys are needed: Global / excludeLintKeys += ThisBuild / Compile / console / fork @@ -10,6 +12,7 @@ lazy val introprog = (project in file(".")) name := Name, version := Version, scalaVersion := scala3, + libraryDependencies += "org.scalameta" %% "munit" % "0.7.29" % Test, ) ThisBuild / Compile / console / fork := true @@ -17,6 +20,7 @@ ThisBuild / Compile / console / fork := true //https://github.com/scalacenter/sbt-version-policy ThisBuild / versionScheme := Some("early-semver") ThisBuild / versionPolicyIntention := Compatibility.None +//ThisBuild / versionPolicyIntention := Compatibility.None //ThisBuild / versionPolicyIntention := Compatibility.BinaryAndSourceCompatible //ThisBuild / versionPolicyIntention := Compatibility.BinaryCompatible //In the sbt shell check version using: From c80904a2da4899c33d66449eac5e1dc4a01ccec6 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Tue, 11 Jun 2024 18:51:26 +0200 Subject: [PATCH 23/39] add TestIO --- src/test/scala/testIO.scala | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/test/scala/testIO.scala diff --git a/src/test/scala/testIO.scala b/src/test/scala/testIO.scala new file mode 100644 index 0000000..77e03ac --- /dev/null +++ b/src/test/scala/testIO.scala @@ -0,0 +1,25 @@ +package introprog + +val tmpDir = "target/tmp" + +class TestIO extends munit.FunSuite { + test("TestIO: createDirIfNotExist, saveString, appendString, loadLines, appendLines") { + val existed = IO.createDirIfNotExist(tmpDir) + assert(IO.isExisting(tmpDir), s"dir should exists: $tmpDir") + val s1 = "hello" + val fn = s"$tmpDir/hello.txt" + IO.saveString(s1, fileName = fn) + val s2 = IO.loadString(fileName = fn) + assertEquals(s1, s2, "saved string different from loaded") + IO.appendString("!\n", fileName = fn ) + val s3 = IO.loadString(fileName = fn) + assertEquals(s3, s2 + "!\n", "saved string is missing appended '!+newline'") + IO.appendLines(Seq("line2"),fileName = fn) + val s4 = IO.loadLines(fileName = fn) + assertEquals(s4, Vector("hello!", "line2"), s"loadLines not as expected: $s4") + val s5 = IO.loadString(fileName = fn) + assertEquals(s5, "hello!\nline2\n", s"loadLines not as expected: $s5") + IO.appendLines(Seq(),fileName = fn) // nothing should be added, not even newline + assertEquals(s5, IO.loadString(fileName = fn), s"loadLines not as expected: $s5") + } +} \ No newline at end of file From 391350cfe9a7f66ed1102b3745af44ae73d557bb Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Tue, 11 Jun 2024 18:53:22 +0200 Subject: [PATCH 24/39] use sbt test in github actions --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7e0488f..3a1a008 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,5 +7,5 @@ jobs: - name: Check out repository code uses: actions/checkout@v2 - name: SBT Build - run: sbt compile + run: sbt test shell: bash From 4601bd194e6b4e3cae2d303e9e14a2be54baf0ee Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Tue, 11 Jun 2024 19:08:11 +0200 Subject: [PATCH 25/39] split tests --- src/test/scala/testIO.scala | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/test/scala/testIO.scala b/src/test/scala/testIO.scala index 77e03ac..a5d3e44 100644 --- a/src/test/scala/testIO.scala +++ b/src/test/scala/testIO.scala @@ -1,11 +1,16 @@ package introprog val tmpDir = "target/tmp" +def createTmp(): Boolean = IO.createDirIfNotExist(tmpDir) -class TestIO extends munit.FunSuite { - test("TestIO: createDirIfNotExist, saveString, appendString, loadLines, appendLines") { - val existed = IO.createDirIfNotExist(tmpDir) +class TestIO extends munit.FunSuite: + + test("TestIO: createDirIfNotExist"): + val existed = createTmp() assert(IO.isExisting(tmpDir), s"dir should exists: $tmpDir") + + test("TestIO: saveString, loadString, appendString, loadLines, appendLines"): + createTmp() val s1 = "hello" val fn = s"$tmpDir/hello.txt" IO.saveString(s1, fileName = fn) @@ -21,5 +26,3 @@ class TestIO extends munit.FunSuite { assertEquals(s5, "hello!\nline2\n", s"loadLines not as expected: $s5") IO.appendLines(Seq(),fileName = fn) // nothing should be added, not even newline assertEquals(s5, IO.loadString(fileName = fn), s"loadLines not as expected: $s5") - } -} \ No newline at end of file From c41fc54d3ee2bc39fddab291e2336ef5f4cd7332 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Tue, 11 Jun 2024 19:33:50 +0200 Subject: [PATCH 26/39] add info on doc view with localhost --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 1b2ddc1..9d11fab 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,17 @@ With [`sbt`](https://www.scala-sbt.org/download.html) and [`git`](https://git-sc > sbt package ``` +## How to build and see the doc pages using a local server + +Run this in linux bash terminal: +``` +sbt doc && cd target/scala-3.3.3/api && python3 -m http.server 8080 +``` +Open Firefox and type this url in the address field: +``` +http://localhost:8080/ +``` + ## Intentions and philosophy behind introprog-scalalib This repo includes utilities to empower learners to advance from basic to intermediate levels of computer science by providing easy-to-use constructs for creating simple desktop apps in terminal and using simple 2D graphics. The utilities are implemented and exposed through an api that follows these guidelines: From c02ec38a0e57cf3871f6e9e57cf066d911ea2579 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Tue, 11 Jun 2024 19:35:01 +0200 Subject: [PATCH 27/39] fix bad backtick in doc comment --- src/main/scala/introprog/Image.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/introprog/Image.scala b/src/main/scala/introprog/Image.scala index 5c5ad9d..d9b5339 100644 --- a/src/main/scala/introprog/Image.scala +++ b/src/main/scala/introprog/Image.scala @@ -32,7 +32,7 @@ class Image (val underlying: java.awt.image.BufferedImage): this - /** Extract and return image pixels.*/ + /** Extract and return image pixels. */ def toMatrix: Array[Array[Color]] = val xs: Array[Array[Color]] = Array.ofDim(width, height) for x <- 0 until width; y <- 0 until height do From 2b33e630a68b83a86541480fdf94f8d5095b299d Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Tue, 11 Jun 2024 19:35:45 +0200 Subject: [PATCH 28/39] fix vertical space --- src/main/scala/introprog/Image.scala | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/scala/introprog/Image.scala b/src/main/scala/introprog/Image.scala index d9b5339..553acfc 100644 --- a/src/main/scala/introprog/Image.scala +++ b/src/main/scala/introprog/Image.scala @@ -8,11 +8,9 @@ object Image: Image(BufferedImage(width, height, BufferedImage.TYPE_INT_RGB)) - class Image (val underlying: java.awt.image.BufferedImage): import java.awt.Color import java.awt.image.BufferedImage - /** Get color of pixel at `(x, y)`.*/ def apply(x: Int, y: Int): Color = Color(underlying.getRGB(x, y)) @@ -31,7 +29,6 @@ class Image (val underlying: java.awt.image.BufferedImage): update(x, y, f(x, y)) this - /** Extract and return image pixels. */ def toMatrix: Array[Array[Color]] = val xs: Array[Array[Color]] = Array.ofDim(width, height) @@ -63,8 +60,9 @@ class Image (val underlying: java.awt.image.BufferedImage): bi.createGraphics().drawImage(underlying, 0, 0, width, height, null) Image(bi) - val hasAlpha = underlying.getColorModel.hasAlpha + val height = underlying.getHeight + val width = underlying.getWidth \ No newline at end of file From 9419136498e8cb10c0ecf8be4d9a84e0b58e938c Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Tue, 11 Jun 2024 19:41:37 +0200 Subject: [PATCH 29/39] improve doc comments on Image --- src/main/scala/introprog/Image.scala | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/scala/introprog/Image.scala b/src/main/scala/introprog/Image.scala index 553acfc..47295c9 100644 --- a/src/main/scala/introprog/Image.scala +++ b/src/main/scala/introprog/Image.scala @@ -1,13 +1,13 @@ package introprog - +/** Companion object to create Image instances */ object Image: import java.awt.image.BufferedImage /** Create new empty Image with specified dimensions `(width, height)`*/ def ofDim(width: Int, height: Int) = Image(BufferedImage(width, height, BufferedImage.TYPE_INT_RGB)) - +/** Image represents pixel arrays backed by underlying java.awtimage.BufferedImage */ class Image (val underlying: java.awt.image.BufferedImage): import java.awt.Color import java.awt.image.BufferedImage @@ -59,10 +59,13 @@ class Image (val underlying: java.awt.image.BufferedImage): val bi = BufferedImage(width, height, imageType) bi.createGraphics().drawImage(underlying, 0, 0, width, height, null) Image(bi) - + + /** Test if alpha channel is supperted. */ val hasAlpha = underlying.getColorModel.hasAlpha + /** The height of this image. */ val height = underlying.getHeight + /** The width of this image. */ val width = underlying.getWidth \ No newline at end of file From 98bbb180a2ba30947d97a5f3ec820ca98958cd53 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Tue, 11 Jun 2024 19:42:34 +0200 Subject: [PATCH 30/39] add trailing period --- src/main/scala/introprog/Image.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/scala/introprog/Image.scala b/src/main/scala/introprog/Image.scala index 47295c9..669de8d 100644 --- a/src/main/scala/introprog/Image.scala +++ b/src/main/scala/introprog/Image.scala @@ -1,6 +1,6 @@ package introprog -/** Companion object to create Image instances */ +/** Companion object to create Image instances. */ object Image: import java.awt.image.BufferedImage /** Create new empty Image with specified dimensions `(width, height)`*/ @@ -23,7 +23,7 @@ class Image (val underlying: java.awt.image.BufferedImage): for x <- 0 until width; y <- 0 until height do update(x, y, f(x, y)) - /** Set color of pixels by passing `f(x, y)` and return self*/ + /** Set color of pixels by passing `f(x, y)` and return self. */ def updated(f: (Int, Int) => Color): Image = for x <- 0 until width; y <- 0 until height do update(x, y, f(x, y)) From b7c3b0c0e5a1fcb8b502951aac9f74a08c73895b Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Tue, 11 Jun 2024 20:04:11 +0200 Subject: [PATCH 31/39] add MovingBlock example --- .../introprog/examples/TestBlockGame.scala | 63 ++++++++++++++++++- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/src/main/scala/introprog/examples/TestBlockGame.scala b/src/main/scala/introprog/examples/TestBlockGame.scala index 018a3c3..8700120 100644 --- a/src/main/scala/introprog/examples/TestBlockGame.scala +++ b/src/main/scala/introprog/examples/TestBlockGame.scala @@ -1,12 +1,17 @@ package introprog.examples -/** Example of a simple BlockGame app with overridden callbacks to handle events +/** Examples of a simple BlockGame app with overridden callbacks to handle events * See the documentation of BlockGame and the source code of TestBlockGame * for inspiration on how to inherit BlockGame to create your own block game. */ object TestBlockGame: /** Create Game and start playing. */ - def main(args: Array[String]): Unit = (new RandomBlocks).play() + def main(args: Array[String]): Unit = + println("Press Enter to toggle random blocks. Close window to continue.") + (new RandomBlocks).play() + println("Opening MovingBlock. Press Ctrl+C to exit.") + (new MovingBlock).start() + println("MovingBlock has ended.") /** A class extending `introprog.BlockGame`, see source code. */ class RandomBlocks extends introprog.BlockGame: @@ -61,3 +66,57 @@ object TestBlockGame: showEnterMessage() gameLoop(stopWhen = state == GameOver) println("Goodbye!") + + end RandomBlocks + + class MovingBlock extends introprog.BlockGame( + title = "MovingBlock", + dim = (10,5), + blockSize = 40, + background = java.awt.Color.BLACK, + framesPerSecond = 50, + messageAreaHeight = 1, + messageAreaBackground = java.awt.Color.DARK_GRAY + ): + + var movesPerSecond: Double = 2 + + def millisBetweenMoves: Int = (1000 / movesPerSecond).round.toInt max 1 + + var _timestampLastMove: Long = System.currentTimeMillis + + def timestampLastMove = _timestampLastMove + + var x = 0 + var y = 0 + + def move(): Unit = + if x == dim._1 - 1 then + x = -1 + y += 1 + end if + x = x+1 + + def erase(): Unit = drawBlock(x, y, java.awt.Color.BLACK) + + def draw(): Unit = drawBlock(x, y, java.awt.Color.CYAN) + + def update(): Unit = + if System.currentTimeMillis > _timestampLastMove + millisBetweenMoves then + move() + _timestampLastMove = System.currentTimeMillis() + + var loopCounter: Int = 0 + + override def gameLoopAction(): Unit = + erase() + update() + draw() + clearMessageArea() + drawTextInMessageArea(s"Loop number: $loopCounter", 1, 0, java.awt.Color.PINK, size = 30) + loopCounter += 1 + + final def start(): Unit = + pixelWindow.show() // möjliggör omstart även om fönstret stängts... + gameLoop(stopWhen = x == dim._1 - 1 && y == dim._2 - 1) + end MovingBlock From 43f11299149f320e7dc6b5664bd5e97351a64f61 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Tue, 11 Jun 2024 20:06:57 +0200 Subject: [PATCH 32/39] minor tweaks to MovingBlock example --- src/main/scala/introprog/examples/TestBlockGame.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/scala/introprog/examples/TestBlockGame.scala b/src/main/scala/introprog/examples/TestBlockGame.scala index 8700120..5f7d810 100644 --- a/src/main/scala/introprog/examples/TestBlockGame.scala +++ b/src/main/scala/introprog/examples/TestBlockGame.scala @@ -88,6 +88,7 @@ object TestBlockGame: def timestampLastMove = _timestampLastMove var x = 0 + var y = 0 def move(): Unit = @@ -117,6 +118,7 @@ object TestBlockGame: loopCounter += 1 final def start(): Unit = - pixelWindow.show() // möjliggör omstart även om fönstret stängts... + pixelWindow.show() // show window again if closed and start() is called again gameLoop(stopWhen = x == dim._1 - 1 && y == dim._2 - 1) + end MovingBlock From 74a56caf0677390b1baa8f27b96962979db997b0 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Tue, 11 Jun 2024 20:23:03 +0200 Subject: [PATCH 33/39] improve docs of BlockGame, fix Documentattion for gameloop is missing #41 --- src/main/scala/introprog/BlockGame.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/scala/introprog/BlockGame.scala b/src/main/scala/introprog/BlockGame.scala index 9b443f8..ed91703 100644 --- a/src/main/scala/introprog/BlockGame.scala +++ b/src/main/scala/introprog/BlockGame.scala @@ -2,7 +2,9 @@ package introprog import java.awt.Color -/** A class for creating games with block-based graphics. +/** A class for creating games with block-based graphics. + * See example usage in [`introprog.examples.TestBlockGame`](https://github.com/lunduniversity/introprog-scalalib/blob/master/src/main/scala/introprog/examples/TestBlockGame.scala#L7). + * * @constructor Create a new game. * @param title the title of the window * @param dim the (width, height) of the window in number of blocks @@ -84,6 +86,8 @@ abstract class BlockGame( /** The game loop that continues while not `stopWhen` is true. * It draws only updated blocks aiming at the desired frame rate. * It calls each `onXXX` method if a corresponding event is detected. + * Use the call-by-name `stopWhen` to pass a condition that ends the loop if false. + * See example usage in `introprog.examples.TestBlockGame`. */ protected def gameLoop(stopWhen: => Boolean): Unit = while !stopWhen do import PixelWindow.Event From 90f8048c8d796859ca0f6c2a1bf1b1c418364b85 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Tue, 11 Jun 2024 20:25:35 +0200 Subject: [PATCH 34/39] fix add to docs explanation of negative y-axis in coordinates #10 --- src/main/scala/introprog/PixelWindow.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/introprog/PixelWindow.scala b/src/main/scala/introprog/PixelWindow.scala index 9693fc7..939ec06 100644 --- a/src/main/scala/introprog/PixelWindow.scala +++ b/src/main/scala/introprog/PixelWindow.scala @@ -96,7 +96,7 @@ object PixelWindow: case _ => throw new IllegalArgumentException(s"Unknown event number: $event") -/** A window with a canvas for pixel-based drawing. +/** A window with a canvas for pixel-based drawing. Y-coordinates are increasing downwards. * * @constructor Create a new window for pixel-based drawing. * @param width the number of horizontal pixels From 5dd070019272c2aba47311ca4c5ad833821cc12c Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Tue, 11 Jun 2024 20:37:16 +0200 Subject: [PATCH 35/39] fix link --- src/main/scala/introprog/BlockGame.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/introprog/BlockGame.scala b/src/main/scala/introprog/BlockGame.scala index ed91703..2222d9a 100644 --- a/src/main/scala/introprog/BlockGame.scala +++ b/src/main/scala/introprog/BlockGame.scala @@ -3,7 +3,7 @@ package introprog import java.awt.Color /** A class for creating games with block-based graphics. - * See example usage in [`introprog.examples.TestBlockGame`](https://github.com/lunduniversity/introprog-scalalib/blob/master/src/main/scala/introprog/examples/TestBlockGame.scala#L7). + * See example usage in [introprog.examples.TestBlockGame](https://github.com/lunduniversity/introprog-scalalib/blob/master/src/main/scala/introprog/examples/TestBlockGame.scala#L7) * * @constructor Create a new game. * @param title the title of the window From b82fc584978bdacf9fd1858efd77581f3e04bb0e Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Thu, 20 Jun 2024 17:35:01 +0200 Subject: [PATCH 36/39] update readme --- docs/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index 803e843..65ea9cb 100644 --- a/docs/index.md +++ b/docs/index.md @@ -30,7 +30,7 @@ Add these magic comment lines starting with `//>` in the beginning of your Scala //> using scala 3 //> using lib "se.lth.cs::introprog:1.4.0" ``` -You can choose a specific Scala 3 version of at least 3.3.3, for example: `3.4.2` +You can choose the latest stable Scala version, or any version from at least 3.3.3 LTS, which this library is compiled against. You run your code with `scala-cli run .` (note the ending dot, meaning "this dir") @@ -55,7 +55,7 @@ See: [api documentation for PixelWindow](https://fileadmin.cs.lth.se/pgk/api/api If you have [sbt](https://www.scala-sbt.org/) installed then you can put this text in a file called `build.sbt` ``` -scalaVersion := "3.3.3" // or any newer released Scala version +scalaVersion := "3.4.2" // or any Scala version from at least 3.3.3 libraryDependencies += "se.lth.cs" %% "introprog" % "1.4.0" ``` From 73d5f5cf055a11c5e75dbf824c827b1d5265f1f2 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Thu, 20 Jun 2024 17:38:04 +0200 Subject: [PATCH 37/39] update index.md --- docs/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index 65ea9cb..0494378 100644 --- a/docs/index.md +++ b/docs/index.md @@ -30,7 +30,7 @@ Add these magic comment lines starting with `//>` in the beginning of your Scala //> using scala 3 //> using lib "se.lth.cs::introprog:1.4.0" ``` -You can choose the latest stable Scala version, or any version from at least 3.3.3 LTS, which this library is compiled against. +You can choose the latest stable Scala version, or any version from at least Scala 3.3.3. You run your code with `scala-cli run .` (note the ending dot, meaning "this dir") @@ -40,7 +40,7 @@ If your program looks like this: //> using scala 3 //> using lib "se.lth.cs::introprog:1.4.0" -@main def run = +@main def MyMain = val w = introprog.PixelWindow() w.drawText("Hello introprog.PixelWindow!", x = 100, y = 100) ``` From 8d4d0a66adac730ef53b9b096dd389ab7cac8ef2 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Thu, 20 Jun 2024 17:40:07 +0200 Subject: [PATCH 38/39] update publish instructions --- PUBLISH.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PUBLISH.md b/PUBLISH.md index c59bd71..5fe1270 100644 --- a/PUBLISH.md +++ b/PUBLISH.md @@ -68,7 +68,7 @@ openpgp-revocs.d pubring.asc trustdb.gpg ## How to publish -1. Build and test locally. +1. Build and test locally using `sbt "compile;test;doc"` 2. Bump `lazy val Version` in `build.sbt`, run `package` in sbt. Note no plus before package as from 1.2.0 we only publish for Scala 3. We also want a release on github and the course home page aligned with the release on Sonatype Central. Therefore You should also: - Don't forget to update the `doc/index.md` file with current version information and package contents etc. Read more on scaladoc here: https://docs.scala-lang.org/scala3/scaladoc.html From 0afe773c5703ea7f8198e1e9ce70d60d16b6cfc4 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Thu, 20 Jun 2024 21:04:29 +0200 Subject: [PATCH 39/39] update build to fix publish --- PUBLISH.md | 41 +++++++++++++++++++++++++++++++++++++++-- build.sbt | 6 ++++-- docs/index.md | 6 +++--- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/PUBLISH.md b/PUBLISH.md index 5fe1270..88da291 100644 --- a/PUBLISH.md +++ b/PUBLISH.md @@ -92,7 +92,43 @@ openpgp-revocs.d pubring.asc trustdb.gpg 4. In `sbt>` run `publishSigned` - a plus sign is not used since we only publish for Scala 3 from 1.2.0. -5. Log into Sonatype Nexus here: (if the page does not load, clear the browser's cache by pressing Ctrl+F5) https://oss.sonatype.org/#welcome +Note: It is falsely said to be `sbt publish` according to https://www.scala-sbt.org/1.x/docs/Publishing.html but you need to use `sbt publishSigned` +after creating a .credentials file in ~/.sbt including below where xxx and yyy is replaced with secret values that is access according to https://central.sonatype.org/publish/generate-token/ If you do just `publish` you will get an error later in the process after closing below that complains that .asc files are missing etc. + +Put .credentials in ~/.sbt +``` +realm=Sonatype Nexus Repository Manager +host=oss.sonatype.org +user=xxx +password=yyy +``` + +When I did publishSIgend last time I got these errors but the publishing went through anyway with the above .credentials in ~/.sbt: +``` +sbt:introprog> publishSigned +[info] Wrote /home/bjornr/git/hub/lunduniversity/introprog-scalalib/target/scala-3.3.3/introprog_3-1.4.0.pom +[warn] multiple main classes detected: run 'show discoveredMainClasses' to see the list +[error] gpg: Warning: not using 'E7232FE8B8357EEC786315FE821738D92B63C95F' as default key: No secret key +[error] gpg: all values passed to '--default-key' ignored +[error] gpg: Warning: not using 'E7232FE8B8357EEC786315FE821738D92B63C95F' as default key: No secret key +[error] gpg: all values passed to '--default-key' ignored +[error] gpg: Warning: not using 'E7232FE8B8357EEC786315FE821738D92B63C95F' as default key: No secret key +[error] gpg: all values passed to '--default-key' ignored +[error] gpg: Warning: not using 'E7232FE8B8357EEC786315FE821738D92B63C95F' as default key: No secret key +[error] gpg: all values passed to '--default-key' ignored +[info] published introprog_3 to https://oss.sonatype.org/service/local/staging/deploy/maven2/se/lth/cs/introprog_3/1.4.0/introprog_3-1.4.0.pom.asc +[info] published introprog_3 to https://oss.sonatype.org/service/local/staging/deploy/maven2/se/lth/cs/introprog_3/1.4.0/introprog_3-1.4.0-javadoc.jar +[info] published introprog_3 to https://oss.sonatype.org/service/local/staging/deploy/maven2/se/lth/cs/introprog_3/1.4.0/introprog_3-1.4.0.pom +[info] published introprog_3 to https://oss.sonatype.org/service/local/staging/deploy/maven2/se/lth/cs/introprog_3/1.4.0/introprog_3-1.4.0.jar.asc +[info] published introprog_3 to https://oss.sonatype.org/service/local/staging/deploy/maven2/se/lth/cs/introprog_3/1.4.0/introprog_3-1.4.0.jar +[info] published introprog_3 to https://oss.sonatype.org/service/local/staging/deploy/maven2/se/lth/cs/introprog_3/1.4.0/introprog_3-1.4.0-javadoc.jar.asc +[info] published introprog_3 to https://oss.sonatype.org/service/local/staging/deploy/maven2/se/lth/cs/introprog_3/1.4.0/introprog_3-1.4.0-sources.jar +[info] published introprog_3 to https://oss.sonatype.org/service/local/staging/deploy/maven2/se/lth/cs/introprog_3/1.4.0/introprog_3-1.4.0-sources.jar.asc +``` + +OOOPS! TODO: I already had this file: `cat ~/.sbt/sonatype_credential` pulled in by `cat ~/.sbt/1.0/sonatype.sbt` so I should remove the last of them as Credentials is now included in the build.sbt + +5. After you have done `sbt publishSigned` then log into Sonatype Nexus here: (if the page does not load, clear the browser's cache by pressing Ctrl+F5) https://oss.sonatype.org/#welcome 6. Click on *Staging Repositories* in the Build Promotion list to the left. Click "Refresh" if list is empty. https://oss.sonatype.org/#stagingRepositories @@ -100,7 +136,7 @@ openpgp-revocs.d pubring.asc trustdb.gpg 8. Download the staged jar by clicking on it and selecting the *Artifact* tab to the right and click the Repository Path to download. Save it e.g. in `tmp`. -9. Verify that the staged jar downloaded from sonatype works by running `scala -cp introprog_3-x.y.z.jar` and in REPL e.g. `val w = new introprog.PixelWindow`. The reason for this step is that there has been incidents where the uploading has failed and the jar was empty. A published jar can not be retracted even if corrupted according to Sonatype policies. +9. Verify that the staged jar downloaded from sonatype works by running something similar to `scala-cli repl . -S 3.4.2 --jar introprog_3-1.4.0.jar` and in REPL e.g. `val w = new introprog.PixelWindow` or `introprog.examples.TestPixelWindow.main(Array())`. The reason for this step is that there has been incidents where the uploading has failed and the jar was empty. A published jar can not be retracted even if corrupted according to Sonatype policies. 10. Click the *Close* icon with a diskette above the repository list to "close" the staging repository. No need to write anything in the "Description" field in the popup. It has happened that the Close failed - then the repo is still "Open" so try to close it again and hope it works this time... @@ -109,3 +145,4 @@ openpgp-revocs.d pubring.asc trustdb.gpg 12. By searching here you can see the repo in progress of being published but it takes a while before it is publicly visible on Central (typically 10-15 minutes). https://oss.sonatype.org/#nexus-search;quick~se.lth.cs 13. When visible on Central at https://repo1.maven.org/maven2/se/lth/cs/introprog_3/ verify with a simple sbt project that it works as shown in [README usage instructions for sbt](https://github.com/lunduniversity/introprog-scalalib/blob/master/README.md#using-sbt). + diff --git a/build.sbt b/build.sbt index 03e5cd8..c6aae06 100644 --- a/build.sbt +++ b/build.sbt @@ -95,10 +95,12 @@ publishConfiguration := publishConfiguration.value.withOverwrite(true) publishLocalConfiguration := publishLocalConfiguration.value.withOverwrite(true) //pushRemoteCacheConfiguration := pushRemoteCacheConfiguration.value.withOverwrite(true) +credentials += Credentials(Path.userHome / ".sbt" / ".credentials") + //https://oss.sonatype.org/#stagingRepositories //https://oss.sonatype.org/#nexus-search;quick~se.lth.cs //https://repo1.maven.org/maven2/se/lth/cs/introprog_2.12/ -//usePgpKeyHex("E7232FE8B8357EEC786315FE821738D92B63C95F") -//https://github.com/sbt/sbt-pgp \ No newline at end of file +//https://github.com/sbt/sbt-pgp + diff --git a/docs/index.md b/docs/index.md index 0494378..f42c663 100644 --- a/docs/index.md +++ b/docs/index.md @@ -28,7 +28,7 @@ Add these magic comment lines starting with `//>` in the beginning of your Scala ``` //> using scala 3 -//> using lib "se.lth.cs::introprog:1.4.0" +//> using dep "se.lth.cs::introprog:1.4.0" ``` You can choose the latest stable Scala version, or any version from at least Scala 3.3.3. @@ -38,7 +38,7 @@ If your program looks like this: ``` //> using scala 3 -//> using lib "se.lth.cs::introprog:1.4.0" +//> using dep "se.lth.cs::introprog:1.4.0" @main def MyMain = val w = introprog.PixelWindow() @@ -52,7 +52,7 @@ See: [api documentation for PixelWindow](https://fileadmin.cs.lth.se/pgk/api/api ### Using sbt -If you have [sbt](https://www.scala-sbt.org/) installed then you can put this text in a file called `build.sbt` +If you have [sbt](https://www.scala-sbt.org/) installed at least version 1.10.0 then you can put this text in a file called `build.sbt` ``` scalaVersion := "3.4.2" // or any Scala version from at least 3.3.3