@@ -111,3 +111,85 @@ cmd.exe /c '.\..\..\mvnBuild.bat'
111111StopOnFailedExecution
112112Pop-Location - StackName " libraryDir"
113113
114+ $ApplicationInsightsAgentVersion = ' 3.5.2'
115+ $ApplicationInsightsAgentFilename = " applicationinsights-agent-${ApplicationInsightsAgentVersion} .jar"
116+ $ApplicationInsightsAgentUrl = " https://repo1.maven.org/maven2/com/microsoft/azure/applicationinsights-agent/${ApplicationInsightsAgentVersion} /${ApplicationInsightsAgentFilename} "
117+
118+ # Download application insights agent from maven central
119+ $ApplicationInsightsAgentFile = " $currDir /$ApplicationInsightsAgentFilename "
120+
121+ # local testing cleanup
122+ if (Test-Path - Path $ApplicationInsightsAgentFile ) {
123+ Remove-Item - Path $ApplicationInsightsAgentFile
124+ }
125+
126+ # local testing cleanup
127+ $oldOutput = [System.IO.Path ]::Combine($currDir , " agent" )
128+ if (Test-Path - Path $oldOutput ) {
129+ Remove-Item - Path $oldOutput - Recurse
130+ }
131+
132+ # local testing cleanup
133+ $oldExtract = [System.IO.Path ]::Combine($currDir , " extract" )
134+ if (Test-Path - Path $oldExtract ) {
135+ Remove-Item - Path $oldExtract - Recurse
136+ }
137+
138+ echo " Start downloading '$ApplicationInsightsAgentUrl ' to '$currDir '"
139+ try {
140+ Invoke-WebRequest - Uri $ApplicationInsightsAgentUrl - OutFile $ApplicationInsightsAgentFile
141+ } catch {
142+ echo " An error occurred. Download fails" $ApplicationInsightsAgentFile
143+ echo " Exiting"
144+ exit 1
145+ }
146+
147+ if (-not (Test-Path - Path $ApplicationInsightsAgentFile )) {
148+ echo " $ApplicationInsightsAgentFile do not exist."
149+ exit 1
150+ }
151+
152+ $extract = new-item - type directory - force $currDir \extract
153+ if (-not (Test-Path - Path $extract )) {
154+ echo " Fail to create a new directory $extract "
155+ exit 1
156+ }
157+
158+ echo " Start extracting content from $ApplicationInsightsAgentFilename to extract folder"
159+ cd - Path $extract - PassThru
160+ Start-Process - FilePath " cmd" - ArgumentList " /c jar xf $ApplicationInsightsAgentFile " - Wait
161+ cd $currDir
162+ echo " Done extracting"
163+
164+ echo " Unsign $ApplicationInsightsAgentFilename "
165+ Remove-Item $extract \META- INF\MSFTSIG.*
166+ $manifest = " $extract \META-INF\MANIFEST.MF"
167+ $newContent = (Get-Content - Raw $manifest | Select-String - Pattern ' (?sm)^(.*?\r?\n)\r?\n' ).Matches[0 ].Groups[1 ].Value
168+ Set-Content - Path $manifest $newContent
169+
170+ Remove-Item $ApplicationInsightsAgentFile
171+ if (-not (Test-Path - Path $ApplicationInsightsAgentFile )) {
172+ echo " Delete the original $ApplicationInsightsAgentFilename successfully"
173+ } else {
174+ echo " Fail to delete original source $ApplicationInsightsAgentFilename "
175+ exit 1
176+ }
177+
178+ $agent = new-item - type directory - force $currDir / agent
179+ $filename = " applicationinsights-agent.jar"
180+ $result = [System.IO.Path ]::Combine($agent , $filename )
181+ echo " re-jar $filename "
182+
183+ cd - Path $extract - PassThru
184+ jar cfm $result META- INF/ MANIFEST.MF .
185+
186+ if (-not (Test-Path - Path $result )) {
187+ echo " Fail to re-archive $filename "
188+ exit 1
189+ }
190+
191+ Write-Host " Creating the functions.codeless file"
192+ New-Item - path $currDir \agent - type file - name " functions.codeless"
193+
194+ Write-Host " Copying the unsigned Application Insights Agent to worker directory"
195+ Copy-Item " $currDir /agent" " $currDir /azure-functions-java-worker/Azure.Functions.Cli/workers/java" - Recurse - Verbose - Force
0 commit comments