Skip to content

Commit 4691caf

Browse files
committed
Fix omit finalize for frameworks
1 parent 16950ce commit 4691caf

8 files changed

Lines changed: 137 additions & 69 deletions

src/java/frameworks/azure_application_insights_agent.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,10 @@ func (a *AzureApplicationInsightsAgentFramework) Supply() error {
101101
a.context.Log.Warning("Could not install default Azure Application Insights configuration: %s", err.Error())
102102
}
103103

104-
// Find the installed JAR
105-
jarPattern := filepath.Join(agentDir, "applicationinsights-agent-*.jar")
106-
matches, err := filepath.Glob(jarPattern)
104+
err = a.constructJarPath(agentDir)
107105
if err != nil {
108-
return fmt.Errorf("failed to search for Azure Application Insights agent JAR: %w", err)
109-
}
110-
if len(matches) == 0 {
111-
return fmt.Errorf("Azure Application Insights agent JAR not found after installation in %s", agentDir)
106+
return fmt.Errorf("azure application insights agent not found during supply: %w", err)
112107
}
113-
a.jarPath = matches[0]
114108

115109
a.context.Log.Info("Azure Application Insights agent %s installed", dep.Version)
116110
return nil
@@ -145,8 +139,10 @@ func (a *AzureApplicationInsightsAgentFramework) installDefaultConfiguration(age
145139

146140
// Finalize configures the Azure Application Insights agent
147141
func (a *AzureApplicationInsightsAgentFramework) Finalize() error {
148-
if a.jarPath == "" {
149-
return nil
142+
agentDir := filepath.Join(a.context.Stager.DepDir(), "azure_application_insights_agent")
143+
err := a.constructJarPath(agentDir)
144+
if err != nil {
145+
return fmt.Errorf("azure application insights agent not found during finalize: %w", err)
150146
}
151147

152148
a.context.Log.BeginStep("Configuring Azure Application Insights agent")
@@ -277,3 +273,17 @@ func (a *AzureApplicationInsightsAgentFramework) getApplicationName() string {
277273

278274
return ""
279275
}
276+
277+
func (a *AzureApplicationInsightsAgentFramework) constructJarPath(agentDir string) error {
278+
// Find the installed JAR
279+
jarPattern := filepath.Join(agentDir, "applicationinsights-agent-*.jar")
280+
matches, err := filepath.Glob(jarPattern)
281+
if err != nil {
282+
return fmt.Errorf("failed to search for Azure Application Insights agent JAR: %w", err)
283+
}
284+
if len(matches) == 0 {
285+
return fmt.Errorf("agent jar not found after installation in %s", agentDir)
286+
}
287+
a.jarPath = matches[0]
288+
return nil
289+
}

src/java/frameworks/checkmarx_iast_agent.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ func (c *CheckmarxIASTAgentFramework) Supply() error {
8888

8989
// Finalize configures the Checkmarx IAST agent
9090
func (c *CheckmarxIASTAgentFramework) Finalize() error {
91-
if c.jarPath == "" {
92-
return nil
93-
}
91+
agentDir := filepath.Join(c.context.Stager.DepDir(), "checkmarx_iast_agent")
92+
c.jarPath = filepath.Join(agentDir, "cx-agent.jar")
9493

9594
c.context.Log.BeginStep("Configuring Checkmarx IAST agent")
9695

src/java/frameworks/datadog_javaagent.go

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,9 @@ func (d *DatadogJavaagentFramework) Supply() error {
9696
return fmt.Errorf("failed to install Datadog Javaagent: %w", err)
9797
}
9898

99-
// Find the installed JAR
100-
jarPattern := filepath.Join(datadogDir, "dd-java-agent*.jar")
101-
matches, err := filepath.Glob(jarPattern)
99+
err = d.constructJarPathAndFixClassCount(datadogDir)
102100
if err != nil {
103-
return fmt.Errorf("failed to search for Datadog agent JAR: %w", err)
104-
}
105-
if len(matches) == 0 {
106-
return fmt.Errorf("Datadog agent JAR not found after installation in %s", datadogDir)
107-
}
108-
d.jarPath = matches[0]
109-
110-
// Fix class count (critical for Datadog agent)
111-
if err := d.fixClassCount(); err != nil {
112-
d.context.Log.Warning("Failed to fix class count: %s", err)
113-
// Continue anyway
101+
return fmt.Errorf("datadog Java agent JAR path not found during supply: %w", err)
114102
}
115103

116104
d.context.Log.Info("Datadog Java agent %s installed", dep.Version)
@@ -119,8 +107,10 @@ func (d *DatadogJavaagentFramework) Supply() error {
119107

120108
// Finalize configures the Datadog Java agent
121109
func (d *DatadogJavaagentFramework) Finalize() error {
122-
if d.jarPath == "" {
123-
return nil
110+
datadogDir := filepath.Join(d.context.Stager.DepDir(), "datadog_javaagent")
111+
err := d.constructJarPathAndFixClassCount(datadogDir)
112+
if err != nil {
113+
return fmt.Errorf("datadog Java agent JAR path not found during finalize: %w", err)
124114
}
125115

126116
d.context.Log.BeginStep("Configuring Datadog Java agent")
@@ -310,3 +300,23 @@ func (d *DatadogJavaagentFramework) getApplicationVersion() string {
310300

311301
return ""
312302
}
303+
304+
func (d *DatadogJavaagentFramework) constructJarPathAndFixClassCount(datadogDir string) error {
305+
// Find the installed JAR
306+
jarPattern := filepath.Join(datadogDir, "dd-java-agent*.jar")
307+
matches, err := filepath.Glob(jarPattern)
308+
if err != nil {
309+
return fmt.Errorf("failed to search for Datadog agent JAR: %w", err)
310+
}
311+
if len(matches) == 0 {
312+
return fmt.Errorf("agent jar not found after installation in %s", datadogDir)
313+
}
314+
d.jarPath = matches[0]
315+
316+
// Fix class count (critical for Datadog agent)
317+
if err := d.fixClassCount(); err != nil {
318+
d.context.Log.Warning("Failed to fix class count: %s", err)
319+
// Continue anyway
320+
}
321+
return nil
322+
}

src/java/frameworks/google_stackdriver_profiler.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,21 @@ func (g *GoogleStackdriverProfilerFramework) Supply() error {
8383
return fmt.Errorf("failed to install Google Stackdriver Profiler: %w", err)
8484
}
8585

86-
// Find the installed agent (native library)
87-
agentPattern := filepath.Join(profilerDir, "profiler_java_agent.so")
88-
if _, err := os.Stat(agentPattern); err != nil {
89-
return fmt.Errorf("Google Stackdriver Profiler agent not found after installation: %w", err)
86+
err = g.constructAgentPath(profilerDir)
87+
if err != nil {
88+
return fmt.Errorf("google stackdriver profiler agent not found during supply: %w", err)
9089
}
91-
g.agentPath = agentPattern
9290

9391
g.context.Log.Info("Google Stackdriver Profiler %s installed", dep.Version)
9492
return nil
9593
}
9694

9795
// Finalize configures the Google Stackdriver Profiler
9896
func (g *GoogleStackdriverProfilerFramework) Finalize() error {
99-
if g.agentPath == "" {
100-
return nil
97+
profilerDir := filepath.Join(g.context.Stager.DepDir(), "google_stackdriver_profiler")
98+
err := g.constructAgentPath(profilerDir)
99+
if err != nil {
100+
return fmt.Errorf("google stackdriver profiler agent not found during finalize: %w", err)
101101
}
102102

103103
g.context.Log.BeginStep("Configuring Google Stackdriver Profiler")
@@ -233,3 +233,13 @@ func (g *GoogleStackdriverProfilerFramework) getApplicationVersion() string {
233233

234234
return ""
235235
}
236+
237+
func (g *GoogleStackdriverProfilerFramework) constructAgentPath(profilerDir string) error {
238+
// Find the installed agent (native library)
239+
agentPattern := filepath.Join(profilerDir, "profiler_java_agent.so")
240+
if _, err := os.Stat(agentPattern); err != nil {
241+
return fmt.Errorf("agent not found after installation: %w", err)
242+
}
243+
g.agentPath = agentPattern
244+
return nil
245+
}

src/java/frameworks/introscope_agent.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,21 @@ func (i *IntroscopeAgentFramework) Supply() error {
6363
return fmt.Errorf("failed to install Introscope agent: %w", err)
6464
}
6565

66-
// Find the installed agent JAR
67-
agentPattern := filepath.Join(agentDir, "Agent.jar")
68-
if _, err := os.Stat(agentPattern); err != nil {
69-
return fmt.Errorf("Introscope Agent.jar not found after installation: %w", err)
66+
err = i.constructAgentPath(agentDir)
67+
if err != nil {
68+
return fmt.Errorf("introscope Agent.jar not found during supply: %w", err)
7069
}
71-
i.agentPath = agentPattern
7270

7371
i.context.Log.Info("Introscope agent %s installed", dep.Version)
7472
return nil
7573
}
7674

7775
// Finalize configures the Introscope agent
7876
func (i *IntroscopeAgentFramework) Finalize() error {
79-
if i.agentPath == "" {
80-
return nil
77+
agentDir := filepath.Join(i.context.Stager.DepDir(), "introscope_agent")
78+
err := i.constructAgentPath(agentDir)
79+
if err != nil {
80+
return fmt.Errorf("ontroscope Agent.jar not found during finalize: %w", err)
8181
}
8282

8383
i.context.Log.BeginStep("Configuring Introscope agent")
@@ -241,3 +241,13 @@ func (i *IntroscopeAgentFramework) getApplicationName() string {
241241

242242
return ""
243243
}
244+
245+
func (i *IntroscopeAgentFramework) constructAgentPath(agentDir string) error {
246+
// Find the installed agent JAR
247+
agentPattern := filepath.Join(agentDir, "Agent.jar")
248+
if _, err := os.Stat(agentPattern); err != nil {
249+
return fmt.Errorf("agent jar not found after installation: %w", err)
250+
}
251+
i.agentPath = agentPattern
252+
return nil
253+
}

src/java/frameworks/maria_db_jdbc.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,25 +68,21 @@ func (f *MariaDBJDBCFramework) Supply() error {
6868
}
6969

7070
// Find the installed JAR
71-
jarPattern := filepath.Join(mariadbDir, "mariadb-jdbc-*.jar")
72-
matches, err := filepath.Glob(jarPattern)
71+
err = f.constructJarPath(mariadbDir)
7372
if err != nil {
74-
return fmt.Errorf("failed to search for MariaDB JDBC JAR: %w", err)
75-
}
76-
if len(matches) == 0 {
77-
return fmt.Errorf("MariaDB JDBC JAR not found after installation in %s", mariadbDir)
73+
return fmt.Errorf("MariaDB JDBC JAR not found during supply: %w", err)
7874
}
79-
f.jarPath = matches[0]
8075

8176
f.context.Log.Info("MariaDB JDBC %s installed", dep.Version)
8277
return nil
8378
}
8479

8580
// Finalize adds the MariaDB JDBC driver to the classpath
8681
func (f *MariaDBJDBCFramework) Finalize() error {
87-
if f.jarPath == "" {
88-
// Not installed, skip
89-
return nil
82+
mariadbDir := filepath.Join(f.context.Stager.DepDir(), "mariadb_jdbc")
83+
err := f.constructJarPath(mariadbDir)
84+
if err != nil {
85+
return fmt.Errorf("MariaDB JDBC JAR not found during finalize: %w", err)
9086
}
9187

9288
f.context.Log.BeginStep("Configuring MariaDB JDBC driver")
@@ -192,3 +188,16 @@ func (f *MariaDBJDBCFramework) hasExistingDriver() bool {
192188

193189
return false
194190
}
191+
192+
func (f *MariaDBJDBCFramework) constructJarPath(mariadbDir string) error {
193+
jarPattern := filepath.Join(mariadbDir, "mariadb-jdbc-*.jar")
194+
matches, err := filepath.Glob(jarPattern)
195+
if err != nil {
196+
return fmt.Errorf("failed to search for MariaDB JDBC JAR: %w", err)
197+
}
198+
if len(matches) == 0 {
199+
return fmt.Errorf("jdbc jar not found after installation in %s", mariadbDir)
200+
}
201+
f.jarPath = matches[0]
202+
return nil
203+
}

src/java/frameworks/riverbed_appinternals_agent.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,21 @@ func (r *RiverbedAppInternalsAgentFramework) Supply() error {
6464
}
6565

6666
// Find the installed agent directory (contains lib/rvbd-agent.jar)
67-
agentJarPath := filepath.Join(agentDir, "lib", "rvbd-agent.jar")
68-
if _, err := os.Stat(agentJarPath); err != nil {
69-
return fmt.Errorf("Riverbed AppInternals agent JAR not found after installation: %w", err)
67+
err = r.constructAgentJarPath(agentDir)
68+
if err != nil {
69+
return fmt.Errorf("riverbed appinternals agent JAR not found during supply: %w", err)
7070
}
71-
r.agentPath = agentJarPath
7271

7372
r.context.Log.Info("Riverbed AppInternals agent %s installed", dep.Version)
7473
return nil
7574
}
7675

7776
// Finalize configures the Riverbed AppInternals agent
7877
func (r *RiverbedAppInternalsAgentFramework) Finalize() error {
79-
if r.agentPath == "" {
80-
return nil
78+
agentDir := filepath.Join(r.context.Stager.DepDir(), "riverbed_appinternals_agent")
79+
err := r.constructAgentJarPath(agentDir)
80+
if err != nil {
81+
return fmt.Errorf("riverbed appinternals agent JAR not found during finalize: %w", err)
8182
}
8283

8384
r.context.Log.BeginStep("Configuring Riverbed AppInternals agent")
@@ -214,3 +215,12 @@ func (r *RiverbedAppInternalsAgentFramework) getApplicationName() string {
214215

215216
return ""
216217
}
218+
219+
func (r *RiverbedAppInternalsAgentFramework) constructAgentJarPath(agentDir string) error {
220+
agentJarPath := filepath.Join(agentDir, "lib", "rvbd-agent.jar")
221+
if _, err := os.Stat(agentJarPath); err != nil {
222+
return fmt.Errorf("agent jar not found after installation: %w", err)
223+
}
224+
r.agentPath = agentJarPath
225+
return nil
226+
}

src/java/frameworks/splunk_otel_java_agent.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,24 +91,21 @@ func (s *SplunkOtelJavaAgentFramework) Supply() error {
9191
}
9292

9393
// Find the installed agent JAR
94-
jarPattern := filepath.Join(agentDir, "splunk-otel-javaagent.jar")
95-
if _, err := os.Stat(jarPattern); err != nil {
96-
// Try alternative name
97-
jarPattern = filepath.Join(agentDir, "splunk-otel-javaagent-all.jar")
98-
if _, err := os.Stat(jarPattern); err != nil {
99-
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)
100-
}
94+
err = s.constructJarPath(agentDir)
95+
if err != nil {
96+
return fmt.Errorf("splunk OTEL Java agent JAR path not found during supply: %w", err)
10197
}
102-
s.jarPath = jarPattern
10398

10499
s.context.Log.Info("Splunk OTEL Java agent %s installed", dep.Version)
105100
return nil
106101
}
107102

108103
// Finalize configures the Splunk OTEL Java agent
109104
func (s *SplunkOtelJavaAgentFramework) Finalize() error {
110-
if s.jarPath == "" {
111-
return nil
105+
agentDir := filepath.Join(s.context.Stager.DepDir(), "splunk_otel_java_agent")
106+
err := s.constructJarPath(agentDir)
107+
if err != nil {
108+
return fmt.Errorf("splunk OTEL Java agent JAR path not found during finalize: %w", err)
112109
}
113110

114111
s.context.Log.BeginStep("Configuring Splunk OTEL Java agent")
@@ -254,3 +251,16 @@ func (s *SplunkOtelJavaAgentFramework) getApplicationName() string {
254251

255252
return ""
256253
}
254+
255+
func (s *SplunkOtelJavaAgentFramework) constructJarPath(agentDir string) error {
256+
jarPattern := filepath.Join(agentDir, "splunk-otel-javaagent.jar")
257+
if _, err := os.Stat(jarPattern); err != nil {
258+
// Try alternative name
259+
jarPattern = filepath.Join(agentDir, "splunk-otel-javaagent-all.jar")
260+
if _, err := os.Stat(jarPattern); err != nil {
261+
return fmt.Errorf("javaagent jar not found after installation in %s (tried both splunk-otel-javaagent.jar and splunk-otel-javaagent-all.jar)", agentDir)
262+
}
263+
}
264+
s.jarPath = jarPattern
265+
return nil
266+
}

0 commit comments

Comments
 (0)