From 6d8d16daae45ddd65e84e5b1250e972b8ebb19d2 Mon Sep 17 00:00:00 2001 From: Gaetano Savo Date: Sat, 29 Mar 2025 08:46:26 +0100 Subject: [PATCH] creato file config.json --- build-and-deploy.ps1 | 27 ++++---- build-and-run-asset-gui.ps1 | 7 ++- config.json | 27 ++++++++ .../advc360/bes/startup/main/build.xml | 26 ++++++++ .../bes/startup/CustomLogFormatter.class | Bin 0 -> 1984 bytes .../bes/startup/main/custom-formatter.jar | Bin 0 -> 2101 bytes .../advc360/bes/startup/main/module.xml | 10 +++ .../bes/startup/CustomLogFormatter.java | 58 ++++++++++++++++++ start-jboss.ps1 | 29 +++++---- stop-jboss.ps1 | 7 ++- unpack_ear.ps1 | 56 +++++++++++++++++ 11 files changed, 218 insertions(+), 29 deletions(-) create mode 100644 config.json create mode 100644 modules/com/armundia/advc360/bes/startup/main/build.xml create mode 100644 modules/com/armundia/advc360/bes/startup/main/build/classes/com/armundia/adv360/bes/startup/CustomLogFormatter.class create mode 100644 modules/com/armundia/advc360/bes/startup/main/custom-formatter.jar create mode 100644 modules/com/armundia/advc360/bes/startup/main/module.xml create mode 100644 modules/com/armundia/advc360/bes/startup/main/src/com/armundia/adv360/bes/startup/CustomLogFormatter.java create mode 100644 unpack_ear.ps1 diff --git a/build-and-deploy.ps1 b/build-and-deploy.ps1 index 8335ecd..26c5a63 100644 --- a/build-and-deploy.ps1 +++ b/build-and-deploy.ps1 @@ -1,17 +1,20 @@ # PowerShell script for building and deploying arm_am-pom to JBoss EAP 7.4 -# Configuration -$JBOSS_HOME = "C:\Dev2012\BUILDERS\jboss-eap-7.4" -$PROJECT_DIR = "C:\Dev2012\source\WindSurf\adv\arm_am-pom" -$DEPLOYMENT_DIR = "$JBOSS_HOME\standalone\deployments" -$MAVEN_PROFILE = "adv360-DEV" # Default development profile -$JAVA_HOME = "C:\Dev2012\BUILDERS\java\jdk1.8.0_291" # Path to Java 8 +# Load configuration from JSON file +$config = Get-Content -Raw -Path "$PSScriptRoot\config.json" | ConvertFrom-Json + +# Configuration variables from JSON +$JBOSS_HOME = $config.jbossHome +$PROJECT_DIR = $config.ear.projectDir +$DEPLOYMENT_DIR = $config.deploymentDir +$MAVEN_PROFILE = $config.ear.mavenProfile +$JAVA_HOME = $config.javaHome # Store the original directory $originalDirectory = Get-Location # Function to check if JBoss is running -function Is-JBossRunning { +function Test-JBossRunning { $jbossProcess = Get-CimInstance Win32_Process -Filter "Name = 'java.exe'" | Where-Object { $_.CommandLine -like "*jboss.home.dir=$JBOSS_HOME*" } return $null -ne $jbossProcess @@ -54,7 +57,7 @@ Write-Host "Current directory: $(Get-Location)" -ForegroundColor Yellow # First build the parent and modules with debug output Write-Host "Building parent POM..." -ForegroundColor Yellow & "$env:JAVA_HOME\bin\java" -version -mvn clean install -N -P$MAVEN_PROFILE -X +mvn clean install -N -P$MAVEN_PROFILE if ($LASTEXITCODE -ne 0) { Write-Host "Maven parent build failed!" -ForegroundColor Red Set-Location $originalDirectory # Restore original directory @@ -64,7 +67,7 @@ if ($LASTEXITCODE -ne 0) { # Build the EJB module first with debug output Write-Host "Building EJB module..." -ForegroundColor Yellow Set-Location "$PROJECT_DIR\arm_am-ejb" -mvn clean install -DskipTests -P$MAVEN_PROFILE -X +mvn clean install -DskipTests -P$MAVEN_PROFILE if ($LASTEXITCODE -ne 0) { Write-Host "Maven EJB module build failed!" -ForegroundColor Red Set-Location $originalDirectory # Restore original directory @@ -74,7 +77,7 @@ if ($LASTEXITCODE -ne 0) { # Build the WAR module with debug output Write-Host "Building WAR module..." -ForegroundColor Yellow Set-Location "$PROJECT_DIR\arm_am" -mvn clean install -DskipTests -P$MAVEN_PROFILE -X +mvn clean install -DskipTests -P$MAVEN_PROFILE if ($LASTEXITCODE -ne 0) { Write-Host "Maven WAR module build failed!" -ForegroundColor Red Set-Location $originalDirectory # Restore original directory @@ -84,7 +87,7 @@ if ($LASTEXITCODE -ne 0) { # Finally build the EAR module with debug output Write-Host "Building EAR module..." -ForegroundColor Yellow Set-Location "$PROJECT_DIR\arm_am-ear" -mvn clean package -DskipTests -P$MAVEN_PROFILE -X +mvn clean package -DskipTests -P$MAVEN_PROFILE if ($LASTEXITCODE -ne 0) { Write-Host "Maven EAR module build failed!" -ForegroundColor Red Set-Location $originalDirectory # Restore original directory @@ -113,7 +116,7 @@ Write-Host "Copying to: $DEPLOYMENT_DIR" -ForegroundColor Yellow Copy-Item $earFile.FullName $DEPLOYMENT_DIR # Check if JBoss is running -if (Is-JBossRunning) { +if (Test-JBossRunning) { Write-Host "JBoss is running - deployment will be automatically picked up" -ForegroundColor Green } else { Write-Host "Note: JBoss is not running. Start JBoss to complete deployment" -ForegroundColor Yellow diff --git a/build-and-run-asset-gui.ps1 b/build-and-run-asset-gui.ps1 index ca496ad..a22501e 100644 --- a/build-and-run-asset-gui.ps1 +++ b/build-and-run-asset-gui.ps1 @@ -1,7 +1,10 @@ # PowerShell script to build and run asset-gui -$projectDir = ".\asset-gui" -$targetDir = ".\arm_am-pom\arm_am\WebContent\adv" +# Load configuration from JSON file +$config = Get-Content -Raw -Path "$PSScriptRoot\config.json" | ConvertFrom-Json + +$projectDir = $config.assetGui.projectDir +$targetDir = $config.assetGui.targetDir Write-Host "Building asset-gui project..." -ForegroundColor Green diff --git a/config.json b/config.json new file mode 100644 index 0000000..8519d49 --- /dev/null +++ b/config.json @@ -0,0 +1,27 @@ +{ + "jbossHome": "C:\\Dev2012\\BUILDERS\\jboss-eap-7.4", + "deploymentDir": "C:\\Dev2012\\BUILDERS\\jboss-eap-7.4\\standalone\\deployments", + "javaHome": "C:\\Dev2012\\BUILDERS\\java\\jdk1.8.0_291", + "jboss": { + "configFile": "standalone\\configuration\\standalone-ADVC-full.xml", + "modules": { + "logmanager": "modules\\system\\layers\\base\\org\\jboss\\logmanager\\main" + } + }, + "customFormatter": { + "src": "src", + "build": "build", + "classes": "build/classes", + "jar": "custom-formatter.jar" + }, + "ear": { + "projectDir": "C:\\Dev2012\\source\\WindSurf\\adv\\arm_am-pom", + "mavenProfile": "adv360-DEV", + "deployedFile": "adv360-ear.ear", + "unpackDir": ".\\arm_am-unpacked" + }, + "assetGui": { + "projectDir": ".\\asset-gui", + "targetDir": ".\\arm_am-pom\\arm_am\\WebContent\\adv" + } +} diff --git a/modules/com/armundia/advc360/bes/startup/main/build.xml b/modules/com/armundia/advc360/bes/startup/main/build.xml new file mode 100644 index 0000000..16656d2 --- /dev/null +++ b/modules/com/armundia/advc360/bes/startup/main/build.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/com/armundia/advc360/bes/startup/main/build/classes/com/armundia/adv360/bes/startup/CustomLogFormatter.class b/modules/com/armundia/advc360/bes/startup/main/build/classes/com/armundia/adv360/bes/startup/CustomLogFormatter.class new file mode 100644 index 0000000000000000000000000000000000000000..c94c3a2ca707b09af1c61119e28a0cac5caa369b GIT binary patch literal 1984 zcmaJ?O?MMj7=CW^aVNu6AyBZO7_ea4CJYp*kk%@cV%4S~i9lOhy-jXI%1kECOj_&r z!nJ$1Zrq}tllJJ5g$ow`1^M0={;r1i zG|cJ9V_prnHQdn&;e9pSRTc#eMI9gDo`(B69$-en64HW>MJ#cA$g#}OUlzW+<+!%+ zed#g`&8>?KVfs~DnrngByh#>C+V5ITFvKUTwW>eG5J?Z;V~9>WWyxT8zFVz7$j=o; z#bY?14#6x@tC$5+)hZLi`$ZH)!55`Rc~LKlRf}-q;mHh_S_lolYMGW(sSt!Y=Tz>> zlH-Vf;`o?Bn=DyDtOj01nxqB-OrpEcwc>PA*FZ zK2dgk%PHDXJgxx`q;3S#;go?5Tre<#Q3IR!l#FzaEd!t7b3#uDpAP+kg59EDHlNRy z%c=3)T)R;#SA{9c8<)o~nyb7}lAQB9SeMuoi$SiI=eWVy{@I;ZArQl9A+5%-%=RPBQgz6Cw092fPvtPz{C zJ%Zow(V`fgsa2#uCpRSJy&GIt9|9#AhN*3OWkenyF&@36bdJ}5Tif5?Rn{WqC%Jn z(vX?6S)*jT@(85ri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_O5qx@A~pkLIX&uJ|{x1Htw9;>PGabD8h z(v`d3{yi5kD=4(GDLd(liR3xY^TMgO+&!Js&aLu2Y4`fgnpN6OfB4G@SswKflJc2dRhhRATx9z-<%6oKjMC(PJ{qQ1M-UA!-60hLOe^-P0Hgr~mNaSuNw`*|iUFVHpduUsK$dR>G9d*z%ueh@Izq>F zs1A6kjn6Vr5f1?%%a|B(75KO<2Nn4U6HIWJ0I2|Qo1y?S1RUa7cuYZ52r$#IR|zl! emo%;*!ZchJM1VId8^|OMAXH;wVED-j;sF5NTj)pt literal 0 HcmV?d00001 diff --git a/modules/com/armundia/advc360/bes/startup/main/module.xml b/modules/com/armundia/advc360/bes/startup/main/module.xml new file mode 100644 index 0000000..6b2693f --- /dev/null +++ b/modules/com/armundia/advc360/bes/startup/main/module.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/modules/com/armundia/advc360/bes/startup/main/src/com/armundia/adv360/bes/startup/CustomLogFormatter.java b/modules/com/armundia/advc360/bes/startup/main/src/com/armundia/adv360/bes/startup/CustomLogFormatter.java new file mode 100644 index 0000000..9c476ef --- /dev/null +++ b/modules/com/armundia/advc360/bes/startup/main/src/com/armundia/adv360/bes/startup/CustomLogFormatter.java @@ -0,0 +1,58 @@ +package com.armundia.adv360.bes.startup; + +import java.util.logging.Formatter; +import java.util.logging.LogRecord; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; + +public class CustomLogFormatter extends Formatter { + + private static final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss,SSS"); + + private String stripXMLTags(String input) { + if (input == null || input.isEmpty()) { + return input; + } + return input.replaceAll("<[^>]*>", ""); + } + + @Override + public String format(LogRecord record) { + StringBuilder sb = new StringBuilder(); + + // Data e ora + sb.append(ZonedDateTime.now().format(dateFormatter)) + .append(" "); + + // Livello log padded a 5 caratteri + String level = record.getLevel().toString(); + sb.append(String.format("%-5s", level)); + + // Nome classe + sb.append("[") + .append(record.getSourceClassName()) + .append("] "); + + // Thread + sb.append("(") + .append(Thread.currentThread().getName()) + .append(") "); + + // Messaggio + String message = formatMessage(record); + sb.append(stripXMLTags(message)); + + // Stack trace se presente + if (record.getThrown() != null) { + sb.append("\n"); + for (StackTraceElement element : record.getThrown().getStackTrace()) { + sb.append("\tat ") + .append(element.toString()) + .append("\n"); + } + } + + sb.append("\n"); + return sb.toString(); + } +} diff --git a/start-jboss.ps1 b/start-jboss.ps1 index a121fcf..fae6756 100644 --- a/start-jboss.ps1 +++ b/start-jboss.ps1 @@ -1,11 +1,14 @@ # PowerShell script to start JBoss EAP 7.4 -# Configuration -$JBOSS_HOME = "C:\Dev2012\BUILDERS\jboss-eap-7.4" -$JAVA_HOME = "C:\Dev2012\BUILDERS\java\jdk1.8.0_291" +# Load configuration from JSON file +$config = Get-Content -Raw -Path "$PSScriptRoot\config.json" | ConvertFrom-Json + +# Configuration variables from JSON +$JBOSS_HOME = $config.jbossHome +$JAVA_HOME = $config.javaHome # Function to check if JBoss is already running -function Is-JBossRunning { +function Test-JBossRunning { $jbossProcess = Get-CimInstance Win32_Process -Filter "Name = 'java.exe'" | Where-Object { $_.CommandLine -like "*jboss.home.dir=$JBOSS_HOME*" } return $null -ne $jbossProcess @@ -24,7 +27,7 @@ if (-not (Test-Path $JBOSS_HOME)) { } # Check if configuration file exists -$configFile = "$JBOSS_HOME\standalone\configuration\standalone-ADVCsvil-full.xml" +$configFile = Join-Path $JBOSS_HOME $config.jboss.configFile if (-not (Test-Path $configFile)) { Write-Host "Error: Configuration file not found at $configFile" -ForegroundColor Red exit 1 @@ -39,7 +42,7 @@ $env:NOPAUSE = "true" # $env:LAUNCH_JBOSS_IN_BACKGROUND = "true" # Check if JBoss is already running -if (Is-JBossRunning) { +if (Test-JBossRunning) { Write-Host "JBoss is already running!" -ForegroundColor Yellow exit 0 } @@ -47,10 +50,10 @@ if (Is-JBossRunning) { Write-Host "Starting JBoss EAP 7.4..." -ForegroundColor Green Write-Host "Using Java from: $JAVA_HOME" -ForegroundColor Yellow Write-Host "JBoss Home: $JBOSS_HOME" -ForegroundColor Yellow -Write-Host "Using configuration: standalone-ADVCsvil-full.xml" -ForegroundColor Yellow +Write-Host "Using configuration: $($config.jboss.configFile)" -ForegroundColor Yellow # Start JBoss in standalone mode -$startScript = "$JBOSS_HOME\bin\standalone.bat" +$startScript = Join-Path $JBOSS_HOME "bin\standalone.bat" $jvmOptions = @( "-DIDServer=GS", "-Dbtf.PathToParse=C:\Dev2012\advc0\in", @@ -71,16 +74,16 @@ Write-Host "JVM Options: $env:JAVA_OPTS" -ForegroundColor Yellow Write-Host "Remote debugging enabled on port 8787" -ForegroundColor Cyan # Create the command line arguments -$cmdArgs = "-c standalone-ADVCsvil-full.xml --debug -b 0.0.0.0 -bmanagement 0.0.0.0" +$cmdArgs = "-c $($config.jboss.configFile) --debug -b 0.0.0.0 -bmanagement 0.0.0.0" # Start JBoss - Modified to use Start-Process with RedirectStandardOutput -$logFile = "$JBOSS_HOME\standalone\log\server.log" +$logFile = Join-Path $JBOSS_HOME "standalone\log\server.log" $processStartInfo = @{ FilePath = $startScript ArgumentList = $cmdArgs RedirectStandardOutput = $logFile - RedirectStandardError = "$JBOSS_HOME\standalone\log\server_error.log" - WorkingDirectory = "$JBOSS_HOME\bin" + RedirectStandardError = Join-Path $JBOSS_HOME "standalone\log\server_error.log" + WorkingDirectory = Join-Path $JBOSS_HOME "bin" NoNewWindow = $true PassThru = $true } @@ -91,7 +94,7 @@ $jbossProcess = Start-Process @processStartInfo # Wait a few seconds to check if the process started successfully Start-Sleep -Seconds 10 -if (Is-JBossRunning) { +if (Test-JBossRunning) { Write-Host "JBoss started successfully!" -ForegroundColor Green Write-Host "Admin console will be available at: http://localhost:9990" -ForegroundColor Yellow Write-Host "Remote debugging is enabled on port 8787" -ForegroundColor Cyan diff --git a/stop-jboss.ps1 b/stop-jboss.ps1 index 0b3c4eb..db2bfe2 100644 --- a/stop-jboss.ps1 +++ b/stop-jboss.ps1 @@ -1,7 +1,10 @@ # PowerShell script to stop JBoss EAP 7.4 -# Configuration -$JBOSS_HOME = "C:\Dev2012\BUILDERS\jboss-eap-7.4" +# Load configuration from JSON file +$config = Get-Content -Raw -Path "$PSScriptRoot\config.json" | ConvertFrom-Json + +# Configuration variables from JSON +$JBOSS_HOME = $config.jbossHome Write-Host "Stopping JBoss EAP 7.4..." -ForegroundColor Yellow diff --git a/unpack_ear.ps1 b/unpack_ear.ps1 new file mode 100644 index 0000000..51c2312 --- /dev/null +++ b/unpack_ear.ps1 @@ -0,0 +1,56 @@ +# Load configuration from JSON file +$config = Get-Content -Raw -Path "$PSScriptRoot\config.json" | ConvertFrom-Json + +# Set paths from configuration +$sourceFile = Join-Path $config.deploymentDir $config.ear.deployedFile +$destinationPath = $config.ear.unpackDir + +# Remove destination directory if it exists +if (Test-Path -Path $destinationPath) { + Remove-Item -Path $destinationPath -Recurse -Force + Write-Host "Removed existing directory: $destinationPath" +} + +# Create destination directory +if (-not (Test-Path -Path $destinationPath)) { + New-Item -ItemType Directory -Path $destinationPath -Force +} + +# Rename .ear to .zip temporarily to use Expand-Archive +$tempZipPath = $sourceFile -replace '\.ear$', '.zip' +Copy-Item -Path $sourceFile -Destination $tempZipPath + +# Extract the EAR contents +Expand-Archive -Path $tempZipPath -DestinationPath $destinationPath -Force + +# Clean up temporary zip file +Remove-Item -Path $tempZipPath + +Write-Host "EAR file extracted to $destinationPath" + +# Function to unpack archive files (war/ejb) +function Expand-JavaArchive { + param ( + [string]$archivePath, + [string]$destinationPath + ) + + $tempZipPath = $archivePath -replace '\.(war|jar)$', '.zip' + Copy-Item -Path $archivePath -Destination $tempZipPath + + # Create extraction directory + if (-not (Test-Path -Path $destinationPath)) { + New-Item -ItemType Directory -Path $destinationPath -Force + } + + # Extract contents + Expand-Archive -Path $tempZipPath -DestinationPath $destinationPath -Force + Remove-Item -Path $tempZipPath + Write-Host "Extracted $archivePath to $destinationPath" +} + +# Find and extract WAR and EJB files +Get-ChildItem -Path $destinationPath -Recurse -Include "*.war", "*-ejbx.jar" | ForEach-Object { + $extractPath = Join-Path (Split-Path -Parent $_.FullName) ($_.BaseName + "_unpacked") + Expand-JavaArchive -archivePath $_.FullName -destinationPath $extractPath +}