Skip to content

Commit

Permalink
Refactor and remove duplicate logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sap-ali committed May 17, 2024
1 parent af9eff7 commit c811910
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions executable/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package executable

import (
"fmt"
"reflect"

"github.com/buildpacks/libcnb"
"github.com/paketo-buildpacks/libjvm"
Expand Down Expand Up @@ -65,15 +66,20 @@ func (d Detect) Detect(context libcnb.DetectContext) (libcnb.DetectResult, error
return libcnb.DetectResult{}, fmt.Errorf("unable to read manifest in %s\n%w", context.Application.Path, err)
}

jarGlob, _ := cr.Resolve("BP_EXECUTABLE_JAR_LOCATION")
_, props, _ := findExecutableJAR(context.Application.Path, jarGlob)

if _, ok := m.Get("Main-Class"); ok {
d.Logger.Info("PASSED: 'Main-Class' manifest attribute found")
result.Plans[0].Provides = append(result.Plans[0].Provides, libcnb.BuildPlanProvide{Name: PlanEntryJVMApplicationPackage})
} else if _, ok := props.Get("Main-Class"); ok {
d.Logger.Info("PASSED: Jar file with '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 c811910

Please sign in to comment.