Created
October 19, 2025 01:20
-
-
Save guinetik/742e944f463d2bb9c94172c5a5e33249 to your computer and use it in GitHub Desktop.
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
| function Optimize-Eclipse { | |
| try { | |
| $eclipsePath = Join-Path $toolsDir "eclipse" | |
| $eclipseExe = Join-Path $eclipsePath "eclipse.exe" | |
| # Tenta iniciar o eclipse em modo silencioso para validar | |
| if (-not (Test-Path $eclipseExe)) { | |
| Write-Host "❌ eclipse.exe não encontrado em $eclipseExe." -ForegroundColor Yellow | |
| return $false | |
| } | |
| Write-Host "Eclipse encontrado em: $eclipseExe" -ForegroundColor DarkGray | |
| Optimize-EclipseRuntime | |
| Install-EclipseJBossTools | |
| Install-EclipseNTail | |
| return $true | |
| } | |
| catch { | |
| Write-Host "❌ Erro ao configurar o Eclipse: $_" -ForegroundColor Yellow | |
| return $false | |
| } | |
| } | |
| function Invoke-EclipseHeadless { | |
| param( | |
| [Parameter(Mandatory)] | |
| [string]$EclipsePath | |
| ) | |
| $eclipseExe = Join-Path $EclipsePath "eclipse.exe" | |
| # Tenta iniciar o eclipse em modo silencioso para validar | |
| if (-not (Test-Path $eclipseExe)) { | |
| Write-Host "❌ eclipse.exe não encontrado em $eclipseExe." -ForegroundColor Yellow | |
| return $false | |
| } | |
| # Testa o eclipse rapidamente para validar | |
| Write-Host "🌌 Testando Eclipse rapidamente para validar..." -ForegroundColor Cyan | |
| Start-Process -FilePath $eclipseExe -ArgumentList "-application", "org.eclipse.equinox.p2.director", "-consoleLog" -Wait -NoNewWindow -PassThru | Out-Null | |
| # Se o eclipse fechar normalmente, assume sucesso | |
| if ($LASTEXITCODE -ne 0) { | |
| return $LASTEXITCODE | |
| } | |
| return 0; | |
| } | |
| function Optimize-EclipseRuntime { | |
| try { | |
| # Verifica se o eclipse está instalado | |
| $eclipsePath = Join-Path $toolsDir "eclipse" | |
| if (-not (Test-Path $eclipsePath)) { | |
| Write-Host "❌ Eclipse não encontrado em $eclipsePath." -ForegroundColor Yellow | |
| return $true | |
| } | |
| # Obtém permissão do usuário para otimizar o eclipse | |
| $configureEclipse = Read-Host "🌌 Otimizar o Eclipse? (S/N)" | |
| if ($configureEclipse -ne "S" -and $configureEclipse -ne "s") { | |
| Write-Host "ℹ️ Configuração do runtime do Eclipse ignorada." -ForegroundColor Cyan | |
| return $true | |
| } | |
| # Verifica se o java está instalado | |
| jabba use "[email protected]" | |
| $JAVA_HOME = $(jabba which $(jabba current)) | |
| if (-not $JAVA_HOME -or -not (Test-Path $JAVA_HOME)) { | |
| Write-Host "❌ Runtime Java não encontrado via Jabba." -ForegroundColor Yellow | |
| return $false | |
| } | |
| # Obtém o caminho do java | |
| Write-Host "💫 javaRuntimePath: $JAVA_HOME" -ForegroundColor Cyan | |
| # Obtém o caminho do eclipse.ini | |
| $eclipseIniPath = Join-Path $eclipsePath "eclipse.ini" | |
| # Verifica se o arquivo eclipse.ini existe | |
| if (-not (Test-Path $eclipseIniPath)) { | |
| Write-Host "❌ Arquivo eclipse.ini não encontrado em $eclipseIniPath" -ForegroundColor Yellow | |
| return $false | |
| } | |
| # Cria um backup do arquivo eclipse.ini | |
| $backupIniPath = "$eclipseIniPath.bkp" | |
| Copy-Item $eclipseIniPath $backupIniPath -Force | |
| # Gera um novo eclipse.ini | |
| try { | |
| Write-Host "💫 Gerando novo eclipse.ini..." -ForegroundColor Cyan | |
| $iniContent = New-EclipseSpecs -SDK $JAVA_HOME -SplashPath (Join-Path $PWD.Path "/lib/splash.png") | |
| $iniContent | Set-Content $eclipseIniPath -Encoding Ascii | |
| # Tenta iniciar o eclipse em modo silencioso para validar | |
| $exitCode = Invoke-EclipseHeadless -EclipsePath $eclipsePath | |
| if ($exitCode -ne 0) { | |
| Move-Item $backupIniPath $eclipseIniPath -Force | |
| throw "Falha ao validar o novo eclipse.ini. Código de saída: $exitCode" | |
| } | |
| # Remove o backup se tudo estiver ok | |
| Write-Host "✅ Eclipse configurado e validado com sucesso!" -ForegroundColor Green | |
| Remove-Item $backupIniPath -Force | |
| } | |
| catch { | |
| Write-Host "❌ Erro durante a configuração: $_" -ForegroundColor Red | |
| Write-Host "🔄 Restaurando o backup do eclipse.ini..." -ForegroundColor Yellow | |
| # Restaura o backup se houver erro | |
| Move-Item $backupIniPath $eclipseIniPath -Force | |
| return $false | |
| } | |
| return $true | |
| } | |
| catch { | |
| Write-Host "❌ Erro inesperado: $_" -ForegroundColor Yellow | |
| return $false | |
| } | |
| } | |
| function Install-EclipsePlugins { | |
| param( | |
| [Parameter(Mandatory)] | |
| [string]$RepositoryUrl, | |
| [Parameter(Mandatory)] | |
| [string[]]$PluginIds, | |
| [switch]$ShowCommand | |
| ) | |
| try { | |
| $eclipsePath = Join-Path $toolsDir "eclipse" | |
| if (-not (Test-Path $eclipsePath)) { | |
| Write-Host "❌ Eclipse não encontrado em $eclipsePath." -ForegroundColor Yellow | |
| return $false | |
| } | |
| $eclipsec = Join-Path $eclipsePath "eclipsec.exe" | |
| if (-not (Test-Path $eclipsec)) { | |
| Write-Host "❌ eclipsec.exe não encontrado em $eclipsec" -ForegroundColor Yellow | |
| return $false | |
| } | |
| # Handle eclipse.ini - backup and modify | |
| $eclipseIni = Join-Path $eclipsePath "eclipse.ini" | |
| $eclipseIniBackup = Join-Path $eclipsePath "eclipse.ini.backup" | |
| if (Test-Path $eclipseIni) { | |
| # Create backup | |
| Copy-Item -Path $eclipseIni -Destination $eclipseIniBackup -Force | |
| # Create a modified version without --vmargs and anything after it | |
| $iniContent = Get-Content -Path $eclipseIni | |
| $newContent = @() | |
| $skipLine = $false | |
| foreach ($line in $iniContent) { | |
| if ($line -eq "--vmargs") { | |
| $skipLine = $true | |
| continue | |
| } | |
| if (-not $skipLine) { | |
| $newContent += $line | |
| } | |
| } | |
| # Write the modified content back to eclipse.ini | |
| $newContent | Set-Content -Path $eclipseIni -Force | |
| Write-Host "📝 Modificado temporariamente eclipse.ini para instalação" -ForegroundColor Cyan | |
| } | |
| $arguments = @( | |
| "-application", "org.eclipse.equinox.p2.director", | |
| "-repository", $RepositoryUrl | |
| ) | |
| foreach ($plugin in $PluginIds) { | |
| $arguments += "-installIU" | |
| $arguments += $plugin | |
| } | |
| if ($ShowCommand) { | |
| Write-Host "🚀 Comando sendo executado:" -ForegroundColor Cyan | |
| Write-Host "$eclipsec $($arguments -join ' ')" -ForegroundColor Gray | |
| } | |
| $installLog = Join-Path $PWD "install.log" | |
| Write-Host "⏳ Instalando plugins no Eclipse a partir do repositório $RepositoryUrl ..." -ForegroundColor Yellow | |
| $processInfo = New-Object System.Diagnostics.ProcessStartInfo | |
| $processInfo.FileName = $eclipsec | |
| $processInfo.Arguments = $arguments -join ' ' | |
| $processInfo.RedirectStandardOutput = $true | |
| $processInfo.RedirectStandardError = $true | |
| $processInfo.UseShellExecute = $false | |
| $processInfo.CreateNoWindow = $true | |
| $process = New-Object System.Diagnostics.Process | |
| $process.StartInfo = $processInfo | |
| $null = $process.Start() | |
| $stdout = $process.StandardOutput.ReadToEnd() | |
| $stderr = $process.StandardError.ReadToEnd() | |
| $process.WaitForExit() | |
| # Restore original eclipse.ini | |
| if (Test-Path $eclipseIniBackup) { | |
| Copy-Item -Path $eclipseIniBackup -Destination $eclipseIni -Force | |
| Remove-Item -Path $eclipseIniBackup -Force | |
| Write-Host "🔄 Restaurado eclipse.ini original" -ForegroundColor Cyan | |
| } | |
| # Save logs | |
| "$stdout`n$stderr" | Set-Content -Path $installLog -Encoding utf8 | |
| if ($process.ExitCode -eq 0) { | |
| Write-Host "✅ Plugins instalados com sucesso!" -ForegroundColor Green | |
| Remove-Item $installLog -ErrorAction SilentlyContinue | |
| return $true | |
| } | |
| else { | |
| Write-Host "❌ Falha na instalação de plugins. Código de saída: $($process.ExitCode)" -ForegroundColor Red | |
| if (Test-Path $installLog) { | |
| Write-Host "📜 Últimas linhas do install.log:" -ForegroundColor Cyan | |
| Get-Content $installLog | Select-Object -Last 20 | |
| } | |
| return $false | |
| } | |
| } | |
| catch { | |
| # Ensure eclipse.ini is restored even if there's an error | |
| $eclipseIni = Join-Path $eclipsePath "eclipse.ini" | |
| $eclipseIniBackup = Join-Path $eclipsePath "eclipse.ini.backup" | |
| if (Test-Path $eclipseIniBackup) { | |
| Copy-Item -Path $eclipseIniBackup -Destination $eclipseIni -Force | |
| Remove-Item -Path $eclipseIniBackup -Force | |
| Write-Host "🔄 Restaurado eclipse.ini original após erro" -ForegroundColor Cyan | |
| } | |
| Write-Host "❌ Erro inesperado ao instalar plugins: $_" -ForegroundColor Red | |
| return $false | |
| } | |
| } | |
| function Install-EclipseJBossTools { | |
| try { | |
| $shouldInstall = Read-Host "🌌 Deseja configurar o Eclipse com os recursos do JBoss Tools? (S/N)" | |
| if ($shouldInstall -eq "S" -or $shouldInstall -eq "s") { | |
| $repository = "https://download.jboss.org/jbosstools/photon/stable/composite/4.19.1" | |
| $plugins = @( | |
| "org.jboss.tools.vpe.resref", | |
| "org.jboss.tools.jst.web.ui", | |
| "org.jboss.ide.eclipse.as.core", | |
| "org.jboss.ide.eclipse.archives.webtools", | |
| "org.jboss.tools.jmx.feature.feature.group" | |
| ) | |
| $success = Install-EclipsePlugins -RepositoryUrl $repository -PluginIds $plugins -ShowCommand | |
| if ($success -eq $true) { | |
| # Optional: Launch Eclipse afterwards | |
| $eclipsePath = Join-Path $toolsDir "eclipse" | |
| $result = Invoke-EclipseHeadless -EclipsePath $eclipsePath | |
| if ($result -ne 0) { | |
| Write-Host "❌ Erro ao iniciar o Eclipse. Código de saída: $result" -ForegroundColor Red | |
| return $false | |
| } | |
| Write-Host "✅ JBoss Tools instalado com sucesso!" -ForegroundColor Green | |
| return $true | |
| } | |
| return $success | |
| } | |
| else { | |
| Write-Host "ℹ️ Instalação do JBoss Tools ignorada." -ForegroundColor Cyan | |
| return $true | |
| } | |
| } | |
| catch { | |
| Write-Host "❌ Erro inesperado ao configurar JBoss Tools: $_" -ForegroundColor Red | |
| return $false | |
| } | |
| } | |
| function Install-EclipseNTail { | |
| try { | |
| $shouldInstall = Read-Host "🌌 Deseja instalar o plugin NTail no Eclipse? (S/N)" | |
| if ($shouldInstall -eq "S" -or $shouldInstall -eq "s") { | |
| $repository = "https://www.certiv.net/updates" | |
| $plugins = @( | |
| "net.certiv.ntail.feature.feature.group" | |
| ) | |
| $success = Install-EclipsePlugins -RepositoryUrl $repository -PluginIds $plugins -ShowCommand | |
| if ($success -eq $true) { | |
| # Optional: Launch Eclipse afterwards | |
| $eclipsePath = Join-Path $toolsDir "eclipse" | |
| $result = Invoke-EclipseHeadless -EclipsePath $eclipsePath | |
| if ($result -ne 0) { | |
| Write-Host "❌ Erro ao iniciar o Eclipse. Código de saída: $result" -ForegroundColor Red | |
| return $false | |
| } | |
| Write-Host "✅ NTail instalado com sucesso!" -ForegroundColor Green | |
| return $true | |
| } | |
| return $success | |
| } | |
| else { | |
| Write-Host "ℹ️ Instalação do NTail ignorada." -ForegroundColor Cyan | |
| return $true | |
| } | |
| } | |
| catch { | |
| Write-Host "❌ Erro inesperado ao configurar NTail: $_" -ForegroundColor Red | |
| return $false | |
| } | |
| } | |
| function New-EclipseSpecs { | |
| param( | |
| [Parameter(Mandatory)] | |
| [string]$SDK, | |
| [Parameter()] | |
| [string]$SplashPath = "C:/workspace/Integracao_mavenized/lib/splash.png" | |
| ) | |
| $specs = Get-SystemSpecs | |
| $heapSettings = if ($specs.RAM_GB -ge 16) { | |
| "-Xms2G`r`n-Xmx4G" | |
| } | |
| elseif ($specs.RAM_GB -ge 8) { | |
| "-Xms1G`r`n-Xmx2G" | |
| } | |
| else { | |
| "-Xms512M`r`n-Xmx1G" | |
| } | |
| $gcThreads = if ($specs.CPU_Threads -ge 8) { 4 } else { 2 } | |
| @" | |
| -startup | |
| plugins/org.eclipse.equinox.launcher_1.6.1000.v20250227-1734.jar | |
| --launcher.library | |
| plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.2.1200.v20250212-0927 | |
| -showsplash | |
| $SplashPath | |
| --launcher.defaultAction | |
| openFile | |
| --launcher.appendVmargs | |
| -vm | |
| $SDK\bin\javaw.exe | |
| --vmargs | |
| $heapSettings | |
| -XX:+UseG1GC | |
| -XX:+UseStringDeduplication | |
| -XX:ParallelGCThreads=$gcThreads | |
| -XX:CICompilerCount=$($specs.CPU_Cores) | |
| -XX:CompileCommand=exclude org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer::getExtendedRange | |
| -Dorg.eclipse.ecf.provider.filetransfer.excludeContributors=org.eclipse.ecf.provider.filetransfer.httpclientjava | |
| -Dosgi.requiredJavaVersion=21 | |
| [email protected]/eclipse-workspace | |
| -Dosgi.dataAreaRequiresExplicitInit=true | |
| -Dorg.eclipse.swt.graphics.Resource.reportNonDisposed=true | |
| -Declipse.e4.inject.javax.warning=false | |
| -Dsun.java.command=Eclipse | |
| --add-modules=ALL-SYSTEM | |
| -Djavax.net.ssl.trustStoreType=Windows-ROOT | |
| -Djavax.net.ssl.trustStore=NONE | |
| -Dosgi.splashLocation=file:/$SplashPath | |
| "@ | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment