Skip to content

Commit 70b152f

Browse files
committed
refactor: remove hardcoded versions from AppDynamics and NewRelic extensions
Replace hardcoded version strings and URLs with dynamic lookups from manifest.yml using InstallOnlyVersion(). This ensures extension versions are always pulled from the manifest, eliminating the need to update code when bumping dependency versions. Changes: - Add InstallOnlyVersion() wrapper method to extensions.Installer - Update AppDynamics extension to use InstallOnlyVersion() - Update NewRelic extension to use InstallOnlyVersion() - Remove hardcoded version 23.11.0-839 from AppDynamics - Remove manual URL construction logic This follows the same pattern used by PHP, HTTPD, and Nginx installations in the buildpack.
1 parent c2911dc commit 70b152f

3 files changed

Lines changed: 14 additions & 16 deletions

File tree

src/php/extensions/appdynamics/appdynamics.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package appdynamics
22

33
import (
44
"fmt"
5+
"path/filepath"
56
"regexp"
67

78
"github.com/cloudfoundry/php-buildpack/src/php/extensions"
@@ -169,21 +170,10 @@ func (e *AppDynamicsExtension) Configure(ctx *extensions.Context) error {
169170
func (e *AppDynamicsExtension) Compile(ctx *extensions.Context, installer *extensions.Installer) error {
170171
fmt.Println("Downloading AppDynamics package...")
171172

172-
// Merge defaults
173-
if _, ok := ctx.Get("APPDYNAMICS_HOST"); !ok {
174-
ctx.Set("APPDYNAMICS_HOST", "java-buildpack.cloudfoundry.org")
175-
}
176-
if _, ok := ctx.Get("APPDYNAMICS_VERSION"); !ok {
177-
ctx.Set("APPDYNAMICS_VERSION", "23.11.0-839")
178-
}
179-
if _, ok := ctx.Get("APPDYNAMICS_PACKAGE"); !ok {
180-
ctx.Set("APPDYNAMICS_PACKAGE", "appdynamics-{APPDYNAMICS_VERSION}.tar.bz2")
181-
}
182-
if _, ok := ctx.Get("APPDYNAMICS_DOWNLOAD_URL"); !ok {
183-
ctx.Set("APPDYNAMICS_DOWNLOAD_URL", "https://{APPDYNAMICS_HOST}/appdynamics-php/{APPDYNAMICS_PACKAGE}")
184-
}
173+
buildDir := ctx.GetString("BUILD_DIR")
174+
appdynamicsInstallDir := filepath.Join(buildDir, "appdynamics")
185175

186-
if err := installer.Package("APPDYNAMICS"); err != nil {
176+
if err := installer.InstallOnlyVersion("appdynamics", appdynamicsInstallDir); err != nil {
187177
return fmt.Errorf("failed to download AppDynamics package: %w", err)
188178
}
189179

src/php/extensions/extension.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,14 @@ func (i *Installer) InstallDependency(dep libbuildpack.Dependency, outputDir str
202202
return i.libbuildpackInst.InstallDependency(dep, outputDir)
203203
}
204204

205+
// InstallOnlyVersion installs the only available version of a dependency
206+
func (i *Installer) InstallOnlyVersion(depName, installDir string) error {
207+
if i.libbuildpackInst == nil {
208+
return fmt.Errorf("libbuildpack installer not available")
209+
}
210+
return i.libbuildpackInst.InstallOnlyVersion(depName, installDir)
211+
}
212+
205213
// Package downloads and installs a package based on a key in the context
206214
// This mimics Python's install.package('PACKAGENAME') method
207215
func (i *Installer) Package(packageKey string) error {

src/php/extensions/newrelic/newrelic.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ func (e *NewRelicExtension) Compile(ctx *extensions.Context, installer *extensio
167167

168168
fmt.Println("-----> Installing NewRelic")
169169

170-
// Install NewRelic package
171-
if err := installer.Package("NEWRELIC"); err != nil {
170+
newrelicInstallDir := filepath.Join(e.buildDir, "newrelic")
171+
if err := installer.InstallOnlyVersion("newrelic", newrelicInstallDir); err != nil {
172172
return fmt.Errorf("failed to install NewRelic package: %w", err)
173173
}
174174

0 commit comments

Comments
 (0)