Skip to content

Commit

Permalink
Merge pull request #330 from tjuchniewicz/feature/dd-java-agent-link
Browse files Browse the repository at this point in the history
Add dd-java-agent.jar as symlink
  • Loading branch information
dmikusa authored Aug 6, 2024
2 parents d5958bf + 9c8a76c commit ff7d199
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This buildpack will participate if all the following conditions are met

The buildpack will do the following for Java applications:

* Contributes the Datadog Java agent to a layer and configures `$JAVA_TOOL_OPTIONS` or `$BP_NATIVE_IMAGE_BUILD_ARGUMENTS` to use it
* Contributes the Datadog Java agent to a layer: `dd-java-agent-<version>.jar` and `dd-java-agent.jar` (as symlink) and configures `$JAVA_TOOL_OPTIONS` or `$BP_NATIVE_IMAGE_BUILD_ARGUMENTS` to use it.

The buildpack will do the following for Node.js applications:

Expand Down
3 changes: 3 additions & 0 deletions datadog/java_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func (j JavaAgent) Contribute(layer libcnb.Layer) (libcnb.Layer, error) {
if err := sherpa.CopyFile(artifact, file); err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to copy artifact to %s\n%w", file, err)
}
if err := os.Symlink(file, filepath.Join(layer.Path, "dd-java-agent.jar")); err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to create symlink to %s\n%w", file, err)
}

if j.NativeImage {
layer.BuildEnvironment.Appendf("BP_NATIVE_IMAGE_BUILD_ARGUMENTS", " ", "-J-javaagent:%s", file)
Expand Down
2 changes: 2 additions & 0 deletions datadog/java_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
. "github.com/onsi/gomega"
"github.com/paketo-buildpacks/libpak"
"github.com/paketo-buildpacks/libpak/bard"
"github.com/paketo-buildpacks/libpak/sherpa"
"github.com/sclevine/spec"

"github.com/paketo-buildpacks/datadog/datadog"
Expand Down Expand Up @@ -63,6 +64,7 @@ func testJavaAgent(t *testing.T, context spec.G, it spec.S) {

Expect(layer.Launch).To(BeTrue())
Expect(filepath.Join(layer.Path, "stub-datadog-agent.jar")).To(BeARegularFile())
Expect(sherpa.SymlinkExists(filepath.Join(layer.Path, "dd-java-agent.jar"))).To(BeTrue())
Expect(layer.LaunchEnvironment["BPI_DATADOG_AGENT_PATH.default"]).To(Equal(filepath.Join(layer.Path, "stub-datadog-agent.jar")))
})
}

0 comments on commit ff7d199

Please sign in to comment.