|
1 |
| -# ######################################################################### |
2 |
| -# ## Code common to scalac.bat, scaladoc.bat and scala.bat |
3 |
| - |
4 |
| -if ($env:JAVACMD) { |
5 |
| - $global:_JAVACMD = $env:JAVACMD |
6 |
| -} elseif ($env:JAVA_HOME) { |
7 |
| - $global:_JAVACMD = Join-Path $env:JAVA_HOME "bin\java.exe" |
8 |
| -} elseif ($env:JDK_HOME) { |
9 |
| - $global:_JAVACMD = Join-Path $env:JDK_HOME "bin\java.exe" |
10 |
| -} else { |
11 |
| - $javaPath = Get-Command java.exe -ErrorAction SilentlyContinue |
12 |
| - if ($javaPath) { |
13 |
| - $javaPathDir = Split-Path $javaPath -Parent |
14 |
| - if ($javaPathDir -notmatch "javapath") { |
15 |
| - $global:_JAVACMD = Join-Path $javaPathDir "java.exe" |
16 |
| - } |
| 1 | +################################################################################################### |
| 2 | +### POWERSHELL COMMON SCRIPT ### |
| 3 | +### ### |
| 4 | +### Author: Hamza REMMAL <[email protected]> ### |
| 5 | +### Since : Scala 3.5.0 ### |
| 6 | +################################################################################################### |
| 7 | + |
| 8 | + |
| 9 | +################################################################################################### |
| 10 | +######################################## UTILITY FUNCTIONS ######################################## |
| 11 | +################################################################################################### |
| 12 | + |
| 13 | +function Scala-GetJavaClasspathSeparator { |
| 14 | + if ($IsWindows) { |
| 15 | + return ';' |
| 16 | + } else { |
| 17 | + return ':' |
17 | 18 | }
|
| 19 | +} |
18 | 20 |
|
19 |
| - if (-not $global:_JAVACMD) { |
20 |
| - $programFilesJava = Join-Path $env:ProgramFiles "Java" |
21 |
| - $javaHome = Get-ChildItem -Path $programFilesJava -Directory -Filter "jre*" | Select-Object -First 1 |
22 |
| - if ($javaHome) { |
23 |
| - $global:_JAVA_HOME = $javaHome.FullName |
24 |
| - } else { |
25 |
| - $optPath = "C:\opt" |
26 |
| - $javaHome = Get-ChildItem -Path $optPath -Directory -Filter "jdk*" | Select-Object -First 1 |
27 |
| - if ($javaHome) { |
28 |
| - $global:_JAVA_HOME = Join-Path $javaHome.FullName "jre" |
| 21 | +function Scala-FetchScalaVersion { |
| 22 | + if (Test-Path $_VERSION_FILE) { |
| 23 | + foreach ($line in Get-Content $_VERSION_FILE) { |
| 24 | + if ($line.StartsWith("version:=")) { |
| 25 | + return $line.Substring(9) |
29 | 26 | }
|
30 | 27 | }
|
31 |
| - |
32 |
| - if ($global:_JAVA_HOME) { |
33 |
| - $global:_JAVACMD = Join-Path $global:_JAVA_HOME "bin\java.exe" |
34 |
| - } |
| 28 | + Write-Error "Error: 'VERSION' file does not contain 'version' entry in ($_VERSION_FILE)" |
| 29 | + } else { |
| 30 | + Write-Error "Error: 'VERSION' file is missing in ($_VERSION_FILE)" |
35 | 31 | }
|
36 | 32 | }
|
37 | 33 |
|
38 |
| -if (-not (Test-Path $global:_JAVACMD)) { |
39 |
| - Write-Error "Error: Java executable not found ($global:_JAVACMD)" |
40 |
| - $global:_EXITCODE = 1 |
41 |
| - exit $global:_EXITCODE |
| 34 | + |
| 35 | +################################################################################################### |
| 36 | +############################################ LOAD JAVA ############################################ |
| 37 | +################################################################################################### |
| 38 | + |
| 39 | +$javaPath = Get-Command java -ErrorAction SilentlyContinue |
| 40 | +if ($javaPath) { $_JAVACMD = $javaPath.Source } |
| 41 | + |
| 42 | +if (-not (Test-Path $_JAVACMD)) { |
| 43 | + Write-Error "Error: Java executable not found ($_JAVACMD)" |
| 44 | + exit 1 |
42 | 45 | }
|
43 | 46 |
|
44 |
| -if (-not $global:_PROG_HOME) { |
| 47 | +if (-not $_PROG_HOME) { |
45 | 48 | Write-Error "Error: Variable _PROG_HOME undefined"
|
46 |
| - $global:_EXITCODE = 1 |
47 |
| - exit $global:_EXITCODE |
| 49 | + exit 1 |
48 | 50 | }
|
49 | 51 |
|
50 |
| -$global:_ETC_DIR = Join-Path $global:_PROG_HOME "etc" |
| 52 | +################################################################################################### |
| 53 | +######################################## VARIOUS VARIABLES ######################################## |
| 54 | +################################################################################################### |
51 | 55 |
|
52 |
| -$global:_PSEP = ";" |
| 56 | +$_ETC_DIR = Join-Path $_PROG_HOME "etc" |
| 57 | +$_BIN_DIR = Join-Path $_PROG_HOME "bin" |
| 58 | +$_MVN_REPOSITORY = "file:///$($_PROG_HOME -replace '\\', '/')/maven2" |
| 59 | +$_VERSION_FILE = Join-Path $_PROG_HOME "VERSION" |
| 60 | +$_PSEP = Scala-GetJavaClasspathSeparator |
0 commit comments