Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Commit 798dcc4

Browse files
committed
Migrate agent samples to NBT agent support
Closes gh-1247
1 parent 97b8d74 commit 798dcc4

File tree

3 files changed

+69
-26
lines changed

3 files changed

+69
-26
lines changed

samples/commandlinerunner-agent/pom.xml

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,23 @@
3434
<build>
3535
<plugins>
3636
<plugin>
37+
<groupId>org.apache.maven.plugins</groupId>
3738
<artifactId>maven-antrun-plugin</artifactId>
3839
<executions>
3940
<execution>
40-
<id>create-native-image-config-folder</id>
41-
<phase>test-compile</phase>
41+
<id>copy-agent-config</id>
42+
<phase>prepare-package</phase>
43+
<goals>
44+
<goal>run</goal>
45+
</goals>
4246
<configuration>
4347
<target>
44-
<mkdir dir="target/classes/META-INF/native-image"/>
48+
<mkdir dir="${project.build.directory}/native/agent-output/main"/>
49+
<copy todir="${project.build.directory}/native/agent-output/main">
50+
<fileset dir="${project.build.directory}/native/agent-output/test" />
51+
</copy>
4552
</target>
4653
</configuration>
47-
<goals>
48-
<goal>run</goal>
49-
</goals>
5054
</execution>
5155
</executions>
5256
</plugin>
@@ -63,10 +67,16 @@
6367
<artifactId>spring-boot-maven-plugin</artifactId>
6468
</plugin>
6569
<plugin>
66-
<groupId>org.apache.maven.plugins</groupId>
67-
<artifactId>maven-surefire-plugin</artifactId>
70+
<groupId>org.graalvm.buildtools</groupId>
71+
<artifactId>native-maven-plugin</artifactId>
72+
<extensions>true</extensions>
6873
<configuration>
69-
<argLine>-agentlib:native-image-agent=access-filter-file=access-filter.json,config-merge-dir=target/classes/META-INF/native-image</argLine>
74+
<agent>
75+
<enabled>true</enabled>
76+
<options name="test">
77+
<option>access-filter-file=${basedir}/access-filter.json</option>
78+
</options>
79+
</agent>
7080
</configuration>
7181
</plugin>
7282
</plugins>

samples/webmvc-tomcat-agent/pom.xml

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,27 +62,37 @@
6262
<artifactId>spring-boot-maven-plugin</artifactId>
6363
</plugin>
6464
<plugin>
65+
<groupId>org.apache.maven.plugins</groupId>
6566
<artifactId>maven-antrun-plugin</artifactId>
6667
<executions>
6768
<execution>
68-
<id>create-native-image-config-folder</id>
69-
<phase>test-compile</phase>
69+
<id>copy-agent-config</id>
70+
<phase>prepare-package</phase>
71+
<goals>
72+
<goal>run</goal>
73+
</goals>
7074
<configuration>
7175
<target>
72-
<mkdir dir="target/classes/META-INF/native-image"/>
76+
<mkdir dir="${project.build.directory}/native/agent-output/main"/>
77+
<copy todir="${project.build.directory}/native/agent-output/main">
78+
<fileset dir="${project.build.directory}/native/agent-output/test" />
79+
</copy>
7380
</target>
7481
</configuration>
75-
<goals>
76-
<goal>run</goal>
77-
</goals>
7882
</execution>
7983
</executions>
8084
</plugin>
8185
<plugin>
82-
<groupId>org.apache.maven.plugins</groupId>
83-
<artifactId>maven-surefire-plugin</artifactId>
86+
<groupId>org.graalvm.buildtools</groupId>
87+
<artifactId>native-maven-plugin</artifactId>
88+
<extensions>true</extensions>
8489
<configuration>
85-
<argLine>-agentlib:native-image-agent=access-filter-file=access-filter.json,config-merge-dir=target/classes/META-INF/native-image</argLine>
90+
<agent>
91+
<enabled>true</enabled>
92+
<options name="test">
93+
<option>access-filter-file=${basedir}/access-filter.json</option>
94+
</options>
95+
</agent>
8696
</configuration>
8797
</plugin>
8898
</plugins>

