Skip to content

Commit 18efd23

Browse files
authored
Supporting Run native behavior for Gradle (#3282)
1 parent e8d1eaa commit 18efd23

File tree

7 files changed

+476
-20
lines changed

7 files changed

+476
-20
lines changed

buildtools/cli.go

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/container/strategies"
1616
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/python"
1717
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/setup"
18+
artutils "github.com/jfrog/jfrog-cli-artifactory/artifactory/utils"
1819
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
1920
"github.com/jfrog/jfrog-cli-core/v2/utils/ioutils"
2021
"github.com/jfrog/jfrog-cli-security/utils/techutils"
@@ -560,8 +561,13 @@ func MvnCmd(c *cli.Context) (err error) {
560561
return err
561562
}
562563

563-
// FlexPack bypasses all config file requirements
564-
if os.Getenv("JFROG_RUN_NATIVE") == "true" {
564+
configFilePath, configExists, err := project.GetProjectConfFilePath(project.Maven)
565+
if err != nil {
566+
return err
567+
}
568+
569+
// FlexPack bypasses all config file requirements (only when no config exists)
570+
if artutils.ShouldRunNative(configFilePath) && !configExists {
565571
log.Debug("Routing to Maven native implementation")
566572
// Extract build configuration for FlexPack
567573
args := cliutils.ExtractCommand(c)
@@ -574,9 +580,11 @@ func MvnCmd(c *cli.Context) (err error) {
574580
return commands.Exec(mvnCmd)
575581
}
576582

577-
configFilePath, err := getProjectConfigPathOrThrow(project.Maven, "mvn", "mvn-config")
578-
if err != nil {
579-
return err
583+
// If config file is missing and not in native mode, return the standard missing-config error.
584+
if !configExists {
585+
if configFilePath, err = getProjectConfigPathOrThrow(project.Maven, "mvn", "mvn-config"); err != nil {
586+
return err
587+
}
580588
}
581589

582590
if c.NArg() < 1 {
@@ -631,10 +639,63 @@ func GradleCmd(c *cli.Context) (err error) {
631639
return err
632640
}
633641

634-
configFilePath, err := getProjectConfigPathOrThrow(project.Gradle, "gradle", "gradle-config")
642+
resolveServer := func(args []string) ([]string, *coreConfig.ServerDetails, error) {
643+
cleanedArgs, serverID, err := coreutils.ExtractServerIdFromCommand(args)
644+
if err != nil {
645+
return nil, nil, fmt.Errorf("failed to extract server ID: %w", err)
646+
}
647+
648+
if serverID == "" {
649+
serverDetails, err := coreConfig.GetDefaultServerConf()
650+
if err != nil {
651+
return cleanedArgs, nil, err
652+
}
653+
if serverDetails == nil {
654+
return cleanedArgs, nil, fmt.Errorf("no default server configuration found. Please configure a server using 'jfrog config add' or specify a server using --server-id")
655+
}
656+
return cleanedArgs, serverDetails, nil
657+
}
658+
659+
serverDetails, err := coreConfig.GetSpecificConfig(serverID, true, true)
660+
if err != nil {
661+
return nil, nil, fmt.Errorf("failed to get server configuration for ID '%s': %w", serverID, err)
662+
}
663+
return cleanedArgs, serverDetails, nil
664+
}
665+
666+
configFilePath, configExists, err := project.GetProjectConfFilePath(project.Gradle)
635667
if err != nil {
636668
return err
637669
}
670+
nativeMode := artutils.ShouldRunNative(configFilePath)
671+
672+
// FlexPack native mode for Gradle (bypasses config file requirements)
673+
if nativeMode && !configExists {
674+
log.Debug("Routing to Gradle FlexPack implementation")
675+
if c.NArg() < 1 {
676+
return cliutils.WrongNumberOfArgumentsHandler(c)
677+
}
678+
args := cliutils.ExtractCommand(c)
679+
args, serverDetails, err := resolveServer(args)
680+
if err != nil {
681+
return err
682+
}
683+
filteredGradleArgs, buildConfiguration, err := build.ExtractBuildDetailsFromArgs(args)
684+
if err != nil {
685+
return err
686+
}
687+
688+
// Create Gradle command with FlexPack (no config file needed)
689+
gradleCmd := gradle.NewGradleCommand().SetConfiguration(buildConfiguration).SetTasks(filteredGradleArgs).SetConfigPath("").SetServerDetails(serverDetails)
690+
return commands.Exec(gradleCmd)
691+
}
692+
693+
// If config file is missing and not in native mode, return the standard missing-config error.
694+
if !configExists {
695+
if configFilePath, err = getProjectConfigPathOrThrow(project.Gradle, "gradle", "gradle-config"); err != nil {
696+
return err
697+
}
698+
}
638699

639700
// Found a config file. Continue as native command.
640701
if c.NArg() < 1 {
@@ -1511,7 +1572,7 @@ func pythonCmd(c *cli.Context, projectType project.ProjectType) error {
15111572
}
15121573

15131574
// FlexPack native mode for Poetry (bypasses config file requirements)
1514-
if os.Getenv("JFROG_RUN_NATIVE") == "true" && projectType == project.Poetry {
1575+
if artutils.ShouldRunNative("") && projectType == project.Poetry {
15151576
log.Debug("Routing to Poetry native implementation")
15161577
args := cliutils.ExtractCommand(c)
15171578
filteredArgs, buildConfiguration, err := build.ExtractBuildDetailsFromArgs(args)

0 commit comments

Comments
 (0)