@@ -38,13 +38,13 @@ func NewJProfilerProfilerFramework(ctx *common.Context) *JProfilerProfilerFramew
3838func (f * JProfilerProfilerFramework ) Detect () (string , error ) {
3939 // JProfiler is disabled by default
4040 // Check for JBP_CONFIG_JPROFILER_PROFILER='{enabled: true}'
41- enabled := os . Getenv ( "JBP_CONFIG_JPROFILER_PROFILER" )
42- if enabled != "" {
43- // Check if "enabled:true" in the agent options
44- // We need case-insensitive check due to inconsistent casing
45- if common . ContainsIgnoreCase ( enabled , "enabled" ) && common . ContainsIgnoreCase ( enabled , "true" ) {
46- return "JProfiler Profiler" , nil
47- }
41+ config , err := f . loadConfig ( )
42+ if err != nil {
43+ f . context . Log . Warning ( "Failed to load jprofile profiler config: %s" , err . Error ())
44+ return "" , nil // Don't fail the build
45+ }
46+ if config . isEnabled () {
47+ return "JProfiler Profiler" , nil
4848 }
4949
5050 return "" , nil
@@ -111,24 +111,20 @@ func (f *JProfilerProfilerFramework) Finalize() error {
111111 }
112112 runtimeAgentPath := filepath .Join (fmt .Sprintf ("$DEPS_DIR/%s" , depsIdx ), relPath )
113113
114- // Build agent options
115- // Default options: port=8849, nowait (don't wait for profiler UI to connect)
116- port := "8849"
117- portConfig := os .Getenv ("JBP_CONFIG_JPROFILER_PROFILER" )
118- if portConfig != "" && common .ContainsIgnoreCase (portConfig , "port" ) {
119- // Simple extraction (would need proper YAML parsing in production)
120- // For now, use default
114+ config , err := f .loadConfig ()
115+ if err != nil {
116+ f .context .Log .Warning ("Failed to load jprofile profiler config: %s" , err .Error ())
117+ return nil // Don't fail the build
121118 }
122119
123- // Check for nowait option (default: true)
124- nowait := "nowait"
125- if portConfig != "" && common .ContainsIgnoreCase (portConfig , "nowait" ) && common .ContainsIgnoreCase (portConfig , "false" ) {
126- nowait = ""
127- }
120+ // Build agent options
121+ // Default options: port=8849, nowait (don't wait for profiler UI to connect)
122+ port := config .Port
123+ nowait := config .NoWait
128124
129125 // Build agent path with options
130126 var agentOptions string
131- if nowait != "" {
127+ if nowait {
132128 agentOptions = fmt .Sprintf ("port=%s,%s" , port , nowait )
133129 } else {
134130 agentOptions = fmt .Sprintf ("port=%s" , port )
@@ -143,3 +139,35 @@ func (f *JProfilerProfilerFramework) Finalize() error {
143139 f .context .Log .Info ("JProfiler Profiler configured (priority 30)" )
144140 return nil
145141}
142+
143+ func (f * JProfilerProfilerFramework ) loadConfig () (* jProfilerConfig , error ) {
144+ // initialize default values
145+ jpConfig := jProfilerConfig {
146+ Enabled : false ,
147+ NoWait : true ,
148+ Port : 8849 ,
149+ }
150+ config := os .Getenv ("JBP_CONFIG_JPROFILER_PROFILER" )
151+ if config != "" {
152+ yamlHandler := common.YamlHandler {}
153+ err := yamlHandler .ValidateFields ([]byte (config ), & jpConfig )
154+ if err != nil {
155+ f .context .Log .Warning ("Unknown user config values: %s" , err .Error ())
156+ }
157+ // overlay JBP_CONFIG_JPROFILER_PROFILER over default values
158+ if err = yamlHandler .Unmarshal ([]byte (config ), & jpConfig ); err != nil {
159+ return nil , fmt .Errorf ("failed to parse JBP_CONFIG_JPROFILER_PROFILER: %w" , err )
160+ }
161+ }
162+ return & jpConfig , nil
163+ }
164+
165+ type jProfilerConfig struct {
166+ Enabled bool `yaml:"enabled"`
167+ NoWait bool `yaml:"nowait"`
168+ Port int `yaml:"port"`
169+ }
170+
171+ func (j * jProfilerConfig ) isEnabled () bool {
172+ return j .Enabled
173+ }
0 commit comments