Skip to content

Commit

Permalink
Simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sap-ali authored and anthonydahanne committed Jul 17, 2024
1 parent dd0d02f commit e2e9876
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions executable/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"reflect"

"github.com/buildpacks/libcnb"
"github.com/paketo-buildpacks/libjvm"
"github.com/paketo-buildpacks/libpak"
"github.com/paketo-buildpacks/libpak/bard"
)
Expand Down Expand Up @@ -61,25 +60,15 @@ func (d Detect) Detect(context libcnb.DetectContext) (libcnb.DetectResult, error
},
}

m, err := libjvm.NewManifest(context.Application.Path)
jarGlob, _ := cr.Resolve("BP_EXECUTABLE_JAR_LOCATION")
execJar, err := LoadExecutableJAR(context.Application.Path, jarGlob)
if err != nil {
return libcnb.DetectResult{}, fmt.Errorf("unable to read manifest in %s\n%w", context.Application.Path, err)
return libcnb.DetectResult{}, fmt.Errorf("unable to load executable JAR\n%w", err)
}

if _, ok := m.Get("Main-Class"); ok {
if !reflect.DeepEqual(execJar, ExecutableJAR{}) {
d.Logger.Info("PASSED: 'Main-Class' manifest attribute found")
result.Plans[0].Provides = append(result.Plans[0].Provides, libcnb.BuildPlanProvide{Name: PlanEntryJVMApplicationPackage})
} else {
jarGlob, _ := cr.Resolve("BP_EXECUTABLE_JAR_LOCATION")
execJar, err := LoadExecutableJAR(context.Application.Path, jarGlob)
if err != nil {
return libcnb.DetectResult{}, fmt.Errorf("unable to load executable JAR\n%w", err)
}

if !reflect.DeepEqual(execJar, ExecutableJAR{}) {
d.Logger.Info("PASSED: 'Main-Class' manifest attribute found")
result.Plans[0].Provides = append(result.Plans[0].Provides, libcnb.BuildPlanProvide{Name: PlanEntryJVMApplicationPackage})
}
}

if cr.ResolveBool("BP_LIVE_RELOAD_ENABLED") {
Expand Down

0 comments on commit e2e9876

Please sign in to comment.