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

Adapt moved logic at core #2362

Merged
merged 9 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
44 changes: 23 additions & 21 deletions artifactory/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import (
"github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/usersmanagement"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
containerutils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/container"
"github.com/jfrog/jfrog-cli-core/v2/common/build"
"github.com/jfrog/jfrog-cli-core/v2/common/commands"
"github.com/jfrog/jfrog-cli-core/v2/common/project"
"github.com/jfrog/jfrog-cli-core/v2/common/spec"
corecommon "github.com/jfrog/jfrog-cli-core/v2/docs/common"
coreConfig "github.com/jfrog/jfrog-cli-core/v2/utils/config"
Expand Down Expand Up @@ -328,7 +330,7 @@ func GetCommands() []cli.Command {
ArgsUsage: common.CreateEnvVars(),
BashComplete: corecommon.CreateBashCompletionFunc(),
Action: func(c *cli.Context) error {
return cliutils.RunConfigCmdWithDeprecationWarning("mvnc", "rt", utils.Maven, c, cliutils.CreateConfigCmd)
return cliutils.RunConfigCmdWithDeprecationWarning("mvnc", "rt", project.Maven, c, cliutils.CreateConfigCmd)
},
},
{
Expand All @@ -341,7 +343,7 @@ func GetCommands() []cli.Command {
SkipFlagParsing: true,
BashComplete: corecommon.CreateBashCompletionFunc(),
Action: func(c *cli.Context) error {
return cliutils.RunNativeCmdWithDeprecationWarning("mvn", utils.Maven, c, buildtools.MvnCmd)
return cliutils.RunNativeCmdWithDeprecationWarning("mvn", project.Maven, c, buildtools.MvnCmd)
},
},
{
Expand All @@ -353,7 +355,7 @@ func GetCommands() []cli.Command {
ArgsUsage: common.CreateEnvVars(),
BashComplete: corecommon.CreateBashCompletionFunc(),
Action: func(c *cli.Context) error {
return cliutils.RunConfigCmdWithDeprecationWarning("gradlec", "rt", utils.Gradle, c, cliutils.CreateConfigCmd)
return cliutils.RunConfigCmdWithDeprecationWarning("gradlec", "rt", project.Gradle, c, cliutils.CreateConfigCmd)
},
},
{
Expand All @@ -366,7 +368,7 @@ func GetCommands() []cli.Command {
SkipFlagParsing: true,
BashComplete: corecommon.CreateBashCompletionFunc(),
Action: func(c *cli.Context) error {
return cliutils.RunNativeCmdWithDeprecationWarning("gradle", utils.Gradle, c, buildtools.GradleCmd)
return cliutils.RunNativeCmdWithDeprecationWarning("gradle", project.Gradle, c, buildtools.GradleCmd)
},
},
{
Expand Down Expand Up @@ -463,7 +465,7 @@ func GetCommands() []cli.Command {
ArgsUsage: common.CreateEnvVars(),
BashComplete: corecommon.CreateBashCompletionFunc(),
Action: func(c *cli.Context) error {
return cliutils.RunConfigCmdWithDeprecationWarning("npmc", "rt", utils.Npm, c, cliutils.CreateConfigCmd)
return cliutils.RunConfigCmdWithDeprecationWarning("npmc", "rt", project.Npm, c, cliutils.CreateConfigCmd)
},
},
{
Expand All @@ -477,7 +479,7 @@ func GetCommands() []cli.Command {
SkipFlagParsing: true,
BashComplete: corecommon.CreateBashCompletionFunc(),
Action: func(c *cli.Context) error {
return cliutils.RunNativeCmdWithDeprecationWarning("npm install", utils.Npm, c, buildtools.NpmInstallCmd)
return cliutils.RunNativeCmdWithDeprecationWarning("npm install", project.Npm, c, buildtools.NpmInstallCmd)
},
},
{
Expand All @@ -491,7 +493,7 @@ func GetCommands() []cli.Command {
SkipFlagParsing: true,
BashComplete: corecommon.CreateBashCompletionFunc(),
Action: func(c *cli.Context) error {
return cliutils.RunNativeCmdWithDeprecationWarning("npm ci", utils.Npm, c, buildtools.NpmCiCmd)
return cliutils.RunNativeCmdWithDeprecationWarning("npm ci", project.Npm, c, buildtools.NpmCiCmd)
},
},
{
Expand All @@ -504,7 +506,7 @@ func GetCommands() []cli.Command {
SkipFlagParsing: true,
BashComplete: corecommon.CreateBashCompletionFunc(),
Action: func(c *cli.Context) error {
return cliutils.RunNativeCmdWithDeprecationWarning("npm p", utils.Npm, c, buildtools.NpmPublishCmd)
return cliutils.RunNativeCmdWithDeprecationWarning("npm p", project.Npm, c, buildtools.NpmPublishCmd)
},
},
{
Expand All @@ -516,7 +518,7 @@ func GetCommands() []cli.Command {
ArgsUsage: common.CreateEnvVars(),
BashComplete: corecommon.CreateBashCompletionFunc(),
Action: func(c *cli.Context) error {
return cliutils.RunConfigCmdWithDeprecationWarning("yarnc", "rt", utils.Yarn, c, cliutils.CreateConfigCmd)
return cliutils.RunConfigCmdWithDeprecationWarning("yarnc", "rt", project.Yarn, c, cliutils.CreateConfigCmd)
},
},
{
Expand All @@ -528,7 +530,7 @@ func GetCommands() []cli.Command {
SkipFlagParsing: true,
BashComplete: corecommon.CreateBashCompletionFunc(),
Action: func(c *cli.Context) error {
return cliutils.RunNativeCmdWithDeprecationWarning("yarn", utils.Yarn, c, buildtools.YarnCmd)
return cliutils.RunNativeCmdWithDeprecationWarning("yarn", project.Yarn, c, buildtools.YarnCmd)
},
},
{
Expand All @@ -540,7 +542,7 @@ func GetCommands() []cli.Command {
ArgsUsage: common.CreateEnvVars(),
BashComplete: corecommon.CreateBashCompletionFunc(),
Action: func(c *cli.Context) error {
return cliutils.RunConfigCmdWithDeprecationWarning("nugetc", "rt", utils.Nuget, c, cliutils.CreateConfigCmd)
return cliutils.RunConfigCmdWithDeprecationWarning("nugetc", "rt", project.Nuget, c, cliutils.CreateConfigCmd)
},
},
{
Expand All @@ -553,7 +555,7 @@ func GetCommands() []cli.Command {
SkipFlagParsing: true,
BashComplete: corecommon.CreateBashCompletionFunc(),
Action: func(c *cli.Context) error {
return cliutils.RunNativeCmdWithDeprecationWarning("nuget", utils.Nuget, c, buildtools.NugetCmd)
return cliutils.RunNativeCmdWithDeprecationWarning("nuget", project.Nuget, c, buildtools.NugetCmd)
},
},
{
Expand All @@ -574,7 +576,7 @@ func GetCommands() []cli.Command {
ArgsUsage: common.CreateEnvVars(),
BashComplete: corecommon.CreateBashCompletionFunc(),
Action: func(c *cli.Context) error {
return cliutils.RunConfigCmdWithDeprecationWarning("dotnetc", "rt", utils.Dotnet, c, cliutils.CreateConfigCmd)
return cliutils.RunConfigCmdWithDeprecationWarning("dotnetc", "rt", project.Dotnet, c, cliutils.CreateConfigCmd)
},
},
{
Expand All @@ -587,7 +589,7 @@ func GetCommands() []cli.Command {
SkipFlagParsing: true,
BashComplete: corecommon.CreateBashCompletionFunc(),
Action: func(c *cli.Context) error {
return cliutils.RunNativeCmdWithDeprecationWarning("dotnet", utils.Dotnet, c, buildtools.DotnetCmd)
return cliutils.RunNativeCmdWithDeprecationWarning("dotnet", project.Dotnet, c, buildtools.DotnetCmd)
},
},
{
Expand All @@ -598,7 +600,7 @@ func GetCommands() []cli.Command {
ArgsUsage: common.CreateEnvVars(),
BashComplete: corecommon.CreateBashCompletionFunc(),
Action: func(c *cli.Context) error {
return cliutils.RunConfigCmdWithDeprecationWarning("go-config", "rt", utils.Go, c, cliutils.CreateConfigCmd)
return cliutils.RunConfigCmdWithDeprecationWarning("go-config", "rt", project.Go, c, cliutils.CreateConfigCmd)
},
},
{
Expand All @@ -625,7 +627,7 @@ func GetCommands() []cli.Command {
SkipFlagParsing: true,
BashComplete: corecommon.CreateBashCompletionFunc(),
Action: func(c *cli.Context) error {
return cliutils.RunNativeCmdWithDeprecationWarning("go", utils.Go, c, buildtools.GoCmd)
return cliutils.RunNativeCmdWithDeprecationWarning("go", project.Go, c, buildtools.GoCmd)
},
},
{
Expand Down Expand Up @@ -659,7 +661,7 @@ func GetCommands() []cli.Command {
ArgsUsage: common.CreateEnvVars(),
BashComplete: corecommon.CreateBashCompletionFunc(),
Action: func(c *cli.Context) error {
return cliutils.RunConfigCmdWithDeprecationWarning("pipc", "rt", utils.Pip, c, cliutils.CreateConfigCmd)
return cliutils.RunConfigCmdWithDeprecationWarning("pipc", "rt", project.Pip, c, cliutils.CreateConfigCmd)
},
},
{
Expand All @@ -673,7 +675,7 @@ func GetCommands() []cli.Command {
SkipFlagParsing: true,
BashComplete: corecommon.CreateBashCompletionFunc(),
Action: func(c *cli.Context) error {
return cliutils.RunNativeCmdWithDeprecationWarning("pip install", utils.Pip, c, pipDeprecatedInstallCmd)
return cliutils.RunNativeCmdWithDeprecationWarning("pip install", project.Pip, c, pipDeprecatedInstallCmd)
},
},
{
Expand Down Expand Up @@ -1123,7 +1125,7 @@ func ocStartBuildCmd(c *cli.Context) error {
}

// Extract build configuration
filteredOcArgs, buildConfiguration, err := utils.ExtractBuildDetailsFromArgs(args)
filteredOcArgs, buildConfiguration, err := build.ExtractBuildDetailsFromArgs(args)
if err != nil {
return err
}
Expand Down Expand Up @@ -1855,10 +1857,10 @@ func pipDeprecatedInstallCmd(c *cli.Context) error {
}

// Get python configuration.
pythonConfig, err := utils.GetResolutionOnlyConfiguration(utils.Pip)
pythonConfig, err := project.GetResolutionOnlyConfiguration(project.Pip)
if err != nil {
return fmt.Errorf("error occurred while attempting to read %[1]s-configuration file: %[2]s\n"+
"Please run 'jf %[1]s-config' command prior to running 'jf %[1]s'", utils.Pip.String(), err.Error())
"Please run 'jf %[1]s-config' command prior to running 'jf %[1]s'", project.Pip.String(), err.Error())
}

// Set arg values.
Expand Down
13 changes: 8 additions & 5 deletions artifactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/json"
"errors"
"fmt"
biutils "github.com/jfrog/build-info-go/utils"
"io"
"net"
"net/http"
Expand All @@ -24,15 +23,19 @@ import (
"testing"
"time"

biutils "github.com/jfrog/build-info-go/utils"

"github.com/buger/jsonparser"
gofrogio "github.com/jfrog/gofrog/io"
"github.com/jfrog/gofrog/version"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/generic"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
"github.com/jfrog/jfrog-cli-core/v2/common/commands"
"github.com/jfrog/jfrog-cli-core/v2/common/project"
"github.com/jfrog/jfrog-cli-core/v2/common/spec"
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/jfrog/jfrog-cli-core/v2/utils/dependencies"
coretests "github.com/jfrog/jfrog-cli-core/v2/utils/tests"
"github.com/jfrog/jfrog-cli/inttestutils"
"github.com/jfrog/jfrog-cli/utils/cliutils"
Expand Down Expand Up @@ -4969,7 +4972,7 @@ func TestGetExtractorsRemoteDetails(t *testing.T) {
}

func validateExtractorRemoteDetails(t *testing.T, downloadPath, expectedRemotePath string) {
serverDetails, remotePath, err := utils.GetExtractorsRemoteDetails(downloadPath)
serverDetails, remotePath, err := dependencies.GetExtractorsRemoteDetails(downloadPath)
assert.NoError(t, err)
assert.Equal(t, expectedRemotePath, remotePath)
assert.False(t, os.Getenv(coreutils.DeprecatedExtractorsRemoteEnv) != "" && serverDetails == nil, "Expected a server to be returned")
Expand All @@ -4993,7 +4996,7 @@ func TestGetReleasesRemoteDetails(t *testing.T) {
}

func validateReleasesRemoteDetails(t *testing.T, downloadPath, expectedRemotePath string) {
serverDetails, remotePath, err := utils.GetExtractorsRemoteDetails(downloadPath)
serverDetails, remotePath, err := dependencies.GetExtractorsRemoteDetails(downloadPath)
assert.NoError(t, err)
assert.Equal(t, expectedRemotePath, remotePath)
assert.False(t, os.Getenv(coreutils.ReleasesRemoteEnv) != "" && serverDetails == nil, "Expected a server to be returned")
Expand Down Expand Up @@ -5658,7 +5661,7 @@ func testProjectInit(t *testing.T, projectExampleName string, technology coreuti
}

func validateProjectYamlFile(t *testing.T, projectDir, technology string) {
techConfig, err := utils.ReadConfigFile(filepath.Join(projectDir, ".jfrog", "projects", technology+".yaml"), utils.YAML)
techConfig, err := project.ReadConfigFile(filepath.Join(projectDir, ".jfrog", "projects", technology+".yaml"), project.YAML)
if assert.NoError(t, err) {
assert.Equal(t, technology, techConfig.GetString("type"))
assert.Equal(t, tests.ServerId, techConfig.GetString("resolver.serverId"))
Expand All @@ -5667,7 +5670,7 @@ func validateProjectYamlFile(t *testing.T, projectDir, technology string) {
}

func validateBuildYamlFile(t *testing.T, projectDir string) {
techConfig, err := utils.ReadConfigFile(filepath.Join(projectDir, ".jfrog", "projects", "build.yaml"), utils.YAML)
techConfig, err := project.ReadConfigFile(filepath.Join(projectDir, ".jfrog", "projects", "build.yaml"), project.YAML)
assert.NoError(t, err)
assert.Equal(t, "build", techConfig.GetString("type"))
assert.Equal(t, filepath.Base(projectDir+"/"), techConfig.GetString("name"))
Expand Down
23 changes: 12 additions & 11 deletions buildinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
clientTestUtils "github.com/jfrog/jfrog-client-go/utils/tests"

buildinfo "github.com/jfrog/build-info-go/entities"
"github.com/jfrog/jfrog-cli-core/v2/common/build"
"github.com/jfrog/jfrog-cli-core/v2/common/spec"
"github.com/jfrog/jfrog-client-go/utils/log"

Expand Down Expand Up @@ -153,7 +154,7 @@ func validateArtifactsProperties(resultItems []rtutils.ResultItem, t *testing.T,
func TestBuildAddDependenciesDryRun(t *testing.T) {
initArtifactoryTest(t, "")
// Clean old build tests if exists
assert.NoError(t, utils.RemoveBuildDir(tests.RtBuildName1, "1", ""))
assert.NoError(t, build.RemoveBuildDir(tests.RtBuildName1, "1", ""))

wd, err := os.Getwd()
assert.NoError(t, err, "Failed to get current dir")
Expand All @@ -163,7 +164,7 @@ func TestBuildAddDependenciesDryRun(t *testing.T) {
noCredsCli := tests.NewJfrogCli(execMain, "jfrog rt", "")
// Execute the bad command on the local file system
assert.NoError(t, noCredsCli.Exec("bad", tests.RtBuildName1, "1", "a/*", "--dry-run=true"))
buildDir, err := utils.GetBuildDir(tests.RtBuildName1, "1", "")
buildDir, err := build.GetBuildDir(tests.RtBuildName1, "1", "")
assert.NoError(t, err)

files, _ := os.ReadDir(buildDir)
Expand All @@ -176,7 +177,7 @@ func TestBuildAddDependenciesDryRun(t *testing.T) {
assert.NoError(t, err)
defer deleteServerConfig(t)
assert.NoError(t, noCredsCli.Exec("bad", tests.RtBuildName1, "2", tests.RtRepo1+"/*", "--from-rt", "--server-id="+tests.ServerId, "--dry-run=true"))
buildDir, err = utils.GetBuildDir(tests.RtBuildName1, "2", "")
buildDir, err = build.GetBuildDir(tests.RtBuildName1, "2", "")
assert.NoError(t, err)

files, _ = os.ReadDir(buildDir)
Expand All @@ -192,7 +193,7 @@ func TestBuildPublishDetailedSummary(t *testing.T) {

// Clean old build tests if exists.
inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails)
assert.NoError(t, utils.RemoveBuildDir(tests.RtBuildName1, buildNumber, ""))
assert.NoError(t, build.RemoveBuildDir(tests.RtBuildName1, buildNumber, ""))

// Upload files with build name & number.
specFile, err := tests.CreateSpec(tests.UploadFlatNonRecursive)
Expand All @@ -217,7 +218,7 @@ func TestBuildPublishDryRun(t *testing.T) {
buildNumber := "11"
// Clean old build tests if exists.
inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails)
assert.NoError(t, utils.RemoveBuildDir(tests.RtBuildName1, buildNumber, ""))
assert.NoError(t, build.RemoveBuildDir(tests.RtBuildName1, buildNumber, ""))

// Upload files with build name & number.
specFile, err := tests.CreateSpec(tests.UploadFlatRecursive)
Expand Down Expand Up @@ -286,7 +287,7 @@ func verifyBuildPublishOutput(t *testing.T, buffer *bytes.Buffer, dryRun bool) {
//
//nolint:unparam
func getFilesFromBuildDir(t *testing.T, buildName, buildNumber string) []os.DirEntry {
buildDir, err := utils.GetBuildDir(buildName, buildNumber, "")
buildDir, err := build.GetBuildDir(buildName, buildNumber, "")
assert.NoError(t, err)

files, err := os.ReadDir(buildDir)
Expand All @@ -312,7 +313,7 @@ func TestBuildAppend(t *testing.T) {
runRt(t, "ba", tests.RtBuildName2, buildNumber2, tests.RtBuildName1, buildNumber1)

// Assert RtBuildName2/buildNumber2 is appended to RtBuildName1/buildNumber1 locally
partials, err := utils.ReadPartialBuildInfoFiles(tests.RtBuildName2, buildNumber2, "")
partials, err := build.ReadPartialBuildInfoFiles(tests.RtBuildName2, buildNumber2, "")
assert.NoError(t, err)
assert.Len(t, partials, 1)
assert.Equal(t, tests.RtBuildName1+"/"+buildNumber1, partials[0].ModuleId)
Expand Down Expand Up @@ -473,11 +474,11 @@ func TestBuildAddDependencies(t *testing.T) {

collectDepsAndPublishBuild(badTest, true, t)
validateBuildAddDepsBuildInfo(t, badTest)
assert.NoError(t, utils.RemoveBuildDir(badTest.buildName, badTest.buildNumber, ""))
assert.NoError(t, build.RemoveBuildDir(badTest.buildName, badTest.buildNumber, ""))

collectDepsAndPublishBuild(badTest, false, t)
validateBuildAddDepsBuildInfo(t, badTest)
assert.NoError(t, utils.RemoveBuildDir(badTest.buildName, badTest.buildNumber, ""))
assert.NoError(t, build.RemoveBuildDir(badTest.buildName, badTest.buildNumber, ""))
}
inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.RtBuildName1, artHttpDetails)
cleanArtifactoryTest()
Expand Down Expand Up @@ -693,7 +694,7 @@ func testBuildAddGit(t *testing.T, useEnvBuildNameAndNumber bool) {
}

// Check partials VCS info
partials, err := utils.ReadPartialBuildInfoFiles(tests.RtBuildName1, buildNumber, "")
partials, err := build.ReadPartialBuildInfoFiles(tests.RtBuildName1, buildNumber, "")
assert.NoError(t, err)
expectedVcsUrl := "https://github.com/jfrog/jfrog-cli-go.git"
expectedVcsRevision := "b033a0e508bdb52eee25654c9e12db33ff01b8ff"
Expand Down Expand Up @@ -844,7 +845,7 @@ func TestModuleName(t *testing.T) {
func collectDepsAndPublishBuild(badTest buildAddDepsBuildInfoTestParams, useEnvBuildNameAndNumber bool, t *testing.T) {
noCredsCli := tests.NewJfrogCli(execMain, "jfrog rt", "")
// Remove old tests data from fs if exists
err := utils.RemoveBuildDir(badTest.buildName, badTest.buildNumber, "")
err := build.RemoveBuildDir(badTest.buildName, badTest.buildNumber, "")
assert.NoError(t, err)

command := []string{"bad"}
Expand Down
Loading
Loading