Skip to content
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
75 changes: 68 additions & 7 deletions buildtools/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/container/strategies"
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/python"
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/setup"
artutils "github.com/jfrog/jfrog-cli-artifactory/artifactory/utils"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
"github.com/jfrog/jfrog-cli-core/v2/utils/ioutils"
"github.com/jfrog/jfrog-cli-security/utils/techutils"
Expand Down Expand Up @@ -560,8 +561,13 @@ func MvnCmd(c *cli.Context) (err error) {
return err
}

// FlexPack bypasses all config file requirements
if os.Getenv("JFROG_RUN_NATIVE") == "true" {
configFilePath, configExists, err := project.GetProjectConfFilePath(project.Maven)
if err != nil {
return err
}

// FlexPack bypasses all config file requirements (only when no config exists)
if artutils.ShouldRunNative(configFilePath) && !configExists {
log.Debug("Routing to Maven native implementation")
// Extract build configuration for FlexPack
args := cliutils.ExtractCommand(c)
Expand All @@ -574,9 +580,11 @@ func MvnCmd(c *cli.Context) (err error) {
return commands.Exec(mvnCmd)
}

configFilePath, err := getProjectConfigPathOrThrow(project.Maven, "mvn", "mvn-config")
if err != nil {
return err
// If config file is missing and not in native mode, return the standard missing-config error.
if !configExists {
if configFilePath, err = getProjectConfigPathOrThrow(project.Maven, "mvn", "mvn-config"); err != nil {
return err
}
}

if c.NArg() < 1 {
Expand Down Expand Up @@ -631,10 +639,63 @@ func GradleCmd(c *cli.Context) (err error) {
return err
}

configFilePath, err := getProjectConfigPathOrThrow(project.Gradle, "gradle", "gradle-config")
resolveServer := func(args []string) ([]string, *coreConfig.ServerDetails, error) {
cleanedArgs, serverID, err := coreutils.ExtractServerIdFromCommand(args)
if err != nil {
return nil, nil, fmt.Errorf("failed to extract server ID: %w", err)
}

if serverID == "" {
serverDetails, err := coreConfig.GetDefaultServerConf()
if err != nil {
return cleanedArgs, nil, err
}
if serverDetails == nil {
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")
}
return cleanedArgs, serverDetails, nil
}

serverDetails, err := coreConfig.GetSpecificConfig(serverID, true, true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be before serverDetails, err := coreConfig.GetDefaultServerConf() condition. Extracting Default Server should be last option.

if err != nil {
return nil, nil, fmt.Errorf("failed to get server configuration for ID '%s': %w", serverID, err)
}
return cleanedArgs, serverDetails, nil
}

configFilePath, configExists, err := project.GetProjectConfFilePath(project.Gradle)
if err != nil {
return err
}
nativeMode := artutils.ShouldRunNative(configFilePath)

// FlexPack native mode for Gradle (bypasses config file requirements)
if nativeMode && !configExists {
log.Debug("Routing to Gradle FlexPack implementation")
if c.NArg() < 1 {
return cliutils.WrongNumberOfArgumentsHandler(c)
}
args := cliutils.ExtractCommand(c)
args, serverDetails, err := resolveServer(args)
if err != nil {
return err
}
filteredGradleArgs, buildConfiguration, err := build.ExtractBuildDetailsFromArgs(args)
if err != nil {
return err
}

// Create Gradle command with FlexPack (no config file needed)
gradleCmd := gradle.NewGradleCommand().SetConfiguration(buildConfiguration).SetTasks(filteredGradleArgs).SetConfigPath("").SetServerDetails(serverDetails)
return commands.Exec(gradleCmd)
}

// If config file is missing and not in native mode, return the standard missing-config error.
if !configExists {
if configFilePath, err = getProjectConfigPathOrThrow(project.Gradle, "gradle", "gradle-config"); err != nil {
return err
}
}

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

// FlexPack native mode for Poetry (bypasses config file requirements)
if os.Getenv("JFROG_RUN_NATIVE") == "true" && projectType == project.Poetry {
if artutils.ShouldRunNative("") && projectType == project.Poetry {
log.Debug("Routing to Poetry native implementation")
args := cliutils.ExtractCommand(c)
filteredArgs, buildConfiguration, err := build.ExtractBuildDetailsFromArgs(args)
Expand Down
Loading
Loading