Skip to content

Commit

Permalink
allow removing exploded binaries
Browse files Browse the repository at this point in the history
Signed-off-by: Emily McMullan <emcmulla@redhat.com>
  • Loading branch information
eemcmullan committed Jan 23, 2025
1 parent 77991ef commit 617032f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const (
MVN_SETTINGS_FILE_INIT_OPTION = "mavenSettingsFile"
GLOBAL_SETTINGS_INIT_OPTION = "mavenCacheDir"
MVN_INSECURE_SETTING = "mavenInsecure"
CLEAN_EXPLODED_BIN_OPTION = "cleanExplodedBin"
JVM_MAX_MEM_INIT_OPTION = "jvmMaxMem"
FERN_FLOWER_INIT_OPTION = "fernFlowerPath"
)
Expand Down Expand Up @@ -336,6 +337,7 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
}

extension := strings.ToLower(path.Ext(config.Location))
explodedBins := []string{}
switch extension {
case JavaArchive, WebArchive, EnterpriseArchive:
depLocation, sourceLocation, err := decompileJava(ctx, log, fernflower,
Expand All @@ -348,7 +350,14 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
// for binaries, we fallback to looking at .jar files only for deps
config.DependencyPath = depLocation
isBinary = true

cleanBin, ok := config.ProviderSpecificConfig[CLEAN_EXPLODED_BIN_OPTION].(bool)
if ok && cleanBin {
log.Info("removing exploded binaries after analysis")
explodedBins = append(explodedBins, depLocation, sourceLocation)
}
}

additionalBuiltinConfig.Location = config.Location
additionalBuiltinConfig.DependencyPath = config.DependencyPath

Expand Down Expand Up @@ -483,6 +492,7 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
globalSettings: globalSettingsFile,
depsLocationCache: make(map[string]int),
includedPaths: provider.GetIncludedPathsFromConfig(config, false),
cleanExplodedBins: explodedBins,
}

if mode == provider.FullAnalysisMode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type javaServiceClient struct {
depsCache map[uri.URI][]*provider.Dep
depsLocationCache map[string]int
includedPaths []string
cleanExplodedBins []string
}

type depLabelItem struct {
Expand Down Expand Up @@ -222,6 +223,11 @@ func (p *javaServiceClient) Stop() {
if err != nil {
p.log.Info("stopping java provider", "error", err)
}
if len(p.cleanExplodedBins) > 0 {
for _, explodedPath := range p.cleanExplodedBins {
os.RemoveAll(explodedPath)
}
}
}

func (p *javaServiceClient) initialization(ctx context.Context) {
Expand Down

0 comments on commit 617032f

Please sign in to comment.