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

✨ CP #755: Add insecure maven setting #756

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -324,6 +324,10 @@ func (p *javaServiceClient) getDependenciesForMaven(_ context.Context) (map[uri.
args = append(args, "-s", p.mvnSettingsFile)
}

if p.mvnInsecure {
args = append(args, "-Dmaven.wagon.http.ssl.insecure=true")
}

// get the graph output
cmd := exec.Command("mvn", args...)
cmd.Dir = moddir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (
WORKSPACE_INIT_OPTION = "workspace"
MVN_SETTINGS_FILE_INIT_OPTION = "mavenSettingsFile"
GLOBAL_SETTINGS_INIT_OPTION = "mavenCacheDir"
MVN_INSECURE_SETTING = "mavenInsecure"
JVM_MAX_MEM_INIT_OPTION = "jvmMaxMem"
FERN_FLOWER_INIT_OPTION = "fernFlowerPath"
)
Expand Down Expand Up @@ -253,6 +254,13 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
}
}

mavenInsecure, ok := config.ProviderSpecificConfig[MVN_INSECURE_SETTING].(bool)
if ok && mavenInsecure {
log.Info("maven insecure setting enabled")
} else {
mavenInsecure = false
}

lspServerPath, ok := config.ProviderSpecificConfig[provider.LspServerPathConfigKey].(string)
if !ok || lspServerPath == "" {
return nil, additionalBuiltinConfig, fmt.Errorf("invalid lspServerPath provided, unable to init java provider")
Expand Down Expand Up @@ -293,6 +301,9 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
if mavenSettingsFile != "" {
mvnOptions = append(mvnOptions, "-s", mavenSettingsFile)
}
if mavenInsecure {
mvnOptions = append(mvnOptions, "-Dmaven.wagon.http.ssl.insecure=true")
}
log.Info("downloading maven artifact", "artifact", mvnCoordinates, "options", mvnOptions)
cmd := exec.CommandContext(ctx, "mvn", mvnOptions...)
cmd.Dir = outputDir
Expand Down Expand Up @@ -466,6 +477,7 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
log: log,
depToLabels: map[string]*depLabelItem{},
isLocationBinary: isBinary,
mvnInsecure: mavenInsecure,
mvnSettingsFile: mavenSettingsFile,
globalSettings: globalSettingsFile,
depsLocationCache: make(map[string]int),
Expand All @@ -477,7 +489,7 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
// we need to do this for jdtls to correctly recognize source attachment for dep
switch svcClient.GetBuildTool() {
case maven:
err := resolveSourcesJarsForMaven(ctx, log, fernflower, config.Location, mavenSettingsFile)
err := resolveSourcesJarsForMaven(ctx, log, fernflower, config.Location, mavenSettingsFile, mavenInsecure)
if err != nil {
// TODO (pgaikwad): should we ignore this failure?
log.Error(err, "failed to resolve maven sources jar for location", "location", config.Location)
Expand Down Expand Up @@ -753,7 +765,7 @@ func (j *javaProvider) GetLocation(ctx context.Context, dep konveyor.Dep, file s

// resolveSourcesJarsForMaven for a given source code location, runs maven to find
// deps that don't have sources attached and decompiles them
func resolveSourcesJarsForMaven(ctx context.Context, log logr.Logger, fernflower, location, mavenSettings string) error {
func resolveSourcesJarsForMaven(ctx context.Context, log logr.Logger, fernflower, location, mavenSettings string, mvnInsecure bool) error {
// TODO (pgaikwad): when we move to external provider, inherit context from parent
ctx, span := tracing.StartNewSpan(ctx, "resolve-sources")
defer span.End()
Expand All @@ -771,6 +783,9 @@ func resolveSourcesJarsForMaven(ctx context.Context, log logr.Logger, fernflower
if mavenSettings != "" {
args = append(args, "-s", mavenSettings)
}
if mvnInsecure {
args = append(args, "-Dmaven.wagon.http.ssl.insecure=true")
}
cmd := exec.CommandContext(ctx, "mvn", args...)
cmd.Dir = location
mvnOutput, err := cmd.CombinedOutput()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type javaServiceClient struct {
workspace string
depToLabels map[string]*depLabelItem
isLocationBinary bool
mvnInsecure bool
mvnSettingsFile string
globalSettings string
depsMutex sync.RWMutex
Expand Down
Loading