29
29
30
30
$FUNC_CLI_DIRECTORY = Join-Path $PSScriptRoot ' Azure.Functions.Cli'
31
31
32
+ $ApplicationInsightsAgentVersion = ' 3.4.0'
33
+ $ApplicationInsightsAgentFilename = " applicationinsights-agent-${ApplicationInsightsAgentVersion} .jar"
34
+ $ApplicationInsightsAgentUrl = " https://repo1.maven.org/maven2/com/microsoft/azure/applicationinsights-agent/${ApplicationInsightsAgentVersion} /${ApplicationInsightsAgentFilename} "
35
+
32
36
Write-Host ' Deleting the Core Tools if exists...'
33
37
Remove-Item - Force " $FUNC_CLI_DIRECTORY .zip" - ErrorAction Ignore
34
38
Remove-Item - Recurse - Force $FUNC_CLI_DIRECTORY - ErrorAction Ignore
@@ -55,4 +59,82 @@ if (-not $UseCoreToolsBuildFromIntegrationTests.IsPresent)
55
59
Write-Host " Copying worker.config.json and annotationLib to worker directory"
56
60
Copy-Item " $PSScriptRoot /annotationLib" " $FUNC_CLI_DIRECTORY /workers/java/annotationLib" - Recurse - Verbose
57
61
62
+ # Download application insights agent from maven central
63
+ $ApplicationInsightsAgentFile = [System.IO.Path ]::Combine($PSScriptRoot , $ApplicationInsightsAgentFilename )
64
+
65
+ # local testing cleanup
66
+ if (Test-Path - Path $ApplicationInsightsAgentFile ) {
67
+ Remove-Item - Path $ApplicationInsightsAgentFile
68
+ }
69
+
70
+ # local testing cleanup
71
+ $oldOutput = [System.IO.Path ]::Combine($PSScriptRoot , " agent" )
72
+ if (Test-Path - Path $oldOutput ) {
73
+ Remove-Item - Path $oldOutput - Recurse
74
+ }
75
+
76
+ # local testing cleanup
77
+ $oldExtract = [System.IO.Path ]::Combine($PSScriptRoot , " extract" )
78
+ if (Test-Path - Path $oldExtract ) {
79
+ Remove-Item - Path $oldExtract - Recurse
80
+ }
81
+
82
+ echo " Start downloading '$ApplicationInsightsAgentUrl ' to '$PSScriptRoot '"
83
+ try {
84
+ Invoke-WebRequest - Uri $ApplicationInsightsAgentUrl - OutFile $ApplicationInsightsAgentFile
85
+ } catch {
86
+ echo " An error occurred. Download fails" $ApplicationInsightsAgentFile
87
+ echo " Exiting"
88
+ exit 1
89
+ }
90
+
91
+ if (-not (Test-Path - Path $ApplicationInsightsAgentFile )) {
92
+ echo " $ApplicationInsightsAgentFile do not exist."
93
+ exit 1
94
+ }
95
+
96
+ $extract = new-item - type directory - force $PSScriptRoot \extract
97
+ if (-not (Test-Path - Path $extract )) {
98
+ echo " Fail to create a new directory $extract "
99
+ exit 1
100
+ }
101
+
102
+ echo " Start extracting content from $ApplicationInsightsAgentFilename to extract folder"
103
+ cd - Path $extract - PassThru
104
+ jar xf $ApplicationInsightsAgentFile
105
+ cd $PSScriptRoot
106
+ echo " Done extracting"
107
+
108
+ echo " Unsign $ApplicationInsightsAgentFilename "
109
+ Remove-Item $extract \META- INF\MSFTSIG.*
110
+ $manifest = " $extract \META-INF\MANIFEST.MF"
111
+ $newContent = (Get-Content - Raw $manifest | Select-String - Pattern ' (?sm)^(.*?\r?\n)\r?\n' ).Matches[0 ].Groups[1 ].Value
112
+ Set-Content - Path $manifest $newContent
113
+
114
+ Remove-Item $ApplicationInsightsAgentFile
115
+ if (-not (Test-Path - Path $ApplicationInsightsAgentFile )) {
116
+ echo " Delete the original $ApplicationInsightsAgentFilename successfully"
117
+ } else {
118
+ echo " Fail to delete original source $ApplicationInsightsAgentFilename "
119
+ exit 1
120
+ }
121
+
122
+ $agent = new-item - type directory - force $PSScriptRoot \agent
123
+ $filename = " applicationinsights-agent.jar"
124
+ $result = [System.IO.Path ]::Combine($agent , $filename )
125
+ echo " re-jar $filename "
126
+
127
+ cd - Path $extract - PassThru
128
+ jar cfm $result META- INF/ MANIFEST.MF .
129
+
130
+ if (-not (Test-Path - Path $result )) {
131
+ echo " Fail to re-archive $filename "
132
+ exit 1
133
+ }
134
+
135
+ Write-Host " Creating the functions.codeless file"
136
+ New-Item - path $PSScriptRoot \agent - type file - name " functions.codeless"
137
+
138
+ Write-Host " Copying the unsigned Application Insights Agent to worker directory"
139
+ Copy-Item " $PSScriptRoot /agent" " $FUNC_CLI_DIRECTORY /workers/java/agent" - Recurse - Verbose
58
140
}
0 commit comments