Skip to content

Commit 1ef43b8

Browse files
committed
✨ Add insecure maven setting (konveyor#755)
Fixes https://issues.redhat.com/browse/MTA-4418 Signed-off-by: Emily McMullan <[email protected]>
1 parent 39f15c8 commit 1ef43b8

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

external-providers/java-external-provider/pkg/java_external_provider/dependency.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,10 @@ func (p *javaServiceClient) getDependenciesForMaven(_ context.Context) (map[uri.
324324
args = append(args, "-s", p.mvnSettingsFile)
325325
}
326326

327+
if p.mvnInsecure {
328+
args = append(args, "-Dmaven.wagon.http.ssl.insecure=true")
329+
}
330+
327331
// get the graph output
328332
cmd := exec.Command("mvn", args...)
329333
cmd.Dir = moddir

external-providers/java-external-provider/pkg/java_external_provider/provider.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const (
4343
WORKSPACE_INIT_OPTION = "workspace"
4444
MVN_SETTINGS_FILE_INIT_OPTION = "mavenSettingsFile"
4545
GLOBAL_SETTINGS_INIT_OPTION = "mavenCacheDir"
46+
MVN_INSECURE_SETTING = "mavenInsecure"
4647
JVM_MAX_MEM_INIT_OPTION = "jvmMaxMem"
4748
FERN_FLOWER_INIT_OPTION = "fernFlowerPath"
4849
)
@@ -253,6 +254,13 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
253254
}
254255
}
255256

257+
mavenInsecure, ok := config.ProviderSpecificConfig[MVN_INSECURE_SETTING].(bool)
258+
if ok && mavenInsecure {
259+
log.Info("maven insecure setting enabled")
260+
} else {
261+
mavenInsecure = false
262+
}
263+
256264
lspServerPath, ok := config.ProviderSpecificConfig[provider.LspServerPathConfigKey].(string)
257265
if !ok || lspServerPath == "" {
258266
return nil, additionalBuiltinConfig, fmt.Errorf("invalid lspServerPath provided, unable to init java provider")
@@ -293,6 +301,9 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
293301
if mavenSettingsFile != "" {
294302
mvnOptions = append(mvnOptions, "-s", mavenSettingsFile)
295303
}
304+
if mavenInsecure {
305+
mvnOptions = append(mvnOptions, "-Dmaven.wagon.http.ssl.insecure=true")
306+
}
296307
log.Info("downloading maven artifact", "artifact", mvnCoordinates, "options", mvnOptions)
297308
cmd := exec.CommandContext(ctx, "mvn", mvnOptions...)
298309
cmd.Dir = outputDir
@@ -466,6 +477,7 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
466477
log: log,
467478
depToLabels: map[string]*depLabelItem{},
468479
isLocationBinary: isBinary,
480+
mvnInsecure: mavenInsecure,
469481
mvnSettingsFile: mavenSettingsFile,
470482
globalSettings: globalSettingsFile,
471483
depsLocationCache: make(map[string]int),
@@ -477,7 +489,7 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
477489
// we need to do this for jdtls to correctly recognize source attachment for dep
478490
switch svcClient.GetBuildTool() {
479491
case maven:
480-
err := resolveSourcesJarsForMaven(ctx, log, fernflower, config.Location, mavenSettingsFile)
492+
err := resolveSourcesJarsForMaven(ctx, log, fernflower, config.Location, mavenSettingsFile, mavenInsecure)
481493
if err != nil {
482494
// TODO (pgaikwad): should we ignore this failure?
483495
log.Error(err, "failed to resolve maven sources jar for location", "location", config.Location)
@@ -753,7 +765,7 @@ func (j *javaProvider) GetLocation(ctx context.Context, dep konveyor.Dep, file s
753765

754766
// resolveSourcesJarsForMaven for a given source code location, runs maven to find
755767
// deps that don't have sources attached and decompiles them
756-
func resolveSourcesJarsForMaven(ctx context.Context, log logr.Logger, fernflower, location, mavenSettings string) error {
768+
func resolveSourcesJarsForMaven(ctx context.Context, log logr.Logger, fernflower, location, mavenSettings string, mvnInsecure bool) error {
757769
// TODO (pgaikwad): when we move to external provider, inherit context from parent
758770
ctx, span := tracing.StartNewSpan(ctx, "resolve-sources")
759771
defer span.End()
@@ -771,6 +783,9 @@ func resolveSourcesJarsForMaven(ctx context.Context, log logr.Logger, fernflower
771783
if mavenSettings != "" {
772784
args = append(args, "-s", mavenSettings)
773785
}
786+
if mvnInsecure {
787+
args = append(args, "-Dmaven.wagon.http.ssl.insecure=true")
788+
}
774789
cmd := exec.CommandContext(ctx, "mvn", args...)
775790
cmd.Dir = location
776791
mvnOutput, err := cmd.CombinedOutput()

external-providers/java-external-provider/pkg/java_external_provider/service_client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type javaServiceClient struct {
3232
workspace string
3333
depToLabels map[string]*depLabelItem
3434
isLocationBinary bool
35+
mvnInsecure bool
3536
mvnSettingsFile string
3637
globalSettings string
3738
depsMutex sync.RWMutex

0 commit comments

Comments
 (0)