Skip to content

Commit

Permalink
use random name for java project
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 28, 2025
1 parent 617032f commit fe62102
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,10 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
explodedBins := []string{}
switch extension {
case JavaArchive, WebArchive, EnterpriseArchive:
cleanBin, ok := config.ProviderSpecificConfig[CLEAN_EXPLODED_BIN_OPTION].(bool)

depLocation, sourceLocation, err := decompileJava(ctx, log, fernflower,
config.Location, getMavenLocalRepoPath(mavenSettingsFile))
config.Location, getMavenLocalRepoPath(mavenSettingsFile), ok)
if err != nil {
cancelFunc()
return nil, additionalBuiltinConfig, err
Expand All @@ -351,7 +353,6 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import (
"strings"
"sync"
"text/template"
"time"

"math/rand"

"github.com/go-logr/logr"
"github.com/konveyor/analyzer-lsp/tracing"
Expand Down Expand Up @@ -159,11 +162,16 @@ func decompile(ctx context.Context, log logr.Logger, filter decompileFilter, wor
// decompileJava unpacks archive at archivePath, decompiles all .class files in it
// creates new java project and puts the java files in the tree of the project
// returns path to exploded archive, path to java project, and an error when encountered
func decompileJava(ctx context.Context, log logr.Logger, fernflower, archivePath string, m2RepoPath string) (explodedPath, projectPath string, err error) {
func decompileJava(ctx context.Context, log logr.Logger, fernflower, archivePath string, m2RepoPath string, cleanBin bool) (explodedPath, projectPath string, err error) {
ctx, span := tracing.StartNewSpan(ctx, "decompile")
defer span.End()

projectPath = filepath.Join(filepath.Dir(archivePath), "java-project")
// only need random project name if there is not dir cleanup after
if cleanBin {
projectPath = filepath.Join(filepath.Dir(archivePath), fmt.Sprintf("java-project-%v", RandomName()))
} else {
projectPath = filepath.Join(filepath.Dir(archivePath), "java-project")
}

decompFilter := alwaysDecompileFilter(true)

Expand Down Expand Up @@ -626,4 +634,14 @@ func toFilePathDependency(_ context.Context, filePath string) (javaArtifact, err
dep.Version = "0.0.0"
return dep, nil

}
}

func RandomName() string {
rand.Seed(int64(time.Now().Nanosecond()))
charset := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
b := make([]byte, 16)
for i := range b {
b[i] = charset[rand.Intn(len(charset))]
}
return string(b)
}

0 comments on commit fe62102

Please sign in to comment.