Skip to content

Instantly share code, notes, and snippets.

@thexmeta
Last active May 22, 2022 17:58
Show Gist options
  • Save thexmeta/bf08807883d9611166f1f6a52cbee72e to your computer and use it in GitHub Desktop.
Save thexmeta/bf08807883d9611166f1f6a52cbee72e to your computer and use it in GitHub Desktop.
Download and install latest eclipse jee
Find-Module -Name Recycle | Install-Module
Import-Module Recycle
$Log = "$(Split-Path $MyInvocation.MyCommand.Path)\Error-$(Get-Date -format 'MMddyy-hhmm').log"
$myURI = "https://download.eclipse.org/technology/epp/downloads/release/release.xml"
$doc = New-Object System.Xml.XmlDocument
$doc.Load($myURI)
# [xml]$doc = (New-Object System.Net.WebClient).DownloadString($myURI)
$presentversion = $doc.packages.present
$presentfixed = $presentversion -replace "/","-"
$presentfile = "eclipse-jee-${presentfixed}-win32-x86_64.zip"
$downladuri = "https://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/${presentversion}/${presentfile}&r=1"
$presentfilename = [System.IO.Path]::GetFileNameWithoutExtension($presentfile)
$destfolder = [System.Environment]::GetEnvironmentVariable('CTEMP', 'Machine') #$env:CTEMP
$eclipsefolder = Join-Path $destfolder $presentfilename #"D:\Developer\Eclipse"
$destfile = Join-Path $destfolder $presentfile
try
{
# Clean Eclipse Folder
Remove-ItemSafely -Recurse -Force -Path $eclipsefolder
$request = [System.Net.WebRequest]::Create($downladuri)
$response=$request.GetResponse()
If ($response.StatusCode -eq "OK")
{
$sourcefilesize = $response.GetResponseHeader("Content-Length")
if ($sourcefilesize -and $sourcefilesize -gt 0)
{
if (Test-Path -Path ($destfolder))
{
$destfilesize = (Test-Path -Path $destfile -PathType Leaf) ? (Get-Item $destfile).Length : 0
}
else
{
New-Item -ItemType Directory -Force -Path $destfolder
$destfilesize = 0
}
if($destfilesize -eq 0 || $destfilesize -ne $sourcefilesize)
{
Remove-ItemSafely -Path $destfile -Force
Start-BitsTransfer -Source $downladuri -Destination $destfile
}
}
}
# Unzip it
Expand-Archive -Path $presentfile -DestinationPath $eclipsefolder
# Delete downloaded package
Remove-ItemSafely -Path $destfile
}
catch {
Add-Content -Value "$(Get-Date): Unable to copy $($SourceFolder.Fullname) because $($Error[0])" -Path $Log
throw
}
finally {
Read-Host -Prompt 'Press ENTER...'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment