diff --git a/.github/workflows/accessTests.yml b/.github/workflows/accessTests.yml index 180e44521..f1f9d450f 100644 --- a/.github/workflows/accessTests.yml +++ b/.github/workflows/accessTests.yml @@ -15,12 +15,12 @@ concurrency: jobs: Access-Tests: if: contains(github.event.pull_request.labels.*.name, 'safe to test') || github.event_name == 'push' - name: ${{ matrix.os }} + name: Access tests (${{ matrix.os }}) strategy: fail-fast: false matrix: - os: [ ubuntu-latest, macos-latest, windows-latest ] - runs-on: ${{ matrix.os }} + os: [ ubuntu, windows, macos ] + runs-on: ${{ matrix.os }}-latest steps: - name: Install Go uses: actions/setup-go@v3 diff --git a/.github/workflows/analysis.yml b/.github/workflows/analysis.yml index d3957b0d4..e78785890 100644 --- a/.github/workflows/analysis.yml +++ b/.github/workflows/analysis.yml @@ -15,8 +15,8 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - runs-on: ${{ matrix.os }} + os: [ ubuntu, windows, macos ] + runs-on: ${{ matrix.os }}-latest steps: - name: Install Go uses: actions/setup-go@v3 diff --git a/.github/workflows/artifactoryTests.yml b/.github/workflows/artifactoryTests.yml index f87493209..440323b26 100644 --- a/.github/workflows/artifactoryTests.yml +++ b/.github/workflows/artifactoryTests.yml @@ -20,8 +20,8 @@ jobs: fail-fast: false matrix: suite: [ artifactory, artifactoryProject ] - os: [ ubuntu-latest, macos-latest, windows-latest ] - runs-on: ${{ matrix.os }} + os: [ ubuntu, windows, macos ] + runs-on: ${{ matrix.os }}-latest steps: - name: Install Go uses: actions/setup-go@v3 diff --git a/.github/workflows/distributionTests.yml b/.github/workflows/distributionTests.yml index c3fb0200a..7804ad677 100644 --- a/.github/workflows/distributionTests.yml +++ b/.github/workflows/distributionTests.yml @@ -15,12 +15,12 @@ concurrency: jobs: Distribution-Tests: if: contains(github.event.pull_request.labels.*.name, 'safe to test') || github.event_name == 'push' - name: ${{ matrix.os }} + name: Distribution tests (${{ matrix.os }}) strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - runs-on: ${{ matrix.os }} + os: [ ubuntu, windows, macos ] + runs-on: ${{ matrix.os }}-latest steps: - name: Install Go uses: actions/setup-go@v3 diff --git a/.github/workflows/frogbot-scan-pull-request.yml b/.github/workflows/frogbot-scan-pull-request.yml index 2bf08dbb9..740419027 100644 --- a/.github/workflows/frogbot-scan-pull-request.yml +++ b/.github/workflows/frogbot-scan-pull-request.yml @@ -14,6 +14,8 @@ jobs: steps: - uses: jfrog/frogbot@v2 env: + JFROG_CLI_LOG_LEVEL: "DEBUG" + # [Mandatory] # JFrog platform URL (This functionality requires version 3.29.0 or above of Xray) JF_URL: ${{ secrets.FROGBOT_URL }} @@ -22,14 +24,6 @@ jobs: # JFrog access token with 'read' permissions on Xray service JF_ACCESS_TOKEN: ${{ secrets.FROGBOT_ACCESS_TOKEN }} - # [Mandatory if JF_ACCESS_TOKEN is not provided] - # JFrog username with 'read' permissions for Xray. Must be provided with JF_PASSWORD - # JF_USER: ${{ secrets.JF_USER }} - - # [Mandatory if JF_ACCESS_TOKEN is not provided] - # JFrog password. Must be provided with JF_USER - # JF_PASSWORD: ${{ secrets.JF_PASSWORD }} - # [Mandatory] # The GitHub token is automatically generated for the job JF_GIT_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -57,15 +51,21 @@ jobs: # [Optional] # Configure the SMTP server to enable Frogbot to send emails with detected secrets in pull request scans. # SMTP server URL including should the relevant port: (Example: smtp.server.com:8080) - # JF_SMTP_SERVER: "" + JF_SMTP_SERVER: ${{ secrets.JF_SMTP_SERVER }} # [Mandatory if JF_SMTP_SERVER is set] # The username required for authenticating with the SMTP server. - # JF_SMTP_USER: "" + JF_SMTP_USER: ${{ secrets.JF_SMTP_USER }} # [Mandatory if JF_SMTP_SERVER is set] # The password associated with the username required for authentication with the SMTP server. - # JF_SMTP_PASSWORD: "" + JF_SMTP_PASSWORD: ${{ secrets.JF_SMTP_PASSWORD }} + + # [Optional] + # List of comma separated email addresses to receive email notifications about secrets + # detected during pull request scanning. The notification is also sent to the email set + # in the committer git profile regardless of whether this variable is set or not. + JF_EMAIL_RECEIVERS: "eco-system@jfrog.com" ########################################################################## ## If your project uses a 'frogbot-config.yml' file, you can define ## @@ -119,8 +119,3 @@ jobs: # The following values are accepted: Low, Medium, High or Critical # JF_MIN_SEVERITY: "" - # [Optional] - # List of comma separated email addresses to receive email notifications about secrets - # detected during pull request scanning. The notification is also sent to the email set - # in the committer git profile regardless of whether this variable is set or not. - # JF_EMAIL_RECEIVERS: "" \ No newline at end of file diff --git a/.github/workflows/frogbot-scan-repository.yml b/.github/workflows/frogbot-scan-repository.yml index c75a19114..14eec776f 100644 --- a/.github/workflows/frogbot-scan-repository.yml +++ b/.github/workflows/frogbot-scan-repository.yml @@ -18,6 +18,8 @@ jobs: steps: - uses: jfrog/frogbot@v2 env: + JFROG_CLI_LOG_LEVEL: "DEBUG" + # [Mandatory] # JFrog platform URL (This functionality requires version 3.29.0 or above of Xray) JF_URL: ${{ secrets.FROGBOT_URL }} diff --git a/.github/workflows/goTests.yml b/.github/workflows/goTests.yml index 88ce52f77..1a74d2221 100644 --- a/.github/workflows/goTests.yml +++ b/.github/workflows/goTests.yml @@ -16,12 +16,12 @@ jobs: GO-tests: # Go modules doesn't allow passing credentials to a private registry using an HTTP URL. Therefore, the Go tests run against a remote Artifactory server. if: contains(github.event.pull_request.labels.*.name, 'safe to test') || github.event_name == 'push' - name: ${{ matrix.os }} + name: Go tests (${{ matrix.os }}) strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - runs-on: ${{ matrix.os }} + os: [ ubuntu, windows, macos ] + runs-on: ${{ matrix.os }}-latest steps: - name: Install Go uses: actions/setup-go@v3 diff --git a/.github/workflows/gradleTests.yml b/.github/workflows/gradleTests.yml index d361d9e9b..edb2c50f9 100644 --- a/.github/workflows/gradleTests.yml +++ b/.github/workflows/gradleTests.yml @@ -15,12 +15,13 @@ concurrency: jobs: Gradle-Tests: if: contains(github.event.pull_request.labels.*.name, 'safe to test') || github.event_name == 'push' - name: ${{ matrix.os }} + name: ${{ matrix.os }}-gradle-${{ matrix.gradle-version }} strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - runs-on: ${{ matrix.os }} + os: [ ubuntu, windows, macos ] + gradle-version: [5.6.4, 8.3] + runs-on: ${{ matrix.os }}-latest env: GRADLE_OPTS: -Dorg.gradle.daemon=false steps: @@ -31,7 +32,7 @@ jobs: - name: Setup Gradle uses: gradle/gradle-build-action@v2 with: - gradle-version: 7.6 + gradle-version: ${{ matrix.gradle-version }} - name: Checkout code uses: actions/checkout@v3 with: diff --git a/.github/workflows/lifecycleTests.yml b/.github/workflows/lifecycleTests.yml new file mode 100644 index 000000000..0f073b2bd --- /dev/null +++ b/.github/workflows/lifecycleTests.yml @@ -0,0 +1,44 @@ +name: Lifecycle Tests +on: + push: + branches: + - '**' + tags-ignore: + - '**' + # Triggers the workflow on labeled PRs only. + pull_request_target: + types: [labeled] +# Ensures that only the latest commit is running for each PR at a time. +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.ref }} + cancel-in-progress: true +jobs: + Lifecycle-Tests: + if: contains(github.event.pull_request.labels.*.name, 'safe to test') || github.event_name == 'push' + name: Lifecycle tests (${{ matrix.os }}) + strategy: + fail-fast: false + matrix: + os: [ ubuntu, windows, macos ] + runs-on: ${{ matrix.os }}-latest + steps: + - name: Install Go + uses: actions/setup-go@v3 + with: + go-version: 1.20.x + - name: Checkout code + uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: Go Cache + uses: actions/cache@v3 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-go- + - name: Checkout code + uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: Run Lifecycle tests + run: go test -v github.com/jfrog/jfrog-cli --timeout 0 --test.lifecycle --jfrog.url=${{ secrets.PLATFORM_URL }} --jfrog.adminToken=${{ secrets.PLATFORM_ADMIN_TOKEN }} --jfrog.user=${{ secrets.PLATFORM_USER }} --ci.runId=${{ runner.os }}-lifecycle diff --git a/.github/workflows/mavenTests.yml b/.github/workflows/mavenTests.yml index e9feb1e17..25d0f1f10 100644 --- a/.github/workflows/mavenTests.yml +++ b/.github/workflows/mavenTests.yml @@ -15,12 +15,12 @@ concurrency: jobs: Maven-Tests: if: contains(github.event.pull_request.labels.*.name, 'safe to test') || github.event_name == 'push' - name: ${{ matrix.os }} + name: Maven tests (${{ matrix.os }}) strategy: fail-fast: false matrix: - os: [ ubuntu-latest, macos-latest, windows-latest ] - runs-on: ${{ matrix.os }} + os: [ ubuntu, windows, macos ] + runs-on: ${{ matrix.os }}-latest steps: - name: Install Go uses: actions/setup-go@v3 diff --git a/.github/workflows/npmTests.yml b/.github/workflows/npmTests.yml index 67e14916a..6d0b79663 100644 --- a/.github/workflows/npmTests.yml +++ b/.github/workflows/npmTests.yml @@ -15,12 +15,12 @@ concurrency: jobs: npm-Tests: if: contains(github.event.pull_request.labels.*.name, 'safe to test') || github.event_name == 'push' - name: ${{ matrix.os }} + name: npm tests (${{ matrix.os }}) strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - runs-on: ${{ matrix.os }} + os: [ ubuntu, windows, macos ] + runs-on: ${{ matrix.os }}-latest steps: - name: Install Go uses: actions/setup-go@v3 diff --git a/.github/workflows/nugetTests.yml b/.github/workflows/nugetTests.yml index 71b9b71ba..c17fadd48 100644 --- a/.github/workflows/nugetTests.yml +++ b/.github/workflows/nugetTests.yml @@ -15,12 +15,12 @@ concurrency: jobs: NuGet-Tests: if: contains(github.event.pull_request.labels.*.name, 'safe to test') || github.event_name == 'push' - name: ${{ matrix.os }} + name: NuGet tests (${{ matrix.os }}) strategy: fail-fast: false matrix: - os: [ ubuntu-latest, macos-latest, windows-latest ] - runs-on: ${{ matrix.os }} + os: [ ubuntu, windows, macos ] + runs-on: ${{ matrix.os }}-latest steps: - name: Install Go uses: actions/setup-go@v3 diff --git a/.github/workflows/pluginsTests.yml b/.github/workflows/pluginsTests.yml index 327954a15..a91275a45 100644 --- a/.github/workflows/pluginsTests.yml +++ b/.github/workflows/pluginsTests.yml @@ -15,12 +15,12 @@ concurrency: jobs: Plugins-Tests: if: contains(github.event.pull_request.labels.*.name, 'safe to test') || github.event_name == 'push' - name: ${{ matrix.os }} + name: Plugins tests (${{ matrix.os }}) strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - runs-on: ${{ matrix.os }} + os: [ ubuntu, windows, macos ] + runs-on: ${{ matrix.os }}-latest steps: - name: Install Go uses: actions/setup-go@v3 diff --git a/.github/workflows/pythonTests.yml b/.github/workflows/pythonTests.yml index f218417ae..d9e7dd0a7 100644 --- a/.github/workflows/pythonTests.yml +++ b/.github/workflows/pythonTests.yml @@ -20,8 +20,8 @@ jobs: fail-fast: false matrix: suite: [ pip, pipenv, poetry ] - os: [ ubuntu-latest, macos-latest, windows-latest ] - runs-on: ${{ matrix.os }} + os: [ ubuntu, windows, macos ] + runs-on: ${{ matrix.os }}-latest steps: - name: Install Go uses: actions/setup-go@v3 diff --git a/.github/workflows/scriptTests.yml b/.github/workflows/scriptTests.yml index c3991a34f..7201edeeb 100644 --- a/.github/workflows/scriptTests.yml +++ b/.github/workflows/scriptTests.yml @@ -12,15 +12,15 @@ concurrency: cancel-in-progress: true jobs: Scripts-tests: - name: ${{ matrix.os }} + name: Script tests (${{ matrix.os }}) defaults: run: shell: bash strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - runs-on: ${{ matrix.os }} + os: [ ubuntu, windows, macos ] + runs-on: ${{ matrix.os }}-latest steps: - name: Checkout code uses: actions/checkout@v3 diff --git a/.github/workflows/transferTests.yml b/.github/workflows/transferTests.yml index 28b98f641..044c6a2e2 100644 --- a/.github/workflows/transferTests.yml +++ b/.github/workflows/transferTests.yml @@ -15,12 +15,12 @@ concurrency: jobs: Transfer-Artifactory-7-Tests: if: contains(github.event.pull_request.labels.*.name, 'safe to test') || github.event_name == 'push' - name: ${{ matrix.os }} + name: Transfer tests (${{ matrix.os }}) strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - runs-on: ${{ matrix.os }} + os: [ ubuntu, windows, macos ] + runs-on: ${{ matrix.os }}-latest steps: - name: Checkout code uses: actions/checkout@v3 diff --git a/.github/workflows/xrayTests.yml b/.github/workflows/xrayTests.yml index e540c76cc..83d8a6f64 100644 --- a/.github/workflows/xrayTests.yml +++ b/.github/workflows/xrayTests.yml @@ -15,12 +15,12 @@ concurrency: jobs: CLI-Tests: if: contains(github.event.pull_request.labels.*.name, 'safe to test') || github.event_name == 'push' - name: ${{ matrix.os }} + name: Xray tests (${{ matrix.os }}) strategy: fail-fast: false matrix: - os: [ ubuntu-latest, macos-latest, windows-latest ] - runs-on: ${{ matrix.os }} + os: [ ubuntu, windows, macos ] + runs-on: ${{ matrix.os }}-latest env: GRADLE_OPTS: -Dorg.gradle.daemon=false steps: @@ -63,7 +63,7 @@ jobs: ref: ${{ github.event.pull_request.head.sha }} - name: Run Xray tests run: go test -v github.com/jfrog/jfrog-cli --timeout 0 --test.xray --jfrog.url=${{ secrets.PLATFORM_URL }} --jfrog.adminToken=${{ secrets.PLATFORM_ADMIN_TOKEN }} --jfrog.user=${{ secrets.PLATFORM_USER }} --test.containerRegistry=${{ secrets.CONTAINER_REGISTRY }} - if: ${{ matrix.os != 'ubuntu-latest' }} + if: ${{ matrix.os != 'ubuntu' }} - name: Run Docker scan and Xray tests run: go test -v github.com/jfrog/jfrog-cli --timeout 0 --test.xray --test.dockerScan --jfrog.url=${{ secrets.PLATFORM_URL }} --jfrog.adminToken=${{ secrets.PLATFORM_ADMIN_TOKEN }} --test.containerRegistry=${{ secrets.CONTAINER_REGISTRY }} - if: ${{ matrix.os == 'ubuntu-latest' }} \ No newline at end of file + if: ${{ matrix.os == 'ubuntu' }} diff --git a/artifactory_test.go b/artifactory_test.go index 9a5fbe194..390961e66 100644 --- a/artifactory_test.go +++ b/artifactory_test.go @@ -7,6 +7,7 @@ import ( "encoding/json" "errors" "fmt" + biutils "github.com/jfrog/build-info-go/utils" "io" "net" "net/http" @@ -191,7 +192,7 @@ func TestArtifactorySimpleUploadWithWildcardSpec(t *testing.T) { // Init tmp dir specFile, err := tests.CreateSpec(tests.UploadTempWildcard) assert.NoError(t, err) - err = fileutils.CopyDir(tests.GetTestResourcesPath()+"cache", filepath.Dir(specFile), true, nil) + err = biutils.CopyDir(tests.GetTestResourcesPath()+"cache", filepath.Dir(specFile), true, nil) assert.NoError(t, err) // Upload runRt(t, "upload", "--spec="+specFile) @@ -1536,9 +1537,9 @@ func TestArtifactorySelfSignedCert(t *testing.T) { serverDetails.InsecureTls = false certsPath, err := coreutils.GetJfrogCertsDir() assert.NoError(t, err) - err = fileutils.CopyFile(certsPath, certificate.KeyFile) + err = biutils.CopyFile(certsPath, certificate.KeyFile) assert.NoError(t, err) - err = fileutils.CopyFile(certsPath, certificate.CertFile) + err = biutils.CopyFile(certsPath, certificate.CertFile) assert.NoError(t, err) searchCmd = generic.NewSearchCommand() searchCmd.SetServerDetails(serverDetails).SetSpec(fileSpec) @@ -2281,7 +2282,7 @@ func TestUploadWithArchiveAndSymlink(t *testing.T) { testFile := filepath.Join(tests.GetTestResourcesPath(), "a", "a1.in") tmpDir, createTempDirCallback := coretests.CreateTempDirWithCallbackAndAssert(t) defer createTempDirCallback() - err := fileutils.CopyFile(tmpDir, testFile) + err := biutils.CopyFile(tmpDir, testFile) assert.NoError(t, err) // Link valid symLink to local file symlinkTarget := filepath.Join(tmpDir, "a1.in") @@ -5006,7 +5007,7 @@ func TestVcsProps(t *testing.T) { func initVcsTestDir(t *testing.T) string { testdataSrc := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "vcs") testdataTarget := tests.Temp - err := fileutils.CopyDir(testdataSrc, testdataTarget, true, nil) + err := biutils.CopyDir(testdataSrc, testdataTarget, true, nil) assert.NoError(t, err) if found, err := fileutils.IsDirExists(filepath.Join(testdataTarget, "gitdata"), false); found { assert.NoError(t, err) @@ -5420,7 +5421,7 @@ func simpleUploadWithAntPatternSpec(t *testing.T) { // Init tmp dir specFile, err := tests.CreateSpec(tests.UploadAntPattern) assert.NoError(t, err) - err = fileutils.CopyDir(tests.GetTestResourcesPath()+"cache", filepath.Dir(specFile), true, nil) + err = biutils.CopyDir(tests.GetTestResourcesPath()+"cache", filepath.Dir(specFile), true, nil) assert.NoError(t, err) // Upload runRt(t, "upload", "--spec="+specFile) @@ -5446,7 +5447,7 @@ func TestUploadWithAntPatternAndExclusionsSpec(t *testing.T) { // Init tmp dir specFile, err := tests.CreateSpec(tests.UploadAntPatternExclusions) assert.NoError(t, err) - err = fileutils.CopyDir(tests.GetTestResourcesPath(), filepath.Dir(specFile), true, nil) + err = biutils.CopyDir(tests.GetTestResourcesPath(), filepath.Dir(specFile), true, nil) assert.NoError(t, err) // Upload runRt(t, "upload", "--spec="+specFile) @@ -5464,7 +5465,7 @@ func TestUploadWithAntPatternAndPlaceholders(t *testing.T) { // Init tmp dir specFile, err := tests.CreateSpec(tests.UploadAntPatternExclusions) assert.NoError(t, err) - err = fileutils.CopyDir(tests.GetTestResourcesPath(), filepath.Dir(specFile), true, nil) + err = biutils.CopyDir(tests.GetTestResourcesPath(), filepath.Dir(specFile), true, nil) assert.NoError(t, err) // Upload runRt(t, "upload", "--spec="+specFile) @@ -5601,7 +5602,7 @@ func testProjectInit(t *testing.T, projectExampleName string, technology coreuti tmpWorkDir, deleteWorkDir := coretests.CreateTempDirWithCallbackAndAssert(t) defer deleteWorkDir() testdataSrc := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), technology.ToString(), projectExampleName) - err = fileutils.CopyDir(testdataSrc, tmpWorkDir, true, nil) + err = biutils.CopyDir(testdataSrc, tmpWorkDir, true, nil) assert.NoError(t, err) if technology == coreutils.Go { goModeOriginalPath := filepath.Join(tmpWorkDir, "createGoProject_go.mod_suffix") @@ -5700,7 +5701,7 @@ func prepareTerraformProject(projectName string, t *testing.T, copyDirs bool) st testdataTarget := filepath.Join(tests.Out, "terraformProject") assert.NoError(t, os.MkdirAll(testdataTarget+string(os.PathSeparator), 0777)) // Copy terraform tests to test environment, so we can change project's config file. - assert.NoError(t, fileutils.CopyDir(projectPath, testdataTarget, copyDirs, nil)) + assert.NoError(t, biutils.CopyDir(projectPath, testdataTarget, copyDirs, nil)) configFileDir := filepath.Join(filepath.FromSlash(testdataTarget), ".jfrog", "projects") _, err := tests.ReplaceTemplateVariables(filepath.Join(configFileDir, "terraform.yaml"), configFileDir) assert.NoError(t, err) diff --git a/distribution/cli.go b/distribution/cli.go index 682156767..0a0664a29 100644 --- a/distribution/cli.go +++ b/distribution/cli.go @@ -2,10 +2,6 @@ package distribution import ( "errors" - "os" - "path/filepath" - "strings" - "github.com/jfrog/jfrog-cli-core/v2/common/commands" "github.com/jfrog/jfrog-cli-core/v2/common/spec" distributionCommands "github.com/jfrog/jfrog-cli-core/v2/distribution/commands" @@ -18,10 +14,14 @@ import ( "github.com/jfrog/jfrog-cli/docs/artifactory/releasebundleupdate" "github.com/jfrog/jfrog-cli/docs/common" "github.com/jfrog/jfrog-cli/utils/cliutils" + "github.com/jfrog/jfrog-cli/utils/distribution" distributionServices "github.com/jfrog/jfrog-client-go/distribution/services" distributionServicesUtils "github.com/jfrog/jfrog-client-go/distribution/services/utils" "github.com/jfrog/jfrog-client-go/utils/errorutils" "github.com/urfave/cli" + "os" + "path/filepath" + "strings" ) func GetCommands() []cli.Command { @@ -111,11 +111,11 @@ func releaseBundleCreateCmd(c *cli.Context) error { return err } releaseBundleCreateCmd := distributionCommands.NewReleaseBundleCreateCommand() - rtDetails, err := createArtifactoryDetailsByFlags(c) + dsDetails, err := createDistributionDetailsByFlags(c) if err != nil { return err } - releaseBundleCreateCmd.SetServerDetails(rtDetails).SetReleaseBundleCreateParams(params).SetSpec(releaseBundleCreateSpec).SetDryRun(c.Bool("dry-run")).SetDetailedSummary(c.Bool("detailed-summary")) + releaseBundleCreateCmd.SetServerDetails(dsDetails).SetReleaseBundleCreateParams(params).SetSpec(releaseBundleCreateSpec).SetDryRun(c.Bool("dry-run")).SetDetailedSummary(c.Bool("detailed-summary")) err = commands.Exec(releaseBundleCreateCmd) if releaseBundleCreateCmd.IsDetailedSummary() { @@ -153,11 +153,11 @@ func releaseBundleUpdateCmd(c *cli.Context) error { return err } releaseBundleUpdateCmd := distributionCommands.NewReleaseBundleUpdateCommand() - rtDetails, err := createArtifactoryDetailsByFlags(c) + dsDetails, err := createDistributionDetailsByFlags(c) if err != nil { return err } - releaseBundleUpdateCmd.SetServerDetails(rtDetails).SetReleaseBundleUpdateParams(params).SetSpec(releaseBundleUpdateSpec).SetDryRun(c.Bool("dry-run")).SetDetailedSummary(c.Bool("detailed-summary")) + releaseBundleUpdateCmd.SetServerDetails(dsDetails).SetReleaseBundleUpdateParams(params).SetSpec(releaseBundleUpdateSpec).SetDryRun(c.Bool("dry-run")).SetDetailedSummary(c.Bool("detailed-summary")) err = commands.Exec(releaseBundleUpdateCmd) if releaseBundleUpdateCmd.IsDetailedSummary() { @@ -177,11 +177,11 @@ func releaseBundleSignCmd(c *cli.Context) error { params.StoringRepository = c.String("repo") params.GpgPassphrase = c.String("passphrase") releaseBundleSignCmd := distributionCommands.NewReleaseBundleSignCommand() - rtDetails, err := createArtifactoryDetailsByFlags(c) + dsDetails, err := createDistributionDetailsByFlags(c) if err != nil { return err } - releaseBundleSignCmd.SetServerDetails(rtDetails).SetReleaseBundleSignParams(params).SetDetailedSummary(c.Bool("detailed-summary")) + releaseBundleSignCmd.SetServerDetails(dsDetails).SetReleaseBundleSignParams(params).SetDetailedSummary(c.Bool("detailed-summary")) err = commands.Exec(releaseBundleSignCmd) if releaseBundleSignCmd.IsDetailedSummary() { if summary := releaseBundleSignCmd.GetSummary(); summary != nil { @@ -192,37 +192,21 @@ func releaseBundleSignCmd(c *cli.Context) error { } func releaseBundleDistributeCmd(c *cli.Context) error { - if c.NArg() != 2 { - return cliutils.WrongNumberOfArgumentsHandler(c) - } - if c.IsSet("max-wait-minutes") && !c.IsSet("sync") { - return cliutils.PrintHelpAndReturnError("The --max-wait-minutes option can't be used without --sync", c) - } - var distributionRules *spec.DistributionRules - if c.IsSet("dist-rules") { - if c.IsSet("site") || c.IsSet("city") || c.IsSet("country-code") { - return cliutils.PrintHelpAndReturnError("The --dist-rules option can't be used with --site, --city or --country-code", c) - } - var err error - distributionRules, err = spec.CreateDistributionRulesFromFile(c.String("dist-rules")) - if err != nil { - return err - } - } else { - distributionRules = createDefaultDistributionRules(c) + if err := distribution.ValidateReleaseBundleDistributeCmd(c); err != nil { + return err } - params := distributionServices.NewDistributeReleaseBundleParams(c.Args().Get(0), c.Args().Get(1)) - releaseBundleDistributeCmd := distributionCommands.NewReleaseBundleDistributeCommand() - rtDetails, err := createArtifactoryDetailsByFlags(c) + dsDetails, err := createDistributionDetailsByFlags(c) if err != nil { return err } - maxWaitMinutes, err := cliutils.GetIntFlagValue(c, "max-wait-minutes", 60) + distributionRules, maxWaitMinutes, params, err := distribution.InitReleaseBundleDistributeCmd(c) if err != nil { return err } - releaseBundleDistributeCmd.SetServerDetails(rtDetails). + + distributeCmd := distributionCommands.NewReleaseBundleDistributeV1Command() + distributeCmd.SetServerDetails(dsDetails). SetDistributeBundleParams(params). SetDistributionRules(distributionRules). SetDryRun(c.Bool("dry-run")). @@ -230,7 +214,7 @@ func releaseBundleDistributeCmd(c *cli.Context) error { SetMaxWaitMinutes(maxWaitMinutes). SetAutoCreateRepo(c.Bool("create-repo")) - return commands.Exec(releaseBundleDistributeCmd) + return commands.Exec(distributeCmd) } func releaseBundleDeleteCmd(c *cli.Context) error { @@ -248,7 +232,7 @@ func releaseBundleDeleteCmd(c *cli.Context) error { return err } } else { - distributionRules = createDefaultDistributionRules(c) + distributionRules = distribution.CreateDefaultDistributionRules(c) } params := distributionServices.NewDeleteReleaseBundleParams(c.Args().Get(0), c.Args().Get(1)) @@ -260,11 +244,11 @@ func releaseBundleDeleteCmd(c *cli.Context) error { } params.MaxWaitMinutes = maxWaitMinutes distributeBundleCmd := distributionCommands.NewReleaseBundleDeleteParams() - rtDetails, err := createArtifactoryDetailsByFlags(c) + dsDetails, err := createDistributionDetailsByFlags(c) if err != nil { return err } - distributeBundleCmd.SetQuiet(cliutils.GetQuietValue(c)).SetServerDetails(rtDetails).SetDistributeBundleParams(params).SetDistributionRules(distributionRules).SetDryRun(c.Bool("dry-run")) + distributeBundleCmd.SetQuiet(cliutils.GetQuietValue(c)).SetServerDetails(dsDetails).SetDistributeBundleParams(params).SetDistributionRules(distributionRules).SetDryRun(c.Bool("dry-run")) return commands.Exec(distributeBundleCmd) } @@ -283,16 +267,6 @@ func createDefaultReleaseBundleSpec(c *cli.Context) *spec.SpecFiles { BuildSpec() } -func createDefaultDistributionRules(c *cli.Context) *spec.DistributionRules { - return &spec.DistributionRules{ - DistributionRules: []spec.DistributionRule{{ - SiteName: c.String("site"), - CityName: c.String("city"), - CountryCodes: cliutils.GetStringsArrFlagValue(c, "country-codes"), - }}, - } -} - func createReleaseBundleCreateUpdateParams(c *cli.Context, bundleName, bundleVersion string) (distributionServicesUtils.ReleaseBundleParams, error) { releaseBundleParams := distributionServicesUtils.NewReleaseBundleParams(bundleName, bundleVersion) releaseBundleParams.SignImmediately = c.Bool("sign") @@ -336,13 +310,13 @@ func populateReleaseNotesSyntax(c *cli.Context) (distributionServicesUtils.Relea return distributionServicesUtils.PlainText, nil } -func createArtifactoryDetailsByFlags(c *cli.Context) (*coreConfig.ServerDetails, error) { - artDetails, err := cliutils.CreateServerDetailsWithConfigOffer(c, true, cliutils.Ds) +func createDistributionDetailsByFlags(c *cli.Context) (*coreConfig.ServerDetails, error) { + dsDetails, err := cliutils.CreateServerDetailsWithConfigOffer(c, true, cliutils.Ds) if err != nil { return nil, err } - if artDetails.DistributionUrl == "" { + if dsDetails.DistributionUrl == "" { return nil, errors.New("the --dist-url option is mandatory") } - return artDetails, nil + return dsDetails, nil } diff --git a/distribution_test.go b/distribution_test.go index 9c23f7304..62cbea526 100644 --- a/distribution_test.go +++ b/distribution_test.go @@ -14,6 +14,7 @@ import ( distributionServices "github.com/jfrog/jfrog-client-go/distribution/services" clientDistUtils "github.com/jfrog/jfrog-client-go/distribution/services/utils" clientUtils "github.com/jfrog/jfrog-client-go/utils" + "github.com/jfrog/jfrog-client-go/utils/distribution" "github.com/jfrog/jfrog-client-go/utils/io/fileutils" "github.com/jfrog/jfrog-client-go/utils/io/httputils" "github.com/jfrog/jfrog-client-go/utils/log" @@ -566,7 +567,7 @@ func TestDistributeSyncTimeout(t *testing.T) { testServer, mockServerDetails, _ := coreTestUtils.CreateDsRestsMockServer(t, func(w http.ResponseWriter, r *http.Request) { if r.RequestURI == "/api/v1/distribution/"+tests.BundleName+"/"+bundleVersion { w.WriteHeader(http.StatusOK) - content, err := json.Marshal(distributionServices.DistributionResponseBody{TrackerId: json.Number(trackerId)}) + content, err := json.Marshal(distribution.DistributionResponseBody{TrackerId: json.Number(trackerId)}) assert.NoError(t, err) _, err = w.Write(content) assert.NoError(t, err) diff --git a/docker_test.go b/docker_test.go index 7f4311374..43b59e310 100644 --- a/docker_test.go +++ b/docker_test.go @@ -3,6 +3,7 @@ package main import ( "context" "fmt" + biutils "github.com/jfrog/build-info-go/utils" "os" "path" "path/filepath" @@ -482,7 +483,7 @@ func runKaniko(t *testing.T, imageToPush string) string { assert.NoError(t, err) workspace, err := filepath.Abs(tests.Out) assert.NoError(t, err) - assert.NoError(t, fileutils.CopyFile(workspace, filepath.Join(testDir, "docker", dockerFile))) + assert.NoError(t, biutils.CopyFile(workspace, filepath.Join(testDir, "docker", dockerFile))) // Run Kaniko to build the test image and push it to Artifactory. _, err = tests.NewContainerRequest(). diff --git a/docs/lifecycle/distribute/help.go b/docs/lifecycle/distribute/help.go new file mode 100644 index 000000000..8a3c2d47f --- /dev/null +++ b/docs/lifecycle/distribute/help.go @@ -0,0 +1,15 @@ +package distribute + +var Usage = []string{"rbd [command options] "} + +func GetDescription() string { + return "Distribute a release bundle." +} + +func GetArguments() string { + return ` release bundle name + Name of the Release Bundle to distribute. + + release bundle version + Version of the Release Bundle to distribute.` +} diff --git a/go.mod b/go.mod index dc83f3523..ec2780edd 100644 --- a/go.mod +++ b/go.mod @@ -7,10 +7,10 @@ require ( github.com/buger/jsonparser v1.1.1 github.com/go-git/go-git/v5 v5.8.1 github.com/gocarina/gocsv v0.0.0-20230616125104-99d496ca653d - github.com/jfrog/build-info-go v1.9.8 + github.com/jfrog/build-info-go v1.9.9 github.com/jfrog/gofrog v1.3.0 - github.com/jfrog/jfrog-cli-core/v2 v2.41.2 - github.com/jfrog/jfrog-client-go v1.31.5 + github.com/jfrog/jfrog-cli-core/v2 v2.41.4 + github.com/jfrog/jfrog-client-go v1.31.6 github.com/jszwec/csvutil v1.8.0 github.com/mholt/archiver/v3 v3.5.1 github.com/stretchr/testify v1.8.4 @@ -21,19 +21,20 @@ require ( golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 golang.org/x/term v0.11.0 gopkg.in/yaml.v2 v2.4.0 + ) require ( dario.cat/mergo v1.0.0 // indirect github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect github.com/BurntSushi/toml v1.3.2 // indirect - github.com/CycloneDX/cyclonedx-go v0.7.1 // indirect + github.com/CycloneDX/cyclonedx-go v0.7.2 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect - github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 // indirect + github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect github.com/VividCortex/ewma v1.2.0 // indirect github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect github.com/acomagu/bufpipe v1.0.4 // indirect - github.com/andybalholm/brotli v1.0.5 // indirect + github.com/andybalholm/brotli v1.0.1 // indirect github.com/c-bata/go-prompt v0.2.5 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect github.com/chzyer/readline v1.5.1 // indirect @@ -56,12 +57,12 @@ require ( github.com/golang-jwt/jwt/v4 v4.5.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.3 // indirect - github.com/golang/snappy v0.0.4 // indirect - github.com/google/uuid v1.3.0 // indirect + github.com/golang/snappy v0.0.2 // indirect + github.com/google/uuid v1.3.1 // indirect github.com/gookit/color v1.5.4 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect - github.com/jedib0t/go-pretty/v6 v6.4.6 // indirect + github.com/jedib0t/go-pretty/v6 v6.4.7 // indirect github.com/kevinburke/ssh_config v1.2.0 // indirect github.com/klauspost/compress v1.16.0 // indirect github.com/klauspost/cpuid/v2 v2.2.3 // indirect @@ -69,7 +70,7 @@ require ( github.com/magiconair/properties v1.8.7 // indirect github.com/manifoldco/promptui v0.9.0 // indirect github.com/mattn/go-colorable v0.1.12 // indirect - github.com/mattn/go-isatty v0.0.16 // indirect + github.com/mattn/go-isatty v0.0.14 // indirect github.com/mattn/go-runewidth v0.0.13 // indirect github.com/mattn/go-tty v0.0.3 // indirect github.com/minio/sha256-simd v1.0.1 // indirect @@ -84,7 +85,7 @@ require ( github.com/opencontainers/runc v1.1.5 // indirect github.com/owenrumney/go-sarif/v2 v2.2.0 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect - github.com/pierrec/lz4/v4 v4.1.15 // indirect + github.com/pierrec/lz4/v4 v4.1.2 // indirect github.com/pjbgf/sha1cd v0.3.0 // indirect github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect github.com/pkg/errors v0.9.1 // indirect @@ -122,10 +123,12 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20230820165857-52ff32c4d8eb +// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20230828134416-f0db33dd9344 -// replace github.com/jfrog/jfrog-cli-core/v2 => github.com/eyalbe4/jfrog-cli-core/v2 v2.22.1-0.20230825095403-f5869e4264d6 +replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20230831153853-3ddf531482e7 // replace github.com/jfrog/gofrog => github.com/jfrog/gofrog v1.2.6-0.20230418122323-2bf299dd6d27 -// replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20230803140217-0a5f43783ae8 +replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20230831152946-6ed2ae1aa57f + +replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20230831151231-e5e7bd035ddc diff --git a/go.sum b/go.sum index bd0657de8..4f38367f0 100644 --- a/go.sum +++ b/go.sum @@ -45,14 +45,14 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/CycloneDX/cyclonedx-go v0.7.1 h1:5w1SxjGm9MTMNTuRbEPyw21ObdbaagTWF/KfF0qHTRE= -github.com/CycloneDX/cyclonedx-go v0.7.1/go.mod h1:N/nrdWQI2SIjaACyyDs/u7+ddCkyl/zkNs8xFsHF2Ps= +github.com/CycloneDX/cyclonedx-go v0.7.2 h1:kKQ0t1dPOlugSIYVOMiMtFqeXI2wp/f5DBIdfux8gnQ= +github.com/CycloneDX/cyclonedx-go v0.7.2/go.mod h1:K2bA+324+Og0X84fA8HhN2X066K7Bxz4rpMQ4ZhjtSk= github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/Microsoft/hcsshim v0.10.0-rc.8 h1:YSZVvlIIDD1UxQpJp0h+dnpLUw+TrY0cx8obKsp3bek= -github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 h1:KLq8BE0KwCL+mmXnjLWEAOYO+2l2AE4YMmqG1ZpZHBs= -github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= +github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 h1:kkhsdkhsCvIsutKu5zLMgWtgh9YxGCNAw8Ad8hjwfYg= +github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow= github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4= github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8= @@ -61,9 +61,8 @@ github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4= github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRBij0P8= github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo= +github.com/andybalholm/brotli v1.0.1 h1:KqhlKozYbRtJvsPrrEeXcO+N2l6NYT5A2QAFmSULpEc= github.com/andybalholm/brotli v1.0.1/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= -github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= -github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q= @@ -189,9 +188,8 @@ github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/snappy v0.0.2 h1:aeE13tS0IiQgFjYdoL8qN3K1N2bXXtI6Vi51/y7BpMw= github.com/golang/snappy v0.0.2/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= -github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= @@ -220,8 +218,8 @@ github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= +github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= @@ -235,16 +233,16 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1: github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= -github.com/jedib0t/go-pretty/v6 v6.4.6 h1:v6aG9h6Uby3IusSSEjHaZNXpHFhzqMmjXcPq1Rjl9Jw= -github.com/jedib0t/go-pretty/v6 v6.4.6/go.mod h1:Ndk3ase2CkQbXLLNf5QDHoYb6J9WtVfmHZu9n8rk2xs= -github.com/jfrog/build-info-go v1.9.8 h1:D8/ga+YgQpqp/CJj2zteS4/twmSy8zvm1v9lCd2Kv1M= -github.com/jfrog/build-info-go v1.9.8/go.mod h1:t31QRpH5xUJKw8XkQlAA+Aq7aanyS1rrzpcK8xSNVts= +github.com/jedib0t/go-pretty/v6 v6.4.7 h1:lwiTJr1DEkAgzljsUsORmWsVn5MQjt1BPJdPCtJ6KXE= +github.com/jedib0t/go-pretty/v6 v6.4.7/go.mod h1:Ndk3ase2CkQbXLLNf5QDHoYb6J9WtVfmHZu9n8rk2xs= +github.com/jfrog/build-info-go v1.8.9-0.20230831151231-e5e7bd035ddc h1:pqu82clhPKyUKJcljMuxYa+kviaWnHycLNCLqZZNl30= +github.com/jfrog/build-info-go v1.8.9-0.20230831151231-e5e7bd035ddc/go.mod h1:QEskae5fQpjeY2PBzsjWtUQVskYSNDF2sSmw/Gx44dQ= github.com/jfrog/gofrog v1.3.0 h1:o4zgsBZE4QyDbz2M7D4K6fXPTBJht+8lE87mS9bw7Gk= github.com/jfrog/gofrog v1.3.0/go.mod h1:IFMc+V/yf7rA5WZ74CSbXe+Lgf0iApEQLxRZVzKRUR0= -github.com/jfrog/jfrog-cli-core/v2 v2.41.2 h1:Gnp93JcDAnHHCN3SHqam2K/S9yJcytS4q+MQd6vv9Ck= -github.com/jfrog/jfrog-cli-core/v2 v2.41.2/go.mod h1:YqB9rEJF1P7uGLIPUvF5qdDDf1zM5f4DneIQNkqyAfs= -github.com/jfrog/jfrog-client-go v1.31.5 h1:dYVgIJzMwX+EU9GEELKPSHFLyfW6UrrjZWMEZtAyx6A= -github.com/jfrog/jfrog-client-go v1.31.5/go.mod h1:icb00ZJN/mMMNkQduHDkzpqsXH9Flwi3f3COYexq3Nc= +github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20230831153853-3ddf531482e7 h1:G60mVnOYqtVJ0UQpkYS2kmbqYZ59q1g8XivZt9W0tUg= +github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20230831153853-3ddf531482e7/go.mod h1:eQJU+jDTcPVqOeHNheURqkMEMXDVNQFKKjcyVEa0058= +github.com/jfrog/jfrog-client-go v1.28.1-0.20230831152946-6ed2ae1aa57f h1:S6l0o2sKFLRJ+QYVB5U/PJhrnwFSmKFFY7eHpRPRH8A= +github.com/jfrog/jfrog-client-go v1.28.1-0.20230831152946-6ed2ae1aa57f/go.mod h1:uUnMrqHX7Xi+OCaZEE4b3BtsmGeOSCB7XqaEWVXEH/E= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/jszwec/csvutil v1.8.0 h1:G7vS2LGdpZZDH1HmHeNbxOaJ/ZnJlpwGFvOkTkJzzNk= @@ -283,9 +281,8 @@ github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= -github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= @@ -324,9 +321,8 @@ github.com/owenrumney/go-sarif/v2 v2.2.0 h1:1DmZaijK0HBZCR1fgcDSGa7VzYkU9NDmbZ7q github.com/owenrumney/go-sarif/v2 v2.2.0/go.mod h1:MSqMMx9WqlBSY7pXoOZWgEsVB4FDNfhcaXDA1j6Sr+w= github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= +github.com/pierrec/lz4/v4 v4.1.2 h1:qvY3YFXRQE/XB8MlLzJH7mSzBs74eA2gg52YTk6jUPM= github.com/pierrec/lz4/v4 v4.1.2/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= -github.com/pierrec/lz4/v4 v4.1.15 h1:MO0/ucJhngq7299dKLwIMtgTfbkoSPF6AoMYDd8Q4q0= -github.com/pierrec/lz4/v4 v4.1.15/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= @@ -385,6 +381,7 @@ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= +github.com/terminalstatic/go-xsd-validate v0.1.5 h1:RqpJnf6HGE2CB/lZB1A8BYguk8uRtcvYAPLCF15qguo= github.com/testcontainers/testcontainers-go v0.23.0 h1:ERYTSikX01QczBLPZpqsETTBO7lInqEP349phDOVJVs= github.com/testcontainers/testcontainers-go v0.23.0/go.mod h1:3gzuZfb7T9qfcH2pHpV4RLlWrPjeWNQah6XlYQ32c4I= github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= @@ -594,7 +591,6 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220909162455-aba9fc2a8ff2/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/go_test.go b/go_test.go index 1b00960c0..0d558121f 100644 --- a/go_test.go +++ b/go_test.go @@ -2,6 +2,7 @@ package main import ( "fmt" + biutils "github.com/jfrog/build-info-go/utils" "os" "os/exec" "path/filepath" @@ -279,7 +280,7 @@ func prepareGoProject(projectName string, t *testing.T, copyDirs bool) string { projectPath := createGoProject(t, projectName, copyDirs) testdataTarget := filepath.Join(tests.Out, "testdata") testdataSrc := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "go", "testdata") - err := fileutils.CopyDir(testdataSrc, testdataTarget, copyDirs, nil) + err := biutils.CopyDir(testdataSrc, testdataTarget, copyDirs, nil) assert.NoError(t, err) configFileDir := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "go", projectName, ".jfrog", "projects") _, err = tests.ReplaceTemplateVariables(filepath.Join(configFileDir, "go.yaml"), filepath.Join(projectPath, ".jfrog", "projects")) @@ -326,12 +327,13 @@ func createTempGoPath(t *testing.T) (tempGoPath string, cleanUp func()) { func createGoProject(t *testing.T, projectName string, includeDirs bool) string { projectSrc := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "go", projectName) projectTarget := filepath.Join(tests.Out, projectName) - err := fileutils.CopyDir(projectSrc, projectTarget, includeDirs, nil) + err := biutils.CopyDir(projectSrc, projectTarget, includeDirs, nil) assert.NoError(t, err) projectTarget, err = filepath.Abs(projectTarget) assert.NoError(t, err) goModeOriginalPath := filepath.Join(projectTarget, "createGoProject_go.mod_suffix") goModeTargetPath := filepath.Join(projectTarget, "go.mod") + assert.NoError(t, os.Chmod(goModeOriginalPath, 0700)) assert.NoError(t, os.Rename(goModeOriginalPath, goModeTargetPath)) return projectTarget } diff --git a/inttestutils/buildinfo.go b/inttestutils/buildinfo.go index 954ca6987..3003172bf 100644 --- a/inttestutils/buildinfo.go +++ b/inttestutils/buildinfo.go @@ -11,8 +11,8 @@ import ( coreutils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" - "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/http/httpclient" + "github.com/jfrog/jfrog-client-go/utils" "github.com/jfrog/jfrog-client-go/utils/io/httputils" "github.com/jfrog/jfrog-client-go/utils/log" "github.com/stretchr/testify/assert" @@ -27,7 +27,7 @@ func DeleteBuild(artifactoryUrl, buildName string, artHttpDetails httputils.Http restApi := path.Join("api/build/", buildName) params := map[string]string{"deleteAll": "1"} - requestFullUrl, err := utils.BuildArtifactoryUrl(artifactoryUrl, restApi, params) + requestFullUrl, err := utils.BuildUrl(artifactoryUrl, restApi, params) if err != nil { log.Error(err) return diff --git a/lifecycle/cli.go b/lifecycle/cli.go index 8caa332d2..647963c10 100644 --- a/lifecycle/cli.go +++ b/lifecycle/cli.go @@ -8,8 +8,10 @@ import ( coreConfig "github.com/jfrog/jfrog-cli-core/v2/utils/config" "github.com/jfrog/jfrog-cli/docs/common" rbCreate "github.com/jfrog/jfrog-cli/docs/lifecycle/create" + rbDistribute "github.com/jfrog/jfrog-cli/docs/lifecycle/distribute" rbPromote "github.com/jfrog/jfrog-cli/docs/lifecycle/promote" "github.com/jfrog/jfrog-cli/utils/cliutils" + "github.com/jfrog/jfrog-cli/utils/distribution" "github.com/jfrog/jfrog-client-go/utils" "github.com/jfrog/jfrog-client-go/utils/errorutils" "github.com/urfave/cli" @@ -43,6 +45,19 @@ func GetCommands() []cli.Command { Category: lcCategory, Action: promote, }, + { + Name: "release-bundle-distribute", + Aliases: []string{"rbd"}, + Flags: cliutils.GetCommandFlags(cliutils.ReleaseBundleDistribute), + Usage: rbDistribute.GetDescription(), + HelpName: coreCommon.CreateUsage("rbd", rbDistribute.GetDescription(), rbDistribute.Usage), + UsageText: rbDistribute.GetArguments(), + ArgsUsage: common.CreateEnvVars(), + BashComplete: coreCommon.CreateBashCompletionFunc(), + Category: lcCategory, + Hidden: true, + Action: distribute, + }, }) } @@ -77,7 +92,7 @@ func create(c *cli.Context) (err error) { return } - createCmd := lifecycle.NewReleaseBundleCreate().SetServerDetails(lcDetails).SetReleaseBundleName(c.Args().Get(0)). + createCmd := lifecycle.NewReleaseBundleCreateCommand().SetServerDetails(lcDetails).SetReleaseBundleName(c.Args().Get(0)). SetReleaseBundleVersion(c.Args().Get(1)).SetSigningKeyName(c.String(cliutils.SigningKey)).SetSync(c.Bool(cliutils.Sync)). SetReleaseBundleProject(cliutils.GetProject(c)).SetBuildsSpecPath(c.String(cliutils.Builds)). SetReleaseBundlesSpecPath(c.String(cliutils.ReleaseBundles)) @@ -102,12 +117,51 @@ func promote(c *cli.Context) error { return err } - createCmd := lifecycle.NewReleaseBundlePromote().SetServerDetails(lcDetails).SetReleaseBundleName(c.Args().Get(0)). + createCmd := lifecycle.NewReleaseBundlePromoteCommand().SetServerDetails(lcDetails).SetReleaseBundleName(c.Args().Get(0)). SetReleaseBundleVersion(c.Args().Get(1)).SetEnvironment(c.Args().Get(2)).SetSigningKeyName(c.String(cliutils.SigningKey)). SetSync(c.Bool(cliutils.Sync)).SetReleaseBundleProject(cliutils.GetProject(c)).SetOverwrite(c.Bool(cliutils.Overwrite)) return commands.Exec(createCmd) } +func distribute(c *cli.Context) error { + if err := validateDistributeCommand(c); err != nil { + return err + } + + lcDetails, err := createLifecycleDetailsByFlags(c) + if err != nil { + return err + } + distributionRules, _, params, err := distribution.InitReleaseBundleDistributeCmd(c) + if err != nil { + return err + } + + distributeCmd := lifecycle.NewReleaseBundleDistributeCommand() + distributeCmd.SetServerDetails(lcDetails). + SetDistributeBundleParams(params). + SetDistributionRules(distributionRules). + SetDryRun(c.Bool("dry-run")). + SetAutoCreateRepo(c.Bool(cliutils.CreateRepo)). + SetPathMappingPattern(c.String(cliutils.PathMappingPattern)). + SetPathMappingTarget(c.String(cliutils.PathMappingTarget)) + return commands.Exec(distributeCmd) +} + +func validateDistributeCommand(c *cli.Context) error { + if err := distribution.ValidateReleaseBundleDistributeCmd(c); err != nil { + return err + } + + mappingPatternProvided := c.IsSet(cliutils.PathMappingPattern) + mappingTargetProvided := c.IsSet(cliutils.PathMappingTarget) + if (mappingPatternProvided && !mappingTargetProvided) || + (!mappingPatternProvided && mappingTargetProvided) { + return errorutils.CheckErrorf("the options --%s and --%s must be provided together", cliutils.PathMappingPattern, cliutils.PathMappingTarget) + } + return nil +} + func assertSigningKeyProvided(c *cli.Context) error { if c.String(cliutils.SigningKey) == "" { return errorutils.CheckErrorf("the --%s option is mandatory", cliutils.SigningKey) diff --git a/lifecycle_test.go b/lifecycle_test.go index 24980c734..5a1516df8 100644 --- a/lifecycle_test.go +++ b/lifecycle_test.go @@ -23,14 +23,14 @@ import ( ) const ( - rbMinVersion = "7.45.0" - gpgKeyPairName = "lc-tests-key-pair" - lcTestdataPath = "lifecycle" - releaseBundlesSpec = "release-bundles-spec.json" - buildsSpec12 = "builds-spec-1-2.json" - buildsSpec3 = "builds-spec-3.json" - prodEnvironment = "PROD" - number1, number2, number3 = "111", "222", "333" + artifactoryLifecycleMinVersion = "7.68.3" + gpgKeyPairName = "lc-tests-key-pair" + lcTestdataPath = "lifecycle" + releaseBundlesSpec = "release-bundles-spec.json" + buildsSpec12 = "builds-spec-1-2.json" + buildsSpec3 = "builds-spec-3.json" + prodEnvironment = "PROD" + number1, number2, number3 = "111", "222", "333" ) var ( @@ -47,11 +47,11 @@ func TestLifecycle(t *testing.T) { deleteBuilds := uploadBuilds(t) defer deleteBuilds() - // Create release bundles from builds synchronously. + // Create release bundle from builds synchronously. createRb(t, buildsSpec12, cliutils.Builds, tests.LcRbName1, number1, true) defer deleteReleaseBundle(t, lcManager, tests.LcRbName1, number1) - // Create release bundles from builds asynchronously and assert status. + // Create release bundle from builds asynchronously and assert status. createRb(t, buildsSpec3, cliutils.Builds, tests.LcRbName2, number2, false) defer deleteReleaseBundle(t, lcManager, tests.LcRbName2, number2) assertStatusCompleted(t, lcManager, tests.LcRbName2, number2, "") @@ -67,6 +67,11 @@ func TestLifecycle(t *testing.T) { searchSpec, err := tests.CreateSpec(tests.SearchAllProdRepo) assert.NoError(t, err) inttestutils.VerifyExistInArtifactory(tests.GetExpectedLifecycleArtifacts(), searchSpec, serverDetails, t) + + distributeRb(t) + // Verify the artifacts were distributed correctly by the provided path mappings. + expected := append(tests.GetExpectedLifecycleArtifacts(), tests.GetExpectedLifecycleMappingArtifacts()...) + inttestutils.VerifyExistInArtifactory(expected, searchSpec, serverDetails, t) } func uploadBuilds(t *testing.T) func() { @@ -80,13 +85,13 @@ func uploadBuilds(t *testing.T) func() { } } -func createRb(t *testing.T, specName, sourceOption, buildName, buildNumber string, sync bool) { +func createRb(t *testing.T, specName, sourceOption, rbName, rbVersion string, sync bool) { specFile, err := getSpecFile(specName) assert.NoError(t, err) argsAndOptions := []string{ "rbc", - buildName, - buildNumber, + rbName, + rbVersion, getOption(sourceOption, specFile), getOption(cliutils.SigningKey, gpgKeyPairName), } @@ -97,6 +102,16 @@ func createRb(t *testing.T, specName, sourceOption, buildName, buildNumber strin assert.NoError(t, lcCli.Exec(argsAndOptions...)) } +func distributeRb(t *testing.T) { + distributionRulesPath := filepath.Join(tests.GetTestResourcesPath(), "distribution", tests.DistributionRules) + assert.NoError(t, lcCli.Exec( + "rbd", tests.LcRbName3, number3, + getOption(cliutils.DistRules, distributionRulesPath), + getOption(cliutils.PathMappingPattern, tests.RtProdRepo+"/(*)"), + getOption(cliutils.PathMappingTarget, tests.RtProdRepo+"/target/{1}"), + )) +} + func getOption(option, value string) string { return fmt.Sprintf("--%s=%s", option, value) } @@ -183,7 +198,7 @@ func initLifecycleTest(t *testing.T) { if !*tests.TestLifecycle { t.Skip("Skipping lifecycle test. To run release bundle test add the '-test.lc=true' option.") } - validateArtifactoryVersion(t, rbMinVersion) + validateArtifactoryVersion(t, artifactoryLifecycleMinVersion) if !isLifecycleSupported(t) { t.Skip("Skipping lifecycle test because the functionality is not enabled on the provided JPD.") diff --git a/main_test.go b/main_test.go index bc6684073..96efc1218 100644 --- a/main_test.go +++ b/main_test.go @@ -221,9 +221,9 @@ func createConfigFileForTest(dirs []string, resolver, deployer string, t *testin // Create config file to make sure the path is valid f, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) assert.NoError(t, err, "Couldn't create file") - defer func() { - assert.NoError(t, f.Close()) - }() + defer func(file *os.File) { + assert.NoError(t, file.Close()) + }(f) _, err = f.Write(d) assert.NoError(t, err) } diff --git a/maven_test.go b/maven_test.go index e7de3a582..16311cb5c 100644 --- a/maven_test.go +++ b/maven_test.go @@ -3,6 +3,7 @@ package main import ( "fmt" buildinfo "github.com/jfrog/build-info-go/entities" + biutils "github.com/jfrog/build-info-go/utils" "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/mvn" "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" "github.com/jfrog/jfrog-cli-core/v2/common/commands" @@ -13,7 +14,6 @@ import ( "github.com/jfrog/jfrog-cli/utils/tests" cliproxy "github.com/jfrog/jfrog-cli/utils/tests/proxy/server" "github.com/jfrog/jfrog-cli/utils/tests/proxy/server/certificate" - "github.com/jfrog/jfrog-client-go/utils/io/fileutils" "github.com/jfrog/jfrog-client-go/utils/log" clientTestUtils "github.com/jfrog/jfrog-client-go/utils/tests" "github.com/stretchr/testify/assert" @@ -178,7 +178,7 @@ func createMultiMavenProject(t *testing.T) string { return "" } destPath = filepath.Join(destPath, tests.Temp) - assert.NoError(t, fileutils.CopyDir(projectDir, destPath, true, nil)) + assert.NoError(t, biutils.CopyDir(projectDir, destPath, true, nil)) return destPath } diff --git a/npm_test.go b/npm_test.go index 6cc36806e..1a5e4a683 100644 --- a/npm_test.go +++ b/npm_test.go @@ -11,7 +11,8 @@ import ( "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/yarn" - biutils "github.com/jfrog/build-info-go/build/utils" + buildutils "github.com/jfrog/build-info-go/build/utils" + biutils "github.com/jfrog/build-info-go/utils" "github.com/jfrog/gofrog/version" coretests "github.com/jfrog/jfrog-cli-core/v2/utils/tests" "github.com/jfrog/jfrog-client-go/utils/log" @@ -69,7 +70,7 @@ func testNpm(t *testing.T, isLegacy bool) { wd, err := os.Getwd() assert.NoError(t, err, "Failed to get current dir") defer clientTestUtils.ChangeDirAndAssert(t, wd) - npmVersion, _, err := biutils.GetNpmVersionAndExecPath(log.Logger) + npmVersion, _, err := buildutils.GetNpmVersionAndExecPath(log.Logger) if err != nil { assert.NoError(t, err) return @@ -134,7 +135,7 @@ func testNpm(t *testing.T, isLegacy bool) { } func readModuleId(t *testing.T, wd string, npmVersion *version.Version) string { - packageInfo, err := biutils.ReadPackageInfoFromPackageJson(filepath.Dir(wd), npmVersion) + packageInfo, err := buildutils.ReadPackageInfoFromPackageJson(filepath.Dir(wd), npmVersion) assert.NoError(t, err) return packageInfo.BuildInfoModuleId() } @@ -171,7 +172,7 @@ func TestNpmConditionalUpload(t *testing.T) { assert.NoError(t, err, "Failed to get current dir") searchSpec, err := tests.CreateSpec(tests.SearchAllNpm) assert.NoError(t, err) - npmVersion, _, err := biutils.GetNpmVersionAndExecPath(log.Logger) + npmVersion, _, err := buildutils.GetNpmVersionAndExecPath(log.Logger) assert.NoError(t, err) npmProjectPath := initNpmProjectTest(t) clientTestUtils.ChangeDirAndAssert(t, npmProjectPath) @@ -350,7 +351,7 @@ func TestNpmPublishDetailedSummary(t *testing.T) { assert.NoError(t, err, "Failed to get current dir") defer clientTestUtils.ChangeDirAndAssert(t, wd) - npmVersion, _, err := biutils.GetNpmVersionAndExecPath(log.Logger) + npmVersion, _, err := buildutils.GetNpmVersionAndExecPath(log.Logger) if err != nil { assert.NoError(t, err) return @@ -460,7 +461,7 @@ func TestYarn(t *testing.T) { testDataSource := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "yarn") testDataTarget := filepath.Join(tempDirPath, tests.Out, "yarn") - assert.NoError(t, fileutils.CopyDir(testDataSource, testDataTarget, true, nil)) + assert.NoError(t, biutils.CopyDir(testDataSource, testDataTarget, true, nil)) yarnProjectPath := filepath.Join(testDataTarget, "yarnproject") assert.NoError(t, createConfigFileForTest([]string{yarnProjectPath}, tests.NpmRemoteRepo, "", t, utils.Yarn, false)) diff --git a/nuget_test.go b/nuget_test.go index b77f106b5..1f5f498b1 100644 --- a/nuget_test.go +++ b/nuget_test.go @@ -4,6 +4,7 @@ import ( "encoding/xml" dotnetUtils "github.com/jfrog/build-info-go/build/utils/dotnet" buildInfo "github.com/jfrog/build-info-go/entities" + biutils "github.com/jfrog/build-info-go/utils" "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/dotnet" "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" "github.com/jfrog/jfrog-cli-core/v2/utils/config" @@ -93,7 +94,7 @@ func createNugetProject(t *testing.T, projectName string) string { err := fileutils.CreateDirIfNotExist(projectTarget) assert.NoError(t, err) - err = fileutils.CopyDir(projectSrc, projectTarget, true, nil) + err = biutils.CopyDir(projectSrc, projectTarget, true, nil) assert.NoError(t, err) return projectTarget } diff --git a/pip_test.go b/pip_test.go index e466d2d25..f7bcc9a96 100644 --- a/pip_test.go +++ b/pip_test.go @@ -1,6 +1,7 @@ package main import ( + biutils "github.com/jfrog/build-info-go/utils" "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" coretests "github.com/jfrog/jfrog-cli-core/v2/utils/tests" "github.com/jfrog/jfrog-cli-core/v2/xray/audit/python" @@ -168,7 +169,7 @@ func createPipProject(t *testing.T, outFolder, projectName string) string { assert.NoError(t, err) // Copy pip-installation file. - err = fileutils.CopyDir(projectSrc, projectTarget, true, nil) + err = biutils.CopyDir(projectSrc, projectTarget, true, nil) assert.NoError(t, err) // Copy pip-config file. diff --git a/pipenv_test.go b/pipenv_test.go index 0200eb0cb..f5b7b9bc6 100644 --- a/pipenv_test.go +++ b/pipenv_test.go @@ -1,6 +1,7 @@ package main import ( + biutils "github.com/jfrog/build-info-go/utils" "os" "path/filepath" "strconv" @@ -112,7 +113,7 @@ func createPipenvProject(t *testing.T, outFolder, projectName string) string { assert.NoError(t, err) // Copy pipenv-installation file. - err = fileutils.CopyDir(projectSrc, projectTarget, true, nil) + err = biutils.CopyDir(projectSrc, projectTarget, true, nil) assert.NoError(t, err) // Copy pipenv-config file. diff --git a/plugins/commands/uninstall_test.go b/plugins/commands/uninstall_test.go index 4aa5b975d..dfee60776 100644 --- a/plugins/commands/uninstall_test.go +++ b/plugins/commands/uninstall_test.go @@ -1,6 +1,7 @@ package commands import ( + biutils "github.com/jfrog/build-info-go/utils" "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" "github.com/jfrog/jfrog-cli-core/v2/utils/log" "github.com/jfrog/jfrog-cli-core/v2/utils/plugins" @@ -39,7 +40,7 @@ func TestRunUninstallCmd(t *testing.T) { return } pluginName := filepath.Base(pluginMockPath) - err = fileutils.CopyDir(pluginMockPath, filepath.Join(pluginsDir, pluginName), true, nil) + err = biutils.CopyDir(pluginMockPath, filepath.Join(pluginsDir, pluginName), true, nil) if err != nil { assert.NoError(t, err) return diff --git a/plugins_test.go b/plugins_test.go index 83e51eb77..dcbe0e187 100644 --- a/plugins_test.go +++ b/plugins_test.go @@ -1,6 +1,7 @@ package main import ( + biutils "github.com/jfrog/build-info-go/utils" "os" "path" "path/filepath" @@ -254,7 +255,7 @@ func TestPublishInstallCustomServer(t *testing.T) { exists, err := fileutils.IsDirExists(filepath.Join(wd, coreutils.PluginsResourcesDirName), false) assert.NoError(t, err) assert.False(t, exists) - err = fileutils.CopyDir(filepath.Join(wd, "testdata", "plugins", "plugin-mock", coreutils.PluginsResourcesDirName), filepath.Join(wd, coreutils.PluginsResourcesDirName), true, nil) + err = biutils.CopyDir(filepath.Join(wd, "testdata", "plugins", "plugin-mock", coreutils.PluginsResourcesDirName), filepath.Join(wd, coreutils.PluginsResourcesDirName), true, nil) assert.NoError(t, err) // Test with resources directory testPublishAndInstall(t, true) diff --git a/poetry_test.go b/poetry_test.go index 89194e1dc..3188ad34d 100644 --- a/poetry_test.go +++ b/poetry_test.go @@ -1,6 +1,7 @@ package main import ( + biutils "github.com/jfrog/build-info-go/utils" "os" "path/filepath" "strconv" @@ -108,7 +109,7 @@ func createPoetryProject(t *testing.T, outFolder, projectName string) string { assert.NoError(t, err) // Copy poetry project - err = fileutils.CopyDir(projectSrc, projectTarget, true, nil) + err = biutils.CopyDir(projectSrc, projectTarget, true, nil) assert.NoError(t, err) // Copy poetry-config file. diff --git a/testdata/go/dependency/createGoProject_go.mod_suffix b/testdata/go/dependency/createGoProject_go.mod_suffix old mode 100644 new mode 100755 diff --git a/testdata/go/project1/createGoProject_go.mod_suffix b/testdata/go/project1/createGoProject_go.mod_suffix old mode 100644 new mode 100755 diff --git a/testdata/go/project2/createGoProject_go.mod_suffix b/testdata/go/project2/createGoProject_go.mod_suffix old mode 100644 new mode 100755 diff --git a/testdata/go/project3/createGoProject_go.mod_suffix b/testdata/go/project3/createGoProject_go.mod_suffix old mode 100644 new mode 100755 diff --git a/testdata/go/project4/createGoProject_go.mod_suffix b/testdata/go/project4/createGoProject_go.mod_suffix old mode 100644 new mode 100755 diff --git a/testdata/go/projectbuild/createGoProject_go.mod_suffix b/testdata/go/projectbuild/createGoProject_go.mod_suffix old mode 100644 new mode 100755 diff --git a/testdata/go/projectmissingdependency/createGoProject_go.mod_suffix b/testdata/go/projectmissingdependency/createGoProject_go.mod_suffix old mode 100644 new mode 100755 diff --git a/testdata/go/vcsfallback/createGoProject_go.mod_suffix b/testdata/go/vcsfallback/createGoProject_go.mod_suffix old mode 100644 new mode 100755 diff --git a/testdata/gradle/projectwithplugin/build.gradle b/testdata/gradle/projectwithplugin/build.gradle index 7664f11cb..d06c9fa99 100644 --- a/testdata/gradle/projectwithplugin/build.gradle +++ b/testdata/gradle/projectwithplugin/build.gradle @@ -9,6 +9,8 @@ buildscript { apply plugin: 'groovy' apply plugin: 'idea' apply plugin: 'com.jfrog.artifactory' +apply plugin: 'maven-publish' + version = 1.0 task initProject(description: 'Initialize project directory structure.') { doLast { @@ -28,6 +30,18 @@ task initProject(description: 'Initialize project directory structure.') { } } +publishing { + publications { + mavenJava(MavenPublication) { + from components.java + } + } +} + +tasks.withType(GenerateModuleMetadata) { + enabled = false +} + artifactory { contextUrl = "${URL}" publish { @@ -40,7 +54,7 @@ artifactory { // Reference to Gradle publications defined in the build script. // This is how we tell the Artifactory Plugin which artifacts should be // published to Artifactory. - publishConfigs('archives', 'published') + publications('mavenJava') publishArtifacts = true // Properties to be attached to the published artifacts. properties = ['qa.level': 'basic', 'dev.team' : 'core'] diff --git a/testdata/npm/npmnpmrcproject/.npmrc b/testdata/npm/npmnpmrcproject/.npmrc old mode 100644 new mode 100755 diff --git a/testdata/npm/npmnpmrcproject/package.json b/testdata/npm/npmnpmrcproject/package.json old mode 100644 new mode 100755 diff --git a/testdata/npm/npmpostinstall/package.json b/testdata/npm/npmpostinstall/package.json old mode 100644 new mode 100755 diff --git a/testdata/npm/npmpostinstall/subdir/package.json b/testdata/npm/npmpostinstall/subdir/package.json old mode 100644 new mode 100755 diff --git a/testdata/npm/npmproject/package.json b/testdata/npm/npmproject/package.json old mode 100644 new mode 100755 diff --git a/testdata/npm/npmprojectci/package.json b/testdata/npm/npmprojectci/package.json old mode 100644 new mode 100755 diff --git a/testdata/npm/npmscopedproject/package.json b/testdata/npm/npmscopedproject/package.json old mode 100644 new mode 100755 diff --git a/testdata/xray/gradle/api/build.gradle b/testdata/xray/gradle/api/build.gradle new file mode 100644 index 000000000..492158b15 --- /dev/null +++ b/testdata/xray/gradle/api/build.gradle @@ -0,0 +1,15 @@ +configurations { + spi +} + +dependencies { + implementation project(':shared') + implementation module("commons-lang:commons-lang:2.4") { + dependency("commons-io:commons-io:1.2") + } + implementation group: 'org.apache.wicket', name: 'wicket', version: '1.3.7' + +} + +// Just a smoke test that using this option does not lead to any exception +compileJava.options.compilerArgs = ['-Xlint:unchecked'] diff --git a/testdata/xray/gradle/api/src/main/java/org/gradle/api/PersonList.java b/testdata/xray/gradle/api/src/main/java/org/gradle/api/PersonList.java new file mode 100644 index 000000000..1d80a16b3 --- /dev/null +++ b/testdata/xray/gradle/api/src/main/java/org/gradle/api/PersonList.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011 JFrog Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.gradle.api; + +import org.gradle.apiImpl.Impl; +import org.gradle.shared.Person; + +import java.util.ArrayList; + + +public class PersonList { + private ArrayList persons = new ArrayList(); + + public void doSomethingWithImpl() { + org.apache.commons.lang.builder.ToStringBuilder stringBuilder; + try { + Class.forName("org.apache.commons.io.FileUtils"); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } + new Impl().implMethod(); + } + +} diff --git a/testdata/xray/gradle/api/src/main/java/org/gradle/api/package.html b/testdata/xray/gradle/api/src/main/java/org/gradle/api/package.html new file mode 100644 index 000000000..cea998a80 --- /dev/null +++ b/testdata/xray/gradle/api/src/main/java/org/gradle/api/package.html @@ -0,0 +1,19 @@ + + + +

