Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Allow removing exploded Java bins #765

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading