Skip to content

Commit

Permalink
✨ do not decompile all JARs, set sourceOnly mode for binaries'
Browse files Browse the repository at this point in the history
Signed-off-by: Pranav Gaikwad <[email protected]>
  • Loading branch information
pranavgaikwad committed Aug 30, 2023
1 parent e1dd9f9 commit a56e961
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions provider/internal/java/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
config.Location = sourceLocation
// for binaries, we fallback to looking at .jar files only for deps
config.DependencyPath = depLocation
// for binaries, always run in source-only mode as we don't know how to correctly resolve deps
config.AnalysisMode = provider.SourceOnlyAnalysisMode
isBinary = true
}

Expand Down
9 changes: 5 additions & 4 deletions provider/internal/java/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ func decompile(ctx context.Context, log logr.Logger, archivePath, projectPath st
if _, err := io.Copy(dstFile, archiveFile); err != nil {
return "", err
}

// If we found a class file, decompile it to java project path
if strings.HasSuffix(f.Name, ClassFile) {
switch {
// when it's a .class file, decompile it into java project
case strings.HasSuffix(f.Name, ClassFile):
// full path in the java project for the decompd file
destPath := filepath.Join(
projectPath, "src", "main", "java",
Expand All @@ -147,7 +147,8 @@ func decompile(ctx context.Context, log logr.Logger, archivePath, projectPath st
} else {
log.V(8).Info("decompiled file", "file", filePath)
}
} else if strings.HasSuffix(f.Name, JavaArchive) || strings.HasSuffix(f.Name, WebArchive) {
// decompile web archives
case strings.HasSuffix(f.Name, WebArchive):
if _, err := decompile(ctx, log, filePath, projectPath); err != nil {
log.Error(err, "failed to decompile file", "file", filePath)
}
Expand Down

0 comments on commit a56e961

Please sign in to comment.