@@ -18,7 +18,7 @@ $ErrorActionPreference = "Stop"
1818
1919# See https://github.com/docToolchain/docToolchain/releases for available versions.
2020# Set DTC_VERSION to " latest" to get the latest, yet unreleased version.
21- $DTC_VERSION = " 3.2.1 "
21+ $DTC_VERSION = " 3.2.2 "
2222if ($env:DTC_VERSION) { $DTC_VERSION = $env:DTC_VERSION }
2323
2424#here you can specify the URL of a theme to use with generateSite-task
@@ -80,11 +80,12 @@ function main($_args) {
8080
8181 if (is_supported_environment $_args[0] -And assert_environment_available $_args[0] $DTC_VERSION) {
8282 # User enforced environment
83- $environment= $_args[0]
83+ $environment = $_args[0]
8484 # shift 1
8585 $null, $_args = $_args
8686 assert_argument_exists $_args
87- } else {
87+ }
88+ else {
8889 $environment = get_environment $_args
8990 }
9091 Write-Output " Using environment: $environment"
@@ -93,21 +94,23 @@ function main($_args) {
9394 # shift 1
9495 $null, $_args = $_args
9596 install_component_and_exit $environment $_args
96- } elseif ( $_args[0] -eq " getJava" ) {
97+ }
98+ elseif ( $_args[0] -eq " getJava" ) {
9799 # TODO: remove getJava in the next major release
98100 Write-Warning " Warning: 'getJava' is deprecated and and will be removed. Use './dtcw install java' instead."
99101 install_component_and_exit $environment " java"
100102 }
101103 # No install command, so forward call to docToolchain but first we check if
102104 # everything is there.
103105 $docker_image_name = " "
104- if ($environment -ne " docker " )
105- {
106+ $docker_extra_arguments = " "
107+ if ($environment -ne " docker " ) {
106108 assert_doctoolchain_installed " $environment" " $DTC_VERSION"
107109 assert_java_version_supported
108110 # TODO: what if 'doctoolchain' found by $PATH does not match the one from the local environment?
109111 # The version provided by $DTC_VERSION could be a different one.
110- } else {
112+ }
113+ else {
111114 $docker_image_name = " doctoolchain/doctoolchain"
112115 if ( $_args[0] -eq " install" ) {
113116 # shift 1
@@ -118,11 +121,20 @@ function main($_args) {
118121 assert_argument_exists $_args
119122 }
120123 Write-Output " Using docker image: $docker_image_name"
124+ if ($args[0] -eq " extra_arguments" ) {
125+ # shift 1
126+ $null, $_args = $_args
127+ $docker_extra_arguments = $args[0]
128+ # shift 1
129+ $null, $_args = $_args
130+ assert_argument_exists $args
131+ Write-Host " Extra arguments passed to docker run $docker_extra_arguments"
132+ }
121133 }
122134 # TODO: can generateDeck, bakePreview be used in combination with other commands?
123135 # The code below assumes we have just one task.
124136
125- $global:command = build_command " $environment" " $DTC_VERSION" " $docker_image_name" $_args
137+ $global:command = build_command " $environment" " $DTC_VERSION" " $docker_image_name" " $docker_extra_arguments " $_args
126138
127139 #TODO: implement HEADLESS mode
128140 # [[ " ${DTC_HEADLESS}" = true ]] && echo " Using headless mode since there is no (terminal) interaction possible"
@@ -183,10 +195,11 @@ Use './dtcw.ps1 tasks' to see all tasks.
183195function print_version_info() {
184196 Write-Host " dtcw ${DTCW_VERSION} - ${DTCW_GIT_HASH}"
185197 if (is_doctoolchain_development_version ${DTC_VERSION}) {
186- $dtc_git_hash= " unknown"
187- $dtc_git_hash= (git -C " $DTC_HOME" rev-parse --short=8 HEAD 2 > $null)
198+ $dtc_git_hash = " unknown"
199+ $dtc_git_hash = (git -C " $DTC_HOME" rev-parse --short=8 HEAD 2 > $null)
188200 Write-Host " docToolchain ${DTC_VERSION} - ${dtc_git_hash}"
189- } else {
201+ }
202+ else {
190203 Write-Host " docToolchain ${DTC_VERSION}"
191204 }
192205 Write-Host " OS/arch: pwsh $os $arch"
@@ -205,7 +218,8 @@ function get_available_environments() {
205218function has($global:command) {
206219 if (Get-Command docker -ErrorAction SilentlyContinue) {
207220 return $True
208- } else {
221+ }
222+ else {
209223 return $False
210224 }
211225}
@@ -219,7 +233,7 @@ function get_dtc_installations($envs, $version) {
219233
220234 if ($envs.Contains(" docker" )) {
221235 # Having docker installed means docToolchain is available
222- $installations+= " docker"
236+ $installations += " docker"
223237 }
224238
225239 #TODO: was bedeutet das?
@@ -239,12 +253,12 @@ function is_supported_environment($environment) {
239253
240254function assert_environment_available($environment, $version) {
241255 # If environment not available, exit with error
242- if ((is_environment_available $environment) -eq $False)
243- {
256+ if ((is_environment_available $environment) -eq $False) {
244257 Write-Error " argument error - environment '$environment' not available"
245258 if ($environment -eq " sdk" ) {
246259 Write-Output " sdkman is not supported on windows"
247- } else {
260+ }
261+ else {
248262 # docker
249263 Write-Output " Install 'docker' on your host to execute docToolchain in a container."
250264 }
@@ -266,7 +280,8 @@ function is_doctoolchain_development_version($version) {
266280 # Alternatives: 'testing', 'dev' (used for development)
267281 if ( ($version -eq " latest" ) -Or ($version -eq " latestdev" ) ) {
268282 return $True
269- } else {
283+ }
284+ else {
270285 return $False
271286 }
272287}
@@ -354,16 +369,19 @@ function local_install_doctoolchain($version) {
354369 if (Test-Path " $DTC_HOME/.git" ) {
355370 Invoke-Expression " git -C " " $DTC_HOME" " pull"
356371 Write-Output " Updated docToolchain in local environment to latest version"
357- } else {
372+ }
373+ else {
358374 if ($version -eq " latest" ) {
359375 Invoke-Expression " git clone " " ${GITHUB_PROJECT_URL}.git" " " " $DTC_HOME" " "
360- } else {
376+ }
377+ else {
361378 # TODO: derive the ssh URL from GITHUB_PROJECT_URL
362379 Invoke-Expression " git clone git@github.com:docToolchain/docToolchain.git " " $DTC_HOME" " "
363380 }
364381 Write-Output " Cloned docToolchain in local environment to latest version"
365382 }
366- } else {
383+ }
384+ else {
367385 New-Item -Path ${DTC_ROOT} -ItemType " directory" -Force > $null
368386 if ($proxy) {
369387 # Pass Proxy-Settings to Gradle
@@ -379,26 +397,29 @@ function local_install_doctoolchain($version) {
379397 }
380398 # Use Proxy for downloading the distribution
381399 Invoke-WebRequest $distribution_url -OutFile " ${DTC_ROOT}\source.zip" -Proxy $proxy -ProxyUseDefaultCredentials
382- } else {
400+ }
401+ else {
383402 Invoke-WebRequest $distribution_url -OutFile " ${DTC_ROOT}\source.zip"
384403 }
385404 Expand-Archive -Force -LiteralPath " ${DTC_ROOT}\source.zip" -DestinationPath " ${DTC_ROOT}\"
386405 Remove-Item " ${DTC_ROOT}\source.zip" # << Remove .zip ?
387406 if ($global:os -eq " windows" ) {
388407 $global:command = " &'${DTC_ROOT}\docToolchain-$DTC_VERSION\bin\doctoolchain.bat' . $global:commandArgs $DTC_OPTS"
389- } else {
408+ }
409+ else {
390410 $global:command = " &'${DTC_ROOT}\docToolchain-$DTC_VERSION\bin\doctoolchain' . $global:commandArgs $DTC_OPTS"
391411 }
392412 Write-Output " Installed docToolchain successfully in '${DTC_HOME}'."
393413 }
394414 # Add it to the existing installations so the output to guide the user can adjust accordingly.
395- $dtc_installations+= " local"
415+ $dtc_installations += " local"
396416}
397417
398418function assert_git_installed($message) {
399419 if (has git) {
400420 return
401- } else {
421+ }
422+ else {
402423 Write-Warning " git - command not found"
403424 Write-Warning $message
404425 exit $ERR_DTCW
@@ -451,7 +472,8 @@ function assert_java_version_supported() {
451472unsupported Java version ${javaversion} [$JAVA_CMD]
452473" @
453474 java_help_and_die
454- } else {
475+ }
476+ else {
455477 if ([int]$javaversion -gt 17 ) {
456478 Write-Warning @ "
457479unsupported Java version ${javaversion} [$JAVA_CMD]
@@ -463,8 +485,7 @@ unsupported Java version ${javaversion} [$JAVA_CMD]
463485 return
464486}
465487
466- function java_help_and_die()
467- {
488+ function java_help_and_die() {
468489 Write-Host @ "
469490docToolchain supports Java versions 11, 14 or 17 (preferred). In case one of those
470491Java versions is installed make sure 'java' is found with your PATH environment
@@ -499,30 +520,31 @@ function local_install_java() {
499520
500521 switch ($global:arch) {
501522 'x86_64' { $global:arch = " x64" }
502- 'arm64' { $global:arch = " aarch64" }
523+ 'arm64' { $global:arch = " aarch64" }
503524 }
504525 if ( ${os} -eq " MINGW64" ) {
505526 Write-Error " MINGW64 is not supported, Please use powershell or WSL"
506527 }
507528 switch ($global:os) {
508- 'Linux' { $global:os = 'linux' }
509- 'Darwin' { $global:os = 'max' }
529+ 'Linux' { $global:os = 'linux' }
530+ 'Darwin' { $global:os = 'max' }
510531 'Cygwin' { $global:os = 'linux' }
511532 }
512- if ($global:os -eq 'windows') { $targetFile = 'jdk.zip'} else { $targetFile = 'jdk.tar.gz'}
533+ if ($global:os -eq 'windows') { $targetFile = 'jdk.zip' } else { $targetFile = 'jdk.tar.gz' }
513534
514- if(!(Test-Path -Path $DTC_JAVA_HOME )){
535+ if (!(Test-Path -Path $DTC_JAVA_HOME )) {
515536 New-Item -ItemType directory -Path $DTC_JAVA_HOME > $null
516537 }
517538 Write-Output " Downloading JDK Temurin $version [$global:os/$global:arch] from Adoptium to $DTC_JAVA_HOME/${targetFile}"
518- $adoptium_java_url= " https://api.adoptium.net/v3/binary/latest/$version/$releasetype/$global:os/$global:arch/$imagetype/$implementation/$heapsize/eclipse?project=jdk"
539+ $adoptium_java_url = " https://api.adoptium.net/v3/binary/latest/$version/$releasetype/$global:os/$global:arch/$imagetype/$implementation/$heapsize/eclipse?project=jdk"
519540 download_file " $adoptium_java_url" " $DTC_JAVA_HOME/${targetFile}"
520541 Write-Output " Extracting JDK from archive file."
521542 # TODO: should we not delete a previsouly installed on?
522543 # Otherwise we may get a mix of different Java versions.
523544 if ($global:os -eq 'windows') {
524545 Expand-Archive -Force -LiteralPath " $DTC_JAVA_HOME\${targetFile}" -DestinationPath " $DTC_JAVA_HOME"
525- } else {
546+ }
547+ else {
526548 tar -zxf " ${DTC_JAVA_HOME}/${targetFile}" --strip 1 -C " ${DTC_JAVA_HOME}/."
527549 }
528550 Remove-Item " $DTC_JAVA_HOME\${targetFile}"
@@ -562,7 +584,7 @@ Java runtime (major version 11, 14 or 17) installed on your host.
562584" @
563585}
564586
565- function build_command($environment, $version, $docker_image, $_args) {
587+ function build_command($environment, $version, $docker_image, $docker_extra_arguments , $ _args) {
566588 $cmd = " "
567589 if ( $environment -eq " docker" ) {
568590 if (-not (Invoke-Expression " docker ps" )) {
@@ -575,20 +597,28 @@ function build_command($environment, $version, $docker_image, $_args) {
575597 Write-Output " "
576598 exit 1
577599 }
578- $container_name= " doctoolchain-${version}-$(date -uFormat '+%Y% m%d_% H%M% S')"
600+ $container_name = " doctoolchain-${version}-$(Get- date -uFormat '+%Y% m%d_% H%M% S')"
579601 $docker_cmd = Get-Command docker
580602
603+ $docker_env_file = " dtcw_docker.env"
604+ $env_file_option = " "
605+ if (Test-Path $docker_env_file) {
606+ $env_file_option = " --env-file ${docker_env_file}"
607+ }
608+
581609 # TODO: DTC_PROJECT_BRANCH is not passed into the docker environment
582610 # See https://github.com/docToolchain/docToolchain/issues/1087
583- $docker_args = " run --rm -i --name ${container_name} -e DTC_HEADLESS=1 -e DTC_SITETHEME -e DTC_PROJECT_BRANCH=${DTC_PROJECT_BRANCH} --entrypoint /bin/bash -v '${PWD}:/project' ${docker_image}:v${version}"
611+ $docker_args = " run --rm -i --name ${container_name} -e DTC_HEADLESS=1 -e DTC_SITETHEME -e DTC_PROJECT_BRANCH=${DTC_PROJECT_BRANCH} $docker_extra_arguments $env_file_option --entrypoint /bin/bash -v '${PWD}:/project' ${docker_image}:v${version}"
584612 $cmd = " $docker_cmd ${docker_args} -c " " doctoolchain . $_args ${DTC_OPTS} && exit " " "
585613
586- } else {
614+ }
615+ else {
587616 if ( $environment -eq " local" ) {
588617 if ($global:os -eq " windows" ) {
589- $cmd=" ${DTC_HOME}/bin/doctoolchain.bat . $_args ${DTC_OPTS}"
590- } else {
591- $cmd=" ${DTC_HOME}/bin/doctoolchain . $_args ${DTC_OPTS}"
618+ $cmd = " ${DTC_HOME}/bin/doctoolchain.bat . $_args ${DTC_OPTS}"
619+ }
620+ else {
621+ $cmd = " ${DTC_HOME}/bin/doctoolchain . $_args ${DTC_OPTS}"
592622 }
593623 }
594624 }
@@ -600,13 +630,13 @@ function show_os_related_info() {
600630}
601631
602632# Location where local installations are placed.
603- $DTC_ROOT= " $HOME/.doctoolchain"
633+ $DTC_ROOT = " $HOME/.doctoolchain"
604634
605635# More than one docToolchain version may be installed locally.
606636# This is the directory for the specific version.
607- $DTC_HOME= " $DTC_ROOT/docToolchain-$DTC_VERSION"
637+ $DTC_HOME = " $DTC_ROOT/docToolchain-$DTC_VERSION"
608638
609639# Directory for local Java installation
610- $DTC_JAVA_HOME= " $DTC_ROOT/jdk"
640+ $DTC_JAVA_HOME = " $DTC_ROOT/jdk"
611641
612642main $args
0 commit comments