diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml deleted file mode 100644 index ca090418..00000000 --- a/.github/workflows/gradle.yml +++ /dev/null @@ -1,80 +0,0 @@ -# The Workflow's name -name: Java CI with Gradle - -# The workflow should run when pushing -on: - push: - branches: [ "prod", "dev", "stage" ] - pull_request: - branches: [ "prod", "dev", "stage" ] - -defaults: - run: - working-directory: ./assignments/exercise-3 - -jobs: - build: - runs-on: ["self-hosted"] - - steps: - - uses: actions/checkout@v4 - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: '17' - distribution: 'temurin' - - - name: Make gradlew executable - run: chmod +x gradlew - - - name: Build with Gradle Wrapper - run: ./gradlew build - - - name: Upload artifacts - uses: actions/upload-artifact@v4 - with: - name: build-artifact - path: . - - - verify: - runs-on: ["self-hosted"] - needs: build - steps: - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: '17' - distribution: 'temurin' - - name: Download build artifact - uses: actions/download-artifact@v4 - with: - name: build-artifact - - name: Run test with Gradle Wrapper - run: ./gradlew test - - name: Run checkstyle with Gradle Wrapper - run: ./gradlew checkstyleMain - - name: Upload artifacts - uses: actions/upload-artifact@v4 - with: - name: verify-artifact - path: . - - publish: - runs-on: ["self-hosted"] - needs: verify - steps: - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: '17' - distribution: 'temurin' - - name: Download build artifact - uses: actions/download-artifact@v4 - with: - name: verify-artifact - - name: Publish library - env: - ORG_GRADLE_PROJECT_dockerRepoUsername: ${{ secrets.REPO_USERNAME }} - ORG_GRADLE_PROJECT_dockerRepoPassword: ${{ secrets.REPO_PASSWORD }} - run: ./gradlew publish diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml deleted file mode 100644 index 89cd6512..00000000 --- a/.github/workflows/python-app.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Python application - -on: - push: - branches: [ "main" ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - name: Set up Python 3.10 - uses: actions/setup-python@v3 - with: - python-version: "3.10" - - name: Run python program - run: | - python assignments/exercise-2/main.py diff --git a/.github/workflows/social-media-integration.yml b/.github/workflows/social-media-integration.yml deleted file mode 100644 index b6d43b59..00000000 --- a/.github/workflows/social-media-integration.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Post Tweet on Push - -on: push - -jobs: - tweet: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Post a tweet on push - uses: julb/action-post-twitter-status@v1 - with: - message: "🚀 Code has been pushed to the repository!" - twitter_app_consumer_api_key: ${{ secrets.TWITTER_API_KEY }} - twitter_app_consumer_api_secret_key: ${{ secrets.TWITTER_API_SECRET_KEY }} - twitter_app_access_token: ${{ secrets.TWITTER_ACCESS_TOKEN }} - twitter_app_access_token_secret: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} diff --git a/.gitignore b/.gitignore deleted file mode 100644 index ae85a76a..00000000 --- a/.gitignore +++ /dev/null @@ -1,61 +0,0 @@ -.DS_Store -build - -.idea -*.iws -*.iml -*.ipr -out/ -!**/src/main/**/out/ -!**/src/test/**/out/ - -demo/mqtt-server/moquette-0.17.0-RC1/.editorconfig -demo/mqtt-server/moquette-0.17.0-RC1/.github/ISSUE_TEMPLATE.md -/demo/mqtt-server/moquette-0.17.0-RC1/.github -/demo/mqtt-server/moquette-0.17.0-RC1/.mvn -demo/mqtt-server/moquette-0.17.0-RC1/about.html -/demo/mqtt-server/moquette-0.17.0-RC1/tools_scripts/benchmark -/demo/mqtt-server/moquette-0.17.0-RC1/tools_scripts -*.jks -demo/mqtt-server/moquette-0.17.0-RC1/broker/src/test/resources/config/password_file.conf -demo/mqtt-server/moquette-0.17.0-RC1/broker/src/test/resources/password_file.conf -demo/mqtt-server/moquette-0.17.0-RC1/ChangeLog.txt -demo/mqtt-server/moquette-0.17.0-RC1/distribution/src/main/resources/password_file.conf -demo/mqtt-server/pulsar-connector/paho1213520249300-tcplocalhost1883/.lck -demo/mqtt-server/pulsar-connector/paho1076680416600-tcplocalhost1883/.lck - -# Created by https://www.toptal.com/developers/gitignore/api/gradle -# Edit at https://www.toptal.com/developers/gitignore?templates=gradle - -### Gradle ### -.gradle -**/build/ -!src/**/build/ - -# Ignore Gradle GUI config -gradle-app.setting - -# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) -!gradle-wrapper.jar - -# Avoid ignore Gradle wrappper properties -!gradle-wrapper.properties - -# Cache of project -.gradletasknamecache - -# Eclipse Gradle plugin generated files -# Eclipse Core -.project -# JDT-specific (Eclipse Java Development Tools) -.classpath - -### Gradle Patch ### -# Java heap dump -*.hprof - -# End of https://www.toptal.com/developers/gitignore/api/gradle - - -# Exclude powerpoint working directory -~*.pptx \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b81..00000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/esd-2024-github-actions.iml b/.idea/esd-2024-github-actions.iml deleted file mode 100644 index d6ebd480..00000000 --- a/.idea/esd-2024-github-actions.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 4444b225..00000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 715425c8..00000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1ddf..00000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 00000000..e69de29b diff --git a/Example demo/.gitignore b/Example demo/.gitignore deleted file mode 100644 index d4e09b58..00000000 --- a/Example demo/.gitignore +++ /dev/null @@ -1,149 +0,0 @@ -### Java -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* -replay_pid* - -### Global/JetBrains -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/**/usage.statistics.xml -.idea/**/dictionaries -.idea/**/shelf - -# AWS User-specific -.idea/**/aws.xml - -# Generated files -.idea/**/contentModel.xml - -# Sensitive or high-churn files -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml -.idea/**/dbnavigator.xml - -# Gradle -.idea/**/gradle.xml -.idea/**/libraries - -# Gradle and Maven with auto-import -# When using Gradle or Maven with auto-import, you should exclude module files, -# since they will be recreated, and may cause churn. Uncomment if using -# auto-import. -# .idea/artifacts -# .idea/compiler.xml -# .idea/jarRepositories.xml -# .idea/modules.xml -# .idea/*.iml -# .idea/modules -# *.iml -# *.ipr - -# CMake -cmake-build-*/ - -# Mongo Explorer plugin -.idea/**/mongoSettings.xml - -# File-based project format -*.iws - -# IntelliJ -out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Cursive Clojure plugin -.idea/replstate.xml - -# SonarLint plugin -.idea/sonarlint/ - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties - -# Editor-based Rest Client -.idea/httpRequests - -# Android studio 3.1+ serialized cache file -.idea/caches/build_file_checksums.ser - -### Global/VisualStudioCode -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json -!.vscode/*.code-snippets - -# Local History for Visual Studio Code -.history/ - -# Built Visual Studio Code Extensions -*.vsix - -### Global/macOS -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### Custom rules -target diff --git a/Example demo/.idea/.gitignore b/Example demo/.idea/.gitignore deleted file mode 100644 index 13566b81..00000000 --- a/Example demo/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/Example demo/.idea/alda-2024-simpletime-Stoyan12314.iml b/Example demo/.idea/alda-2024-simpletime-Stoyan12314.iml deleted file mode 100644 index d6ebd480..00000000 --- a/Example demo/.idea/alda-2024-simpletime-Stoyan12314.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/Example demo/.idea/compiler.xml b/Example demo/.idea/compiler.xml deleted file mode 100644 index 0063c42d..00000000 --- a/Example demo/.idea/compiler.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/Example demo/.idea/encodings.xml b/Example demo/.idea/encodings.xml deleted file mode 100644 index c5f5f7d2..00000000 --- a/Example demo/.idea/encodings.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/Example demo/.idea/jarRepositories.xml b/Example demo/.idea/jarRepositories.xml deleted file mode 100644 index 712ab9d9..00000000 --- a/Example demo/.idea/jarRepositories.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/Example demo/.idea/misc.xml b/Example demo/.idea/misc.xml deleted file mode 100644 index 48b7d7c0..00000000 --- a/Example demo/.idea/misc.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/Example demo/.idea/modules.xml b/Example demo/.idea/modules.xml deleted file mode 100644 index 3ae2c77a..00000000 --- a/Example demo/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/Example demo/.idea/vcs.xml b/Example demo/.idea/vcs.xml deleted file mode 100644 index 35eb1ddf..00000000 --- a/Example demo/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Example demo/README.adoc b/Example demo/README.adoc deleted file mode 100644 index 6ce7e7cc..00000000 --- a/Example demo/README.adoc +++ /dev/null @@ -1,49 +0,0 @@ -ifdef::env-github[] -:imagesdir: images/ -endif::[] -:imagesdir: images - -== Simple Time - -The exercise for the first week is an appetizer before we start with the real work, "the dinner". Goal of the assignment -is to get familiar with our way of working using an external API by describing the requirements and a Factory class, as part of -your implementation, that creates instances of the classes that implement the API. - -The API is published in the Maven central repository: -https://central.sonatype.com/artifact/io.github.fontysvenlo.alda/simpletime_api/2.5 - -The JavaDoc is published on https://fontysvenlo.github.io/alda_simpletime_api/v2.5/simpletimeapi/module-summary.html - -The main exercise for the first seven weeks will be about an appointment planning tool to schedule appointments. As you can imagine, -Time and Duration play an important role in such an application. Dealing with dates and times is always a bit awkward. Even in Java, -it took a long time (since Java8) before a decent Date and Time API (`java.time`) was available. It's an extensive API that needs some studying -for proper use. - -Normally you shouldn't reinvent the wheel, but this week we do by developing our own simple and stupid `Time` and `Duration` classes. -We purposely do not use the `java.time` API. You'll be provided with a Maven project that contains a reference to the API (simpletimeapi) and a Service -Finder facility already. In your test classes, you can invoke the static `getFactory()` method of the `ServiceFinder` (see test package) class to get an -`AbstractSimpleTimeFactory` object that in turn can create `Time` and `Duration` objects. -See the class diagram below. - -.Class diagram for the classes Time and Duration. -image::simpletimecd.svg[] - - -== Tasks - -Read the JavaDoc published on: -https://fontysvenlo.github.io/alda_simpletime_api/v2.5/simpletimeapi/module-summary.html - -Open the provided project in your IDE. You'll probably need to build the project first, in order to download Maven dependencies. - -Based on this api, Test-Driven develop your implementations of the types: - -. SimpleTimeFactory - -. Time - -. Duration - -Make sure that the test coverage is 100 percent, using the already available *JacoCoverage* plugin (as it was available in PRC2). Write only code that is needed for your tests to succeed. That way you will keep your code coverage at 100% automatically. - -Our teacher tests are just a final check. First try to fully test and implement the required functionality. Commit on a regular base, but only push your solution to Github at the moment you think you completely solved the assignment. Your task is not finished as long as there are red tests in either YOUR or OUR test runs and as long as the coverage of YOUR tests on YOUR code is on the required (CodeGrade) level. diff --git a/Example demo/assignment/pom.xml b/Example demo/assignment/pom.xml deleted file mode 100644 index 2007633e..00000000 --- a/Example demo/assignment/pom.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - 4.0.0 - - io.github.fontysvenlo - informaticspom - 1.3 - - - io.github.fontysvenlo.alda - simpletimeimpl - 1.0-SNAPSHOT - jar - Simpletime Assignment - - - UTF-8 - - --add-opens simpletimeimpl/simpletime=ALL-UNNAMED - --add-opens simpletimeimpl/simpletimeimpl=ALL-UNNAMED - --add-opens java.base/java.lang=ALL-UNNAMED - - - true - - - - - io.github.fontysvenlo.alda - simpletime_api - 2.5 - - - - - - - - - org.jacoco - jacoco-maven-plugin - 0.8.12 - - - - - - prepare-agent - - - - - report - prepare-package - - report - - - - - - - diff --git a/Example demo/assignment/src/main/java/module-info.java b/Example demo/assignment/src/main/java/module-info.java deleted file mode 100644 index 59e4cb96..00000000 --- a/Example demo/assignment/src/main/java/module-info.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * ALDA Assignment SimpleTime Implementation. - */ -module simpletimeimpl { - requires simpletimeapi; - uses simpletimeapi.AbstractSimpleTimeFactory; - provides simpletimeapi.AbstractSimpleTimeFactory with simpletime.SimpleTimeFactory; -} diff --git a/Example demo/assignment/src/main/java/simpletime/SimpleTimeFactory.java b/Example demo/assignment/src/main/java/simpletime/SimpleTimeFactory.java deleted file mode 100644 index 351876db..00000000 --- a/Example demo/assignment/src/main/java/simpletime/SimpleTimeFactory.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2023 Informatics Fontys FHTenL University of Applied Science Venlo - */ -package simpletime; - -import simpletimeapi.Duration; -import simpletimeapi.Time; -import simpletimeapi.AbstractSimpleTimeFactory; -import simpletimeimpl.DurationImpl; // Import the concrete implementation for Duration -import simpletimeimpl.TimeImpl; // Import the concrete implementation for Time - -/** - * This class implements the AbstractSimpleTimeFactory interface, providing factory methods to - * create instances of the Time and Duration implementations. These instances will be - * black-box tested by the teacher's tests. - * - * Authors: - * Richard van den Ham {@code r.vandenham@fontys.nl} - * Pieter van den Hombergh {@code p.vandenhombergh@fontys.nl} - */ -public class SimpleTimeFactory implements AbstractSimpleTimeFactory { - - /** - * Public constructor required for service loader to instantiate this factory class. - * This constructor doesn't require any arguments and is responsible for initializing the factory. - */ - public SimpleTimeFactory() { - } - - /** - * Factory method that creates a Time object. - * The method takes the number of hours and minutes as parameters and returns a new instance - * of the TimeImpl class. The TimeImpl class will ensure the hours and minutes are normalized. - * - * @param hours - The number of hours (can be negative or greater than 24 but will be normalized). - * @param minutes - The number of minutes (can be negative or exceed 60 but will be normalized). - * @return a new TimeImpl instance representing the normalized time. - */ - @Override - public Time createTime(int hours, int minutes) { - // Return a new instance of TimeImpl with the given hours and minutes - return new TimeImpl(hours, minutes); - } - - /** - * Factory method that creates a Duration object. - * This method takes the number of hours and minutes as parameters and returns an instance - * of the DurationImpl class. It calculates the total duration using the provided hours and minutes. - * - * @param hours - The number of hours in the duration. - * @param minutes - The number of minutes in the duration. - * @return a new DurationImpl instance representing the total duration. - */ - @Override - public Duration createDuration(int hours, int minutes) { - // Return a new instance of DurationImpl with the given hours and minutes - return new DurationImpl(hours, minutes); - } - - /** - * Factory method that creates a Duration object based on the total number of minutes. - * The method takes the total length in minutes and converts it into hours and minutes - * to create an instance of the DurationImpl class. - * - * @param lengthInMinutes - The total duration in minutes. - * @return a new DurationImpl instance representing the duration with hours and minutes calculated. - */ - @Override - public Duration createDuration(int lengthInMinutes) { - // Return a new instance of DurationImpl with the total minutes provided - return new DurationImpl(lengthInMinutes); - } -} diff --git a/Example demo/assignment/src/main/java/simpletimeimpl/DurationImpl.java b/Example demo/assignment/src/main/java/simpletimeimpl/DurationImpl.java deleted file mode 100644 index 30d2a13f..00000000 --- a/Example demo/assignment/src/main/java/simpletimeimpl/DurationImpl.java +++ /dev/null @@ -1,141 +0,0 @@ -package simpletimeimpl; - -import simpletimeapi.Duration; - -/** - * This class implements the {@link Duration} interface and provides - * methods for working with time durations in hours and minutes. - */ -public class DurationImpl implements Duration { - // The 'hours' and 'minutes' fields are final, meaning they are immutable once assigned. - // These fields store the duration in hours and minutes. - private final int hours; - private final int minutes; - - /** - * Constructor that takes the total number of minutes as an input and splits it into hours and minutes. - * 'totalMinutes' represents the complete duration in minutes, which is then divided to get hours and minutes. - * - * @param totalMinutes the total duration in minutes - */ - public DurationImpl(int totalMinutes) { - // Normalize total minutes into hours and minutes - this.hours = totalMinutes / 60; - this.minutes = totalMinutes % 60; - } - - /** - * Constructor that directly takes hours and minutes. - * This constructor is used when you already have hours and minutes separately. - * It normalizes excessive minutes (i.e., converts them to hours). - * - * @param hours the number of hours - * @param minutes the number of minutes - */ - public DurationImpl(int hours, int minutes) { - // Normalize excessive minutes into hours - int totalMinutes = hours * 60 + minutes; - this.hours = totalMinutes / 60; - this.minutes = totalMinutes % 60; - } - - /** - * Method to return the total duration in minutes. - * This converts the stored hours and minutes into the equivalent total minutes. - * - * @return the total duration in minutes - */ - @Override - public int asMinutes() { - return hours * 60 + minutes; // Convert hours to minutes and add the stored minutes. - } - - /** - * Getter method to retrieve the hours component of the duration. - * - * @return the number of hours - */ - @Override - public int getHours() { - return hours; - } - - /** - * Getter method to retrieve the minutes component of the duration. - * - * @return the number of minutes - */ - @Override - public int getMinutes() { - return minutes; - } - - /** - * Method to add another {@link Duration} object to this Duration. - * Takes another Duration as input, converts both Durations into minutes, adds them together, - * and returns a new {@link DurationImpl} object representing the result. - * - * @param other the other Duration to be added - * @return a new DurationImpl object representing the combined duration - */ - @Override - public Duration plus(Duration other) { - // Add the total minutes of both durations. - int totalMinutes = this.asMinutes() + other.asMinutes(); - // Return a new DurationImpl with the total minutes calculated. - return new DurationImpl(totalMinutes); - } - - /** - * Method that returns a string representation of the Duration object. - * Returns the total duration as a string in the format: "X minutes". - * - * @return a string representation of the duration - */ - @Override - public String toString() { - return asMinutes() + " minutes"; // Convert the total minutes to a string. - } - - /** - * Override the equals method to check if two Duration objects are equal. - * Two Duration objects are considered equal if they represent the same number of total minutes. - * - * @param other the object to compare to - * @return true if the two durations are equal, false otherwise - */ - @Override - public boolean equals(Object other) { - // Check if the current object is compared to itself. - if (this == other) return true; - // Check if the other object is an instance of the Duration interface. - if (!(other instanceof Duration)) return false; - // Convert the other object to a Duration and compare the total minutes. - Duration that = (Duration) other; - return this.asMinutes() == that.asMinutes(); - } - - /** - * Override the hashCode method to ensure consistent behavior with equals. - * Returns the hash code based on the total minutes of the duration. - * - * @return the hash code for this duration - */ - @Override - public int hashCode() { - return Integer.hashCode(asMinutes()); // Generate a hash code based on total minutes. - } - - /** - * Implement the compareTo method from the Comparable interface. - * Compares this Duration object with another Duration based on their total minutes. - * - * @param other the other Duration to compare to - * @return a negative integer, zero, or a positive integer if this duration is less than, equal to, or greater than the other - */ - @Override - public int compareTo(Duration other) { - // Compare the two durations based on their total minutes. - return Integer.compare(this.asMinutes(), other.asMinutes()); - } -} diff --git a/Example demo/assignment/src/main/java/simpletimeimpl/TimeImpl.java b/Example demo/assignment/src/main/java/simpletimeimpl/TimeImpl.java deleted file mode 100644 index 89faa4f8..00000000 --- a/Example demo/assignment/src/main/java/simpletimeimpl/TimeImpl.java +++ /dev/null @@ -1,180 +0,0 @@ -package simpletimeimpl; - -import simpletimeapi.Duration; -import simpletimeapi.Time; -/** - * This class implements the {@link Time} interface and provides - * methods for working with time values in hours and minutes. - */ -public class TimeImpl implements Time { - // The 'hours' and 'minutes' fields are final, meaning once they are set, they cannot be changed. - // These fields store the normalized hours and minutes of a given time. - private final int hours; - private final int minutes; - - /** - * Constructor to create a TimeImpl object. It takes hours and minutes as input and normalizes them - * into the valid range [0, 24) for hours and [0, 60) for minutes. - * - * @param hours the number of hours - * @param minutes the number of minutes - * @throws IllegalArgumentException if the time is outside the valid range of 0 to 23:59 - */ - public TimeImpl(int hours, int minutes) { - // Convert the given hours and minutes into total minutes for easier manipulation. - int totalMinutes = hours * 60 + minutes; - - // Total number of minutes in a day (24 hours * 60 minutes = 1440 minutes). - int minutesInADay = 24 * 60; - - // Check if the total minutes are outside the valid range of a day. - // If the totalMinutes is less than 0 or greater than or equal to 1440, - // throw an IllegalArgumentException indicating invalid time. - if (totalMinutes < 0 || totalMinutes >= minutesInADay) { - throw new IllegalArgumentException("Time must be within 0 to 23:59"); - } - - // Normalize the time into valid hours and minutes. - // Divide totalMinutes by 60 to get the normalized hours. - this.hours = totalMinutes / 60; - // Use modulus to get the remaining minutes after dividing by 60. - this.minutes = totalMinutes % 60; - } - - /** - * Getter method to retrieve the hours of the time object. - * - * @return the number of hours - */ - @Override - public int getHours() { - return hours; - } - - /** - * Getter method to retrieve the minutes of the time object. - * - * @return the number of minutes - */ - @Override - public int getMinutes() { - return minutes; - } - - /** - * Method to add a number of minutes to the current Time object. - * Returns a new TimeImpl object with the result. - * - * @param minutesToAdd the number of minutes to add - * @return a new TimeImpl object with the updated time - */ - @Override - public Time addTime(int minutesToAdd) { - // Calculate total minutes after adding minutesToAdd to the current time. - int totalMinutes = this.asMinutes() + minutesToAdd; - - // Total minutes in a day (1440 minutes). - int minutesInADay = 24 * 60; - - // Normalize the total minutes to ensure it wraps around correctly in a 24-hour format. - // This ensures that the time is always valid, even if minutesToAdd is positive or negative. - totalMinutes = ((totalMinutes % minutesInADay) + minutesInADay) % minutesInADay; - - // Create and return a new TimeImpl object with the normalized hours and minutes. - return new TimeImpl(totalMinutes / 60, totalMinutes % 60); - } - - /** - * Overloaded method to add another {@link Time} object to the current time. - * - * @param t the other Time object to add - * @return a new TimeImpl object with the combined time - */ - @Override - public Time addTime(Time t) { - // Use the addTime method by converting the Time object 't' to minutes. - return addTime(t.asMinutes()); - } - - /** - * Helper method to return the total number of minutes since midnight. - * - * @return the total minutes from 00:00 to the current time - */ - @Override - public int asMinutes() { - return hours * 60 + minutes; // Convert hours to minutes and add the current minutes. - } - - /** - * Calculate the time difference (in minutes) between this time and another Time object. - * Returns a Duration object representing the time difference. - * - * @param other the other Time object - * @return a {@link Duration} object representing the difference - */ - @Override - public Duration until(Time other) { - // Calculate the difference in minutes between the two times. - int diff = other.asMinutes() - this.asMinutes(); - - // If the difference is negative, assume the other time is on the next day, - // so add 1440 minutes (24 hours * 60 minutes) to the difference. - if (diff < 0) { - diff += 24 * 60; - } - - // Return a new DurationImpl object with the calculated difference in minutes. - return new DurationImpl(diff); - } - - /** - * Override the equals method to check if two Time objects are equal. - * Two Time objects are considered equal if they represent the same number of minutes. - * - * @param other the object to compare to - * @return true if the two times are equal, false otherwise - */ - @Override - public boolean equals(Object other) { - // Check if the current object is compared to itself. - if (this == other) return true; - // Check if the other object is an instance of the Time interface. - if (!(other instanceof Time)) return false; - // Convert the other object to a Time object and compare the total minutes. - Time that = (Time) other; - return this.asMinutes() == that.asMinutes(); - } - - /** - * Override the hashCode method to generate a hash based on the total minutes. - * This ensures consistency between the equals and hashCode methods. - * - * @return the hash code for this time - */ - @Override - public int hashCode() { - return Integer.hashCode(asMinutes()); - } - - /** - * Override the toString method to return a string representation of the time in "HH:MM" format. - * - * @return a string representing the time in "HH:MM" format - */ @Override - public String toString() { - return String.format("%02d:%02d", hours, minutes); // Format hours and minutes with leading zeros. - } - - /** - * Implement the compareTo method from the Comparable interface. - * This allows Time objects to be compared based on their total minutes. - * - * @param other the other Time object to compare to - * @return a negative integer, zero, or a positive integer if this time is less than, equal to, or greater than the other - */ - @Override - public int compareTo(Time other) { - return Integer.compare(this.asMinutes(), other.asMinutes()); // Compare times based on total minutes. - } -} diff --git a/Example demo/assignment/src/test/java/simpletime/ServiceFinder.java b/Example demo/assignment/src/test/java/simpletime/ServiceFinder.java deleted file mode 100644 index 27297029..00000000 --- a/Example demo/assignment/src/test/java/simpletime/ServiceFinder.java +++ /dev/null @@ -1,24 +0,0 @@ -package simpletime; - -import java.util.ServiceLoader; -import java.util.Optional; -import static org.assertj.core.api.Assumptions.assumeThat; -import simpletimeapi.AbstractSimpleTimeFactory; - -/** - * - * @author Pieter van den Hombergh {@code p.vandenhombergh@fontys.nl} - */ -public class ServiceFinder { - - /** - * Try to find the factory provided by this module. - * - * @return an AbstractSimpleTimeFactory implementing object - */ - public static AbstractSimpleTimeFactory getFactory() { - Optional findFirst = ServiceLoader.load(AbstractSimpleTimeFactory.class ).findFirst(); - assumeThat( findFirst ).as("Factory service not found").isNotEmpty(); - return findFirst.get(); - } -} diff --git a/Example demo/assignment/src/test/java/simpletime/SimpleTimeFactoryTest.java b/Example demo/assignment/src/test/java/simpletime/SimpleTimeFactoryTest.java deleted file mode 100644 index e392a512..00000000 --- a/Example demo/assignment/src/test/java/simpletime/SimpleTimeFactoryTest.java +++ /dev/null @@ -1,188 +0,0 @@ -package simpletime; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import simpletimeapi.Duration; -import simpletimeapi.Time; -import simpletimeimpl.DurationImpl; -import simpletimeimpl.TimeImpl; - -import static org.junit.jupiter.api.Assertions.*; - -class SimpleTimeFactoryTest { - - private SimpleTimeFactory factory; - - @BeforeEach - void setUp() { - factory = new SimpleTimeFactory(); - } - - // Tests for createTime method - - @Test - void testCreateTimeWithValidTimeReturnsNonNull() { - // Act - Time time = factory.createTime(10, 30); - - // Assert - assertNotNull(time, "Expected a non-null Time object"); - } - - @Test - void testCreateTimeWithValidTimeReturnsCorrectInstance() { - // Act - Time time = factory.createTime(10, 30); - - // Assert - assertTrue(time instanceof TimeImpl, "Expected Time object to be an instance of TimeImpl"); - } - - @Test - void testCreateTimeReturnsCorrectHours() { - // Act - Time time = factory.createTime(10, 30); - - // Assert - assertEquals(10, time.getHours(), "Expected hours to be 10"); - } - - @Test - void testCreateTimeReturnsCorrectMinutes() { - // Act - Time time = factory.createTime(10, 30); - - // Assert - assertEquals(30, time.getMinutes(), "Expected minutes to be 30"); - } - - @Test - void testCreateTimeWithExcessiveMinutesReturnsCorrectHours() { - // Act - Time time = factory.createTime(10, 90); // 90 minutes = 1 hour and 30 minutes - - // Assert - assertEquals(11, time.getHours(), "Expected hours to be 11 after normalizing 90 minutes"); - } - - @Test - void testCreateTimeWithExcessiveMinutesReturnsCorrectMinutes() { - // Act - Time time = factory.createTime(10, 90); // 90 minutes = 1 hour and 30 minutes - - // Assert - assertEquals(30, time.getMinutes(), "Expected minutes to be 30 after normalizing 90 minutes"); - } - - @Test - void testCreateTimeWithNegativeMinutesReturnsCorrectHours() { - // Act - Time time = factory.createTime(10, -30); // Negative minutes should wrap around - - // Assert - assertEquals(9, time.getHours(), "Expected hours to be 9 after wrapping negative minutes"); - } - - @Test - void testCreateTimeWithNegativeMinutesReturnsCorrectMinutes() { - // Act - Time time = factory.createTime(10, -30); // Negative minutes should wrap around - - // Assert - assertEquals(30, time.getMinutes(), "Expected minutes to be 30 after wrapping negative minutes"); - } - - // Tests for createDuration with hours and minutes - - @Test - void testCreateDurationWithValidValuesReturnsNonNull() { - // Act - Duration duration = factory.createDuration(2, 45); - - // Assert - assertNotNull(duration, "Expected a non-null Duration object"); - } - - @Test - void testCreateDurationWithValidValuesReturnsCorrectInstance() { - // Act - Duration duration = factory.createDuration(2, 45); - - // Assert - assertTrue(duration instanceof DurationImpl, "Expected Duration object to be an instance of DurationImpl"); - } - - @Test - void testCreateDurationReturnsCorrectHours() { - // Act - Duration duration = factory.createDuration(2, 45); - - // Assert - assertEquals(2, duration.getHours(), "Expected hours to be 2"); - } - - @Test - void testCreateDurationReturnsCorrectMinutes() { - // Act - Duration duration = factory.createDuration(2, 45); - - // Assert - assertEquals(45, duration.getMinutes(), "Expected minutes to be 45"); - } - - @Test - void testCreateDurationWithExcessiveMinutesReturnsCorrectHours() { - // Act - Duration duration = factory.createDuration(1, 120); // 120 minutes = 2 hours - - // Assert - assertEquals(3, duration.getHours(), "Expected hours to be 3 after normalizing 120 minutes"); - } - - @Test - void testCreateDurationWithExcessiveMinutesReturnsCorrectMinutes() { - // Act - Duration duration = factory.createDuration(1, 120); // 120 minutes = 2 hours - - // Assert - assertEquals(0, duration.getMinutes(), "Expected minutes to be 0 after normalizing 120 minutes"); - } - - // Tests for createDuration with total minutes - - @Test - void testCreateDurationFromTotalMinutesReturnsNonNull() { - // Act - Duration duration = factory.createDuration(185); // 185 minutes = 3 hours and 5 minutes - - // Assert - assertNotNull(duration, "Expected a non-null Duration object"); - } - - @Test - void testCreateDurationFromTotalMinutesReturnsCorrectInstance() { - // Act - Duration duration = factory.createDuration(185); // 185 minutes = 3 hours and 5 minutes - - // Assert - assertTrue(duration instanceof DurationImpl, "Expected Duration object to be an instance of DurationImpl"); - } - - @Test - void testCreateDurationFromTotalMinutesReturnsCorrectHours() { - // Act - Duration duration = factory.createDuration(185); // 185 minutes = 3 hours and 5 minutes - - // Assert - assertEquals(3, duration.getHours(), "Expected hours to be 3"); - } - - @Test - void testCreateDurationFromTotalMinutesReturnsCorrectMinutes() { - // Act - Duration duration = factory.createDuration(185); // 185 minutes = 3 hours and 5 minutes - - // Assert - assertEquals(5, duration.getMinutes(), "Expected minutes to be 5"); - } -} diff --git a/Example demo/assignment/src/test/java/simpletimeimpl/DurationImplTest.java b/Example demo/assignment/src/test/java/simpletimeimpl/DurationImplTest.java deleted file mode 100644 index fff4f895..00000000 --- a/Example demo/assignment/src/test/java/simpletimeimpl/DurationImplTest.java +++ /dev/null @@ -1,298 +0,0 @@ -package simpletimeimpl; - -import org.junit.jupiter.api.Test; -import simpletimeapi.Duration; - -import static org.junit.jupiter.api.Assertions.*; - -class DurationImplTest { - - @Test - void testConstructorWithTotalMinutesForHours() { - // Arrange - int totalMinutes = 150; // 150 minutes = 2 hours and 30 minutes - - // Act - Duration duration = new DurationImpl(totalMinutes); - - // Assert - assertEquals(2, duration.getHours(), "Expected 2 hours from 150 minutes"); - } - - @Test - void testConstructorWithTotalMinutesForMinutes() { - // Arrange - int totalMinutes = 150; // 150 minutes = 2 hours and 30 minutes - - // Act - Duration duration = new DurationImpl(totalMinutes); - - // Assert - assertEquals(30, duration.getMinutes(), "Expected 30 minutes from 150 minutes"); - } - - @Test - void testConstructorWithTotalMinutesForAsMinutes() { - // Arrange - int totalMinutes = 150; // 150 minutes = 2 hours and 30 minutes - - // Act - Duration duration = new DurationImpl(totalMinutes); - - // Assert - assertEquals(150, duration.asMinutes(), "Expected total of 150 minutes"); - } - - @Test - void testConstructorWithHoursAndMinutesForHours() { - // Arrange - int hours = 1; - int minutes = 45; // 1 hour and 45 minutes = 105 minutes - - // Act - Duration duration = new DurationImpl(hours, minutes); - - // Assert - assertEquals(1, duration.getHours(), "Expected 1 hour from input of 1 hour 45 minutes"); - } - - @Test - void testConstructorWithHoursAndMinutesForMinutes() { - // Arrange - int hours = 1; - int minutes = 45; // 1 hour and 45 minutes = 105 minutes - - // Act - Duration duration = new DurationImpl(hours, minutes); - - // Assert - assertEquals(45, duration.getMinutes(), "Expected 45 minutes from input of 1 hour 45 minutes"); - } - - @Test - void testConstructorWithHoursAndMinutesForAsMinutes() { - // Arrange - int hours = 1; - int minutes = 45; // 1 hour and 45 minutes = 105 minutes - - // Act - Duration duration = new DurationImpl(hours, minutes); - - // Assert - assertEquals(105, duration.asMinutes(), "Expected total of 105 minutes from 1 hour 45 minutes"); - } - - @Test - void testAsMinutes() { - // Arrange - int hours = 3; - int minutes = 20; // 3 hours and 20 minutes = 200 minutes - - // Act - Duration duration = new DurationImpl(hours, minutes); - - // Assert - assertEquals(200, duration.asMinutes(), "Expected 200 total minutes from 3 hours 20 minutes"); - } - - @Test - void testGetHours() { - // Arrange - int totalMinutes = 200; // 200 minutes = 3 hours and 20 minutes - - // Act - Duration duration = new DurationImpl(totalMinutes); - - // Assert - assertEquals(3, duration.getHours(), "Expected 3 hours from 200 total minutes"); - } - - @Test - void testGetMinutes() { - // Arrange - int totalMinutes = 200; // 200 minutes = 3 hours and 20 minutes - - // Act - Duration duration = new DurationImpl(totalMinutes); - - // Assert - assertEquals(20, duration.getMinutes(), "Expected 20 minutes from 200 total minutes"); - } - - @Test - void testPlusForHours() { - // Arrange - Duration duration1 = new DurationImpl(1, 30); // 1 hour 30 minutes - Duration duration2 = new DurationImpl(2, 15); // 2 hours 15 minutes - - // Act - Duration result = duration1.plus(duration2); // Should sum to 3 hours 45 minutes (225 minutes) - - // Assert - assertEquals(3, result.getHours(), "Expected 3 hours from sum of 1:30 and 2:15"); - } - - @Test - void testPlusForMinutes() { - // Arrange - Duration duration1 = new DurationImpl(1, 30); // 1 hour 30 minutes - Duration duration2 = new DurationImpl(2, 15); // 2 hours 15 minutes - - // Act - Duration result = duration1.plus(duration2); // Should sum to 3 hours 45 minutes (225 minutes) - - // Assert - assertEquals(45, result.getMinutes(), "Expected 45 minutes from sum of 1:30 and 2:15"); - } - - @Test - void testPlusForAsMinutes() { - // Arrange - Duration duration1 = new DurationImpl(1, 30); // 1 hour 30 minutes - Duration duration2 = new DurationImpl(2, 15); // 2 hours 15 minutes - - // Act - Duration result = duration1.plus(duration2); // Should sum to 3 hours 45 minutes (225 minutes) - - // Assert - assertEquals(225, result.asMinutes(), "Expected total of 225 minutes from sum of 1:30 and 2:15"); - } - - @Test - void testToString() { - // Arrange - int totalMinutes = 125; // 125 minutes - - // Act - Duration duration = new DurationImpl(totalMinutes); - - // Assert - assertEquals("125 minutes", duration.toString(), "Expected '125 minutes' as the string representation"); - } - - @Test - void testEqualsSameObject() { - // Arrange - Duration duration = new DurationImpl(1, 30); // 1 hour 30 minutes - - // Act & Assert - assertTrue(duration.equals(duration), "Expected object to be equal to itself"); - } - - @Test - void testEqualsDifferentObjectSameValues() { - // Arrange - Duration duration1 = new DurationImpl(1, 30); // 1 hour 30 minutes - Duration duration2 = new DurationImpl(1, 30); // Another instance with the same values - - // Act & Assert - assertTrue(duration1.equals(duration2), "Expected two Duration instances with the same values to be equal"); - } - - @Test - void testHashCodeForSameValues() { - // Arrange - Duration duration1 = new DurationImpl(1, 30); // 1 hour 30 minutes - Duration duration2 = new DurationImpl(1, 30); // Another instance with the same values - - // Act & Assert - assertEquals(duration1.hashCode(), duration2.hashCode(), "Expected hash codes to be the same for equal Duration objects"); - } - - @Test - void testEqualsDifferentObjectDifferentValues() { - // Arrange - Duration duration1 = new DurationImpl(1, 30); // 1 hour 30 minutes - Duration duration2 = new DurationImpl(2, 45); // 2 hours 45 minutes - - // Act & Assert - assertFalse(duration1.equals(duration2), "Expected two Duration objects with different values to not be equal"); - } - - @Test - void testEqualsWithNull() { - // Arrange - Duration duration = new DurationImpl(1, 30); // 1 hour 30 minutes - - // Act & Assert - assertFalse(duration.equals(null), "Expected a Duration to not be equal to null"); - } - - @Test - void testEqualsWithDifferentType() { - // Arrange - Duration duration = new DurationImpl(1, 30); // 1 hour 30 minutes - - // Act & Assert - assertFalse(duration.equals("1:30"), "Expected a Duration object to not equal an object of a different type"); - } - - @Test - void testHashCodeConsistency() { - // Arrange - Duration duration = new DurationImpl(1, 30); // 1 hour 30 minutes - - // Act - int hashCode1 = duration.hashCode(); - int hashCode2 = duration.hashCode(); - - // Assert - assertEquals(hashCode1, hashCode2, "Expected hash code to remain consistent across multiple invocations"); - } - - @Test - void testCompareToSameDuration() { - // Arrange - Duration duration1 = new DurationImpl(90); // 90 minutes - Duration duration2 = new DurationImpl(90); // Another instance with 90 minutes - - // Act & Assert - assertEquals(0, duration1.compareTo(duration2), "Expected comparison of two equal durations to return 0"); - } - - @Test - void testCompareToLongerDuration() { - // Arrange - Duration duration1 = new DurationImpl(1, 30); // 1 hour 30 minutes - Duration duration2 = new DurationImpl(2, 0); // 2 hours - - // Act & Assert - assertTrue(duration1.compareTo(duration2) < 0, "Expected comparison of a shorter duration to return a negative value"); - } - - @Test - void testCompareToShorterDuration() { - // Arrange - Duration duration1 = new DurationImpl(2, 30); // 2 hours 30 minutes - Duration duration2 = new DurationImpl(2, 0); // 2 hours - - // Act & Assert - assertTrue(duration1.compareTo(duration2) > 0, "Expected comparison of a longer duration to return a positive value"); - } - - @Test - void testPlusWithNegativeDurationForHours() { - // Arrange - Duration duration1 = new DurationImpl(1, 30); // 1 hour 30 minutes - Duration negativeDuration = new DurationImpl(-30); // -30 minutes - - // Act - Duration result = duration1.plus(negativeDuration); // 1 hour - - // Assert - assertEquals(1, result.getHours(), "Expected hours to be 1 after subtracting 30 minutes"); - } - @Test - void testPlusWithNegativeDurationForMinutes() { - // Arrange - Duration duration1 = new DurationImpl(1, 30); // 1 hour 30 minutes - Duration negativeDuration = new DurationImpl(-30); // -30 minutes - - // Act - Duration result = duration1.plus(negativeDuration); // 1 hour - - // Assert - assertEquals(0, result.getMinutes(), "Expected minutes to be 0 after subtracting 30 minutes"); - } - -} diff --git a/Example demo/assignment/src/test/java/simpletimeimpl/TimeImplTest.java b/Example demo/assignment/src/test/java/simpletimeimpl/TimeImplTest.java deleted file mode 100644 index df8aa116..00000000 --- a/Example demo/assignment/src/test/java/simpletimeimpl/TimeImplTest.java +++ /dev/null @@ -1,575 +0,0 @@ -package simpletimeimpl; - -import org.junit.jupiter.api.Test; -import simpletimeapi.Duration; -import simpletimeapi.Time; - -import static org.junit.jupiter.api.Assertions.*; - -class TimeImplTest { - - @Test - void testConstructorWithValidTime() { - // Arrange - int hours = 10; - int minutes = 45; - - // Act - Time time = new TimeImpl(hours, minutes); - - // Assert - assertEquals(10, time.getHours(), "Expected hours to be 10"); - assertEquals(45, time.getMinutes(), "Expected minutes to be 45"); - } - - @Test - void testConstructorWithValidBoundaryTime() { - // Arrange - int hours = 23; - int minutes = 59; - - // Act - Time time = new TimeImpl(hours, minutes); - - // Assert - assertEquals(23, time.getHours(), "Expected hours to be 23"); - assertEquals(59, time.getMinutes(), "Expected minutes to be 59"); - } - - @Test - void testConstructorWithTooManyMinutesThrowsException() { - // Arrange - int hours = 24; // Exceeds valid 23:59 - - // Act & Assert - assertThrows(IllegalArgumentException.class, () -> new TimeImpl(hours, 0), - "Expected exception when hours exceed 23"); - } - - @Test - void testConstructorWithNegativeMinutesNormalized() { - // Arrange - int hours = 10; - int minutes = -15; // -15 minutes from 10:00 should result in 9:45 - - // Act - Time time = new TimeImpl(hours, minutes); - - // Assert - assertEquals(9, time.getHours(), "Expected hours to be 9 after normalizing negative minutes"); - assertEquals(45, time.getMinutes(), "Expected minutes to be 45 after normalizing negative minutes"); - } - - - @Test - void testConstructorWithTotalMinutesOutOfBoundsThrowsException() { - // Arrange - int hours = 25; // More than 24 hours - int minutes = 120; // More than 60 minutes - - // Act & Assert - assertThrows(IllegalArgumentException.class, () -> new TimeImpl(hours, minutes), - "Expected exception when total time exceeds 24 hours"); - } - - @Test - void testAddTimeWithMinutesWrapAround() { - // Arrange - Time time = new TimeImpl(23, 30); // 11:30 PM - - // Act - Time newTime = time.addTime(120); // Add 2 hours (should wrap to 01:30 AM) - - // Assert - assertEquals(1, newTime.getHours(), "Expected hours to wrap around to 1 AM"); - assertEquals(30, newTime.getMinutes(), "Expected minutes to remain 30"); - } - - @Test - void testAddTimeWithNegativeMinutes() { - // Arrange - Time time = new TimeImpl(2, 30); // 2:30 AM - - // Act - Time newTime = time.addTime(-180); // Subtract 3 hours (should wrap to 11:30 PM) - - // Assert - assertEquals(23, newTime.getHours(), "Expected hours to wrap around to 11 PM"); - assertEquals(30, newTime.getMinutes(), "Expected minutes to remain 30"); - } - - @Test - void testAddTimeWithAnotherTimeObject() { - // Arrange - Time time1 = new TimeImpl(10, 30); // 10:30 AM - Time time2 = new TimeImpl(3, 45); // 3:45 AM - - // Act - Time result = time1.addTime(time2); // Adding 3:45 to 10:30 - - // Assert - assertEquals(14, result.getHours(), "Expected hours to be 14 (2:15 PM)"); - assertEquals(15, result.getMinutes(), "Expected minutes to be 15"); - } - - @Test - void testAsMinutes() { - // Arrange - Time time = new TimeImpl(2, 30); // 2:30 AM - - // Act - int minutes = time.asMinutes(); - - // Assert - assertEquals(150, minutes, "Expected total minutes to be 150 (2 hours 30 minutes)"); - } - - @Test - void testUntilMethodWithTimeOnNextDay() { - // Arrange - Time time1 = new TimeImpl(23, 45); // 11:45 PM - Time time2 = new TimeImpl(0, 15); // 12:15 AM the next day - - // Act - Duration duration = time1.until(time2); - - // Assert - assertEquals(30, duration.asMinutes(), "Expected duration to be 30 minutes"); - } - - @Test - void testUntilMethodWithinSameDay() { - // Arrange - Time time1 = new TimeImpl(10, 30); // 10:30 AM - Time time2 = new TimeImpl(12, 0); // 12:00 PM - - // Act - Duration duration = time1.until(time2); - - // Assert - assertEquals(90, duration.asMinutes(), "Expected duration to be 90 minutes"); - } - - @Test - void testEqualsMethodWithSameTime() { - // Arrange - Time time1 = new TimeImpl(10, 30); // 10:30 AM - Time time2 = new TimeImpl(10, 30); // 10:30 AM - - // Act & Assert - assertTrue(time1.equals(time2), "Expected both Time objects to be equal"); - } - - @Test - void testEqualsMethodWithDifferentTime() { - // Arrange - Time time1 = new TimeImpl(10, 30); // 10:30 AM - Time time2 = new TimeImpl(11, 30); // 11:30 AM - - // Act & Assert - assertFalse(time1.equals(time2), "Expected Time objects with different times to not be equal"); - } - - @Test - void testEqualsMethodWithNull() { - // Arrange - Time time = new TimeImpl(10, 30); // 10:30 AM - - // Act & Assert - assertFalse(time.equals(null), "Expected Time object to not be equal to null"); - } - - @Test - void testHashCodeConsistency() { - // Arrange - Time time = new TimeImpl(10, 30); // 10:30 AM - - // Act - int hashCode1 = time.hashCode(); - int hashCode2 = time.hashCode(); - - // Assert - assertEquals(hashCode1, hashCode2, "Expected hashCode to remain consistent across multiple calls"); - } - - @Test - void testCompareToMethodWithSameTime() { - // Arrange - Time time1 = new TimeImpl(10, 30); // 10:30 AM - Time time2 = new TimeImpl(10, 30); // 10:30 AM - - // Act & Assert - assertEquals(0, time1.compareTo(time2), "Expected compareTo to return 0 for same times"); - } - - @Test - void testCompareToMethodWithEarlierTime() { - // Arrange - Time time1 = new TimeImpl(10, 30); // 10:30 AM - Time time2 = new TimeImpl(9, 30); // 9:30 AM - - // Act & Assert - assertTrue(time1.compareTo(time2) > 0, "Expected compareTo to return a positive value when time1 is later"); - } - - @Test - void testCompareToMethodWithLaterTime() { - // Arrange - Time time1 = new TimeImpl(10, 30); // 10:30 AM - Time time2 = new TimeImpl(11, 30); // 11:30 AM - - // Act & Assert - assertTrue(time1.compareTo(time2) < 0, "Expected compareTo to return a negative value when time1 is earlier"); - } - - @Test - void testToStringMethod() { - // Arrange - Time time = new TimeImpl(10, 30); // 10:30 AM - - // Act - String result = time.toString(); - - // Assert - assertEquals("10:30", result, "Expected string representation to be '10:30'"); - } - @Test - void testAddTimeWithPositiveMinutes() { - // Arrange - Time time = new TimeImpl(10, 0); // 10:00 AM - - // Act - Time newTime = time.addTime(120); // Add 2 hours (120 minutes) - - // Assert - assertEquals(12, newTime.getHours(), "Expected hours to be 12 after adding 120 minutes"); - assertEquals(0, newTime.getMinutes(), "Expected minutes to remain 0 after adding 120 minutes"); - } - - @Test - void testAddTimeWithWrapAround() { - // Arrange - Time time = new TimeImpl(23, 0); // 11:00 PM - - // Act - Time newTime = time.addTime(120); // Add 2 hours, should wrap to 01:00 AM - - // Assert - assertEquals(1, newTime.getHours(), "Expected hours to be 1 after adding 120 minutes"); - assertEquals(0, newTime.getMinutes(), "Expected minutes to remain 0 after adding 120 minutes"); - } - - - @Test - void testConstructorWithValidTimeHours() { - // Arrange - int hours = 10; - int minutes = 45; - - // Act - Time time = new TimeImpl(hours, minutes); - - // Assert - assertEquals(10, time.getHours(), "Expected hours to be 10"); - } - - @Test - void testConstructorWithValidTimeMinutes() { - // Arrange - int hours = 10; - int minutes = 45; - - // Act - Time time = new TimeImpl(hours, minutes); - - // Assert - assertEquals(45, time.getMinutes(), "Expected minutes to be 45"); - } - - @Test - void testConstructorWithValidBoundaryTimeHours() { - // Arrange - int hours = 23; - int minutes = 59; - - // Act - Time time = new TimeImpl(hours, minutes); - - // Assert - assertEquals(23, time.getHours(), "Expected hours to be 23"); - } - - @Test - void testConstructorWithValidBoundaryTimeMinutes() { - // Arrange - int hours = 23; - int minutes = 59; - - // Act - Time time = new TimeImpl(hours, minutes); - - // Assert - assertEquals(59, time.getMinutes(), "Expected minutes to be 59"); - } - - - - @Test - void testConstructorWithNegativeMinutesNormalizedHours() { - // Arrange - int hours = 10; - int minutes = -15; // -15 minutes from 10:00 should result in 9:45 - - // Act - Time time = new TimeImpl(hours, minutes); - - // Assert - assertEquals(9, time.getHours(), "Expected hours to be 9 after normalizing negative minutes"); - } - - @Test - void testConstructorWithNegativeMinutesNormalizedMinutes() { - // Arrange - int hours = 10; - int minutes = -15; // -15 minutes from 10:00 should result in 9:45 - - // Act - Time time = new TimeImpl(hours, minutes); - - // Assert - assertEquals(45, time.getMinutes(), "Expected minutes to be 45 after normalizing negative minutes"); - } - - - - @Test - void testAddTimeWithMinutesWrapAroundHours() { - // Arrange - Time time = new TimeImpl(23, 30); // 11:30 PM - - // Act - Time newTime = time.addTime(120); // Add 2 hours (should wrap to 01:30 AM) - - // Assert - assertEquals(1, newTime.getHours(), "Expected hours to wrap around to 1 AM"); - } - - @Test - void testAddTimeWithMinutesWrapAroundMinutes() { - // Arrange - Time time = new TimeImpl(23, 30); // 11:30 PM - - // Act - Time newTime = time.addTime(120); // Add 2 hours (should wrap to 01:30 AM) - - // Assert - assertEquals(30, newTime.getMinutes(), "Expected minutes to remain 30"); - } - - @Test - void testAddTimeWithNegativeMinutesHours() { - // Arrange - Time time = new TimeImpl(2, 30); // 2:30 AM - - // Act - Time newTime = time.addTime(-180); // Subtract 3 hours (should wrap to 11:30 PM) - - // Assert - assertEquals(23, newTime.getHours(), "Expected hours to wrap around to 11 PM"); - } - - @Test - void testAddTimeWithNegativeMinutesMinutes() { - // Arrange - Time time = new TimeImpl(2, 30); // 2:30 AM - - // Act - Time newTime = time.addTime(-180); // Subtract 3 hours (should wrap to 11:30 PM) - - // Assert - assertEquals(30, newTime.getMinutes(), "Expected minutes to remain 30"); - } - - @Test - void testAddTimeWithAnotherTimeObjectHours() { - // Arrange - Time time1 = new TimeImpl(10, 30); // 10:30 AM - Time time2 = new TimeImpl(3, 45); // 3:45 AM - - // Act - Time result = time1.addTime(time2); // Adding 3:45 to 10:30 - - // Assert - assertEquals(14, result.getHours(), "Expected hours to be 14 (2:15 PM)"); - } - - @Test - void testAddTimeWithAnotherTimeObjectMinutes() { - // Arrange - Time time1 = new TimeImpl(10, 30); // 10:30 AM - Time time2 = new TimeImpl(3, 45); // 3:45 AM - - // Act - Time result = time1.addTime(time2); // Adding 3:45 to 10:30 - - // Assert - assertEquals(15, result.getMinutes(), "Expected minutes to be 15"); - } - - - - @Test - void testAddTimeWithPositiveMinutesHours() { - // Arrange - Time time = new TimeImpl(10, 0); // 10:00 AM - - // Act - Time newTime = time.addTime(120); // Add 2 hours (120 minutes) - - // Assert - assertEquals(12, newTime.getHours(), "Expected hours to be 12 after adding 120 minutes"); - } - - @Test - void testAddTimeWithPositiveMinutesMinutes() { - // Arrange - Time time = new TimeImpl(10, 0); // 10:00 AM - - // Act - Time newTime = time.addTime(120); // Add 2 hours (120 minutes) - - // Assert - assertEquals(0, newTime.getMinutes(), "Expected minutes to remain 0 after adding 120 minutes"); - } - - @Test - void testAddTimeWithWrapAroundHours() { - // Arrange - Time time = new TimeImpl(23, 0); // 11:00 PM - - // Act - Time newTime = time.addTime(120); // Add 2 hours, should wrap to 01:00 AM - - // Assert - assertEquals(1, newTime.getHours(), "Expected hours to be 1 after adding 120 minutes"); - } - - @Test - void testAddTimeWithWrapAroundMinutes() { - // Arrange - Time time = new TimeImpl(23, 0); // 11:00 PM - - // Act - Time newTime = time.addTime(120); // Add 2 hours, should wrap to 01:00 AM - - // Assert - assertEquals(0, newTime.getMinutes(), "Expected minutes to remain 0 after adding 120 minutes"); - } - - @Test - void testEqualsSameTime() { - // Arrange - TimeImpl time1 = new TimeImpl(10, 30); - TimeImpl time2 = new TimeImpl(10, 30); - - // Act & Assert - assertTrue(time1.equals(time2), "Expected both Time objects to be equal"); - } - - @Test - void testEqualsDifferentTime() { - // Arrange - TimeImpl time1 = new TimeImpl(10, 30); - TimeImpl time2 = new TimeImpl(11, 45); - - // Act & Assert - assertFalse(time1.equals(time2), "Expected Time objects with different times to not be equal"); - } - - @Test - void testEqualsNull() { - // Arrange - TimeImpl time1 = new TimeImpl(10, 30); - - // Act & Assert - assertFalse(time1.equals(null), "Expected Time object to not be equal to null"); - } - - @Test - void testEqualsDifferentType() { - // Arrange - TimeImpl time1 = new TimeImpl(10, 30); - String someString = "Some String"; - - // Act & Assert - assertFalse(time1.equals(someString), "Expected Time object to not be equal to an object of a different type"); - } - - @Test - void testEqualsSameInstance() { - // Arrange - TimeImpl time1 = new TimeImpl(10, 30); - - // Act & Assert - assertTrue(time1.equals(time1), "Expected Time object to be equal to itself"); - } - - - @Test - void testConstructorWithNegativeMinutes() { - // Arrange - int hours = 10; - int minutes = -1; // -1 minute should wrap to the previous hour - - // Act - Time time = new TimeImpl(hours, minutes); - - // Assert - assertEquals(9, time.getHours(), "Expected hours to be 9 after wrapping negative minutes"); - assertEquals(59, time.getMinutes(), "Expected minutes to be 59 after wrapping negative minutes"); - } - - - @Test - void testConstructorWithTooManyMinutes() { - // Arrange - int hours = 10; - int minutes = 60; // 60 minutes should roll over into the next hour - - // Act - Time time = new TimeImpl(hours, minutes); - - // Assert - assertEquals(11, time.getHours(), "Expected hours to be 11 after rolling over 60 minutes"); - assertEquals(0, time.getMinutes(), "Expected minutes to be 0 after rolling over 60 minutes"); - } - - @Test - void testConstructorWithNegativeHours() { - // Arrange & Act & Assert - assertThrows(IllegalArgumentException.class, () -> new TimeImpl(-1, 30), - "Expected exception when hours are negative"); - } - - @Test - void testConstructorWithTooManyHours() { - // Arrange & Act & Assert - assertThrows(IllegalArgumentException.class, () -> new TimeImpl(24, 0), - "Expected exception when hours are greater than 23"); - } - - @Test - void testConstructorWithEdgeTime() { - // Arrange - int hours = 23; - int minutes = 59; - - // Act - TimeImpl time = new TimeImpl(hours, minutes); - - // Assert - assertEquals(23, time.getHours(), "Expected hours to be 23"); - assertEquals(59, time.getMinutes(), "Expected minutes to be 59"); - } - -} diff --git a/Example demo/images/simpletimecd.svg b/Example demo/images/simpletimecd.svg deleted file mode 100644 index 710cc96b..00000000 --- a/Example demo/images/simpletimecd.svg +++ /dev/null @@ -1,7 +0,0 @@ - - -TimeClientJMS Module simpletimeapiJMS Module teachertestsJMS Module simpletimeimplall implementing partscan stay encapsulated.simpletimeimplsimpletimesimpletimeapiStudent WorkTimeImplementationDurationImplementationSimpleTimeFactory Duration createTime(int l){ return new ApDuration(...) }AbstractSimpleTimeFactory+ createDuration(lengthInMinutes: int): Duration+ createDuration(hours:int, minutues: int) : Duration+ createTime(hours:int, minutes: int): TimeTimeComparableDurationComparableTime+ getHours():int+ getMinutes():int+ isBefore( otherTime:Time ):boolean+ isBeforeOrEqual( otherTime: Time ):boolean+ addTime( time: Time):Time+ addTime( lengthInMinutes: int ):Time+ asMinutes():int+ untill( otherTime:Time ):DurationDuration + getHours():int+ getMinutes():int+ asMinutes():int+ plus( d: Duration): Durationrequirescreates ►creates ► \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index d6d45c37..00000000 --- a/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# GitHub Actions Workshop - - - -# ESD template - -Please make sure all artifacts are in this GitHub repository. -That includes: - -- Code -- Workshop materials -- Presentation (if applicable) -- References. -- Docker (compose) file (if applicable) diff --git a/Workshop Presentation back up.pptx b/Workshop Presentation back up.pptx deleted file mode 100644 index 61c3ee49..00000000 Binary files a/Workshop Presentation back up.pptx and /dev/null differ diff --git a/Workshop Presentation.pptx b/Workshop Presentation.pptx deleted file mode 100644 index b33e114d..00000000 Binary files a/Workshop Presentation.pptx and /dev/null differ diff --git a/assignments/README.md b/assignments/README.md deleted file mode 100644 index 5a052c91..00000000 --- a/assignments/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# Github Actions Assignments - -In this folder are all Github actions assignment. - -## Prerequisites -- Git installed on your machine -- A GitHub account -- Docker Desktop installed -- VS Code installed \ No newline at end of file diff --git a/assignments/exercise-1/README.md b/assignments/exercise-1/README.md deleted file mode 100644 index 73d9650a..00000000 --- a/assignments/exercise-1/README.md +++ /dev/null @@ -1,22 +0,0 @@ -# Exercise 1 - -1. Fork https://github.com/evl-8/esd-github-actions-assignment -2. Go to repository `Settings > Actions > Runners` and click on `New self-hosted-runner` -3. Select Linux and scroll down to `Configure` section. -4. Extract `--url ` and `--token ` -
Example: `$ ./config.cmd --url https://github.com/evl-8/github-action-demo --token - ABCDEFIGHIJKLMNOPQRSTUVW12345` extracts to - `Url: https://github.com/evl-8/github-action-demo` and - `Token: ABCDEFIGHIJKLMNOPQRSTUVW12345` -5. Go into the cloned `esd-github-actions-assignment` and open the `docker-compose.yml` -6. Follow the instructions inside the file -7. Run `docker compose up` - -You have now created a Github actions runner! -It should look like the picture beneath. -The name is the Container ID of the running docker instance. - -![](../images/github_actions_runner.png) - ---- -[Next Exercise](../exercise-2/README.md) \ No newline at end of file diff --git a/assignments/exercise-2/README.md b/assignments/exercise-2/README.md deleted file mode 100644 index 3963b308..00000000 --- a/assignments/exercise-2/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# Exercise 2 - -In this exercise you will create a small Github actions workflow. - -Create a workflow action in `.github\workflows\` and call it "exercise-2" - - Give it the name "Python application" - - The workflow should run when pushing to main - - Use actions/setup-python@v3 with version 3.10. - - The workflow should run main.py - -> [!TIP] -> The command to run a python file is `python ` - ---- -[Previous Exercise](../exercise-1/README.md) \ No newline at end of file diff --git a/assignments/exercise-2/main.py b/assignments/exercise-2/main.py deleted file mode 100644 index c35b6a20..00000000 --- a/assignments/exercise-2/main.py +++ /dev/null @@ -1 +0,0 @@ -print("Hello World from Python!") \ No newline at end of file diff --git a/assignments/exercise-3/.gitattributes b/assignments/exercise-3/.gitattributes deleted file mode 100644 index f91f6460..00000000 --- a/assignments/exercise-3/.gitattributes +++ /dev/null @@ -1,12 +0,0 @@ -# -# https://help.github.com/articles/dealing-with-line-endings/ -# -# Linux start script should use lf -/gradlew text eol=lf - -# These are Windows script files and should use crlf -*.bat text eol=crlf - -# Binary files should be left untouched -*.jar binary - diff --git a/assignments/exercise-3/README.md b/assignments/exercise-3/README.md deleted file mode 100644 index 3da4e4f1..00000000 --- a/assignments/exercise-3/README.md +++ /dev/null @@ -1,102 +0,0 @@ -# Exercise 3 - -This exercise will guide you how to build, verify and publish a Java project using Github Actions. -Each task we will incrementally enhance the workflow. - -## Creating the build job - -The goal of this step is to build the Java app using a job. - -### Requirements -- The workflow name should be "Java CI with Gradle" -- The workflow must run when pushing to branch "dev" -- The job must be called "build" -- The job should run on "self-hosted" - -### Steps - -- Checkout the source code -- Setup Java 17 -- Execute `./gradlew build` -- Upload the results as artifacts - -> [!TIP] -> Set a default working directory -> -> ``` -> defaults: -> run: -> working-directory: -> ``` - -> [!TIP] -> If `gradlew` cannot be execute, add -> ``` -> - name: Make gradlew executable -> run: chmod +x gradlew -> ``` ->as step before. - -## Creating the verify job - -Now that the app is build, we need to verify the code. -Verify means running tests and checkstyle. - -### Requirements - - The job should run on your self hosted runner - - The job must be called "verify" - - The job must depend on "build" - -### Steps - -- Download the results from the previous job -- Setup Java 17 -- Run the tests with `./gradlew test` -- Run the checkstyle with `/gradlew checkstyleMain` -- Upload the results as artifacts - -## Creating the publish job - -In this job, we will upload our final Jar to a nexus repository server - -### Requirements - - The job must run on your self hosted runner - - The job must be named "publish" - - The job must depend on "verify" - -> [!TIP] -> You can add secrets by clicking `Settings` > `Secrets and variables` > `Actions`. - -### Preparation - -- Add secrets to the github repository - - Add a secret `REPO_USERNAME` with the value `admin` - - Add a secret `REPO_PASSWORD` with the value `admin123` - -### Steps - -- Setup Java 17 -- Download the results from the previous job -- Execute `./gradlew publish` - - -``` -env: - ORG_GRADLE_PROJECT_dockerRepoUsername: ${{ secrets.REPO_USERNAME }} - ORG_GRADLE_PROJECT_dockerRepoPassword: ${{ secrets.REPO_PASSWORD }} -``` - -## Making a pull request - -### Requirements - -Edit the workflow so that: - -- The workflow should run when pushing on branch "prod", "dev" and "stage" -- The workflow should run when making a pull request on branch "prod", "dev" and "stage" - -After that: - -- Create a pull request from `dev` into `stage` -- Wait for all Github actions and `Merge pull request` -- Do the same for `stage` into prod \ No newline at end of file diff --git a/assignments/exercise-3/build.gradle.kts b/assignments/exercise-3/build.gradle.kts deleted file mode 100644 index 68ba47ec..00000000 --- a/assignments/exercise-3/build.gradle.kts +++ /dev/null @@ -1,72 +0,0 @@ -/* - * This file was generated by the Gradle 'init' task. - * - * This generated file contains a sample Java application project to get you started. - * For more details on building Java & JVM projects, please refer to https://docs.gradle.org/8.10.2/userguide/building_java_projects.html in the Gradle documentation. - * This project uses @Incubating APIs which are subject to change. - */ - -plugins { - // Apply the application plugin to add support for building a CLI application in Java. - application - checkstyle - `maven-publish` -} - -repositories { - // Use Maven Central for resolving dependencies. - mavenCentral() -} - -checkstyle { - toolVersion = "10.20.1" -} - -dependencies { - // This dependency is used by the application. - implementation(libs.guava) -} - -publishing { - publications { - create("maven") { - groupId = "org.gradle.sample" - artifactId = "library" - version = "1.0.0-SNAPSHOT" - - from(components["java"]) - } - } - - repositories { - maven { - // change to point to your repo, e.g. http://my.org/repo - url = uri("http://nexus:8081/nexus/content/repositories/snapshots/") - name = "dockerRepo" - credentials(PasswordCredentials::class) - isAllowInsecureProtocol = true - } - } -} - -testing { - suites { - // Configure the built-in test suite - val test by getting(JvmTestSuite::class) { - // Use JUnit Jupiter test framework - useJUnitJupiter("5.10.3") - } - } -} - -// Apply a specific Java toolchain to ease working on different environments. -java { - toolchain { - languageVersion = JavaLanguageVersion.of(17) - } -} - -application { - // Define the main class for the application. - mainClass = "org.example.App" -} diff --git a/assignments/exercise-3/config/checkstyle/checkstyle.xml b/assignments/exercise-3/config/checkstyle/checkstyle.xml deleted file mode 100644 index dc8ccecf..00000000 --- a/assignments/exercise-3/config/checkstyle/checkstyle.xml +++ /dev/null @@ -1,411 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/assignments/exercise-3/gradle.properties b/assignments/exercise-3/gradle.properties deleted file mode 100644 index 18f452c7..00000000 --- a/assignments/exercise-3/gradle.properties +++ /dev/null @@ -1,6 +0,0 @@ -# This file was generated by the Gradle 'init' task. -# https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties - -org.gradle.parallel=true -org.gradle.caching=true - diff --git a/assignments/exercise-3/gradle/libs.versions.toml b/assignments/exercise-3/gradle/libs.versions.toml deleted file mode 100644 index f4740390..00000000 --- a/assignments/exercise-3/gradle/libs.versions.toml +++ /dev/null @@ -1,8 +0,0 @@ -# This file was generated by the Gradle 'init' task. -# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format - -[versions] -guava = "33.2.1-jre" - -[libraries] -guava = { module = "com.google.guava:guava", version.ref = "guava" } diff --git a/assignments/exercise-3/gradle/wrapper/gradle-wrapper.jar b/assignments/exercise-3/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index a4b76b95..00000000 Binary files a/assignments/exercise-3/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/assignments/exercise-3/gradle/wrapper/gradle-wrapper.properties b/assignments/exercise-3/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index df97d72b..00000000 --- a/assignments/exercise-3/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,7 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip -networkTimeout=10000 -validateDistributionUrl=true -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/assignments/exercise-3/gradlew b/assignments/exercise-3/gradlew deleted file mode 100644 index f5feea6d..00000000 --- a/assignments/exercise-3/gradlew +++ /dev/null @@ -1,252 +0,0 @@ -#!/bin/sh - -# -# Copyright © 2015-2021 the original authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# SPDX-License-Identifier: Apache-2.0 -# - -############################################################################## -# -# Gradle start up script for POSIX generated by Gradle. -# -# Important for running: -# -# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is -# noncompliant, but you have some other compliant shell such as ksh or -# bash, then to run this script, type that shell name before the whole -# command line, like: -# -# ksh Gradle -# -# Busybox and similar reduced shells will NOT work, because this script -# requires all of these POSIX shell features: -# * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a testable exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». -# -# Important for patching: -# -# (2) This script targets any POSIX shell, so it avoids extensions provided -# by Bash, Ksh, etc; in particular arrays are avoided. -# -# The "traditional" practice of packing multiple parameters into a -# space-separated string is a well documented source of bugs and security -# problems, so this is (mostly) avoided, by progressively accumulating -# options in "$@", and eventually passing that to Java. -# -# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, -# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; -# see the in-line comments for details. -# -# There are tweaks for specific operating systems such as AIX, CygWin, -# Darwin, MinGW, and NonStop. -# -# (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt -# within the Gradle project. -# -# You can find Gradle at https://github.com/gradle/gradle/. -# -############################################################################## - -# Attempt to set APP_HOME - -# Resolve links: $0 may be a link -app_path=$0 - -# Need this for daisy-chained symlinks. -while - APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path - [ -h "$app_path" ] -do - ls=$( ls -ld "$app_path" ) - link=${ls#*' -> '} - case $link in #( - /*) app_path=$link ;; #( - *) app_path=$APP_HOME$link ;; - esac -done - -# This is normally unused -# shellcheck disable=SC2034 -APP_BASE_NAME=${0##*/} -# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s -' "$PWD" ) || exit - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD=maximum - -warn () { - echo "$*" -} >&2 - -die () { - echo - echo "$*" - echo - exit 1 -} >&2 - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "$( uname )" in #( - CYGWIN* ) cygwin=true ;; #( - Darwin* ) darwin=true ;; #( - MSYS* | MINGW* ) msys=true ;; #( - NONSTOP* ) nonstop=true ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD=$JAVA_HOME/jre/sh/java - else - JAVACMD=$JAVA_HOME/bin/java - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD=java - if ! command -v java >/dev/null 2>&1 - then - die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -fi - -# Increase the maximum file descriptors if we can. -if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then - case $MAX_FD in #( - max*) - # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC2039,SC3045 - MAX_FD=$( ulimit -H -n ) || - warn "Could not query maximum file descriptor limit" - esac - case $MAX_FD in #( - '' | soft) :;; #( - *) - # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC2039,SC3045 - ulimit -n "$MAX_FD" || - warn "Could not set maximum file descriptor limit to $MAX_FD" - esac -fi - -# Collect all arguments for the java command, stacking in reverse order: -# * args from the command line -# * the main class name -# * -classpath -# * -D...appname settings -# * --module-path (only if needed) -# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. - -# For Cygwin or MSYS, switch paths to Windows format before running java -if "$cygwin" || "$msys" ; then - APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) - - JAVACMD=$( cygpath --unix "$JAVACMD" ) - - # Now convert the arguments - kludge to limit ourselves to /bin/sh - for arg do - if - case $arg in #( - -*) false ;; # don't mess with options #( - /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath - [ -e "$t" ] ;; #( - *) false ;; - esac - then - arg=$( cygpath --path --ignore --mixed "$arg" ) - fi - # Roll the args list around exactly as many times as the number of - # args, so each arg winds up back in the position where it started, but - # possibly modified. - # - # NB: a `for` loop captures its iteration list before it begins, so - # changing the positional parameters here affects neither the number of - # iterations, nor the values presented in `arg`. - shift # remove old arg - set -- "$@" "$arg" # push replacement arg - done -fi - - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Collect all arguments for the java command: -# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, -# and any embedded shellness will be escaped. -# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be -# treated as '${Hostname}' itself on the command line. - -set -- \ - "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ - "$@" - -# Stop when "xargs" is not available. -if ! command -v xargs >/dev/null 2>&1 -then - die "xargs is not available" -fi - -# Use "xargs" to parse quoted args. -# -# With -n1 it outputs one arg per line, with the quotes and backslashes removed. -# -# In Bash we could simply go: -# -# readarray ARGS < <( xargs -n1 <<<"$var" ) && -# set -- "${ARGS[@]}" "$@" -# -# but POSIX shell has neither arrays nor command substitution, so instead we -# post-process each arg (as a line of input to sed) to backslash-escape any -# character that might be a shell metacharacter, then use eval to reverse -# that process (while maintaining the separation between arguments), and wrap -# the whole thing up as a single "set" statement. -# -# This will of course break if any of these variables contains a newline or -# an unmatched quote. -# - -eval "set -- $( - printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | - xargs -n1 | - sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | - tr '\n' ' ' - )" '"$@"' - -exec "$JAVACMD" "$@" diff --git a/assignments/exercise-3/gradlew.bat b/assignments/exercise-3/gradlew.bat deleted file mode 100644 index 9d21a218..00000000 --- a/assignments/exercise-3/gradlew.bat +++ /dev/null @@ -1,94 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem -@rem SPDX-License-Identifier: Apache-2.0 -@rem - -@if "%DEBUG%"=="" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%"=="" set DIRNAME=. -@rem This is normally unused -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if %ERRORLEVEL% equ 0 goto execute - -echo. 1>&2 -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. 1>&2 -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if %ERRORLEVEL% equ 0 goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -set EXIT_CODE=%ERRORLEVEL% -if %EXIT_CODE% equ 0 set EXIT_CODE=1 -if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% -exit /b %EXIT_CODE% - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/assignments/exercise-3/settings.gradle.kts b/assignments/exercise-3/settings.gradle.kts deleted file mode 100644 index f2f2c804..00000000 --- a/assignments/exercise-3/settings.gradle.kts +++ /dev/null @@ -1,14 +0,0 @@ -/* - * This file was generated by the Gradle 'init' task. - * - * The settings file is used to specify which projects to include in your build. - * For more detailed information on multi-project builds, please refer to https://docs.gradle.org/8.10.2/userguide/multi_project_builds.html in the Gradle documentation. - * This project uses @Incubating APIs which are subject to change. - */ - -plugins { - // Apply the foojay-resolver plugin to allow automatic download of JDKs - id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" -} - -rootProject.name = "esd-github-actions-solution" diff --git a/assignments/exercise-3/src/main/java/org/example/App.java b/assignments/exercise-3/src/main/java/org/example/App.java deleted file mode 100644 index ec97996d..00000000 --- a/assignments/exercise-3/src/main/java/org/example/App.java +++ /dev/null @@ -1,15 +0,0 @@ -/* - * This source file was generated by the Gradle 'init' task - */ - -package org.example; - -public class App { - public String getGreeting() { - return "Hello World!"; - } - - public static void main(String[] args) { - System.out.println(new App().getGreeting()); - } -} diff --git a/assignments/exercise-3/src/test/java/org/example/AppTest.java b/assignments/exercise-3/src/test/java/org/example/AppTest.java deleted file mode 100644 index 1fdf5898..00000000 --- a/assignments/exercise-3/src/test/java/org/example/AppTest.java +++ /dev/null @@ -1,17 +0,0 @@ -/* - * This source file was generated by the Gradle 'init' task - */ - -package org.example; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -class AppTest { - @Test - void appHasAGreeting() { - App classUnderTest = new App(); - assertNotNull(classUnderTest.getGreeting(), "app should have a greeting"); - } -} diff --git a/assignments/exercise-4/README.md b/assignments/exercise-4/README.md deleted file mode 100644 index f74b2310..00000000 --- a/assignments/exercise-4/README.md +++ /dev/null @@ -1,45 +0,0 @@ -# Exercise 4: Deploy a Static Site with GitHub Actions - -In this exercise, you will create a workflow that uses **GitHub Pages** to deploy a static site online. - -## Steps - -### 1. Prepare the Static Site - -The `index.html` file is already provided in the `exercise` folder. - ---- - -### 2. Create a Workflow Action - -1. In the `.github/workflows/` directory, create a new file named `exercise-4.yml`. - ---- - -### 3. Configure the Workflow - -1. **Give the workflow a name**: `"Deploy Static Site"`. -2. **Trigger the workflow**: Set it to run when pushing to the `main` branch. -3. **Add the following steps**: - - Checkout the repository code using `actions/checkout@v3`. - - Deploy to GitHub Pages using `peaceiris/actions-gh-pages@v3`. - - Set the `publish_dir` to point to the `exercise` directory (where `index.html` is located). - ---- - -### 4. Set Up GitHub Pages - -1. Go to your repository **Settings**. -2. Under **Pages**, set the source to the `gh-pages` branch. - ---- - -## Tips - -- The `peaceiris/actions-gh-pages@v3` action simplifies deployment by handling the publishing process. -- Make sure to commit and push the `exercise-4.yml` file to trigger the workflow. - ---- - -Good luck, and happy coding! -[Next Exercise](../exercise-5/README.md) \ No newline at end of file diff --git a/assignments/exercise-5/.gitattributes b/assignments/exercise-5/.gitattributes deleted file mode 100644 index 3b41682a..00000000 --- a/assignments/exercise-5/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -/mvnw text eol=lf -*.cmd text eol=crlf diff --git a/assignments/exercise-5/.gitignore b/assignments/exercise-5/.gitignore deleted file mode 100644 index 549e00a2..00000000 --- a/assignments/exercise-5/.gitignore +++ /dev/null @@ -1,33 +0,0 @@ -HELP.md -target/ -!.mvn/wrapper/maven-wrapper.jar -!**/src/main/**/target/ -!**/src/test/**/target/ - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ -!**/src/main/**/build/ -!**/src/test/**/build/ - -### VS Code ### -.vscode/ diff --git a/assignments/exercise-5/README.md b/assignments/exercise-5/README.md deleted file mode 100644 index d8b7076f..00000000 --- a/assignments/exercise-5/README.md +++ /dev/null @@ -1,71 +0,0 @@ -# Exercise 5: Run Unit Tests and Comment with GitHub Actions - -In this exercise, you will create a workflow that runs unit tests for the provided Java Spring Boot project, and if the tests pass, posts a comment on the commit itself. - -## Steps - -### 1. Prepare the Java Spring Boot Project -The Java Spring Boot project is already provided in the exercise folder. - -### 2. Create a Workflow Action -In the `.github/workflows/` directory, create a new file named `exercise-5.yml`. - -### 3. Configure the Workflow -- **Name the Workflow**: `"Test and Comment"`. -- **Trigger the Workflow**: Set it to run on `push` events. - - **Add the Following Steps**: - 1. **Checkout the Repository Code**: - Use `actions/checkout@v3`. - 2. **Set Up JDK**: - Use `actions/setup-java@v3` to set up JDK (e.g., Java 17). - 3. **Compile Project**: - Run: - ```bash - mvn compile - ``` - 4. **Run Unit Tests**: - Execute: - ```bash - mvn test - ``` - 5. **Implement Conditional Logic**: - Use: - ```yaml - if: ${{ success() }} - ... - ... - ... - - ``` - to check if the tests have passed. - 6. **Post a Comment on the Commit**: - Use `actions/github-script@v6` to post a comment indicating success. - with this code: - ```yaml - script: | - const commit_sha = context.sha; - await github.repos.createCommitComment({ - owner: context.repo.owner, - repo: context.repo.repo, - commit_sha: commit_sha, - body: '✅ All unit tests passed successfully!', - }); - -### 4. Verify the Workflow -1. **Commit and Push Changes**: - Make sure to commit and push the `exercise-5.yml` file to trigger the workflow. -2. **Observe Workflow Execution**: - Go to your GitHub repository and click on the "Actions" tab to see the workflow run details. -3. **Check the Commit for the Comment**: - Navigate to the commit to verify if a comment has been posted indicating that the tests passed. - -## Tips - -### Permissions -Ensure your workflow has the necessary permissions to post comments by including: - - - permissions: - contents: write - -[Next Exercise](../exercise-6/README.md) \ No newline at end of file diff --git a/assignments/exercise-5/mvnw b/assignments/exercise-5/mvnw deleted file mode 100644 index 19529ddf..00000000 --- a/assignments/exercise-5/mvnw +++ /dev/null @@ -1,259 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Apache Maven Wrapper startup batch script, version 3.3.2 -# -# Optional ENV vars -# ----------------- -# JAVA_HOME - location of a JDK home dir, required when download maven via java source -# MVNW_REPOURL - repo url base for downloading maven distribution -# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven -# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output -# ---------------------------------------------------------------------------- - -set -euf -[ "${MVNW_VERBOSE-}" != debug ] || set -x - -# OS specific support. -native_path() { printf %s\\n "$1"; } -case "$(uname)" in -CYGWIN* | MINGW*) - [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" - native_path() { cygpath --path --windows "$1"; } - ;; -esac - -# set JAVACMD and JAVACCMD -set_java_home() { - # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched - if [ -n "${JAVA_HOME-}" ]; then - if [ -x "$JAVA_HOME/jre/sh/java" ]; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - JAVACCMD="$JAVA_HOME/jre/sh/javac" - else - JAVACMD="$JAVA_HOME/bin/java" - JAVACCMD="$JAVA_HOME/bin/javac" - - if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then - echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 - echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 - return 1 - fi - fi - else - JAVACMD="$( - 'set' +e - 'unset' -f command 2>/dev/null - 'command' -v java - )" || : - JAVACCMD="$( - 'set' +e - 'unset' -f command 2>/dev/null - 'command' -v javac - )" || : - - if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then - echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 - return 1 - fi - fi -} - -# hash string like Java String::hashCode -hash_string() { - str="${1:-}" h=0 - while [ -n "$str" ]; do - char="${str%"${str#?}"}" - h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) - str="${str#?}" - done - printf %x\\n $h -} - -verbose() { :; } -[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } - -die() { - printf %s\\n "$1" >&2 - exit 1 -} - -trim() { - # MWRAPPER-139: - # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. - # Needed for removing poorly interpreted newline sequences when running in more - # exotic environments such as mingw bash on Windows. - printf "%s" "${1}" | tr -d '[:space:]' -} - -# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties -while IFS="=" read -r key value; do - case "${key-}" in - distributionUrl) distributionUrl=$(trim "${value-}") ;; - distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; - esac -done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" -[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" - -case "${distributionUrl##*/}" in -maven-mvnd-*bin.*) - MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ - case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in - *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; - :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; - :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; - :Linux*x86_64*) distributionPlatform=linux-amd64 ;; - *) - echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 - distributionPlatform=linux-amd64 - ;; - esac - distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" - ;; -maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; -*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; -esac - -# apply MVNW_REPOURL and calculate MAVEN_HOME -# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ -[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" -distributionUrlName="${distributionUrl##*/}" -distributionUrlNameMain="${distributionUrlName%.*}" -distributionUrlNameMain="${distributionUrlNameMain%-bin}" -MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" -MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" - -exec_maven() { - unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : - exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" -} - -if [ -d "$MAVEN_HOME" ]; then - verbose "found existing MAVEN_HOME at $MAVEN_HOME" - exec_maven "$@" -fi - -case "${distributionUrl-}" in -*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; -*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; -esac - -# prepare tmp dir -if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then - clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } - trap clean HUP INT TERM EXIT -else - die "cannot create temp dir" -fi - -mkdir -p -- "${MAVEN_HOME%/*}" - -# Download and Install Apache Maven -verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." -verbose "Downloading from: $distributionUrl" -verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" - -# select .zip or .tar.gz -if ! command -v unzip >/dev/null; then - distributionUrl="${distributionUrl%.zip}.tar.gz" - distributionUrlName="${distributionUrl##*/}" -fi - -# verbose opt -__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' -[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v - -# normalize http auth -case "${MVNW_PASSWORD:+has-password}" in -'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; -has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; -esac - -if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then - verbose "Found wget ... using wget" - wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" -elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then - verbose "Found curl ... using curl" - curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" -elif set_java_home; then - verbose "Falling back to use Java to download" - javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" - targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" - cat >"$javaSource" <<-END - public class Downloader extends java.net.Authenticator - { - protected java.net.PasswordAuthentication getPasswordAuthentication() - { - return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); - } - public static void main( String[] args ) throws Exception - { - setDefault( new Downloader() ); - java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); - } - } - END - # For Cygwin/MinGW, switch paths to Windows format before running javac and java - verbose " - Compiling Downloader.java ..." - "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" - verbose " - Running Downloader.java ..." - "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" -fi - -# If specified, validate the SHA-256 sum of the Maven distribution zip file -if [ -n "${distributionSha256Sum-}" ]; then - distributionSha256Result=false - if [ "$MVN_CMD" = mvnd.sh ]; then - echo "Checksum validation is not supported for maven-mvnd." >&2 - echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 - exit 1 - elif command -v sha256sum >/dev/null; then - if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then - distributionSha256Result=true - fi - elif command -v shasum >/dev/null; then - if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then - distributionSha256Result=true - fi - else - echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 - echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 - exit 1 - fi - if [ $distributionSha256Result = false ]; then - echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 - echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 - exit 1 - fi -fi - -# unzip and move -if command -v unzip >/dev/null; then - unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" -else - tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" -fi -printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" -mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" - -clean || : -exec_maven "$@" diff --git a/assignments/exercise-5/mvnw.cmd b/assignments/exercise-5/mvnw.cmd deleted file mode 100644 index 249bdf38..00000000 --- a/assignments/exercise-5/mvnw.cmd +++ /dev/null @@ -1,149 +0,0 @@ -<# : batch portion -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Apache Maven Wrapper startup batch script, version 3.3.2 -@REM -@REM Optional ENV vars -@REM MVNW_REPOURL - repo url base for downloading maven distribution -@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven -@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output -@REM ---------------------------------------------------------------------------- - -@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) -@SET __MVNW_CMD__= -@SET __MVNW_ERROR__= -@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% -@SET PSModulePath= -@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( - IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) -) -@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% -@SET __MVNW_PSMODULEP_SAVE= -@SET __MVNW_ARG0_NAME__= -@SET MVNW_USERNAME= -@SET MVNW_PASSWORD= -@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) -@echo Cannot start maven from wrapper >&2 && exit /b 1 -@GOTO :EOF -: end batch / begin powershell #> - -$ErrorActionPreference = "Stop" -if ($env:MVNW_VERBOSE -eq "true") { - $VerbosePreference = "Continue" -} - -# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties -$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl -if (!$distributionUrl) { - Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" -} - -switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { - "maven-mvnd-*" { - $USE_MVND = $true - $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" - $MVN_CMD = "mvnd.cmd" - break - } - default { - $USE_MVND = $false - $MVN_CMD = $script -replace '^mvnw','mvn' - break - } -} - -# apply MVNW_REPOURL and calculate MAVEN_HOME -# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ -if ($env:MVNW_REPOURL) { - $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } - $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" -} -$distributionUrlName = $distributionUrl -replace '^.*/','' -$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' -$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" -if ($env:MAVEN_USER_HOME) { - $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" -} -$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' -$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" - -if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { - Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" - Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" - exit $? -} - -if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { - Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" -} - -# prepare tmp dir -$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile -$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" -$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null -trap { - if ($TMP_DOWNLOAD_DIR.Exists) { - try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } - catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } - } -} - -New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null - -# Download and Install Apache Maven -Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." -Write-Verbose "Downloading from: $distributionUrl" -Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" - -$webclient = New-Object System.Net.WebClient -if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { - $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) -} -[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null - -# If specified, validate the SHA-256 sum of the Maven distribution zip file -$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum -if ($distributionSha256Sum) { - if ($USE_MVND) { - Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." - } - Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash - if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { - Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." - } -} - -# unzip and move -Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null -Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null -try { - Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null -} catch { - if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { - Write-Error "fail to move MAVEN_HOME" - } -} finally { - try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } - catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } -} - -Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/assignments/exercise-5/pom.xml b/assignments/exercise-5/pom.xml deleted file mode 100644 index 1b150852..00000000 --- a/assignments/exercise-5/pom.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 3.4.0 - - - org.example - Calculator - 0.0.1-SNAPSHOT - Calculator - Calculator - - - - - - - - - - - - - - - 17 - - - - org.mockito - mockito-junit-jupiter - 5.14.2 - test - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-devtools - runtime - true - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/assignments/exercise-6/.gitattributes b/assignments/exercise-6/.gitattributes deleted file mode 100644 index 3b41682a..00000000 --- a/assignments/exercise-6/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -/mvnw text eol=lf -*.cmd text eol=crlf diff --git a/assignments/exercise-6/.gitignore b/assignments/exercise-6/.gitignore deleted file mode 100644 index 549e00a2..00000000 --- a/assignments/exercise-6/.gitignore +++ /dev/null @@ -1,33 +0,0 @@ -HELP.md -target/ -!.mvn/wrapper/maven-wrapper.jar -!**/src/main/**/target/ -!**/src/test/**/target/ - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ -!**/src/main/**/build/ -!**/src/test/**/build/ - -### VS Code ### -.vscode/ diff --git a/assignments/exercise-6/.mvn/wrapper/maven-wrapper.properties b/assignments/exercise-6/.mvn/wrapper/maven-wrapper.properties deleted file mode 100644 index d58dfb70..00000000 --- a/assignments/exercise-6/.mvn/wrapper/maven-wrapper.properties +++ /dev/null @@ -1,19 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -wrapperVersion=3.3.2 -distributionType=only-script -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip diff --git a/assignments/exercise-6/README.md b/assignments/exercise-6/README.md deleted file mode 100644 index a4ed59cd..00000000 --- a/assignments/exercise-6/README.md +++ /dev/null @@ -1,50 +0,0 @@ - -# Exercise 6: Create Reusable Workflows and Templates with GitHub Actions - -In this exercise, you will create reusable workflows and use it. - -## Steps - -### 1. Create a Reusable Workflow -- **Directory**: Navigate to the `.github/workflows/` directory in your repository. -- **Create the Workflow File**: Create a new file named `ci.yml`. - -### 2. Configure the Reusable Workflow -- **Name the Workflow**: `"Reusable CI Workflow"`. -- **Trigger the Workflow**: Use the `workflow_call` trigger to allow other workflows to invoke it. -- **Define Workflow Inputs**: - - Specify required inputs, such as the Node.js version. -- **Add the Following Steps**: - 1. **Checkout the Repository Code**: - Use `actions/checkout@v3`. - 2. **Set Up Node.js Environment**: - Use `actions/setup-node@v3` and configure it to use the Node.js version passed as an input. - 3. **Install Dependencies**: - Run: - ```bash - npm install - ``` - 4. **Run Tests**: - Execute: - ```bash - npm test - ``` - -### 3. Create a Workflow to Call the Reusable Workflow -- **Directory**: In the `.github/workflows/` directory of the same repository, create a new file named `main.yml`. -- **Configure the Workflow**: - - **Name the Workflow**: `"CI"`. - - **Trigger the Workflow**: Set it to run on pushes to the `main` branch. - - **Call the Reusable Workflow**: - - Use the `uses` keyword to reference the reusable workflow. - - Provide the required inputs such as the Node.js version. - -### 4. Verify the Workflows -1. **Commit and Push Changes**: - Push the `ci.yml` and `main.yml` files to the repository. -2. **Observe Workflow Execution**: - Go to the "Actions" tab in your GitHub repository to verify the workflow runs. -3. **Check Logs and Results**: - Confirm that the reusable workflow is called and all steps execute successfully. - -Happy coding! diff --git a/assignments/exercise-6/mvnw b/assignments/exercise-6/mvnw deleted file mode 100644 index 19529ddf..00000000 --- a/assignments/exercise-6/mvnw +++ /dev/null @@ -1,259 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Apache Maven Wrapper startup batch script, version 3.3.2 -# -# Optional ENV vars -# ----------------- -# JAVA_HOME - location of a JDK home dir, required when download maven via java source -# MVNW_REPOURL - repo url base for downloading maven distribution -# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven -# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output -# ---------------------------------------------------------------------------- - -set -euf -[ "${MVNW_VERBOSE-}" != debug ] || set -x - -# OS specific support. -native_path() { printf %s\\n "$1"; } -case "$(uname)" in -CYGWIN* | MINGW*) - [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" - native_path() { cygpath --path --windows "$1"; } - ;; -esac - -# set JAVACMD and JAVACCMD -set_java_home() { - # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched - if [ -n "${JAVA_HOME-}" ]; then - if [ -x "$JAVA_HOME/jre/sh/java" ]; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - JAVACCMD="$JAVA_HOME/jre/sh/javac" - else - JAVACMD="$JAVA_HOME/bin/java" - JAVACCMD="$JAVA_HOME/bin/javac" - - if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then - echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 - echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 - return 1 - fi - fi - else - JAVACMD="$( - 'set' +e - 'unset' -f command 2>/dev/null - 'command' -v java - )" || : - JAVACCMD="$( - 'set' +e - 'unset' -f command 2>/dev/null - 'command' -v javac - )" || : - - if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then - echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 - return 1 - fi - fi -} - -# hash string like Java String::hashCode -hash_string() { - str="${1:-}" h=0 - while [ -n "$str" ]; do - char="${str%"${str#?}"}" - h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) - str="${str#?}" - done - printf %x\\n $h -} - -verbose() { :; } -[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } - -die() { - printf %s\\n "$1" >&2 - exit 1 -} - -trim() { - # MWRAPPER-139: - # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. - # Needed for removing poorly interpreted newline sequences when running in more - # exotic environments such as mingw bash on Windows. - printf "%s" "${1}" | tr -d '[:space:]' -} - -# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties -while IFS="=" read -r key value; do - case "${key-}" in - distributionUrl) distributionUrl=$(trim "${value-}") ;; - distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; - esac -done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" -[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" - -case "${distributionUrl##*/}" in -maven-mvnd-*bin.*) - MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ - case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in - *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; - :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; - :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; - :Linux*x86_64*) distributionPlatform=linux-amd64 ;; - *) - echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 - distributionPlatform=linux-amd64 - ;; - esac - distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" - ;; -maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; -*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; -esac - -# apply MVNW_REPOURL and calculate MAVEN_HOME -# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ -[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" -distributionUrlName="${distributionUrl##*/}" -distributionUrlNameMain="${distributionUrlName%.*}" -distributionUrlNameMain="${distributionUrlNameMain%-bin}" -MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" -MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" - -exec_maven() { - unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : - exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" -} - -if [ -d "$MAVEN_HOME" ]; then - verbose "found existing MAVEN_HOME at $MAVEN_HOME" - exec_maven "$@" -fi - -case "${distributionUrl-}" in -*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; -*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; -esac - -# prepare tmp dir -if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then - clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } - trap clean HUP INT TERM EXIT -else - die "cannot create temp dir" -fi - -mkdir -p -- "${MAVEN_HOME%/*}" - -# Download and Install Apache Maven -verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." -verbose "Downloading from: $distributionUrl" -verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" - -# select .zip or .tar.gz -if ! command -v unzip >/dev/null; then - distributionUrl="${distributionUrl%.zip}.tar.gz" - distributionUrlName="${distributionUrl##*/}" -fi - -# verbose opt -__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' -[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v - -# normalize http auth -case "${MVNW_PASSWORD:+has-password}" in -'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; -has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; -esac - -if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then - verbose "Found wget ... using wget" - wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" -elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then - verbose "Found curl ... using curl" - curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" -elif set_java_home; then - verbose "Falling back to use Java to download" - javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" - targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" - cat >"$javaSource" <<-END - public class Downloader extends java.net.Authenticator - { - protected java.net.PasswordAuthentication getPasswordAuthentication() - { - return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); - } - public static void main( String[] args ) throws Exception - { - setDefault( new Downloader() ); - java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); - } - } - END - # For Cygwin/MinGW, switch paths to Windows format before running javac and java - verbose " - Compiling Downloader.java ..." - "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" - verbose " - Running Downloader.java ..." - "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" -fi - -# If specified, validate the SHA-256 sum of the Maven distribution zip file -if [ -n "${distributionSha256Sum-}" ]; then - distributionSha256Result=false - if [ "$MVN_CMD" = mvnd.sh ]; then - echo "Checksum validation is not supported for maven-mvnd." >&2 - echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 - exit 1 - elif command -v sha256sum >/dev/null; then - if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then - distributionSha256Result=true - fi - elif command -v shasum >/dev/null; then - if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then - distributionSha256Result=true - fi - else - echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 - echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 - exit 1 - fi - if [ $distributionSha256Result = false ]; then - echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 - echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 - exit 1 - fi -fi - -# unzip and move -if command -v unzip >/dev/null; then - unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" -else - tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" -fi -printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" -mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" - -clean || : -exec_maven "$@" diff --git a/assignments/exercise-6/mvnw.cmd b/assignments/exercise-6/mvnw.cmd deleted file mode 100644 index 249bdf38..00000000 --- a/assignments/exercise-6/mvnw.cmd +++ /dev/null @@ -1,149 +0,0 @@ -<# : batch portion -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Apache Maven Wrapper startup batch script, version 3.3.2 -@REM -@REM Optional ENV vars -@REM MVNW_REPOURL - repo url base for downloading maven distribution -@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven -@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output -@REM ---------------------------------------------------------------------------- - -@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) -@SET __MVNW_CMD__= -@SET __MVNW_ERROR__= -@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% -@SET PSModulePath= -@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( - IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) -) -@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% -@SET __MVNW_PSMODULEP_SAVE= -@SET __MVNW_ARG0_NAME__= -@SET MVNW_USERNAME= -@SET MVNW_PASSWORD= -@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) -@echo Cannot start maven from wrapper >&2 && exit /b 1 -@GOTO :EOF -: end batch / begin powershell #> - -$ErrorActionPreference = "Stop" -if ($env:MVNW_VERBOSE -eq "true") { - $VerbosePreference = "Continue" -} - -# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties -$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl -if (!$distributionUrl) { - Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" -} - -switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { - "maven-mvnd-*" { - $USE_MVND = $true - $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" - $MVN_CMD = "mvnd.cmd" - break - } - default { - $USE_MVND = $false - $MVN_CMD = $script -replace '^mvnw','mvn' - break - } -} - -# apply MVNW_REPOURL and calculate MAVEN_HOME -# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ -if ($env:MVNW_REPOURL) { - $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } - $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" -} -$distributionUrlName = $distributionUrl -replace '^.*/','' -$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' -$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" -if ($env:MAVEN_USER_HOME) { - $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" -} -$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' -$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" - -if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { - Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" - Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" - exit $? -} - -if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { - Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" -} - -# prepare tmp dir -$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile -$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" -$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null -trap { - if ($TMP_DOWNLOAD_DIR.Exists) { - try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } - catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } - } -} - -New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null - -# Download and Install Apache Maven -Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." -Write-Verbose "Downloading from: $distributionUrl" -Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" - -$webclient = New-Object System.Net.WebClient -if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { - $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) -} -[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null - -# If specified, validate the SHA-256 sum of the Maven distribution zip file -$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum -if ($distributionSha256Sum) { - if ($USE_MVND) { - Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." - } - Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash - if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { - Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." - } -} - -# unzip and move -Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null -Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null -try { - Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null -} catch { - if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { - Write-Error "fail to move MAVEN_HOME" - } -} finally { - try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } - catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } -} - -Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/assignments/exercise-6/pom.xml b/assignments/exercise-6/pom.xml deleted file mode 100644 index 1b150852..00000000 --- a/assignments/exercise-6/pom.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 3.4.0 - - - org.example - Calculator - 0.0.1-SNAPSHOT - Calculator - Calculator - - - - - - - - - - - - - - - 17 - - - - org.mockito - mockito-junit-jupiter - 5.14.2 - test - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-devtools - runtime - true - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/assignments/exercise-6/src/main/java/org/example/calculator/Calculator.java b/assignments/exercise-6/src/main/java/org/example/calculator/Calculator.java deleted file mode 100644 index 4fbac8cc..00000000 --- a/assignments/exercise-6/src/main/java/org/example/calculator/Calculator.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.example.calculator; -import org.springframework.stereotype.Component; - -@Component -public class Calculator { - public double add(double a, double b) { - return a + b; - } - - public double subtract(double a, double b) { - return a - b; - } - - public double multiply(double a, double b) { - return a * b; - } - - public double divide(double a, double b) { - if (b == 0) { - throw new ArithmeticException("Division by zero"); - } - return a / b; - } -} diff --git a/assignments/exercise-6/src/main/java/org/example/calculator/CalculatorApplication.java b/assignments/exercise-6/src/main/java/org/example/calculator/CalculatorApplication.java deleted file mode 100644 index 1f2c4fc7..00000000 --- a/assignments/exercise-6/src/main/java/org/example/calculator/CalculatorApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.example.calculator; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class CalculatorApplication { - - public static void main(String[] args) { - SpringApplication.run(CalculatorApplication.class, args); - } - -} diff --git a/assignments/exercise-6/src/main/resources/application.properties b/assignments/exercise-6/src/main/resources/application.properties deleted file mode 100644 index 232807e6..00000000 --- a/assignments/exercise-6/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.application.name=Calculator diff --git a/assignments/exercise-6/src/test/java/org/example/calculator/CalculatorApplicationTests.java b/assignments/exercise-6/src/test/java/org/example/calculator/CalculatorApplicationTests.java deleted file mode 100644 index 7d38fb2e..00000000 --- a/assignments/exercise-6/src/test/java/org/example/calculator/CalculatorApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.example.calculator; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class CalculatorApplicationTests { - - @Test - void contextLoads() { - } - -} diff --git a/assignments/exercise-6/src/test/java/org/example/calculator/CalculatorTest.java b/assignments/exercise-6/src/test/java/org/example/calculator/CalculatorTest.java deleted file mode 100644 index f4230c1c..00000000 --- a/assignments/exercise-6/src/test/java/org/example/calculator/CalculatorTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.example.calculator; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -class CalculatorTest { - - private final Calculator calculator = new Calculator(); - - @Test - void testAddition() { - assertEquals(5.0, calculator.add(2.0, 3.0)); - } - - @Test - void testSubtraction() { - assertEquals(4.0, calculator.subtract(7.0, 3.0)); - } - - @Test - void testMultiplication() { - assertEquals(15.0, calculator.multiply(3.0, 5.0)); - } - - @Test - void testDivision() { - assertEquals(4.0, calculator.divide(12.0, 3.0)); - } - - @Test - void testDivisionByZero() { - Exception exception = assertThrows(ArithmeticException.class, () -> { - calculator.divide(5.0, 0.0); - }); - assertEquals("Division by zero", exception.getMessage()); - } -} \ No newline at end of file diff --git a/assignments/images/github_actions_runner.png b/assignments/images/github_actions_runner.png deleted file mode 100644 index 0ca49fcd..00000000 Binary files a/assignments/images/github_actions_runner.png and /dev/null differ diff --git a/brainstorm.txt b/brainstorm.txt deleted file mode 100644 index 6995fbaf..00000000 --- a/brainstorm.txt +++ /dev/null @@ -1,43 +0,0 @@ -GitHub workflow refresher (emphasize usage for GitHub actions) -Explain common git worflow (different branchens, push) -Where does GitHub fit in the picture? - -Github actions introduction - use cases (where do i need this, and why - what are the benefits) - Main features: workflows, events, jobs, actions, triggers - Explain syntax, files - Triggers (usually, on push, pull request) - dependencies between jobs (not steps) - - Different development branches dev/stage/prod - Should be general (you can have different workflows for different branches) - - Mention that test need to pass so the job can succeed - explain differences between self-hosted runners vs github-hosted runners - - - Show job example with Java, Kotlin - unconventional example (posting something on social media if a jobs runs) - - -The workshop task should require thinking from the audience. -Give the group a project from the repository -That will have an example of workflow. -Give participants a basic example. -They should figure out based on that. - - -For practical assignments. -Let them do small incremental assignments that build into a larger goal/task. - - -Mention the GitHub actions marketplace. -Brief explanation what they are and where to use it. - -Comparison to Jenkins/Gitlab - -Advanced things. - -Reusable workflows - -Caching packages/dependencies \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 97bb8361..00000000 --- a/docker-compose.yml +++ /dev/null @@ -1,17 +0,0 @@ -services: - github-actions-runner: - image: evl8/esd-github-actions-runner - environment: - - URL= - - TOKEN= - networks: - - esd - nexus: - image: sonatype/nexus:oss - ports: - - "8081:8081" - networks: - - esd -networks: - esd: - driver: bridge \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index 250421ce..00000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,29 +0,0 @@ -# base -FROM ubuntu:20.04 - -# set the github runner version -ARG RUNNER_VERSION="2.321.0" - -# update the base packages and add a non-sudo user -RUN apt-get update -y && apt-get upgrade -y && useradd -m docker - -RUN apt-get install curl -y - -# cd into the user directory, download and unzip the github actions runner -RUN cd /home/docker && mkdir actions-runner && cd actions-runner \ - && curl -O -L https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz \ - && tar xzf ./actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz - -# install some additional dependencies -RUN chown -R docker ~docker && /home/docker/actions-runner/bin/installdependencies.sh - -COPY docker-start.sh docker-start.sh - -RUN chmod +x docker-start.sh - -# since the config and run script for actions are not allowed to be run by root, -# set the user to "docker" so all subsequent commands are run as the docker user -USER docker - -# set the entrypoint to the start.sh script -ENTRYPOINT ["./docker-start.sh"] diff --git a/docker/docker-start.sh b/docker/docker-start.sh deleted file mode 100644 index c10bbcf4..00000000 --- a/docker/docker-start.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -cd /home/docker/actions-runner - -if ./run.sh | grep -q 'Runner listener exit with terminated error'; then - echo "Configuration missing. Running the config command." - # Place your conditional command here, for example: - ./config.sh --url $URL --token $TOKEN --unattended - ./run.sh -else - echo "Already configured." -fi - - - - diff --git a/exercise-4.yml b/exercise-4.yml new file mode 100644 index 00000000..067521ba --- /dev/null +++ b/exercise-4.yml @@ -0,0 +1,21 @@ +name: Deploy Static Site + +on: + push: + branches: + - gh-pages + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Deploy to GitHub Pages + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: assignments/exercise-4 + clean: true diff --git a/assignments/exercise-4/index.html b/index.html similarity index 100% rename from assignments/exercise-4/index.html rename to index.html