diff --git a/src/java/frameworks/azure_application_insights_agent.go b/src/java/frameworks/azure_application_insights_agent.go index c4f65e1b3..b80f47530 100644 --- a/src/java/frameworks/azure_application_insights_agent.go +++ b/src/java/frameworks/azure_application_insights_agent.go @@ -101,16 +101,12 @@ func (a *AzureApplicationInsightsAgentFramework) Supply() error { a.context.Log.Warning("Could not install default Azure Application Insights configuration: %s", err.Error()) } - // Find the installed JAR - jarPattern := filepath.Join(agentDir, "applicationinsights-agent-*.jar") - matches, err := filepath.Glob(jarPattern) + // constructJarPath can be skipped here and do it only in finalize, but it can be left as a double check + // if jar path exists after the dependency install + err = a.constructJarPath(agentDir) if err != nil { - return fmt.Errorf("failed to search for Azure Application Insights agent JAR: %w", err) - } - if len(matches) == 0 { - return fmt.Errorf("Azure Application Insights agent JAR not found after installation in %s", agentDir) + return fmt.Errorf("azure application insights agent not found during supply: %w", err) } - a.jarPath = matches[0] a.context.Log.Info("Azure Application Insights agent %s installed", dep.Version) return nil @@ -145,8 +141,10 @@ func (a *AzureApplicationInsightsAgentFramework) installDefaultConfiguration(age // Finalize configures the Azure Application Insights agent func (a *AzureApplicationInsightsAgentFramework) Finalize() error { - if a.jarPath == "" { - return nil + agentDir := filepath.Join(a.context.Stager.DepDir(), "azure_application_insights_agent") + err := a.constructJarPath(agentDir) + if err != nil { + return fmt.Errorf("azure application insights agent not found during finalize: %w", err) } a.context.Log.BeginStep("Configuring Azure Application Insights agent") @@ -277,3 +275,17 @@ func (a *AzureApplicationInsightsAgentFramework) getApplicationName() string { return "" } + +func (a *AzureApplicationInsightsAgentFramework) constructJarPath(agentDir string) error { + // Find the installed JAR + jarPattern := filepath.Join(agentDir, "applicationinsights-agent-*.jar") + matches, err := filepath.Glob(jarPattern) + if err != nil { + return fmt.Errorf("failed to search for Azure Application Insights agent JAR: %w", err) + } + if len(matches) == 0 { + return fmt.Errorf("agent jar not found after installation in %s", agentDir) + } + a.jarPath = matches[0] + return nil +} diff --git a/src/java/frameworks/checkmarx_iast_agent.go b/src/java/frameworks/checkmarx_iast_agent.go index cc4b5341a..1cef5b317 100644 --- a/src/java/frameworks/checkmarx_iast_agent.go +++ b/src/java/frameworks/checkmarx_iast_agent.go @@ -88,9 +88,8 @@ func (c *CheckmarxIASTAgentFramework) Supply() error { // Finalize configures the Checkmarx IAST agent func (c *CheckmarxIASTAgentFramework) Finalize() error { - if c.jarPath == "" { - return nil - } + agentDir := filepath.Join(c.context.Stager.DepDir(), "checkmarx_iast_agent") + c.jarPath = filepath.Join(agentDir, "cx-agent.jar") c.context.Log.BeginStep("Configuring Checkmarx IAST agent") diff --git a/src/java/frameworks/datadog_javaagent.go b/src/java/frameworks/datadog_javaagent.go index 07f961675..f767dd1c5 100644 --- a/src/java/frameworks/datadog_javaagent.go +++ b/src/java/frameworks/datadog_javaagent.go @@ -96,21 +96,11 @@ func (d *DatadogJavaagentFramework) Supply() error { return fmt.Errorf("failed to install Datadog Javaagent: %w", err) } - // Find the installed JAR - jarPattern := filepath.Join(datadogDir, "dd-java-agent*.jar") - matches, err := filepath.Glob(jarPattern) + // constructJarPathAndFixClassCount can be skipped here and do it only in finalize, but it can be left + // as a double check if jar path exists after the dependency install + err = d.constructJarPathAndFixClassCount(datadogDir) if err != nil { - return fmt.Errorf("failed to search for Datadog agent JAR: %w", err) - } - if len(matches) == 0 { - return fmt.Errorf("Datadog agent JAR not found after installation in %s", datadogDir) - } - d.jarPath = matches[0] - - // Fix class count (critical for Datadog agent) - if err := d.fixClassCount(); err != nil { - d.context.Log.Warning("Failed to fix class count: %s", err) - // Continue anyway + return fmt.Errorf("datadog Java agent JAR path not found during supply: %w", err) } d.context.Log.Info("Datadog Java agent %s installed", dep.Version) @@ -119,8 +109,10 @@ func (d *DatadogJavaagentFramework) Supply() error { // Finalize configures the Datadog Java agent func (d *DatadogJavaagentFramework) Finalize() error { - if d.jarPath == "" { - return nil + datadogDir := filepath.Join(d.context.Stager.DepDir(), "datadog_javaagent") + err := d.constructJarPathAndFixClassCount(datadogDir) + if err != nil { + return fmt.Errorf("datadog Java agent JAR path not found during finalize: %w", err) } d.context.Log.BeginStep("Configuring Datadog Java agent") @@ -310,3 +302,23 @@ func (d *DatadogJavaagentFramework) getApplicationVersion() string { return "" } + +func (d *DatadogJavaagentFramework) constructJarPathAndFixClassCount(datadogDir string) error { + // Find the installed JAR + jarPattern := filepath.Join(datadogDir, "dd-java-agent*.jar") + matches, err := filepath.Glob(jarPattern) + if err != nil { + return fmt.Errorf("failed to search for Datadog agent JAR: %w", err) + } + if len(matches) == 0 { + return fmt.Errorf("agent jar not found after installation in %s", datadogDir) + } + d.jarPath = matches[0] + + // Fix class count (critical for Datadog agent) + if err := d.fixClassCount(); err != nil { + d.context.Log.Warning("Failed to fix class count: %s", err) + // Continue anyway + } + return nil +} diff --git a/src/java/frameworks/elastic_apm_agent.go b/src/java/frameworks/elastic_apm_agent.go index 7e7469142..16f55ca90 100644 --- a/src/java/frameworks/elastic_apm_agent.go +++ b/src/java/frameworks/elastic_apm_agent.go @@ -73,16 +73,10 @@ func (e *ElasticApmAgentFramework) Supply() error { return fmt.Errorf("failed to install Elastic APM agent: %w", err) } - // Find the installed JAR - jarPattern := filepath.Join(elasticDir, "elastic-apm-agent*.jar") - matches, err := filepath.Glob(jarPattern) + err = e.constructJarPath(elasticDir) if err != nil { - return fmt.Errorf("failed to search for Elastic APM agent JAR: %w", err) + return fmt.Errorf("elastic apm agent jar not found during supply: %w", err) } - if len(matches) == 0 { - return fmt.Errorf("Elastic APM agent JAR not found after installation in %s", elasticDir) - } - e.jarPath = matches[0] e.context.Log.Info("Elastic APM agent %s installed", dep.Version) return nil @@ -90,9 +84,17 @@ func (e *ElasticApmAgentFramework) Supply() error { // Finalize configures the Elastic APM agent func (e *ElasticApmAgentFramework) Finalize() error { - if e.jarPath == "" || e.service == nil { - return nil + elasticDir := filepath.Join(e.context.Stager.DepDir(), "elastic_apm_agent") + err := e.constructJarPath(elasticDir) + if err != nil { + return fmt.Errorf("elastic apm agent jar not found during finalize: %w", err) + } + service := e.findElasticApmService() + // service should not be nil as detect has already passed + if service == nil { + e.context.Log.Debug("Elastic APM Agent: No elastic-apm service found") } + e.service = service e.context.Log.BeginStep("Configuring Elastic APM agent") @@ -257,3 +259,17 @@ func (e *ElasticApmAgentFramework) getApplicationName() string { return "" } + +func (e *ElasticApmAgentFramework) constructJarPath(elasticDir string) error { + // Find the installed JAR + jarPattern := filepath.Join(elasticDir, "elastic-apm-agent*.jar") + matches, err := filepath.Glob(jarPattern) + if err != nil { + return fmt.Errorf("failed to search for Elastic APM agent JAR: %w", err) + } + if len(matches) == 0 { + return fmt.Errorf("agent jar not found after installation in %s", elasticDir) + } + e.jarPath = matches[0] + return nil +} diff --git a/src/java/frameworks/google_stackdriver_profiler.go b/src/java/frameworks/google_stackdriver_profiler.go index 2e08da7c9..ac1d1c166 100644 --- a/src/java/frameworks/google_stackdriver_profiler.go +++ b/src/java/frameworks/google_stackdriver_profiler.go @@ -83,12 +83,12 @@ func (g *GoogleStackdriverProfilerFramework) Supply() error { return fmt.Errorf("failed to install Google Stackdriver Profiler: %w", err) } - // Find the installed agent (native library) - agentPattern := filepath.Join(profilerDir, "profiler_java_agent.so") - if _, err := os.Stat(agentPattern); err != nil { - return fmt.Errorf("Google Stackdriver Profiler agent not found after installation: %w", err) + // constructAgentPath can be skipped here and do it only in finalize, but it can be left as a double check + // if jar path exists after the dependency install + err = g.constructAgentPath(profilerDir) + if err != nil { + return fmt.Errorf("google stackdriver profiler agent not found during supply: %w", err) } - g.agentPath = agentPattern g.context.Log.Info("Google Stackdriver Profiler %s installed", dep.Version) return nil @@ -96,8 +96,10 @@ func (g *GoogleStackdriverProfilerFramework) Supply() error { // Finalize configures the Google Stackdriver Profiler func (g *GoogleStackdriverProfilerFramework) Finalize() error { - if g.agentPath == "" { - return nil + profilerDir := filepath.Join(g.context.Stager.DepDir(), "google_stackdriver_profiler") + err := g.constructAgentPath(profilerDir) + if err != nil { + return fmt.Errorf("google stackdriver profiler agent not found during finalize: %w", err) } g.context.Log.BeginStep("Configuring Google Stackdriver Profiler") @@ -233,3 +235,13 @@ func (g *GoogleStackdriverProfilerFramework) getApplicationVersion() string { return "" } + +func (g *GoogleStackdriverProfilerFramework) constructAgentPath(profilerDir string) error { + // Find the installed agent (native library) + agentPattern := filepath.Join(profilerDir, "profiler_java_agent.so") + if _, err := os.Stat(agentPattern); err != nil { + return fmt.Errorf("agent not found after installation: %w", err) + } + g.agentPath = agentPattern + return nil +} diff --git a/src/java/frameworks/introscope_agent.go b/src/java/frameworks/introscope_agent.go index c9e81180d..98a71c0cd 100644 --- a/src/java/frameworks/introscope_agent.go +++ b/src/java/frameworks/introscope_agent.go @@ -63,12 +63,12 @@ func (i *IntroscopeAgentFramework) Supply() error { return fmt.Errorf("failed to install Introscope agent: %w", err) } - // Find the installed agent JAR - agentPattern := filepath.Join(agentDir, "Agent.jar") - if _, err := os.Stat(agentPattern); err != nil { - return fmt.Errorf("Introscope Agent.jar not found after installation: %w", err) + // constructAgentPath can be skipped here and do it only in finalize, but it can be left as a double check + // if jar path exists after the dependency install + err = i.constructAgentPath(agentDir) + if err != nil { + return fmt.Errorf("introscope Agent.jar not found during supply: %w", err) } - i.agentPath = agentPattern i.context.Log.Info("Introscope agent %s installed", dep.Version) return nil @@ -76,8 +76,10 @@ func (i *IntroscopeAgentFramework) Supply() error { // Finalize configures the Introscope agent func (i *IntroscopeAgentFramework) Finalize() error { - if i.agentPath == "" { - return nil + agentDir := filepath.Join(i.context.Stager.DepDir(), "introscope_agent") + err := i.constructAgentPath(agentDir) + if err != nil { + return fmt.Errorf("introscope Agent.jar not found during finalize: %w", err) } i.context.Log.BeginStep("Configuring Introscope agent") @@ -241,3 +243,13 @@ func (i *IntroscopeAgentFramework) getApplicationName() string { return "" } + +func (i *IntroscopeAgentFramework) constructAgentPath(agentDir string) error { + // Find the installed agent JAR + agentPattern := filepath.Join(agentDir, "Agent.jar") + if _, err := os.Stat(agentPattern); err != nil { + return fmt.Errorf("agent jar not found after installation: %w", err) + } + i.agentPath = agentPattern + return nil +} diff --git a/src/java/frameworks/maria_db_jdbc.go b/src/java/frameworks/maria_db_jdbc.go index 149768b9f..3f8010e74 100644 --- a/src/java/frameworks/maria_db_jdbc.go +++ b/src/java/frameworks/maria_db_jdbc.go @@ -67,16 +67,12 @@ func (f *MariaDBJDBCFramework) Supply() error { return fmt.Errorf("failed to install MariaDB JDBC: %w", err) } - // Find the installed JAR - jarPattern := filepath.Join(mariadbDir, "mariadb-jdbc-*.jar") - matches, err := filepath.Glob(jarPattern) + // constructJarPath can be skipped here and do it only in finalize, but it can be left as a double check + // if jar path exists after the dependency install + err = f.constructJarPath(mariadbDir) if err != nil { - return fmt.Errorf("failed to search for MariaDB JDBC JAR: %w", err) - } - if len(matches) == 0 { - return fmt.Errorf("MariaDB JDBC JAR not found after installation in %s", mariadbDir) + return fmt.Errorf("jdbc jar not found during supply: %w", err) } - f.jarPath = matches[0] f.context.Log.Info("MariaDB JDBC %s installed", dep.Version) return nil @@ -84,9 +80,10 @@ func (f *MariaDBJDBCFramework) Supply() error { // Finalize adds the MariaDB JDBC driver to the classpath func (f *MariaDBJDBCFramework) Finalize() error { - if f.jarPath == "" { - // Not installed, skip - return nil + mariadbDir := filepath.Join(f.context.Stager.DepDir(), "mariadb_jdbc") + err := f.constructJarPath(mariadbDir) + if err != nil { + return fmt.Errorf("jdbc jar not found during finalize: %w", err) } f.context.Log.BeginStep("Configuring MariaDB JDBC driver") @@ -192,3 +189,16 @@ func (f *MariaDBJDBCFramework) hasExistingDriver() bool { return false } + +func (f *MariaDBJDBCFramework) constructJarPath(mariadbDir string) error { + jarPattern := filepath.Join(mariadbDir, "mariadb-jdbc-*.jar") + matches, err := filepath.Glob(jarPattern) + if err != nil { + return fmt.Errorf("failed to search for MariaDB JDBC JAR: %w", err) + } + if len(matches) == 0 { + return fmt.Errorf("jdbc jar not found after installation in %s", mariadbDir) + } + f.jarPath = matches[0] + return nil +} diff --git a/src/java/frameworks/riverbed_appinternals_agent.go b/src/java/frameworks/riverbed_appinternals_agent.go index 218eae7b9..3f76a0a53 100644 --- a/src/java/frameworks/riverbed_appinternals_agent.go +++ b/src/java/frameworks/riverbed_appinternals_agent.go @@ -63,12 +63,12 @@ func (r *RiverbedAppInternalsAgentFramework) Supply() error { return fmt.Errorf("failed to install Riverbed AppInternals agent: %w", err) } - // Find the installed agent directory (contains lib/rvbd-agent.jar) - agentJarPath := filepath.Join(agentDir, "lib", "rvbd-agent.jar") - if _, err := os.Stat(agentJarPath); err != nil { - return fmt.Errorf("Riverbed AppInternals agent JAR not found after installation: %w", err) + // constructAgentJarPath can be skipped here and do it only in finalize, but it can be left as a double check + // if jar path exists after the dependency install + err = r.constructAgentJarPath(agentDir) + if err != nil { + return fmt.Errorf("riverbed appinternals agent JAR not found during supply: %w", err) } - r.agentPath = agentJarPath r.context.Log.Info("Riverbed AppInternals agent %s installed", dep.Version) return nil @@ -76,8 +76,10 @@ func (r *RiverbedAppInternalsAgentFramework) Supply() error { // Finalize configures the Riverbed AppInternals agent func (r *RiverbedAppInternalsAgentFramework) Finalize() error { - if r.agentPath == "" { - return nil + agentDir := filepath.Join(r.context.Stager.DepDir(), "riverbed_appinternals_agent") + err := r.constructAgentJarPath(agentDir) + if err != nil { + return fmt.Errorf("riverbed appinternals agent JAR not found during finalize: %w", err) } r.context.Log.BeginStep("Configuring Riverbed AppInternals agent") @@ -214,3 +216,13 @@ func (r *RiverbedAppInternalsAgentFramework) getApplicationName() string { return "" } + +func (r *RiverbedAppInternalsAgentFramework) constructAgentJarPath(agentDir string) error { + // Find the installed agent directory (contains lib/rvbd-agent.jar) + agentJarPath := filepath.Join(agentDir, "lib", "rvbd-agent.jar") + if _, err := os.Stat(agentJarPath); err != nil { + return fmt.Errorf("agent jar not found after installation: %w", err) + } + r.agentPath = agentJarPath + return nil +} diff --git a/src/java/frameworks/sky_walking_agent.go b/src/java/frameworks/sky_walking_agent.go index 2b34bca9c..9edb9b5e6 100644 --- a/src/java/frameworks/sky_walking_agent.go +++ b/src/java/frameworks/sky_walking_agent.go @@ -81,12 +81,12 @@ func (s *SkyWalkingAgentFramework) Supply() error { return fmt.Errorf("failed to install SkyWalking agent: %w", err) } - // Find the installed agent JAR (in skywalking-agent subdirectory) - jarPattern := filepath.Join(agentDir, "skywalking-agent", "skywalking-agent.jar") - if _, err := os.Stat(jarPattern); err != nil { - return fmt.Errorf("SkyWalking agent JAR not found after installation: %w", err) + // constructJarPath can be skipped here and do it only in finalize, but it can be left as a double check + // if jar path exists after the dependency install + err = s.constructJarPath(agentDir) + if err != nil { + return fmt.Errorf("agent jar path not found during supply: %w", err) } - s.jarPath = jarPattern s.context.Log.Info("SkyWalking agent %s installed", dep.Version) return nil @@ -94,8 +94,10 @@ func (s *SkyWalkingAgentFramework) Supply() error { // Finalize configures the SkyWalking agent func (s *SkyWalkingAgentFramework) Finalize() error { - if s.jarPath == "" { - return nil + agentDir := filepath.Join(s.context.Stager.DepDir(), "sky_walking_agent") + err := s.constructJarPath(agentDir) + if err != nil { + return fmt.Errorf("agent jar path not found during finalize: %w", err) } s.context.Log.BeginStep("Configuring SkyWalking agent") @@ -197,3 +199,13 @@ func (s *SkyWalkingAgentFramework) getCredentials() SkyWalkingCredentials { return creds } + +func (s *SkyWalkingAgentFramework) constructJarPath(agentDir string) error { + // Find the installed agent JAR (in skywalking-agent subdirectory) + jarPattern := filepath.Join(agentDir, "skywalking-agent", "skywalking-agent.jar") + if _, err := os.Stat(jarPattern); err != nil { + return fmt.Errorf("agent jar not found after installation: %w", err) + } + s.jarPath = jarPattern + return nil +} diff --git a/src/java/frameworks/splunk_otel_java_agent.go b/src/java/frameworks/splunk_otel_java_agent.go index e0ee8610e..7a3785a1b 100644 --- a/src/java/frameworks/splunk_otel_java_agent.go +++ b/src/java/frameworks/splunk_otel_java_agent.go @@ -90,16 +90,12 @@ func (s *SplunkOtelJavaAgentFramework) Supply() error { return fmt.Errorf("failed to install Splunk OTEL Java agent: %w", err) } - // Find the installed agent JAR - jarPattern := filepath.Join(agentDir, "splunk-otel-javaagent.jar") - if _, err := os.Stat(jarPattern); err != nil { - // Try alternative name - jarPattern = filepath.Join(agentDir, "splunk-otel-javaagent-all.jar") - if _, err := os.Stat(jarPattern); err != nil { - return fmt.Errorf("Splunk OTEL Java agent JAR not found after installation in %s (tried both splunk-otel-javaagent.jar and splunk-otel-javaagent-all.jar)", agentDir) - } + // constructJarPath can be skipped here and do it only in finalize, but it can be left as a double check + // if jar path exists after the dependency install + err = s.constructJarPath(agentDir) + if err != nil { + return fmt.Errorf("splunk OTEL Java agent JAR path not found during supply: %w", err) } - s.jarPath = jarPattern s.context.Log.Info("Splunk OTEL Java agent %s installed", dep.Version) return nil @@ -107,8 +103,10 @@ func (s *SplunkOtelJavaAgentFramework) Supply() error { // Finalize configures the Splunk OTEL Java agent func (s *SplunkOtelJavaAgentFramework) Finalize() error { - if s.jarPath == "" { - return nil + agentDir := filepath.Join(s.context.Stager.DepDir(), "splunk_otel_java_agent") + err := s.constructJarPath(agentDir) + if err != nil { + return fmt.Errorf("splunk OTEL Java agent JAR path not found during finalize: %w", err) } s.context.Log.BeginStep("Configuring Splunk OTEL Java agent") @@ -254,3 +252,16 @@ func (s *SplunkOtelJavaAgentFramework) getApplicationName() string { return "" } + +func (s *SplunkOtelJavaAgentFramework) constructJarPath(agentDir string) error { + jarPattern := filepath.Join(agentDir, "splunk-otel-javaagent.jar") + if _, err := os.Stat(jarPattern); err != nil { + // Try alternative name + jarPattern = filepath.Join(agentDir, "splunk-otel-javaagent-all.jar") + if _, err := os.Stat(jarPattern); err != nil { + return fmt.Errorf("javaagent jar not found after installation in %s (tried both splunk-otel-javaagent.jar and splunk-otel-javaagent-all.jar)", agentDir) + } + } + s.jarPath = jarPattern + return nil +}