Skip to content

Commit 9121453

Browse files
authored
move appinsights to pom and update build scripts (#808)
1 parent a791664 commit 9121453

File tree

3 files changed

+58
-116
lines changed

3 files changed

+58
-116
lines changed

Diff for: package-pipeline.ps1

+10-35
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,16 @@ param (
55
# A function that checks exit codes and fails script if an error is found
66
function StopOnFailedExecution {
77
if ($LastExitCode)
8-
{
8+
{
99
exit $LastExitCode
1010
}
1111
}
1212

13-
$ApplicationInsightsAgentVersion = '3.5.4'
14-
$ApplicationInsightsAgentFilename = "applicationinsights-agent-${ApplicationInsightsAgentVersion}.jar"
15-
$ApplicationInsightsAgentUrl = "https://repo1.maven.org/maven2/com/microsoft/azure/applicationinsights-agent/${ApplicationInsightsAgentVersion}/${ApplicationInsightsAgentFilename}"
16-
17-
Write-Host "Building azure-functions-java-worker"
18-
mvn clean package --no-transfer-progress -B
13+
Write-Host "Building azure-functions-java-worker with appinsights profile"
14+
mvn clean package --no-transfer-progress -B -P appinsights
1915
StopOnFailedExecution
2016

21-
Write-Host "Creating nuget package Microsoft.Azure.Functions.JavaWorker"
17+
Write-Host "Creating nuget package Microsoft.Azure.Functions.JavaWorker"
2218
Write-Host "buildNumber: " $buildNumber
2319
Get-Command nuget
2420
StopOnFailedExecution
@@ -30,12 +26,13 @@ copy-item ./worker.config.json pkg
3026
copy-item ./tools/AzureFunctionsJavaWorker.nuspec pkg/
3127
copy-item ./annotationLib pkg/annotationLib -Recurse
3228

33-
# Download application insights agent from maven central
34-
$ApplicationInsightsAgentFile = [System.IO.Path]::Combine($PSScriptRoot, $ApplicationInsightsAgentFilename)
29+
# locate the agent jar produced by the `appinsights` Maven profile
30+
$ApplicationInsightsAgentFile = [System.IO.Path]::Combine($PSScriptRoot, 'target', 'agent', 'applicationinsights-agent.jar')
3531

36-
# local testing cleanup
37-
if (Test-Path -Path $ApplicationInsightsAgentFile) {
38-
Remove-Item -Path $ApplicationInsightsAgentFile
32+
if (!(Test-Path -Path $ApplicationInsightsAgentFile)) {
33+
Write-Host "Error: $ApplicationInsightsAgentFile not found."
34+
Write-Host "Make sure you enabled the 'appinsights' Maven profile that copies the AI agent to target/agent/."
35+
exit 1
3936
}
4037

4138
# local testing cleanup
@@ -56,20 +53,6 @@ if (-not(Test-Path -Path $extract)) {
5653
exit 1
5754
}
5855

59-
echo "Start downloading '$ApplicationInsightsAgentUrl' to '$PSScriptRoot'"
60-
try {
61-
Invoke-WebRequest -Uri $ApplicationInsightsAgentUrl -OutFile $ApplicationInsightsAgentFile
62-
} catch {
63-
echo "An error occurred. Download fails" $ApplicationInsightsAgentFile
64-
echo "Exiting"
65-
exit 1
66-
}
67-
68-
if (-not(Test-Path -Path $ApplicationInsightsAgentFile)) {
69-
echo "$ApplicationInsightsAgentFile do not exist."
70-
exit 1
71-
}
72-
7356
echo "Start extracting content from $ApplicationInsightsAgentFilename to extract folder"
7457
cd -Path $extract -PassThru
7558
jar xf $ApplicationInsightsAgentFile
@@ -82,14 +65,6 @@ $manifest = "$extract\META-INF\MANIFEST.MF"
8265
$newContent = (Get-Content -Raw $manifest | Select-String -Pattern '(?sm)^(.*?\r?\n)\r?\n').Matches[0].Groups[1].Value
8366
Set-Content -Path $manifest $newContent
8467

85-
Remove-Item $ApplicationInsightsAgentFile
86-
if (-not(Test-Path -Path $ApplicationInsightsAgentFile)) {
87-
echo "Delete the original $ApplicationInsightsAgentFilename successfully"
88-
} else {
89-
echo "Fail to delete original source $ApplicationInsightsAgentFilename"
90-
exit 1
91-
}
92-
9368
$agent = new-item -type directory -force $PSScriptRoot\agent
9469
$filename = "applicationinsights-agent.jar"
9570
$result = [System.IO.Path]::Combine($agent, $filename)

Diff for: pom.xml

+48
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<azure.functions.java.library.version>2.2.0</azure.functions.java.library.version>
2121
<jupiter.version>5.9.1</jupiter.version>
2222
<mockito-core.version>4.11.0</mockito-core.version>
23+
<appinsights.agents.version>3.6.2</appinsights.agents.version>
2324
</properties>
2425
<licenses>
2526
<license>
@@ -321,4 +322,51 @@
321322
</plugin>
322323
</plugins>
323324
</build>
325+
<profiles>
326+
<profile>
327+
<id>appinsights</id>
328+
<dependencies>
329+
<dependency>
330+
<groupId>com.microsoft.azure</groupId>
331+
<artifactId>applicationinsights-agent</artifactId>
332+
<version>${appinsights.agents.version}</version>
333+
<scope>provided</scope>
334+
</dependency>
335+
</dependencies>
336+
337+
<build>
338+
<plugins>
339+
<!--
340+
Use the Maven Dependency Plugin to copy the agent from your local Maven repo
341+
into target/agent/applicationinsights-agent.jar at package time.
342+
-->
343+
<plugin>
344+
<groupId>org.apache.maven.plugins</groupId>
345+
<artifactId>maven-dependency-plugin</artifactId>
346+
<version>3.5.0</version>
347+
<executions>
348+
<execution>
349+
<id>copy-ai-agent</id>
350+
<phase>package</phase>
351+
<goals>
352+
<goal>copy</goal>
353+
</goals>
354+
<configuration>
355+
<artifactItems>
356+
<artifactItem>
357+
<groupId>com.microsoft.azure</groupId>
358+
<artifactId>applicationinsights-agent</artifactId>
359+
<version>${appinsights.agents.version}</version>
360+
<outputDirectory>${project.build.directory}/agent</outputDirectory>
361+
<destFileName>applicationinsights-agent.jar</destFileName>
362+
</artifactItem>
363+
</artifactItems>
364+
</configuration>
365+
</execution>
366+
</executions>
367+
</plugin>
368+
</plugins>
369+
</build>
370+
</profile>
371+
</profiles>
324372
</project>

Diff for: setup-tests-pipeline.ps1

-81
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ else
2929

3030
$FUNC_CLI_DIRECTORY = Join-Path $PSScriptRoot 'Azure.Functions.Cli'
3131

32-
$ApplicationInsightsAgentVersion = '3.5.4'
33-
$ApplicationInsightsAgentFilename = "applicationinsights-agent-${ApplicationInsightsAgentVersion}.jar"
34-
$ApplicationInsightsAgentUrl = "https://repo1.maven.org/maven2/com/microsoft/azure/applicationinsights-agent/${ApplicationInsightsAgentVersion}/${ApplicationInsightsAgentFilename}"
35-
3632
Write-Host 'Deleting the Core Tools if exists...'
3733
Remove-Item -Force "$FUNC_CLI_DIRECTORY.zip" -ErrorAction Ignore
3834
Remove-Item -Recurse -Force $FUNC_CLI_DIRECTORY -ErrorAction Ignore
@@ -58,83 +54,6 @@ if (-not $UseCoreToolsBuildFromIntegrationTests.IsPresent)
5854
Copy-Item "$PSScriptRoot/worker.config.json" "$FUNC_CLI_DIRECTORY/workers/java" -Force -Verbose
5955
Write-Host "Copying worker.config.json and annotationLib to worker directory"
6056
Copy-Item "$PSScriptRoot/annotationLib" "$FUNC_CLI_DIRECTORY/workers/java" -Recurse -Verbose -Force
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-
13857
Write-Host "Copying the unsigned Application Insights Agent to worker directory"
13958
Copy-Item "$PSScriptRoot/agent" "$FUNC_CLI_DIRECTORY/workers/java" -Recurse -Verbose -Force
14059
}

0 commit comments

Comments
 (0)