Created
November 28, 2015 02:36
-
-
Save koola/9c0e3740a11e9ce6ef4a to your computer and use it in GitHub Desktop.
Development environment build tools setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
powershell.exe -executionpolicy unrestricted -command "%~dp0\build.ps1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$installPath = (get-location).path | |
$apps = @{ | |
'jdk' = @{ | |
'path' = "$installPath\jdk"; | |
'32-bit' = 'http://download.oracle.com/otn-pub/java/jdk/7u25-b17/jdk-7u25-windows-i586.exe'; | |
'64-bit' = 'http://download.oracle.com/otn-pub/java/jdk/7u25-b17/jdk-7u25-windows-x64.exe' | |
}; | |
'nodejs' = @{ | |
'path' = "$installPath\nodejs"; | |
'32-bit' = 'http://nodejs.org/dist/v0.10.32/node.exe'; | |
'64-bit' = 'http://nodejs.org/dist/v0.10.32/x64/node.exe' | |
}; | |
'npm' = @{ | |
'path' = "$installPath\nodejs"; | |
'noarch' = 'http://nodejs.org/dist/npm/npm-1.4.9.zip' | |
}; | |
'maven' = @{ | |
'path' = "$installPath\maven"; | |
'noarch' = 'http://apache.mirror.serversaustralia.com.au/maven/maven-3/3.0.5/binaries/apache-maven-3.0.5-bin.zip' | |
} | |
} | |
function WebDownload([string]$src, [string]$dst, [string]$cookie='') { | |
if (Test-Path $dst) { | |
"Found '$dst', skipping..." | |
return | |
} | |
try { | |
"Downloading '$src' to '$dst'" | |
$wc = new-object System.Net.WebClient | |
$wc.Headers.Add([System.Net.HttpRequestHeader]::ContentType,"application/octet-stream") | |
if ($cookie) { | |
$wc.Headers.Add([System.Net.HttpRequestHeader]::Cookie,$cookie) | |
} | |
$proxy = New-Object System.Net.WebProxy($env:http_proxy) | |
$proxy.useDefaultCredentials = $true | |
$wc.Proxy = $proxy | |
$wc.DownloadFile($src, $dst) | |
} catch [Net.WebException],[System.IO.IOException] { | |
Write-Error "Failed to download $src" -ErrorAction stop | |
} | |
} | |
$arch = (gwmi Win32_OperatingSystem).OSArchitecture; | |
set-alias zip "$installPath\bin\7z.exe" | |
# main | |
foreach($app in $($apps.keys)) { | |
$url = if ($apps.$app.noarch) { $apps.$app.noarch } else { $apps.$app.$arch } | |
$filename = [System.IO.Path]::GetFileName($url) | |
$fileTemp = "$env:temp" | |
$filePath = "$fileTemp\$filename" | |
$appsHome = $apps.$app.path | |
mkdir "$appsHome" 2>&1> $null | |
"Installing $app..." | |
switch ($app) { | |
"jdk" { | |
WebDownload "$url" "$filePath" "oraclelicense=accept-securebackup-cookie" | |
zip e -y -r "-ir!111" "-o$fileTemp" "$filePath" > $null | |
zip e -y "-o$fileTemp" "$fileTemp\111" > $null | |
if (!(Test-Path "$fileTemp\tools.zip")) { | |
Write-Error "Failed to extract JDK" -ErrorAction stop | |
} | |
zip x -y "-o$appsHome" "$fileTemp\tools.zip" > $null | |
get-childitem "$appsHome" -include *.pack -recurse | foreach { | |
$file = $_.fullname.trimend(".pack") | |
& "$appsHome\bin\unpack200.exe" -r "$file.pack" "$file.jar" 2>&1> $null | |
} | |
} | |
"nodejs" { | |
WebDownload "$url" "$filePath" | |
mv "$filePath" "$appsHome" -force | |
} | |
"npm" { | |
WebDownload "$url" "$filePath" | |
zip x -y "-o$appsHome" "$filePath" > $null | |
} | |
"maven" { | |
WebDownload "$url" "$filePath" | |
zip x -y "-o$fileTemp" "$filePath" > $null | |
$workspace = "$fileTemp\{0}" -f $filename.TrimEnd('-bin.zip') | |
mv "$workspace\*" "$appsHome" -force | |
cp "bin\settings.xml" "maven\conf" -force | |
} | |
} | |
} | |
# Print versions | |
$cmdOut = (mvn -v 2>&1) | findstr /R "^Apache ^Java.ver" | |
" | |
Installed versions:" | |
"{0, -10}: {1}" -f "Java", ($cmdOut[1] -split ' ')[2] -replace ',','' | |
"{0, -10}: {1}" -f "Maven", ($cmdOut[0] -split ' ')[2] | |
"{0, -10}: {1}" -f "Node", (node -v) -replace 'v','' | |
"{0, -10}: {1}" -f "NPM", (npm -v) -replace 'v','' | |
# Clean up | |
#Get-Childitem $env:temp | Remove-Item -recurse -force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment