Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit ae2030b

Browse files
authored
Move to cmt 2 (#82)
* Move to CMT 2.0 * The exercise on compiler code rewrite should contain the rewritten code - Code is rewritten to indentation based syntax and new control structure syntax * Add build definitions to remaining exercises * Fix pattern match issue in exercise on multiversal equality * Add CMT 2 configuration file * Update exercise instructions for the initial state exercise * Update exercise on compiler code rewriting for Scala 2 migrations * Update instructions for the exercise on syntax rewriting * Minor update to initial state exercise instructions * Update build - Remove unused definition/bump Akka version - Remove unused value definition in build definition - Bump Akka version - Change vals to lazy * Fix build * Update exercise instructions * Adapt modified syntax for wildcard imports * The exercise on deprecated syntax rewriting contains the result * Shorten exercise titles * Change CI in view of switch to CMT 2 * Remove redundant CMT 1 files - As the project is moved to a CMT 2 project structure, the CMT 1 specific stuff can be removed * Update versions of Github actions * Update CI - Github actions 'set-output' is deprecated * Revert change to CI * Use integrated caching in actions/setup-java@v3 * Add compiler option "-source:future-migration" from second exercise onward * Update exercise instructions Exercises on: - parameter tupling - extension methods * Update build status check * Update exercise instructions for contextual abstractions exercise - Update to `using`/`summon` * Update exercise instructions for contextual abstractions exercise II - Use `given` where appropriate * Update enum exercise instructions * Update instructions for exercise on Union types * Fix remaining warning in test for some exercises * Remove implicit conversion import as it isn't needed - From some unclear reason, there are a couple of instances of `scala.language.implicitConversions` in both main and test code that are completely unnecessary. Removed them from the Scala 2 code (first exercise - Initial State) * Remove implicit conversion import as it isn't needed - For some unclear reason, there are a couple of instances of `scala.language.implicitConversions` in both main and test code that are completely unnecessary. Removed them from the Scala 3 code (second exercise onwards) * Update formatting of code * Apply () instead of the deprecated auto-application to () * Update logback configuration
1 parent f43ad52 commit ae2030b

File tree

166 files changed

+1379
-1303
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+1379
-1303
lines changed

.github/workflows/ci.yml

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,51 +7,48 @@ on:
77
pull_request:
88
branches: [ main ]
99

10+
env:
11+
EXERCISES_DIRECTORY: ./exercises
12+
1013
jobs:
14+
list-exercises:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
exercises: ${{steps.list.outputs.exercises}}
18+
steps:
19+
- uses: actions/checkout@v3
20+
- id: list
21+
run: echo "::set-output name=exercises::$(ls $EXERCISES_DIRECTORY | grep exercise_ | jq -cnR '[inputs | select(length>0)]')"
22+
# run: echo "name=exercises::$(ls $EXERCISES_DIRECTORY | grep exercise_ | jq -cnR '[inputs | select(length>0)]')" >> $GITHUB_OUTPUT
23+
1124
validate_course:
1225
runs-on: ubuntu-latest
26+
needs: list-exercises
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
exercise: ${{fromJson(needs.list-exercises.outputs.exercises)}}
31+
steps:
32+
- uses: actions/checkout@v3
33+
- name: Set up JDK 11
34+
uses: actions/setup-java@v3
35+
with:
36+
java-version: 11
37+
cache: 'sbt'
38+
distribution: 'temurin'
1339

40+
- name: Test with sbt
41+
run: sbt test
42+
working-directory: ${{env.EXERCISES_DIRECTORY}}/${{matrix.exercise}}
43+
validate_course_summary:
44+
if: ${{ always() }}
45+
runs-on: ubuntu-latest
46+
needs: validate_course
1447
steps:
48+
- name: Check build matrix status
49+
if: ${{ needs.validate_course.result != 'success' }}
50+
run: exit 1
1551

16-
- name: Checkout Course Repo
17-
uses: actions/checkout@v2
18-
with:
19-
path: course-repo
20-
# fetch-depth: 0 indicates all history. (CMT requires them)
21-
fetch-depth: 0
22-
23-
- name: Setup Course Management Tools
24-
uses: robinraju/release-downloader@v1.1
25-
with:
26-
repository: eloots/course-management-tools
27-
tag: "1.0.0"
28-
fileName: "course-management-tools.zip"
29-
out-file-path: "."
30-
- run: |
31-
unzip course-management-tools.zip
32-
echo "$GITHUB_WORKSPACE/course-management-tools/bin" >> $GITHUB_PATH
33-
34-
- name: Set up JDK 11
35-
uses: actions/setup-java@v1
36-
with:
37-
java-version: 11
38-
39-
- name: Setup Coursier Cache
40-
uses: coursier/cache-action@v6.2
41-
with:
42-
root: "course-repo"
43-
44-
- name: Generate Tests Script using CMT
45-
run: |
46-
git config --global user.email "no-reply@lunatech.com"
47-
git config --global user.name "Lunatech Labs"
48-
cmt-mainadm -dot -t runTests.sh $GITHUB_WORKSPACE/course-repo
49-
50-
- name: Run Tests
51-
run: |
52-
chmod +x runTests.sh
53-
./runTests.sh
54-
5552
create_release:
5653
runs-on: ubuntu-latest
5754
needs: [validate_course]
@@ -61,7 +58,7 @@ jobs:
6158
steps:
6259

6360
- name: Checkout Course Repo
64-
uses: actions/checkout@v2
61+
uses: actions/checkout@v3
6562
with:
6663
path: lunatech-scala-2-to-scala3-course
6764
fetch-depth: 0
@@ -78,9 +75,10 @@ jobs:
7875
echo "$GITHUB_WORKSPACE/course-management-tools/bin" >> $GITHUB_PATH
7976
8077
- name: Set up JDK 11
81-
uses: actions/setup-java@v1
78+
uses: actions/setup-java@v3
8279
with:
8380
java-version: 11
81+
distribution: 'temurin'
8482

8583
- name: Setup Coursier Cache
8684
uses: coursier/cache-action@v6.2

README.md

Lines changed: 95 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,112 @@
11
# Moving Forward from Scala 2 to Scala 3
22

3-
![Scala Course CI](https://github.com/lunatech-labs/lunatech-scala-2-to-scala3-course/workflows/Scala%20Course%20CI/badge.svg)
4-
53
## Description
64

7-
The target audience for this course is the Scala _Application_ Developer Community.
8-
In other words, the focus is on people who use the language to develop 'end-user'
9-
applications and not necessarily those developers who design and write libraries,
10-
toolkits or frameworks (although they may benefit from what is in this course if
11-
they haven't already worked with Dotty).
5+
The target audience for this course is the Scala _Application_ Developer Community. In other words, the focus is on people who use the language to develop 'end-user' applications and not necessarily those developers who design and write libraries, toolkits or frameworks (although they may benefit from what is in this course if they haven't already worked with Scala 3).
126

13-
The goal of the course is to explore the new features in the Scala language brought
14-
by [the Dotty project](https://dotty.epfl.ch). Even though it is still early days
15-
and the first release candidate of the Scala 3 language is probably not out for
16-
another 6 months, it is our believe that one can never start too early to learn
17-
Dotty for the following reasons:
7+
The goal of the course is to explore the new features in the Scala language brought by [the Scala 3 project](https://dotty.epfl.ch). Even though it is still early days and the first release candidate of the Scala 3 language is probably not out for another 6 months, it is our believe that one can never start too early to learn Scala 3 for the following reasons:
188

199
- There is a lot to learn, so if you wait until everything is ready, you risk having to play catchup.
20-
- There are many opportunities to contribute to the Dotty project, which will accelerate its development in the coming months. Using Dotty will provide opportunities to identity issues to be fixed sooner rather than later.
10+
- There are many opportunities to contribute to the Scala 3 project, which will accelerate its development in the coming months. Using Scala 3 will provide opportunities to identity issues to be fixed sooner rather than later.
11+
12+
## Approach
13+
14+
We start from an existing Scala 2 application: an [[Akka](https://akka.io)] actor based Sudoku solver. We start from the application as-is, but with an sbt build definition that uses the Scala 3 compiler.
15+
16+
Through a series of exercises, we look at specific Scala 3 features and apply these to the Scala 2 code, thereby transforming it step-by-step into a version that exploits a whole series of nice features offered by the new language.
17+
18+
Note that this is work in progress, so keep watching this space!
19+
20+
## Usage
21+
22+
This repository is structured in such a way that it can be transformed into two different artifacts for specific use cases:
23+
24+
- A _studentified_ repository: this is a standalone sbt project which is typically used for teaching or learning purposes. A user of this repository will be working on one exercise at any one point in time and will be able to use a number of custom [sbt] commands:
25+
- `man`: print a manual page for the global project
26+
- `man e`: print a manual page for the current exercise. In general, this page will contain some background information on the exercise and a series of specific instructions, hints or tips for the current exercise
27+
- `listExercises`: will print a list of all available exercises
28+
- `nextExercise`: move to the next exercise and pull in the tests (if any) for that exercise. This command preserves the current state of the application leaving any code added or changed by the student unmodified.
29+
- `prevExercise`: the opposite of the `nextExercise` command
30+
- `pullSolution`: pulls in the reference solution code for the current exercise. This command is handy in a class room setting where at some point in time, the instructor wants to move to the next exercise and the student hasn't completed the current exercise. Note that it will overwrite any code written by the student
31+
- `gotoExercise <exerciseID>`: jump to an exercise specified by the exerciseID. Note that this command support TAB completion for the exerciseID. Also, remember that this will pull in tests for the exercise and probably you'll want to pull in the solution by running the `pullSolution` command.
32+
- `saveState`: can be executed prior to executing the `pullSolution` command: it will save the current state of an exercise so that it can be restored later.
33+
- `savedStates`: show the exercise ids of all exercises for which a state was saved
34+
- `restoreState <exerciseID>`: restore a previously save state
35+
- A _linearized_ repository: this is a git repository in which every exercise in the master repository is turned into a commit:
36+
- Used to edit the master repository: In general this is a scratch pad repository that is discarded once it has served its purpose. In this use case, interactive rebasing on the linearized repo is used to transform the code across a range of exercises. Once this rebasing is finished, all applied changes can be applied on the master repo by a process of `delinearization`
37+
- **There is a second use case for a linearized repo: it can can be used to inspect the differences between consecutive exercises (using a tools such as `SourceTree` or `GitKraken`)**
38+
39+
_Studentification_, _linearization_, and _delinearization_ as well as some administrative tasks (such as renumbering exercises), is done using the so-called [Course Management Tools](https://github.com/lightbend/course-management-tools).
40+
41+
In the following sections, we'll explain `studentify`, `linearize` and `delinearize` commands.
42+
43+
### How to _"studentify"_ a master repository
44+
45+
1. Create a folder in which the _studentified_ version will be
46+
- Clone the [Course Management Tools (CMT)](https://github.com/lightbend/course-management-tools)
47+
- Start an `sbt` session in the cloned CMT repo
48+
- From the `sbt` prompt, run the _studentify_ command with the `-dot` option and provide two arguments:
49+
- The first one is the _absolute_ path to the root folder of the master repository of the exercises
50+
- The second one is the _absolute_ path of the folder in which the studentified version will be created
51+
- Once the _studentify_ command is finished, you can _cd_ into the studentified versions root folder and start an _sbt_ session. You will now be able to use all the student commands listed in the previous section.
52+
53+
Assuming that:
54+
55+
- The root folder of the cloned course master repo is located at the following [absolute] path: `/home/userx/src/lunatech-scala-2-to-scala3-course`
56+
- The folder that will hold the _studentified_ version has the following [absolute] path: `/home/userx/stu`
57+
58+
`studentify` should be invoked as follows:
59+
60+
```
61+
studentify -dot /home/userx/src/lunatech-scala-2-to-scala3-course /home/userx/stu
62+
```
63+
64+
### How to _"linearize"_/_"delinearize"_ a master repository
65+
66+
In the context of the _"Moving from Scala 2 to Scala 3"_ course, _linearize_ allows one to view the changes between the different exercises. In other words, this feature allows one to see exactly what needs to be done to _"solve"_ the exercise. So, if you want to actually learn something, don't use this feature — instead, give the exercises a try first...
67+
68+
In a broader context, _"linearize"_/_"delinearize"_ is an important tool to evolve/change the master repository of this course.
69+
70+
The following picture shows the typical process to evolve code in a master repository with the utilisation of a _linearized_ repository:
2171

22-
## The exercises master repository
72+
![Linearization/Delinearization](images/Lin-Delin.png)
2373

24-
This repository, located in the `exercises` subfolder, contains all exercises in a multi-project _sbt_ build. In order to run exercises directly from this repo, _cd_ into this folder and run _sbt_. Alternatively, import the build.sbt file in your favourite development environment (Metals with a client of your choice or IntelliJ).
74+
Follow the following steps:
2575

26-
## The snippets repository
76+
1. Choose a folder in which the _linearized_ version will be created
77+
- Clone the [Course Management Tools (CMT)](https://github.com/lightbend/course-management-tools)
78+
- Start an `sbt` session in the cloned CMT repo
79+
- Run the _linearize_ command and provide two arguments:
80+
- The first one is the _absolute_ path to the root folder of the master repository of the exercises
81+
- The second one is the absolute path of the folder in which the _linearized_ version will be created (see 1.)
82+
- Once the _linearize_ command is finished, _cd_ into the _linearized_ version's root folder and start refactoring your code using interactive rebasing (e.g. `git rebase -i --root`).
83+
- To apply all changes made in the _linearized_ repo to the master repository, execute the `delinearize` command supplying two arguments:
84+
- The first one is the _absolute_ path to the root folder of the master repository of the exercises
85+
- The second one is the absolute path of the `linearized` project folder
86+
- Repeat the _interactive rebasing_ / _delinearization_ sequence as many times as you want
2787

28-
This repository, located in the `code-snippets` folder contains small examples, built mainly for demo purposes (and for inclusion in course slides).
88+
Assuming that:
2989

30-
## Course Artifacts
90+
- The root folder of the cloned course master repo is located at the following [absolute] path: `/home/userx/src/lunatech-scala-2-to-scala3-course`
91+
- The folder that will hold the _linearized_ version has the following [absolute] path: `/home/userx/lin`
3192

32-
Various artifacts are generated for this course:
93+
`linearize` should be invoked as follows:
3394

34-
- The exercises in _studentified_ format: this is the format that is tuned for learning purposes.
35-
- The exercises in _linearized_ format: useful to study the changes between consecutive exercises.
36-
- The course slide deck in PDF format.
95+
```
96+
linearize -dot /home/userx/src/lunatech-scala-2-to-scala3-course /home/userx/stu
97+
```
3798

38-
If you want to have a concise overview on how to utilize the _studentified_ and the _linearized_ artifacts, there's a video on this topic what you can find [here](https://youtu.be/2zmXTGG7Nkg).
99+
With the same assumptions, _delinearizing_ the linearized repo is done with the following command:
39100

40-
You can find these artifacts in [the releases](https://github.com/lunatech-labs/lunatech-scala-2-to-scala3-course/releases) of this project.
101+
```
102+
delinearize /home/userx/src/lunatech-scala-2-to-scala3-course /home/userx/stu/lunatech-scala-2-to-scala3-course
103+
```
104+
Note two changes on this command compared to the `linearize` one: the `-dot` option is not present and the second argument is changed.
41105

42-
> Note: We recently renamed the default branch to `main`. If you already have a clone/fork of this repo, please follow the instructions in the [0.24.0-v2 release notes](https://github.com/lunatech-labs/lunatech-scala-2-to-scala3-course/releases/tag/0.24.0-v2)
106+
> NOTES
107+
>
108+
> - During the process of interactive rebasing, make sure NOT to change the commit message (which in fact is the exercise's project name) or to squash commits as this will make it impossible to _delinearize_ the project.
109+
> - Editing code directly in the _master repo_ and editing code via _linearize_/_delinearize_ are mutually exclusive processes. In practice, this means that when you've been using `linearize`/`delinearize` and you decide to make a change directly to files in the exercises in the master repository, you should discard the `linearized` artifact.
110+
> - Project `common` is aggregated in all exercises. As such, it is the same across _all_ exercises. Also, the _Linearization_/_Delinearization_ process will not transfer changes made in the _linearized_ repository
111+
> - `studentify` and `linearize` mandate that your master repository has no files in your git _index_ or _workspace_, so, commit any work before using these commands. Don't worry about commiting stuff temporarily. Either stash any pending changes or commit them and possibly squash them later.
112+
> Finally: reflect carefully about the best editing approach. In many cases, direct edits in the master repository may be simpler to apply than going through an interactive rebasing session.

course-management.conf

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1-
studentify {
2-
3-
relative-source-folder = exercises
1+
cmt {
2+
# Folder in the main git repository holding the exercises
3+
main-repo-exercise-folder = exercises
44

5-
main-base-project-name = scala-2-to-scala-3-main
6-
studentified-project-name = scala-2-to-scala-3
5+
# Folder in studentified repo holding the current exercise code
6+
studentified-repo-active-exercise-folder = code
77

8-
use-configure-for-projects = true
8+
# List of folders containing test code
9+
test-code-folders = [
10+
"src/test"
11+
]
912

10-
readme-in-test-resources = false
13+
# List of README files
14+
read-me-files = [
15+
"README.md"
16+
]
17+
18+
# List of files or folders to leave untouched in the studentified
19+
# repo.
20+
cmt-studentified-dont-touch = [
21+
.idea
22+
.bsp
23+
.bloop
24+
.vscode
25+
target
26+
]
1127
}

0 commit comments

Comments
 (0)