Skip to content

Commit

Permalink
👻 minor fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Pranav Gaikwad <[email protected]>
  • Loading branch information
pranavgaikwad committed Oct 5, 2023
1 parent 7c3a9fe commit fd283ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions provider/internal/java/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ func resolveSourcesJars(ctx context.Context, log logr.Logger, location, mavenSet
if err != nil {
return err
}
defer mvnOutput.Close()
args := []string{
"dependency:sources",
"-Djava.net.useSystemProxies=true",
Expand Down
22 changes: 15 additions & 7 deletions provider/internal/java/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ func decompile(ctx context.Context, log logr.Logger, filter decompileFilter, wor
workerCount = int(math.Min(float64(len(jobs)), float64(workerCount)))
// init workers
for i := 0; i < workerCount; i++ {
logger := log.WithName(fmt.Sprintf("decompileWorker-%d", i))
wg.Add(1)
log.V(6).Info("init decompile worker")
go func(log logr.Logger) {
defer log.V(6).Info("shutting down decompile worker")
defer wg.Done()
log.V(6).Info("init decompile worker")
for job := range jobChan {
// apply decompile filter
if !filter.shouldDecompile(job.artifact) {
Expand All @@ -129,19 +130,23 @@ func decompile(ctx context.Context, log logr.Logger, filter decompileFilter, wor
}
// if we just decompiled a java archive, we need to
// explode it further and copy files to project
// TODO(djzager): should we grab deps?
if job.artifact.packaging == JavaArchive && projectPath != "" {
_, _, _, err = explode(ctx, log, job.outputPath, projectPath)
if err != nil {
log.V(5).Error(err, "failed to explode decompiled jar", "path", job.inputPath)
}
}
}
}(log.WithName(fmt.Sprintf("decompileWorker-%d", i)))
}(logger)
}

seenJobs := map[string]bool{}
for _, job := range jobs {
jobChan <- job
jobKey := fmt.Sprintf("%s-%s", job.inputPath, job.outputPath)
if _, ok := seenJobs[jobKey]; !ok {
seenJobs[jobKey] = true
jobChan <- job
}
}

close(jobChan)
Expand Down Expand Up @@ -186,6 +191,7 @@ func decompileJava(ctx context.Context, log logr.Logger, archivePath string) (ex

// explode explodes the given JAR, WAR or EAR archive, generates javaArtifact struct for given archive
// and identifies all .class found recursively. returns output path, a list of decompileJob for .class files
// it also returns a list of any javaArtifact we could interpret from jars
func explode(ctx context.Context, log logr.Logger, archivePath, projectPath string) (string, []decompileJob, []javaArtifact, error) {
var dependencies []javaArtifact
fileInfo, err := os.Stat(archivePath)
Expand Down Expand Up @@ -261,7 +267,6 @@ func explode(ctx context.Context, log logr.Logger, archivePath, projectPath stri
destPath = strings.ReplaceAll(destPath, "WEB-INF/classes", "")
destPath = strings.ReplaceAll(destPath, "META-INF/classes", "")
destPath = strings.TrimSuffix(destPath, ClassFile) + ".java"
// TODO (pgaikwad): pass real artifact for filtering to work correctly
decompileJobs = append(decompileJobs, decompileJob{
inputPath: filePath,
outputPath: destPath,
Expand All @@ -288,11 +293,12 @@ func explode(ctx context.Context, log logr.Logger, archivePath, projectPath stri
// decompile web archives
case strings.HasSuffix(f.Name, WebArchive):
// TODO(djzager): Should we add these deps to the pom?
_, nestedJobs, _, err := explode(ctx, log, filePath, projectPath)
_, nestedJobs, deps, err := explode(ctx, log, filePath, projectPath)
if err != nil {
log.Error(err, "failed to decompile file", "file", filePath)
}
decompileJobs = append(decompileJobs, nestedJobs...)
dependencies = append(dependencies, deps...)
// attempt to add nested jars as dependency before decompiling
case strings.HasSuffix(f.Name, JavaArchive):
dep, err := toDependency(ctx, filePath)
Expand All @@ -303,7 +309,9 @@ func explode(ctx context.Context, log logr.Logger, archivePath, projectPath stri
outputPath := filepath.Join(
filepath.Dir(filePath), fmt.Sprintf("%s-decompiled",
strings.TrimSuffix(f.Name, JavaArchive)), filepath.Base(f.Name))
// TODO(djzager): Is it possible for the
// TODO(djzager): Is it possible for the javaArtifact be empty
// it is not an issue right now, but if we used a decompileFilter
// javaArtifact has to be accurate for filter to work
decompileJobs = append(decompileJobs, decompileJob{
inputPath: filePath,
outputPath: outputPath,
Expand Down

0 comments on commit fd283ef

Please sign in to comment.