These are the API classes

+ diff --git a/testdata/xray/gradle/api/src/main/java/org/gradle/apiImpl/Impl.java b/testdata/xray/gradle/api/src/main/java/org/gradle/apiImpl/Impl.java new file mode 100644 index 000000000..76cf0cc22 --- /dev/null +++ b/testdata/xray/gradle/api/src/main/java/org/gradle/apiImpl/Impl.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2011 JFrog Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.gradle.apiImpl; + + +public class Impl { + + public void implMethod() { + double a = 4.0 * 4; + } + +} diff --git a/testdata/xray/gradle/build.gradle b/testdata/xray/gradle/build.gradle index e1b9e8fd3..1ae1ed814 100644 --- a/testdata/xray/gradle/build.gradle +++ b/testdata/xray/gradle/build.gradle @@ -1,21 +1,33 @@ -apply plugin: 'groovy' -apply plugin: 'idea' +/* + * Copyright (C) 2013 JFrog Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -version = 1.0 -task initProject(description: 'Initialize project directory structure.') { - doLast { - // Default package to be created in each src dir. - def defaultPackage = 'org/jfrog/minimal-project' +buildscript { + repositories { + mavenCentral() + } +} - ['java', 'groovy', 'resources'].each { - // convention.sourceSets contains the directory structure - // for our Groovy project. So we use this structure - // and make a directory for each node. - sourceSets*."${it}".srcDirs*.each { dir -> - def newDir = new File(dir, defaultPackage) - logger.info "Creating directory $newDir" // gradle -i shows this message. - newDir.mkdirs() // Create dir. - } - } +allprojects { + repositories { + mavenCentral() } -} \ No newline at end of file + apply plugin: 'java' + apply plugin: 'maven-publish' + + group = 'org.jfrog.example.gradle' + version = '1.0' + status = 'integration' +} diff --git a/testdata/xray/gradle/gradle/wrapper/gradle-wrapper.jar b/testdata/xray/gradle/gradle/wrapper/gradle-wrapper.jar new file mode 100755 index 000000000..5c2d1cf01 Binary files /dev/null and b/testdata/xray/gradle/gradle/wrapper/gradle-wrapper.jar differ diff --git a/testdata/xray/gradle/gradle/wrapper/gradle-wrapper.properties b/testdata/xray/gradle/gradle/wrapper/gradle-wrapper.properties new file mode 100755 index 000000000..5028f28f8 --- /dev/null +++ b/testdata/xray/gradle/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/testdata/xray/gradle/gradlew b/testdata/xray/gradle/gradlew new file mode 100755 index 000000000..83f2acfdc --- /dev/null +++ b/testdata/xray/gradle/gradlew @@ -0,0 +1,188 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/testdata/xray/gradle/gradlew.bat b/testdata/xray/gradle/gradlew.bat new file mode 100755 index 000000000..9618d8d96 --- /dev/null +++ b/testdata/xray/gradle/gradlew.bat @@ -0,0 +1,100 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/testdata/xray/gradle/services/webservice/build.gradle b/testdata/xray/gradle/services/webservice/build.gradle new file mode 100644 index 000000000..f3ded41f2 --- /dev/null +++ b/testdata/xray/gradle/services/webservice/build.gradle @@ -0,0 +1,8 @@ +apply plugin: 'war' + +dependencies { + implementation project(':shared'), 'commons-collections:commons-collections:3.2@jar', 'commons-io:commons-io:1.2', 'commons-lang:commons-lang:2.4@jar' + implementation group: 'org.apache.wicket', name: 'wicket', version: '1.3.7' + testImplementation group: 'junit', name: 'junit', version: '4.11' + implementation project(':api') +} diff --git a/testdata/xray/gradle/services/webservice/src/main/java/org/gradle/webservice/TestTest.java b/testdata/xray/gradle/services/webservice/src/main/java/org/gradle/webservice/TestTest.java new file mode 100644 index 000000000..4843cca41 --- /dev/null +++ b/testdata/xray/gradle/services/webservice/src/main/java/org/gradle/webservice/TestTest.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2011 JFrog Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.gradle.webservice; + +import org.apache.commons.collections.list.GrowthList; +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.lang.builder.ToStringBuilder; +import org.gradle.api.PersonList; +import org.gradle.shared.Person; + +public class TestTest { + private String name; + + public void method() { + FilenameUtils.separatorsToUnix("my/unix/filename"); + ToStringBuilder.reflectionToString(new Person("name")); + new GrowthList(); + new PersonList().doSomethingWithImpl(); // compile with api-spi, runtime with api + } + +} diff --git a/testdata/xray/gradle/services/webservice/src/test/java/org/gradle/webservice/TestTestTest.java b/testdata/xray/gradle/services/webservice/src/test/java/org/gradle/webservice/TestTestTest.java new file mode 100644 index 000000000..b8e22a4ad --- /dev/null +++ b/testdata/xray/gradle/services/webservice/src/test/java/org/gradle/webservice/TestTestTest.java @@ -0,0 +1,31 @@ +/* + * Copyright 2007 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.gradle.webservice; + +import junit.framework.TestCase; + +/** + * @author Hans Dockter + */ +public class TestTestTest extends TestCase { + public void testClasspath() { + new TestTest().method(); + } + + public void testApiCompileClasspath() { + new org.gradle.api.PersonList(); + } +} diff --git a/testdata/xray/gradle/settings.gradle b/testdata/xray/gradle/settings.gradle index 6cf974940..397a3021a 100644 --- a/testdata/xray/gradle/settings.gradle +++ b/testdata/xray/gradle/settings.gradle @@ -1 +1 @@ -rootProject.name = 'minimal-example' \ No newline at end of file +include "shared", "api", "services:webservice" diff --git a/testdata/xray/gradle/shared/src/main/java/org/gradle/shared/Person.java b/testdata/xray/gradle/shared/src/main/java/org/gradle/shared/Person.java new file mode 100644 index 000000000..d9ed11ee8 --- /dev/null +++ b/testdata/xray/gradle/shared/src/main/java/org/gradle/shared/Person.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2011 JFrog Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.gradle.shared; + +import java.io.IOException; +import java.util.Properties; + +public class Person { + private String name; + + public Person(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String readProperty() throws IOException { + Properties properties = new Properties(); + properties.load(getClass().getClassLoader().getResourceAsStream("org/gradle/shared/main.properties")); + return properties.getProperty("main"); + } +} diff --git a/testdata/xray/gradle/shared/src/main/java/org/gradle/shared/package-info.java b/testdata/xray/gradle/shared/src/main/java/org/gradle/shared/package-info.java new file mode 100644 index 000000000..7c5f65caf --- /dev/null +++ b/testdata/xray/gradle/shared/src/main/java/org/gradle/shared/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2011 JFrog Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * These are the shared classes. + */ +package org.gradle.shared; diff --git a/testdata/xray/gradle/shared/src/main/resources/org/gradle/shared/main.properties b/testdata/xray/gradle/shared/src/main/resources/org/gradle/shared/main.properties new file mode 100644 index 000000000..fe6422c8d --- /dev/null +++ b/testdata/xray/gradle/shared/src/main/resources/org/gradle/shared/main.properties @@ -0,0 +1,16 @@ +# +# Copyright (C) 2011 JFrog Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +main=mainValue diff --git a/transfer_test.go b/transfer_test.go index 1ac5ce147..40c735552 100644 --- a/transfer_test.go +++ b/transfer_test.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + biutils "github.com/jfrog/build-info-go/utils" "os" "path/filepath" "strconv" @@ -397,7 +398,7 @@ func generateSnapshotFiles(t *testing.T) (repoSnapshotDir string) { assert.NoError(t, err) repoState, err := state.GetRepoStateFilepath(tests.RtRepo1, false) assert.NoError(t, err) - assert.NoError(t, fileutils.CopyFile(repoSnapshotDir, repoState)) + assert.NoError(t, biutils.CopyFile(repoSnapshotDir, repoState)) // Create snapshot file at snapshots directory. repoSnapshotFile, err := state.GetRepoSnapshotFilePath(tests.RtRepo1) diff --git a/utils/cliutils/commandsflags.go b/utils/cliutils/commandsflags.go index 625841bc1..24bc36d46 100644 --- a/utils/cliutils/commandsflags.go +++ b/utils/cliutils/commandsflags.go @@ -131,8 +131,9 @@ const ( TransferInstall = "transfer-plugin-install" // Lifecycle commands keys - ReleaseBundleCreate = "release-bundle-create" - ReleaseBundlePromote = "release-bundle-promote" + ReleaseBundleCreate = "release-bundle-create" + ReleaseBundlePromote = "release-bundle-promote" + ReleaseBundleDistribute = "release-bundle-distribute" // *** Artifactory Commands' flags *** // Base flags @@ -424,14 +425,16 @@ const ( desc = "desc" releaseNotesPath = "release-notes-path" releaseNotesSyntax = "release-notes-syntax" - distRules = "dist-rules" - site = "site" - city = "city" - countryCodes = "country-codes" - sync = "sync" - maxWaitMinutes = "max-wait-minutes" deleteFromDist = "delete-from-dist" - createRepo = "create-repo" + + // Common release-bundle-* v1&v2 flags + DistRules = "dist-rules" + site = "site" + city = "city" + countryCodes = "country-codes" + sync = "sync" + maxWaitMinutes = "max-wait-minutes" + CreateRepo = "create-repo" // *** Xray Commands' flags *** // Base flags @@ -542,17 +545,22 @@ const ( InstallPluginHomeDir = "home-dir" // Unique lifecycle flags - lifecyclePrefix = "lc-" - lcUrl = lifecyclePrefix + url - lcSync = lifecyclePrefix + Sync - lcProject = lifecyclePrefix + project - Builds = "builds" - lcBuilds = lifecyclePrefix + Builds - ReleaseBundles = "release-bundles" - lcReleaseBundles = lifecyclePrefix + ReleaseBundles - SigningKey = "signing-key" - lcSigningKey = lifecyclePrefix + SigningKey - lcOverwrite = lifecyclePrefix + Overwrite + lifecyclePrefix = "lc-" + lcUrl = lifecyclePrefix + url + lcSync = lifecyclePrefix + Sync + lcProject = lifecyclePrefix + project + Builds = "builds" + lcBuilds = lifecyclePrefix + Builds + ReleaseBundles = "release-bundles" + lcReleaseBundles = lifecyclePrefix + ReleaseBundles + SigningKey = "signing-key" + lcSigningKey = lifecyclePrefix + SigningKey + lcOverwrite = lifecyclePrefix + Overwrite + PathMappingPattern = "mapping-pattern" + lcPathMappingPattern = lifecyclePrefix + PathMappingPattern + PathMappingTarget = "mapping-target" + lcPathMappingTarget = lifecyclePrefix + PathMappingTarget + lcDryRun = lifecyclePrefix + dryRun ) var flagsMap = map[string]cli.Flag{ @@ -1237,9 +1245,9 @@ var flagsMap = map[string]cli.Flag{ Name: repo, Usage: "[Optional] A repository name at source Artifactory to store release bundle artifacts in. If not provided, Artifactory will use the default one.` `", }, - distRules: cli.StringFlag{ - Name: distRules, - Usage: "Path to distribution rules.` `", + DistRules: cli.StringFlag{ + Name: DistRules, + Usage: "[Optional] Path to distribution rules.` `", }, site: cli.StringFlag{ Name: site, @@ -1509,8 +1517,8 @@ var flagsMap = map[string]cli.Flag{ Name: "format", Hidden: true, }, - createRepo: cli.BoolFlag{ - Name: createRepo, + CreateRepo: cli.BoolFlag{ + Name: CreateRepo, Usage: "[Default: false] Set to true to create the repository on the edge if it does not exist.` `", }, Filestore: cli.BoolFlag{ @@ -1613,6 +1621,19 @@ var flagsMap = map[string]cli.Flag{ Name: Overwrite, Usage: "[Default: false] Set to true to replace artifacts with the same name but a different checksum if such already exist at the promotion targets. By default, the promotion is stopped in a case of such conflict.` `", }, + lcPathMappingPattern: cli.StringFlag{ + Name: PathMappingPattern, + Usage: "[Optional] Specify along with '" + PathMappingTarget + "' to distribute artifacts to a different path on the edge node. You can use wildcards to specify multiple artifacts.` `", + }, + lcPathMappingTarget: cli.StringFlag{ + Name: PathMappingTarget, + Usage: "[Optional] The target path for distributed artifacts on the edge node. If not specified, the artifacts will have the same path and name on the edge node, as on the source Artifactory server. " + + "For flexibility in specifying the distribution path, you can include placeholders in the form of {1}, {2} which are replaced by corresponding tokens in the pattern path that are enclosed in parenthesis.` `", + }, + lcDryRun: cli.BoolFlag{ + Name: dryRun, + Usage: "[Default: false] Set to true to only simulate the distribution of the release bundle.` `", + }, } var commandFlags = map[string][]string{ @@ -1836,11 +1857,11 @@ var commandFlags = map[string][]string{ InsecureTls, rbDetailedSummary, }, ReleaseBundleV1Distribute: { - distUrl, user, password, accessToken, serverId, rbDryRun, distRules, - site, city, countryCodes, sync, maxWaitMinutes, InsecureTls, createRepo, + distUrl, user, password, accessToken, serverId, rbDryRun, DistRules, + site, city, countryCodes, sync, maxWaitMinutes, InsecureTls, CreateRepo, }, ReleaseBundleV1Delete: { - distUrl, user, password, accessToken, serverId, rbDryRun, distRules, + distUrl, user, password, accessToken, serverId, rbDryRun, DistRules, site, city, countryCodes, sync, maxWaitMinutes, InsecureTls, deleteFromDist, deleteQuiet, }, TemplateConsumer: { @@ -1897,6 +1918,10 @@ var commandFlags = map[string][]string{ ReleaseBundlePromote: { lcUrl, user, password, accessToken, serverId, lcSigningKey, lcSync, lcProject, lcOverwrite, }, + ReleaseBundleDistribute: { + lcUrl, user, password, accessToken, serverId, lcDryRun, DistRules, site, city, countryCodes, + InsecureTls, CreateRepo, lcPathMappingPattern, lcPathMappingTarget, + }, // Xray's commands OfflineUpdate: { licenseId, from, to, Version, target, Stream, Periodic, diff --git a/utils/cliutils/utils_test.go b/utils/cliutils/utils_test.go index c3cef052d..0d257bb5f 100644 --- a/utils/cliutils/utils_test.go +++ b/utils/cliutils/utils_test.go @@ -3,6 +3,7 @@ package cliutils import ( "errors" "fmt" + biutils "github.com/jfrog/build-info-go/utils" configtests "github.com/jfrog/jfrog-cli-core/v2/utils/config/tests" clientTestUtils "github.com/jfrog/jfrog-client-go/utils/tests" "path/filepath" @@ -14,7 +15,6 @@ import ( commandUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils" "github.com/jfrog/jfrog-client-go/utils/io/content" - "github.com/jfrog/jfrog-client-go/utils/io/fileutils" "github.com/jfrog/jfrog-client-go/utils/log" "github.com/stretchr/testify/assert" ) @@ -50,7 +50,7 @@ func TestPrintCommandSummary(t *testing.T) { testdata := filepath.Join(tests.GetTestResourcesPath(), "reader", "printcommandsummary.json") tmpDir, createTempDirCallback := coretests.CreateTempDirWithCallbackAndAssert(t) defer createTempDirCallback() - err := fileutils.CopyFile(tmpDir, testdata) + err := biutils.CopyFile(tmpDir, testdata) assert.NoError(t, err) reader := content.NewContentReader(filepath.Join(tmpDir, "printcommandsummary.json"), content.DefaultKey) diff --git a/utils/distribution/distribute.go b/utils/distribution/distribute.go new file mode 100644 index 000000000..bbc82bae9 --- /dev/null +++ b/utils/distribution/distribute.go @@ -0,0 +1,52 @@ +package distribution + +import ( + "github.com/jfrog/jfrog-cli-core/v2/common/spec" + "github.com/jfrog/jfrog-cli/utils/cliutils" + distributionUtils "github.com/jfrog/jfrog-client-go/utils/distribution" + "github.com/urfave/cli" +) + +func CreateDefaultDistributionRules(c *cli.Context) *spec.DistributionRules { + return &spec.DistributionRules{ + DistributionRules: []spec.DistributionRule{{ + SiteName: c.String("site"), + CityName: c.String("city"), + CountryCodes: cliutils.GetStringsArrFlagValue(c, "country-codes"), + }}, + } +} + +func ValidateReleaseBundleDistributeCmd(c *cli.Context) error { + if c.NArg() != 2 { + return cliutils.WrongNumberOfArgumentsHandler(c) + } + if c.IsSet("max-wait-minutes") && !c.IsSet("sync") { + return cliutils.PrintHelpAndReturnError("The --max-wait-minutes option can't be used without --sync", c) + } + + if c.IsSet("dist-rules") && (c.IsSet("site") || c.IsSet("city") || c.IsSet("country-code")) { + return cliutils.PrintHelpAndReturnError("The --dist-rules option can't be used with --site, --city or --country-code", c) + } + + return nil +} + +func InitReleaseBundleDistributeCmd(c *cli.Context) (distributionRules *spec.DistributionRules, maxWaitMinutes int, params distributionUtils.DistributionParams, err error) { + if c.IsSet("dist-rules") { + distributionRules, err = spec.CreateDistributionRulesFromFile(c.String("dist-rules")) + if err != nil { + return + } + } else { + distributionRules = CreateDefaultDistributionRules(c) + } + + maxWaitMinutes, err = cliutils.GetIntFlagValue(c, "max-wait-minutes", 60) + if err != nil { + return + } + + params = distributionUtils.NewDistributeReleaseBundleParams(c.Args().Get(0), c.Args().Get(1)) + return +} diff --git a/utils/tests/consts.go b/utils/tests/consts.go index 8373be6d7..f415aa1f0 100644 --- a/utils/tests/consts.go +++ b/utils/tests/consts.go @@ -2099,6 +2099,20 @@ func GetExpectedLifecycleArtifacts() []string { } } +func GetExpectedLifecycleMappingArtifacts() []string { + return []string{ + RtProdRepo + "/target/a1.in", + RtProdRepo + "/target/a2.in", + RtProdRepo + "/target/a3.in", + RtProdRepo + "/target/b1.in", + RtProdRepo + "/target/b2.in", + RtProdRepo + "/target/b3.in", + RtProdRepo + "/target/c1.in", + RtProdRepo + "/target/c2.in", + RtProdRepo + "/target/c3.in", + } +} + func GetGoPublishWithExclusionsExpectedRepoGo() []string { var expected = []string{ GoRepo + "/github.com/jfrog/dependency/@v/v1.1.1.info", diff --git a/utils/tests/utils.go b/utils/tests/utils.go index d5ab82381..19540b144 100644 --- a/utils/tests/utils.go +++ b/utils/tests/utils.go @@ -106,7 +106,7 @@ func init() { TestXray = flag.Bool("test.xray", false, "Test Xray") TestAccess = flag.Bool("test.access", false, "Test Access") TestTransfer = flag.Bool("test.transfer", false, "Test files transfer") - TestLifecycle = flag.Bool("test.lc", false, "Test lifecycle") + TestLifecycle = flag.Bool("test.lifecycle", false, "Test lifecycle") ContainerRegistry = flag.String("test.containerRegistry", "localhost:8082", "Container registry") HideUnitTestLog = flag.Bool("test.hideUnitTestLog", false, "Hide unit tests logs and print it in a file") InstallDataTransferPlugin = flag.Bool("test.installDataTransferPlugin", false, "Install data-transfer plugin on the source Artifactory server") diff --git a/xray_test.go b/xray_test.go index a59e356b0..fd3ff3150 100644 --- a/xray_test.go +++ b/xray_test.go @@ -5,6 +5,7 @@ import ( "errors" "flag" "fmt" + biutils "github.com/jfrog/build-info-go/utils" "net/http" "net/http/httptest" "os" @@ -152,7 +153,7 @@ func testXrayAuditNpm(t *testing.T, format string) string { defer createTempDirCallback() npmProjectPath := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "xray", "npm") // Copy the npm project from the testdata to a temp dir - assert.NoError(t, fileutils.CopyDir(npmProjectPath, tempDirPath, true, nil)) + assert.NoError(t, biutils.CopyDir(npmProjectPath, tempDirPath, true, nil)) prevWd := changeWD(t, tempDirPath) defer clientTestUtils.ChangeDirAndAssert(t, prevWd) // Run npm install before executing jfrog xr npm-audit @@ -195,7 +196,7 @@ func testXrayAuditYarn(t *testing.T, projectDirName string, yarnCmd func()) { defer createTempDirCallback() yarnProjectPath := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "xray", projectDirName) // Copy the Yarn project from the testdata to a temp directory - assert.NoError(t, fileutils.CopyDir(yarnProjectPath, tempDirPath, true, nil)) + assert.NoError(t, biutils.CopyDir(yarnProjectPath, tempDirPath, true, nil)) prevWd := changeWD(t, tempDirPath) defer clientTestUtils.ChangeDirAndAssert(t, prevWd) // Run yarn install before executing jf audit --yarn. Return error to assert according to test. @@ -232,7 +233,7 @@ func testXrayAuditNuget(t *testing.T, projectName, format string) string { defer createTempDirCallback() projectPath := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "xray", "nuget", projectName) - assert.NoError(t, fileutils.CopyDir(projectPath, tempDirPath, true, nil)) + assert.NoError(t, biutils.CopyDir(projectPath, tempDirPath, true, nil)) prevWd := changeWD(t, tempDirPath) defer clientTestUtils.ChangeDirAndAssert(t, prevWd) // Add dummy descriptor file to check that we run only specific audit @@ -244,12 +245,12 @@ func testXrayAuditNuget(t *testing.T, projectName, format string) string { func TestXrayAuditGradleJson(t *testing.T) { output := testXrayAuditGradle(t, string(utils.Json)) - verifyJsonScanResults(t, output, 0, 0, 0) + verifyJsonScanResults(t, output, 0, 3, 3) } func TestXrayAuditGradleSimpleJson(t *testing.T) { output := testXrayAuditGradle(t, string(utils.SimpleJson)) - verifySimpleJsonScanResults(t, output, 0, 0) + verifySimpleJsonScanResults(t, output, 3, 3) } func testXrayAuditGradle(t *testing.T, format string) string { @@ -258,7 +259,7 @@ func testXrayAuditGradle(t *testing.T, format string) string { defer createTempDirCallback() gradleProjectPath := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "xray", "gradle") // Copy the gradle project from the testdata to a temp dir - assert.NoError(t, fileutils.CopyDir(gradleProjectPath, tempDirPath, true, nil)) + assert.NoError(t, biutils.CopyDir(gradleProjectPath, tempDirPath, true, nil)) prevWd := changeWD(t, tempDirPath) defer clientTestUtils.ChangeDirAndAssert(t, prevWd) // Add dummy descriptor file to check that we run only specific audit @@ -282,7 +283,7 @@ func testXrayAuditMaven(t *testing.T, format string) string { defer createTempDirCallback() mvnProjectPath := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "xray", "maven") // Copy the maven project from the testdata to a temp dir - assert.NoError(t, fileutils.CopyDir(mvnProjectPath, tempDirPath, true, nil)) + assert.NoError(t, biutils.CopyDir(mvnProjectPath, tempDirPath, true, nil)) prevWd := changeWD(t, tempDirPath) defer clientTestUtils.ChangeDirAndAssert(t, prevWd) // Add dummy descriptor file to check that we run only specific audit @@ -307,7 +308,7 @@ func TestXrayAuditDetectTech(t *testing.T) { defer createTempDirCallback() mvnProjectPath := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "xray", "maven") // Copy the maven project from the testdata to a temp dir - assert.NoError(t, fileutils.CopyDir(mvnProjectPath, tempDirPath, true, nil)) + assert.NoError(t, biutils.CopyDir(mvnProjectPath, tempDirPath, true, nil)) prevWd := changeWD(t, tempDirPath) defer clientTestUtils.ChangeDirAndAssert(t, prevWd) // Run generic audit on mvn project with a vulnerable dependency @@ -325,7 +326,7 @@ func TestXrayAuditMultiProjects(t *testing.T) { defer createTempDirCallback() multiProject := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "xray") // Copy the multi project from the testdata to a temp dir - assert.NoError(t, fileutils.CopyDir(multiProject, tempDirPath, true, nil)) + assert.NoError(t, biutils.CopyDir(multiProject, tempDirPath, true, nil)) workingDirsFlag := fmt.Sprintf("--working-dirs=%s, %s ,%s, %s", filepath.Join(tempDirPath, "maven"), filepath.Join(tempDirPath, "nuget", "single"), filepath.Join(tempDirPath, "python", "pip"), filepath.Join(tempDirPath, "jas-test")) @@ -363,7 +364,7 @@ func testXrayAuditPip(t *testing.T, format, requirementsFile string) string { defer createTempDirCallback() pipProjectPath := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "xray", "python", "pip") // Copy the pip project from the testdata to a temp dir - assert.NoError(t, fileutils.CopyDir(pipProjectPath, tempDirPath, true, nil)) + assert.NoError(t, biutils.CopyDir(pipProjectPath, tempDirPath, true, nil)) prevWd := changeWD(t, tempDirPath) defer clientTestUtils.ChangeDirAndAssert(t, prevWd) // Add dummy descriptor file to check that we run only specific audit @@ -392,7 +393,7 @@ func testXrayAuditPipenv(t *testing.T, format string) string { defer createTempDirCallback() pipenvProjectPath := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "xray", "python", "pipenv") // Copy the pipenv project from the testdata to a temp dir - assert.NoError(t, fileutils.CopyDir(pipenvProjectPath, tempDirPath, true, nil)) + assert.NoError(t, biutils.CopyDir(pipenvProjectPath, tempDirPath, true, nil)) prevWd := changeWD(t, tempDirPath) defer clientTestUtils.ChangeDirAndAssert(t, prevWd) // Add dummy descriptor file to check that we run only specific audit @@ -454,7 +455,7 @@ func testXrayAuditPoetry(t *testing.T, format string) string { defer createTempDirCallback() poetryProjectPath := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "xray", "python", "poetry") // Copy the poetry project from the testdata to a temp dir - assert.NoError(t, fileutils.CopyDir(poetryProjectPath, tempDirPath, true, nil)) + assert.NoError(t, biutils.CopyDir(poetryProjectPath, tempDirPath, true, nil)) prevWd := changeWD(t, tempDirPath) defer clientTestUtils.ChangeDirAndAssert(t, prevWd) // Add dummy descriptor file to check that we run only specific audit @@ -485,7 +486,7 @@ func validateXrayVersion(t *testing.T, minVersion string) { assert.NoError(t, err) return } - err = coreutils.ValidateMinimumVersion(coreutils.Xray, xrayVersion.GetVersion(), minVersion) + err = clientUtils.ValidateMinimumVersion(clientUtils.Xray, xrayVersion.GetVersion(), minVersion) if err != nil { t.Skip(err) } @@ -683,7 +684,7 @@ func testXrayAuditJas(t *testing.T, format string, project string) string { defer createTempDirCallback() projectDir := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), filepath.Join("xray", project)) // Copy the multi project from the testdata to a temp dir - assert.NoError(t, fileutils.CopyDir(projectDir, tempDirPath, true, nil)) + assert.NoError(t, biutils.CopyDir(projectDir, tempDirPath, true, nil)) // Configure a new server named "default" createJfrogHomeConfig(t, true) defer cleanTestsHomeEnv() @@ -718,7 +719,7 @@ func TestCurationAudit(t *testing.T) { tempDirPath, createTempDirCallback := coretests.CreateTempDirWithCallbackAndAssert(t) defer createTempDirCallback() multiProject := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "xray") - assert.NoError(t, fileutils.CopyDir(multiProject, tempDirPath, true, nil)) + assert.NoError(t, biutils.CopyDir(multiProject, tempDirPath, true, nil)) rootDir, err := os.Getwd() require.NoError(t, err) defer func() {