spring-native-docs/src/main/asciidoc/tracing-agent.adoc

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ When using the agent to compute configuration for native-image, there are a coup
1010

1111
The first option is interesting for identifying the missing native configuration when a library or a pattern is not recognized by Spring Native.
1212

13-
NOTE: See this related https://github.com/oracle/graal/issues/3283[graal#3283] issue that should make this process much easier. For now, you can make a manual diff between the native configuration generated by Spring Native and the one generated by the tracing agent.
14-
1513
The second option sounds more appealing for a repeatable setup but by default the generated configuration will include anything required by the test infrastructure, which is unnecessary when the application runs for real.
1614
To address this problem the agent supports an access-filter file that will cause certain data to be excluded from the generated output.
1715

@@ -92,15 +90,42 @@ This following snippet would go into the maven pom:
9290
<!-- ... -->
9391
<plugin>
9492
<groupId>org.apache.maven.plugins</groupId>
95-
<artifactId>maven-surefire-plugin</artifactId>
93+
<artifactId>maven-antrun-plugin</artifactId>
94+
<executions>
95+
<execution>
96+
<id>copy-agent-config</id>
97+
<phase>prepare-package</phase>
98+
<goals>
99+
<goal>run</goal>
100+
</goals>
101+
<configuration>
102+
<target>
103+
<mkdir dir="${project.build.directory}/native/agent-output/main"/>
104+
<copy todir="${project.build.directory}/native/agent-output/main">
105+
<fileset dir="${project.build.directory}/native/agent-output/test" />
106+
</copy>
107+
</target>
108+
</configuration>
109+
</execution>
110+
</executions>
111+
</plugin>
112+
<plugin>
113+
<groupId>org.graalvm.buildtools</groupId>
114+
<artifactId>native-maven-plugin</artifactId>
115+
<extensions>true</extensions>
96116
<configuration>
97-
<argLine>-agentlib:native-image-agent=access-filter-file=access-filter.json,config-merge-dir=target/classes/META-INF/native-image</argLine>
117+
<agent>
118+
<enabled>true</enabled>
119+
<options name="test">
120+
<option>access-filter-file=${basedir}/access-filter.json</option>
121+
</options>
122+
</agent>
98123
</configuration>
99124
</plugin>
100125
</plugins>
101126
----
102127

103-
NOTE: You need to activate the AOT mode when running the tracing agent on the application as documented in <<spring-aot-modes>>,
128+
NOTE: You need to activate the AOT mode when running the tracing agent on the application as documented in <<aot-modes>>,
104129
for tests this is not needed since AOT mode is enabled automatically when AOT files are detected.
105130

106131
Also update the `spring-aot` build plugin to enable the `native-agent` mode in order to not generate `*-config.json` files since the agent will take care of that:
@@ -116,6 +141,4 @@ Also update the `spring-aot` build plugin to enable the `native-agent` mode in o
116141
</plugin>
117142
----
118143

119-
Run the JVM tests with `mvn clean test` to generate the native configuration, then build the native image with `mvn -DskipTests -Pnative package`. If that's not enough, you can add additional native configuration using `@NativeHint` annotations.
120-
121-
WARNING: If you see a `java.lang.ClassCastException: sun.reflect.generics.tree.FieldTypeSignature[] cannot be cast to java.lang.reflect.Type[]` error, this is a GraalVM bug related to https://github.com/oracle/graal/pull/4075. A workaround is to replace `queryAll*` entries by "All*" entries.
144+
Build the native image with `mvn -Pnative -DskipNativeTests package`. If that's not enough, you can add additional native configuration using `@NativeHint` annotations.

0 commit comments

Comments
 (0)