5656import java .util .List ;
5757import java .util .stream .Collectors ;
5858
59- import static org .graalvm .buildtools .utils .Utils .parseBoolean ;
60-
6159public abstract class AgentUtils {
6260
61+ private static final String STANDARD = "standard" ;
62+ private static final String CONDITIONAL = "conditional" ;
63+ private static final String DIRECT = "direct" ;
64+ private static final String DISABLED = "disabled" ;
65+
6366 public static AgentMode getAgentMode (Xpp3Dom agent ) throws Exception {
6467 Xpp3Dom defaultModeNode = Xpp3DomParser .getTagByName (agent , "defaultMode" );
6568 // if default mode is not provided in pom, return Standard mode
@@ -72,13 +75,13 @@ public static AgentMode getAgentMode(Xpp3Dom agent) throws Exception {
7275 AgentMode agentMode ;
7376 String mode = defaultModeNode .getValue ();
7477 switch (mode .toLowerCase ()) {
75- case "standard" :
76- agentMode = new StandardAgentMode ();
77- break ;
78- case "disabled" :
78+ case DISABLED :
7979 agentMode = new DisabledAgentMode ();
8080 break ;
81- case "conditional" :
81+ case STANDARD :
82+ agentMode = new StandardAgentMode ();
83+ break ;
84+ case CONDITIONAL :
8285 // conditional mode needs few more options declared in xml
8386 if (agentModes == null ) {
8487 throw new RuntimeException ("Tag <modes> not provided in agent configuration." );
@@ -91,12 +94,12 @@ public static AgentMode getAgentMode(Xpp3Dom agent) throws Exception {
9194 throw new Exception ("UserCodeFilterPath must be provided in agent configuration" );
9295 }
9396
94- Boolean parallel = parseBooleanNode (agentModes , "parallel" );
97+ Boolean parallel = Utils . parseBooleanNode (agentModes , "parallel" );
9598 agentMode = new ConditionalAgentMode (userCodeFilterPathNode .getValue (),
9699 extraFilterPathNode != null ? extraFilterPathNode .getValue () : "" ,
97100 parallel == null ? false : parallel );
98101 break ;
99- case "direct" :
102+ case DIRECT :
100103 // direct mode is given
101104 if (agentModes == null ) {
102105 throw new RuntimeException ("Tag <modes> not provided in agent configuration." );
@@ -138,11 +141,11 @@ public static AgentConfiguration collectAgentProperties(MavenSession session, Xp
138141
139142 ArrayList <String > callerFilterFiles = (ArrayList <String >) getFilterFiles (options , "callerFilterFiles" );
140143 ArrayList <String > accessFilterFiles = (ArrayList <String >) getFilterFiles (options , "accessFilterFiles" );
141- Boolean builtinCallerFilter = parseBooleanNode (options , "builtinCallerFilter" );
142- Boolean builtinHeuristicFilter = parseBooleanNode (options , "builtinHeuristicFilter" );
143- Boolean enableExperimentalPredefinedClasses = parseBooleanNode (options , "enableExperimentalPredefinedClasses" );
144- Boolean enableExperimentalUnsafeAllocationTracing = parseBooleanNode (options , "enableExperimentalUnsafeAllocationTracing" );
145- Boolean trackReflectionMetadata = parseBooleanNode (options , "trackReflectionMetadata" );
144+ Boolean builtinCallerFilter = Utils . parseBooleanNode (options , "builtinCallerFilter" );
145+ Boolean builtinHeuristicFilter = Utils . parseBooleanNode (options , "builtinHeuristicFilter" );
146+ Boolean enableExperimentalPredefinedClasses = Utils . parseBooleanNode (options , "enableExperimentalPredefinedClasses" );
147+ Boolean enableExperimentalUnsafeAllocationTracing = Utils . parseBooleanNode (options , "enableExperimentalUnsafeAllocationTracing" );
148+ Boolean trackReflectionMetadata = Utils . parseBooleanNode (options , "trackReflectionMetadata" );
146149
147150 AgentMode mode ;
148151 try {
@@ -175,7 +178,7 @@ private static Boolean isAgentEnabledInCmd(MavenSession session) {
175178 String systemProperty = session .getSystemProperties ().getProperty ("agent" );
176179 if (systemProperty != null ) {
177180 // -Dagent=[true|false] overrides configuration in the POM.
178- return parseBoolean ("agent system property" , systemProperty );
181+ return Boolean . parseBoolean (systemProperty );
179182 }
180183
181184 return null ;
@@ -187,7 +190,7 @@ private static boolean isAgentEnabled(MavenSession session, Xpp3Dom agent) {
187190 return cmdEnable ;
188191 }
189192
190- Boolean val = parseBooleanNode (agent , "enabled" );
193+ Boolean val = Utils . parseBooleanNode (agent , "enabled" );
191194 if (val == null ) {
192195 return false ;
193196 }
@@ -210,18 +213,4 @@ private static List<String> getFilterFiles(Xpp3Dom root, String type) {
210213 .map (Xpp3Dom ::getValue )
211214 .collect (Collectors .toCollection (ArrayList ::new ));
212215 }
213-
214- private static Boolean parseBooleanNode (Xpp3Dom root , String name ) {
215- if (root == null ) {
216- return null ;
217- }
218-
219- Xpp3Dom node = Xpp3DomParser .getTagByName (root , name );
220- if (node == null ) {
221- // if node is not provided, default value is false
222- return null ;
223- }
224-
225- return Utils .parseBoolean ("<" + name + ">" , node .getValue ());
226- }
227216}
0 commit comments