Skip to content

Commit

Permalink
Merge pull request #35 from paketo-buildpacks/jvm-application-package
Browse files Browse the repository at this point in the history
Require jvm-application-package in build plan
  • Loading branch information
ekcasey authored Mar 10, 2021
2 parents fbb36ad + 550e3ff commit fc2a4c4
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 41 deletions.
16 changes: 13 additions & 3 deletions distzip/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,26 @@ import (
"github.com/paketo-buildpacks/libpak"
)

const (
PlanEntryJVMApplication = "jvm-application"
PlanEntryJVMApplicationPackage = "jvm-application-package"
PlanEntryJRE = "jre"
)

type Detect struct{}

func (Detect) Detect(context libcnb.DetectContext) (libcnb.DetectResult, error) {
result := libcnb.DetectResult{
Pass: true,
Plans: []libcnb.BuildPlan{
{
Provides: []libcnb.BuildPlanProvide{
{Name: PlanEntryJVMApplication},
},
Requires: []libcnb.BuildPlanRequire{
{Name: "jre", Metadata: map[string]interface{}{"launch": true}},
{Name: "jvm-application"},
{Name: PlanEntryJRE, Metadata: map[string]interface{}{"launch": true}},
{Name: PlanEntryJVMApplicationPackage},
{Name: PlanEntryJVMApplication},
},
},
},
Expand All @@ -48,7 +58,7 @@ func (Detect) Detect(context libcnb.DetectContext) (libcnb.DetectResult, error)
ConfigurationResolver: cr,
}
if _, ok, _ := sr.Resolve(); ok {
result.Plans[0].Provides = append(result.Plans[0].Provides, libcnb.BuildPlanProvide{Name: "jvm-application"})
result.Plans[0].Provides = append(result.Plans[0].Provides, libcnb.BuildPlanProvide{Name: PlanEntryJVMApplicationPackage})
}

return result, nil
Expand Down
96 changes: 58 additions & 38 deletions distzip/detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,55 +57,75 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
Expect(os.RemoveAll(ctx.Application.Path)).To(Succeed())
})

it("passes without application script", func() {
Expect(detect.Detect(ctx)).To(Equal(libcnb.DetectResult{
Pass: true,
Plans: []libcnb.BuildPlan{
{
Requires: []libcnb.BuildPlanRequire{
{Name: "jre", Metadata: map[string]interface{}{"launch": true}},
{Name: "jvm-application"},
context("application script not found", func() {
it("requires jvm-application-package", func() {
Expect(detect.Detect(ctx)).To(Equal(libcnb.DetectResult{
Pass: true,
Plans: []libcnb.BuildPlan{
{
Provides: []libcnb.BuildPlanProvide{
{Name: "jvm-application"},
},
Requires: []libcnb.BuildPlanRequire{
{Name: "jre", Metadata: map[string]interface{}{"launch": true}},
{Name: "jvm-application-package"},
{Name: "jvm-application"},
},
},
},
},
}))
}))
})
})

it("passes with multiple application scripts", func() {
Expect(os.MkdirAll(filepath.Join(ctx.Application.Path, "app", "bin"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(ctx.Application.Path, "app", "bin", "script-1"), []byte{}, 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(ctx.Application.Path, "app", "bin", "script-2"), []byte{}, 0755)).To(Succeed())
context("multiple application scripts", func() {
it.Before(func() {
Expect(os.MkdirAll(filepath.Join(ctx.Application.Path, "app", "bin"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(ctx.Application.Path, "app", "bin", "script-1"), []byte{}, 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(ctx.Application.Path, "app", "bin", "script-2"), []byte{}, 0755)).To(Succeed())
})

Expect(detect.Detect(ctx)).To(Equal(libcnb.DetectResult{
Pass: true,
Plans: []libcnb.BuildPlan{
{
Requires: []libcnb.BuildPlanRequire{
{Name: "jre", Metadata: map[string]interface{}{"launch": true}},
{Name: "jvm-application"},
it("requires jvm-application-package", func() {
Expect(detect.Detect(ctx)).To(Equal(libcnb.DetectResult{
Pass: true,
Plans: []libcnb.BuildPlan{
{
Provides: []libcnb.BuildPlanProvide{
{Name: "jvm-application"},
},
Requires: []libcnb.BuildPlanRequire{
{Name: "jre", Metadata: map[string]interface{}{"launch": true}},
{Name: "jvm-application-package"},
{Name: "jvm-application"},
},
},
},
},
}))
}))
})
})

it("passes and provices with single application script", func() {
Expect(os.MkdirAll(filepath.Join(ctx.Application.Path, "app", "bin"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(ctx.Application.Path, "app", "bin", "script"), []byte{}, 0755)).To(Succeed())
context("single application script", func() {
it.Before(func() {
Expect(os.MkdirAll(filepath.Join(ctx.Application.Path, "app", "bin"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(ctx.Application.Path, "app", "bin", "script"), []byte{}, 0755)).To(Succeed())
})

Expect(detect.Detect(ctx)).To(Equal(libcnb.DetectResult{
Pass: true,
Plans: []libcnb.BuildPlan{
{
Provides: []libcnb.BuildPlanProvide{
{Name: "jvm-application"},
},
Requires: []libcnb.BuildPlanRequire{
{Name: "jre", Metadata: map[string]interface{}{"launch": true}},
{Name: "jvm-application"},
it("requires and provides jvm-application-package", func() {
Expect(detect.Detect(ctx)).To(Equal(libcnb.DetectResult{
Pass: true,
Plans: []libcnb.BuildPlan{
{
Provides: []libcnb.BuildPlanProvide{
{Name: "jvm-application"},
{Name: "jvm-application-package"},
},
Requires: []libcnb.BuildPlanRequire{
{Name: "jre", Metadata: map[string]interface{}{"launch": true}},
{Name: "jvm-application-package"},
{Name: "jvm-application"},
},
},
},
},
}))
}))
})
})
}

0 comments on commit fc2a4c4

Please sign in to comment.