diff --git a/run.ps1 b/run.ps1 new file mode 100644 index 0000000..e723171 --- /dev/null +++ b/run.ps1 @@ -0,0 +1,37 @@ +<# +.SYNOPSIS + Runs the solution of a specific exercise. +.DESCRIPTION + This script runs the solution of a specific exercise. +.PARAMETER Vorlesung + The number of the lecture to run the solution. +.PARAMETER Aufgabe + The number of the exercise to run the solution. +.EXAMPLE + Run the solution of exercise 1 of lecture 12. + .\Run -Vorlesung 12 -Aufgabe 1 +#> +param( + [UInt16]$Vorlesung, + [Uint16]$Aufgabe +) + +if ((-not (Get-Command java -ErrorAction SilentlyContinue)) -or (-not (Get-Command javac -ErrorAction SilentlyContinue))) { + throw "Java is not installed. Please install Java." +} + +$formatVorlesung = '{0:d2}' -f $Vorlesung +$formatAufgabe = '{0:d2}' -f $Aufgabe + +Write-Host "Vorlesung $formatVorlesung / Aufgabe $formatAufgabe" + +$folderPathAufgabe = "VL$formatVorlesung/Aufgabe$formatAufgabe" +$filePathAufgabe = "$folderPathAufgabe/Aufgabe$formatAufgabe.java" + +if (Test-Path $folderPathAufgabe -PathType Container) { + Get-ChildItem -path $folderPathAufgabe -Filter *.java -File | ForEach-Object { &"javac" $_.FullName} +} + +if (Test-Path $filePathAufgabe -PathType Leaf) { + java $filePathAufgabe.Replace('/', '.').Replace('.java', '') +} \ No newline at end of file