From a5a93e08749d506757867e4df4fea9e093eb2176 Mon Sep 17 00:00:00 2001 From: Anthony-LT Date: Sat, 11 Oct 2025 13:32:01 +0200 Subject: [PATCH] Add files via upload --- LabWK4/HELP.md | 28 ++ LabWK4/mvnw | 295 ++++++++++++++++++ LabWK4/mvnw.cmd | 189 +++++++++++ LabWK4/pom.xml | 60 ++++ .../com/example/labwk4/LabWk4Application.java | 13 + .../labwk4/controller/greetController.java | 28 ++ .../com/example/labwk4/controller/time.java | 40 +++ .../example/labwk4/controller/weather.java | 40 +++ .../com/example/labwk4/service/timeS.java | 25 ++ .../com/example/labwk4/service/weatherS.java | 22 ++ .../src/main/resources/application.properties | 1 + .../labwk4/LabWk4ApplicationTests.java | 13 + LabWK4/target/classes/application.properties | 1 + .../example/labwk4/LabWk4Application.class | Bin 0 -> 743 bytes .../labwk4/controller/greetController.class | Bin 0 -> 1912 bytes .../com/example/labwk4/controller/time.class | Bin 0 -> 2110 bytes .../example/labwk4/controller/weather.class | Bin 0 -> 2322 bytes .../com/example/labwk4/service/timeS.class | Bin 0 -> 1171 bytes .../com/example/labwk4/service/weatherS.class | Bin 0 -> 937 bytes .../labwk4/LabWk4ApplicationTests.class | Bin 0 -> 541 bytes 20 files changed, 755 insertions(+) create mode 100644 LabWK4/HELP.md create mode 100644 LabWK4/mvnw create mode 100644 LabWK4/mvnw.cmd create mode 100644 LabWK4/pom.xml create mode 100644 LabWK4/src/main/java/com/example/labwk4/LabWk4Application.java create mode 100644 LabWK4/src/main/java/com/example/labwk4/controller/greetController.java create mode 100644 LabWK4/src/main/java/com/example/labwk4/controller/time.java create mode 100644 LabWK4/src/main/java/com/example/labwk4/controller/weather.java create mode 100644 LabWK4/src/main/java/com/example/labwk4/service/timeS.java create mode 100644 LabWK4/src/main/java/com/example/labwk4/service/weatherS.java create mode 100644 LabWK4/src/main/resources/application.properties create mode 100644 LabWK4/src/test/java/com/example/labwk4/LabWk4ApplicationTests.java create mode 100644 LabWK4/target/classes/application.properties create mode 100644 LabWK4/target/classes/com/example/labwk4/LabWk4Application.class create mode 100644 LabWK4/target/classes/com/example/labwk4/controller/greetController.class create mode 100644 LabWK4/target/classes/com/example/labwk4/controller/time.class create mode 100644 LabWK4/target/classes/com/example/labwk4/controller/weather.class create mode 100644 LabWK4/target/classes/com/example/labwk4/service/timeS.class create mode 100644 LabWK4/target/classes/com/example/labwk4/service/weatherS.class create mode 100644 LabWK4/target/test-classes/com/example/labwk4/LabWk4ApplicationTests.class diff --git a/LabWK4/HELP.md b/LabWK4/HELP.md new file mode 100644 index 0000000..0a7f2a0 --- /dev/null +++ b/LabWK4/HELP.md @@ -0,0 +1,28 @@ +# Getting Started + +### Reference Documentation + +For further reference, please consider the following sections: + +* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) +* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/3.5.6/maven-plugin) +* [Create an OCI image](https://docs.spring.io/spring-boot/3.5.6/maven-plugin/build-image.html) +* [Spring Boot DevTools](https://docs.spring.io/spring-boot/3.5.6/reference/using/devtools.html) +* [Spring Web](https://docs.spring.io/spring-boot/3.5.6/reference/web/servlet.html) + +### Guides + +The following guides illustrate how to use some features concretely: + +* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) +* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) +* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) + +### Maven Parent overrides + +Due to Maven's design, elements are inherited from the parent POM to the project POM. +While most of the inheritance is fine, it also inherits unwanted elements like `` and `` from the +parent. +To prevent this, the project POM contains empty overrides for these elements. +If you manually switch to a different parent and actually want the inheritance, you need to remove those overrides. + diff --git a/LabWK4/mvnw b/LabWK4/mvnw new file mode 100644 index 0000000..bd8896b --- /dev/null +++ b/LabWK4/mvnw @@ -0,0 +1,295 @@ +#!/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.4 +# +# 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:]' +} + +scriptDir="$(dirname "$0")" +scriptName="$(basename "$0")" + +# 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 <"$scriptDir/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in $scriptDir/.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${scriptName#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 + +# Find the actual extracted directory name (handles snapshots where filename != directory name) +actualDistributionDir="" + +# First try the expected directory name (for regular distributions) +if [ -d "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" ]; then + if [ -f "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/bin/$MVN_CMD" ]; then + actualDistributionDir="$distributionUrlNameMain" + fi +fi + +# If not found, search for any directory with the Maven executable (for snapshots) +if [ -z "$actualDistributionDir" ]; then + # enable globbing to iterate over items + set +f + for dir in "$TMP_DOWNLOAD_DIR"/*; do + if [ -d "$dir" ]; then + if [ -f "$dir/bin/$MVN_CMD" ]; then + actualDistributionDir="$(basename "$dir")" + break + fi + fi + done + set -f +fi + +if [ -z "$actualDistributionDir" ]; then + verbose "Contents of $TMP_DOWNLOAD_DIR:" + verbose "$(ls -la "$TMP_DOWNLOAD_DIR")" + die "Could not find Maven distribution directory in extracted archive" +fi + +verbose "Found extracted Maven distribution directory: $actualDistributionDir" +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$actualDistributionDir/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$actualDistributionDir" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/LabWK4/mvnw.cmd b/LabWK4/mvnw.cmd new file mode 100644 index 0000000..92450f9 --- /dev/null +++ b/LabWK4/mvnw.cmd @@ -0,0 +1,189 @@ +<# : 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.4 +@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 -eq $False) { "/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_M2_PATH = "$HOME/.m2" +if ($env:MAVEN_USER_HOME) { + $MAVEN_M2_PATH = "$env:MAVEN_USER_HOME" +} + +if (-not (Test-Path -Path $MAVEN_M2_PATH)) { + New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null +} + +$MAVEN_WRAPPER_DISTS = $null +if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) { + $MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists" +} else { + $MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists" +} + +$MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain" +$MAVEN_HOME_NAME = ([System.Security.Cryptography.SHA256]::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 + +# Find the actual extracted directory name (handles snapshots where filename != directory name) +$actualDistributionDir = "" + +# First try the expected directory name (for regular distributions) +$expectedPath = Join-Path "$TMP_DOWNLOAD_DIR" "$distributionUrlNameMain" +$expectedMvnPath = Join-Path "$expectedPath" "bin/$MVN_CMD" +if ((Test-Path -Path $expectedPath -PathType Container) -and (Test-Path -Path $expectedMvnPath -PathType Leaf)) { + $actualDistributionDir = $distributionUrlNameMain +} + +# If not found, search for any directory with the Maven executable (for snapshots) +if (!$actualDistributionDir) { + Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object { + $testPath = Join-Path $_.FullName "bin/$MVN_CMD" + if (Test-Path -Path $testPath -PathType Leaf) { + $actualDistributionDir = $_.Name + } + } +} + +if (!$actualDistributionDir) { + Write-Error "Could not find Maven distribution directory in extracted archive" +} + +Write-Verbose "Found extracted Maven distribution directory: $actualDistributionDir" +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$actualDistributionDir" -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/LabWK4/pom.xml b/LabWK4/pom.xml new file mode 100644 index 0000000..399db04 --- /dev/null +++ b/LabWK4/pom.xml @@ -0,0 +1,60 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.5.6 + + + com.example + LabWK4 + 0.0.1-SNAPSHOT + LabWK4 + LabWK4 + + + + + + + + + + + + + + + 21 + + + + 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/LabWK4/src/main/java/com/example/labwk4/LabWk4Application.java b/LabWK4/src/main/java/com/example/labwk4/LabWk4Application.java new file mode 100644 index 0000000..59c6a23 --- /dev/null +++ b/LabWK4/src/main/java/com/example/labwk4/LabWk4Application.java @@ -0,0 +1,13 @@ +package com.example.labwk4; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class LabWk4Application { + + public static void main(String[] args) { + SpringApplication.run(LabWk4Application.class, args); + } + +} diff --git a/LabWK4/src/main/java/com/example/labwk4/controller/greetController.java b/LabWK4/src/main/java/com/example/labwk4/controller/greetController.java new file mode 100644 index 0000000..dfa46b0 --- /dev/null +++ b/LabWK4/src/main/java/com/example/labwk4/controller/greetController.java @@ -0,0 +1,28 @@ +package com.example.labwk4.controller; + +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/hello") +public class greetController { + + @GetMapping + public String sayHello() { + return "Hello World!"; + } + + @GetMapping("/{name}") + public String sayHelloToName(@PathVariable String name) { + return "Hello " + name + "!"; + } + + @GetMapping("/add/{num1}/{num2}") + public String addNumbers(@PathVariable int num1, @PathVariable int num2) { + return "Sum: " + (num1 + num2); + } + + @GetMapping("/multiply/{num1}/{num2}") + public String multiplyNumbers(@PathVariable int num1, @PathVariable int num2) { + return "Product: " + (num1 * num2); + } +} diff --git a/LabWK4/src/main/java/com/example/labwk4/controller/time.java b/LabWK4/src/main/java/com/example/labwk4/controller/time.java new file mode 100644 index 0000000..64478b5 --- /dev/null +++ b/LabWK4/src/main/java/com/example/labwk4/controller/time.java @@ -0,0 +1,40 @@ +package com.example.labwk4.controller; + +import com.example.labwk4.service.timeS; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +@RestController +@RequestMapping("/time") +public class time { + private final timeS timeService; + + public time(timeS timeService) { + this.timeService = timeService; + } + + @GetMapping + public String getTime() { + return "Current time: " + timeService.getCurrentTime(); + } + + @GetMapping("/date") + public String getDate() { + return "Current date: " + timeService.getCurrentDate(); + } + + @GetMapping("/day") + public String getDay() { + return "Current day: " + timeService.getCurrentDayOfWeek(); + } + + @GetMapping("/all") + public Map getAllTimeInfo() { + return Map.of( + "time", timeService.getCurrentTime(), + "date", timeService.getCurrentDate(), + "day", timeService.getCurrentDayOfWeek() + ); + } +} \ No newline at end of file diff --git a/LabWK4/src/main/java/com/example/labwk4/controller/weather.java b/LabWK4/src/main/java/com/example/labwk4/controller/weather.java new file mode 100644 index 0000000..cfe2c05 --- /dev/null +++ b/LabWK4/src/main/java/com/example/labwk4/controller/weather.java @@ -0,0 +1,40 @@ +package com.example.labwk4.controller; + +import com.example.labwk4.service.weatherS; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +@RestController +@RequestMapping("/weather") +public class weather { + private final weatherS weatherService; + + public weather(weatherS weatherService) { + this.weatherService = weatherService; + } + + @GetMapping("/temperature") + public String getTemperature() { + return "Current temperature: " + weatherService.getCurrentTemperature() + "°C"; + } + + @GetMapping("/condition") + public String getCondition() { + return "Current weather: " + weatherService.getWeatherCondition(); + } + + @GetMapping("/wind") + public String getWindSpeed() { + return "Current wind speed: " + weatherService.getWindSpeed() + " km/h"; + } + + @GetMapping("/all") + public Map getAllWeather() { + return Map.of( + "temperature", weatherService.getCurrentTemperature(), + "condition", weatherService.getWeatherCondition(), + "windSpeed", weatherService.getWindSpeed() + ); + } +} \ No newline at end of file diff --git a/LabWK4/src/main/java/com/example/labwk4/service/timeS.java b/LabWK4/src/main/java/com/example/labwk4/service/timeS.java new file mode 100644 index 0000000..f54fc34 --- /dev/null +++ b/LabWK4/src/main/java/com/example/labwk4/service/timeS.java @@ -0,0 +1,25 @@ +package com.example.labwk4.service; + +import org.springframework.stereotype.Service; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.DayOfWeek; + +@Service +public class timeS { + + public String getCurrentTime() { + return LocalDateTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss")); + } + + public String getCurrentDate() { + return LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); + } + + public String getCurrentDayOfWeek() { + DayOfWeek day = LocalDate.now().getDayOfWeek(); + return day.toString(); + } +} \ No newline at end of file diff --git a/LabWK4/src/main/java/com/example/labwk4/service/weatherS.java b/LabWK4/src/main/java/com/example/labwk4/service/weatherS.java new file mode 100644 index 0000000..31f3a0e --- /dev/null +++ b/LabWK4/src/main/java/com/example/labwk4/service/weatherS.java @@ -0,0 +1,22 @@ +package com.example.labwk4.service; + +import org.springframework.stereotype.Service; +import java.util.Random; + +@Service +public class weatherS { + private final Random random = new Random(); + + public int getCurrentTemperature() { + return random.nextInt(51) - 10; + } + + public String getWeatherCondition() { + String[] conditions = {"Sunny", "Rainy", "Cloudy", "Windy"}; + return conditions[random.nextInt(conditions.length)]; + } + + public int getWindSpeed() { + return random.nextInt(101); + } +} \ No newline at end of file diff --git a/LabWK4/src/main/resources/application.properties b/LabWK4/src/main/resources/application.properties new file mode 100644 index 0000000..f88f583 --- /dev/null +++ b/LabWK4/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=LabWK4 diff --git a/LabWK4/src/test/java/com/example/labwk4/LabWk4ApplicationTests.java b/LabWK4/src/test/java/com/example/labwk4/LabWk4ApplicationTests.java new file mode 100644 index 0000000..b04b41c --- /dev/null +++ b/LabWK4/src/test/java/com/example/labwk4/LabWk4ApplicationTests.java @@ -0,0 +1,13 @@ +package com.example.labwk4; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class LabWk4ApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/LabWK4/target/classes/application.properties b/LabWK4/target/classes/application.properties new file mode 100644 index 0000000..f88f583 --- /dev/null +++ b/LabWK4/target/classes/application.properties @@ -0,0 +1 @@ +spring.application.name=LabWK4 diff --git a/LabWK4/target/classes/com/example/labwk4/LabWk4Application.class b/LabWK4/target/classes/com/example/labwk4/LabWk4Application.class new file mode 100644 index 0000000000000000000000000000000000000000..251584ea4cb09d59bf251fed898f21a68b057175 GIT binary patch literal 743 zcma)4O;6iE5Ph2u96~4|l(e+;P^qdy4(tW>5`+YidNOU*RN>Im+HA}cdpBCI3xA6f zRS*1t{wTz(i-aX|s3p&6zTV8fnZNgc?f@L)T^lvj12j5lVuhi5DSio_3Z3w;(WQ(X z!^)x3${jJ(2Yb^1Ert)V$+)~0*&>yc8(qy0cqpQ?`N8pGk*ZiYWpo>DtOe+Fu#OiD zLt_)3FRaqZ%!*8289V2ZF^*44XQh%l*+Mf!gYapZaVqkB^t0lbI1e`33zs3sMmu@! z_}J)~N(w8YR90G$+lNOCjj=hG3>%@+@=K9L(*E$d4873ABAp7Wy#45GxC@mtd<_4G z0gs*uMK9?OmJL3oxUdP~Z7m7YE>5MpFz4Td=gUb;iS3CgY%D)3KVknF=lh;7hMn() zb}Exol`H>lt&J;pLI_7o=_(f?3TKG7k}vtVmJ`}gg|`vjBcO}%Uk%LP49N|$IB7<@ zIlKkCDZ^coJ`5_^B-#0wfF8EUTE$Cj6NoSVRDuDmUNHQP)w8F1f1aRA3b0neXrYf+ XrisZvlCJIHDc{%2uXW_NS1QCQm2n1TfyF>} zRb7WIX%16Tbb zgPyO*xVhh5cUw9%k@kHRxx0~4h79_$K%uVNN?@kph3Z8TG*z@Mn?5y_hHgoJM@F8N z`^tjpc;xLiJ}62}pcu=8v_1lJ)iDVOEWJuX;{|HRi#-N>6o%SJkS?4x^d4I z=%+{qYF|fPcV9K#rWdwdIk0t~D)U_SdbW_P*-_AK{en(RHcYq5Xo=b5=gM?+dsA9` zqauc#*pq%jH^=?eI=&OQe3InA_ypTK@6C2on$A&$$+sli?W_k3zEIs5*J+zX65JLL z8`*J46o2@>CUJ^x^Uxac0KPTQ8YbP~1H6VEn&?$jN*Wv{5f-S^Jw zm5PV181woN*Pj!5AGdJQ?bxYedmd|TViU<;)~C3LuXwGpnG-8Te9f8MN`iaKqKI!; z%gso)la`@8Gl_3YxQCj9`*w=H6S#6bc3!xryUNX`FPqXQvSoC1An@DpeD)2q@Xut} z_EmhPp>;Ru)kZJWkmiKr_CZgLF@G~;pFJ@r9)dnZUHbl(XB2B%-Uve#)qNSqDt7R_ zz}1nQ#!+?fSm4rso3fHwURc37zJ&HS!8eF+A=i&6x!i@-UjGx~4<2%u<7z(x4(7R* zGXpGOk&?j2SfZ76zDdd2UuHoAMkBahJNabX`x^J9xk^C2Ak?zqXF0e*s^I By{-TN literal 0 HcmV?d00001 diff --git a/LabWK4/target/classes/com/example/labwk4/controller/time.class b/LabWK4/target/classes/com/example/labwk4/controller/time.class new file mode 100644 index 0000000000000000000000000000000000000000..30820fb379e16a1985962db82f2f82188893a61b GIT binary patch literal 2110 zcmb_c+fo}x5IrL#Ruap_Lg5l(gE2S)C*E90>{x^Zi(r!o;~*j`<)@J}h_zNb%I*ll zL;fS5kyPbYJmdrNQLgmtF45W&v0detnd$E7Gu@}V=bvZie*@UWVHODt8AzH)VVGg! zDL>(s!`-H}S9>bzieY%&c5Su6FjQEnW{^h4K-RMO`MR+H6outL`03ScJ1`d^C7GoGUFk#{fatsSEb6^;23RUWQo^aJc z@MgZSQtqWvQJ(EKi#bX;Z{jUXF-*64OO&Kr=jzZ_$8_=)ca_g@v(WE3089rtV`5fE z7<+z;E0F_3UfbU>aaG$Vd*N;Iv%RB3AzC>iKA*+{LsIjT#v+{>$go^^c{x|AlvznOsQBY$ z+ZB(x?V9ioc+DYAt}N@^sdCTOa->YEW1A|mGzj~J_M#Xjc7-~YjmO;MZJ~rmo(2&f zHp1+F*VX)1ZQrH`HeFXLu52nd!&+H-P0R1-<~Y*Mr_yU#r=n)nY`0rG4$W~<6tBY-0bDPnL-_~uzaQBsS-50*1afoJ^pkK%Jhc0>d zs7gg&z{Gtim9ISB32Wu2u}$3&jqHMs^WFkW<6%sxDGiig6Ok7;iB{5$52KvLE*=@! z)ARh8dZjn*wtFI5!V2jMM|_*tmGr10KgZ`Kx)_G^kh={>_)BFeTis54i28Yd&hg-^ zBL-Z5601`*hVfq{f+$hdDz*|tv$^BC!Yeu4_l0kuLc`UU)1Xide8+I@|F2SOhI!#S zec%cD2Wj&37fz=Xom03)+V@D>rd`{!tAB#6-ufNJuOub#KCNRIqIDEWI%P19+ayhe zw_)J}lE^PWW%!WJDf;_qWB7<33*qmO#7H-~`WuWtFnW$j;1^PaFAN99$pG05FGk28 z(;aPH3jja43~>4!Z}$VvTmm>205W{~1k8ty?e1m3bLY6$4}A5NfIlPPdnginn&Iz* zJb?M!d_+R-dU%-5-3SkJe_^>t$`q9cSR}U_MEVkDu#7p9HT@w;^ASnwq)Fg&XtJKq wZG(#TMPU6hu+3$rg_i{v~7`3>p53f2d~x`S`Yk|pgv4p7DHzYDzwN&o-= literal 0 HcmV?d00001 diff --git a/LabWK4/target/classes/com/example/labwk4/controller/weather.class b/LabWK4/target/classes/com/example/labwk4/controller/weather.class new file mode 100644 index 0000000000000000000000000000000000000000..39480c9d127afabe9b80d36c71094197c1f57d9d GIT binary patch literal 2322 zcmb_dTUQ%Z6#fnnCWPVAK%t<;$fXTbJ6=#~L6k;m(NHQuQ1LcNPQx^lnK*L-_QC(* z&!}rz?c%`)AN^4-zsXF<(4;P0%ZHgcXW!1=-?z`6zy3b`1HcBpPoW3B8v1l3&@V9h z$UHU;+jJ_%PVtc}DS`eq%dynDKyP+&e*j4gXh`W8gf6g9a%+bC(X7>NNw4Bbb=fGn zj`CdFmY#7UO?4zaf#GOXklwLXl61^>@$^G&%dN1Q!Z1cOjOw_Aw7}d2d;~66q{=ls zPdaK(*6PwTRm0y%7&V5uXnd}TVyXN2t5V!jPTL3x%_ zX(n?;#}uXo#(2g-SRDPzma<$&U_9H!Ee(N}gCnmBT+4Qb?cx%Y{fdrEP_rJKWI5$R zUCMHrWQ`{=CorhmrKPZdYZ|WW$YN38Qakf4N6AWnzjkce4Y~7BVB&mjk;Q5fHv|Sq zU06#JuXB6SI(HBT-q7%-j<@i(z)fZk@p+5qV)F6qD@IU@0Lt^-}J0t9|`-^k;SIC-Yq-_FJM{fCn>6taDq(|prvUsi;r*<2TvTAbQ@+}^<;W(}`gD#@+a^CeShF=f5?qLw) z#PzDY6h)&*LJafF*0?Jb38)9%DUfJ#%#JZ)y%9E0tVdJ9{cJUC!U!lPp-gYXwxf<_ z3$+?KhVMYZsyNYAT6tc-7GpZPE-^{O{W_EEGfdkSNEO_MSCX4nfVv(HhnqoL3EaAH z`Mc6rEG=Sy(f^C<4-I;^(Mz_b4*9#|y2@9cSr3Wylh_fMie^eChVJc*`146FiO<+N zEp=23RY?>CrqAR=I^zeon5s;*W*m+5rf#Wf_*P)%-%a^13hTnF{0;SRmJ|2jN5oZv>jai5eTTbE zegl1K>34{w8&9GA!d(yE<$D;td=H_Is{xE)g}aH+8n^Hscl2vU6}ZiHg432CfmKY? zEC|2Co#1z9=~rmKVdxZNz!M6>6Z)IVv1VjFG>jsz(Po&E_xY?JLiqTAs}Elkc=8l4 zbq2n2p}-pqoOw~;nNvd8k@3|F1-`?;IebJE11P>jSnWc3HUi@r=F>~zdNTc5xR{~v z8E&>Anjl%gES={_;XKP+U`DgC1QsI5K5oLgiB9P5lEQmU?N(D8{2f2x{?jvX^VsHo aoT=_ncE9<4(0uRWD{4}d9^xAoG4&6Ynotb@ literal 0 HcmV?d00001 diff --git a/LabWK4/target/classes/com/example/labwk4/service/timeS.class b/LabWK4/target/classes/com/example/labwk4/service/timeS.class new file mode 100644 index 0000000000000000000000000000000000000000..def26bf61f8cbcac796c4d8b4a23ebccd55b6a95 GIT binary patch literal 1171 zcmah}T~pIQ6g^7|DKQo-P()Nd{A!C3KTxrCoMGrNJOptpgU{P`TSJ>HlWf8MD}6!6 z2Y-M+%JFUjZDe4~!|vYQvuE!)dpE!T{QL!A6BQF9NEt|57{wUFd z8j4};o$I^mJwvKcJTQ^LxB=6`4Ok4b5nQ>RupQap-6~gNpCSVL@`Pc&P;{<=R5Hji zWOjDSo>vY-6O*`QAZK9;(+tbQT`d`ST-g`Y+fk@Qz%VXbAGxBT&#+O54~kN+slfHy zmE_siv5)~7LS?Z^)Aii zBE<(haCLk>nO0xikgnJHA8~~tOKP`zK_Gk;*HmIcR|6>;(<6?dlxONW_}HC5E|AJzvKMZs=0Ro4zj{{$f1xr|=C#AnMn0{2$u2N)E&!`_Q{Q&z;gAuGztCvB=VpD6y06fEUiWpv? zM6KTZn$Q|&ox#Z6Jj28(X1-CJ840=skPd>(;=VFi7jOjy2gL%eVv*rtFOGb1%A?^x z5U_i4wBe70K9)VmG40A!E)L9-C3U|1);Vsf>4&o%F_ztD_r3%l8)Qm&Hu-KMLyh)<2(7U`l zpp4g!dwj6RwY2w1GG`9th+(b$AAM~yEcbvqBnm7PQx z8HqhPlGNU|QnBII0MV=MSoi(W&`$G%=8-sw^^rd^LW|g(4TT@18{EWw+IEJX5KYVO zo1z@W^oHoXOSdg#DFRCMbFlgkIGuAWe1-d&av9vC)4n{=igUv9nll*R%pDP$s0A;Bl8k_1ET((eYhLc zD<&p-u!lFDH}6fS^ZxPr24H~QI!Y+lP-$WfRfhIVJP95PJ>|FIOh%TWdaksx7Yya2 z?zo0^hHhjME|(%nV@cX@G4Jz0g!l9QAWdTx39F1A$=v1)l`Aum46Q(Ec~c~z%tj)N ziRlC;67g7M%H=DvVjmTmdcnV6IAdr=Mq9bGfe{lj@7)#Jszi=euBh`sYh(RHR67Vv zHs!N|K17%*D>E)q#oe&fsXjDC7RhVn2HgMqODAqa45z+Ro@Po32KJ